aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main
diff options
context:
space:
mode:
authordaniel <dc443y@att.com>2017-10-24 22:00:08 -0500
committerdaniel <dc443y@att.com>2017-10-25 09:29:41 -0500
commit85b1ada7cc0883aa8b86ea6e11bf86719e1cc10e (patch)
tree86f4712aa717e1fa5e510c345f887b3e0c11f6c8 /controlloop/common/eventmanager/src/main
parent7e3ace91847ec5aaccfeeff638a8d2d9b17e45fc (diff)
Fix Source/Target Lock
The locking of the target is now taken care of when the operation manager is initialized. This allows us to keep the template flow the same and to ensure that for vFW we will not lock the source if it is not intended to be the target. NOTE: This will have to be revised in the future if policy chaining will support having different targets specified for each policy in the chain. Additional work was done for hardening the APPC model code to make sure exceptions are caught and we gracefully end processing the event with memory clean up and a final failure notification sent. Issue-Id: POLICY-367 Change-Id: Ic796d95eb5400067744492f810dd8069ba6241b3 Signed-off-by: Daniel Cruz <dc443y@att.com> Signed-off-by: daniel <dc443y@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src/main')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java31
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java69
2 files changed, 65 insertions, 35 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 91db147c8..2a5a3d0a9 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
@@ -31,6 +31,7 @@ import java.util.UUID;
import org.onap.policy.aai.AAIGETVnfResponse;
import org.onap.policy.aai.AAIGETVserverResponse;
import org.onap.policy.aai.AAIManager;
+import org.onap.policy.aai.util.AAIException;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopNotificationType;
@@ -289,7 +290,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
return notification;
}
- public ControlLoopOperationManager processControlLoop() throws ControlLoopException {
+ public ControlLoopOperationManager processControlLoop() throws ControlLoopException, AAIException {
//
// Check if they activated us
//
@@ -397,7 +398,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
//
LockResult<GuardResult, TargetLock> lockResult = PolicyGuard.lockTarget(
this.currentOperation.policy.getTarget().getType(),
- this.getTargetInstance(this.currentOperation.policy),
+ this.currentOperation.getTargetEntity(),
this.onset.requestID,
this);
//
@@ -694,32 +695,6 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
return false;
}
- public String getTargetInstance(Policy policy) {
- if (policy.getTarget() != null) {
- if (policy.getTarget().getType() != null) {
- switch(policy.getTarget().getType()) {
- case PNF:
- break;
- case VM:
- case VNF:
- if (this.onset.target.equalsIgnoreCase("vserver.vserver-name")) {
- return this.onset.AAI.get("vserver.vserver-name");
- }
- else if (this.onset.target.equalsIgnoreCase("generic-vnf.vnf-id")) {
- return this.onset.AAI.get("generic-vnf.vnf-id");
- }
- else if (this.onset.target.equalsIgnoreCase("generic-vnf.vnf-name")) {
- return this.onset.AAI.get("generic-vnf.vnf-name");
- }
- break;
- default:
- break;
- }
- }
- }
- return null;
- }
-
@Override
public String toString() {
return "ControlLoopEventManager [closedLoopControlName=" + closedLoopControlName + ", requestID=" + requestID
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
index eeb724ad2..1c46b9991 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
@@ -84,6 +84,7 @@ public class ControlLoopOperationManager implements Serializable {
private LinkedList<Operation> operationHistory = new LinkedList<Operation>();
private PolicyResult policyResult = null;
private ControlLoopEventManager eventManager = null;
+ private String targetEntity;
public ControlLoopEventManager getEventManager() {
return eventManager;
@@ -93,6 +94,9 @@ public class ControlLoopOperationManager implements Serializable {
this.eventManager = eventManager;
}
+ public String getTargetEntity() {
+ return this.targetEntity;
+ }
//
// Internal class used for tracking
@@ -123,21 +127,72 @@ public class ControlLoopOperationManager implements Serializable {
this.guardApprovalStatus = guardApprovalStatus;
}
-
- public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, ControlLoopEventManager em) throws ControlLoopException {
+ public String getTarget(Policy policy) throws ControlLoopException, AAIException {
+ if (policy.getTarget() != null) {
+ if (policy.getTarget().getType() != null) {
+ switch(policy.getTarget().getType()) {
+ case PNF:
+ break;
+ case VM:
+ case VNF:
+ VirtualControlLoopEvent virtualOnset = (VirtualControlLoopEvent) this.onset;
+ if (this.onset.target.equalsIgnoreCase("vserver.vserver-name")) {
+ return virtualOnset.AAI.get("vserver.vserver-name");
+ }
+ else if (this.onset.target.equalsIgnoreCase("generic-vnf.vnf-id")) {
+ return virtualOnset.AAI.get("generic-vnf.vnf-id");
+ }
+ else if (this.onset.target.equalsIgnoreCase("generic-vnf.vnf-name")) {
+ /*
+ * If the vnf-name was retrieved from the onset then the vnf-id
+ * must be obtained from the event manager's A&AI GET query
+ */
+ String vnfId = this.eventManager.getVnfResponse().vnfID;
+ if (vnfId == null) {
+ throw new AAIException("No vnf-id found");
+ }
+ return vnfId;
+ }
+ break;
+ default:
+ throw new ControlLoopException("The target type is not supported");
+ }
+ }
+ else {
+ throw new ControlLoopException("The target type is null");
+ }
+ }
+ else {
+ throw new ControlLoopException("The target is null");
+ }
+ return null;
+ }
+
+ public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, ControlLoopEventManager em) throws ControlLoopException, AAIException {
this.onset = onset;
this.policy = policy;
this.guardApprovalStatus = "NONE";
this.eventManager = em;
-
+ this.targetEntity = getTarget(policy);
+
//
// Let's make a sanity check
//
switch (policy.getActor()) {
case "APPC":
+ if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
+ /*
+ * The target vnf-id may not be the same as the source vnf-id
+ * specified in the yaml, the target vnf-id is retrieved by
+ * a named query to A&AI.
+ */
+ String targetVnf = AppcLcmActorServiceProvider.vnfNamedQuery(
+ policy.getTarget().getResourceID(), this.targetEntity);
+ this.targetEntity = targetVnf;
+ }
break;
case "SO":
- break;
+ break;
case "VFC":
break;
default:
@@ -210,11 +265,11 @@ public class ControlLoopOperationManager implements Serializable {
if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
this.operationRequest = APPCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
- operation.operation, this.policy, eventManager.getVnfResponse());
+ operation.operation, this.policy, this.targetEntity);
}
else {
this.operationRequest = AppcLcmActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
- operation.operation, this.policy, eventManager.getVnfResponse());
+ operation.operation, this.policy, this.targetEntity);
}
//
// Save the operation
@@ -593,7 +648,7 @@ public class ControlLoopOperationManager implements Serializable {
newEntry.requestId = this.onset.requestID.toString();
newEntry.actor = this.currentOperation.operation.actor;
newEntry.operation = this.currentOperation.operation.operation;
- newEntry.target = this.eventManager.getTargetInstance(this.policy);
+ newEntry.target = this.targetEntity;
newEntry.starttime = Timestamp.from(this.currentOperation.operation.start);
newEntry.subrequestId = this.currentOperation.operation.subRequestId;
newEntry.endtime = new Timestamp(this.currentOperation.operation.end.toEpochMilli());