Fix Retries for Policies 39/16439/2
authordaniel <dc443y@att.com>
Thu, 28 Sep 2017 15:01:21 +0000 (10:01 -0500)
committerdaniel <dc443y@att.com>
Thu, 28 Sep 2017 15:57:26 +0000 (10:57 -0500)
This applies changes to make retries work properly
for all control loops. The current design was ignoring
the upper bound of the retries and retrying until either
a success or control loop timeout occured. This is now
fixed to only do retries until the limit is reached that
is specified from the policy.

The operation is now started in the GUARD.PERMITTED rule.
I think this is better because it stops Policy from doing
extra processing if there is a guard deny. This is also
needed so that we can properly do retries for all cases.

The notifications sent in GUARD_NOT_YET_QUERIED and
GUARD.RESPONSE are now more informative with the
message specifying the actor and recipe. The not queried
rule has a message stating that we are sending a query
to guard and the guard response message in the guard
response rule specifices the result from guard.

During a retest of vDNS it appeared that the archetype
template was no longer working, this was because there
were changes in the JUnit template that were not
reflected in the archetype template. These were added
to archetype and vDNS is verified to work again.

Another small fix needed was making sure the action for
vCPE is "Restart" instead of "restart". APPC will
reject our request if "Restart" is not sent as the
action.

Issue-ID: POLICY-259
Change-Id: I28dd3c9a629d297b408775a01afadd5c19351e37
Signed-off-by: Daniel Cruz <dc443y@att.com>
12 files changed:
controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java
controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
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/VFCControlLoopTest.java
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java

index 9e63e46..75810c0 100644 (file)
@@ -94,7 +94,8 @@ public class APPCActorServiceProvider implements Actor {
                request.CommonHeader = new CommonHeader();
                request.CommonHeader.RequestID = onset.requestID;
                request.CommonHeader.SubRequestID = operation.subRequestId;
-               request.Action = policy.getRecipe();
+               request.Action = policy.getRecipe().substring(0, 1).toUpperCase() 
+                        + policy.getRecipe().substring(1);
                
                /*
                 * The target vnf-id may not be the same as the source vnf-id
index 9f556fa..4ff1c1d 100644 (file)
@@ -232,7 +232,8 @@ public class AppcLcmActorServiceProvider implements Actor {
          * An action is required for all APPC requests, this will 
          * be the recipe specified in the policy.
          */
-        appcRequest.setAction(policy.getRecipe().toLowerCase());
+        appcRequest.setAction(policy.getRecipe().substring(0, 1).toUpperCase() 
+                + policy.getRecipe().substring(1).toLowerCase());
 
         /*
          * For R1, the payloads will not be required for the Restart, 
index f1df440..63ecd2e 100644 (file)
@@ -157,7 +157,7 @@ public class AppcLcmServiceProviderTest {
 
         /* An action is required and cannot be null */
         assertNotNull(appcRequest.getAction());
-        assertEquals(appcRequest.getAction(), "restart");
+        assertEquals(appcRequest.getAction(), "Restart");
 
         /* Action Identifiers are required and cannot be null */
         assertNotNull(appcRequest.getActionIdentifiers());
index e13352a..590e324 100644 (file)
@@ -346,8 +346,6 @@ public class ControlLoopOperationManager implements Serializable {
                    return null;
                } else if (response instanceof SOResponse) {
                        SOResponse msoResponse = (SOResponse) response;
-                       
-                       Integer operationAttempt = this.attempts;
 
                        switch (msoResponse.httpResponseCode) {
                        case 200:
@@ -355,7 +353,7 @@ public class ControlLoopOperationManager implements Serializable {
                                //
                                // Consider it as success
                                //
-                               this.completeOperation(operationAttempt, msoResponse.httpResponseCode + " Success", PolicyResult.SUCCESS);
+                               this.completeOperation(this.attempts, msoResponse.httpResponseCode + " Success", PolicyResult.SUCCESS);
                                if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
                                        return null;
                                }
@@ -364,23 +362,21 @@ public class ControlLoopOperationManager implements Serializable {
                                //
                                // Consider it as failure
                                //
-                               this.completeOperation(operationAttempt, msoResponse.httpResponseCode + " Failed", PolicyResult.FAILURE);
+                               this.completeOperation(this.attempts, msoResponse.httpResponseCode + " Failed", PolicyResult.FAILURE);
                                if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
                                        return null;
                                }
-                               // increment operation attempts for retries
-                               this.attempts += 1;
                                return PolicyResult.FAILURE;
                        }
 
                } else if (response instanceof VFCResponse) {
                        VFCResponse vfcResponse = (VFCResponse) response;
-                       Integer operationAttempt = this.attempts;
+
                        if (vfcResponse.responseDescriptor.getStatus().equalsIgnoreCase("finished")) {
                                //
                                // Consider it as success
                                //
-                               this.completeOperation(operationAttempt, " Success", PolicyResult.SUCCESS);
+                               this.completeOperation(this.attempts, " Success", PolicyResult.SUCCESS);
                                if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
                                        return null;
                                }
@@ -389,7 +385,7 @@ public class ControlLoopOperationManager implements Serializable {
                                //
                                // Consider it as failure
                                //
-                               this.completeOperation(operationAttempt, " Failed", PolicyResult.FAILURE);
+                               this.completeOperation(this.attempts, " Failed", PolicyResult.FAILURE);
                                if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
                                        return null;
                                }
index 3dc984d..c3bd446 100644 (file)
@@ -515,7 +515,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
                 $params.getClosedLoopControlName(), drools.getRule().getName(),
                 $event, $manager, $operation, $lock);    
 
-    Object request = $operation.getOperationRequest();
+    Object request = $operation.startOperation($event);
     
     if (request != null) {
       logger.debug("{}: {}: starting operation ..", 
@@ -592,18 +592,13 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED"
     logger.info("{}: {}: event={} manager={} operation={} lock={}", 
                 $params.getClosedLoopControlName(), drools.getRule().getName(),
                 $event, $manager, $operation, $lock);
-
-    //
-    // We are starting the operation but the actor won't be contacted until Guard is queried and permitted.
-    //
-    $operation.startOperation($event);
     
     //
     // Sending notification that we are about to query Guard ("DB write - start operation")
     //
     VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
     notification.notification = ControlLoopNotificationType.OPERATION;
-    notification.message = $operation.getOperationMessage();
+    notification.message = "Sending guard query for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe();
     notification.history = $operation.getHistory();
     notification.from = "policy";
     notification.policyName = drools.getRule().getName();
@@ -663,7 +658,7 @@ rule "${policyName}.GUARD.RESPONSE"
         
         
     //we will permit the operation if there was no Guard for it
-    if("Indeterminate".equals($guardResponse.result)){
+    if("Indeterminate".equalsIgnoreCase($guardResponse.result)){
         $guardResponse.result = "Permit";
     }
     
@@ -672,7 +667,7 @@ rule "${policyName}.GUARD.RESPONSE"
     //
     VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
     notification.notification = ControlLoopNotificationType.OPERATION;
-    notification.message = $operation.getOperationMessage($guardResponse.result);
+    notification.message = "Guard result for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe() + " is " + $guardResponse.result;
     notification.history = $operation.getHistory();
     notification.from = "policy";
     notification.policyName = drools.getRule().getName();
@@ -935,7 +930,7 @@ rule "${policyName}.SO.RESPONSE"
         $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID )
         $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() )
         $lock : TargetLock (requestID == $event.requestID)
-        $response : SOResponse( request.requestId == $event.requestID.toString() )  
+        $response : SOResponse( requestReferences.requestId.toString() == $event.requestID.toString() )  
     then
         
     Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
index 03a38e5..6916524 100644 (file)
@@ -487,7 +487,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
                Logger.metrics($lock);
                
 
-               Object request = $operation.getOperationRequest();
+               Object request = $operation.startOperation($event);
                
                if (request != null) {
                        Logger.info("Starting operation");
@@ -561,19 +561,13 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED"
                Logger.metrics($manager);
                Logger.metrics($operation);
                Logger.metrics($lock);
-
-
-               //
-               // We are starting the operation but the actor won't be contacted until Guard is queried and permitted.
-               //
-               $operation.startOperation($event);
                
                //
                // Sending notification that we are about to query Guard ("DB write - start operation")
                //
                VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
                notification.notification = ControlLoopNotificationType.OPERATION;
-               notification.message = $operation.getOperationMessage();
+               notification.message = "Sending guard query for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe();
                notification.history = $operation.getHistory();
                notification.from = "policy";
                notification.policyName = drools.getRule().getName();
@@ -637,7 +631,7 @@ rule "${policyName}.GUARD.RESPONSE"
                
                
                //we will permit the operation if there was no Guard for it
-               if("Indeterminate".equals($guardResponse.result)){
+               if("Indeterminate".equalsIgnoreCase($guardResponse.result)){
                        $guardResponse.result = "Permit";
                }
                
@@ -646,7 +640,7 @@ rule "${policyName}.GUARD.RESPONSE"
                //
                VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
                notification.notification = ControlLoopNotificationType.OPERATION;
-               notification.message = $operation.getOperationMessage($guardResponse.result);
+               notification.message = "Guard result for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe() + " is " + $guardResponse.result;
                notification.history = $operation.getHistory();
                notification.from = "policy";
                notification.policyName = drools.getRule().getName();
index a6a4d3f..77a1ac0 100644 (file)
@@ -76,7 +76,7 @@ public class ControlLoopXacmlGuardTest {
        @BeforeClass
        public static void setPUProp(){
                System.setProperty(OPSHISTPUPROP, "TestOperationsHistoryPU");
-               Util.setTestGuardProps();
+               Util.setGuardProps();
        }
        @AfterClass
        public static void restorePUProp(){
index df10714..66a72bc 100644 (file)
@@ -275,18 +275,26 @@ public final class Util {
         PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
         PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
        }
+       
        public static void setSOProps(){
                PolicyEngine.manager.setEnvironmentProperty("so.url", "http://localhost:6667");
         PolicyEngine.manager.setEnvironmentProperty("so.username", "SO");
         PolicyEngine.manager.setEnvironmentProperty("so.password", "SO");
        }
-       public static void setTestGuardProps(){
+
+       public static void setGuardProps(){
                PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL,         "http://localhost:6669/pdp/api/getDecision");
                PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER,        "python");
                PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS,        "test");
                PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_USER, "python");
                PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_PASS, "test");
                PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_ENV,         "TEST");
+    }
+       
+       public static void setVFCProps() {
+           PolicyEngine.manager.setEnvironmentProperty("vfc.url", "http://localhost:6668");
+        PolicyEngine.manager.setEnvironmentProperty("vfc.username", "VFC");
+        PolicyEngine.manager.setEnvironmentProperty("vfc.password", "VFC");
        }
-
+       
 }
index 9743f88..d43537b 100644 (file)
@@ -45,7 +45,6 @@ import org.onap.policy.controlloop.policy.ControlLoopPolicy;
 import org.onap.policy.controlloop.policy.TargetType;
 import org.onap.policy.drools.http.server.HttpServletServer;
 import org.onap.policy.drools.impl.PolicyEngineJUnitImpl;
-import org.onap.policy.drools.system.PolicyEngine;
 import org.onap.policy.guard.PolicyGuard;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,13 +59,8 @@ public class VCPEControlLoopTest {
     
     static {
         /* Set environment properties */
-        PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
-        PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
-        PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
-        
-        PolicyEngine.manager.setEnvironmentProperty("guard.url", "http://localhost:6669/pdp/api/getDecision");
-        PolicyEngine.manager.setEnvironmentProperty("guard.username", "GUARD");
-        PolicyEngine.manager.setEnvironmentProperty("guard.password", "GUARD");
+        Util.setAAIProps();
+        Util.setGuardProps();
     }
     
     @BeforeClass
@@ -198,7 +192,7 @@ public class VCPEControlLoopTest {
          * See if Guard permits this action, if it does 
          * not then the test should fail
          */
-        if (((VirtualControlLoopNotification)obj).message.contains("Guard result: PERMIT")) {
+        if (((VirtualControlLoopNotification)obj).message.contains("PERMIT")) {
             
             /* 
              * A notification should be sent out of the Policy
index a8a4bf3..0b0cb6d 100644 (file)
@@ -61,6 +61,7 @@ public class VDNSControlLoopTest {
         /* Set environment properties */
         Util.setAAIProps();
         Util.setSOProps();
+        Util.setGuardProps();
     }
     
        @BeforeClass
@@ -68,6 +69,7 @@ public class VDNSControlLoopTest {
                try {
                        Util.buildAaiSim();
                        Util.buildSoSim();
+                       Util.buildGuardSim();
                } catch (Exception e) {
                        fail(e.getMessage());
                }
index a484569..fbe9129 100644 (file)
@@ -59,10 +59,8 @@ public class VFCControlLoopTest {
        static {
            /* Set environment properties */
         Util.setAAIProps();
-        
-        PolicyEngine.manager.setEnvironmentProperty("vfc.url", "http://localhost:6668");
-        PolicyEngine.manager.setEnvironmentProperty("vfc.username", "VFC");
-        PolicyEngine.manager.setEnvironmentProperty("vfc.password", "VFC");
+        Util.setVFCProps();
+        Util.setGuardProps();
        }
        
        @BeforeClass
index a63344d..2569768 100644 (file)
@@ -62,12 +62,14 @@ public class VFWControlLoopTest {
     static {
         /* Set environment properties */
         Util.setAAIProps();
+        Util.setGuardProps();
     }
     
     @BeforeClass
     public static void setUpSimulator() {
         try {
             Util.buildAaiSim();
+            Util.buildGuardSim();
         } catch (Exception e) {
             fail(e.getMessage());
         }
@@ -192,7 +194,7 @@ public class VFWControlLoopTest {
          * See if Guard permits this action, if it does 
          * not then the test should fail
          */
-        if (((VirtualControlLoopNotification)obj).message.contains("Guard result: Permit")) {
+        if (((VirtualControlLoopNotification)obj).message.contains("PERMIT")) {
             
             /*
              * Obtain the ControlLoopNoticiation, it should be of type operation