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 } catch (NullPointerException ex) {
108 workflowAction.buildAndThrowException(execution, "Error in FlowManipulator Modify Flows", ex);
110 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
112 ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence);
114 execution.setVariable("buildingBlock", ebb);
116 execution.setVariable(COMPLETED, currentSequence >= flowsToExecute.size());
117 execution.setVariable(G_CURRENT_SEQUENCE, currentSequence);
120 public void updateFlowStatistics(DelegateExecution execution) {
122 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
123 if (currentSequence > 1) {
124 InfraActiveRequests request = this.getUpdatedRequest(execution, currentSequence);
125 requestDbclient.updateInfraActiveRequests(request);
127 } catch (Exception ex) {
129 "Bpmn Flow Statistics was unable to update Request Db with the new completion percentage. Competion percentage may be invalid.",
134 protected InfraActiveRequests getUpdatedRequest(DelegateExecution execution, int currentSequence) {
135 List<ExecuteBuildingBlock> flowsToExecute =
136 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
137 String requestId = (String) execution.getVariable(G_REQUEST_ID);
138 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
139 ExecuteBuildingBlock completedBB = flowsToExecute.get(currentSequence - 2);
140 ExecuteBuildingBlock nextBB = flowsToExecute.get(currentSequence - 1);
141 int completedBBs = currentSequence - 1;
142 int totalBBs = flowsToExecute.size();
143 int remainingBBs = totalBBs - completedBBs;
144 String statusMessage = this.getStatusMessage(completedBB.getBuildingBlock().getBpmnFlowName(),
145 nextBB.getBuildingBlock().getBpmnFlowName(), completedBBs, remainingBBs);
146 Long percentProgress = this.getPercentProgress(completedBBs, totalBBs);
147 request.setFlowStatus(statusMessage);
148 request.setProgress(percentProgress);
149 request.setLastModifiedBy("CamundaBPMN");
153 protected Long getPercentProgress(int completedBBs, int totalBBs) {
154 double ratio = (completedBBs / (totalBBs * 1.0));
155 int percentProgress = (int) (ratio * 95);
156 return (long) (percentProgress + 5);
159 protected String getStatusMessage(String completedBB, String nextBB, int completedBBs, int remainingBBs) {
160 return "Execution of " + completedBB + " has completed successfully, next invoking " + nextBB
161 + " (Execution Path progress: BBs completed = " + completedBBs + "; BBs remaining = " + remainingBBs
165 public void sendSyncAck(DelegateExecution execution) {
166 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
167 final String resourceId = (String) execution.getVariable("resourceId");
168 ServiceInstancesResponse serviceInstancesResponse = new ServiceInstancesResponse();
169 RequestReferences requestRef = new RequestReferences();
170 requestRef.setInstanceId(resourceId);
171 requestRef.setRequestId(requestId);
172 serviceInstancesResponse.setRequestReferences(requestRef);
173 ObjectMapper mapper = new ObjectMapper();
174 String jsonRequest = "";
176 jsonRequest = mapper.writeValueAsString(serviceInstancesResponse);
177 } catch (JsonProcessingException e) {
178 workflowAction.buildAndThrowException(execution,
179 "Could not marshall ServiceInstancesRequest to Json string to respond to API Handler.", e);
181 WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
182 callbackResponse.setStatusCode(200);
183 callbackResponse.setMessage("Success");
184 callbackResponse.setResponse(jsonRequest);
185 String processKey = execution.getProcessEngineServices().getRepositoryService()
186 .getProcessDefinition(execution.getProcessDefinitionId()).getKey();
187 WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId,
189 logger.info("Successfully sent sync ack.");
190 updateInstanceId(execution);
193 public void sendErrorSyncAck(DelegateExecution execution) {
194 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
196 ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
197 String errorMsg = (String) execution.getVariable("WorkflowActionErrorMessage");
198 if (errorMsg == null) {
199 errorMsg = "WorkflowAction failed unexpectedly.";
201 String processKey = exceptionBuilder.getProcessKey(execution);
202 String buildworkflowException =
203 "<aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>"
205 + "</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException>";
206 WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
207 callbackResponse.setStatusCode(500);
208 callbackResponse.setMessage("Fail");
209 callbackResponse.setResponse(buildworkflowException);
210 WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId,
212 execution.setVariable("sentSyncResponse", true);
213 } catch (Exception ex) {
214 logger.error(" Sending Sync Error Activity Failed. {}", ex.getMessage(), ex);
218 public void updateRequestStatusToComplete(DelegateExecution execution) {
220 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
221 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
222 final String action = (String) execution.getVariable(G_ACTION);
223 final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
224 final String resourceName = (String) execution.getVariable("resourceName");
225 String statusMessage = (String) execution.getVariable("StatusMessage");
227 if (statusMessage == null) {
229 macroAction = "ALaCarte-" + resourceName + "-" + action + " request was executed correctly.";
231 macroAction = "Macro-" + resourceName + "-" + action + " request was executed correctly.";
234 macroAction = statusMessage;
236 execution.setVariable("finalStatusMessage", macroAction);
237 Timestamp endTime = new Timestamp(System.currentTimeMillis());
238 request.setEndTime(endTime);
239 request.setFlowStatus("Successfully completed all Building Blocks");
240 request.setStatusMessage(macroAction);
241 request.setProgress(100L);
242 request.setRequestStatus("COMPLETE");
243 request.setLastModifiedBy("CamundaBPMN");
244 requestsDbListener.post(request, new DelegateExecutionImpl(execution));
245 requestDbclient.updateInfraActiveRequests(request);
246 } catch (Exception ex) {
247 workflowAction.buildAndThrowException(execution, "Error Updating Request Database", ex);
251 public void checkRetryStatus(DelegateExecution execution) {
252 String handlingCode = (String) execution.getVariable(HANDLINGCODE);
253 String requestId = (String) execution.getVariable(G_REQUEST_ID);
254 String retryDuration = (String) execution.getVariable("RetryDuration");
255 int retryCount = (int) execution.getVariable(RETRY_COUNT);
258 envMaxRetries = Integer.parseInt(this.environment.getProperty(maxRetries));
259 } catch (Exception ex) {
260 logger.error("Could not read maxRetries from config file. Setting max to 5 retries", ex);
263 int nextCount = retryCount + 1;
264 if ("Retry".equals(handlingCode)) {
265 workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
267 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
268 request.setRetryStatusMessage(
269 "Retry " + nextCount + "/" + envMaxRetries + " will be started in " + retryDuration);
270 requestDbclient.updateInfraActiveRequests(request);
271 } catch (Exception ex) {
272 logger.warn("Failed to update Request Db Infra Active Requests with Retry Status", ex);
274 if (retryCount < envMaxRetries) {
275 int currSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
276 execution.setVariable(G_CURRENT_SEQUENCE, currSequence - 1);
277 execution.setVariable(RETRY_COUNT, nextCount);
279 workflowAction.buildAndThrowException(execution,
280 "Exceeded maximum retries. Ending flow with status Abort");
283 execution.setVariable(RETRY_COUNT, 0);
288 * Rollback will only handle Create/Activate/Assign Macro flows. Execute layer will rollback the flow its currently
291 public void rollbackExecutionPath(DelegateExecution execution) {
292 final String action = (String) execution.getVariable(G_ACTION);
293 final String resourceName = (String) execution.getVariable("resourceName");
294 if (!(boolean) execution.getVariable("isRollback")) {
295 List<ExecuteBuildingBlock> flowsToExecute =
296 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
298 List<ExecuteBuildingBlock> flowsToExecuteChangeBBs = flowsToExecute.stream()
299 .filter(buildingBlock -> buildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change"))
300 .collect(Collectors.toList());
302 List<ExecuteBuildingBlock> rollbackFlows = new ArrayList<>();
303 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
304 int listSize = flowsToExecute.size();
306 for (int i = listSize - 1; i >= 0; i--) {
307 if (i > currentSequence - 1) {
308 flowsToExecute.remove(i);
310 String flowName = flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName();
311 if (flowName.startsWith("Assign")) {
312 flowName = flowName.replaceFirst("Assign", "Unassign");
313 } else if (flowName.startsWith("Create")) {
314 flowName = flowName.replaceFirst("Create", "Delete");
315 } else if (flowName.startsWith("Activate")) {
316 flowName = flowName.replaceFirst("Activate", "Deactivate");
317 } else if (flowName.startsWith("Add")) {
318 flowName = flowName.replaceFirst("Add", "Delete");
319 } else if (flowName.startsWith("VNF")) {
320 if (flowName.startsWith("VNFSet")) {
321 flowName = flowName.replaceFirst("VNFSet", "VNFUnset");
322 } else if (flowName.startsWith("VNFLock")) {
323 flowName = flowName.replaceFirst("VNFLock", "VNFUnlock");
324 } else if (flowName.startsWith("VNFStop")) {
325 flowName = flowName.replaceFirst("VNFStop", "VNFStart");
326 } else if (flowName.startsWith("VNFQuiesce")) {
327 flowName = flowName.replaceFirst("VNFQuiesce", "VNFResume");
334 flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName);
335 rollbackFlows.add(flowsToExecute.get(i));
339 String handlingCode = (String) execution.getVariable(HANDLINGCODE);
340 List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>(rollbackFlows);
341 if ("RollbackToAssigned".equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode)
342 || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)) {
343 for (ExecuteBuildingBlock rollbackFlow : rollbackFlows) {
344 if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("Unassign")
345 && !rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")) {
346 rollbackFlowsFiltered.remove(rollbackFlow);
347 } else if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("Delete")
348 && ((!rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")
349 && (ROLLBACKTOCREATED.equals(handlingCode)
350 || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)))
351 || (rollbackFlow.getBuildingBlock().getBpmnFlowName()
352 .contains("FabricConfiguration")
353 && ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)))) {
354 rollbackFlowsFiltered.remove(rollbackFlow);
359 List<ExecuteBuildingBlock> rollbackFlowsFilteredNonChangeBBs = new ArrayList<>();
360 if (action.equals(REPLACEINSTANCE) && resourceName.equals(VFMODULE)) {
361 for (ExecuteBuildingBlock executeBuildingBlock : rollbackFlowsFiltered) {
362 if (!executeBuildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change")) {
363 rollbackFlowsFilteredNonChangeBBs.add(executeBuildingBlock);
366 rollbackFlowsFiltered.clear();
367 rollbackFlowsFiltered.addAll(flowsToExecuteChangeBBs);
368 rollbackFlowsFiltered.addAll(rollbackFlowsFilteredNonChangeBBs);
371 workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
372 execution.setVariable("isRollbackNeeded", !rollbackFlows.isEmpty());
373 execution.setVariable("flowsToExecute", rollbackFlowsFiltered);
374 execution.setVariable(HANDLINGCODE, "PreformingRollback");
375 execution.setVariable("isRollback", true);
376 execution.setVariable(G_CURRENT_SEQUENCE, 0);
377 execution.setVariable(RETRY_COUNT, 0);
379 workflowAction.buildAndThrowException(execution,
380 "Rollback has already been called. Cannot rollback a request that is currently in the rollback state.");
384 protected void updateInstanceId(DelegateExecution execution) {
386 String requestId = (String) execution.getVariable(G_REQUEST_ID);
387 String resourceId = (String) execution.getVariable("resourceId");
388 WorkflowType resourceType = (WorkflowType) execution.getVariable("resourceType");
389 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
390 if (resourceType == WorkflowType.SERVICE) {
391 request.setServiceInstanceId(resourceId);
392 } else if (resourceType == WorkflowType.VNF) {
393 request.setVnfId(resourceId);
394 } else if (resourceType == WorkflowType.VFMODULE) {
395 request.setVfModuleId(resourceId);
396 } else if (resourceType == WorkflowType.VOLUMEGROUP) {
397 request.setVolumeGroupId(resourceId);
398 } else if (resourceType == WorkflowType.NETWORK) {
399 request.setNetworkId(resourceId);
400 } else if (resourceType == WorkflowType.CONFIGURATION) {
401 request.setConfigurationId(resourceId);
402 } else if (resourceType == WorkflowType.INSTANCE_GROUP) {
403 request.setInstanceGroupId(resourceId);
405 setInstanceName(resourceId, resourceType, request);
406 request.setLastModifiedBy("CamundaBPMN");
407 requestDbclient.updateInfraActiveRequests(request);
408 } catch (Exception ex) {
409 logger.error("Exception in updateInstanceId", ex);
410 workflowAction.buildAndThrowException(execution, "Failed to update Request db with instanceId");
414 public void postProcessingExecuteBB(DelegateExecution execution) {
415 List<ExecuteBuildingBlock> flowsToExecute =
416 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
417 String handlingCode = (String) execution.getVariable(HANDLINGCODE);
418 final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
419 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
420 String requestAction = (String) execution.getVariable(G_ACTION);
421 ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence - 1);
422 String bbFlowName = ebb.getBuildingBlock().getBpmnFlowName();
423 if ("ActivateVfModuleBB".equalsIgnoreCase(bbFlowName) && aLaCarte && "Success".equalsIgnoreCase(handlingCode)
424 && !(requestAction.equalsIgnoreCase("replaceInstance")
425 || requestAction.equalsIgnoreCase("replaceInstanceRetainAssignments"))) {
426 postProcessingExecuteBBActivateVfModule(execution, ebb, flowsToExecute);
430 protected void postProcessingExecuteBBActivateVfModule(DelegateExecution execution, ExecuteBuildingBlock ebb,
431 List<ExecuteBuildingBlock> flowsToExecute) {
433 String serviceInstanceId = ebb.getWorkflowResourceIds().getServiceInstanceId();
434 String vnfId = ebb.getWorkflowResourceIds().getVnfId();
435 String vfModuleId = ebb.getResourceId();
436 ebb.getWorkflowResourceIds().setVfModuleId(vfModuleId);
437 String serviceModelUUID =
438 bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId).getModelVersionId();
439 String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
440 String vfModuleCustomizationUUID =
441 bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
442 List<Vnfc> vnfcs = workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, Types.VNFC);
443 logger.debug("Vnfc Size: {}", vnfcs.size());
444 for (Vnfc vnfc : vnfcs) {
445 String modelCustomizationId = vnfc.getModelCustomizationId();
446 logger.debug("Processing Vnfc: {}", modelCustomizationId);
447 CvnfcConfigurationCustomization fabricConfig = catalogDbClient.getCvnfcCustomization(serviceModelUUID,
448 vnfCustomizationUUID, vfModuleCustomizationUUID, modelCustomizationId);
449 if (fabricConfig != null && fabricConfig.getConfigurationResource() != null
450 && fabricConfig.getConfigurationResource().getToscaNodeType() != null
451 && fabricConfig.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
452 String configurationId = getConfigurationId(vnfc);
453 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
454 configurationResourceKeys.setCvnfcCustomizationUUID(modelCustomizationId);
455 configurationResourceKeys.setVfModuleCustomizationUUID(vfModuleCustomizationUUID);
456 configurationResourceKeys.setVnfResourceCustomizationUUID(vnfCustomizationUUID);
457 configurationResourceKeys.setVnfcName(vnfc.getVnfcName());
458 ExecuteBuildingBlock addConfigBB = getExecuteBBForConfig(ADD_FABRIC_CONFIGURATION_BB, ebb,
459 configurationId, configurationResourceKeys);
460 flowsToExecute.add(addConfigBB);
461 flowsToExecute.forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}",
462 executeBB.getBuildingBlock().getBpmnFlowName()));
463 execution.setVariable("flowsToExecute", flowsToExecute);
464 execution.setVariable(COMPLETED, false);
466 logger.debug("No cvnfcCustomization found for customizationId: {}", modelCustomizationId);
469 } catch (EntityNotFoundException e) {
470 logger.debug("Will not be running Fabric Config Building Blocks", e);
471 } catch (Exception e) {
472 String errorMessage = "Error occurred in post processing of Vf Module create";
473 execution.setVariable(HANDLINGCODE, ROLLBACKTOCREATED);
474 execution.setVariable("WorkflowActionErrorMessage", errorMessage);
475 logger.error(errorMessage, e);
479 protected String getConfigurationId(Vnfc vnfc) throws Exception {
480 Configuration configuration =
481 workflowAction.getRelatedResourcesInVnfc(vnfc, Configuration.class, Types.CONFIGURATION);
482 if (configuration != null) {
483 return configuration.getConfigurationId();
485 return UUID.randomUUID().toString();
489 protected ExecuteBuildingBlock getExecuteBBForConfig(String bbName, ExecuteBuildingBlock ebb,
490 String configurationId, ConfigurationResourceKeys configurationResourceKeys) {
491 BuildingBlock buildingBlock =
492 new BuildingBlock().setBpmnFlowName(bbName).setMsoId(UUID.randomUUID().toString());
494 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(ebb.getWorkflowResourceIds());
495 workflowResourceIds.setConfigurationId(configurationId);
496 return new ExecuteBuildingBlock().setaLaCarte(ebb.isaLaCarte()).setApiVersion(ebb.getApiVersion())
497 .setRequestAction(ebb.getRequestAction()).setVnfType(ebb.getVnfType()).setRequestId(ebb.getRequestId())
498 .setRequestDetails(ebb.getRequestDetails()).setBuildingBlock(buildingBlock)
499 .setWorkflowResourceIds(workflowResourceIds).setConfigurationResourceKeys(configurationResourceKeys);
502 protected void setInstanceName(String resourceId, WorkflowType resourceType, InfraActiveRequests request) {
503 logger.debug("Setting instanceName in infraActiveRequest");
505 if (resourceType == WorkflowType.SERVICE && request.getServiceInstanceName() == null) {
506 ServiceInstance service = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
507 if (service != null) {
508 request.setServiceInstanceName(service.getServiceInstanceName());
510 } else if (resourceType == WorkflowType.VNF && request.getVnfName() == null) {
511 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(resourceId);
513 request.setVnfName(vnf.getVnfName());
515 } else if (resourceType == WorkflowType.VFMODULE && request.getVfModuleName() == null) {
516 VfModule vfModule = bbInputSetupUtils.getAAIVfModule(request.getVnfId(), resourceId);
517 if (vfModule != null) {
518 request.setVfModuleName(vfModule.getVfModuleName());
520 } else if (resourceType == WorkflowType.VOLUMEGROUP && request.getVolumeGroupName() == null) {
521 Optional<VolumeGroup> volumeGroup =
522 bbInputSetupUtils.getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
523 volumeGroup.ifPresent(group -> request.setVolumeGroupName(group.getVolumeGroupName()));
524 } else if (resourceType == WorkflowType.NETWORK && request.getNetworkName() == null) {
525 L3Network network = bbInputSetupUtils.getAAIL3Network(resourceId);
526 if (network != null) {
527 request.setNetworkName(network.getNetworkName());
529 } else if (resourceType == WorkflowType.CONFIGURATION && request.getConfigurationName() == null) {
530 org.onap.aai.domain.yang.Configuration configuration =
531 bbInputSetupUtils.getAAIConfiguration(resourceId);
532 if (configuration != null) {
533 request.setConfigurationName(configuration.getConfigurationName());
535 } else if (resourceType == WorkflowType.INSTANCE_GROUP && request.getInstanceGroupName() == null) {
536 InstanceGroup instanceGroup = bbInputSetupUtils.getAAIInstanceGroup(resourceId);
537 if (instanceGroup != null) {
538 request.setInstanceGroupName(instanceGroup.getInstanceGroupName());
541 } catch (Exception ex) {
542 logger.error("Exception in setInstanceName", ex);