set multi-stage flag in listener to log success 60/91960/1
authorMnushkin, Dmitry <dmitry.mnushkin@att.com>
Wed, 24 Jul 2019 16:44:16 +0000 (12:44 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Wed, 24 Jul 2019 16:44:16 +0000 (12:44 -0400)
set multi-stage flag in listener to log success msg
added post listener for requests db object

Issue-ID: SO-2153
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I4b27cbb69b983bd2f7c0d72c8ebb4d9c43201120

bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/PostCompletionRequestsDbListener.java [new file with mode: 0644]
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/RequestsDbListenerRunner.java [new file with mode: 0644]
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListener.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListenerTest.java [moved from bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipTest.java with 85% similarity]

diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/PostCompletionRequestsDbListener.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/PostCompletionRequestsDbListener.java
new file mode 100644 (file)
index 0000000..f888e53
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.common.listener.db;
+
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+
+public interface PostCompletionRequestsDbListener {
+
+    public boolean shouldRunFor(BuildingBlockExecution execution);
+
+    public void run(InfraActiveRequests request, BuildingBlockExecution execution);
+
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/RequestsDbListenerRunner.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/RequestsDbListenerRunner.java
new file mode 100644 (file)
index 0000000..68cda5c
--- /dev/null
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.common.listener.db;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import javax.annotation.PostConstruct;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.listener.ListenerRunner;
+import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class RequestsDbListenerRunner extends ListenerRunner {
+
+
+    private static Logger logger = LoggerFactory.getLogger(FlowManipulatorListenerRunner.class);
+
+    protected List<PostCompletionRequestsDbListener> postListeners;
+
+    @PostConstruct
+    protected void init() {
+
+        postListeners =
+                new ArrayList<>(Optional.ofNullable(context.getBeansOfType(PostCompletionRequestsDbListener.class))
+                        .orElse(new HashMap<>()).values());
+
+    }
+
+    public void post(InfraActiveRequests request, BuildingBlockExecution execution) {
+
+        List<PostCompletionRequestsDbListener> filtered =
+                filterListeners(postListeners, (item -> item.shouldRunFor(execution)));
+
+        logger.info("Running post request db listeners:\n{}",
+                filtered.stream().map(item -> item.getClass().getName()).collect(Collectors.joining("\n")));
+        filtered.forEach(item -> item.run(request, execution));
+
+    }
+
+}
index a17556f..073dead 100644 (file)
@@ -28,6 +28,7 @@ import javax.persistence.EntityNotFoundException;
 import org.camunda.bpm.engine.delegate.DelegateExecution;
 import org.onap.aai.domain.yang.Vnfc;
 import org.onap.so.bpmn.common.DelegateExecutionImpl;
+import org.onap.so.bpmn.common.listener.db.RequestsDbListenerRunner;
 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
 import org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse;
 import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder;
@@ -81,6 +82,8 @@ public class WorkflowActionBBTasks {
     private CatalogDbClient catalogDbClient;
     @Autowired
     private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
+    @Autowired
+    private RequestsDbListenerRunner requestsDbListener;
 
     public void selectBB(DelegateExecution execution) {
         List<ExecuteBuildingBlock> flowsToExecute =
@@ -225,6 +228,7 @@ public class WorkflowActionBBTasks {
             request.setProgress(Long.valueOf(100));
             request.setRequestStatus("COMPLETE");
             request.setLastModifiedBy("CamundaBPMN");
+            requestsDbListener.post(request, new DelegateExecutionImpl(execution));
             requestDbclient.updateInfraActiveRequests(request);
         } catch (Exception ex) {
             workflowAction.buildAndThrowException(execution, "Error Updating Request Database", ex);
index fd0de08..376a27e 100644 (file)
@@ -24,16 +24,18 @@ import java.util.Collections;
 import java.util.List;
 import org.onap.so.bpmn.common.BBConstants;
 import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.listener.db.PostCompletionRequestsDbListener;
 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulator;
 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
 import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.db.request.beans.InfraActiveRequests;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 @Component
-public class MultiStageSkipListener implements FlowManipulator {
+public class MultiStageSkipListener implements FlowManipulator, PostCompletionRequestsDbListener {
 
     @Autowired
     protected BBInputSetupUtils bbInputSetupUtils;
@@ -41,12 +43,21 @@ public class MultiStageSkipListener implements FlowManipulator {
     @Autowired
     private CatalogDbClient catalogDbClient;
 
+    private static final String G_MULTI_STAGE_DESIGN = "multiStageDesign";
+
     @Override
     public boolean shouldRunFor(String currentBBName, boolean isFirst, BuildingBlockExecution execution) {
         return ((boolean) execution.getVariable(BBConstants.G_ALACARTE)) && "AssignVfModuleBB".equals(currentBBName)
                 && isFirst;
     }
 
+
+    @Override
+    public boolean shouldRunFor(BuildingBlockExecution execution) {
+
+        return (boolean) execution.getVariable(G_MULTI_STAGE_DESIGN);
+    }
+
     @Override
     public void run(List<ExecuteBuildingBlock> flowsToExecute, ExecuteBuildingBlock currentBB,
             BuildingBlockExecution execution) {
@@ -61,10 +72,15 @@ public class MultiStageSkipListener implements FlowManipulator {
                 if (vnfCust != null && vnfCust.getMultiStageDesign() != null
                         && vnfCust.getMultiStageDesign().equalsIgnoreCase("true")) {
                     flowsToExecute.retainAll(Collections.singletonList(currentBB));
+                    execution.setVariable(G_MULTI_STAGE_DESIGN, Boolean.valueOf(vnfCust.getMultiStageDesign()));
                 }
             }
         }
 
     }
 
+    @Override
+    public void run(InfraActiveRequests request, BuildingBlockExecution execution) {
+        request.setFlowStatus("Successfully completed Assign Building Block only due to multi-stage-design VNF");
+    }
 }
@@ -36,16 +36,16 @@ import org.mockito.junit.MockitoJUnitRunner;
 import org.onap.so.bpmn.common.BBConstants;
 import org.onap.so.bpmn.common.BuildingBlockExecution;
 import org.onap.so.bpmn.common.DelegateExecutionImpl;
-import org.onap.so.bpmn.infrastructure.workflow.tasks.listeners.MultiStageSkipListener;
 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
 import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.db.request.beans.InfraActiveRequests;
 
 @RunWith(MockitoJUnitRunner.class)
-public class MultiStageSkipTest {
+public class MultiStageSkipListenerTest {
 
     @Mock
     private CatalogDbClient catalogDbClient;
@@ -71,6 +71,12 @@ public class MultiStageSkipTest {
         assertFalse("should not be triggered",
                 multiStageSkipListener.shouldRunFor("AssignVfModuleBB2", true, execution));
 
+        execution.setVariable("multiStageDesign", true);
+        assertTrue("should be triggered", multiStageSkipListener.shouldRunFor(execution));
+
+        execution.setVariable("multiStageDesign", false);
+        assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor(execution));
+
 
     }
 
@@ -107,6 +113,15 @@ public class MultiStageSkipTest {
         assertEquals("Flows should only have Assign", flowsToExecute.size(), 1);
         assertEquals("Flows should only have Assign", flowsToExecute.get(0).getBuildingBlock().getBpmnFlowName(),
                 "AssignVfModuleBB");
+    }
+
+    @Test
+    public void postCompletionRequestsDbListenerTest() {
+        InfraActiveRequests request = new InfraActiveRequests();
+        BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
+        multiStageSkipListener.run(request, execution);
 
+        assertEquals("Successfully completed Assign Building Block only due to multi-stage-design VNF",
+                request.getFlowStatus());
     }
 }