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 javax.persistence.EntityNotFoundException;
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.onap.aai.domain.yang.GenericVnf;
31 import org.onap.aai.domain.yang.InstanceGroup;
32 import org.onap.aai.domain.yang.L3Network;
33 import org.onap.aai.domain.yang.ServiceInstance;
34 import org.onap.aai.domain.yang.VfModule;
35 import org.onap.aai.domain.yang.Vnfc;
36 import org.onap.aai.domain.yang.VolumeGroup;
37 import org.onap.so.bpmn.common.DelegateExecutionImpl;
38 import org.onap.so.bpmn.common.listener.db.RequestsDbListenerRunner;
39 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
40 import org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse;
41 import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder;
42 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
43 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
44 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
45 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
46 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
47 import org.onap.aaiclient.client.aai.AAIObjectType;
48 import org.onap.aaiclient.client.aai.entities.Configuration;
49 import org.onap.so.client.exception.ExceptionBuilder;
50 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
51 import org.onap.so.db.catalog.client.CatalogDbClient;
52 import org.onap.so.db.request.beans.InfraActiveRequests;
53 import org.onap.so.db.request.client.RequestsDbClient;
54 import org.onap.so.serviceinstancebeans.RequestReferences;
55 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58 import org.springframework.beans.factory.annotation.Autowired;
59 import org.springframework.core.env.Environment;
60 import org.springframework.stereotype.Component;
61 import com.fasterxml.jackson.core.JsonProcessingException;
62 import com.fasterxml.jackson.databind.ObjectMapper;
65 public class WorkflowActionBBTasks {
67 private static final String G_CURRENT_SEQUENCE = "gCurrentSequence";
68 private static final String G_REQUEST_ID = "mso-request-id";
69 private static final String G_ALACARTE = "aLaCarte";
70 private static final String G_ACTION = "requestAction";
71 private static final String RETRY_COUNT = "retryCount";
72 private static final String FABRIC_CONFIGURATION = "FabricConfiguration";
73 private static final String ADD_FABRIC_CONFIGURATION_BB = "AddFabricConfigurationBB";
74 private static final String COMPLETED = "completed";
75 private static final String HANDLINGCODE = "handlingCode";
76 private static final String ROLLBACKTOCREATED = "RollbackToCreated";
77 private static final String REPLACEINSTANCE = "replaceInstance";
78 private static final String VFMODULE = "VfModule";
79 protected String maxRetries = "mso.rainyDay.maxRetries";
80 private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBTasks.class);
83 private RequestsDbClient requestDbclient;
85 private WorkflowAction workflowAction;
87 private WorkflowActionBBFailure workflowActionBBFailure;
89 private Environment environment;
91 private BBInputSetupUtils bbInputSetupUtils;
93 private CatalogDbClient catalogDbClient;
95 private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
97 private RequestsDbListenerRunner requestsDbListener;
99 public void selectBB(DelegateExecution execution) {
100 List<ExecuteBuildingBlock> flowsToExecute =
101 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
102 execution.setVariable("MacroRollback", false);
104 flowManipulatorListenerRunner.modifyFlows(flowsToExecute, new DelegateExecutionImpl(execution));
105 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
107 ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence);
109 execution.setVariable("buildingBlock", ebb);
111 if (currentSequence >= flowsToExecute.size()) {
112 execution.setVariable(COMPLETED, true);
114 execution.setVariable(COMPLETED, false);
116 execution.setVariable(G_CURRENT_SEQUENCE, currentSequence);
119 public void updateFlowStatistics(DelegateExecution execution) {
121 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
122 if (currentSequence > 1) {
123 InfraActiveRequests request = this.getUpdatedRequest(execution, currentSequence);
124 requestDbclient.updateInfraActiveRequests(request);
126 } catch (Exception ex) {
128 "Bpmn Flow Statistics was unable to update Request Db with the new completion percentage. Competion percentage may be invalid.",
133 protected InfraActiveRequests getUpdatedRequest(DelegateExecution execution, int currentSequence) {
134 List<ExecuteBuildingBlock> flowsToExecute =
135 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
136 String requestId = (String) execution.getVariable(G_REQUEST_ID);
137 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
138 ExecuteBuildingBlock completedBB = flowsToExecute.get(currentSequence - 2);
139 ExecuteBuildingBlock nextBB = flowsToExecute.get(currentSequence - 1);
140 int completedBBs = currentSequence - 1;
141 int totalBBs = flowsToExecute.size();
142 int remainingBBs = totalBBs - completedBBs;
143 String statusMessage = this.getStatusMessage(completedBB.getBuildingBlock().getBpmnFlowName(),
144 nextBB.getBuildingBlock().getBpmnFlowName(), completedBBs, remainingBBs);
145 Long percentProgress = this.getPercentProgress(completedBBs, totalBBs);
146 request.setFlowStatus(statusMessage);
147 request.setProgress(percentProgress);
148 request.setLastModifiedBy("CamundaBPMN");
152 protected Long getPercentProgress(int completedBBs, int totalBBs) {
153 double ratio = (completedBBs / (totalBBs * 1.0));
154 int percentProgress = (int) (ratio * 95);
155 return new Long(percentProgress + 5);
158 protected String getStatusMessage(String completedBB, String nextBB, int completedBBs, int remainingBBs) {
159 return "Execution of " + completedBB + " has completed successfully, next invoking " + nextBB
160 + " (Execution Path progress: BBs completed = " + completedBBs + "; BBs remaining = " + remainingBBs
164 public void sendSyncAck(DelegateExecution execution) {
165 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
166 final String resourceId = (String) execution.getVariable("resourceId");
167 ServiceInstancesResponse serviceInstancesResponse = new ServiceInstancesResponse();
168 RequestReferences requestRef = new RequestReferences();
169 requestRef.setInstanceId(resourceId);
170 requestRef.setRequestId(requestId);
171 serviceInstancesResponse.setRequestReferences(requestRef);
172 ObjectMapper mapper = new ObjectMapper();
173 String jsonRequest = "";
175 jsonRequest = mapper.writeValueAsString(serviceInstancesResponse);
176 } catch (JsonProcessingException e) {
177 workflowAction.buildAndThrowException(execution,
178 "Could not marshall ServiceInstancesRequest to Json string to respond to API Handler.", e);
180 WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
181 callbackResponse.setStatusCode(200);
182 callbackResponse.setMessage("Success");
183 callbackResponse.setResponse(jsonRequest);
184 String processKey = execution.getProcessEngineServices().getRepositoryService()
185 .getProcessDefinition(execution.getProcessDefinitionId()).getKey();
186 WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId,
188 logger.info("Successfully sent sync ack.");
189 updateInstanceId(execution);
192 public void sendErrorSyncAck(DelegateExecution execution) {
193 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
195 ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
196 String errorMsg = (String) execution.getVariable("WorkflowActionErrorMessage");
197 if (errorMsg == null) {
198 errorMsg = "WorkflowAction failed unexpectedly.";
200 String processKey = exceptionBuilder.getProcessKey(execution);
201 String buildworkflowException =
202 "<aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>"
204 + "</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException>";
205 WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
206 callbackResponse.setStatusCode(500);
207 callbackResponse.setMessage("Fail");
208 callbackResponse.setResponse(buildworkflowException);
209 WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId,
211 execution.setVariable("sentSyncResponse", true);
212 } catch (Exception ex) {
213 logger.error(" Sending Sync Error Activity Failed. {}", ex.getMessage(), ex);
217 public void updateRequestStatusToComplete(DelegateExecution execution) {
219 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
220 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
221 final String action = (String) execution.getVariable(G_ACTION);
222 final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
223 final String resourceName = (String) execution.getVariable("resourceName");
224 String statusMessage = (String) execution.getVariable("StatusMessage");
225 String macroAction = "";
226 if (statusMessage == null) {
228 macroAction = "ALaCarte-" + resourceName + "-" + action + " request was executed correctly.";
230 macroAction = "Macro-" + resourceName + "-" + action + " request was executed correctly.";
233 macroAction = statusMessage;
235 execution.setVariable("finalStatusMessage", macroAction);
236 Timestamp endTime = new Timestamp(System.currentTimeMillis());
237 request.setEndTime(endTime);
238 request.setFlowStatus("Successfully completed all Building Blocks");
239 request.setStatusMessage(macroAction);
240 request.setProgress(Long.valueOf(100));
241 request.setRequestStatus("COMPLETE");
242 request.setLastModifiedBy("CamundaBPMN");
243 requestsDbListener.post(request, new DelegateExecutionImpl(execution));
244 requestDbclient.updateInfraActiveRequests(request);
245 } catch (Exception ex) {
246 workflowAction.buildAndThrowException(execution, "Error Updating Request Database", ex);
250 public void checkRetryStatus(DelegateExecution execution) {
251 String handlingCode = (String) execution.getVariable(HANDLINGCODE);
252 String requestId = (String) execution.getVariable(G_REQUEST_ID);
253 String retryDuration = (String) execution.getVariable("RetryDuration");
254 int retryCount = (int) execution.getVariable(RETRY_COUNT);
257 envMaxRetries = Integer.parseInt(this.environment.getProperty(maxRetries));
258 } catch (Exception ex) {
259 logger.error("Could not read maxRetries from config file. Setting max to 5 retries", ex);
262 int nextCount = retryCount + 1;
263 if ("Retry".equals(handlingCode)) {
264 workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
266 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
267 request.setRetryStatusMessage(
268 "Retry " + nextCount + "/" + envMaxRetries + " will be started in " + retryDuration);
269 requestDbclient.updateInfraActiveRequests(request);
270 } catch (Exception ex) {
271 logger.warn("Failed to update Request Db Infra Active Requests with Retry Status", ex);
273 if (retryCount < envMaxRetries) {
274 int currSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
275 execution.setVariable(G_CURRENT_SEQUENCE, currSequence - 1);
276 execution.setVariable(RETRY_COUNT, nextCount);
278 workflowAction.buildAndThrowException(execution,
279 "Exceeded maximum retries. Ending flow with status Abort");
282 execution.setVariable(RETRY_COUNT, 0);
287 * Rollback will only handle Create/Activate/Assign Macro flows. Execute layer will rollback the flow its currently
290 public void rollbackExecutionPath(DelegateExecution execution) {
291 final String action = (String) execution.getVariable(G_ACTION);
292 final String resourceName = (String) execution.getVariable("resourceName");
293 if (!(boolean) execution.getVariable("isRollback")) {
294 List<ExecuteBuildingBlock> flowsToExecute =
295 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
297 List<ExecuteBuildingBlock> flowsToExecuteChangeBBs = new ArrayList();
298 for (int i = 0; i < flowsToExecute.size(); i++) {
299 if (flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName().startsWith("Change")) {
300 flowsToExecuteChangeBBs.add(flowsToExecute.get(i));
304 List<ExecuteBuildingBlock> rollbackFlows = new ArrayList();
305 int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
306 int listSize = flowsToExecute.size();
308 for (int i = listSize - 1; i >= 0; i--) {
309 if (i > currentSequence - 1) {
310 flowsToExecute.remove(i);
312 String flowName = flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName();
313 if (flowName.startsWith("Assign")) {
314 flowName = flowName.replaceFirst("Assign", "Unassign");
315 } else if (flowName.startsWith("Create")) {
316 flowName = flowName.replaceFirst("Create", "Delete");
317 } else if (flowName.startsWith("Activate")) {
318 flowName = flowName.replaceFirst("Activate", "Deactivate");
319 } else if (flowName.startsWith("Add")) {
320 flowName = flowName.replaceFirst("Add", "Delete");
321 } else if (flowName.startsWith("VNF")) {
322 if (flowName.startsWith("VNFSet")) {
323 flowName = flowName.replaceFirst("VNFSet", "VNFUnset");
324 } else if (flowName.startsWith("VNFLock")) {
325 flowName = flowName.replaceFirst("VNFLock", "VNFUnlock");
326 } else if (flowName.startsWith("VNFStop")) {
327 flowName = flowName.replaceFirst("VNFStop", "VNFStart");
328 } else if (flowName.startsWith("VNFQuiesce")) {
329 flowName = flowName.replaceFirst("VNFQuiesce", "VNFResume");
336 flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName);
337 rollbackFlows.add(flowsToExecute.get(i));
341 String handlingCode = (String) execution.getVariable(HANDLINGCODE);
342 List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>();
343 rollbackFlowsFiltered.addAll(rollbackFlows);
344 if ("RollbackToAssigned".equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode)) {
345 for (int i = 0; i < rollbackFlows.size(); i++) {
346 if (rollbackFlows.get(i).getBuildingBlock().getBpmnFlowName().contains("Unassign") && !rollbackFlows
347 .get(i).getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")) {
348 rollbackFlowsFiltered.remove(rollbackFlows.get(i));
349 } else if (rollbackFlows.get(i).getBuildingBlock().getBpmnFlowName().contains("Delete")
350 && ROLLBACKTOCREATED.equals(handlingCode)) {
351 rollbackFlowsFiltered.remove(rollbackFlows.get(i));
356 List<ExecuteBuildingBlock> rollbackFlowsFilteredNonChangeBBs = new ArrayList();
357 if (action.equals(REPLACEINSTANCE) && resourceName.equals(VFMODULE)) {
358 for (int i = 0; i < rollbackFlowsFiltered.size(); i++) {
359 if (!rollbackFlowsFiltered.get(i).getBuildingBlock().getBpmnFlowName().startsWith("Change")) {
360 rollbackFlowsFilteredNonChangeBBs.add(rollbackFlowsFiltered.get(i));
363 rollbackFlowsFiltered.clear();
364 rollbackFlowsFiltered.addAll(flowsToExecuteChangeBBs);
365 rollbackFlowsFiltered.addAll(rollbackFlowsFilteredNonChangeBBs);
368 workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
369 if (rollbackFlows.isEmpty())
370 execution.setVariable("isRollbackNeeded", false);
372 execution.setVariable("isRollbackNeeded", true);
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 ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence - 1);
421 String bbFlowName = ebb.getBuildingBlock().getBpmnFlowName();
422 if ("ActivateVfModuleBB".equalsIgnoreCase(bbFlowName) && aLaCarte && "Success".equalsIgnoreCase(handlingCode)) {
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();
440 workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, AAIObjectType.VNFC);
441 logger.debug("Vnfc Size: {}", vnfcs.size());
442 for (Vnfc vnfc : vnfcs) {
443 String modelCustomizationId = vnfc.getModelCustomizationId();
444 logger.debug("Processing Vnfc: {}", modelCustomizationId);
445 CvnfcConfigurationCustomization fabricConfig = catalogDbClient.getCvnfcCustomization(serviceModelUUID,
446 vnfCustomizationUUID, vfModuleCustomizationUUID, modelCustomizationId);
447 if (fabricConfig != null && fabricConfig.getConfigurationResource() != null
448 && fabricConfig.getConfigurationResource().getToscaNodeType() != null
449 && fabricConfig.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
450 String configurationId = getConfigurationId(vnfc);
451 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
452 configurationResourceKeys.setCvnfcCustomizationUUID(modelCustomizationId);
453 configurationResourceKeys.setVfModuleCustomizationUUID(vfModuleCustomizationUUID);
454 configurationResourceKeys.setVnfResourceCustomizationUUID(vnfCustomizationUUID);
455 configurationResourceKeys.setVnfcName(vnfc.getVnfcName());
456 ExecuteBuildingBlock addConfigBB = getExecuteBBForConfig(ADD_FABRIC_CONFIGURATION_BB, ebb,
457 configurationId, configurationResourceKeys);
458 flowsToExecute.add(addConfigBB);
459 flowsToExecute.stream()
460 .forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}",
461 executeBB.getBuildingBlock().getBpmnFlowName()));
462 execution.setVariable("flowsToExecute", flowsToExecute);
463 execution.setVariable(COMPLETED, false);
465 logger.debug("No cvnfcCustomization found for customizationId: {}", modelCustomizationId);
468 } catch (EntityNotFoundException e) {
469 logger.debug("Will not be running Fabric Config Building Blocks", e);
470 } catch (Exception e) {
471 String errorMessage = "Error occurred in post processing of Vf Module create";
472 execution.setVariable(HANDLINGCODE, ROLLBACKTOCREATED);
473 execution.setVariable("WorkflowActionErrorMessage", errorMessage);
474 logger.error(errorMessage, e);
478 protected String getConfigurationId(Vnfc vnfc) {
479 List<Configuration> configurations =
480 workflowAction.getRelatedResourcesInVnfc(vnfc, Configuration.class, AAIObjectType.CONFIGURATION);
481 if (!configurations.isEmpty()) {
482 Configuration configuration = configurations.get(0);
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 = ebb.getWorkflowResourceIds();
495 workflowResourceIds.setConfigurationId(configurationId);
496 ExecuteBuildingBlock configBB = new ExecuteBuildingBlock().setaLaCarte(ebb.isaLaCarte())
497 .setApiVersion(ebb.getApiVersion()).setRequestAction(ebb.getRequestAction())
498 .setVnfType(ebb.getVnfType()).setRequestId(ebb.getRequestId())
499 .setRequestDetails(ebb.getRequestDetails()).setBuildingBlock(buildingBlock)
500 .setWorkflowResourceIds(workflowResourceIds).setConfigurationResourceKeys(configurationResourceKeys);
504 protected void setInstanceName(String resourceId, WorkflowType resourceType, InfraActiveRequests request) {
505 logger.debug("Setting instanceName in infraActiveRequest");
507 if (resourceType == WorkflowType.SERVICE && request.getServiceInstanceName() == null) {
508 ServiceInstance service = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
509 if (service != null) {
510 request.setServiceInstanceName(service.getServiceInstanceName());
512 } else if (resourceType == WorkflowType.VNF && request.getVnfName() == null) {
513 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(resourceId);
515 request.setVnfName(vnf.getVnfName());
517 } else if (resourceType == WorkflowType.VFMODULE && request.getVfModuleName() == null) {
518 VfModule vfModule = bbInputSetupUtils.getAAIVfModule(request.getVnfId(), resourceId);
519 if (vfModule != null) {
520 request.setVfModuleName(vfModule.getVfModuleName());
522 } else if (resourceType == WorkflowType.VOLUMEGROUP && request.getVolumeGroupName() == null) {
523 Optional<VolumeGroup> volumeGroup =
524 bbInputSetupUtils.getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
525 if (volumeGroup.isPresent()) {
526 request.setVolumeGroupName(volumeGroup.get().getVolumeGroupName());
528 } else if (resourceType == WorkflowType.NETWORK && request.getNetworkName() == null) {
529 L3Network network = bbInputSetupUtils.getAAIL3Network(resourceId);
530 if (network != null) {
531 request.setNetworkName(network.getNetworkName());
533 } else if (resourceType == WorkflowType.CONFIGURATION && request.getConfigurationName() == null) {
534 org.onap.aai.domain.yang.Configuration configuration =
535 bbInputSetupUtils.getAAIConfiguration(resourceId);
536 if (configuration != null) {
537 request.setConfigurationName(configuration.getConfigurationName());
539 } else if (resourceType == WorkflowType.INSTANCE_GROUP && request.getInstanceGroupName() == null) {
540 InstanceGroup instanceGroup = bbInputSetupUtils.getAAIInstanceGroup(resourceId);
541 if (instanceGroup != null) {
542 request.setInstanceGroupName(instanceGroup.getInstanceGroupName());
545 } catch (Exception ex) {
546 logger.error("Exception in setInstanceName", ex);