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 =
48 "Building Block (%s) not set up in Orchestration_Status_Validation table in CatalogDB.";
49 private static final String UNKNOWN_RESOURCE_TYPE =
50 "Building Block (%s) not set up correctly in Orchestration_Status_Validation table in CatalogDB. ResourceType=(%s), TargetAction=(%s)";
51 private static final String ORCHESTRATION_VALIDATION_FAIL =
52 "Orchestration Status Validation failed. ResourceType=(%s), TargetAction=(%s), OrchestrationStatus=(%s)";
53 private static final String ORCHESTRATION_STATUS_VALIDATION_RESULT = "orchestrationStatusValidationResult";
54 private static final String ALACARTE = "aLaCarte";
55 private static final String MULTI_STAGE_DESIGN_OFF = "false";
56 private static final String MULTI_STAGE_DESIGN_ON = "true";
60 private ExtractPojosForBB extractPojosForBB;
62 private ExceptionBuilder exceptionBuilder;
64 private CatalogDbClient catalogDbClient;
66 public void validateOrchestrationStatus(BuildingBlockExecution execution) {
68 OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult =
69 execution.getVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT);
71 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, null);
73 boolean aLaCarte = (boolean) execution.getVariable(ALACARTE);
75 String buildingBlockFlowName = execution.getFlowToBeCalled();
77 BuildingBlockDetail buildingBlockDetail = catalogDbClient.getBuildingBlockDetail(buildingBlockFlowName);
79 if (buildingBlockDetail == null) {
80 throw new OrchestrationStatusValidationException(
81 String.format(BUILDING_BLOCK_DETAIL_NOT_FOUND, buildingBlockFlowName));
84 OrchestrationStatus orchestrationStatus = null;
86 switch (buildingBlockDetail.getResourceType()) {
88 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance =
89 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
90 orchestrationStatus = serviceInstance.getOrchestrationStatus();
93 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf =
94 extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
95 orchestrationStatus = genericVnf.getOrchestrationStatus();
98 org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule =
99 extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
100 orchestrationStatus = vfModule.getOrchestrationStatus();
103 org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup =
104 extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
105 orchestrationStatus = volumeGroup.getOrchestrationStatus();
108 org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network =
109 extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
110 orchestrationStatus = network.getOrchestrationStatus();
112 case NETWORK_COLLECTION:
113 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInst =
114 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
115 org.onap.so.bpmn.servicedecomposition.bbobjects.Collection networkCollection =
116 serviceInst.getCollection();
117 orchestrationStatus = networkCollection.getOrchestrationStatus();
120 org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration configuration =
121 extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
122 orchestrationStatus = configuration.getOrchestrationStatus();
125 org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup instanceGroup =
126 extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
127 orchestrationStatus = instanceGroup.getOrchestrationStatus();
130 // short circuit and exit method
131 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT,
132 OrchestrationStatusValidationDirective.VALIDATION_SKIPPED);
135 // can't currently get here, so not tested. Added in case enum is expanded without a change to this
137 throw new OrchestrationStatusValidationException(
138 String.format(UNKNOWN_RESOURCE_TYPE, buildingBlockFlowName,
139 buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction()));
142 if (orchestrationStatus == null) {
143 throw new OrchestrationStatusValidationException(
144 "The resource's orchstration status is null. Cannot perform task on a null orchestration status");
146 OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = catalogDbClient
147 .getOrchestrationStatusStateTransitionDirective(buildingBlockDetail.getResourceType(),
148 orchestrationStatus, buildingBlockDetail.getTargetAction());
150 if (aLaCarte && ResourceType.VF_MODULE.equals(buildingBlockDetail.getResourceType())
151 && OrchestrationAction.CREATE.equals(buildingBlockDetail.getTargetAction())
152 && OrchestrationStatus.PENDING_ACTIVATION.equals(orchestrationStatus)) {
153 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf =
154 extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
155 orchestrationStatusStateTransitionDirective = processPossibleSecondStageofVfModuleCreate(execution,
156 previousOrchestrationStatusValidationResult, genericVnf,
157 orchestrationStatusStateTransitionDirective);
160 if (orchestrationStatusStateTransitionDirective
161 .getFlowDirective() == OrchestrationStatusValidationDirective.FAIL) {
162 throw new OrchestrationStatusValidationException(
163 String.format(ORCHESTRATION_VALIDATION_FAIL, buildingBlockDetail.getResourceType(),
164 buildingBlockDetail.getTargetAction(), orchestrationStatus));
167 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT,
168 orchestrationStatusStateTransitionDirective.getFlowDirective());
169 } catch (BBObjectNotFoundException ex) {
170 if (execution.getFlowToBeCalled().contains("Unassign")) {
171 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT,
172 OrchestrationStatusValidationDirective.SILENT_SUCCESS);
174 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex);
176 } catch (Exception e) {
177 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e);
181 private OrchestrationStatusStateTransitionDirective processPossibleSecondStageofVfModuleCreate(
182 BuildingBlockExecution execution,
183 OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult,
184 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf,
185 OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective) {
186 if (previousOrchestrationStatusValidationResult != null && previousOrchestrationStatusValidationResult
187 .equals(OrchestrationStatusValidationDirective.SILENT_SUCCESS)) {
188 String multiStageDesign = MULTI_STAGE_DESIGN_OFF;
189 if (genericVnf.getModelInfoGenericVnf() != null) {
190 multiStageDesign = genericVnf.getModelInfoGenericVnf().getMultiStageDesign();
192 if (multiStageDesign != null && multiStageDesign.equalsIgnoreCase(MULTI_STAGE_DESIGN_ON)) {
193 orchestrationStatusStateTransitionDirective
194 .setFlowDirective(OrchestrationStatusValidationDirective.CONTINUE);
197 return orchestrationStatusStateTransitionDirective;