2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.flowspecific.tasks;
23 import java.util.Optional;
24 import org.onap.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
27 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
28 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
29 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
30 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
31 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
32 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
33 import org.onap.so.client.exception.BBObjectNotFoundException;
34 import org.onap.so.client.exception.ExceptionBuilder;
35 import org.onap.so.db.catalog.beans.BBNameSelectionReference;
36 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
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 static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_NAME;
44 import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_VERSION;
48 public class ControllerExecution {
49 private static final Logger logger = LoggerFactory.getLogger(ControllerExecution.class);
50 private static final String CONTROLLER_ACTOR = "actor";
51 private static final String BUILDING_BLOCK = "buildingBlock";
52 private static final String SCOPE = "scope";
53 private static final String ACTION = "action";
54 private static final String BBNAME = "bbName";
55 private static final String MSO_REQUEST_ID = "msoRequestId";
58 private ExceptionBuilder exceptionUtil;
60 private CatalogDbClient catalogDbClient;
62 private ExtractPojosForBB extractPojosForBB;
65 * Setting Controller Actor, Scope and Action Variables in BuildingBlockExecution object
67 * @param execution - BuildingBlockExecution object
69 public void setControllerActorScopeAction(BuildingBlockExecution execution) {
71 ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
72 BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
74 String scope = Optional.ofNullable(buildingBlock.getBpmnScope()).orElseThrow(
75 () -> new NullPointerException("BPMN Scope is NULL in the orchestration_flow_reference table "));
76 String action = Optional.ofNullable(buildingBlock.getBpmnAction()).orElseThrow(
77 () -> new NullPointerException("BPMN Action is NULL in the orchestration_flow_reference table "));
78 String controllerActor;
81 if (String.valueOf(scope).equals("pnf")) {
82 Pnf pnf = getPnf(execution);
83 String pnfModelUUID = pnf.getModelInfoPnf().getModelCustomizationUuid();
84 PnfResourceCustomization pnfResourceCustomization =
85 catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(pnfModelUUID);
87 controllerActor = Optional.ofNullable(pnfResourceCustomization.getControllerActor()).orElse("APPC");
88 execution.setVariable(MSO_REQUEST_ID,
89 execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId());
90 execution.setVariable(PRC_BLUEPRINT_VERSION, pnfResourceCustomization.getBlueprintVersion());
91 execution.setVariable(PRC_BLUEPRINT_NAME, pnfResourceCustomization.getBlueprintName());
92 } else if ("service".equalsIgnoreCase(scope)) {
93 GeneralBuildingBlock gbb = execution.getGeneralBuildingBlock();
94 ModelInfoServiceInstance modelInfoServiceInstance =
95 gbb.getServiceInstance().getModelInfoServiceInstance();
96 controllerActor = Optional.ofNullable(modelInfoServiceInstance.getControllerActor()).orElse("CDS");
98 GenericVnf genericVnf = getGenericVnf(execution);
99 String modelUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
100 VnfResourceCustomization vnfResourceCustomization =
101 catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(modelUuid);
103 controllerActor = Optional.ofNullable(vnfResourceCustomization.getControllerActor()).orElse("APPC");
106 execution.setVariable(SCOPE, scope);
107 execution.setVariable(ACTION, action);
108 execution.setVariable(CONTROLLER_ACTOR, controllerActor);
110 logger.debug("Executing Controller Execution for ControllerActor: {}, Scope: {} , Action: {}",
111 controllerActor, scope, action);
112 } catch (Exception ex) {
113 logger.error("An exception occurred while fetching Controller Actor,Scope and Action ", ex);
114 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
119 * Selecting bbName from BBNameSelectionReference and setting the value in a variable of BuildingBlockExecution
121 * @param execution - BuildingBlockExecution object
123 public void selectBB(BuildingBlockExecution execution) {
126 String controllerActor = execution.getVariable(CONTROLLER_ACTOR);
127 String action = Optional.of((String) execution.getVariable(ACTION)).get();
128 String scope = Optional.of((String) execution.getVariable(SCOPE)).get();
129 BBNameSelectionReference bbNameSelectionReference =
130 catalogDbClient.getBBNameSelectionReference(controllerActor, scope, action);
131 String bbName = bbNameSelectionReference.getBbName();
132 execution.setVariable(BBNAME, bbName);
133 logger.debug(" Executing {} BPMN", bbName);
134 } catch (Exception ex) {
135 logger.error("An exception occurred while getting bbname from catalogdb ", ex);
136 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
142 private Pnf getPnf(BuildingBlockExecution buildingBlockExecution) throws BBObjectNotFoundException {
143 return extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.PNF);
146 private GenericVnf getGenericVnf(BuildingBlockExecution buildingBlockExecution) throws BBObjectNotFoundException {
147 return extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.GENERIC_VNF_ID);