From 8813ba72c340e45f586b71c9ee12382cdecec91f Mon Sep 17 00:00:00 2001 From: "Mnushkin, Dmitry" Date: Wed, 24 Jul 2019 12:44:16 -0400 Subject: set multi-stage flag in listener to log success 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) Change-Id: I4b27cbb69b983bd2f7c0d72c8ebb4d9c43201120 --- .../db/PostCompletionRequestsDbListener.java | 33 ++++++ .../listener/db/RequestsDbListenerRunner.java | 65 +++++++++++ .../workflow/tasks/WorkflowActionBBTasks.java | 4 + .../tasks/listeners/MultiStageSkipListener.java | 18 ++- .../listeners/MultiStageSkipListenerTest.java | 127 +++++++++++++++++++++ .../tasks/listeners/MultiStageSkipTest.java | 112 ------------------ 6 files changed, 246 insertions(+), 113 deletions(-) create mode 100644 bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/PostCompletionRequestsDbListener.java create mode 100644 bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/RequestsDbListenerRunner.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListenerTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipTest.java 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 index 0000000000..f888e5333a --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/PostCompletionRequestsDbListener.java @@ -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 index 0000000000..68cda5c22b --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/RequestsDbListenerRunner.java @@ -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 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 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)); + + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index a17556f091..073dead8b3 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -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 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); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListener.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListener.java index fd0de086ad..376a27e830 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListener.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListener.java @@ -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 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"); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListenerTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListenerTest.java new file mode 100644 index 0000000000..9e2eac416c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListenerTest.java @@ -0,0 +1,127 @@ +/*- + * ============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.infrastructure.workflow.tasks.listeners; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.List; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +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.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 MultiStageSkipListenerTest { + + @Mock + private CatalogDbClient catalogDbClient; + + @Mock + private BBInputSetupUtils bbInputSetupUtils; + + @InjectMocks + private MultiStageSkipListener multiStageSkipListener; + + @Test + public void testTrigger() { + BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); + execution.setVariable(BBConstants.G_ALACARTE, true); + + assertTrue("should be triggered", multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution)); + + execution.setVariable(BBConstants.G_ALACARTE, false); + assertFalse("should not be triggered", + multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution)); + + execution.setVariable(BBConstants.G_ALACARTE, true); + 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)); + + + } + + @Test + public void testProcessMultiStageSkip() { + String vfModuleId = "vfModuleId"; + String vnfId = "vnfId"; + List flowsToExecute = new ArrayList<>(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("serviceInstanceId"); + workflowResourceIds.setVnfId(vnfId); + flowsToExecute.add(new ExecuteBuildingBlock()); + flowsToExecute.add(new ExecuteBuildingBlock()); + flowsToExecute.add(new ExecuteBuildingBlock()); + flowsToExecute.get(0).setResourceId(vfModuleId); + flowsToExecute.get(0).setBuildingBlock(new BuildingBlock()); + flowsToExecute.get(0).getBuildingBlock().setBpmnFlowName("AssignVfModuleBB"); + flowsToExecute.get(0).setWorkflowResourceIds(workflowResourceIds); + BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); + + org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule(); + vfModule.setVfModuleId(vfModuleId); + org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf(); + vnf.setModelCustomizationId("modelCustomizationUUID"); + VnfResourceCustomization vnfCust = new VnfResourceCustomization(); + vnfCust.setModelCustomizationUUID("modelCustomizationUUID"); + vnfCust.setMultiStageDesign("true"); + when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(vnf.getModelCustomizationId())) + .thenReturn(vnfCust); + when(bbInputSetupUtils.getAAIVfModule(eq(vnfId), eq(vfModuleId))).thenReturn(null); + when(bbInputSetupUtils.getAAIGenericVnf(eq(vnfId))).thenReturn(vnf); + + multiStageSkipListener.run(flowsToExecute, flowsToExecute.get(0), execution); + 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()); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipTest.java deleted file mode 100644 index b6f8aafa55..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/*- - * ============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.infrastructure.workflow.tasks.listeners; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.List; -import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -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; - -@RunWith(MockitoJUnitRunner.class) -public class MultiStageSkipTest { - - @Mock - private CatalogDbClient catalogDbClient; - - @Mock - private BBInputSetupUtils bbInputSetupUtils; - - @InjectMocks - private MultiStageSkipListener multiStageSkipListener; - - @Test - public void testTrigger() { - BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); - execution.setVariable(BBConstants.G_ALACARTE, true); - - assertTrue("should be triggered", multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution)); - - execution.setVariable(BBConstants.G_ALACARTE, false); - assertFalse("should not be triggered", - multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution)); - - execution.setVariable(BBConstants.G_ALACARTE, true); - assertFalse("should not be triggered", - multiStageSkipListener.shouldRunFor("AssignVfModuleBB2", true, execution)); - - - } - - @Test - public void testProcessMultiStageSkip() { - String vfModuleId = "vfModuleId"; - String vnfId = "vnfId"; - List flowsToExecute = new ArrayList<>(); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("serviceInstanceId"); - workflowResourceIds.setVnfId(vnfId); - flowsToExecute.add(new ExecuteBuildingBlock()); - flowsToExecute.add(new ExecuteBuildingBlock()); - flowsToExecute.add(new ExecuteBuildingBlock()); - flowsToExecute.get(0).setResourceId(vfModuleId); - flowsToExecute.get(0).setBuildingBlock(new BuildingBlock()); - flowsToExecute.get(0).getBuildingBlock().setBpmnFlowName("AssignVfModuleBB"); - flowsToExecute.get(0).setWorkflowResourceIds(workflowResourceIds); - BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); - - org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule(); - vfModule.setVfModuleId(vfModuleId); - org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf(); - vnf.setModelCustomizationId("modelCustomizationUUID"); - VnfResourceCustomization vnfCust = new VnfResourceCustomization(); - vnfCust.setModelCustomizationUUID("modelCustomizationUUID"); - vnfCust.setMultiStageDesign("true"); - when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(vnf.getModelCustomizationId())) - .thenReturn(vnfCust); - when(bbInputSetupUtils.getAAIVfModule(eq(vnfId), eq(vfModuleId))).thenReturn(null); - when(bbInputSetupUtils.getAAIGenericVnf(eq(vnfId))).thenReturn(vnf); - - multiStageSkipListener.run(flowsToExecute, flowsToExecute.get(0), execution); - assertEquals("Flows should only have Assign", flowsToExecute.size(), 1); - assertEquals("Flows should only have Assign", flowsToExecute.get(0).getBuildingBlock().getBpmnFlowName(), - "AssignVfModuleBB"); - - } -} -- cgit 1.2.3-korg