Fix Final Failure on AAI Queries 91/21291/1
authordaniel <dc443y@att.com>
Mon, 30 Oct 2017 12:58:34 +0000 (07:58 -0500)
committerdaniel <dc443y@att.com>
Mon, 30 Oct 2017 13:08:59 +0000 (08:08 -0500)
The drools engine will now send final failure notifications
if there is an error returned from  A&AI queries instead of
rejected notifications.

Issue-Id: POLICY-364
Change-Id: Ie9c22686d859c633bad47d223726957cc9599f7c
Signed-off-by: Daniel Cruz <dc443y@att.com>
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java

index d320b75..b167420 100644 (file)
@@ -149,7 +149,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
                        // Syntax check the event
                        //
                        checkEventSyntax(event);
-                       checkEventAAISyntax(event);
+                       
                        //
                        // At this point we are good to go with this event
                        //
@@ -184,7 +184,6 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
                        // Syntax check the event
                        //
                        checkEventSyntax(event);
-                       checkEventAAISyntax(event);
        
                        //
                        // Check the YAML
@@ -437,7 +436,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
                ;
        }
                
-       public NEW_EVENT_STATUS onNewEvent(VirtualControlLoopEvent event) {
+       public NEW_EVENT_STATUS onNewEvent(VirtualControlLoopEvent event) throws AAIException {
                try {
                        this.checkEventSyntax(event);
                        if (event.closedLoopEventStatus == ControlLoopEventStatus.ONSET) {
@@ -445,6 +444,11 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
                                // Check if this is our original ONSET
                                //
                                if (event.equals(this.onset)) {
+                                   //
+                                   // Query A&AI if needed
+                                   //
+                                   queryAai(event);
+                                   
                                        //
                                        // DO NOT retract it
                                        //
@@ -546,58 +550,58 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
                                ! "generic-vnf.vnf-name".equalsIgnoreCase(event.target) ) {
                        throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME");
                }
+               if (event.AAI == null) {
+            throw new ControlLoopException("AAI is null");
+        }
+        if (event.AAI.get("generic-vnf.vnf-id") == null && event.AAI.get("vserver.vserver-name") == null &&
+                event.AAI.get("generic-vnf.vnf-name") == null) {
+            throw new ControlLoopException("generic-vnf.vnf-id or generic-vnf.vnf-name or vserver.vserver-name information missing");
+        }
        }
        
-       public void checkEventAAISyntax(VirtualControlLoopEvent event) throws ControlLoopException {
-               if (event.AAI == null) {
-                       throw new ControlLoopException("AAI is null");
-               }
-               if (event.AAI.get("generic-vnf.vnf-id") == null && event.AAI.get("vserver.vserver-name") == null &&
-                               event.AAI.get("generic-vnf.vnf-name") == null) {
-                       throw new ControlLoopException("generic-vnf.vnf-id or generic-vnf.vnf-name or vserver.vserver-name information missing");
-               }
+       public void queryAai(VirtualControlLoopEvent event) throws AAIException {
                if (event.AAI.get("vserver.is-closed-loop-disabled") == null) {
                        try {
                                if (event.AAI.get("generic-vnf.vnf-id") != null) {
                                        vnfResponse = getAAIVnfInfo(event); 
                                        if (vnfResponse == null) {
-                                               throw new ControlLoopException("AAI Response is null (query by vnf-id)");
+                                               throw new AAIException("AAI Response is null (query by vnf-id)");
                                        }
                                        if (vnfResponse.requestError != null) {
-                                               throw new ControlLoopException("AAI Responded with a request error (query by vnf-id)");
+                                               throw new AAIException("AAI Responded with a request error (query by vnf-id)");
                                        }
                                        if (isClosedLoopDisabled(vnfResponse) == true) {
-                                               throw new ControlLoopException("is-closed-loop-disabled is set to true");       
+                                               throw new AAIException("is-closed-loop-disabled is set to true");       
                                        }
                                } else if (event.AAI.get("generic-vnf.vnf-name") != null) {
                                        vnfResponse = getAAIVnfInfo(event); 
                                        if (vnfResponse == null) {
-                                               throw new ControlLoopException("AAI Response is null (query by vnf-name)");
+                                               throw new AAIException("AAI Response is null (query by vnf-name)");
                                        }
                                        if (vnfResponse.requestError != null) {
-                                               throw new ControlLoopException("AAI Responded with a request error (query by vnf-name)");
+                                               throw new AAIException("AAI Responded with a request error (query by vnf-name)");
                                        }
                                        if (isClosedLoopDisabled(vnfResponse) == true) {
-                                               throw new ControlLoopException("is-closed-loop-disabled is set to true");       
+                                               throw new AAIException("is-closed-loop-disabled is set to true");       
                                        }
                                } else if (event.AAI.get("vserver.vserver-name") != null) {
                                        vserverResponse = getAAIVserverInfo(event); 
                                        if (vserverResponse == null) {
-                                               throw new ControlLoopException("AAI Response is null (query by vserver-name)");
+                                               throw new AAIException("AAI Response is null (query by vserver-name)");
                                        }
                                        if (vserverResponse.requestError != null) {
-                                               throw new ControlLoopException("AAI responded with a request error (query by vserver-name)");
+                                               throw new AAIException("AAI responded with a request error (query by vserver-name)");
                                        }
                                        if (isClosedLoopDisabled(vserverResponse) == true) {
-                                               throw new ControlLoopException("is-closed-loop-disabled is set to true");       
+                                               throw new AAIException("is-closed-loop-disabled is set to true");       
                                        }
                                }
                        } catch (Exception e) {
                                logger.error("Exception from getAAIInfo: ", e);
-                               throw new ControlLoopException("Exception from getAAIInfo: " + e.toString());
+                               throw new AAIException("Exception from getAAIInfo: " + e.toString());
                        }
                } else if (isClosedLoopDisabled(event)) {
-                       throw new ControlLoopException("is-closed-loop-disabled is set to true");
+                       throw new AAIException("is-closed-loop-disabled is set to true");
                }
        }
        
index 2233615..be0eb2b 100644 (file)
@@ -40,6 +40,7 @@ import org.onap.policy.aai.Relationship;
 import org.onap.policy.aai.RelationshipData;
 import org.onap.policy.aai.RelationshipDataItem;
 import org.onap.policy.aai.RelationshipList;
+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;
@@ -227,6 +228,17 @@ public class ControlLoopEventManagerTest {
         
         assertNotNull(notification);
         assertEquals(ControlLoopNotificationType.ACTIVE, notification.notification);
+        
+        ControlLoopEventManager.NEW_EVENT_STATUS status = null;
+        try {
+            status = manager.onNewEvent(event);
+        } catch (AAIException e) {
+            logger.warn(e.toString());
+            fail("A&AI Query Failed");
+        }
+        assertNotNull(status);
+        assertEquals(ControlLoopEventManager.NEW_EVENT_STATUS.FIRST_ONSET, status);
+        
         AAIGETVnfResponse response = manager.getVnfResponse();
         assertNotNull(response);
         assertNull(manager.getVserverResponse());
@@ -240,7 +252,13 @@ public class ControlLoopEventManagerTest {
         event2.AAI = new HashMap<>();
         event2.AAI.put("generic-vnf.vnf-name", "onsetTwo");
         
-        ControlLoopEventManager.NEW_EVENT_STATUS status = manager.onNewEvent(event2);
+        
+        try {
+            status = manager.onNewEvent(event2);
+        } catch (AAIException e) {
+            logger.warn(e.toString());
+            fail("A&AI Query Failed");
+        }
         assertEquals(ControlLoopEventManager.NEW_EVENT_STATUS.SUBSEQUENT_ONSET, status);
         AAIGETVnfResponse response2 = manager.getVnfResponse();
         assertNotNull(response2);
index e7a3119..1714d3e 100644 (file)
@@ -107,6 +107,16 @@ public class ControlLoopOperationManagerTest {
                        assertNotNull(notification);
                        assertEquals(ControlLoopNotificationType.ACTIVE, notification.notification);
                        
+                       ControlLoopEventManager.NEW_EVENT_STATUS status = null;
+               try {
+                   status = eventManager.onNewEvent(onset);
+               } catch (AAIException e) {
+                   logger.warn(e.toString());
+                   fail("A&AI Query Failed");
+               }
+               assertNotNull(status);
+               assertEquals(ControlLoopEventManager.NEW_EVENT_STATUS.FIRST_ONSET, status);
+                       
                        ControlLoopOperationManager manager = new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
                        logger.debug("{}",manager);
                        //
@@ -226,6 +236,16 @@ public class ControlLoopOperationManagerTest {
                        assertNotNull(notification);
                        assertEquals(ControlLoopNotificationType.ACTIVE, notification.notification);
 
+                       ControlLoopEventManager.NEW_EVENT_STATUS status = null;
+            try {
+                status = eventManager.onNewEvent(onset);
+            } catch (AAIException e) {
+                logger.warn(e.toString());
+                fail("A&AI Query Failed");
+            }
+            assertNotNull(status);
+            assertEquals(ControlLoopEventManager.NEW_EVENT_STATUS.FIRST_ONSET, status);
+                       
                        ControlLoopOperationManager manager = new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
                        //
                        //
index 1a0eb31..8ecc114 100644 (file)
@@ -109,7 +109,7 @@ public class AaiSimulatorJaxRs {
        @Path("/v11/nodes/vservers")
        @Consumes(MediaType.APPLICATION_JSON)
        @Produces("application/json")
-       public String getByVserverName (@QueryParam("vserverName") String vserverName)
+       public String getByVserverName (@QueryParam("vserver-name") String vserverName)
        {
                if ("getFail".equals(vserverName)) {
                        return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"nodes/vservers\",\"Node Not Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}";
index 2f8d861..725e01e 100644 (file)
@@ -294,49 +294,50 @@ rule "${policyName}.EVENT.MANAGER"
     logger.info("{}: {}: event={} manager={} clTimer={}", 
                 $params.getClosedLoopControlName(), drools.getRule().getName(),
                 $event, $manager, $clTimer);
-    //
-    // Check which event this is.
-    //
-    ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
-
-    //
-    // Check what kind of event this is
-    //
-    if (eventStatus == NEW_EVENT_STATUS.SUBSEQUENT_ONSET) {
-        //
-        // We don't care about subsequent onsets
-        //
-        logger.info("{}: {}: subsequent onset", 
-                    $params.getClosedLoopControlName(), drools.getRule().getName());
-        retract($event);
-        return;
-    }
-    if (eventStatus == NEW_EVENT_STATUS.SYNTAX_ERROR) {
-        //
-        // Ignore any bad syntax events
-        //
-        logger.warn("{}: {}: syntax error", 
-                    $params.getClosedLoopControlName(), drools.getRule().getName());
-        retract($event);
-        return;
-    }
-    //
-    // We only want the initial ONSET event in memory,
-    // all the other events need to be retracted to support
-    // cleanup and avoid the other rules being fired for this event.
-    //
-    if (eventStatus != NEW_EVENT_STATUS.FIRST_ONSET) {
-        logger.warn("{}: {}: no first onset", 
-                    $params.getClosedLoopControlName(), drools.getRule().getName());
-        retract($event);
-    }
     
-    logger.debug("{}: {}: target={}", $params.getClosedLoopControlName(), 
-                 drools.getRule().getName(), $event.target);
-    //
-    // Now start seeing if we need to process this event
-    //
     try {
+           //
+           // Check which event this is.
+           //
+           ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
+           //
+           // Check what kind of event this is
+           //
+           if (eventStatus == NEW_EVENT_STATUS.SUBSEQUENT_ONSET) {
+               //
+               // We don't care about subsequent onsets
+               //
+               logger.info("{}: {}: subsequent onset", 
+                           $params.getClosedLoopControlName(), drools.getRule().getName());
+               retract($event);
+               return;
+           }
+           if (eventStatus == NEW_EVENT_STATUS.SYNTAX_ERROR) {
+               //
+               // Ignore any bad syntax events
+               //
+               logger.warn("{}: {}: syntax error", 
+                           $params.getClosedLoopControlName(), drools.getRule().getName());
+               retract($event);
+               return;
+           }
+           //
+           // We only want the initial ONSET event in memory,
+           // all the other events need to be retracted to support
+           // cleanup and avoid the other rules being fired for this event.
+           //
+           if (eventStatus != NEW_EVENT_STATUS.FIRST_ONSET) {
+               logger.warn("{}: {}: no first onset", 
+                           $params.getClosedLoopControlName(), drools.getRule().getName());
+               retract($event);
+           }
+           
+           logger.debug("{}: {}: target={}", $params.getClosedLoopControlName(), 
+                        drools.getRule().getName(), $event.target);
+           //
+           // Now start seeing if we need to process this event
+           //
+
         //
         // Check if this is a Final Event
         //
index aaa40d1..55812f1 100644 (file)
@@ -279,13 +279,7 @@ public class VCPEControlLoopTest implements TopicListener {
             String policyName = notification.policyName;
             if (policyName.endsWith("EVENT")) {
                 logger.debug("Rule Fired: " + notification.policyName);
-                if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-name"))) {
-                       assertEquals(ControlLoopNotificationType.REJECTED, notification.notification);
-                       kieSession.halt();
-                }
-                else {
-                    assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
-                }
+                assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
             }
             else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
                 logger.debug("Rule Fired: " + notification.policyName);
@@ -320,8 +314,14 @@ public class VCPEControlLoopTest implements TopicListener {
             }
             else if (policyName.endsWith("EVENT.MANAGER")) {
                 logger.debug("Rule Fired: " + notification.policyName);
-                assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification));
-                kieSession.halt();
+                if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-name"))) {
+                    assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification);
+                    kieSession.halt();
+                }
+                else {
+                    assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification));
+                    kieSession.halt();
+                }
             }
             else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) {
                 logger.debug("Rule Fired: " + notification.policyName);
index 3e1785d..f7e2c30 100644 (file)
@@ -322,13 +322,7 @@ public class VDNSControlLoopTest implements TopicListener {
             String policyName = notification.policyName;
             if (policyName.endsWith("EVENT")) {
                 logger.debug("Rule Fired: " + notification.policyName);
-                if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-id"))) {
-                       assertEquals(ControlLoopNotificationType.REJECTED, notification.notification);
-                       kieSession.halt();
-                }
-                else {
-                    assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
-                }
+                assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
             }
             else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
                 logger.debug("Rule Fired: " + notification.policyName);
@@ -365,6 +359,9 @@ public class VDNSControlLoopTest implements TopicListener {
                 if ("error".equals(notification.AAI.get("vserver.vserver-name"))) {
                        assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification);
                 }
+                else if ("getFail".equals(notification.AAI.get("vserver.vserver-name"))) {
+                    assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification);
+                }
                 else {
                        assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification));
                 }
index 601eef0..5ef20b5 100644 (file)
@@ -325,13 +325,7 @@ public class VFWControlLoopTest implements TopicListener {
             String policyName = notification.policyName;
             if (policyName.endsWith("EVENT")) {
                 logger.debug("Rule Fired: " + notification.policyName);
-                if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-name"))) {
-                       assertEquals(ControlLoopNotificationType.REJECTED, notification.notification);
-                       kieSession.halt();
-                }
-                else {
-                    assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
-                }
+                assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
             }
             else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
                 logger.debug("Rule Fired: " + notification.policyName);
@@ -370,6 +364,9 @@ public class VFWControlLoopTest implements TopicListener {
                        assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification);
                        assertEquals("Target vnf-id could not be found", notification.message);
                 }
+                else if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-name"))) {
+                    assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification);
+                }
                 else {
                     assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification));
                 }