diff options
author | Max Benjamin <max.benjamin@att.com> | 2020-02-20 14:27:46 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-02-20 14:27:46 +0000 |
commit | b1861dea5628f79ec8728d6f8ed97ea4e6278095 (patch) | |
tree | eb05379110a247158cfe37510bbf5c1c3c556731 /bpmn/so-bpmn-tasks | |
parent | 4ee5be728e9738f4e626ac4bb2a0cdff97cf14ac (diff) | |
parent | 7955aa1d34f6579eb1a1a6064ceba228f0c70594 (diff) |
Merge "Skips the VfModule or VNF Configassign/ConfigDeploy action."
Diffstat (limited to 'bpmn/so-bpmn-tasks')
2 files changed, 318 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java new file mode 100644 index 0000000000..682a0471ee --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Tech Mahindra + * ================================================================================ + * 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 java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.apache.logging.log4j.util.Strings; +import org.onap.so.bpmn.common.BBConstants; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulator; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +@Component +public class SkipCDSBuildingBlockListener implements FlowManipulator { + + @Autowired + private CatalogDbClient catalogDbClient; + + private Set<String> vnfActions = + new HashSet<String>(Arrays.asList("config-assign", "config-deploy", "VnfConfigAssign", "VnfConfigDeploy")); + + private Set<String> vFModuleAction = + new HashSet<String>(Arrays.asList("VfModuleConfigAssign", "VfModuleConfigDeploy")); + + @Override + public boolean shouldRunFor(String currentBBName, boolean isFirst, BuildingBlockExecution execution) { + + return "ControllerExecutionBB".equals(currentBBName); + } + + /** + * Skip the CDS Building block according to the Skip Flag. + * + * @param flowsToExecute - List of ExecuteBuildingBlock object. + * @param execution - BuildingBlockExecution object + * @param currentBB - ExecuteBuildingBlock object + * + */ + @Override + public void run(List<ExecuteBuildingBlock> flowsToExecute, ExecuteBuildingBlock currentBB, + BuildingBlockExecution execution) { + String customizationUUID = currentBB.getBuildingBlock().getKey(); + + if (Strings.isEmpty(customizationUUID)) { + return; + } + + if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VNF") + && containsIgnoreCaseAction(currentBB, vnfActions)) { + List<VnfResourceCustomization> vnfResourceCustomizations = + catalogDbClient.getVnfResourceCustomizationByModelUuid( + currentBB.getRequestDetails().getModelInfo().getModelUuid()); + if (!CollectionUtils.isEmpty(vnfResourceCustomizations)) { + VnfResourceCustomization vrc = catalogDbClient.findVnfResourceCustomizationInList(customizationUUID, + vnfResourceCustomizations); + if (null != vrc) { + boolean skipConfigVNF = vrc.isSkipPostInstConf(); + currentSequenceSkipCheck(execution, skipConfigVNF); + } + + } + } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VFModule") + && containsIgnoreCaseAction(currentBB, vFModuleAction)) { + + VfModuleCustomization vfc = + catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(customizationUUID); + + if (null != vfc) { + boolean skipVfModule = vfc.isSkipPostInstConf(); + currentSequenceSkipCheck(execution, skipVfModule); + } + } + + + } + + private boolean containsIgnoreCaseAction(ExecuteBuildingBlock currentBB, Set<String> actions) { + return actions.stream().filter(action -> action.equalsIgnoreCase(currentBB.getBuildingBlock().getBpmnAction())) + .findFirst().isPresent(); + } + + + private void currentSequenceSkipCheck(BuildingBlockExecution execution, boolean skipModule) { + if (skipModule) { + int currentSequence = execution.getVariable(BBConstants.G_CURRENT_SEQUENCE); + execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, currentSequence + 1); + } + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java new file mode 100644 index 0000000000..fb162f857b --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java @@ -0,0 +1,202 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Tech Mahindra + * ================================================================================ + * 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.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.List; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +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.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class SkipCDSBuildingBlockListenerTest { + + private static final String VNF_SCOPE = "VNF"; + private static final String VF_SCOPE = "VFModule"; + private static final String TEST_MODELUUID = "123456789"; + private static final String VNF_TEST_ACTION = "VnfConfigAssign"; + private static final String VFModule_TEST_ACTION = "VfModuleConfigAssign"; + private static final String MODELCUSTOMIZATIONUUID = "123456789"; + private static final String BBNAME = "ControllerExecutionBB"; + private static final boolean ISFIRST = true; + + private int actual; + private List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>(); + private List<VnfResourceCustomization> vnfResourceCustomization; + private List<VfModuleCustomization> vfModuleCustomization; + private ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock(); + private RequestDetails reqDetail = new RequestDetails(); + private BuildingBlockExecution buildingBlockExecution = new DelegateExecutionImpl(new DelegateExecutionFake()); + private VnfResourceCustomization vnfCust = new VnfResourceCustomization(); + private VfModuleCustomization vfCust = new VfModuleCustomization(); + private BuildingBlock buildingBlock = new BuildingBlock(); + + @InjectMocks + private SkipCDSBuildingBlockListener skipCDSBuildingBlockListener; + @Mock + private CatalogDbClient catalogDbClient; + + @Before + public void before() { + ModelInfo model = new ModelInfo(); + model.setModelUuid(TEST_MODELUUID); + reqDetail.setModelInfo(model); + executeBuildingBlock.setRequestDetails(reqDetail); + } + + @Test + public void testTrigger() { + BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); + skipCDSBuildingBlockListener.shouldRunFor(BBNAME, ISFIRST, execution); + assertEquals("ControllerExecutionBB", BBNAME); + } + + @Test + public void testProcessForVNFToSkipCDSBB() { + // given + setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, 0); + vnfResourceCustomization = getVnfResourceCustomizationList(true); + + when(catalogDbClient.getVnfResourceCustomizationByModelUuid( + executeBuildingBlock.getRequestDetails().getModelInfo().getModelUuid())) + .thenReturn(vnfResourceCustomization); + when(catalogDbClient.findVnfResourceCustomizationInList(executeBuildingBlock.getBuildingBlock().getKey(), + vnfResourceCustomization)).thenReturn(vnfCust); + + // when + skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); + + // then + actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); + assertEquals(1, actual); + + } + + @Test + public void testProcessForVNFNotToSkipCDSBB() { + // given + setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, 0); + vnfResourceCustomization = getVnfResourceCustomizationList(false); + + when(catalogDbClient.getVnfResourceCustomizationByModelUuid( + executeBuildingBlock.getRequestDetails().getModelInfo().getModelUuid())) + .thenReturn(vnfResourceCustomization); + when(catalogDbClient.findVnfResourceCustomizationInList(executeBuildingBlock.getBuildingBlock().getKey(), + vnfResourceCustomization)).thenReturn(vnfCust); + + // when + skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); + + // then + actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); + assertEquals(0, actual); + + } + + + @Test + public void testProcessForVFToSkipCDSBB() { + // given + setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, 0); + vfModuleCustomization = getVfModuleCustomizationList(true); + + when(catalogDbClient + .getVfModuleCustomizationByModelCuztomizationUUID(executeBuildingBlock.getBuildingBlock().getKey())) + .thenReturn(vfCust); + + // when + skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); + + // then + actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); + assertEquals(1, actual); + + } + + @Test + public void testProcessForVFNotToSkipCDSBB() { + // given + setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, 0); + vfModuleCustomization = getVfModuleCustomizationList(false); + + when(catalogDbClient + .getVfModuleCustomizationByModelCuztomizationUUID(executeBuildingBlock.getBuildingBlock().getKey())) + .thenReturn(vfCust); + + // when + skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); + + // then + actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); + assertEquals(0, actual); + + } + + /** + * setting scope action in buildingBlock and BB current sequence in BuildingBlockExecution + * + * @param scope + * @param action + * @param squence + */ + private void setBuildingBlockAndCurrentSequence(String scope, String action, int sequence) { + buildingBlock.setBpmnScope(scope); + buildingBlock.setBpmnAction(action); + buildingBlock.setBpmnFlowName("ControllerExecutionBB"); + buildingBlock.setKey(MODELCUSTOMIZATIONUUID); + executeBuildingBlock.setBuildingBlock(buildingBlock); + buildingBlockExecution.setVariable(BBConstants.G_CURRENT_SEQUENCE, sequence); + + } + + private List<VnfResourceCustomization> getVnfResourceCustomizationList(boolean setSkippost) { + List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>(); + vnfCust.setModelCustomizationUUID(MODELCUSTOMIZATIONUUID); + vnfCust.setSkipPostInstConf(setSkippost); + vnfResourceCustomizations.add(vnfCust); + return vnfResourceCustomizations; + } + + private List<VfModuleCustomization> getVfModuleCustomizationList(boolean setSkippost) { + List<VfModuleCustomization> vfModuleCustomizations = new ArrayList<>(); + vfCust.setModelCustomizationUUID(MODELCUSTOMIZATIONUUID); + vfCust.setSkipPostInstConf(setSkippost); + vfModuleCustomizations.add(vfCust); + return vfModuleCustomizations; + } + +} |