From 334ddc139c8c8aa3a8ced93c6057a65ba51c8321 Mon Sep 17 00:00:00 2001
From: Jim Hahn <jrh3@att.com>
Date: Mon, 9 Mar 2020 10:22:29 -0400
Subject: Immediately finish if guard is disabled

Modified the Guard Actor to check the "disabled" flag during
start() instead of waiting until it gets down into startOperationAsync.

Issue-ID: POLICY-1625-guard-disabled
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: Id6ccf506b82504552d6e1f4637ad11e2e41e77e5
---
 .../controlloop/actor/guard/GuardOperation.java    | 26 ++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

(limited to 'models-interactions/model-actors/actor.guard/src/main')

diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
index 431ad3711..b9dfb9eba 100644
--- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
@@ -23,11 +23,13 @@ package org.onap.policy.controlloop.actor.guard;
 import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.controlloop.actorserviceprovider.CallbackManager;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 import org.onap.policy.controlloop.actorserviceprovider.Util;
 import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
@@ -37,6 +39,8 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Guard Operation. The outcome message is set to the guard response. If the guard is
@@ -54,6 +58,7 @@ import org.onap.policy.models.decisions.concepts.DecisionResponse;
  * </dl>
  */
 public class GuardOperation extends HttpOperation<DecisionResponse> {
+    private static final Logger logger = LoggerFactory.getLogger(GuardOperation.class);
 
     // operation name
     public static final String NAME = OperationPartial.GUARD_OPERATION_NAME;
@@ -83,12 +88,25 @@ public class GuardOperation extends HttpOperation<DecisionResponse> {
     }
 
     @Override
-    protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
-        if (config.isDisabled()) {
-            // guard is disabled, thus it is always treated as a success
-            return CompletableFuture.completedFuture(params.makeOutcome());
+    public CompletableFuture<OperationOutcome> start() {
+        if (!config.isDisabled()) {
+            // enabled - do full guard operation
+            return super.start();
         }
 
+        // guard is disabled, thus it is always treated as a success
+        logger.info("{}: guard disabled, always succeeds for {}", getFullName(), params.getRequestId());
+
+        final Executor executor = params.getExecutor();
+        final CallbackManager callbacks = new CallbackManager();
+
+        return CompletableFuture.completedFuture(params.makeOutcome())
+                        .whenCompleteAsync(callbackStarted(callbacks), executor)
+                        .whenCompleteAsync(callbackCompleted(callbacks), executor);
+    }
+
+    @Override
+    protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
         outcome.setSubRequestId(String.valueOf(attempt));
 
         DecisionRequest request = Util.translate(getName(), makeRequest(), DecisionRequest.class);
-- 
cgit 1.2.3-korg