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.FlowManipulatorListenerRunner;
31 import org.onap.so.bpmn.common.listener.flowmanipulator.PreFlowManipulator;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
33 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
34 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
35 import org.onap.so.db.catalog.beans.Service;
36 import org.onap.so.db.catalog.beans.VfModuleCustomization;
37 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
38 import org.onap.so.db.catalog.client.CatalogDbClient;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.stereotype.Component;
43 import org.springframework.util.CollectionUtils;
46 public class SkipCDSBuildingBlockListener implements PreFlowManipulator {
48 private static Logger logger = LoggerFactory.getLogger(SkipCDSBuildingBlockListener.class);
51 private CatalogDbClient catalogDbClient;
53 private Set<String> vnfActions =
54 new HashSet<String>(Arrays.asList("config-assign", "config-deploy", "VnfConfigAssign", "VnfConfigDeploy"));
56 private Set<String> vFModuleAction =
57 new HashSet<String>(Arrays.asList("VfModuleConfigAssign", "VfModuleConfigDeploy"));
59 private Set<String> pnfActions =
60 new HashSet<>(Arrays.asList("config-assign", "config-deploy", "PnfConfigAssign", "PnfConfigDeploy"));
63 public boolean shouldRunFor(String currentBBName, boolean isFirst, BuildingBlockExecution execution) {
65 return "ControllerExecutionBB".equals(currentBBName);
69 * Skip the CDS Building block according to the Skip Flag.
71 * @param flowsToExecute - List of ExecuteBuildingBlock object.
72 * @param execution - BuildingBlockExecution object
73 * @param currentBB - ExecuteBuildingBlock object
77 public void run(List<ExecuteBuildingBlock> flowsToExecute, ExecuteBuildingBlock currentBB,
78 BuildingBlockExecution execution) {
79 String customizationUUID = currentBB.getBuildingBlock().getKey();
81 if ("SERVICE".equalsIgnoreCase(currentBB.getBuildingBlock().getBpmnScope())) {
82 String modelUUID = currentBB.getRequestDetails().getModelInfo().getModelUuid();
83 Service service = catalogDbClient.getServiceByID(modelUUID);
84 currentSequenceSkipCheck(execution, service.getSkipPostInstConf());
85 } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VNF")
86 && containsIgnoreCaseAction(currentBB, vnfActions)) {
87 List<VnfResourceCustomization> vnfResourceCustomizations =
88 catalogDbClient.getVnfResourceCustomizationByModelUuid(
89 currentBB.getRequestDetails().getModelInfo().getModelUuid());
90 if (!CollectionUtils.isEmpty(vnfResourceCustomizations)) {
91 VnfResourceCustomization vrc = catalogDbClient.findVnfResourceCustomizationInList(customizationUUID,
92 vnfResourceCustomizations);
94 logger.debug("getSkipPostInstConf value: " + vrc.getSkipPostInstConf().booleanValue());
95 boolean skipConfigVNF = vrc.getSkipPostInstConf().booleanValue();
96 currentSequenceSkipCheck(execution, skipConfigVNF);
100 } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VFModule")
101 && containsIgnoreCaseAction(currentBB, vFModuleAction)) {
103 VfModuleCustomization vfc =
104 catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(customizationUUID);
107 logger.debug("getSkipPostInstConf value: " + vfc.getSkipPostInstConf().booleanValue());
108 boolean skipVfModule = vfc.getSkipPostInstConf();
109 currentSequenceSkipCheck(execution, skipVfModule);
112 } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("PNF")
113 && containsIgnoreCaseAction(currentBB, pnfActions)) {
114 PnfResourceCustomization pnfResourceCustomization =
115 catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(customizationUUID);
117 if (null != pnfResourceCustomization) {
118 logger.debug("getSkipPostInstConf value: " + pnfResourceCustomization.getSkipPostInstConf());
119 boolean skipConfigPNF = pnfResourceCustomization.getSkipPostInstConf();
120 currentSequenceSkipCheck(execution, skipConfigPNF);
125 private boolean containsIgnoreCaseAction(ExecuteBuildingBlock currentBB, Set<String> actions) {
126 return actions.stream().filter(action -> action.equalsIgnoreCase(currentBB.getBuildingBlock().getBpmnAction()))
127 .findFirst().isPresent();
131 private void currentSequenceSkipCheck(BuildingBlockExecution execution, boolean skipModule) {
133 int currentSequence = execution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
134 execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, currentSequence + 1);