diff options
Diffstat (limited to 'resource-assignment/provider')
3 files changed, 28 insertions, 6 deletions
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelper.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelper.java index d33703df..040d1927 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelper.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelper.java @@ -8,9 +8,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,9 +27,13 @@ public interface LockHelper { void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */); + void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */, int lockWait /* Seconds */, int retryCount); + void unlock(String resourceName, boolean force); void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */); + void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */, int lockWait /* Seconds */, int retryCount); + void unlock(Collection<String> resourceNameList, boolean force); } diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelperImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelperImpl.java index 3a8c730e..1611b537 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelperImpl.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelperImpl.java @@ -41,7 +41,12 @@ public class LockHelperImpl implements LockHelper { @Override public void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */) { - lock(Collections.singleton(resourceName), lockRequester, lockTimeout); + lock(resourceName, lockRequester, lockTimeout, lockWait, retryCount); + } + + @Override + public void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */, int lockWait /* Seconds */, int retryCount) { + lock(Collections.singleton(resourceName), lockRequester, lockTimeout, lockWait, retryCount); } @Override @@ -51,13 +56,18 @@ public class LockHelperImpl implements LockHelper { @Override public void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */) { + lock(resourceNameList, lockRequester, lockTimeout, lockWait, retryCount); + } + + @Override + public void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */, int lockWait /* Seconds */, int retryCount) { for (int i = 0; true; i++) { try { tryLock(resourceNameList, lockRequester, lockTimeout); log.info("Resources locked: " + resourceNameList); return; } catch (ResourceLockedException e) { - if (i > retryCount) { + if (i >= retryCount) { throw e; } try { diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceLockNode.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceLockNode.java index d1ba1eb7..a7d4b0e2 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceLockNode.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceLockNode.java @@ -45,8 +45,12 @@ public class ResourceLockNode implements SvcLogicJavaPlugin { String lockRequester = getParam(paramMap, "lock-requester", false, generateLockRequester()); String lockTimeoutStr = getParam(paramMap, "lock-timeout", false, "600"); // Default lock timeout: 10 min int lockTimeout = Integer.parseInt(lockTimeoutStr); + String lockWaitStr = getParam(paramMap, "lock-wait", false, "5"); // Time waiting before next retry. Default: 5 sec + int lockWait = Integer.parseInt(lockWaitStr); + String lockRetryCountStr = getParam(paramMap, "lock-retry-count", false, "10"); // Default: 10 retries + int lockRetryCount = Integer.parseInt(lockRetryCountStr); - lockHelper.lock(resourceName, lockRequester, lockTimeout); + lockHelper.lock(resourceName, lockRequester, lockTimeout, lockWait, lockRetryCount); } public void unlockResource(Map<String, String> paramMap, SvcLogicContext ctx) throws SvcLogicException { @@ -56,6 +60,10 @@ public class ResourceLockNode implements SvcLogicJavaPlugin { } public void lockResource(String resourceName, String lockRequester, int lockTimeout /* sec */) { + lockResource(resourceName, lockRequester, lockTimeout, 5, 10); + } + + public void lockResource(String resourceName, String lockRequester, int lockTimeout /* sec */, int lockWait /* Seconds */, int retryCount) { if (lockRequester == null) { lockRequester = generateLockRequester(); } @@ -63,7 +71,7 @@ public class ResourceLockNode implements SvcLogicJavaPlugin { lockTimeout = 600; } - lockHelper.lock(resourceName, lockRequester, lockTimeout); + lockHelper.lock(resourceName, lockRequester, lockTimeout, lockWait, retryCount); } public void unlockResource(String resourceName) { |