d87b11a1a6125fc06b86a72037b1f39035b28cd1
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / workflow / tasks / WorkflowAction.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.workflow.tasks;
24
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Collections;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Optional;
32 import java.util.UUID;
33 import java.util.regex.Matcher;
34 import java.util.regex.Pattern;
35 import java.util.stream.Collectors;
36
37 import org.camunda.bpm.engine.delegate.DelegateExecution;
38 import org.javatuples.Pair;
39 import org.slf4j.LoggerFactory;
40 import org.onap.aai.domain.yang.GenericVnf;
41 import org.onap.aai.domain.yang.L3Network;
42 import org.onap.aai.domain.yang.Relationship;
43 import org.onap.aai.domain.yang.ServiceInstance;
44 import org.onap.aai.domain.yang.VolumeGroup;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
47 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
48 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
49 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
50 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
51 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
52 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
53 import org.onap.so.client.aai.AAICommonObjectMapperProvider;
54 import org.onap.so.client.aai.entities.AAIResultWrapper;
55 import org.onap.so.client.aai.entities.Relationships;
56 import org.onap.so.client.exception.ExceptionBuilder;
57 import org.onap.so.client.orchestration.AAIConfigurationResources;
58 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
59 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
60 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
61 import org.onap.so.db.catalog.beans.CvnfcCustomization;
62 import org.onap.so.db.catalog.beans.VfModuleCustomization;
63 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
64 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
65 import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
66 import org.onap.so.db.catalog.client.CatalogDbClient;
67 import org.onap.so.serviceinstancebeans.ModelInfo;
68 import org.onap.so.serviceinstancebeans.ModelType;
69 import org.onap.so.serviceinstancebeans.Networks;
70 import org.onap.so.serviceinstancebeans.RelatedInstance;
71 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
72 import org.onap.so.serviceinstancebeans.RequestDetails;
73 import org.onap.so.serviceinstancebeans.Service;
74 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
75 import org.onap.so.serviceinstancebeans.VfModules;
76 import org.onap.so.serviceinstancebeans.Vnfs;
77 import org.slf4j.Logger;
78 import org.springframework.beans.factory.annotation.Autowired;
79 import org.springframework.core.env.Environment;
80 import org.springframework.stereotype.Component;
81
82 import com.fasterxml.jackson.databind.ObjectMapper;
83
84 @Component
85 public class WorkflowAction {
86
87         private static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage";
88         private static final String SERVICE_INSTANCES = "serviceInstances";
89         private static final String VF_MODULES = "vfModules";
90         private static final String WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI = "WorkflowAction was unable to verify if the instance name already exist in AAI.";
91         private static final String G_ORCHESTRATION_FLOW = "gOrchestrationFlow";
92         private static final String G_ACTION = "requestAction";
93         private static final String G_CURRENT_SEQUENCE = "gCurrentSequence";
94         private static final String G_REQUEST_ID = "mso-request-id";
95         private static final String G_BPMN_REQUEST = "bpmnRequest";
96         private static final String G_ALACARTE = "aLaCarte";
97         private static final String G_APIVERSION = "apiVersion";
98         private static final String G_URI = "requestUri";
99         private static final String G_ISTOPLEVELFLOW = "isTopLevelFlow";
100         private static final String VNF_TYPE = "vnfType";
101         private static final String SERVICE = "Service";
102         private static final String VNF = "Vnf";
103         private static final String VFMODULE = "VfModule";
104         private static final String VOLUMEGROUP = "VolumeGroup";
105         private static final String NETWORK = "Network";
106         private static final String NETWORKCOLLECTION = "NetworkCollection";
107         private static final String CONFIGURATION = "Configuration";
108         private static final String ASSIGNINSTANCE = "assignInstance";
109         private static final String CREATEINSTANCE = "createInstance";
110         private static final String USERPARAMSERVICE = "service";
111         private static final String supportedTypes = "vnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups";
112         private static final String HOMINGSOLUTION = "Homing_Solution";
113         private static final String FABRIC_CONFIGURATION = "FabricConfiguration";
114         private static final String G_SERVICE_TYPE = "serviceType";
115         private static final String SERVICE_TYPE_TRANSPORT = "TRANSPORT";
116         private static final Logger logger = LoggerFactory.getLogger(WorkflowAction.class);
117         
118         @Autowired
119         protected BBInputSetup bbInputSetup;
120         @Autowired
121         protected BBInputSetupUtils bbInputSetupUtils;
122         @Autowired
123         private ExceptionBuilder exceptionBuilder;
124         @Autowired
125         private CatalogDbClient catalogDbClient;
126         @Autowired
127         private AAIConfigurationResources aaiConfigurationResources;
128         @Autowired
129         private WorkflowActionExtractResourcesAAI workflowActionUtils;
130
131         @Autowired
132         private Environment environment;
133         private String defaultCloudOwner = "org.onap.so.cloud-owner";
134
135         public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
136                 this.bbInputSetupUtils = bbInputSetupUtils;
137         }
138
139         public void setBbInputSetup(BBInputSetup bbInputSetup) {
140                 this.bbInputSetup = bbInputSetup;
141         }
142
143         public void selectExecutionList(DelegateExecution execution) throws Exception {
144                 final String requestAction = (String) execution.getVariable(G_ACTION);
145                 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
146                 final String bpmnRequest = (String) execution.getVariable(G_BPMN_REQUEST);
147                 final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
148                 final String apiVersion = (String) execution.getVariable(G_APIVERSION);
149                 final String uri = (String) execution.getVariable(G_URI);
150                 final String vnfType = (String) execution.getVariable(VNF_TYPE);
151                 String serviceInstanceId = (String) execution.getVariable("serviceInstanceId");
152                 final String serviceType = Optional.ofNullable((String) execution.getVariable(G_SERVICE_TYPE)).orElse("");
153
154                 List<OrchestrationFlow> orchFlows = (List<OrchestrationFlow>) execution.getVariable(G_ORCHESTRATION_FLOW);
155                 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
156                 WorkflowResourceIds workflowResourceIds = populateResourceIdsFromApiHandler(execution);
157                 List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
158                 List<Resource> resourceCounter = new ArrayList<>();
159                 execution.setVariable("sentSyncResponse", false);
160                 execution.setVariable("homing", false);
161                 execution.setVariable("calledHoming", false);
162
163                 try {
164                         ObjectMapper mapper = new ObjectMapper();
165                         execution.setVariable(G_ISTOPLEVELFLOW, true);
166                         ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
167                         RequestDetails requestDetails = sIRequest.getRequestDetails();
168                         String cloudOwner = "";
169                         try{
170                                 cloudOwner = requestDetails.getCloudConfiguration().getCloudOwner();
171                         } catch (Exception ex) {
172                                 cloudOwner = environment.getProperty(defaultCloudOwner);
173                         }
174                         boolean suppressRollback = false;
175                         try{
176                                 suppressRollback = requestDetails.getRequestInfo().getSuppressRollback();
177                         } catch (Exception ex) {
178                                 suppressRollback = false;
179                         }
180                         execution.setVariable("suppressRollback", suppressRollback);
181                         Resource resource = extractResourceIdAndTypeFromUri(uri);
182                         WorkflowType resourceType = resource.getResourceType();
183                         execution.setVariable("resourceName", resourceType.toString());
184                         String resourceId = "";
185                         if (resource.isGenerated()) {
186                                 resourceId = validateResourceIdInAAI(resource.getResourceId(), resourceType,
187                                                 sIRequest.getRequestDetails().getRequestInfo().getInstanceName(), sIRequest.getRequestDetails(),
188                                                 workflowResourceIds);
189                         } else {
190                                 resourceId = resource.getResourceId();
191                         }
192                         if((serviceInstanceId == null || serviceInstanceId.equals("")) && resourceType == WorkflowType.SERVICE){
193                                 serviceInstanceId = resourceId;
194                         }
195                         execution.setVariable("resourceId", resourceId);
196                         execution.setVariable("resourceType", resourceType);
197
198                         if (aLaCarte) {
199                                 if (orchFlows == null || orchFlows.isEmpty()) {
200                                                 orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, cloudOwner, serviceType);
201                                 }
202                                 orchFlows = filterOrchFlows(sIRequest, orchFlows, resourceType, execution);
203                                 String key = "";
204                                 ModelInfo modelInfo = sIRequest.getRequestDetails().getModelInfo();
205                                 if(modelInfo != null) {
206                                         if(modelInfo.getModelType().equals(ModelType.service)) {
207                                                 key = modelInfo.getModelVersionId();
208                                         } else {
209                                                 key = modelInfo.getModelCustomizationId();
210                                         }
211                                 }
212                                 boolean isConfiguration = isConfiguration(orchFlows);
213                                 Resource resourceKey = new Resource(resourceType, key, aLaCarte);
214                                 List<ExecuteBuildingBlock> configBuildingBlocks = getConfigBuildingBlocks(sIRequest, orchFlows, requestId, resourceKey, apiVersion, resourceId, requestAction, aLaCarte, vnfType,
215                                                 workflowResourceIds, requestDetails, isConfiguration);
216                                 for (OrchestrationFlow orchFlow : orchFlows) {
217                                         if(!orchFlow.getFlowName().contains("Configuration")) {
218                                                 ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, resourceId,
219                                                                 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false);
220                                                 flowsToExecute.add(ebb);
221                                         }
222                                 }
223                                 flowsToExecute.addAll(configBuildingBlocks);
224                         } else {
225                                 boolean foundRelated = false;
226                                 boolean containsService = false;
227                                 if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(ASSIGNINSTANCE)) {
228                                         // SERVICE-MACRO-ASSIGN will always get user params with a
229                                         // service.
230                                         if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
231                                                 List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters()
232                                                                 .getUserParams();
233                                                 for (Map<String, Object> params : userParams) {
234                                                         if (params.containsKey(USERPARAMSERVICE)) {
235                                                                 containsService = true;
236                                                         }
237                                                 }
238                                                 if (containsService) {
239                                                         traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction);
240                                                 }
241                                         } else {
242                                                 buildAndThrowException(execution,
243                                                                 "Service-Macro-Assign request details must contain user params with a service");
244                                         }
245                                 } else if (resourceType == WorkflowType.SERVICE
246                                                 && requestAction.equalsIgnoreCase(CREATEINSTANCE)) {
247                                         // SERVICE-MACRO-CREATE will get user params with a service,
248                                         // a service with a network, a service with a
249                                         // networkcollection, OR an empty service.
250                                         // If user params is just a service or null and macro
251                                         // queries the SI and finds a VNF, macro fails.
252
253                                         if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
254                                                 List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters()
255                                                                 .getUserParams();
256                                                 for (Map<String, Object> params : userParams) {
257                                                         if (params.containsKey(USERPARAMSERVICE)) {
258                                                                 containsService = true;
259                                                         }
260                                                 }
261                                         }
262                                         if (containsService) {
263                                                 foundRelated = traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction);
264                                         }
265                                         if (!foundRelated) {
266                                                 traverseCatalogDbService(execution, sIRequest, resourceCounter);
267                                         }
268                                 } else if (resourceType == WorkflowType.SERVICE
269                                                 && (requestAction.equalsIgnoreCase("activateInstance")
270                                                                 || requestAction.equalsIgnoreCase("unassignInstance")
271                                                                 || requestAction.equalsIgnoreCase("deleteInstance")
272                                                                 || requestAction.equalsIgnoreCase("activate" + FABRIC_CONFIGURATION))) {
273                                         // SERVICE-MACRO-ACTIVATE, SERVICE-MACRO-UNASSIGN, and
274                                         // SERVICE-MACRO-DELETE
275                                         // Will never get user params with service, macro will have
276                                         // to query the SI in AAI to find related instances.
277                                         traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds);
278                                 } else if (resourceType == WorkflowType.SERVICE
279                                                 && requestAction.equalsIgnoreCase("deactivateInstance")) {
280                                         resourceCounter.add(new Resource(WorkflowType.SERVICE,"",false));
281                                 } else if (resourceType == WorkflowType.VNF && (requestAction.equalsIgnoreCase("replaceInstance") || (requestAction.equalsIgnoreCase("recreateInstance")))) {
282                                         traverseAAIVnf(execution, resourceCounter, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds);
283                                 } else {
284                                         buildAndThrowException(execution, "Current Macro Request is not supported");
285                                 }
286                                 String foundObjects = "";
287                                 for(WorkflowType type : WorkflowType.values()){
288                                         foundObjects = foundObjects + type + " - " + resourceCounter.stream().filter(x -> type.equals(x.getResourceType())).collect(Collectors.toList()).size() + "    ";
289                                 }
290                                 logger.info("Found {}", foundObjects);
291
292                                 if (orchFlows == null || orchFlows.isEmpty()) {
293                                         orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, cloudOwner, serviceType);
294                                 }
295                                 flowsToExecute = buildExecuteBuildingBlockList(orchFlows, resourceCounter, requestId, apiVersion, resourceId,
296                                                 resourceType, requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails);
297                                 if (!resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()).collect(Collectors.toList()).isEmpty()) {
298                                         logger.info("Sorting for Vlan Tagging");
299                                         flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction);
300                                 }
301                                 // By default, enable homing at VNF level for CREATEINSTANCE and ASSIGNINSTANCE
302                                 if (resourceType == WorkflowType.SERVICE
303                                         && (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE))
304                                         && !resourceCounter.stream().filter(x -> WorkflowType.VNF.equals(x.getResourceType())).collect(Collectors.toList()).isEmpty()) {
305                                         execution.setVariable("homing", true);
306                                         execution.setVariable("calledHoming", false);
307                                 }
308                                 if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) || requestAction.equalsIgnoreCase(CREATEINSTANCE))){
309                                         generateResourceIds(flowsToExecute, resourceCounter, serviceInstanceId);
310                                 }else{
311                                         updateResourceIdsFromAAITraversal(flowsToExecute, resourceCounter, aaiResourceIds, serviceInstanceId);
312                                 }
313                         }
314
315                         // If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is specified, enable it.                      
316                         if (sIRequest.getRequestDetails().getRequestParameters() != null && 
317                                         sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
318                                 List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams();
319                                 for (Map<String, Object> params : userParams) {
320                                         if (params.containsKey(HOMINGSOLUTION)) {
321                                                 if (params.get(HOMINGSOLUTION).equals("none")) {
322                                                         execution.setVariable("homing", false);
323                                                 } else {
324                                                         execution.setVariable("homing", true);
325                                                 }
326                                         }
327                                 }
328                         }
329
330                         if (flowsToExecute.isEmpty()) {
331                                 throw new IllegalStateException("Macro did not come up with a valid execution path.");
332                         }
333                         List<String> flowNames = new ArrayList<>();
334                         logger.info("List of BuildingBlocks to execute:");
335                         for (ExecuteBuildingBlock ebb : flowsToExecute) {
336                                 logger.info(ebb.getBuildingBlock().getBpmnFlowName());
337                                 flowNames.add(ebb.getBuildingBlock().getBpmnFlowName());
338                         }
339                         execution.setVariable("flowNames", flowNames);
340                         execution.setVariable(G_CURRENT_SEQUENCE, 0);
341                         execution.setVariable("retryCount", 0);
342                         execution.setVariable("isRollback", false);
343                         execution.setVariable("flowsToExecute", flowsToExecute);
344                         execution.setVariable("isRollbackComplete", false);
345
346                 } catch (Exception ex) {
347                         buildAndThrowException(execution, "Exception in create execution list " + ex.getMessage(), ex);
348                 }
349         }
350         
351         protected boolean isConfiguration(List<OrchestrationFlow> orchFlows) {
352                 for(OrchestrationFlow flow : orchFlows) {
353                         if(flow.getFlowName().contains("Configuration")) {
354                                 return true;
355                         }
356                 }
357                 return false;
358         }
359
360         protected List<ExecuteBuildingBlock> getConfigBuildingBlocks(ServiceInstancesRequest sIRequest, List<OrchestrationFlow> orchFlows, String requestId, Resource resourceKey,
361                         String apiVersion, String resourceId, String requestAction, boolean aLaCarte, String vnfType,
362                         WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, boolean isConfiguration) {
363                 List<OrchestrationFlow> result = new ArrayList<>(orchFlows);
364                 result = orchFlows.stream().filter(item -> item.getFlowName().contains(FABRIC_CONFIGURATION)).collect(Collectors.toList());
365                 String vnfCustomizationUUID = "";
366                 String vfModuleCustomizationUUID = sIRequest.getRequestDetails().getModelInfo().getModelCustomizationUuid();
367                 RelatedInstanceList[] relatedInstanceList = sIRequest.getRequestDetails().getRelatedInstanceList();
368                 if (relatedInstanceList != null) {
369                         for (RelatedInstanceList relatedInstList : relatedInstanceList) {
370                                 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
371                                 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
372                                         vnfCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationUuid();
373                                 }
374                         }
375                 }
376                 
377                 List<VnfVfmoduleCvnfcConfigurationCustomization> fabricCustomizations = traverseCatalogDbForConfiguration(vnfCustomizationUUID, vfModuleCustomizationUUID);
378                 List<ExecuteBuildingBlock> flowsToExecuteConfigs = new ArrayList<>();
379                 for(VnfVfmoduleCvnfcConfigurationCustomization fabricConfig : fabricCustomizations) {
380                         
381                         if (requestAction.equals(CREATEINSTANCE)) {
382                                 workflowResourceIds.setConfigurationId(UUID.randomUUID().toString());
383                         } else {
384                                 //TODO AAI lookup for configuration update/delete
385                         }
386                         for(OrchestrationFlow orchFlow : result) {
387                                 resourceKey.setVfModuleCustomizationId(vfModuleCustomizationUUID);
388                                 resourceKey.setCvnfModuleCustomizationId(fabricConfig.getCvnfcCustomization().getModelCustomizationUUID());
389                                 resourceKey.setVnfCustomizationId(vnfCustomizationUUID);
390                                 ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, resourceId,
391                                                 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, true);
392                                 flowsToExecuteConfigs.add(ebb);
393                         }
394                 }
395                 return flowsToExecuteConfigs;
396         }
397
398         protected List<Resource> sortVfModulesByBaseFirst(List<Resource> vfModuleResources) {
399                 int count = 0;
400                 for(Resource resource : vfModuleResources){
401                         if(resource.isBaseVfModule()){
402                                 Collections.swap(vfModuleResources, 0, count);
403                                 break;
404                 }
405                         count++;
406                 }
407                 return vfModuleResources;
408         }
409         
410         protected List<Resource> sortVfModulesByBaseLast(List<Resource> vfModuleResources) {
411                 int count = 0;
412                 for(Resource resource : vfModuleResources){
413                         if(resource.isBaseVfModule()){
414                                 Collections.swap(vfModuleResources, vfModuleResources.size()-1, count);
415                                 break;
416                 }
417                         count++;
418                 }
419                 return vfModuleResources;
420         }
421
422         private void updateResourceIdsFromAAITraversal(List<ExecuteBuildingBlock> flowsToExecute,
423                         List<Resource> resourceCounter, List<Pair<WorkflowType, String>> aaiResourceIds, String serviceInstanceId) {
424                 for(Pair<WorkflowType,String> pair : aaiResourceIds){
425                         logger.debug(pair.getValue0() + ", " + pair.getValue1());
426                 }
427                 
428                 Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)).forEach(type -> {
429                         List<Resource> resources = resourceCounter.stream().filter(x -> type.equals(x.getResourceType())).collect(Collectors.toList());
430                         for(int i = 0; i < resources.size(); i++){
431                                 updateWorkflowResourceIds(flowsToExecute, type, resources.get(i).getResourceId(), retrieveAAIResourceId(aaiResourceIds,type), null, serviceInstanceId);
432                 }
433                 });
434         }
435
436         private String retrieveAAIResourceId(List<Pair<WorkflowType, String>> aaiResourceIds, WorkflowType resource){
437                 String id = null;
438                 for(int i = 0; i<aaiResourceIds.size();i++){
439                         if(aaiResourceIds.get(i).getValue0() == resource){
440                                 id = aaiResourceIds.get(i).getValue1();
441                                 aaiResourceIds.remove(i);
442                                 break;
443                         }
444                 }
445                 return id;
446         }
447         private void generateResourceIds(List<ExecuteBuildingBlock> flowsToExecute, List<Resource> resourceCounter, String serviceInstanceId) {
448                 Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)).forEach(type -> {
449                         List<Resource> resources = resourceCounter.stream().filter(x -> type.equals(x.getResourceType())).collect(Collectors.toList());
450                         for(int i = 0; i < resources.size(); i++){
451                                 Resource resource = resourceCounter.stream().filter(x -> type.equals(x.getResourceType()))
452                                                 .collect(Collectors.toList()).get(i);
453                                 updateWorkflowResourceIds(flowsToExecute, type, resource.getResourceId(), null, resource.getVirtualLinkKey(),serviceInstanceId);
454                         }
455                 });
456         }       
457         
458         protected void updateWorkflowResourceIds(List<ExecuteBuildingBlock> flowsToExecute, WorkflowType resource, String key, String id, String virtualLinkKey, String serviceInstanceId){
459                 String resourceId = id;
460                 if(resourceId==null){
461                         resourceId = UUID.randomUUID().toString();
462                 }
463                 for(ExecuteBuildingBlock ebb : flowsToExecute){
464                         if(key != null && key.equalsIgnoreCase(ebb.getBuildingBlock().getKey()) && ebb.getBuildingBlock().getBpmnFlowName().contains(resource.toString())){
465                                 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
466                                 workflowResourceIds.setServiceInstanceId(serviceInstanceId);
467                                 if(resource == WorkflowType.VNF){
468                                         workflowResourceIds.setVnfId(resourceId);
469                                 }else if(resource == WorkflowType.VFMODULE){
470                                         workflowResourceIds.setVfModuleId(resourceId);
471                                 }else if(resource == WorkflowType.VOLUMEGROUP){
472                                         workflowResourceIds.setVolumeGroupId(resourceId);
473                                 }else if(resource == WorkflowType.NETWORK){
474                                         workflowResourceIds.setNetworkId(resourceId);
475                                 }else if(resource == WorkflowType.NETWORKCOLLECTION){
476                                         workflowResourceIds.setNetworkCollectionId(resourceId);
477                                 }else if(resource == WorkflowType.CONFIGURATION){
478                                         workflowResourceIds.setConfigurationId(resourceId);
479                                 }
480                                 ebb.setWorkflowResourceIds(workflowResourceIds);
481                         }
482                         if(virtualLinkKey != null && ebb.getBuildingBlock().getIsVirtualLink() 
483                                         && virtualLinkKey.equalsIgnoreCase(ebb.getBuildingBlock().getVirtualLinkKey())) {
484                                 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
485                                 workflowResourceIds.setServiceInstanceId(serviceInstanceId);
486                                 workflowResourceIds.setNetworkId(resourceId);
487                                 ebb.setWorkflowResourceIds(workflowResourceIds);
488                         }
489                 }
490         }
491
492         protected CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution, org.onap.so.db.catalog.beans.Service service) {
493                 CollectionResourceCustomization networkCollection = null;
494                 int count = 0;
495                 for(CollectionResourceCustomization collectionCust : service.getCollectionResourceCustomizations()){
496                         if(catalogDbClient.getNetworkCollectionResourceCustomizationByID(collectionCust.getModelCustomizationUUID()) != null) {
497                                 networkCollection = collectionCust;
498                                 count++;
499                         }
500                 }
501                 if(count == 0){
502                         return null;
503                 }else if(count > 1) {
504                         buildAndThrowException(execution, "Found multiple Network Collections in the Service model, only one per Service is supported.");
505                 }
506                 return networkCollection;
507         }
508         
509         protected void traverseCatalogDbService(DelegateExecution execution, ServiceInstancesRequest sIRequest,
510                         List<Resource> resourceCounter) {
511                 String modelUUID = sIRequest.getRequestDetails().getModelInfo().getModelVersionId();
512                 org.onap.so.db.catalog.beans.Service service = catalogDbClient.getServiceByID(modelUUID);
513                 if (service == null) {
514                         buildAndThrowException(execution, "Could not find the service model in catalog db.");
515                 } else {
516                         resourceCounter.add(new Resource(WorkflowType.SERVICE,service.getModelUUID(),false));
517                         if (service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty()) {
518                                 List<CollectionResourceCustomization> customizations = service.getCollectionResourceCustomizations();
519                                 if(customizations.isEmpty()) {
520                                         logger.debug("No Collections found. CollectionResourceCustomization list is empty.");
521                                 }else{
522                                         CollectionResourceCustomization collectionResourceCustomization = findCatalogNetworkCollection(execution, service);
523                                         if(collectionResourceCustomization!=null){
524                                                 resourceCounter.add(new Resource(WorkflowType.NETWORKCOLLECTION,collectionResourceCustomization.getModelCustomizationUUID(),false));
525                                                 logger.debug("Found a network collection");
526                                                 if(collectionResourceCustomization.getCollectionResource()!=null){
527                                                         if(collectionResourceCustomization.getCollectionResource().getInstanceGroup() != null){
528                                                                 String toscaNodeType = collectionResourceCustomization.getCollectionResource().getInstanceGroup().getToscaNodeType();
529                                                                 if (toscaNodeType != null && toscaNodeType.contains("NetworkCollection")) {
530                                                                         int minNetworks = 0;
531                                                                         org.onap.so.db.catalog.beans.InstanceGroup instanceGroup = collectionResourceCustomization.getCollectionResource().getInstanceGroup();
532                                                                         CollectionResourceInstanceGroupCustomization collectionInstCust = null;
533                                                                         if(!instanceGroup.getCollectionInstanceGroupCustomizations().isEmpty()) {
534                                                                                 for(CollectionResourceInstanceGroupCustomization collectionInstanceGroupTemp : instanceGroup.getCollectionInstanceGroupCustomizations()) {
535                                                                                         if(collectionInstanceGroupTemp.getModelCustomizationUUID().equalsIgnoreCase(collectionResourceCustomization.getModelCustomizationUUID())) {
536                                                                                                 collectionInstCust = collectionInstanceGroupTemp;
537                                                                                                 break;
538                                                                                         }
539                                                                                 }
540                                                                                 if(collectionInstCust != null && collectionInstCust.getSubInterfaceNetworkQuantity() != null) {
541                                                                                         minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity();
542                                                                                 }
543                                                                         }
544                                                                         logger.debug("minNetworks: {}" , minNetworks);
545                                                                         CollectionNetworkResourceCustomization collectionNetworkResourceCust = null;
546                                                                         for(CollectionNetworkResourceCustomization collectionNetworkTemp : instanceGroup.getCollectionNetworkResourceCustomizations()) {
547                                                                                 if(collectionNetworkTemp.getNetworkResourceCustomization().getModelCustomizationUUID().equalsIgnoreCase(collectionResourceCustomization.getModelCustomizationUUID())) {
548                                                                                         collectionNetworkResourceCust = collectionNetworkTemp;
549                                                                                         break;
550                                                                                 }
551                                                                         }
552                                                                         for (int i = 0; i < minNetworks; i++) {
553                                                                                 if(collectionNetworkResourceCust != null && collectionInstCust != null) {
554                                                                                         Resource resource = new Resource(WorkflowType.VIRTUAL_LINK,collectionNetworkResourceCust.getModelCustomizationUUID(),false);
555                                                                                         resource.setVirtualLinkKey(Integer.toString(i));
556                                                                                         resourceCounter.add(resource);
557                                                                                 }
558                                                                         }
559                                                                 } else {
560                                                                         logger.debug("Instance Group tosca node type does not contain NetworkCollection:  {}" , toscaNodeType);
561                                                                 }
562                                                         }else{
563                                                                 logger.debug("No Instance Group found for network collection.");
564                                                         }
565                                                 }else{
566                                                         logger.debug("No Network Collection found. collectionResource is null");
567                                                 }
568                                         } else {
569                                                 logger.debug("No Network Collection Customization found");
570                                         }
571                                 }
572                                 if (resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()).collect(Collectors.toList()).isEmpty()) {
573                                         if (service.getNetworkCustomizations() == null) {
574                                                 logger.debug("No networks were found on this service model");
575                                         } else {
576                                                 for (int i = 0; i < service.getNetworkCustomizations().size(); i++) {
577                                                         resourceCounter.add(new Resource(WorkflowType.NETWORK,service.getNetworkCustomizations().get(i).getModelCustomizationUUID(),false));
578                                                 }
579                                         }
580                                 }
581                         } else {
582                                 buildAndThrowException(execution,
583                                                 "Cannot orchestrate Service-Macro-Create without user params with a vnf. Please update ASDC model for new macro orchestration support or add service_recipe records to route to old macro flows");
584                         }
585                 }
586         }
587
588         protected void traverseAAIService(DelegateExecution execution, List<Resource> resourceCounter, String resourceId, List<Pair<WorkflowType, String>> aaiResourceIds) {
589                 try {
590                         ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
591                         org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = bbInputSetup
592                                         .getExistingServiceInstance(serviceInstanceAAI);
593                         resourceCounter.add(new Resource(WorkflowType.SERVICE,serviceInstanceMSO.getServiceInstanceId(),false));
594                         if (serviceInstanceMSO.getVnfs() != null) {
595                                 for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO
596                                                 .getVnfs()) {
597                                         aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VNF, vnf.getVnfId()));
598                                         resourceCounter.add(new Resource(WorkflowType.VNF,vnf.getVnfId(),false));
599                                         if (vnf.getVfModules() != null) {
600                                                 for (VfModule vfModule : vnf.getVfModules()) {
601                                                         aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
602                                                         resourceCounter.add(new Resource(WorkflowType.VFMODULE,vfModule.getVfModuleId(),false));
603                                                 }
604                                         }
605                                         if (vnf.getVolumeGroups() != null) {
606                                                 for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
607                                                                 .getVolumeGroups()) {
608                                                         aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
609                                                         resourceCounter.add(new Resource(WorkflowType.VOLUMEGROUP,volumeGroup.getVolumeGroupId(),false));
610                                                 }
611                                         }
612                                 }
613                         }
614                         if (serviceInstanceMSO.getNetworks() != null) {
615                                 for (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network : serviceInstanceMSO
616                                                 .getNetworks()) {
617                                         aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.NETWORK, network.getNetworkId()));
618                                         resourceCounter.add(new Resource(WorkflowType.NETWORK,network.getNetworkId(),false));
619                                 }
620                         }
621                         if (serviceInstanceMSO.getCollection() != null) {
622                                 logger.debug("found networkcollection");
623                                 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.NETWORKCOLLECTION, serviceInstanceMSO.getCollection().getId()));
624                                 resourceCounter.add(new Resource(WorkflowType.NETWORKCOLLECTION,serviceInstanceMSO.getCollection().getId(),false));
625                         }
626                         if (serviceInstanceMSO.getConfigurations() !=null) {
627                                 for(Configuration config : serviceInstanceMSO.getConfigurations()){
628                                         Optional<org.onap.aai.domain.yang.Configuration> aaiConfig = aaiConfigurationResources.getConfiguration(config.getConfigurationId());
629                                         if(aaiConfig.isPresent() && aaiConfig.get().getRelationshipList()!=null){
630                                                 for(Relationship relationship : aaiConfig.get().getRelationshipList().getRelationship()){
631                                                         if(relationship.getRelatedTo().contains("vnfc")){
632                                                                 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, config.getConfigurationId()));
633                                                                 resourceCounter.add(new Resource(WorkflowType.CONFIGURATION,config.getConfigurationId(),false));
634                                                                 break;
635                                                         }
636                                                 }
637                                         }
638                                 }
639                         }
640                 } catch (Exception ex) {
641                         buildAndThrowException(execution,
642                                         "Could not find existing Service Instance or related Instances to execute the request on.");
643                 }
644         }
645
646         private void traverseAAIVnf(DelegateExecution execution, List<Resource> resourceCounter, String serviceId, String vnfId,
647                         List<Pair<WorkflowType, String>> aaiResourceIds) {
648                 try{
649                         ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId);
650                         org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = bbInputSetup
651                                         .getExistingServiceInstance(serviceInstanceAAI);
652                         resourceCounter.add(new Resource(WorkflowType.SERVICE,serviceInstanceMSO.getServiceInstanceId(),false));
653                         if (serviceInstanceMSO.getVnfs() != null) {
654                                 for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO
655                                                 .getVnfs()) {
656                                         if(vnf.getVnfId().equals(vnfId)){
657                                                 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VNF, vnf.getVnfId()));
658                                                 resourceCounter.add(new Resource(WorkflowType.VNF,vnf.getVnfId(),false));
659                                                 if (vnf.getVfModules() != null) {
660                                                         for (VfModule vfModule : vnf.getVfModules()) {
661                                                                 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
662                                                                 resourceCounter.add(new Resource(WorkflowType.VFMODULE,vfModule.getVfModuleId(),false));        
663                                                                 findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(), resourceCounter, aaiResourceIds);
664                                                         }
665                                                 }
666                                                 if (vnf.getVolumeGroups() != null) {
667                                                         for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
668                                                                         .getVolumeGroups()) {
669                                                                 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
670                                                                 resourceCounter.add(new Resource(WorkflowType.VOLUMEGROUP,volumeGroup.getVolumeGroupId(),false));
671                                                         }
672                                                 }
673                                                 break;
674                                         }
675                                 }
676                         }
677                 } catch (Exception ex) {
678                         buildAndThrowException(execution,
679                                         "Could not find existing Vnf or related Instances to execute the request on.");
680                 }
681         }
682
683         private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, List<Resource> resourceCounter, 
684                         List<Pair<WorkflowType, String>> aaiResourceIds) {
685                 try{
686                         org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId);
687                         AAIResultWrapper vfModuleWrapper = new AAIResultWrapper(
688                                         new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule));
689                         Optional<Relationships> relationshipsOp;
690                         relationshipsOp = vfModuleWrapper.getRelationships();
691                         if(relationshipsOp.isPresent()) {
692                                 relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get());
693                                 if(relationshipsOp.isPresent()){
694                                         Optional<Configuration> config = workflowActionUtils.extractRelationshipsConfiguration(relationshipsOp.get());
695                                         if(config.isPresent()){
696                                                 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, config.get().getConfigurationId()));
697                                                 resourceCounter.add(new Resource(WorkflowType.CONFIGURATION, config.get().getConfigurationId(), false));
698                                         }
699                                 }
700                         }
701                 }catch (Exception ex){
702                         buildAndThrowException(execution,
703                                         "Failed to find Configuration object from the vfModule.");
704                 }
705         }
706         
707         protected boolean traverseUserParamsService(DelegateExecution execution, List<Resource> resourceCounter,
708                         ServiceInstancesRequest sIRequest, String requestAction)
709                         throws IOException {
710                 boolean foundRelated = false;
711                 boolean foundVfModuleOrVG = false;
712                 String vnfCustomizationUUID = "";
713                 String vfModuleCustomizationUUID = "";
714                 if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
715                         List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams();
716                         for (Map<String, Object> params : userParams) {
717                                 if (params.containsKey(USERPARAMSERVICE)) {
718                                         ObjectMapper obj = new ObjectMapper();
719                                         String input = obj.writeValueAsString(params.get(USERPARAMSERVICE));
720                                         Service validate = obj.readValue(input, Service.class);
721                                         resourceCounter.add(new Resource(WorkflowType.SERVICE,validate.getModelInfo().getModelVersionId(),false));
722                                         if (validate.getResources().getVnfs() != null) {
723                                                 for (Vnfs vnf : validate.getResources().getVnfs()) {
724                                                         resourceCounter.add(new Resource(WorkflowType.VNF,vnf.getModelInfo().getModelCustomizationId(),false));
725                                                         foundRelated = true;
726                                                         if(vnf.getModelInfo()!=null && vnf.getModelInfo().getModelCustomizationUuid()!=null){
727                                                                 vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid();
728                                                         }
729                                                         if (vnf.getVfModules() != null) {
730                                                                 for (VfModules vfModule : vnf.getVfModules()) {
731                                                                         VfModuleCustomization vfModuleCustomization = catalogDbClient
732                                                                                         .getVfModuleCustomizationByModelCuztomizationUUID(
733                                                                                                         vfModule.getModelInfo().getModelCustomizationUuid());
734                                                                         if (vfModuleCustomization != null) {
735
736                                                                                 if(vfModuleCustomization.getVfModule() != null && vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null && vfModuleCustomization.getVolumeHeatEnv() != null) {
737                                                                                         resourceCounter.add(new Resource(WorkflowType.VOLUMEGROUP,vfModuleCustomization.getModelCustomizationUUID(),false));
738                                                                                         foundRelated = true;
739                                                                                         foundVfModuleOrVG = true;
740                                                                                 }
741
742                                                                                 if(vfModuleCustomization.getVfModule() != null && vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null && vfModuleCustomization.getHeatEnvironment() != null){
743                                                                                         foundRelated = true;
744                                                                                         foundVfModuleOrVG = true;
745                                                                                         Resource resource = new Resource(WorkflowType.VFMODULE,vfModuleCustomization.getModelCustomizationUUID(),false);
746                                                                                         if(vfModuleCustomization.getVfModule().getIsBase()!=null && vfModuleCustomization.getVfModule().getIsBase()){
747                                                                                                 resource.setBaseVfModule(true);
748                                                                                         }else{
749                                                                                                 resource.setBaseVfModule(false);
750                                                                                         }
751                                                                                         resourceCounter.add(resource);
752                                                                                         if(vfModule.getModelInfo()!=null && vfModule.getModelInfo().getModelCustomizationUuid()!=null){
753                                                                                                 vfModuleCustomizationUUID = vfModule.getModelInfo().getModelCustomizationUuid();
754                                                                                         }
755                                                                                         if(!vnfCustomizationUUID.equals("")&&!vfModuleCustomizationUUID.equals("")){
756                                                                                                 List<VnfVfmoduleCvnfcConfigurationCustomization> configs = traverseCatalogDbForConfiguration(vnfCustomizationUUID,vfModuleCustomizationUUID);
757                                                                                                 for(VnfVfmoduleCvnfcConfigurationCustomization config : configs){
758                                                                                                         Resource configResource = new Resource(WorkflowType.CONFIGURATION,config.getConfigurationResource().getModelUUID(),false);
759                                                                                                         resource.setVnfCustomizationId(vnf.getModelInfo().getModelCustomizationId());
760                                                                                                         resource.setVfModuleCustomizationId(vfModule.getModelInfo().getModelCustomizationId());
761                                                                                                         resourceCounter.add(configResource);
762                                                                                                 }
763                                                                                         }
764                                                                                 }
765                                                                                 if(!foundVfModuleOrVG){
766                                                                                         buildAndThrowException(execution, "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null");
767                                                                                 }
768                                                                         }
769                                                                 }
770                                                         }
771                                                 }
772                                         }
773                                         if (validate.getResources().getNetworks() != null) {
774                                                 for (Networks network : validate.getResources().getNetworks()) {
775                                                         resourceCounter.add(new Resource(WorkflowType.NETWORK,network.getModelInfo().getModelCustomizationId(),false));
776                                                         foundRelated = true;
777                                                 }
778                                                 if (requestAction.equals(CREATEINSTANCE)) {
779                                                         String networkColCustId = queryCatalogDBforNetworkCollection(execution, sIRequest);
780                                                         if (networkColCustId != null) {
781                                                                 resourceCounter.add(new Resource(WorkflowType.NETWORKCOLLECTION,networkColCustId,false));
782                                                                 foundRelated = true;
783                                                         }
784                                                 }
785                                         }
786                                         break;
787                                 }
788                         }
789                 }
790                 return foundRelated;
791         }
792
793         protected List<VnfVfmoduleCvnfcConfigurationCustomization> traverseCatalogDbForConfiguration(String vnfCustomizationUUID, String vfModuleCustomizationUUID) {
794                 List<VnfVfmoduleCvnfcConfigurationCustomization> configurations = new ArrayList<>();
795                 try{
796                         List<CvnfcCustomization> cvnfcCustomizations = catalogDbClient.getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID(vnfCustomizationUUID, vfModuleCustomizationUUID);
797                         for(CvnfcCustomization cvnfc : cvnfcCustomizations){
798                                 for(VnfVfmoduleCvnfcConfigurationCustomization customization : cvnfc.getVnfVfmoduleCvnfcConfigurationCustomization()){
799                                         if(customization.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)){
800                                                 configurations.add(customization);
801                                         }
802                                 }
803                         }
804                         logger.debug("found {} configuration(s)" , configurations.size() );
805                         return configurations;
806                 } catch (Exception ex){
807                         logger.error("Error in finding configurations", ex);
808                         return configurations;
809                 }
810         }
811
812         protected String queryCatalogDBforNetworkCollection(DelegateExecution execution, ServiceInstancesRequest sIRequest) {
813                 org.onap.so.db.catalog.beans.Service service = catalogDbClient
814                                 .getServiceByID(sIRequest.getRequestDetails().getModelInfo().getModelVersionId());
815                 if (service != null) {
816                         CollectionResourceCustomization networkCollection = this.findCatalogNetworkCollection(execution, service);
817                         if(networkCollection != null) {
818                                 return networkCollection.getModelCustomizationUUID();
819                         }
820                 }
821                 return null;
822         }
823
824         protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) {
825                 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
826                 workflowResourceIds.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
827                 workflowResourceIds.setNetworkId((String) execution.getVariable("networkId"));
828                 workflowResourceIds.setVfModuleId((String) execution.getVariable("vfModuleId"));
829                 workflowResourceIds.setVnfId((String) execution.getVariable("vnfId"));
830                 workflowResourceIds.setVolumeGroupId((String) execution.getVariable("volumeGroupId"));
831                 workflowResourceIds.setInstanceGroupId((String) execution.getVariable("instanceGroupId"));
832                 return workflowResourceIds;
833         }
834
835         protected Resource extractResourceIdAndTypeFromUri(String uri) {
836             Pattern patt = Pattern.compile(
837                     "[vV]\\d+.*?(?:(?:/(?<type>" + supportedTypes + ")(?:/(?<id>[^/]+))?)(?:/(?<action>[^/]+))?)?$");
838             Matcher m = patt.matcher(uri);
839             Boolean generated = false;
840
841             if (m.find()) {
842                 logger.debug("found match on {} : {} " , uri ,  m);
843                 String type = m.group("type");
844                 String id = m.group("id");
845                 String action = m.group("action");
846                 if (type == null) {
847                     throw new IllegalArgumentException("Uri could not be parsed. No type found. " + uri);
848                 }
849                 if (action == null) {
850                     if (type.equals(SERVICE_INSTANCES) && (id == null || id.equals("assign"))) {
851                         id = UUID.randomUUID().toString();
852                         generated = true;
853                     }else if (type.equals(VF_MODULES) && id.equals("scaleOut")) {
854                         id = UUID.randomUUID().toString();
855                         generated = true;
856                     }
857                 } else {
858                     if (action.matches(supportedTypes)) {
859                         id = UUID.randomUUID().toString();
860                         generated = true;
861                         type = action;
862                     }
863                 }
864                 return new Resource(WorkflowType.fromString(convertTypeFromPlural(type)), id, generated);
865             } else {
866                 throw new IllegalArgumentException("Uri could not be parsed: " + uri);
867             }
868         }
869
870         protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName,
871                         RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws Exception {
872                 try {
873                         if ("SERVICE".equalsIgnoreCase(type.toString())) {
874                                 String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId();
875                                 String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType();
876                                 if (instanceName != null) {
877                                         Optional<ServiceInstance> serviceInstanceAAI = bbInputSetupUtils
878                                                         .getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName);
879                                         if (serviceInstanceAAI.isPresent()) {
880                                                 return serviceInstanceAAI.get().getServiceInstanceId();
881                                         }
882                                 }
883                         } else if ("NETWORK".equalsIgnoreCase(type.toString())) {
884                                 Optional<L3Network> network = bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(
885                                                 workflowResourceIds.getServiceInstanceId(), instanceName);
886                                 if (network.isPresent()) {
887                                         return network.get().getNetworkId();
888                                 }
889                         } else if ("VNF".equalsIgnoreCase(type.toString())) {
890                                 Optional<GenericVnf> vnf = bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(
891                                                 workflowResourceIds.getServiceInstanceId(), instanceName);
892                                 if (vnf.isPresent()) {
893                                         return vnf.get().getVnfId();
894                                 }
895                         } else if ("VFMODULE".equalsIgnoreCase(type.toString())) {
896                                 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId());
897                                 if (vnf != null && vnf.getVfModules() != null) {
898                                         for (org.onap.aai.domain.yang.VfModule vfModule : vnf.getVfModules().getVfModule()) {
899                                                 if (vfModule.getVfModuleName().equalsIgnoreCase(instanceName)) {
900                                                         return vfModule.getVfModuleId();
901                                                 }
902                                         }
903                                 }
904                         } else if ("VOLUMEGROUP".equalsIgnoreCase(type.toString())) {
905                                 Optional<VolumeGroup> volumeGroup = bbInputSetupUtils
906                                                 .getRelatedVolumeGroupByNameFromVnf(workflowResourceIds.getVnfId(), instanceName);
907                                 if (volumeGroup.isPresent()) {
908                                         return volumeGroup.get().getVolumeGroupId();
909                                 }
910                                 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId());
911                                 if (vnf != null && vnf.getVfModules() != null) {
912                                         for (org.onap.aai.domain.yang.VfModule vfModule : vnf.getVfModules().getVfModule()) {
913                                                 Optional<VolumeGroup> volumeGroupFromVfModule = bbInputSetupUtils
914                                                                 .getRelatedVolumeGroupByNameFromVfModule(vnf.getVnfId(), vfModule.getVfModuleId(), instanceName);
915                                                 if (volumeGroupFromVfModule.isPresent()) {
916                                                         return volumeGroupFromVfModule.get().getVolumeGroupId();
917                                                 }
918                                         }
919                                 }
920                         }
921                         return generatedResourceId;
922                 } catch (Exception ex) {
923                         logger.error(WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI, ex);
924                         throw new IllegalStateException(
925                                         WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI);
926                 }
927         }
928
929         protected String convertTypeFromPlural(String type) {
930                 if (!type.matches(supportedTypes)) {
931                         return type;
932                 } else {
933                         if (type.equals(SERVICE_INSTANCES)) {
934                                 return SERVICE;
935                         } else {
936                                 return type.substring(0, 1).toUpperCase() + type.substring(1, type.length() - 1);
937                         }
938                 }
939         }
940
941         protected List<ExecuteBuildingBlock> sortExecutionPathByObjectForVlanTagging(List<ExecuteBuildingBlock> orchFlows,
942                         String requestAction) {
943                 List<ExecuteBuildingBlock> sortedOrchFlows = new ArrayList<>();
944                 if (requestAction.equals(CREATEINSTANCE)) {
945                         for (ExecuteBuildingBlock ebb : orchFlows) {
946                                 if (ebb.getBuildingBlock().getBpmnFlowName().equals("AssignNetworkBB")) {
947                                         String key = ebb.getBuildingBlock().getKey();
948                                         boolean isVirtualLink = Boolean.TRUE.equals(ebb.getBuildingBlock().getIsVirtualLink());
949                                         String virtualLinkKey = ebb.getBuildingBlock().getVirtualLinkKey();
950                                         sortedOrchFlows.add(ebb);
951                                         for (ExecuteBuildingBlock ebb2 : orchFlows) {
952                                                 if (!isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("CreateNetworkBB")
953                                                                 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
954                                                         sortedOrchFlows.add(ebb2);
955                                                         break;
956                                                 }
957                                                 if(isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("CreateNetworkBB")
958                                                                 && ebb2.getBuildingBlock().getVirtualLinkKey().equalsIgnoreCase(virtualLinkKey)) {
959                                                         sortedOrchFlows.add(ebb2);
960                                                         break;
961                                                 }
962                                         }
963                                         for (ExecuteBuildingBlock ebb2 : orchFlows) {
964                                                 if (!isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("ActivateNetworkBB")
965                                                                 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
966                                                         sortedOrchFlows.add(ebb2);
967                                                         break;
968                                                 }
969                                                 if(isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("ActivateNetworkBB")
970                                                                 && ebb2.getBuildingBlock().getVirtualLinkKey().equalsIgnoreCase(virtualLinkKey)) {
971                                                         sortedOrchFlows.add(ebb2);
972                                                         break;
973                                                 }
974                                         }
975                                 } else if (ebb.getBuildingBlock().getBpmnFlowName().equals("CreateNetworkBB")
976                                                 || ebb.getBuildingBlock().getBpmnFlowName().equals("ActivateNetworkBB")) {
977                                         continue;
978                                 } else if (!ebb.getBuildingBlock().getBpmnFlowName().equals("")) {
979                                         sortedOrchFlows.add(ebb);
980                                 }
981                         }
982                 } else if (requestAction.equals("deleteInstance")) {
983                         for (ExecuteBuildingBlock ebb : orchFlows) {
984                                 if (ebb.getBuildingBlock().getBpmnFlowName().equals("DeactivateNetworkBB")) {
985                                         sortedOrchFlows.add(ebb);
986                                         String key = ebb.getBuildingBlock().getKey();
987                                         for (ExecuteBuildingBlock ebb2 : orchFlows) {
988                                                 if (ebb2.getBuildingBlock().getBpmnFlowName().equals("DeleteNetworkBB")
989                                                                 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
990                                                         sortedOrchFlows.add(ebb2);
991                                                         break;
992                                                 }
993                                         }
994                                         for (ExecuteBuildingBlock ebb2 : orchFlows) {
995                                                 if (ebb2.getBuildingBlock().getBpmnFlowName().equals("UnassignNetworkBB")
996                                                                 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
997                                                         sortedOrchFlows.add(ebb2);
998                                                         break;
999                                                 }
1000                                         }
1001                                 } else if (ebb.getBuildingBlock().getBpmnFlowName().equals("DeleteNetworkBB")
1002                                                 || ebb.getBuildingBlock().getBpmnFlowName().equals("UnassignNetworkBB")) {
1003                                         continue;
1004                                 } else if (!ebb.getBuildingBlock().getBpmnFlowName().equals("")) {
1005                                         sortedOrchFlows.add(ebb);
1006                                 }
1007                         }
1008                 }
1009                 return sortedOrchFlows;
1010         }
1011
1012         protected List<ExecuteBuildingBlock> buildExecuteBuildingBlockList(List<OrchestrationFlow> orchFlows,
1013                         List<Resource> resourceCounter, String requestId, String apiVersion, String resourceId, WorkflowType resourceType,
1014                         String requestAction, boolean aLaCarte, String vnfType,
1015                         WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails) {
1016                 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
1017                 for (OrchestrationFlow orchFlow : orchFlows) {
1018                         if (orchFlow.getFlowName().contains(SERVICE)) {
1019                                 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.SERVICE == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1020                                         workflowResourceIds.setServiceInstanceId(resourceId);
1021                                         flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.SERVICE == x.getResourceType())
1022                                                         .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1023                                                         requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1024                                 }
1025                         } else if (orchFlow.getFlowName().contains(VNF)) {
1026                                 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.VNF == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1027                                         flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.VNF == x.getResourceType())
1028                                                         .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1029                                                         requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1030                                 }
1031                         } else if (orchFlow.getFlowName().contains(NETWORK)
1032                                         && !orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
1033                                 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.NETWORK == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1034                                         flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.NETWORK == x.getResourceType())
1035                                                         .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1036                                                         requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1037                                 }
1038                                 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.VIRTUAL_LINK == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1039                                         Resource resource = resourceCounter.stream().filter(x -> WorkflowType.VIRTUAL_LINK == x.getResourceType())
1040                                                         .collect(Collectors.toList()).get(i);
1041                                         flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource, apiVersion, resourceId,
1042                                                         requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, true, resource.getVirtualLinkKey(), false));
1043                                 }
1044                         } else if (orchFlow.getFlowName().contains(VFMODULE)) {
1045                                 List<Resource> vfModuleResourcesSorted = null;
1046                                 if(requestAction.equals("createInstance")||requestAction.equals("assignInstance")||requestAction.equals("activateInstance")){
1047                                         vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceCounter.stream().filter(x -> WorkflowType.VFMODULE == x.getResourceType())
1048                                                 .collect(Collectors.toList()));
1049                                 }else{
1050                                         vfModuleResourcesSorted = sortVfModulesByBaseLast(resourceCounter.stream().filter(x -> WorkflowType.VFMODULE == x.getResourceType())
1051                                                         .collect(Collectors.toList()));
1052                                 }
1053                                 for (int i = 0; i < vfModuleResourcesSorted.size(); i++) {
1054                                         flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, vfModuleResourcesSorted.get(i), apiVersion, resourceId,
1055                                                         requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1056                                 }
1057                         } else if (orchFlow.getFlowName().contains(VOLUMEGROUP)) {
1058                                 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.VOLUMEGROUP == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1059                                         flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.VOLUMEGROUP == x.getResourceType())
1060                                                         .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1061                                                         requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1062                                 }
1063                         } else if (orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
1064                                 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1065                                         flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType())
1066                                                         .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1067                                                         requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1068                                 }
1069                         } else if (orchFlow.getFlowName().contains(CONFIGURATION)) {
1070                                 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.CONFIGURATION == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1071                                         flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.CONFIGURATION == x.getResourceType())
1072                                                         .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1073                                                         requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, true));
1074                                 }
1075                         }else {
1076                                 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, null, apiVersion, resourceId,
1077                                                 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1078                         }
1079                 }
1080                 return flowsToExecute;
1081         }
1082
1083         protected ExecuteBuildingBlock buildExecuteBuildingBlock(OrchestrationFlow orchFlow, String requestId, Resource resource,
1084                         String apiVersion, String resourceId, String requestAction, boolean aLaCarte, String vnfType,
1085                         WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, boolean isVirtualLink, String virtualLinkKey, boolean isConfiguration) {
1086                 ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
1087                 BuildingBlock buildingBlock = new BuildingBlock();
1088                 buildingBlock.setBpmnFlowName(orchFlow.getFlowName());
1089                 buildingBlock.setMsoId(UUID.randomUUID().toString());
1090                 if(resource == null){
1091                         buildingBlock.setKey("");
1092                 }else{
1093                         buildingBlock.setKey(resource.getResourceId());
1094                 }
1095                 buildingBlock.setIsVirtualLink(isVirtualLink);
1096                 buildingBlock.setVirtualLinkKey(virtualLinkKey);
1097                 executeBuildingBlock.setApiVersion(apiVersion);
1098                 executeBuildingBlock.setaLaCarte(aLaCarte);
1099                 executeBuildingBlock.setRequestAction(requestAction);
1100                 executeBuildingBlock.setResourceId(resourceId);
1101                 executeBuildingBlock.setVnfType(vnfType);
1102                 executeBuildingBlock.setWorkflowResourceIds(workflowResourceIds);
1103                 executeBuildingBlock.setRequestId(requestId);
1104                 executeBuildingBlock.setBuildingBlock(buildingBlock);
1105                 executeBuildingBlock.setRequestDetails(requestDetails);
1106                 if(resource != null && (isConfiguration || resource.getResourceType().equals(WorkflowType.CONFIGURATION))){
1107                         ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
1108                         if (resource != null){
1109                                 configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId());
1110                                 configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId());
1111                                 configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId());
1112                         }
1113                         executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys);
1114                 }
1115                 return executeBuildingBlock;
1116         }
1117
1118         protected List<OrchestrationFlow> queryNorthBoundRequestCatalogDb(DelegateExecution execution, String requestAction,
1119                         WorkflowType resourceName, boolean aLaCarte, String cloudOwner) {
1120                 return this.queryNorthBoundRequestCatalogDb(execution, requestAction, resourceName, aLaCarte, cloudOwner, "");
1121         }
1122         
1123         protected List<OrchestrationFlow> queryNorthBoundRequestCatalogDb(DelegateExecution execution, String requestAction,
1124                         WorkflowType resourceName, boolean aLaCarte, String cloudOwner, String serviceType) {
1125                 List<OrchestrationFlow> listToExecute = new ArrayList<>();
1126                 NorthBoundRequest northBoundRequest = null;
1127                 if (serviceType.equalsIgnoreCase(SERVICE_TYPE_TRANSPORT)) {
1128                         northBoundRequest = catalogDbClient
1129                                         .getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwnerAndServiceType(requestAction,
1130                                                         resourceName.toString(), aLaCarte, cloudOwner, serviceType);
1131                 } else {
1132                         northBoundRequest = catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(
1133                                         requestAction, resourceName.toString(), aLaCarte, cloudOwner);
1134                 }
1135                 if(northBoundRequest == null){
1136                         if(aLaCarte){
1137                                 buildAndThrowException(execution,"The request: ALaCarte " + resourceName + " " + requestAction + " is not supported by GR_API.");
1138                         }else{
1139                                 buildAndThrowException(execution,"The request: Macro " + resourceName + " " + requestAction + " is not supported by GR_API.");
1140                         }
1141                 } else {
1142                 if(northBoundRequest.getIsToplevelflow()!=null){
1143                         execution.setVariable(G_ISTOPLEVELFLOW, northBoundRequest.getIsToplevelflow());
1144                 }
1145                 List<OrchestrationFlow> flows = northBoundRequest.getOrchestrationFlowList();
1146                 if (flows == null)
1147                         flows = new ArrayList<>();
1148                 for (OrchestrationFlow flow : flows) {
1149                         if (!flow.getFlowName().contains("BB")) {
1150                                 List<OrchestrationFlow> macroQueryFlows = catalogDbClient
1151                                                 .getOrchestrationFlowByAction(flow.getFlowName());
1152                                 for (OrchestrationFlow macroFlow : macroQueryFlows) {
1153                                         listToExecute.add(macroFlow);
1154                                 }
1155                         } else {
1156                                 listToExecute.add(flow);
1157                         }
1158                 }
1159                 }
1160                 return listToExecute;
1161         }
1162         
1163         protected List<OrchestrationFlow> filterOrchFlows(ServiceInstancesRequest sIRequest, List<OrchestrationFlow> orchFlows, WorkflowType resourceType, DelegateExecution execution) {
1164                 List<OrchestrationFlow> result = new ArrayList<>(orchFlows);
1165                 String vnfCustomizationUUID = "";
1166                 String vfModuleCustomizationUUID = sIRequest.getRequestDetails().getModelInfo().getModelCustomizationUuid();
1167                 RelatedInstanceList[] relatedInstanceList = sIRequest.getRequestDetails().getRelatedInstanceList();
1168                 if (relatedInstanceList != null) {
1169                         for (RelatedInstanceList relatedInstList : relatedInstanceList) {
1170                                 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
1171                                 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
1172                                         vnfCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationUuid();
1173                                 }
1174                         }
1175                 }
1176                 
1177                 if (resourceType.equals(WorkflowType.VFMODULE)) {
1178                         List<VnfVfmoduleCvnfcConfigurationCustomization> fabricCustomizations = traverseCatalogDbForConfiguration(vnfCustomizationUUID, vfModuleCustomizationUUID);
1179                         if (fabricCustomizations.isEmpty()) {
1180                                 result = orchFlows.stream().filter(item -> !item.getFlowName().contains(FABRIC_CONFIGURATION)).collect(Collectors.toList());
1181                         }
1182                 }
1183                 return result;
1184         }
1185
1186         protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) {
1187                 logger.error(msg, ex);
1188                 execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg);
1189                 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
1190         }
1191
1192         protected void buildAndThrowException(DelegateExecution execution, String msg) {
1193                 logger.error(msg);
1194                 execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg);
1195                 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
1196         }
1197         
1198         public void handleRuntimeException (DelegateExecution execution){
1199                 StringBuilder wfeExpMsg = new StringBuilder("Runtime error ");
1200                 String runtimeErrorMessage = null;
1201                 try{
1202                         String javaExpMsg = (String) execution.getVariable("BPMN_javaExpMsg");
1203                         if (javaExpMsg != null && !javaExpMsg.isEmpty()) {
1204                                 wfeExpMsg = wfeExpMsg.append(": ").append(javaExpMsg);
1205                         }
1206                         runtimeErrorMessage = wfeExpMsg.toString();
1207                         logger.error(runtimeErrorMessage);
1208                         execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, runtimeErrorMessage);
1209                 } catch (Exception e){
1210                         logger.error("Runtime error", e);
1211                         //if runtime message was mulformed
1212                         runtimeErrorMessage = "Runtime error";
1213                 }
1214                 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, runtimeErrorMessage);
1215         }
1216 }