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 MULTI_STAGE_DESIGN_OFF = "false";
49 private static final String MULTI_STAGE_DESIGN_ON = "true";
53 private ExtractPojosForBB extractPojosForBB;
55 private ExceptionBuilder exceptionBuilder;
57 private CatalogDbClient catalogDbClient;
59 public void validateOrchestrationStatus(BuildingBlockExecution execution) {
61 OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult = execution.getVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT);
63 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, null);
65 String buildingBlockFlowName = execution.getFlowToBeCalled();
67 BuildingBlockDetail buildingBlockDetail = catalogDbClient.getBuildingBlockDetail(buildingBlockFlowName);
69 if (buildingBlockDetail == null) {
70 throw new OrchestrationStatusValidationException(String.format(BUILDING_BLOCK_DETAIL_NOT_FOUND, buildingBlockFlowName));
73 OrchestrationStatus orchestrationStatus = null;
75 switch(buildingBlockDetail.getResourceType()) {
77 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
78 orchestrationStatus = serviceInstance.getOrchestrationStatus();
81 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
82 orchestrationStatus = genericVnf.getOrchestrationStatus();
85 org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
86 orchestrationStatus = vfModule.getOrchestrationStatus();
89 org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
90 orchestrationStatus = volumeGroup.getOrchestrationStatus();
93 org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
94 orchestrationStatus = network.getOrchestrationStatus();
96 case NETWORK_COLLECTION:
97 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInst = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
98 org.onap.so.bpmn.servicedecomposition.bbobjects.Collection networkCollection = serviceInst.getCollection();
99 orchestrationStatus = networkCollection.getOrchestrationStatus();
102 org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID, execution.getLookupMap().get(ResourceKey.CONFIGURATION_ID));
103 orchestrationStatus = configuration.getOrchestrationStatus();
106 // can't currently get here, so not tested. Added in case enum is expanded without a change to this code
107 throw new OrchestrationStatusValidationException(String.format(UNKNOWN_RESOURCE_TYPE, buildingBlockFlowName, buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction()));
110 if(orchestrationStatus==null){
111 throw new OrchestrationStatusValidationException("The resource's orchstration status is null. Cannot perform task on a null orchestration status");
113 OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = catalogDbClient.getOrchestrationStatusStateTransitionDirective(buildingBlockDetail.getResourceType(), orchestrationStatus, buildingBlockDetail.getTargetAction());
115 if(ResourceType.VF_MODULE.equals(buildingBlockDetail.getResourceType()) && OrchestrationAction.CREATE.equals(buildingBlockDetail.getTargetAction()) &&
116 OrchestrationStatus.PENDING_ACTIVATION.equals(orchestrationStatus)) {
117 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
118 orchestrationStatusStateTransitionDirective = processPossibleSecondStageofVfModuleCreate(execution, previousOrchestrationStatusValidationResult,
119 genericVnf, orchestrationStatusStateTransitionDirective);
122 if (orchestrationStatusStateTransitionDirective.getFlowDirective() == OrchestrationStatusValidationDirective.FAIL) {
123 throw new OrchestrationStatusValidationException(String.format(ORCHESTRATION_VALIDATION_FAIL, buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction(), orchestrationStatus));
126 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, orchestrationStatusStateTransitionDirective.getFlowDirective());
127 }catch(BBObjectNotFoundException ex){
128 if(execution.getFlowToBeCalled().contains("Unassign")){
129 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, OrchestrationStatusValidationDirective.SILENT_SUCCESS);
131 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex);
133 }catch (Exception e) {
134 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e);
138 private OrchestrationStatusStateTransitionDirective processPossibleSecondStageofVfModuleCreate(BuildingBlockExecution execution, OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult,
139 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf, OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective) {
140 if (previousOrchestrationStatusValidationResult != null && previousOrchestrationStatusValidationResult.equals(OrchestrationStatusValidationDirective.SILENT_SUCCESS)) {
141 String multiStageDesign = "false";
142 if (genericVnf.getModelInfoGenericVnf() != null) {
143 multiStageDesign = genericVnf.getModelInfoGenericVnf().getMultiStageDesign();
145 if (multiStageDesign != null && multiStageDesign.equalsIgnoreCase("true")) {
146 orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.CONTINUE);
149 return orchestrationStatusStateTransitionDirective;