2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Tech Mahindra
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.workflow.tasks.listeners;
23 import java.util.Arrays;
24 import java.util.HashSet;
25 import java.util.List;
27 import org.apache.logging.log4j.util.Strings;
28 import org.onap.so.bpmn.common.BBConstants;
29 import org.onap.so.bpmn.common.BuildingBlockExecution;
30 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulator;
31 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
32 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
33 import org.onap.so.db.catalog.beans.VfModuleCustomization;
34 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
35 import org.onap.so.db.catalog.client.CatalogDbClient;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Component;
38 import org.springframework.util.CollectionUtils;
41 public class SkipCDSBuildingBlockListener implements FlowManipulator {
44 private CatalogDbClient catalogDbClient;
46 private Set<String> vnfActions =
47 new HashSet<String>(Arrays.asList("config-assign", "config-deploy", "VnfConfigAssign", "VnfConfigDeploy"));
49 private Set<String> vFModuleAction =
50 new HashSet<String>(Arrays.asList("VfModuleConfigAssign", "VfModuleConfigDeploy"));
52 private Set<String> pnfActions =
53 new HashSet<>(Arrays.asList("config-assign", "config-deploy", "PnfConfigAssign", "PnfConfigDeploy"));
55 private static final String COMPLETED = "completed";
58 public boolean shouldRunFor(String currentBBName, boolean isFirst, BuildingBlockExecution execution) {
60 return "ControllerExecutionBB".equals(currentBBName);
64 * Skip the CDS Building block according to the Skip Flag.
66 * @param flowsToExecute - List of ExecuteBuildingBlock object.
67 * @param execution - BuildingBlockExecution object
68 * @param currentBB - ExecuteBuildingBlock object
72 public void run(List<ExecuteBuildingBlock> flowsToExecute, ExecuteBuildingBlock currentBB,
73 BuildingBlockExecution execution) {
74 String customizationUUID = currentBB.getBuildingBlock().getKey();
75 int flowsToExecuteSize = flowsToExecute.size();
77 if (Strings.isEmpty(customizationUUID)) {
81 if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VNF")
82 && containsIgnoreCaseAction(currentBB, vnfActions)) {
83 List<VnfResourceCustomization> vnfResourceCustomizations =
84 catalogDbClient.getVnfResourceCustomizationByModelUuid(
85 currentBB.getRequestDetails().getModelInfo().getModelUuid());
86 if (!CollectionUtils.isEmpty(vnfResourceCustomizations)) {
87 VnfResourceCustomization vrc = catalogDbClient.findVnfResourceCustomizationInList(customizationUUID,
88 vnfResourceCustomizations);
90 boolean skipConfigVNF = vrc.isSkipPostInstConf();
91 currentSequenceSkipCheck(execution, skipConfigVNF, flowsToExecuteSize);
95 } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VFModule")
96 && containsIgnoreCaseAction(currentBB, vFModuleAction)) {
98 VfModuleCustomization vfc =
99 catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(customizationUUID);
102 boolean skipVfModule = vfc.isSkipPostInstConf();
103 currentSequenceSkipCheck(execution, skipVfModule, flowsToExecuteSize);
106 } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("PNF")
107 && containsIgnoreCaseAction(currentBB, pnfActions)) {
108 PnfResourceCustomization pnfResourceCustomization =
109 catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(customizationUUID);
111 if (null != pnfResourceCustomization) {
112 boolean skipConfigPNF = pnfResourceCustomization.isSkipPostInstConf();
113 currentSequenceSkipCheck(execution, skipConfigPNF, flowsToExecuteSize);
118 private boolean containsIgnoreCaseAction(ExecuteBuildingBlock currentBB, Set<String> actions) {
119 return actions.stream().filter(action -> action.equalsIgnoreCase(currentBB.getBuildingBlock().getBpmnAction()))
120 .findFirst().isPresent();
124 private void currentSequenceSkipCheck(BuildingBlockExecution execution, boolean skipModule,
125 int flowsToExecuteSize) {
127 int currentSequence = execution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
129 if (currentSequence >= flowsToExecuteSize) {
130 execution.setVariable(COMPLETED, true);
132 execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, currentSequence);