diff options
Diffstat (limited to 'controlloop/common/eventmanager')
4 files changed, 69 insertions, 36 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()); diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java index caa17ff38..d41d8bf57 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java @@ -40,6 +40,7 @@ import org.onap.policy.appclcm.LCMResponseWrapper; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.ControlLoopException; +import org.onap.policy.controlloop.ControlLoopTargetType; import org.onap.policy.controlloop.Util; import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.PolicyResult; @@ -56,6 +57,7 @@ public class ControlLoopOperationManagerTest { onset = new VirtualControlLoopEvent(); onset.requestID = UUID.randomUUID(); onset.target = "generic-vnf.vnf-name"; + onset.target_type = ControlLoopTargetType.VNF; onset.closedLoopAlarmStart = Instant.now(); onset.AAI = new HashMap<>(); onset.AAI.put("generic-vnf.vnf-name", "testTriggerSource"); diff --git a/controlloop/common/eventmanager/src/test/resources/test.yaml b/controlloop/common/eventmanager/src/test/resources/test.yaml index e15c8f0e1..7a9435ecc 100644 --- a/controlloop/common/eventmanager/src/test/resources/test.yaml +++ b/controlloop/common/eventmanager/src/test/resources/test.yaml @@ -23,7 +23,8 @@ policies: description: actor: APPC recipe: Restart - target: VM + target: + type: VNF retry: 1 timeout: 20 success: final_success |