diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2018-09-17 15:51:05 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-17 15:51:05 +0000 |
commit | 8c16c0756ab3b78028db7c5f2022097587867e0e (patch) | |
tree | c360726919896f40c75ebe8e2dfe505021fa031c /controlloop | |
parent | d76dd05fbb53b382da2e5acf5e4fce748a233af2 (diff) | |
parent | 910dc65cba60b0dafe975b88d69df6559dee7abb (diff) |
Merge "Option to disable target locking. Needed by CLC."
Diffstat (limited to 'controlloop')
2 files changed, 70 insertions, 34 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java index 8641ddc27..bd1904904 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java @@ -104,6 +104,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { private TargetLock targetLock = null; private AaiGetVnfResponse vnfResponse = null; private AaiGetVserverResponse vserverResponse = null; + private boolean useTargetLock = true; /** * Wrapper for AAI vserver named-query response. This is initialized in a lazy @@ -161,6 +162,14 @@ public class ControlLoopEventManager implements LockCallback, Serializable { this.isActivated = isActivated; } + public boolean useTargetLock() { + return useTargetLock(); + } + + public void setUseTargetLock(boolean useTargetLock) { + this.useTargetLock = useTargetLock; + } + public VirtualControlLoopEvent getOnsetEvent() { return this.onset; } @@ -268,7 +277,6 @@ public class ControlLoopEventManager implements LockCallback, Serializable { // Parse the YAML specification // this.processor = new ControlLoopProcessor(yamlSpecification); - // // At this point we are good to go with this event // @@ -480,6 +488,17 @@ public class ControlLoopEventManager implements LockCallback, Serializable { throw new ControlLoopException("Do not have a current operation."); } // + // Not using target locks? Create and return a lock w/o actually locking. + // + if (!this.useTargetLock) { + TargetLock lock = PolicyGuard.createTargetLock(this.currentOperation.policy.getTarget().getType(), + this.currentOperation.getTargetEntity(), + this.onset.getRequestId(), this); + this.targetLock = lock; + LockResult<GuardResult, TargetLock> lockResult = LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock); + return lockResult; + } + // // Have we acquired it already? // if (this.targetLock != null) { @@ -523,8 +542,12 @@ public class ControlLoopEventManager implements LockCallback, Serializable { TargetLock returnLock = this.targetLock; this.targetLock = null; - - PolicyGuard.unlockTarget(returnLock); + // + // if using target locking unlock before returning + // + if (this.useTargetLock) { + PolicyGuard.unlockTarget(returnLock); + } // always return the old target lock so rules can retract it return returnLock; 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 |