Merge "Added support for volume group request to"
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / workflow / tasks / WorkflowActionBBTasks.java
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 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     protected String maxRetries = "mso.rainyDay.maxRetries";
78     private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBTasks.class);
79
80     @Autowired
81     private RequestsDbClient requestDbclient;
82     @Autowired
83     private WorkflowAction workflowAction;
84     @Autowired
85     private WorkflowActionBBFailure workflowActionBBFailure;
86     @Autowired
87     private Environment environment;
88     @Autowired
89     private BBInputSetupUtils bbInputSetupUtils;
90     @Autowired
91     private CatalogDbClient catalogDbClient;
92     @Autowired
93     private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
94     @Autowired
95     private RequestsDbListenerRunner requestsDbListener;
96
97     public void selectBB(DelegateExecution execution) {
98         List<ExecuteBuildingBlock> flowsToExecute =
99                 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
100         execution.setVariable("MacroRollback", false);
101
102         flowManipulatorListenerRunner.modifyFlows(flowsToExecute, new DelegateExecutionImpl(execution));
103         int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
104
105         ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence);
106
107         execution.setVariable("buildingBlock", ebb);
108         currentSequence++;
109         if (currentSequence >= flowsToExecute.size()) {
110             execution.setVariable(COMPLETED, true);
111         } else {
112             execution.setVariable(COMPLETED, false);
113         }
114         execution.setVariable(G_CURRENT_SEQUENCE, currentSequence);
115     }
116
117     public void updateFlowStatistics(DelegateExecution execution) {
118         try {
119             int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
120             if (currentSequence > 1) {
121                 InfraActiveRequests request = this.getUpdatedRequest(execution, currentSequence);
122                 requestDbclient.updateInfraActiveRequests(request);
123             }
124         } catch (Exception ex) {
125             logger.warn(
126                     "Bpmn Flow Statistics was unable to update Request Db with the new completion percentage. Competion percentage may be invalid.",
127                     ex);
128         }
129     }
130
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");
147         return request;
148     }
149
150     protected Long getPercentProgress(int completedBBs, int totalBBs) {
151         double ratio = (completedBBs / (totalBBs * 1.0));
152         int percentProgress = (int) (ratio * 95);
153         return new Long(percentProgress + 5);
154     }
155
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
159                 + ").";
160     }
161
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 = "";
172         try {
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);
177         }
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,
185                 callbackResponse);
186         logger.info("Successfully sent sync ack.");
187         updateInstanceId(execution);
188     }
189
190     public void sendErrorSyncAck(DelegateExecution execution) {
191         final String requestId = (String) execution.getVariable(G_REQUEST_ID);
192         try {
193             ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
194             String errorMsg = (String) execution.getVariable("WorkflowActionErrorMessage");
195             if (errorMsg == null) {
196                 errorMsg = "WorkflowAction failed unexpectedly.";
197             }
198             String processKey = exceptionBuilder.getProcessKey(execution);
199             String buildworkflowException =
200                     "<aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>"
201                             + errorMsg
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,
208                     callbackResponse);
209             execution.setVariable("sentSyncResponse", true);
210         } catch (Exception ex) {
211             logger.error(" Sending Sync Error Activity Failed. {}", ex.getMessage(), ex);
212         }
213     }
214
215     public void updateRequestStatusToComplete(DelegateExecution execution) {
216         try {
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");
223             String macroAction = "";
224             if (statusMessage == null) {
225                 if (aLaCarte) {
226                     macroAction = "ALaCarte-" + resourceName + "-" + action + " request was executed correctly.";
227                 } else {
228                     macroAction = "Macro-" + resourceName + "-" + action + " request was executed correctly.";
229                 }
230             } else {
231                 macroAction = statusMessage;
232             }
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(Long.valueOf(100));
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);
245         }
246     }
247
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);
253         int envMaxRetries;
254         try {
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);
258             envMaxRetries = 5;
259         }
260         int nextCount = retryCount + 1;
261         if ("Retry".equals(handlingCode)) {
262             workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
263             try {
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);
270             }
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);
275             } else {
276                 workflowAction.buildAndThrowException(execution,
277                         "Exceeded maximum retries. Ending flow with status Abort");
278             }
279         } else {
280             execution.setVariable(RETRY_COUNT, 0);
281         }
282     }
283
284     /**
285      * Rollback will only handle Create/Activate/Assign Macro flows. Execute layer will rollback the flow its currently
286      * working on.
287      */
288     public void rollbackExecutionPath(DelegateExecution execution) {
289         if (!(boolean) execution.getVariable("isRollback")) {
290             List<ExecuteBuildingBlock> flowsToExecute =
291                     (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
292             List<ExecuteBuildingBlock> rollbackFlows = new ArrayList();
293             int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
294             int listSize = flowsToExecute.size();
295             for (int i = listSize - 1; i >= 0; i--) {
296                 if (i > currentSequence - 1) {
297                     flowsToExecute.remove(i);
298                 } else {
299                     String flowName = flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName();
300                     if (flowName.startsWith("Assign")) {
301                         flowName = flowName.replaceFirst("Assign", "Unassign");
302                     } else if (flowName.startsWith("Create")) {
303                         flowName = flowName.replaceFirst("Create", "Delete");
304                     } else if (flowName.startsWith("Activate")) {
305                         flowName = flowName.replaceFirst("Activate", "Deactivate");
306                     } else if (flowName.startsWith("Add")) {
307                         flowName = flowName.replaceFirst("Add", "Delete");
308                     } else {
309                         continue;
310                     }
311                     flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName);
312                     rollbackFlows.add(flowsToExecute.get(i));
313                 }
314             }
315
316             String handlingCode = (String) execution.getVariable(HANDLINGCODE);
317             List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>();
318             rollbackFlowsFiltered.addAll(rollbackFlows);
319             if ("RollbackToAssigned".equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode)) {
320                 for (int i = 0; i < rollbackFlows.size(); i++) {
321                     if (rollbackFlows.get(i).getBuildingBlock().getBpmnFlowName().contains("Unassign") && !rollbackFlows
322                             .get(i).getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")) {
323                         rollbackFlowsFiltered.remove(rollbackFlows.get(i));
324                     } else if (rollbackFlows.get(i).getBuildingBlock().getBpmnFlowName().contains("Delete")
325                             && ROLLBACKTOCREATED.equals(handlingCode)) {
326                         rollbackFlowsFiltered.remove(rollbackFlows.get(i));
327                     }
328                 }
329             }
330
331             workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
332             if (rollbackFlows.isEmpty())
333                 execution.setVariable("isRollbackNeeded", false);
334             else
335                 execution.setVariable("isRollbackNeeded", true);
336             execution.setVariable("flowsToExecute", rollbackFlowsFiltered);
337             execution.setVariable(HANDLINGCODE, "PreformingRollback");
338             execution.setVariable("isRollback", true);
339             execution.setVariable(G_CURRENT_SEQUENCE, 0);
340             execution.setVariable(RETRY_COUNT, 0);
341         } else {
342             workflowAction.buildAndThrowException(execution,
343                     "Rollback has already been called. Cannot rollback a request that is currently in the rollback state.");
344         }
345     }
346
347     protected void updateInstanceId(DelegateExecution execution) {
348         try {
349             String requestId = (String) execution.getVariable(G_REQUEST_ID);
350             String resourceId = (String) execution.getVariable("resourceId");
351             WorkflowType resourceType = (WorkflowType) execution.getVariable("resourceType");
352             InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
353             if (resourceType == WorkflowType.SERVICE) {
354                 request.setServiceInstanceId(resourceId);
355             } else if (resourceType == WorkflowType.VNF) {
356                 request.setVnfId(resourceId);
357             } else if (resourceType == WorkflowType.VFMODULE) {
358                 request.setVfModuleId(resourceId);
359             } else if (resourceType == WorkflowType.VOLUMEGROUP) {
360                 request.setVolumeGroupId(resourceId);
361             } else if (resourceType == WorkflowType.NETWORK) {
362                 request.setNetworkId(resourceId);
363             } else if (resourceType == WorkflowType.CONFIGURATION) {
364                 request.setConfigurationId(resourceId);
365             } else if (resourceType == WorkflowType.INSTANCE_GROUP) {
366                 request.setInstanceGroupId(resourceId);
367             }
368             setInstanceName(resourceId, resourceType, request);
369             request.setLastModifiedBy("CamundaBPMN");
370             requestDbclient.updateInfraActiveRequests(request);
371         } catch (Exception ex) {
372             logger.error("Exception in updateInstanceId", ex);
373             workflowAction.buildAndThrowException(execution, "Failed to update Request db with instanceId");
374         }
375     }
376
377     public void postProcessingExecuteBB(DelegateExecution execution) {
378         List<ExecuteBuildingBlock> flowsToExecute =
379                 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
380         String handlingCode = (String) execution.getVariable(HANDLINGCODE);
381         final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
382         int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
383         ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence - 1);
384         String bbFlowName = ebb.getBuildingBlock().getBpmnFlowName();
385         if ("ActivateVfModuleBB".equalsIgnoreCase(bbFlowName) && aLaCarte && "Success".equalsIgnoreCase(handlingCode)) {
386             postProcessingExecuteBBActivateVfModule(execution, ebb, flowsToExecute);
387         }
388     }
389
390     protected void postProcessingExecuteBBActivateVfModule(DelegateExecution execution, ExecuteBuildingBlock ebb,
391             List<ExecuteBuildingBlock> flowsToExecute) {
392         try {
393             String serviceInstanceId = ebb.getWorkflowResourceIds().getServiceInstanceId();
394             String vnfId = ebb.getWorkflowResourceIds().getVnfId();
395             String vfModuleId = ebb.getResourceId();
396             ebb.getWorkflowResourceIds().setVfModuleId(vfModuleId);
397             String serviceModelUUID =
398                     bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId).getModelVersionId();
399             String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
400             String vfModuleCustomizationUUID =
401                     bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
402             List<Vnfc> vnfcs =
403                     workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, AAIObjectType.VNFC);
404             logger.debug("Vnfc Size: {}", vnfcs.size());
405             for (Vnfc vnfc : vnfcs) {
406                 String modelCustomizationId = vnfc.getModelCustomizationId();
407                 logger.debug("Processing Vnfc: {}", modelCustomizationId);
408                 CvnfcConfigurationCustomization fabricConfig = catalogDbClient.getCvnfcCustomization(serviceModelUUID,
409                         vnfCustomizationUUID, vfModuleCustomizationUUID, modelCustomizationId);
410                 if (fabricConfig != null && fabricConfig.getConfigurationResource() != null
411                         && fabricConfig.getConfigurationResource().getToscaNodeType() != null
412                         && fabricConfig.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
413                     String configurationId = getConfigurationId(vnfc);
414                     ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
415                     configurationResourceKeys.setCvnfcCustomizationUUID(modelCustomizationId);
416                     configurationResourceKeys.setVfModuleCustomizationUUID(vfModuleCustomizationUUID);
417                     configurationResourceKeys.setVnfResourceCustomizationUUID(vnfCustomizationUUID);
418                     configurationResourceKeys.setVnfcName(vnfc.getVnfcName());
419                     ExecuteBuildingBlock addConfigBB = getExecuteBBForConfig(ADD_FABRIC_CONFIGURATION_BB, ebb,
420                             configurationId, configurationResourceKeys);
421                     flowsToExecute.add(addConfigBB);
422                     flowsToExecute.stream()
423                             .forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}",
424                                     executeBB.getBuildingBlock().getBpmnFlowName()));
425                     execution.setVariable("flowsToExecute", flowsToExecute);
426                     execution.setVariable(COMPLETED, false);
427                 } else {
428                     logger.debug("No cvnfcCustomization found for customizationId: {}", modelCustomizationId);
429                 }
430             }
431         } catch (EntityNotFoundException e) {
432             logger.debug("Will not be running Fabric Config Building Blocks", e);
433         } catch (Exception e) {
434             String errorMessage = "Error occurred in post processing of Vf Module create";
435             execution.setVariable(HANDLINGCODE, ROLLBACKTOCREATED);
436             execution.setVariable("WorkflowActionErrorMessage", errorMessage);
437             logger.error(errorMessage, e);
438         }
439     }
440
441     protected String getConfigurationId(Vnfc vnfc) {
442         List<Configuration> configurations =
443                 workflowAction.getRelatedResourcesInVnfc(vnfc, Configuration.class, AAIObjectType.CONFIGURATION);
444         if (!configurations.isEmpty()) {
445             Configuration configuration = configurations.get(0);
446             return configuration.getConfigurationId();
447         } else {
448             return UUID.randomUUID().toString();
449         }
450     }
451
452     protected ExecuteBuildingBlock getExecuteBBForConfig(String bbName, ExecuteBuildingBlock ebb,
453             String configurationId, ConfigurationResourceKeys configurationResourceKeys) {
454         BuildingBlock buildingBlock =
455                 new BuildingBlock().setBpmnFlowName(bbName).setMsoId(UUID.randomUUID().toString());
456
457         WorkflowResourceIds workflowResourceIds = ebb.getWorkflowResourceIds();
458         workflowResourceIds.setConfigurationId(configurationId);
459         ExecuteBuildingBlock configBB = new ExecuteBuildingBlock().setaLaCarte(ebb.isaLaCarte())
460                 .setApiVersion(ebb.getApiVersion()).setRequestAction(ebb.getRequestAction())
461                 .setVnfType(ebb.getVnfType()).setRequestId(ebb.getRequestId())
462                 .setRequestDetails(ebb.getRequestDetails()).setBuildingBlock(buildingBlock)
463                 .setWorkflowResourceIds(workflowResourceIds).setConfigurationResourceKeys(configurationResourceKeys);
464         return configBB;
465     }
466
467     protected void setInstanceName(String resourceId, WorkflowType resourceType, InfraActiveRequests request) {
468         logger.debug("Setting instanceName in infraActiveRequest");
469         try {
470             if (resourceType == WorkflowType.SERVICE && request.getServiceInstanceName() == null) {
471                 ServiceInstance service = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
472                 if (service != null) {
473                     request.setServiceInstanceName(service.getServiceInstanceName());
474                 }
475             } else if (resourceType == WorkflowType.VNF && request.getVnfName() == null) {
476                 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(resourceId);
477                 if (vnf != null) {
478                     request.setVnfName(vnf.getVnfName());
479                 }
480             } else if (resourceType == WorkflowType.VFMODULE && request.getVfModuleName() == null) {
481                 VfModule vfModule = bbInputSetupUtils.getAAIVfModule(request.getVnfId(), resourceId);
482                 if (vfModule != null) {
483                     request.setVfModuleName(vfModule.getVfModuleName());
484                 }
485             } else if (resourceType == WorkflowType.VOLUMEGROUP && request.getVolumeGroupName() == null) {
486                 Optional<VolumeGroup> volumeGroup =
487                         bbInputSetupUtils.getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
488                 if (volumeGroup.isPresent()) {
489                     request.setVolumeGroupName(volumeGroup.get().getVolumeGroupName());
490                 }
491             } else if (resourceType == WorkflowType.NETWORK && request.getNetworkName() == null) {
492                 L3Network network = bbInputSetupUtils.getAAIL3Network(resourceId);
493                 if (network != null) {
494                     request.setNetworkName(network.getNetworkName());
495                 }
496             } else if (resourceType == WorkflowType.CONFIGURATION && request.getConfigurationName() == null) {
497                 org.onap.aai.domain.yang.Configuration configuration =
498                         bbInputSetupUtils.getAAIConfiguration(resourceId);
499                 if (configuration != null) {
500                     request.setConfigurationName(configuration.getConfigurationName());
501                 }
502             } else if (resourceType == WorkflowType.INSTANCE_GROUP && request.getInstanceGroupName() == null) {
503                 InstanceGroup instanceGroup = bbInputSetupUtils.getAAIInstanceGroup(resourceId);
504                 if (instanceGroup != null) {
505                     request.setInstanceGroupName(instanceGroup.getInstanceGroupName());
506                 }
507             }
508         } catch (Exception ex) {
509             logger.error("Exception in setInstanceName", ex);
510         }
511     }
512 }