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";
59 private ExtractPojosForBB extractPojosForBB;
61 private ExceptionBuilder exceptionBuilder;
63 private CatalogDbClient catalogDbClient;
67 * This method validate's the status of the OrchestrationStatus against the buildingBlockDetail ResourceType
71 public void validateOrchestrationStatus(BuildingBlockExecution execution) {
73 OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult =
74 execution.getVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT);
76 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, null);
78 boolean aLaCarte = (boolean) execution.getVariable(ALACARTE);
80 String buildingBlockFlowName = execution.getFlowToBeCalled();
82 BuildingBlockDetail buildingBlockDetail = catalogDbClient.getBuildingBlockDetail(buildingBlockFlowName);
84 if (buildingBlockDetail == null) {
85 throw new OrchestrationStatusValidationException(
86 String.format(BUILDING_BLOCK_DETAIL_NOT_FOUND, buildingBlockFlowName));
89 OrchestrationStatus orchestrationStatus = null;
91 switch (buildingBlockDetail.getResourceType()) {
93 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance =
94 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
95 orchestrationStatus = serviceInstance.getOrchestrationStatus();
98 org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf =
99 extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
100 orchestrationStatus = genericVnf.getOrchestrationStatus();
103 org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule =
104 extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
105 orchestrationStatus = vfModule.getOrchestrationStatus();
108 org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup =
109 extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
110 orchestrationStatus = volumeGroup.getOrchestrationStatus();
113 org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network =
114 extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
115 orchestrationStatus = network.getOrchestrationStatus();
117 case NETWORK_COLLECTION:
118 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInst =
119 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
120 org.onap.so.bpmn.servicedecomposition.bbobjects.Collection networkCollection =
121 serviceInst.getCollection();
122 orchestrationStatus = networkCollection.getOrchestrationStatus();
125 org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration configuration =
126 extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
127 orchestrationStatus = configuration.getOrchestrationStatus();
130 org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup instanceGroup =
131 extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
132 orchestrationStatus = instanceGroup.getOrchestrationStatus();
135 // short circuit and exit method
136 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT,
137 OrchestrationStatusValidationDirective.VALIDATION_SKIPPED);
140 // can't currently get here, so not tested. Added in case enum is expanded
141 // without a change to this
143 throw new OrchestrationStatusValidationException(
144 String.format(UNKNOWN_RESOURCE_TYPE, buildingBlockFlowName,
145 buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction()));
148 if (orchestrationStatus == null) {
149 throw new OrchestrationStatusValidationException(
150 "The resource's orchstration status is null. Cannot perform task on a null orchestration status");
152 OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = catalogDbClient
153 .getOrchestrationStatusStateTransitionDirective(buildingBlockDetail.getResourceType(),
154 orchestrationStatus, buildingBlockDetail.getTargetAction());
156 if (orchestrationStatusStateTransitionDirective
157 .getFlowDirective() == OrchestrationStatusValidationDirective.FAIL) {
158 throw new OrchestrationStatusValidationException(
159 String.format(ORCHESTRATION_VALIDATION_FAIL, buildingBlockDetail.getResourceType(),
160 buildingBlockDetail.getTargetAction(), orchestrationStatus));
163 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT,
164 orchestrationStatusStateTransitionDirective.getFlowDirective());
165 } catch (BBObjectNotFoundException ex) {
167 "Error occurred for bb object notfound in OrchestrationStatusValidator validateOrchestrationStatus ",
169 if (execution.getFlowToBeCalled().contains("Unassign")) {
170 execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT,
171 OrchestrationStatusValidationDirective.SILENT_SUCCESS);
173 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex);
175 } catch (Exception e) {
176 logger.error("Exception occurred", e);
177 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e);