Change CLC granularity to CL level. 13/107813/3
authorpramod.jamkhedkar <pramod@research.att.com>
Mon, 18 May 2020 15:27:50 +0000 (11:27 -0400)
committerpramod.jamkhedkar <pramod@research.att.com>
Tue, 19 May 2020 14:34:32 +0000 (10:34 -0400)
Change CLC granularity from target level to CL level. Remove the target
matching for the db query at PIP level.

Issue-ID: POLICY-2573
Change-Id: If9ba1a4d22c3b8bc5dfce0632f7037ad085f6ea6
Signed-off-by: pramod.jamkhedkar <pramod@research.att.com>
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java
applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/SonCoordinationTest.java
applications/guard/src/test/resources/requests/coordination.cl.vPci.node.1.json
applications/guard/src/test/resources/requests/coordination.cl.vSonh.node.1.json

index b269e25..fb018b0 100644 (file)
@@ -90,7 +90,7 @@ public class GetOperationOutcomePip extends StdOnapPip {
         target = getAttribute(pipFinder, PIP_REQUEST_TARGET);
 
         logger.debug("Going to query DB about: clname={}, target={}", clname, target);
-        String outcome = doDatabaseQuery(clname, target);
+        String outcome = doDatabaseQuery(clname);
         logger.debug("Query result is: {}", outcome);
 
         StdMutablePIPResponse pipResponse = new StdMutablePIPResponse();
@@ -102,8 +102,8 @@ public class GetOperationOutcomePip extends StdOnapPip {
         return new StdPIPResponse(pipResponse);
     }
 
-    private String doDatabaseQuery(String clname, String target) {
-        logger.info("Querying operations history for {} {}", clname, target);
+    private String doDatabaseQuery(String clname) {
+        logger.info("Querying operations history for {}", clname);
         //
         // Only can query if we have an EntityManager
         //
@@ -120,11 +120,9 @@ public class GetOperationOutcomePip extends StdOnapPip {
             //
             return em.createQuery("select e.outcome from Dbao e"
                                   + " where e.closedLoopName= ?1"
-                                  + " and e.target= ?2"
                                   + " order by e.endtime desc",
                                   String.class)
                 .setParameter(1, clname)
-                .setParameter(2, target)
                 .setMaxResults(1)
                 .getSingleResult();
         } catch (NoResultException e) {
index e0dc7cd..dcb172e 100644 (file)
@@ -189,13 +189,12 @@ public class GetOperationOutcomePipTest {
         // Use reflection to run getCountFromDB
         //
         Method method = GetOperationOutcomePip.class.getDeclaredMethod("doDatabaseQuery",
-                                                                       String.class,
                                                                        String.class);
         method.setAccessible(true);
         //
         // Test pipEngine
         //
-        String outcome = (String) method.invoke(pipEngine, "testcl1", "testtarget1");
+        String outcome = (String) method.invoke(pipEngine, "testcl1");
         assertThat(outcome).isNull();
         //
         // Insert entry
@@ -204,7 +203,7 @@ public class GetOperationOutcomePipTest {
         //
         // Test pipEngine
         //
-        outcome = (String) method.invoke(pipEngine, "testcl1", "testtarget1");
+        outcome = (String) method.invoke(pipEngine, "testcl1");
         //
         // outcome should be "1"
         //
@@ -214,25 +213,21 @@ public class GetOperationOutcomePipTest {
         //
         insertEntry("testcl1", "testtarget1", "2");
         insertEntry("testcl2", "testtarget2", "3");
-        insertEntry("testcl1", "testtarget2", "4");
         //
         // Test pipEngine
         //
-        outcome = (String) method.invoke(pipEngine, "testcl1", "testtarget1");
+        outcome = (String) method.invoke(pipEngine, "testcl1");
         assertEquals("2", outcome);
 
-        outcome = (String) method.invoke(pipEngine, "testcl2", "testtarget2");
+        outcome = (String) method.invoke(pipEngine, "testcl2");
         assertEquals("3", outcome);
 
-        outcome = (String) method.invoke(pipEngine, "testcl1", "testtarget2");
-        assertEquals("4", outcome);
-
         //
         // Shut it down
         //
         pipEngine.shutdown();
 
-        assertThat(method.invoke(pipEngine, "testcl1", "testtarget2")).isNull();
+        assertThat(method.invoke(pipEngine, "testcl1")).isNull();
     }
 
     private void insertEntry(String cl, String target, String outcome) {
index 2c7ad58..b20c8cc 100644 (file)
@@ -42,6 +42,7 @@ import java.util.stream.Stream;
 import org.apache.commons.io.IOUtils;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardYamlCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -157,15 +158,16 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
         /*
          * Replace function placeholders with appropriate values
          */
-        try (Stream<String> stream = Files.lines(Paths.get(xacmlProtoFilename))) {
-            return stream.map(s -> s.replace("UNIQUE_ID", uniqueId))
-                .map(s -> s.replace("CONTROL_LOOP_ONE", cLOne))
-                .map(s -> s.replace("CONTROL_LOOP_TWO", cLTwo))
-                .collect(Collectors.joining(XacmlPolicyUtils.LINE_SEPARATOR));
-        } catch (IOException e) {
-            throw new ToscaPolicyConversionException(
-                "Error while generating XACML policy for coordination directive", e);
+        String policyXml = ResourceUtils.getResourceAsString(xacmlProtoFilename);
+        if (policyXml == null) {
+            throw new ToscaPolicyConversionException("Error while generating XACML policy for coordination directive");
         }
+        policyXml = policyXml.replace("UNIQUE_ID", uniqueId);
+        policyXml = policyXml.replace("CONTROL_LOOP_ONE", cLOne);
+        policyXml = policyXml.replace("CONTROL_LOOP_TWO", cLTwo);
+
+        return policyXml;
+
     }
 
 }
index 5b62f36..31aced6 100644 (file)
@@ -251,10 +251,6 @@ public class CoordinationTest {
         //
         insertOperationEvent(requestCl1Node1, OPEN);
         //
-        // Try cl2 on node2, cl1 only open on node1: should get permit
-        //
-        requestAndCheckDecision(requestCl2Node2, PERMIT);
-        //
         // Open cl2 on node2
         //
         insertOperationEvent(requestCl2Node2, OPEN);
index e840bb7..fc4c5e6 100644 (file)
@@ -275,7 +275,7 @@ public class SonCoordinationTest {
         //
         Dbao newEntry = new Dbao();
         newEntry.setActor(properties.get("actor").toString());
-        newEntry.setOperation(properties.get("recipe").toString());
+        newEntry.setOperation(properties.get("operation").toString());
         newEntry.setClosedLoopName(properties.get("clname").toString());
         newEntry.setOutcome(outcome);
         newEntry.setStarttime(Date.from(Instant.now().minusMillis(20000)));
index 22e710b..d6a48c7 100644 (file)
@@ -7,7 +7,7 @@
     "resource": {
         "guard": {
             "actor": "SDNR",
-            "recipe": "ModifyConfig",
+            "operation": "ModifyConfig",
             "clname": "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459",
             "target": "node1"
         }
index 5846da3..10f2bc1 100644 (file)
@@ -7,7 +7,7 @@
     "resource": {
         "guard": {
             "actor": "SDNR",
-            "recipe": "ModifyConfigANR",
+            "operation": "ModifyConfigANR",
             "clname": "ControlLoop-vSONH-7d4baf04-8875-4d1f-946d-06b874048b61",
             "target": "node1"
         }