aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/guard/src
diff options
context:
space:
mode:
authorJoshua Reich <jreich@research.att.com>2018-09-13 14:24:43 -0700
committerJoshua Reich <jreich@research.att.com>2018-09-14 12:13:23 -0700
commit910dc65cba60b0dafe975b88d69df6559dee7abb (patch)
tree69cae99ac556f1b81a1bef7e284c46d340a33b8d /controlloop/common/guard/src
parent97956f188f4a8d92d734bf491d5e15a78a03459f (diff)
Option to disable target locking. Needed by CLC.
When used, the ControlLoopEventManager will set useTargetLock to false converting TargetLock lock/unlock operations to no-ops. Allows CLC-specified logic to coordinate closed loops instead of hard-coded mutual-exclusion enforced by target locking. Change-Id: Ic067c1e1ce47b12d12742ed4bc04d59aa42751d6 Issue-ID: POLICY-953 Signed-off-by: Joshua Reich <jreich@research.att.com>
Diffstat (limited to 'controlloop/common/guard/src')
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java75
1 files changed, 44 insertions, 31 deletions
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java
index e4fd27415..a7b4f73f2 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java
@@ -81,60 +81,73 @@ public class PolicyGuard {
}
/**
- * Lock a target.
+ * Create a lock.
*
* @param targetType the target type
* @param targetInstance the target instance
* @param requestID the request Id
- * @param callback the LockCallback
- * @param holdSec maximum number of seconds to hold the lock
- * @return the LockResult
+ * @return the TargetLock
* @throws IllegalArgumentException if an argument is null
*/
- public static LockResult<GuardResult, TargetLock> lockTarget(TargetType targetType, String targetInstance,
- UUID requestID, LockCallback callback, int holdSec) {
-
- String owner = makeOwner(targetType, requestID);
-
- boolean result = factory.getManager().lock(targetInstance, owner, holdSec);
- if (!result) {
- return LockResult.createLockResult(GuardResult.LOCK_DENIED, null);
- }
-
- TargetLock lock = null;
+ public static TargetLock createTargetLock(TargetType targetType, String targetInstance,
+ UUID requestID, LockCallback callback) {
switch (targetType) {
case PNF:
//
// Create the Lock object
//
- lock = new PNFTargetLock(targetType, targetInstance, requestID, callback);
- break;
+ return new PNFTargetLock(targetType, targetInstance, requestID, callback);
case VM:
//
// Create the Lock object
//
- lock = new VMTargetLock(targetType, targetInstance, requestID, callback);
- break;
+ return new VMTargetLock(targetType, targetInstance, requestID, callback);
case VNF:
//
// Create the Lock object
//
- lock = new VNFTargetLock(targetType, targetInstance, requestID, callback);
- break;
-
+ return new VNFTargetLock(targetType, targetInstance, requestID, callback);
default:
logger.error("invalid target type {} for lock on {}", targetType, targetInstance);
- factory.getManager().unlock(targetInstance, owner);
- return LockResult.createLockResult(GuardResult.LOCK_EXCEPTION, null);
+ return null;
}
-
- //
- // Return result
- //
- logger.debug("Locked {}", lock);
- return LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock);
}
-
+
+ /**
+ * Lock a target.
+ *
+ * @param targetType the target type
+ * @param targetInstance the target instance
+ * @param requestID the request Id
+ * @param callback the LockCallback
+ * @param holdSec maximum number of seconds to hold the lock
+ * @return the LockResult
+ * @throws IllegalArgumentException if an argument is null
+ */
+ public static LockResult<GuardResult, TargetLock> lockTarget(TargetType targetType, String targetInstance,
+ UUID requestID, LockCallback callback, int holdSec) {
+ String owner = makeOwner(targetType, requestID);
+ boolean result = factory.getManager().lock(targetInstance, owner, holdSec);
+ if (!result) {
+ return LockResult.createLockResult(GuardResult.LOCK_DENIED, null);
+ }
+
+ TargetLock lock = createTargetLock(targetType, targetInstance, requestID, callback);
+ if (lock == null) {
+ //
+ // Bad lock type: unlock and return exception result
+ //
+ factory.getManager().unlock(targetInstance, owner);
+ return LockResult.createLockResult(GuardResult.LOCK_EXCEPTION, null);
+ } else {
+ //
+ // Return result
+ //
+ logger.debug("Locked {}", lock);
+ return LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock);
+ }
+ }
+
/**
* Extends a lock on a target.
* @param lock current lock