Enable guards in junit tests 85/104185/2
authorJim Hahn <jrh3@att.com>
Mon, 23 Mar 2020 19:49:28 +0000 (15:49 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 23 Mar 2020 21:48:52 +0000 (17:48 -0400)
Flipped the flag(s) to enable guard checks in the various junit
tests for the Usecases and Frankfurt controllers.  Note: the guard
checks use the guard simulator.
Modified new actor code to not include operation history on first
"guard denied" report (i.e., make it work like usecases does).

Issue-ID: POLICY-2434
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I2897da4a0c8fb76fa00cb0f6cf8562c0703005d3

controlloop/common/controller-frankfurt/pom.xml
controlloop/common/controller-frankfurt/src/test/resources/config/event-manager.properties
controlloop/common/controller-usecases/src/test/resources/config/controlloop.properties.environment
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
controlloop/common/eventmanager/src/test/resources/eventService/event-svc-guard-disabled.properties
controlloop/common/eventmanager/src/test/resources/eventService/event-svc-invalid-db.properties
controlloop/common/eventmanager/src/test/resources/eventService/event-svc-with-db.properties
controlloop/common/feature-controlloop-management/src/main/feature/config/event-manager.properties
controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java

index 3951170..078235d 100644 (file)
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <profiles>
index 50f3372..9244fd2 100644 (file)
@@ -29,8 +29,11 @@ operation.history.password=
 # configured and started.  Thus some of them have a "placeholder" property.
 #
 
-actor.service.GUARD.disabled=true
+#actor.service.GUARD.disabled=true
 actor.service.GUARD.clientName=GUARD
+actor.service.GUARD.onapName=my-onap-name
+actor.service.GUARD.onapComponent=my-onap-component
+actor.service.GUARD.onapInstance=my-onap-instance
 actor.service.GUARD.operations.Decision.path=decision
 
 actor.service.AAI.clientName=AAI
@@ -57,7 +60,7 @@ actor.service.CDS.grpcTimeout=10
 actor.service.CDS.operations.xxx.yyy=
 
 actor.service.SDNC.clientName=SDNC
-actor.service.SDNC.path=
+actor.service.SDNC.path=/
 actor.service.SDNC.operations.BandwidthOnDemand.placeholder=
 actor.service.SDNC.operations.Reroute.placeholder=
 
index f5d1c5d..d0b5448 100644 (file)
@@ -2,7 +2,7 @@
 # ============LICENSE_START=======================================================
 # ONAP
 # ================================================================================
-# Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
 # Modifications Copyright (C) 2019 Bell Canada.
 # ================================================================================
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,7 +41,7 @@ pdpx.password=pdpx
 
 guard.url=http://localhost:6669/policy/pdpx/v1/decision
 guard.jdbc.url=jdbc:mariadb://localhost:3306/operationshistory
-guard.disabled=true
+guard.disabled=false
 
 sdnc.url=sdnc
 sdnc.username=sdnc
index b880fd1..156dad7 100644 (file)
@@ -106,6 +106,13 @@ public class ControlLoopOperationManager2 implements Serializable {
 
     private final Deque<Operation> operationHistory = new ConcurrentLinkedDeque<>();
 
+    /**
+     * Set to {@code true} to prevent the last item in {@link #operationHistory} from
+     * being included in the outcome of {@link #getHistory()}. Used when the operation
+     * aborts prematurely due to lock-denied, guard-denied, etc.
+     */
+    private boolean holdLast = false;
+
     /**
      * Queue of outcomes yet to be processed. Outcomes are added to this each time the
      * "start" or "complete" callback is invoked.
@@ -417,6 +424,7 @@ public class ControlLoopOperationManager2 implements Serializable {
             case LOCK_LOST:
             case GUARD_DENIED:
             case CONTROL_LOOP_TIMEOUT:
+                holdLast = false;
                 return false;
             default:
                 break;
@@ -541,8 +549,16 @@ public class ControlLoopOperationManager2 implements Serializable {
      * @return the list of control loop operations
      */
     public List<ControlLoopOperation> getHistory() {
-        return operationHistory.stream().map(Operation::getClOperation).map(ControlLoopOperation::new)
-                        .collect(Collectors.toList());
+        Operation last = (holdLast ? operationHistory.removeLast() : null);
+
+        List<ControlLoopOperation> result = operationHistory.stream().map(Operation::getClOperation)
+                        .map(ControlLoopOperation::new).collect(Collectors.toList());
+
+        if (last != null) {
+            operationHistory.add(last);
+        }
+
+        return result;
     }
 
     /**
@@ -553,6 +569,9 @@ public class ControlLoopOperationManager2 implements Serializable {
      * @param message message to put into the DB
      */
     private void storeFailureInDataBase(OperationOutcome outcome, PolicyResult result, String message) {
+        // don't include this in history yet
+        holdLast = true;
+
         outcome.setActor(actor);
         outcome.setOperation(operation);
         outcome.setMessage(message);
index 65f6c0c..289de44 100644 (file)
@@ -20,4 +20,7 @@
 
 actor.service.GUARD.disabled=true
 actor.service.GUARD.clientName=guard-client
+actor.service.GUARD.onapName=my-onap-name
+actor.service.GUARD.onapComponent=my-onap-component
+actor.service.GUARD.onapInstance=my-onap-instance
 actor.service.GUARD.operations.Decision.path=decide
index 59b0615..09a6fbb 100644 (file)
@@ -20,6 +20,9 @@
 
 #actor.service.GUARD.disabled=true
 actor.service.GUARD.clientName=guard-client
+actor.service.GUARD.onapName=my-onap-name
+actor.service.GUARD.onapComponent=my-onap-component
+actor.service.GUARD.onapInstance=my-onap-instance
 actor.service.GUARD.operations.Decision.path=decide
 
 # purposely missing the URL
index 6e003f6..0fd886b 100644 (file)
@@ -20,6 +20,9 @@
 
 #actor.service.GUARD.disabled=true
 actor.service.GUARD.clientName=guard-client
+actor.service.GUARD.onapName=my-onap-name
+actor.service.GUARD.onapComponent=my-onap-component
+actor.service.GUARD.onapInstance=my-onap-instance
 actor.service.GUARD.operations.Decision.path=decide
 
 operation.history.url=jdbc:h2:mem:EventManagerServicesTest
index 7c90703..2147684 100644 (file)
@@ -32,6 +32,9 @@ operation.history.password=${env:SQL_PASSWORD}
 
 actor.service.GUARD.disabled=${envd:GUARD_DISABLED:false}
 actor.service.GUARD.clientName=GUARD
+actor.service.GUARD.onapName=Policy
+actor.service.GUARD.onapComponent=Drools PDP
+actor.service.GUARD.onapInstance=Frankfurt
 actor.service.GUARD.operations.Decision.path=decision
 
 actor.service.AAI.clientName=AAI
index ed6cd6c..5a5218c 100644 (file)
@@ -1,8 +1,8 @@
 /*-
  * ============LICENSE_START=======================================================
- * guard
+ * ONAP
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -72,7 +72,7 @@ public class PolicyGuardXacmlHelper {
         decisionRequest.setAction("guard");
         Map<String, String> guard = new HashMap<>();
         guard.put("actor", xacmlReq.getActorId());
-        guard.put("recipe", xacmlReq.getOperationId());
+        guard.put("operation", xacmlReq.getOperationId());
         guard.put("target", xacmlReq.getTargetId());
         if (xacmlReq.getClnameId() != null) {
             guard.put("clname", xacmlReq.getClnameId());