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.onap.so.bpmn.common.BBConstants;
28 import org.onap.so.bpmn.common.BuildingBlockExecution;
29 import org.onap.so.bpmn.common.listener.flowmanipulator.PreFlowManipulator;
30 import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource;
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.Service;
34 import org.onap.so.db.catalog.beans.VfModuleCustomization;
35 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
36 import org.onap.so.db.catalog.client.CatalogDbClient;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
43 public class SkipCDSBuildingBlockListener implements PreFlowManipulator {
45 private static Logger logger = LoggerFactory.getLogger(SkipCDSBuildingBlockListener.class);
48 private CatalogDbClient catalogDbClient;
50 private Set<String> vnfActions = new HashSet<String>(Arrays.asList("config-assign", "config-deploy",
51 "VnfConfigAssign", "VnfConfigDeploy", "config-upgrade-assign", "config-upgrade-deploy"));
53 private Set<String> vFModuleAction =
54 new HashSet<String>(Arrays.asList("VfModuleConfigAssign", "VfModuleConfigDeploy"));
56 private Set<String> pnfActions =
57 new HashSet<>(Arrays.asList("config-assign", "config-deploy", "PnfConfigAssign", "PnfConfigDeploy"));
60 public boolean shouldRunFor(String currentBBName, boolean isFirst, BuildingBlockExecution execution) {
62 return "ControllerExecutionBB".equals(currentBBName);
66 * Skip the CDS Building block according to the Skip Flag.
68 * @param flowsToExecute - List of ExecuteBuildingBlock object.
69 * @param execution - BuildingBlockExecution object
70 * @param currentBB - ExecuteBuildingBlock object
74 public void run(List<ExecuteBuildingBlock> flowsToExecute, ExecuteBuildingBlock currentBB,
75 BuildingBlockExecution execution) {
76 String resourceKey = currentBB.getBuildingBlock().getKey();
77 List<Resource> resources = execution.getVariable("resources");
78 Resource resource = resources.stream().filter(r -> resourceKey.equals(r.getResourceId())).findFirst()
79 .orElseThrow(() -> new IllegalArgumentException("Resource not found for key:" + resourceKey));
81 String scope = currentBB.getBuildingBlock().getBpmnScope();
83 if ("SERVICE".equalsIgnoreCase(scope)) {
84 Service service = catalogDbClient.getServiceByID(resource.getModelVersionId());
85 currentSequenceSkipCheck(execution, service.getSkipPostInstConf());
86 } else if ("VNF".equalsIgnoreCase(scope) && containsIgnoreCaseAction(currentBB, vnfActions)) {
87 VnfResourceCustomization vrc = catalogDbClient
88 .getVnfResourceCustomizationByModelCustomizationUUID(resource.getModelCustomizationId());
90 logger.debug("getSkipPostInstConf value: " + vrc.getSkipPostInstConf());
91 boolean skipConfigVNF = vrc.getSkipPostInstConf();
92 currentSequenceSkipCheck(execution, skipConfigVNF);
94 } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VFModule")
95 && containsIgnoreCaseAction(currentBB, vFModuleAction)) {
96 VfModuleCustomization vfc = catalogDbClient
97 .getVfModuleCustomizationByModelCuztomizationUUID(resource.getModelCustomizationId());
99 logger.debug("getSkipPostInstConf value: " + vfc.getSkipPostInstConf().booleanValue());
100 boolean skipVfModule = vfc.getSkipPostInstConf();
101 currentSequenceSkipCheck(execution, skipVfModule);
103 } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("PNF")
104 && containsIgnoreCaseAction(currentBB, pnfActions)) {
105 PnfResourceCustomization pnfResourceCustomization = catalogDbClient
106 .getPnfResourceCustomizationByModelCustomizationUUID(resource.getModelCustomizationId());
108 if (null != pnfResourceCustomization) {
109 logger.debug("getSkipPostInstConf value: " + pnfResourceCustomization.getSkipPostInstConf());
110 boolean skipConfigPNF = pnfResourceCustomization.getSkipPostInstConf();
111 currentSequenceSkipCheck(execution, skipConfigPNF);
116 private boolean containsIgnoreCaseAction(ExecuteBuildingBlock currentBB, Set<String> actions) {
117 return actions.stream().filter(action -> action.equalsIgnoreCase(currentBB.getBuildingBlock().getBpmnAction()))
118 .findFirst().isPresent();
122 private void currentSequenceSkipCheck(BuildingBlockExecution execution, boolean skipModule) {
124 int currentSequence = execution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
125 execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, currentSequence + 1);