ba5d283c0157454e948e652085ea23c4702c8b95
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.workflow.tasks;
22
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.so.client.aai.AAIObjectType;
48 import org.onap.so.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;
63
64 @Component
65 public class WorkflowActionBBTasks {
66
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 ASSIGN_FABRIC_CONFIGURATION_BB = "AssignFabricConfigurationBB";
74     private static final String ACTIVATE_FABRIC_CONFIGURATION_BB = "ActivateFabricConfigurationBB";
75     private static final String COMPLETED = "completed";
76     private static final String HANDLINGCODE = "handlingCode";
77     private static final String ROLLBACKTOCREATED = "RollbackToCreated";
78     protected String maxRetries = "mso.rainyDay.maxRetries";
79     private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBTasks.class);
80
81     @Autowired
82     private RequestsDbClient requestDbclient;
83     @Autowired
84     private WorkflowAction workflowAction;
85     @Autowired
86     private WorkflowActionBBFailure workflowActionBBFailure;
87     @Autowired
88     private Environment environment;
89     @Autowired
90     private BBInputSetupUtils bbInputSetupUtils;
91     @Autowired
92     private CatalogDbClient catalogDbClient;
93     @Autowired
94     private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
95     @Autowired
96     private RequestsDbListenerRunner requestsDbListener;
97
98     public void selectBB(DelegateExecution execution) {
99         List<ExecuteBuildingBlock> flowsToExecute =
100                 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
101         execution.setVariable("MacroRollback", false);
102
103         flowManipulatorListenerRunner.modifyFlows(flowsToExecute, new DelegateExecutionImpl(execution));
104         int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
105
106         ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence);
107
108         execution.setVariable("buildingBlock", ebb);
109         currentSequence++;
110         if (currentSequence >= flowsToExecute.size()) {
111             execution.setVariable(COMPLETED, true);
112         } else {
113             execution.setVariable(COMPLETED, false);
114         }
115         execution.setVariable(G_CURRENT_SEQUENCE, currentSequence);
116     }
117
118     public void updateFlowStatistics(DelegateExecution execution) {
119         try {
120             int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
121             if (currentSequence > 1) {
122                 InfraActiveRequests request = this.getUpdatedRequest(execution, currentSequence);
123                 requestDbclient.updateInfraActiveRequests(request);
124             }
125         } catch (Exception ex) {
126             logger.warn(
127                     "Bpmn Flow Statistics was unable to update Request Db with the new completion percentage. Competion percentage may be invalid.",
128                     ex);
129         }
130     }
131
132     protected InfraActiveRequests getUpdatedRequest(DelegateExecution execution, int currentSequence) {
133         List<ExecuteBuildingBlock> flowsToExecute =
134                 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
135         String requestId = (String) execution.getVariable(G_REQUEST_ID);
136         InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
137         ExecuteBuildingBlock completedBB = flowsToExecute.get(currentSequence - 2);
138         ExecuteBuildingBlock nextBB = flowsToExecute.get(currentSequence - 1);
139         int completedBBs = currentSequence - 1;
140         int totalBBs = flowsToExecute.size();
141         int remainingBBs = totalBBs - completedBBs;
142         String statusMessage = this.getStatusMessage(completedBB.getBuildingBlock().getBpmnFlowName(),
143                 nextBB.getBuildingBlock().getBpmnFlowName(), completedBBs, remainingBBs);
144         Long percentProgress = this.getPercentProgress(completedBBs, totalBBs);
145         request.setFlowStatus(statusMessage);
146         request.setProgress(percentProgress);
147         request.setLastModifiedBy("CamundaBPMN");
148         return request;
149     }
150
151     protected Long getPercentProgress(int completedBBs, int totalBBs) {
152         double ratio = (completedBBs / (totalBBs * 1.0));
153         int percentProgress = (int) (ratio * 95);
154         return new Long(percentProgress + 5);
155     }
156
157     protected String getStatusMessage(String completedBB, String nextBB, int completedBBs, int remainingBBs) {
158         return "Execution of " + completedBB + " has completed successfully, next invoking " + nextBB
159                 + " (Execution Path progress: BBs completed = " + completedBBs + "; BBs remaining = " + remainingBBs
160                 + ").";
161     }
162
163     public void sendSyncAck(DelegateExecution execution) {
164         final String requestId = (String) execution.getVariable(G_REQUEST_ID);
165         final String resourceId = (String) execution.getVariable("resourceId");
166         ServiceInstancesResponse serviceInstancesResponse = new ServiceInstancesResponse();
167         RequestReferences requestRef = new RequestReferences();
168         requestRef.setInstanceId(resourceId);
169         requestRef.setRequestId(requestId);
170         serviceInstancesResponse.setRequestReferences(requestRef);
171         ObjectMapper mapper = new ObjectMapper();
172         String jsonRequest = "";
173         try {
174             jsonRequest = mapper.writeValueAsString(serviceInstancesResponse);
175         } catch (JsonProcessingException e) {
176             workflowAction.buildAndThrowException(execution,
177                     "Could not marshall ServiceInstancesRequest to Json string to respond to API Handler.", e);
178         }
179         WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
180         callbackResponse.setStatusCode(200);
181         callbackResponse.setMessage("Success");
182         callbackResponse.setResponse(jsonRequest);
183         String processKey = execution.getProcessEngineServices().getRepositoryService()
184                 .getProcessDefinition(execution.getProcessDefinitionId()).getKey();
185         WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId,
186                 callbackResponse);
187         logger.info("Successfully sent sync ack.");
188         updateInstanceId(execution);
189     }
190
191     public void sendErrorSyncAck(DelegateExecution execution) {
192         final String requestId = (String) execution.getVariable(G_REQUEST_ID);
193         try {
194             ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
195             String errorMsg = (String) execution.getVariable("WorkflowActionErrorMessage");
196             if (errorMsg == null) {
197                 errorMsg = "WorkflowAction failed unexpectedly.";
198             }
199             String processKey = exceptionBuilder.getProcessKey(execution);
200             String buildworkflowException =
201                     "<aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>"
202                             + errorMsg
203                             + "</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException>";
204             WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
205             callbackResponse.setStatusCode(500);
206             callbackResponse.setMessage("Fail");
207             callbackResponse.setResponse(buildworkflowException);
208             WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId,
209                     callbackResponse);
210             execution.setVariable("sentSyncResponse", true);
211         } catch (Exception ex) {
212             logger.error(" Sending Sync Error Activity Failed. {}", ex.getMessage(), ex);
213         }
214     }
215
216     public void updateRequestStatusToComplete(DelegateExecution execution) {
217         try {
218             final String requestId = (String) execution.getVariable(G_REQUEST_ID);
219             InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
220             final String action = (String) execution.getVariable(G_ACTION);
221             final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
222             final String resourceName = (String) execution.getVariable("resourceName");
223             String statusMessage = (String) execution.getVariable("StatusMessage");
224             String macroAction = "";
225             if (statusMessage == null) {
226                 if (aLaCarte) {
227                     macroAction = "ALaCarte-" + resourceName + "-" + action + " request was executed correctly.";
228                 } else {
229                     macroAction = "Macro-" + resourceName + "-" + action + " request was executed correctly.";
230                 }
231             } else {
232                 macroAction = statusMessage;
233             }
234             execution.setVariable("finalStatusMessage", macroAction);
235             Timestamp endTime = new Timestamp(System.currentTimeMillis());
236             request.setEndTime(endTime);
237             request.setFlowStatus("Successfully completed all Building Blocks");
238             request.setStatusMessage(macroAction);
239             request.setProgress(Long.valueOf(100));
240             request.setRequestStatus("COMPLETE");
241             request.setLastModifiedBy("CamundaBPMN");
242             requestsDbListener.post(request, new DelegateExecutionImpl(execution));
243             requestDbclient.updateInfraActiveRequests(request);
244         } catch (Exception ex) {
245             workflowAction.buildAndThrowException(execution, "Error Updating Request Database", ex);
246         }
247     }
248
249     public void checkRetryStatus(DelegateExecution execution) {
250         String handlingCode = (String) execution.getVariable(HANDLINGCODE);
251         String requestId = (String) execution.getVariable(G_REQUEST_ID);
252         String retryDuration = (String) execution.getVariable("RetryDuration");
253         int retryCount = (int) execution.getVariable(RETRY_COUNT);
254         int envMaxRetries;
255         try {
256             envMaxRetries = Integer.parseInt(this.environment.getProperty(maxRetries));
257         } catch (Exception ex) {
258             logger.error("Could not read maxRetries from config file. Setting max to 5 retries", ex);
259             envMaxRetries = 5;
260         }
261         int nextCount = retryCount + 1;
262         if ("Retry".equals(handlingCode)) {
263             workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
264             try {
265                 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
266                 request.setRetryStatusMessage(
267                         "Retry " + nextCount + "/" + envMaxRetries + " will be started in " + retryDuration);
268                 requestDbclient.updateInfraActiveRequests(request);
269             } catch (Exception ex) {
270                 logger.warn("Failed to update Request Db Infra Active Requests with Retry Status", ex);
271             }
272             if (retryCount < envMaxRetries) {
273                 int currSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
274                 execution.setVariable(G_CURRENT_SEQUENCE, currSequence - 1);
275                 execution.setVariable(RETRY_COUNT, nextCount);
276             } else {
277                 workflowAction.buildAndThrowException(execution,
278                         "Exceeded maximum retries. Ending flow with status Abort");
279             }
280         } else {
281             execution.setVariable(RETRY_COUNT, 0);
282         }
283     }
284
285     /**
286      * Rollback will only handle Create/Activate/Assign Macro flows. Execute layer will rollback the flow its currently
287      * working on.
288      */
289     public void rollbackExecutionPath(DelegateExecution execution) {
290         if (!(boolean) execution.getVariable("isRollback")) {
291             List<ExecuteBuildingBlock> flowsToExecute =
292                     (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
293             List<ExecuteBuildingBlock> rollbackFlows = new ArrayList();
294             int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
295             int listSize = flowsToExecute.size();
296             for (int i = listSize - 1; i >= 0; i--) {
297                 if (i > currentSequence - 1) {
298                     flowsToExecute.remove(i);
299                 } else {
300                     String flowName = flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName();
301                     if (flowName.startsWith("Assign")) {
302                         flowName = flowName.replaceFirst("Assign", "Unassign");
303                     } else if (flowName.startsWith("Create")) {
304                         flowName = flowName.replaceFirst("Create", "Delete");
305                     } else if (flowName.startsWith("Activate")) {
306                         flowName = flowName.replaceFirst("Activate", "Deactivate");
307                     } else {
308                         continue;
309                     }
310                     flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName);
311                     rollbackFlows.add(flowsToExecute.get(i));
312                 }
313             }
314
315             String handlingCode = (String) execution.getVariable(HANDLINGCODE);
316             List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>();
317             rollbackFlowsFiltered.addAll(rollbackFlows);
318             if ("RollbackToAssigned".equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode)) {
319                 for (int i = 0; i < rollbackFlows.size(); i++) {
320                     if (rollbackFlows.get(i).getBuildingBlock().getBpmnFlowName().contains("Unassign") && !rollbackFlows
321                             .get(i).getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")) {
322                         rollbackFlowsFiltered.remove(rollbackFlows.get(i));
323                     } else if (rollbackFlows.get(i).getBuildingBlock().getBpmnFlowName().contains("Delete")
324                             && ROLLBACKTOCREATED.equals(handlingCode)) {
325                         rollbackFlowsFiltered.remove(rollbackFlows.get(i));
326                     }
327                 }
328             }
329
330             workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
331             if (rollbackFlows.isEmpty())
332                 execution.setVariable("isRollbackNeeded", false);
333             else
334                 execution.setVariable("isRollbackNeeded", true);
335             execution.setVariable("flowsToExecute", rollbackFlowsFiltered);
336             execution.setVariable(HANDLINGCODE, "PreformingRollback");
337             execution.setVariable("isRollback", true);
338             execution.setVariable(G_CURRENT_SEQUENCE, 0);
339             execution.setVariable(RETRY_COUNT, 0);
340         } else {
341             workflowAction.buildAndThrowException(execution,
342                     "Rollback has already been called. Cannot rollback a request that is currently in the rollback state.");
343         }
344     }
345
346     protected void updateInstanceId(DelegateExecution execution) {
347         try {
348             String requestId = (String) execution.getVariable(G_REQUEST_ID);
349             String resourceId = (String) execution.getVariable("resourceId");
350             WorkflowType resourceType = (WorkflowType) execution.getVariable("resourceType");
351             InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
352             if (resourceType == WorkflowType.SERVICE) {
353                 request.setServiceInstanceId(resourceId);
354             } else if (resourceType == WorkflowType.VNF) {
355                 request.setVnfId(resourceId);
356             } else if (resourceType == WorkflowType.VFMODULE) {
357                 request.setVfModuleId(resourceId);
358             } else if (resourceType == WorkflowType.VOLUMEGROUP) {
359                 request.setVolumeGroupId(resourceId);
360             } else if (resourceType == WorkflowType.NETWORK) {
361                 request.setNetworkId(resourceId);
362             } else if (resourceType == WorkflowType.CONFIGURATION) {
363                 request.setConfigurationId(resourceId);
364             } else if (resourceType == WorkflowType.INSTANCE_GROUP) {
365                 request.setInstanceGroupId(resourceId);
366             }
367             setInstanceName(resourceId, resourceType, request);
368             request.setLastModifiedBy("CamundaBPMN");
369             requestDbclient.updateInfraActiveRequests(request);
370         } catch (Exception ex) {
371             logger.error("Exception in updateInstanceId", ex);
372             workflowAction.buildAndThrowException(execution, "Failed to update Request db with instanceId");
373         }
374     }
375
376     public void postProcessingExecuteBB(DelegateExecution execution) {
377         List<ExecuteBuildingBlock> flowsToExecute =
378                 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
379         String handlingCode = (String) execution.getVariable(HANDLINGCODE);
380         final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
381         int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
382         ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence - 1);
383         String bbFlowName = ebb.getBuildingBlock().getBpmnFlowName();
384         if ("ActivateVfModuleBB".equalsIgnoreCase(bbFlowName) && aLaCarte && "Success".equalsIgnoreCase(handlingCode)) {
385             postProcessingExecuteBBActivateVfModule(execution, ebb, flowsToExecute);
386         }
387     }
388
389     protected void postProcessingExecuteBBActivateVfModule(DelegateExecution execution, ExecuteBuildingBlock ebb,
390             List<ExecuteBuildingBlock> flowsToExecute) {
391         try {
392             String serviceInstanceId = ebb.getWorkflowResourceIds().getServiceInstanceId();
393             String vnfId = ebb.getWorkflowResourceIds().getVnfId();
394             String vfModuleId = ebb.getResourceId();
395             ebb.getWorkflowResourceIds().setVfModuleId(vfModuleId);
396             String serviceModelUUID =
397                     bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId).getModelVersionId();
398             String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
399             String vfModuleCustomizationUUID =
400                     bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
401             List<Vnfc> vnfcs =
402                     workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, AAIObjectType.VNFC);
403             logger.debug("Vnfc Size: {}", vnfcs.size());
404             for (Vnfc vnfc : vnfcs) {
405                 String modelCustomizationId = vnfc.getModelCustomizationId();
406                 logger.debug("Processing Vnfc: {}", modelCustomizationId);
407                 CvnfcConfigurationCustomization fabricConfig = catalogDbClient.getCvnfcCustomization(serviceModelUUID,
408                         vnfCustomizationUUID, vfModuleCustomizationUUID, modelCustomizationId);
409                 if (fabricConfig != null && fabricConfig.getConfigurationResource() != null
410                         && fabricConfig.getConfigurationResource().getToscaNodeType() != null
411                         && fabricConfig.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
412                     String configurationId = getConfigurationId(vnfc);
413                     ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
414                     configurationResourceKeys.setCvnfcCustomizationUUID(modelCustomizationId);
415                     configurationResourceKeys.setVfModuleCustomizationUUID(vfModuleCustomizationUUID);
416                     configurationResourceKeys.setVnfResourceCustomizationUUID(vnfCustomizationUUID);
417                     configurationResourceKeys.setVnfcName(vnfc.getVnfcName());
418                     ExecuteBuildingBlock assignConfigBB = getExecuteBBForConfig(ASSIGN_FABRIC_CONFIGURATION_BB, ebb,
419                             configurationId, configurationResourceKeys);
420                     ExecuteBuildingBlock activateConfigBB = getExecuteBBForConfig(ACTIVATE_FABRIC_CONFIGURATION_BB, ebb,
421                             configurationId, configurationResourceKeys);
422                     flowsToExecute.add(assignConfigBB);
423                     flowsToExecute.add(activateConfigBB);
424                     flowsToExecute.stream()
425                             .forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}",
426                                     executeBB.getBuildingBlock().getBpmnFlowName()));
427                     execution.setVariable("flowsToExecute", flowsToExecute);
428                     execution.setVariable(COMPLETED, false);
429                 } else {
430                     logger.debug("No cvnfcCustomization found for customizationId: {}", modelCustomizationId);
431                 }
432             }
433         } catch (EntityNotFoundException e) {
434             logger.debug("Will not be running Fabric Config Building Blocks", e);
435         } catch (Exception e) {
436             String errorMessage = "Error occurred in post processing of Vf Module create";
437             execution.setVariable(HANDLINGCODE, ROLLBACKTOCREATED);
438             execution.setVariable("WorkflowActionErrorMessage", errorMessage);
439             logger.error(errorMessage, e);
440         }
441     }
442
443     protected String getConfigurationId(Vnfc vnfc) {
444         List<Configuration> configurations =
445                 workflowAction.getRelatedResourcesInVnfc(vnfc, Configuration.class, AAIObjectType.CONFIGURATION);
446         if (!configurations.isEmpty()) {
447             Configuration configuration = configurations.get(0);
448             return configuration.getConfigurationId();
449         } else {
450             return UUID.randomUUID().toString();
451         }
452     }
453
454     protected ExecuteBuildingBlock getExecuteBBForConfig(String bbName, ExecuteBuildingBlock ebb,
455             String configurationId, ConfigurationResourceKeys configurationResourceKeys) {
456         BuildingBlock buildingBlock =
457                 new BuildingBlock().setBpmnFlowName(bbName).setMsoId(UUID.randomUUID().toString());
458
459         WorkflowResourceIds workflowResourceIds = ebb.getWorkflowResourceIds();
460         workflowResourceIds.setConfigurationId(configurationId);
461         ExecuteBuildingBlock configBB = new ExecuteBuildingBlock().setaLaCarte(ebb.isaLaCarte())
462                 .setApiVersion(ebb.getApiVersion()).setRequestAction(ebb.getRequestAction())
463                 .setVnfType(ebb.getVnfType()).setRequestId(ebb.getRequestId())
464                 .setRequestDetails(ebb.getRequestDetails()).setBuildingBlock(buildingBlock)
465                 .setWorkflowResourceIds(workflowResourceIds).setConfigurationResourceKeys(configurationResourceKeys);
466         return configBB;
467     }
468
469     protected void setInstanceName(String resourceId, WorkflowType resourceType, InfraActiveRequests request) {
470         logger.debug("Setting instanceName in infraActiveRequest");
471         try {
472             if (resourceType == WorkflowType.SERVICE && request.getServiceInstanceName() == null) {
473                 ServiceInstance service = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
474                 if (service != null) {
475                     request.setServiceInstanceName(service.getServiceInstanceName());
476                 }
477             } else if (resourceType == WorkflowType.VNF && request.getVnfName() == null) {
478                 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(resourceId);
479                 if (vnf != null) {
480                     request.setVnfName(vnf.getVnfName());
481                 }
482             } else if (resourceType == WorkflowType.VFMODULE && request.getVfModuleName() == null) {
483                 VfModule vfModule = bbInputSetupUtils.getAAIVfModule(request.getVnfId(), resourceId);
484                 if (vfModule != null) {
485                     request.setVfModuleName(vfModule.getVfModuleName());
486                 }
487             } else if (resourceType == WorkflowType.VOLUMEGROUP && request.getVolumeGroupName() == null) {
488                 Optional<VolumeGroup> volumeGroup =
489                         bbInputSetupUtils.getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
490                 if (volumeGroup.isPresent()) {
491                     request.setVolumeGroupName(volumeGroup.get().getVolumeGroupName());
492                 }
493             } else if (resourceType == WorkflowType.NETWORK && request.getNetworkName() == null) {
494                 L3Network network = bbInputSetupUtils.getAAIL3Network(resourceId);
495                 if (network != null) {
496                     request.setNetworkName(network.getNetworkName());
497                 }
498             } else if (resourceType == WorkflowType.CONFIGURATION && request.getConfigurationName() == null) {
499                 org.onap.aai.domain.yang.Configuration configuration =
500                         bbInputSetupUtils.getAAIConfiguration(resourceId);
501                 if (configuration != null) {
502                     request.setConfigurationName(configuration.getConfigurationName());
503                 }
504             } else if (resourceType == WorkflowType.INSTANCE_GROUP && request.getInstanceGroupName() == null) {
505                 InstanceGroup instanceGroup = bbInputSetupUtils.getAAIInstanceGroup(resourceId);
506                 if (instanceGroup != null) {
507                     request.setInstanceGroupName(instanceGroup.getInstanceGroupName());
508                 }
509             }
510         } catch (Exception ex) {
511             logger.error("Exception in setInstanceName", ex);
512         }
513     }
514 }