diff options
3 files changed, 69 insertions, 6 deletions
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 1c46b9991..a1b63e487 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 @@ -165,7 +165,7 @@ public class ControlLoopOperationManager implements Serializable { else { throw new ControlLoopException("The target is null"); } - return null; + throw new ControlLoopException("Target does not match target type"); } public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, ControlLoopEventManager em) throws ControlLoopException, AAIException { @@ -289,9 +289,12 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; case "VFC": - this.operationRequest = VFCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.operation, this.policy, this.eventManager.getVnfResponse()); - this.currentOperation = operation; - return operationRequest; + this.operationRequest = VFCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.operation, this.policy, this.eventManager.getVnfResponse()); + this.currentOperation = operation; + if (this.operationRequest == null) { + this.policyResult = PolicyResult.FAILURE; + } + return operationRequest; } return null; diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl index 725e01e22..93b4e0a8a 100644 --- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl +++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl @@ -604,6 +604,11 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" retract($operation); modify($manager) {finishOperation($operation)}; } + else if ("vfc".equalsIgnoreCase($operation.policy.getActor())) { + retract($opTimer); + retract($operation); + modify($manager) {finishOperation($operation)}; + } } end diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java index 2581e3d80..39dac8131 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java @@ -166,6 +166,56 @@ public class VFCControlLoopTest implements TopicListener { */ dumpFacts(kieSession); } + + @Test + public void nullRequestTest() throws IOException { + + /* + * Allows the PolicyEngine to callback to this object to + * notify that there is an event ready to be pulled + * from the queue + */ + for (TopicSink sink : noopTopics) { + assertTrue(sink.start()); + sink.register(this); + } + + /* + * Create a unique requestId + */ + requestID = UUID.randomUUID(); + + /* + * Simulate an onset event the policy engine will + * receive from DCAE to kick off processing through + * the rules + */ + + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.closedLoopControlName = pair.a.getControlLoop().getControlLoopName(); + event.requestID = UUID.randomUUID(); + event.closedLoopEventClient = "tca.instance00009"; + event.target_type = ControlLoopTargetType.VM; + event.target = "vserver.vserver-name"; + event.from = "DCAE"; + event.closedLoopAlarmStart = Instant.now(); + event.AAI = new HashMap<String, String>(); + event.AAI.put("vserver.vserver-name", "nullRequest"); + event.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + kieSession.insert(event); + + kieSession.fireUntilHalt(); + + /* + * The only fact in memory should be Params + */ + assertEquals(1, kieSession.getFactCount()); + + /* + * Print what's left in memory + */ + dumpFacts(kieSession); + } /** * This method will start a kie session and instantiate @@ -274,7 +324,12 @@ public class VFCControlLoopTest implements TopicListener { } else if (policyName.endsWith("EVENT.MANAGER")) { logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification)); + if ("nullRequest".equals(notification.AAI.get("vserver.vserver-name"))){ + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification); + } + else { + assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.notification); + } kieSession.halt(); } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { @@ -304,7 +359,7 @@ public class VFCControlLoopTest implements TopicListener { event.requestID = UUID.randomUUID(); event.closedLoopEventClient = "tca.instance00009"; event.target_type = ControlLoopTargetType.VM; - event.target = "VM_NAME"; + event.target = "vserver.vserver-name"; event.from = "DCAE"; event.closedLoopAlarmStart = Instant.now(); event.AAI = new HashMap<String, String>(); |