2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
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;
23 import org.onap.so.bpmn.common.BuildingBlockExecution;
24 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
25 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
26 import org.onap.so.client.exception.BBObjectNotFoundException;
27 import org.onap.so.client.exception.ExceptionBuilder;
28 import org.onap.so.client.exception.OrchestrationStatusValidationException;
29 import org.onap.so.db.catalog.beans.BuildingBlockDetail;
30 import org.onap.so.db.catalog.beans.OrchestrationAction;
31 import org.onap.so.db.catalog.beans.OrchestrationStatus;
32 import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective;
33 import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective;
34 import org.onap.so.db.catalog.beans.ResourceType;
35 import org.onap.so.db.catalog.client.CatalogDbClient;
36 import org.onap.so.logger.MsoLogger;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Component;
41 public class OrchestrationStatusValidator {
42 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, OrchestrationStatusValidator.class);
44 private static final String BUILDING_BLOCK_DETAIL_NOT_FOUND = "Building Block (%s) not set up in Orchestration_Status_Validation table in CatalogDB.";
45 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)";
46 private static final String ORCHESTRATION_VALIDATION_FAIL = "Orchestration Status Validation failed. ResourceType=(%s), TargetAction=(%s), OrchestrationStatus=(%s)";
47 private static final String ORCHESTRATION_STATUS_VALIDATION_RESULT = "orchestrationStatusValidationResult";
48 private static final String ALACARTE = "aLaCarte";
49 private static final String MULTI_STAGE_DESIGN_OFF = "false";
50 private static final String MULTI_STAGE_DESIGN_ON = "true";
54 private ExtractPojosForBB extractPojosForBB;
56 private ExceptionBuilder exceptionBuilder;
58 private CatalogDbClient catalogDbClient;
60 public void validateOrchestrationStatus(BuildingBlockExecution execution) {
62 OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult = execution.getVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT);
64 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, null);
66 boolean aLaCarte = (boolean) execution.getVariable(ALACARTE);
68 String buildingBlockFlowName = execution.getFlowToBeCalled();
70 BuildingBlockDetail buildingBlockDetail = catalogDbClient.getBuildingBlockDetail(buildingBlockFlowName);
72 if (buildingBlockDetail == null) {
73 throw new OrchestrationStatusValidationException(String.format(BUILDING_BLOCK_DETAIL_NOT_FOUND, buildingBlockFlowName));
76 OrchestrationStatus orchestrationStatus = null;
78 switch(buildingBlockDetail.getResourceType()) {
80 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
81 orchestrationStatus = serviceInstance.getOrchestrationStatus();
84 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
85 orchestrationStatus = genericVnf.getOrchestrationStatus();
88 org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
89 orchestrationStatus = vfModule.getOrchestrationStatus();
92 org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
93 orchestrationStatus = volumeGroup.getOrchestrationStatus();
96 org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
97 orchestrationStatus = network.getOrchestrationStatus();
99 case NETWORK_COLLECTION:
100 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInst = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
101 org.onap.so.bpmn.servicedecomposition.bbobjects.Collection networkCollection = serviceInst.getCollection();
102 orchestrationStatus = networkCollection.getOrchestrationStatus();
105 org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID, execution.getLookupMap().get(ResourceKey.CONFIGURATION_ID));
106 orchestrationStatus = configuration.getOrchestrationStatus();
109 //short circuit and exit method
110 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, OrchestrationStatusValidationDirective.VALIDATION_SKIPPED);
113 // can't currently get here, so not tested. Added in case enum is expanded without a change to this code
114 throw new OrchestrationStatusValidationException(String.format(UNKNOWN_RESOURCE_TYPE, buildingBlockFlowName, buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction()));
117 if(orchestrationStatus==null){
118 throw new OrchestrationStatusValidationException("The resource's orchstration status is null. Cannot perform task on a null orchestration status");
120 OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = catalogDbClient.getOrchestrationStatusStateTransitionDirective(buildingBlockDetail.getResourceType(), orchestrationStatus, buildingBlockDetail.getTargetAction());
122 if(aLaCarte && ResourceType.VF_MODULE.equals(buildingBlockDetail.getResourceType()) && OrchestrationAction.CREATE.equals(buildingBlockDetail.getTargetAction()) &&
123 OrchestrationStatus.PENDING_ACTIVATION.equals(orchestrationStatus)) {
124 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
125 orchestrationStatusStateTransitionDirective = processPossibleSecondStageofVfModuleCreate(execution, previousOrchestrationStatusValidationResult,
126 genericVnf, orchestrationStatusStateTransitionDirective);
129 if (orchestrationStatusStateTransitionDirective.getFlowDirective() == OrchestrationStatusValidationDirective.FAIL) {
130 throw new OrchestrationStatusValidationException(String.format(ORCHESTRATION_VALIDATION_FAIL, buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction(), orchestrationStatus));
133 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, orchestrationStatusStateTransitionDirective.getFlowDirective());
134 }catch(BBObjectNotFoundException ex){
135 if(execution.getFlowToBeCalled().contains("Unassign")){
136 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, OrchestrationStatusValidationDirective.SILENT_SUCCESS);
138 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex);
140 }catch (Exception e) {
141 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e);
145 private OrchestrationStatusStateTransitionDirective processPossibleSecondStageofVfModuleCreate(BuildingBlockExecution execution, OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult,
146 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf, OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective) {
147 if (previousOrchestrationStatusValidationResult != null && previousOrchestrationStatusValidationResult.equals(OrchestrationStatusValidationDirective.SILENT_SUCCESS)) {
148 String multiStageDesign = MULTI_STAGE_DESIGN_OFF;
149 if (genericVnf.getModelInfoGenericVnf() != null) {
150 multiStageDesign = genericVnf.getModelInfoGenericVnf().getMultiStageDesign();
152 if (multiStageDesign != null && multiStageDesign.equalsIgnoreCase(MULTI_STAGE_DESIGN_ON)) {
153 orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.CONTINUE);
156 return orchestrationStatusStateTransitionDirective;