2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.workflow.tasks;
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
27 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
28 import org.onap.so.client.exception.BBObjectNotFoundException;
29 import org.onap.so.client.exception.ExceptionBuilder;
30 import org.onap.so.client.exception.OrchestrationStatusValidationException;
31 import org.onap.so.db.catalog.beans.BuildingBlockDetail;
32 import org.onap.so.db.catalog.beans.OrchestrationAction;
33 import org.onap.so.db.catalog.beans.OrchestrationStatus;
34 import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective;
35 import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective;
36 import org.onap.so.db.catalog.beans.ResourceType;
37 import org.onap.so.db.catalog.client.CatalogDbClient;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.stereotype.Component;
44 public class OrchestrationStatusValidator {
45 private static final Logger logger = LoggerFactory.getLogger(OrchestrationStatusValidator.class);
47 private static final String BUILDING_BLOCK_DETAIL_NOT_FOUND = "Building Block (%s) not set up in Orchestration_Status_Validation table in CatalogDB.";
48 private static final String UNKNOWN_RESOURCE_TYPE = "Building Block (%s) not set up correctly in Orchestration_Status_Validation table in CatalogDB. ResourceType=(%s), TargetAction=(%s)";
49 private static final String ORCHESTRATION_VALIDATION_FAIL = "Orchestration Status Validation failed. ResourceType=(%s), TargetAction=(%s), OrchestrationStatus=(%s)";
50 private static final String ORCHESTRATION_STATUS_VALIDATION_RESULT = "orchestrationStatusValidationResult";
51 private static final String ALACARTE = "aLaCarte";
52 private static final String MULTI_STAGE_DESIGN_OFF = "false";
53 private static final String MULTI_STAGE_DESIGN_ON = "true";
57 private ExtractPojosForBB extractPojosForBB;
59 private ExceptionBuilder exceptionBuilder;
61 private CatalogDbClient catalogDbClient;
63 public void validateOrchestrationStatus(BuildingBlockExecution execution) {
65 OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult = execution.getVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT);
67 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, null);
69 boolean aLaCarte = (boolean) execution.getVariable(ALACARTE);
71 String buildingBlockFlowName = execution.getFlowToBeCalled();
73 BuildingBlockDetail buildingBlockDetail = catalogDbClient.getBuildingBlockDetail(buildingBlockFlowName);
75 if (buildingBlockDetail == null) {
76 throw new OrchestrationStatusValidationException(String.format(BUILDING_BLOCK_DETAIL_NOT_FOUND, buildingBlockFlowName));
79 OrchestrationStatus orchestrationStatus = null;
81 switch(buildingBlockDetail.getResourceType()) {
83 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
84 orchestrationStatus = serviceInstance.getOrchestrationStatus();
87 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
88 orchestrationStatus = genericVnf.getOrchestrationStatus();
91 org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
92 orchestrationStatus = vfModule.getOrchestrationStatus();
95 org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
96 orchestrationStatus = volumeGroup.getOrchestrationStatus();
99 org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
100 orchestrationStatus = network.getOrchestrationStatus();
102 case NETWORK_COLLECTION:
103 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInst = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
104 org.onap.so.bpmn.servicedecomposition.bbobjects.Collection networkCollection = serviceInst.getCollection();
105 orchestrationStatus = networkCollection.getOrchestrationStatus();
108 org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID, execution.getLookupMap().get(ResourceKey.CONFIGURATION_ID));
109 orchestrationStatus = configuration.getOrchestrationStatus();
112 org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID, execution.getLookupMap().get(ResourceKey.INSTANCE_GROUP_ID));
113 orchestrationStatus = instanceGroup.getOrchestrationStatus();
116 //short circuit and exit method
117 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, OrchestrationStatusValidationDirective.VALIDATION_SKIPPED);
120 // can't currently get here, so not tested. Added in case enum is expanded without a change to this code
121 throw new OrchestrationStatusValidationException(String.format(UNKNOWN_RESOURCE_TYPE, buildingBlockFlowName, buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction()));
124 if(orchestrationStatus==null){
125 throw new OrchestrationStatusValidationException("The resource's orchstration status is null. Cannot perform task on a null orchestration status");
127 OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = catalogDbClient.getOrchestrationStatusStateTransitionDirective(buildingBlockDetail.getResourceType(), orchestrationStatus, buildingBlockDetail.getTargetAction());
129 if(aLaCarte && ResourceType.VF_MODULE.equals(buildingBlockDetail.getResourceType()) && OrchestrationAction.CREATE.equals(buildingBlockDetail.getTargetAction()) &&
130 OrchestrationStatus.PENDING_ACTIVATION.equals(orchestrationStatus)) {
131 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
132 orchestrationStatusStateTransitionDirective = processPossibleSecondStageofVfModuleCreate(execution, previousOrchestrationStatusValidationResult,
133 genericVnf, orchestrationStatusStateTransitionDirective);
136 if (orchestrationStatusStateTransitionDirective.getFlowDirective() == OrchestrationStatusValidationDirective.FAIL) {
137 throw new OrchestrationStatusValidationException(String.format(ORCHESTRATION_VALIDATION_FAIL, buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction(), orchestrationStatus));
140 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, orchestrationStatusStateTransitionDirective.getFlowDirective());
141 }catch(BBObjectNotFoundException ex){
142 if(execution.getFlowToBeCalled().contains("Unassign")){
143 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, OrchestrationStatusValidationDirective.SILENT_SUCCESS);
145 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex);
147 }catch (Exception e) {
148 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e);
152 private OrchestrationStatusStateTransitionDirective processPossibleSecondStageofVfModuleCreate(BuildingBlockExecution execution, OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult,
153 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf, OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective) {
154 if (previousOrchestrationStatusValidationResult != null && previousOrchestrationStatusValidationResult.equals(OrchestrationStatusValidationDirective.SILENT_SUCCESS)) {
155 String multiStageDesign = MULTI_STAGE_DESIGN_OFF;
156 if (genericVnf.getModelInfoGenericVnf() != null) {
157 multiStageDesign = genericVnf.getModelInfoGenericVnf().getMultiStageDesign();
159 if (multiStageDesign != null && multiStageDesign.equalsIgnoreCase(MULTI_STAGE_DESIGN_ON)) {
160 orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.CONTINUE);
163 return orchestrationStatusStateTransitionDirective;