2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.bpmn.infrastructure.workflow.tasks;
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;
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;
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;
82 import com.fasterxml.jackson.databind.ObjectMapper;
85 public class WorkflowAction {
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);
119 protected BBInputSetup bbInputSetup;
121 protected BBInputSetupUtils bbInputSetupUtils;
123 private ExceptionBuilder exceptionBuilder;
125 private CatalogDbClient catalogDbClient;
127 private AAIConfigurationResources aaiConfigurationResources;
129 private WorkflowActionExtractResourcesAAI workflowActionUtils;
132 private Environment environment;
133 private String defaultCloudOwner = "org.onap.so.cloud-owner";
135 public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
136 this.bbInputSetupUtils = bbInputSetupUtils;
139 public void setBbInputSetup(BBInputSetup bbInputSetup) {
140 this.bbInputSetup = bbInputSetup;
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("");
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);
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 = "";
170 cloudOwner = requestDetails.getCloudConfiguration().getCloudOwner();
171 } catch (Exception ex) {
172 cloudOwner = environment.getProperty(defaultCloudOwner);
174 boolean suppressRollback = false;
176 suppressRollback = requestDetails.getRequestInfo().getSuppressRollback();
177 } catch (Exception ex) {
178 suppressRollback = false;
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);
190 resourceId = resource.getResourceId();
192 if((serviceInstanceId == null || serviceInstanceId.equals("")) && resourceType == WorkflowType.SERVICE){
193 serviceInstanceId = resourceId;
195 execution.setVariable("resourceId", resourceId);
196 execution.setVariable("resourceType", resourceType);
199 if (orchFlows == null || orchFlows.isEmpty()) {
200 orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, cloudOwner, serviceType);
202 orchFlows = filterOrchFlows(sIRequest, orchFlows, resourceType, execution);
204 ModelInfo modelInfo = sIRequest.getRequestDetails().getModelInfo();
205 if(modelInfo != null) {
206 if(modelInfo.getModelType().equals(ModelType.service)) {
207 key = modelInfo.getModelVersionId();
209 key = modelInfo.getModelCustomizationId();
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);
223 flowsToExecute.addAll(configBuildingBlocks);
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
230 if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
231 List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters()
233 for (Map<String, Object> params : userParams) {
234 if (params.containsKey(USERPARAMSERVICE)) {
235 containsService = true;
238 if (containsService) {
239 traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction);
242 buildAndThrowException(execution,
243 "Service-Macro-Assign request details must contain user params with a service");
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.
253 if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
254 List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters()
256 for (Map<String, Object> params : userParams) {
257 if (params.containsKey(USERPARAMSERVICE)) {
258 containsService = true;
262 if (containsService) {
263 foundRelated = traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction);
266 traverseCatalogDbService(execution, sIRequest, resourceCounter);
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);
284 buildAndThrowException(execution, "Current Macro Request is not supported");
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() + " ";
290 logger.info("Found {}", foundObjects);
292 if (orchFlows == null || orchFlows.isEmpty()) {
293 orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, cloudOwner, serviceType);
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);
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);
308 if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) || requestAction.equalsIgnoreCase(CREATEINSTANCE))){
309 generateResourceIds(flowsToExecute, resourceCounter, serviceInstanceId);
311 updateResourceIdsFromAAITraversal(flowsToExecute, resourceCounter, aaiResourceIds, serviceInstanceId);
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);
324 execution.setVariable("homing", true);
330 if (flowsToExecute.isEmpty()) {
331 throw new IllegalStateException("Macro did not come up with a valid execution path.");
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());
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);
346 } catch (Exception ex) {
347 buildAndThrowException(execution, "Exception in create execution list " + ex.getMessage(), ex);
351 protected boolean isConfiguration(List<OrchestrationFlow> orchFlows) {
352 for(OrchestrationFlow flow : orchFlows) {
353 if(flow.getFlowName().contains("Configuration")) {
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();
377 List<VnfVfmoduleCvnfcConfigurationCustomization> fabricCustomizations = traverseCatalogDbForConfiguration(vnfCustomizationUUID, vfModuleCustomizationUUID);
378 List<ExecuteBuildingBlock> flowsToExecuteConfigs = new ArrayList<>();
379 for(VnfVfmoduleCvnfcConfigurationCustomization fabricConfig : fabricCustomizations) {
381 if (requestAction.equals(CREATEINSTANCE)) {
382 workflowResourceIds.setConfigurationId(UUID.randomUUID().toString());
384 //TODO AAI lookup for configuration update/delete
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);
395 return flowsToExecuteConfigs;
398 protected List<Resource> sortVfModulesByBaseFirst(List<Resource> vfModuleResources) {
400 for(Resource resource : vfModuleResources){
401 if(resource.isBaseVfModule()){
402 Collections.swap(vfModuleResources, 0, count);
407 return vfModuleResources;
410 protected List<Resource> sortVfModulesByBaseLast(List<Resource> vfModuleResources) {
412 for(Resource resource : vfModuleResources){
413 if(resource.isBaseVfModule()){
414 Collections.swap(vfModuleResources, vfModuleResources.size()-1, count);
419 return vfModuleResources;
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());
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);
436 private String retrieveAAIResourceId(List<Pair<WorkflowType, String>> aaiResourceIds, WorkflowType resource){
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);
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);
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();
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);
480 ebb.setWorkflowResourceIds(workflowResourceIds);
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);
492 protected CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution, org.onap.so.db.catalog.beans.Service service) {
493 CollectionResourceCustomization networkCollection = null;
495 for(CollectionResourceCustomization collectionCust : service.getCollectionResourceCustomizations()){
496 if(catalogDbClient.getNetworkCollectionResourceCustomizationByID(collectionCust.getModelCustomizationUUID()) != null) {
497 networkCollection = collectionCust;
503 }else if(count > 1) {
504 buildAndThrowException(execution, "Found multiple Network Collections in the Service model, only one per Service is supported.");
506 return networkCollection;
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.");
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.");
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")) {
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;
540 if(collectionInstCust != null && collectionInstCust.getSubInterfaceNetworkQuantity() != null) {
541 minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity();
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;
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);
560 logger.debug("Instance Group tosca node type does not contain NetworkCollection: {}" , toscaNodeType);
563 logger.debug("No Instance Group found for network collection.");
566 logger.debug("No Network Collection found. collectionResource is null");
569 logger.debug("No Network Collection Customization found");
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");
576 for (int i = 0; i < service.getNetworkCustomizations().size(); i++) {
577 resourceCounter.add(new Resource(WorkflowType.NETWORK,service.getNetworkCustomizations().get(i).getModelCustomizationUUID(),false));
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");
588 protected void traverseAAIService(DelegateExecution execution, List<Resource> resourceCounter, String resourceId, List<Pair<WorkflowType, String>> aaiResourceIds) {
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
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));
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));
614 if (serviceInstanceMSO.getNetworks() != null) {
615 for (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network : serviceInstanceMSO
617 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.NETWORK, network.getNetworkId()));
618 resourceCounter.add(new Resource(WorkflowType.NETWORK,network.getNetworkId(),false));
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));
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));
640 } catch (Exception ex) {
641 buildAndThrowException(execution,
642 "Could not find existing Service Instance or related Instances to execute the request on.");
646 private void traverseAAIVnf(DelegateExecution execution, List<Resource> resourceCounter, String serviceId, String vnfId,
647 List<Pair<WorkflowType, String>> aaiResourceIds) {
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
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);
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));
677 } catch (Exception ex) {
678 buildAndThrowException(execution,
679 "Could not find existing Vnf or related Instances to execute the request on.");
683 private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, List<Resource> resourceCounter,
684 List<Pair<WorkflowType, String>> aaiResourceIds) {
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));
701 }catch (Exception ex){
702 buildAndThrowException(execution,
703 "Failed to find Configuration object from the vfModule.");
707 protected boolean traverseUserParamsService(DelegateExecution execution, List<Resource> resourceCounter,
708 ServiceInstancesRequest sIRequest, String requestAction)
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));
726 if(vnf.getModelInfo()!=null && vnf.getModelInfo().getModelCustomizationUuid()!=null){
727 vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid();
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) {
736 if(vfModuleCustomization.getVfModule() != null && vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null && vfModuleCustomization.getVolumeHeatEnv() != null) {
737 resourceCounter.add(new Resource(WorkflowType.VOLUMEGROUP,vfModuleCustomization.getModelCustomizationUUID(),false));
739 foundVfModuleOrVG = true;
742 if(vfModuleCustomization.getVfModule() != null && vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null && vfModuleCustomization.getHeatEnvironment() != null){
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);
749 resource.setBaseVfModule(false);
751 resourceCounter.add(resource);
752 if(vfModule.getModelInfo()!=null && vfModule.getModelInfo().getModelCustomizationUuid()!=null){
753 vfModuleCustomizationUUID = vfModule.getModelInfo().getModelCustomizationUuid();
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);
765 if(!foundVfModuleOrVG){
766 buildAndThrowException(execution, "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null");
773 if (validate.getResources().getNetworks() != null) {
774 for (Networks network : validate.getResources().getNetworks()) {
775 resourceCounter.add(new Resource(WorkflowType.NETWORK,network.getModelInfo().getModelCustomizationId(),false));
778 if (requestAction.equals(CREATEINSTANCE)) {
779 String networkColCustId = queryCatalogDBforNetworkCollection(execution, sIRequest);
780 if (networkColCustId != null) {
781 resourceCounter.add(new Resource(WorkflowType.NETWORKCOLLECTION,networkColCustId,false));
793 protected List<VnfVfmoduleCvnfcConfigurationCustomization> traverseCatalogDbForConfiguration(String vnfCustomizationUUID, String vfModuleCustomizationUUID) {
794 List<VnfVfmoduleCvnfcConfigurationCustomization> configurations = new ArrayList<>();
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);
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;
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();
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;
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;
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");
847 throw new IllegalArgumentException("Uri could not be parsed. No type found. " + uri);
849 if (action == null) {
850 if (type.equals(SERVICE_INSTANCES) && (id == null || id.equals("assign"))) {
851 id = UUID.randomUUID().toString();
853 }else if (type.equals(VF_MODULES) && id.equals("scaleOut")) {
854 id = UUID.randomUUID().toString();
858 if (action.matches(supportedTypes)) {
859 id = UUID.randomUUID().toString();
864 return new Resource(WorkflowType.fromString(convertTypeFromPlural(type)), id, generated);
866 throw new IllegalArgumentException("Uri could not be parsed: " + uri);
870 protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName,
871 RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws Exception {
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();
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();
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();
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();
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();
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();
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);
929 protected String convertTypeFromPlural(String type) {
930 if (!type.matches(supportedTypes)) {
933 if (type.equals(SERVICE_INSTANCES)) {
936 return type.substring(0, 1).toUpperCase() + type.substring(1, type.length() - 1);
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);
957 if(isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("CreateNetworkBB")
958 && ebb2.getBuildingBlock().getVirtualLinkKey().equalsIgnoreCase(virtualLinkKey)) {
959 sortedOrchFlows.add(ebb2);
963 for (ExecuteBuildingBlock ebb2 : orchFlows) {
964 if (!isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("ActivateNetworkBB")
965 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
966 sortedOrchFlows.add(ebb2);
969 if(isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("ActivateNetworkBB")
970 && ebb2.getBuildingBlock().getVirtualLinkKey().equalsIgnoreCase(virtualLinkKey)) {
971 sortedOrchFlows.add(ebb2);
975 } else if (ebb.getBuildingBlock().getBpmnFlowName().equals("CreateNetworkBB")
976 || ebb.getBuildingBlock().getBpmnFlowName().equals("ActivateNetworkBB")) {
978 } else if (!ebb.getBuildingBlock().getBpmnFlowName().equals("")) {
979 sortedOrchFlows.add(ebb);
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);
994 for (ExecuteBuildingBlock ebb2 : orchFlows) {
995 if (ebb2.getBuildingBlock().getBpmnFlowName().equals("UnassignNetworkBB")
996 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
997 sortedOrchFlows.add(ebb2);
1001 } else if (ebb.getBuildingBlock().getBpmnFlowName().equals("DeleteNetworkBB")
1002 || ebb.getBuildingBlock().getBpmnFlowName().equals("UnassignNetworkBB")) {
1004 } else if (!ebb.getBuildingBlock().getBpmnFlowName().equals("")) {
1005 sortedOrchFlows.add(ebb);
1009 return sortedOrchFlows;
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));
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));
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));
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));
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()));
1050 vfModuleResourcesSorted = sortVfModulesByBaseLast(resourceCounter.stream().filter(x -> WorkflowType.VFMODULE == x.getResourceType())
1051 .collect(Collectors.toList()));
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));
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));
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));
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));
1076 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, null, apiVersion, resourceId,
1077 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1080 return flowsToExecute;
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("");
1093 buildingBlock.setKey(resource.getResourceId());
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());
1113 executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys);
1115 return executeBuildingBlock;
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, "");
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);
1132 northBoundRequest = catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(
1133 requestAction, resourceName.toString(), aLaCarte, cloudOwner);
1135 if(northBoundRequest == null){
1137 buildAndThrowException(execution,"The request: ALaCarte " + resourceName + " " + requestAction + " is not supported by GR_API.");
1139 buildAndThrowException(execution,"The request: Macro " + resourceName + " " + requestAction + " is not supported by GR_API.");
1142 if(northBoundRequest.getIsToplevelflow()!=null){
1143 execution.setVariable(G_ISTOPLEVELFLOW, northBoundRequest.getIsToplevelflow());
1145 List<OrchestrationFlow> flows = northBoundRequest.getOrchestrationFlowList();
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);
1156 listToExecute.add(flow);
1160 return listToExecute;
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();
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());
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);
1192 protected void buildAndThrowException(DelegateExecution execution, String msg) {
1194 execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg);
1195 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
1198 public void handleRuntimeException (DelegateExecution execution){
1199 StringBuilder wfeExpMsg = new StringBuilder("Runtime error ");
1200 String runtimeErrorMessage = null;
1202 String javaExpMsg = (String) execution.getVariable("BPMN_javaExpMsg");
1203 if (javaExpMsg != null && !javaExpMsg.isEmpty()) {
1204 wfeExpMsg = wfeExpMsg.append(": ").append(javaExpMsg);
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";
1214 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, runtimeErrorMessage);