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 java.sql.Timestamp;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Optional;
27 import java.util.UUID;
28 import java.util.stream.Collectors;
29 import javax.persistence.EntityNotFoundException;
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.onap.aai.domain.yang.GenericVnf;
32 import org.onap.aai.domain.yang.InstanceGroup;
33 import org.onap.aai.domain.yang.L3Network;
34 import org.onap.aai.domain.yang.ServiceInstance;
35 import org.onap.aai.domain.yang.VfModule;
36 import org.onap.aai.domain.yang.Vnfc;
37 import org.onap.aai.domain.yang.VolumeGroup;
38 import org.onap.aaiclient.client.aai.entities.Configuration;
39 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
40 import org.onap.so.bpmn.common.DelegateExecutionImpl;
41 import org.onap.so.bpmn.common.listener.db.RequestsDbListenerRunner;
42 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
43 import org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse;
44 import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder;
45 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
46 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
47 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
48 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
49 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
50 import org.onap.so.client.exception.ExceptionBuilder;
51 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
52 import org.onap.so.db.catalog.client.CatalogDbClient;
53 import org.onap.so.db.request.beans.InfraActiveRequests;
54 import org.onap.so.db.request.client.RequestsDbClient;
55 import org.onap.so.serviceinstancebeans.RequestReferences;
56 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.core.env.Environment;
61 import org.springframework.stereotype.Component;
62 import com.fasterxml.jackson.core.JsonProcessingException;
63 import com.fasterxml.jackson.databind.ObjectMapper;
66 public class WorkflowActionBBTasks {
68 private static final String G_CURRENT_SEQUENCE = "gCurrentSequence";
69 private static final String G_REQUEST_ID = "mso-request-id";
70 private static final String G_ALACARTE = "aLaCarte";
71 private static final String G_ACTION = "requestAction";
72 private static final String RETRY_COUNT = "retryCount";
73 private static final String FABRIC_CONFIGURATION = "FabricConfiguration";
74 private static final String ADD_FABRIC_CONFIGURATION_BB = "AddFabricConfigurationBB";
75 private static final String COMPLETED = "completed";
76 private static final String HANDLINGCODE = "handlingCode";
77 private static final String ROLLBACKTOCREATED = "RollbackToCreated";
78 private static final String ROLLBACKTOCREATEDNOCONFIGURATION = "RollbackToCreatedNoConfiguration";
79 private static final String REPLACEINSTANCE = "replaceInstance";
80 private static final String VFMODULE = "VfModule";
81 protected String maxRetries = "mso.rainyDay.maxRetries";
82 private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBTasks.class);
85 private RequestsDbClient requestDbclient;
87 private WorkflowAction workflowAction;
89 private WorkflowActionBBFailure workflowActionBBFailure;
91 private Environment environment;
93 private BBInputSetupUtils bbInputSetupUtils;
95 private CatalogDbClient catalogDbClient;
97 private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
99 private RequestsDbListenerRunner requestsDbListener;
101 public void selectBB(DelegateExecution execution) {
102 List<ExecuteBuildingBlock> flowsToExecute =
103 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
104 execution.setVariable("MacroRollback", false);
106 flowManipulatorListenerRunner.modifyFlows(flowsToExecute, new DelegateExecutionImpl(execution));
107 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
109 ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence);
111 execution.setVariable("buildingBlock", ebb);
113 execution.setVariable(COMPLETED, currentSequence >= flowsToExecute.size());
114 execution.setVariable(G_CURRENT_SEQUENCE, currentSequence);
117 public void updateFlowStatistics(DelegateExecution execution) {
119 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
120 if (currentSequence > 1) {
121 InfraActiveRequests request = this.getUpdatedRequest(execution, currentSequence);
122 requestDbclient.updateInfraActiveRequests(request);
124 } catch (Exception ex) {
126 "Bpmn Flow Statistics was unable to update Request Db with the new completion percentage. Competion percentage may be invalid.",
131 protected InfraActiveRequests getUpdatedRequest(DelegateExecution execution, int currentSequence) {
132 List<ExecuteBuildingBlock> flowsToExecute =
133 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
134 String requestId = (String) execution.getVariable(G_REQUEST_ID);
135 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
136 ExecuteBuildingBlock completedBB = flowsToExecute.get(currentSequence - 2);
137 ExecuteBuildingBlock nextBB = flowsToExecute.get(currentSequence - 1);
138 int completedBBs = currentSequence - 1;
139 int totalBBs = flowsToExecute.size();
140 int remainingBBs = totalBBs - completedBBs;
141 String statusMessage = this.getStatusMessage(completedBB.getBuildingBlock().getBpmnFlowName(),
142 nextBB.getBuildingBlock().getBpmnFlowName(), completedBBs, remainingBBs);
143 Long percentProgress = this.getPercentProgress(completedBBs, totalBBs);
144 request.setFlowStatus(statusMessage);
145 request.setProgress(percentProgress);
146 request.setLastModifiedBy("CamundaBPMN");
150 protected Long getPercentProgress(int completedBBs, int totalBBs) {
151 double ratio = (completedBBs / (totalBBs * 1.0));
152 int percentProgress = (int) (ratio * 95);
153 return (long) (percentProgress + 5);
156 protected String getStatusMessage(String completedBB, String nextBB, int completedBBs, int remainingBBs) {
157 return "Execution of " + completedBB + " has completed successfully, next invoking " + nextBB
158 + " (Execution Path progress: BBs completed = " + completedBBs + "; BBs remaining = " + remainingBBs
162 public void sendSyncAck(DelegateExecution execution) {
163 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
164 final String resourceId = (String) execution.getVariable("resourceId");
165 ServiceInstancesResponse serviceInstancesResponse = new ServiceInstancesResponse();
166 RequestReferences requestRef = new RequestReferences();
167 requestRef.setInstanceId(resourceId);
168 requestRef.setRequestId(requestId);
169 serviceInstancesResponse.setRequestReferences(requestRef);
170 ObjectMapper mapper = new ObjectMapper();
171 String jsonRequest = "";
173 jsonRequest = mapper.writeValueAsString(serviceInstancesResponse);
174 } catch (JsonProcessingException e) {
175 workflowAction.buildAndThrowException(execution,
176 "Could not marshall ServiceInstancesRequest to Json string to respond to API Handler.", e);
178 WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
179 callbackResponse.setStatusCode(200);
180 callbackResponse.setMessage("Success");
181 callbackResponse.setResponse(jsonRequest);
182 String processKey = execution.getProcessEngineServices().getRepositoryService()
183 .getProcessDefinition(execution.getProcessDefinitionId()).getKey();
184 WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId,
186 logger.info("Successfully sent sync ack.");
187 updateInstanceId(execution);
190 public void sendErrorSyncAck(DelegateExecution execution) {
191 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
193 ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
194 String errorMsg = (String) execution.getVariable("WorkflowActionErrorMessage");
195 if (errorMsg == null) {
196 errorMsg = "WorkflowAction failed unexpectedly.";
198 String processKey = exceptionBuilder.getProcessKey(execution);
199 String buildworkflowException =
200 "<aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>"
202 + "</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException>";
203 WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
204 callbackResponse.setStatusCode(500);
205 callbackResponse.setMessage("Fail");
206 callbackResponse.setResponse(buildworkflowException);
207 WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId,
209 execution.setVariable("sentSyncResponse", true);
210 } catch (Exception ex) {
211 logger.error(" Sending Sync Error Activity Failed. {}", ex.getMessage(), ex);
215 public void updateRequestStatusToComplete(DelegateExecution execution) {
217 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
218 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
219 final String action = (String) execution.getVariable(G_ACTION);
220 final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
221 final String resourceName = (String) execution.getVariable("resourceName");
222 String statusMessage = (String) execution.getVariable("StatusMessage");
224 if (statusMessage == null) {
226 macroAction = "ALaCarte-" + resourceName + "-" + action + " request was executed correctly.";
228 macroAction = "Macro-" + resourceName + "-" + action + " request was executed correctly.";
231 macroAction = statusMessage;
233 execution.setVariable("finalStatusMessage", macroAction);
234 Timestamp endTime = new Timestamp(System.currentTimeMillis());
235 request.setEndTime(endTime);
236 request.setFlowStatus("Successfully completed all Building Blocks");
237 request.setStatusMessage(macroAction);
238 request.setProgress(100L);
239 request.setRequestStatus("COMPLETE");
240 request.setLastModifiedBy("CamundaBPMN");
241 requestsDbListener.post(request, new DelegateExecutionImpl(execution));
242 requestDbclient.updateInfraActiveRequests(request);
243 } catch (Exception ex) {
244 workflowAction.buildAndThrowException(execution, "Error Updating Request Database", ex);
248 public void checkRetryStatus(DelegateExecution execution) {
249 String handlingCode = (String) execution.getVariable(HANDLINGCODE);
250 String requestId = (String) execution.getVariable(G_REQUEST_ID);
251 String retryDuration = (String) execution.getVariable("RetryDuration");
252 int retryCount = (int) execution.getVariable(RETRY_COUNT);
255 envMaxRetries = Integer.parseInt(this.environment.getProperty(maxRetries));
256 } catch (Exception ex) {
257 logger.error("Could not read maxRetries from config file. Setting max to 5 retries", ex);
260 int nextCount = retryCount + 1;
261 if ("Retry".equals(handlingCode)) {
262 workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
264 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
265 request.setRetryStatusMessage(
266 "Retry " + nextCount + "/" + envMaxRetries + " will be started in " + retryDuration);
267 requestDbclient.updateInfraActiveRequests(request);
268 } catch (Exception ex) {
269 logger.warn("Failed to update Request Db Infra Active Requests with Retry Status", ex);
271 if (retryCount < envMaxRetries) {
272 int currSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
273 execution.setVariable(G_CURRENT_SEQUENCE, currSequence - 1);
274 execution.setVariable(RETRY_COUNT, nextCount);
276 workflowAction.buildAndThrowException(execution,
277 "Exceeded maximum retries. Ending flow with status Abort");
280 execution.setVariable(RETRY_COUNT, 0);
285 * Rollback will only handle Create/Activate/Assign Macro flows. Execute layer will rollback the flow its currently
288 public void rollbackExecutionPath(DelegateExecution execution) {
289 final String action = (String) execution.getVariable(G_ACTION);
290 final String resourceName = (String) execution.getVariable("resourceName");
291 if (!(boolean) execution.getVariable("isRollback")) {
292 List<ExecuteBuildingBlock> flowsToExecute =
293 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
295 List<ExecuteBuildingBlock> flowsToExecuteChangeBBs = flowsToExecute.stream()
296 .filter(buildingBlock -> buildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change"))
297 .collect(Collectors.toList());
299 List<ExecuteBuildingBlock> rollbackFlows = new ArrayList<>();
300 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
301 int listSize = flowsToExecute.size();
303 for (int i = listSize - 1; i >= 0; i--) {
304 if (i > currentSequence - 1) {
305 flowsToExecute.remove(i);
307 String flowName = flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName();
308 if (flowName.startsWith("Assign")) {
309 flowName = flowName.replaceFirst("Assign", "Unassign");
310 } else if (flowName.startsWith("Create")) {
311 flowName = flowName.replaceFirst("Create", "Delete");
312 } else if (flowName.startsWith("Activate")) {
313 flowName = flowName.replaceFirst("Activate", "Deactivate");
314 } else if (flowName.startsWith("Add")) {
315 flowName = flowName.replaceFirst("Add", "Delete");
316 } else if (flowName.startsWith("VNF")) {
317 if (flowName.startsWith("VNFSet")) {
318 flowName = flowName.replaceFirst("VNFSet", "VNFUnset");
319 } else if (flowName.startsWith("VNFLock")) {
320 flowName = flowName.replaceFirst("VNFLock", "VNFUnlock");
321 } else if (flowName.startsWith("VNFStop")) {
322 flowName = flowName.replaceFirst("VNFStop", "VNFStart");
323 } else if (flowName.startsWith("VNFQuiesce")) {
324 flowName = flowName.replaceFirst("VNFQuiesce", "VNFResume");
331 flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName);
332 rollbackFlows.add(flowsToExecute.get(i));
336 String handlingCode = (String) execution.getVariable(HANDLINGCODE);
337 List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>(rollbackFlows);
338 if ("RollbackToAssigned".equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode)
339 || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)) {
340 for (ExecuteBuildingBlock rollbackFlow : rollbackFlows) {
341 if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("Unassign")
342 && !rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")) {
343 rollbackFlowsFiltered.remove(rollbackFlow);
344 } else if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("Delete")
345 && ((!rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")
346 && (ROLLBACKTOCREATED.equals(handlingCode)
347 || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)))
348 || (rollbackFlow.getBuildingBlock().getBpmnFlowName()
349 .contains("FabricConfiguration")
350 && ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)))) {
351 rollbackFlowsFiltered.remove(rollbackFlow);
356 List<ExecuteBuildingBlock> rollbackFlowsFilteredNonChangeBBs = new ArrayList<>();
357 if (action.equals(REPLACEINSTANCE) && resourceName.equals(VFMODULE)) {
358 for (ExecuteBuildingBlock executeBuildingBlock : rollbackFlowsFiltered) {
359 if (!executeBuildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change")) {
360 rollbackFlowsFilteredNonChangeBBs.add(executeBuildingBlock);
363 rollbackFlowsFiltered.clear();
364 rollbackFlowsFiltered.addAll(flowsToExecuteChangeBBs);
365 rollbackFlowsFiltered.addAll(rollbackFlowsFilteredNonChangeBBs);
368 workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
369 execution.setVariable("isRollbackNeeded", !rollbackFlows.isEmpty());
370 execution.setVariable("flowsToExecute", rollbackFlowsFiltered);
371 execution.setVariable(HANDLINGCODE, "PreformingRollback");
372 execution.setVariable("isRollback", true);
373 execution.setVariable(G_CURRENT_SEQUENCE, 0);
374 execution.setVariable(RETRY_COUNT, 0);
376 workflowAction.buildAndThrowException(execution,
377 "Rollback has already been called. Cannot rollback a request that is currently in the rollback state.");
381 protected void updateInstanceId(DelegateExecution execution) {
383 String requestId = (String) execution.getVariable(G_REQUEST_ID);
384 String resourceId = (String) execution.getVariable("resourceId");
385 WorkflowType resourceType = (WorkflowType) execution.getVariable("resourceType");
386 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
387 if (resourceType == WorkflowType.SERVICE) {
388 request.setServiceInstanceId(resourceId);
389 } else if (resourceType == WorkflowType.VNF) {
390 request.setVnfId(resourceId);
391 } else if (resourceType == WorkflowType.VFMODULE) {
392 request.setVfModuleId(resourceId);
393 } else if (resourceType == WorkflowType.VOLUMEGROUP) {
394 request.setVolumeGroupId(resourceId);
395 } else if (resourceType == WorkflowType.NETWORK) {
396 request.setNetworkId(resourceId);
397 } else if (resourceType == WorkflowType.CONFIGURATION) {
398 request.setConfigurationId(resourceId);
399 } else if (resourceType == WorkflowType.INSTANCE_GROUP) {
400 request.setInstanceGroupId(resourceId);
402 setInstanceName(resourceId, resourceType, request);
403 request.setLastModifiedBy("CamundaBPMN");
404 requestDbclient.updateInfraActiveRequests(request);
405 } catch (Exception ex) {
406 logger.error("Exception in updateInstanceId", ex);
407 workflowAction.buildAndThrowException(execution, "Failed to update Request db with instanceId");
411 public void postProcessingExecuteBB(DelegateExecution execution) {
412 List<ExecuteBuildingBlock> flowsToExecute =
413 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
414 String handlingCode = (String) execution.getVariable(HANDLINGCODE);
415 final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
416 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
417 String requestAction = (String) execution.getVariable(G_ACTION);
418 ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence - 1);
419 String bbFlowName = ebb.getBuildingBlock().getBpmnFlowName();
420 if ("ActivateVfModuleBB".equalsIgnoreCase(bbFlowName) && aLaCarte && "Success".equalsIgnoreCase(handlingCode)
421 && !(requestAction.equalsIgnoreCase("replaceInstance")
422 || requestAction.equalsIgnoreCase("replaceInstanceRetainAssignments"))) {
423 postProcessingExecuteBBActivateVfModule(execution, ebb, flowsToExecute);
427 protected void postProcessingExecuteBBActivateVfModule(DelegateExecution execution, ExecuteBuildingBlock ebb,
428 List<ExecuteBuildingBlock> flowsToExecute) {
430 String serviceInstanceId = ebb.getWorkflowResourceIds().getServiceInstanceId();
431 String vnfId = ebb.getWorkflowResourceIds().getVnfId();
432 String vfModuleId = ebb.getResourceId();
433 ebb.getWorkflowResourceIds().setVfModuleId(vfModuleId);
434 String serviceModelUUID =
435 bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId).getModelVersionId();
436 String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
437 String vfModuleCustomizationUUID =
438 bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
439 List<Vnfc> vnfcs = workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, Types.VNFC);
440 logger.debug("Vnfc Size: {}", vnfcs.size());
441 for (Vnfc vnfc : vnfcs) {
442 String modelCustomizationId = vnfc.getModelCustomizationId();
443 logger.debug("Processing Vnfc: {}", modelCustomizationId);
444 CvnfcConfigurationCustomization fabricConfig = catalogDbClient.getCvnfcCustomization(serviceModelUUID,
445 vnfCustomizationUUID, vfModuleCustomizationUUID, modelCustomizationId);
446 if (fabricConfig != null && fabricConfig.getConfigurationResource() != null
447 && fabricConfig.getConfigurationResource().getToscaNodeType() != null
448 && fabricConfig.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
449 String configurationId = getConfigurationId(vnfc);
450 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
451 configurationResourceKeys.setCvnfcCustomizationUUID(modelCustomizationId);
452 configurationResourceKeys.setVfModuleCustomizationUUID(vfModuleCustomizationUUID);
453 configurationResourceKeys.setVnfResourceCustomizationUUID(vnfCustomizationUUID);
454 configurationResourceKeys.setVnfcName(vnfc.getVnfcName());
455 ExecuteBuildingBlock addConfigBB = getExecuteBBForConfig(ADD_FABRIC_CONFIGURATION_BB, ebb,
456 configurationId, configurationResourceKeys);
457 flowsToExecute.add(addConfigBB);
458 flowsToExecute.forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}",
459 executeBB.getBuildingBlock().getBpmnFlowName()));
460 execution.setVariable("flowsToExecute", flowsToExecute);
461 execution.setVariable(COMPLETED, false);
463 logger.debug("No cvnfcCustomization found for customizationId: {}", modelCustomizationId);
466 } catch (EntityNotFoundException e) {
467 logger.debug("Will not be running Fabric Config Building Blocks", e);
468 } catch (Exception e) {
469 String errorMessage = "Error occurred in post processing of Vf Module create";
470 execution.setVariable(HANDLINGCODE, ROLLBACKTOCREATED);
471 execution.setVariable("WorkflowActionErrorMessage", errorMessage);
472 logger.error(errorMessage, e);
476 protected String getConfigurationId(Vnfc vnfc) throws Exception {
477 Configuration configuration =
478 workflowAction.getRelatedResourcesInVnfc(vnfc, Configuration.class, Types.CONFIGURATION);
479 if (configuration != null) {
480 return configuration.getConfigurationId();
482 return UUID.randomUUID().toString();
486 protected ExecuteBuildingBlock getExecuteBBForConfig(String bbName, ExecuteBuildingBlock ebb,
487 String configurationId, ConfigurationResourceKeys configurationResourceKeys) {
488 BuildingBlock buildingBlock =
489 new BuildingBlock().setBpmnFlowName(bbName).setMsoId(UUID.randomUUID().toString());
491 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(ebb.getWorkflowResourceIds());
492 workflowResourceIds.setConfigurationId(configurationId);
493 return new ExecuteBuildingBlock().setaLaCarte(ebb.isaLaCarte()).setApiVersion(ebb.getApiVersion())
494 .setRequestAction(ebb.getRequestAction()).setVnfType(ebb.getVnfType()).setRequestId(ebb.getRequestId())
495 .setRequestDetails(ebb.getRequestDetails()).setBuildingBlock(buildingBlock)
496 .setWorkflowResourceIds(workflowResourceIds).setConfigurationResourceKeys(configurationResourceKeys);
499 protected void setInstanceName(String resourceId, WorkflowType resourceType, InfraActiveRequests request) {
500 logger.debug("Setting instanceName in infraActiveRequest");
502 if (resourceType == WorkflowType.SERVICE && request.getServiceInstanceName() == null) {
503 ServiceInstance service = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
504 if (service != null) {
505 request.setServiceInstanceName(service.getServiceInstanceName());
507 } else if (resourceType == WorkflowType.VNF && request.getVnfName() == null) {
508 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(resourceId);
510 request.setVnfName(vnf.getVnfName());
512 } else if (resourceType == WorkflowType.VFMODULE && request.getVfModuleName() == null) {
513 VfModule vfModule = bbInputSetupUtils.getAAIVfModule(request.getVnfId(), resourceId);
514 if (vfModule != null) {
515 request.setVfModuleName(vfModule.getVfModuleName());
517 } else if (resourceType == WorkflowType.VOLUMEGROUP && request.getVolumeGroupName() == null) {
518 Optional<VolumeGroup> volumeGroup =
519 bbInputSetupUtils.getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
520 volumeGroup.ifPresent(group -> request.setVolumeGroupName(group.getVolumeGroupName()));
521 } else if (resourceType == WorkflowType.NETWORK && request.getNetworkName() == null) {
522 L3Network network = bbInputSetupUtils.getAAIL3Network(resourceId);
523 if (network != null) {
524 request.setNetworkName(network.getNetworkName());
526 } else if (resourceType == WorkflowType.CONFIGURATION && request.getConfigurationName() == null) {
527 org.onap.aai.domain.yang.Configuration configuration =
528 bbInputSetupUtils.getAAIConfiguration(resourceId);
529 if (configuration != null) {
530 request.setConfigurationName(configuration.getConfigurationName());
532 } else if (resourceType == WorkflowType.INSTANCE_GROUP && request.getInstanceGroupName() == null) {
533 InstanceGroup instanceGroup = bbInputSetupUtils.getAAIInstanceGroup(resourceId);
534 if (instanceGroup != null) {
535 request.setInstanceGroupName(instanceGroup.getInstanceGroupName());
538 } catch (Exception ex) {
539 logger.error("Exception in setInstanceName", ex);