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.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;
 
  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 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);
 
  82     private RequestsDbClient requestDbclient;
 
  84     private WorkflowAction workflowAction;
 
  86     private WorkflowActionBBFailure workflowActionBBFailure;
 
  88     private Environment environment;
 
  90     private BBInputSetupUtils bbInputSetupUtils;
 
  92     private CatalogDbClient catalogDbClient;
 
  94     private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
 
  96     private RequestsDbListenerRunner requestsDbListener;
 
  98     public void selectBB(DelegateExecution execution) {
 
  99         List<ExecuteBuildingBlock> flowsToExecute =
 
 100                 (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
 
 101         execution.setVariable("MacroRollback", false);
 
 103         flowManipulatorListenerRunner.modifyFlows(flowsToExecute, new DelegateExecutionImpl(execution));
 
 104         int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
 
 106         ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence);
 
 108         execution.setVariable("buildingBlock", ebb);
 
 110         if (currentSequence >= flowsToExecute.size()) {
 
 111             execution.setVariable(COMPLETED, true);
 
 113             execution.setVariable(COMPLETED, false);
 
 115         execution.setVariable(G_CURRENT_SEQUENCE, currentSequence);
 
 118     public void updateFlowStatistics(DelegateExecution execution) {
 
 120             int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
 
 121             if (currentSequence > 1) {
 
 122                 InfraActiveRequests request = this.getUpdatedRequest(execution, currentSequence);
 
 123                 requestDbclient.updateInfraActiveRequests(request);
 
 125         } catch (Exception ex) {
 
 127                     "Bpmn Flow Statistics was unable to update Request Db with the new completion percentage. Competion percentage may be invalid.",
 
 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");
 
 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);
 
 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
 
 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 = "";
 
 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);
 
 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,
 
 187         logger.info("Successfully sent sync ack.");
 
 188         updateInstanceId(execution);
 
 191     public void sendErrorSyncAck(DelegateExecution execution) {
 
 192         final String requestId = (String) execution.getVariable(G_REQUEST_ID);
 
 194             ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
 
 195             String errorMsg = (String) execution.getVariable("WorkflowActionErrorMessage");
 
 196             if (errorMsg == null) {
 
 197                 errorMsg = "WorkflowAction failed unexpectedly.";
 
 199             String processKey = exceptionBuilder.getProcessKey(execution);
 
 200             String buildworkflowException =
 
 201                     "<aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>"
 
 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,
 
 210             execution.setVariable("sentSyncResponse", true);
 
 211         } catch (Exception ex) {
 
 212             logger.error(" Sending Sync Error Activity Failed. {}", ex.getMessage(), ex);
 
 216     public void updateRequestStatusToComplete(DelegateExecution execution) {
 
 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) {
 
 227                     macroAction = "ALaCarte-" + resourceName + "-" + action + " request was executed correctly.";
 
 229                     macroAction = "Macro-" + resourceName + "-" + action + " request was executed correctly.";
 
 232                 macroAction = statusMessage;
 
 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);
 
 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);
 
 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);
 
 261         int nextCount = retryCount + 1;
 
 262         if ("Retry".equals(handlingCode)) {
 
 263             workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
 
 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);
 
 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);
 
 277                 workflowAction.buildAndThrowException(execution,
 
 278                         "Exceeded maximum retries. Ending flow with status Abort");
 
 281             execution.setVariable(RETRY_COUNT, 0);
 
 286      * Rollback will only handle Create/Activate/Assign Macro flows. Execute layer will rollback the flow its currently
 
 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);
 
 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");
 
 310                     flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName);
 
 311                     rollbackFlows.add(flowsToExecute.get(i));
 
 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));
 
 330             workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
 
 331             if (rollbackFlows.isEmpty())
 
 332                 execution.setVariable("isRollbackNeeded", false);
 
 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);
 
 341             workflowAction.buildAndThrowException(execution,
 
 342                     "Rollback has already been called. Cannot rollback a request that is currently in the rollback state.");
 
 346     protected void updateInstanceId(DelegateExecution execution) {
 
 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);
 
 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");
 
 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);
 
 389     protected void postProcessingExecuteBBActivateVfModule(DelegateExecution execution, ExecuteBuildingBlock ebb,
 
 390             List<ExecuteBuildingBlock> flowsToExecute) {
 
 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();
 
 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);
 
 430                     logger.debug("No cvnfcCustomization found for customizationId: {}", modelCustomizationId);
 
 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);
 
 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();
 
 450             return UUID.randomUUID().toString();
 
 454     protected ExecuteBuildingBlock getExecuteBBForConfig(String bbName, ExecuteBuildingBlock ebb,
 
 455             String configurationId, ConfigurationResourceKeys configurationResourceKeys) {
 
 456         ExecuteBuildingBlock configBB = new ExecuteBuildingBlock();
 
 457         BuildingBlock buildingBlock = new BuildingBlock();
 
 458         buildingBlock.setBpmnFlowName(bbName);
 
 459         buildingBlock.setMsoId(UUID.randomUUID().toString());
 
 460         configBB.setaLaCarte(ebb.isaLaCarte());
 
 461         configBB.setApiVersion(ebb.getApiVersion());
 
 462         configBB.setRequestAction(ebb.getRequestAction());
 
 463         configBB.setVnfType(ebb.getVnfType());
 
 464         configBB.setRequestId(ebb.getRequestId());
 
 465         configBB.setRequestDetails(ebb.getRequestDetails());
 
 466         configBB.setBuildingBlock(buildingBlock);
 
 467         WorkflowResourceIds workflowResourceIds = ebb.getWorkflowResourceIds();
 
 468         workflowResourceIds.setConfigurationId(configurationId);
 
 469         configBB.setWorkflowResourceIds(workflowResourceIds);
 
 470         configBB.setConfigurationResourceKeys(configurationResourceKeys);
 
 474     protected void setInstanceName(String resourceId, WorkflowType resourceType, InfraActiveRequests request) {
 
 475         logger.debug("Setting instanceName in infraActiveRequest");
 
 477             if (resourceType == WorkflowType.SERVICE && request.getServiceInstanceName() == null) {
 
 478                 ServiceInstance service = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
 
 479                 if (service != null) {
 
 480                     request.setServiceInstanceName(service.getServiceInstanceName());
 
 482             } else if (resourceType == WorkflowType.VNF && request.getVnfName() == null) {
 
 483                 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(resourceId);
 
 485                     request.setVnfName(vnf.getVnfName());
 
 487             } else if (resourceType == WorkflowType.VFMODULE && request.getVfModuleName() == null) {
 
 488                 VfModule vfModule = bbInputSetupUtils.getAAIVfModule(request.getVnfId(), resourceId);
 
 489                 if (vfModule != null) {
 
 490                     request.setVfModuleName(vfModule.getVfModuleName());
 
 492             } else if (resourceType == WorkflowType.VOLUMEGROUP && request.getVolumeGroupName() == null) {
 
 493                 Optional<VolumeGroup> volumeGroup =
 
 494                         bbInputSetupUtils.getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
 
 495                 if (volumeGroup.isPresent()) {
 
 496                     request.setVolumeGroupName(volumeGroup.get().getVolumeGroupName());
 
 498             } else if (resourceType == WorkflowType.NETWORK && request.getNetworkName() == null) {
 
 499                 L3Network network = bbInputSetupUtils.getAAIL3Network(resourceId);
 
 500                 if (network != null) {
 
 501                     request.setNetworkName(network.getNetworkName());
 
 503             } else if (resourceType == WorkflowType.CONFIGURATION && request.getConfigurationName() == null) {
 
 504                 org.onap.aai.domain.yang.Configuration configuration =
 
 505                         bbInputSetupUtils.getAAIConfiguration(resourceId);
 
 506                 if (configuration != null) {
 
 507                     request.setConfigurationName(configuration.getConfigurationName());
 
 509             } else if (resourceType == WorkflowType.INSTANCE_GROUP && request.getInstanceGroupName() == null) {
 
 510                 InstanceGroup instanceGroup = bbInputSetupUtils.getAAIInstanceGroup(resourceId);
 
 511                 if (instanceGroup != null) {
 
 512                     request.setInstanceGroupName(instanceGroup.getInstanceGroupName());
 
 515         } catch (Exception ex) {
 
 516             logger.error("Exception in setInstanceName", ex);