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.ResourceKey;
30 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
31 import org.onap.so.client.exception.BBObjectNotFoundException;
32 import org.onap.so.client.exception.ExceptionBuilder;
33 import org.onap.so.db.catalog.beans.BBNameSelectionReference;
34 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
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;
41 import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_NAME;
42 import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_VERSION;
46 public class ControllerExecution {
47 private static final Logger logger = LoggerFactory.getLogger(ControllerExecution.class);
48 private static final String CONTROLLER_ACTOR = "actor";
49 private static final String BUILDING_BLOCK = "buildingBlock";
50 private static final String SCOPE = "scope";
51 private static final String ACTION = "action";
52 private static final String BBNAME = "bbName";
53 private static final String MSO_REQUEST_ID = "msoRequestId";
56 private ExceptionBuilder exceptionUtil;
58 private CatalogDbClient catalogDbClient;
60 private ExtractPojosForBB extractPojosForBB;
63 * Setting Controller Actor, Scope and Action Variables in BuildingBlockExecution object
65 * @param execution - BuildingBlockExecution object
67 public void setControllerActorScopeAction(BuildingBlockExecution execution) {
69 ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
70 BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
72 String scope = Optional.ofNullable(buildingBlock.getBpmnScope()).orElseThrow(
73 () -> new NullPointerException("BPMN Scope is NULL in the orchestration_flow_reference table "));
74 String action = Optional.ofNullable(buildingBlock.getBpmnAction()).orElseThrow(
75 () -> new NullPointerException("BPMN Action is NULL in the orchestration_flow_reference table "));
76 String controllerActor;
79 if (String.valueOf(scope).equals("pnf")) {
80 Pnf pnf = getPnf(execution);
81 String pnfModelUUID = pnf.getModelInfoPnf().getModelCustomizationUuid();
82 PnfResourceCustomization pnfResourceCustomization =
83 catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(pnfModelUUID);
85 controllerActor = Optional.ofNullable(pnfResourceCustomization.getControllerActor()).orElse("APPC");
86 execution.setVariable(MSO_REQUEST_ID,
87 execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId());
88 execution.setVariable(PRC_BLUEPRINT_VERSION, pnfResourceCustomization.getBlueprintVersion());
89 execution.setVariable(PRC_BLUEPRINT_NAME, pnfResourceCustomization.getBlueprintName());
91 GenericVnf genericVnf = getGenericVnf(execution);
92 String modelUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
93 VnfResourceCustomization vnfResourceCustomization =
94 catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(modelUuid);
96 controllerActor = Optional.ofNullable(vnfResourceCustomization.getControllerActor()).orElse("APPC");
99 execution.setVariable(SCOPE, scope);
100 execution.setVariable(ACTION, action);
101 execution.setVariable(CONTROLLER_ACTOR, controllerActor);
103 logger.debug("Executing Controller Execution for ControllerActor: {}, Scope: {} , Action: {}",
104 controllerActor, scope, action);
105 } catch (Exception ex) {
106 logger.error("An exception occurred while fetching Controller Actor,Scope and Action ", ex);
107 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
112 * Selecting bbName from BBNameSelectionReference and setting the value in a variable of BuildingBlockExecution
114 * @param execution - BuildingBlockExecution object
116 public void selectBB(BuildingBlockExecution execution) {
119 String controllerActor = execution.getVariable(CONTROLLER_ACTOR);
120 String action = Optional.of((String) execution.getVariable(ACTION)).get();
121 String scope = Optional.of((String) execution.getVariable(SCOPE)).get();
122 BBNameSelectionReference bbNameSelectionReference =
123 catalogDbClient.getBBNameSelectionReference(controllerActor, scope, action);
124 String bbName = bbNameSelectionReference.getBbName();
125 execution.setVariable(BBNAME, bbName);
126 logger.debug(" Executing {} BPMN", bbName);
127 } catch (Exception ex) {
128 logger.error("An exception occurred while getting bbname from catalogdb ", ex);
129 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
135 private Pnf getPnf(BuildingBlockExecution buildingBlockExecution) throws BBObjectNotFoundException {
136 return extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.PNF);
139 private GenericVnf getGenericVnf(BuildingBlockExecution buildingBlockExecution) throws BBObjectNotFoundException {
140 return extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.GENERIC_VNF_ID);