From 506267bf7e9d961f1a6b2a989ee8a23ca67b9d61 Mon Sep 17 00:00:00 2001 From: Charles Cole Date: Mon, 16 Oct 2017 12:05:08 -0500 Subject: Add support for AAI Named Query error handling Errors from AAI after a Named query now throw an AAIEXception. This is caught in the template to allow the resources to be removed from memory and a final failure to be thrown. Issue-ID: POLICY-314 Change-Id: I319d29ef537b2d01ca288622aac1d9dbbe05f5eb Signed-off-by: Charles Cole --- .../policy/template/demo/VFWControlLoopTest.java | 96 +++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) (limited to 'controlloop/templates/template.demo/src/test') diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java index cef39b5e8..6424d02b6 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java @@ -35,6 +35,7 @@ import java.util.UUID; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; @@ -170,6 +171,72 @@ public class VFWControlLoopTest implements TopicListener { kieSession.dispose(); } + @Test + public void namedQueryFailTest() { + + /* + * Start the kie session + */ + try { + kieSession = startSession("../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl", + "src/test/resources/yaml/policy_ControlLoop_vFW.yaml", + "service=ServiceDemo;resource=Res1Demo;type=operational", + "CL_vFW", + "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0"); + } catch (IOException e) { + e.printStackTrace(); + logger.debug("Could not create kieSession"); + fail("Could not create kieSession"); + } + + /* + * 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 + */ + sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "error"); + + try { + kieSession.fireUntilHalt(); + } + catch (Exception e) { + e.printStackTrace(); + logger.warn(e.toString()); + fail(e.getMessage()); + } + + + /* + * The only fact in memory should be Params + */ + assertEquals(1, kieSession.getFactCount()); + + /* + * Print what's left in memory + */ + dumpFacts(kieSession); + + /* + * Gracefully shut down the kie session + */ + kieSession.dispose(); + } + /** * This method will start a kie session and instantiate * the Policy Engine. @@ -279,7 +346,13 @@ public class VFWControlLoopTest implements TopicListener { } else if (policyName.endsWith("EVENT.MANAGER")) { logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification)); + if ("error".equals(notification.AAI.get("generic-vnf.vnf-id"))) { + assertTrue(ControlLoopNotificationType.FINAL_FAILURE.equals(notification.notification)); + assertEquals("Exception in processing closed loop", notification.message); + } + else { + assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification)); + } kieSession.halt(); } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { @@ -326,6 +399,27 @@ public class VFWControlLoopTest implements TopicListener { kieSession.insert(event); } + /** + * This method is used to simulate event messages from DCAE + * that start the control loop (onset message) or end the + * control loop (abatement message). + * + * @param policy the controlLoopName comes from the policy + * @param requestID the requestId for this event + * @param status could be onset or abated + */ + protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vnfId) { + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); + event.requestID = requestID; + event.target = "generic-vnf.vnf-id"; + event.closedLoopAlarmStart = Instant.now(); + event.AAI = new HashMap<>(); + event.AAI.put("generic-vnf.vnf-id", vnfId); + event.closedLoopEventStatus = status; + kieSession.insert(event); + } + /** * This method will dump all the facts in the working memory. * -- cgit 1.2.3-korg