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.Vnfc;
45 import org.onap.aai.domain.yang.VolumeGroup;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
48 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
49 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
50 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
51 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
52 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
53 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
54 import org.onap.so.client.aai.AAICommonObjectMapperProvider;
55 import org.onap.so.client.aai.AAIObjectType;
56 import org.onap.so.client.aai.entities.AAIResultWrapper;
57 import org.onap.so.client.aai.entities.Relationships;
58 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
59 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
60 import org.onap.so.client.exception.ExceptionBuilder;
61 import org.onap.so.client.orchestration.AAIConfigurationResources;
62 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
63 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
64 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
65 import org.onap.so.db.catalog.beans.CvnfcCustomization;
66 import org.onap.so.db.catalog.beans.VfModuleCustomization;
67 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
68 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
69 import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
70 import org.onap.so.db.catalog.client.CatalogDbClient;
71 import org.onap.so.serviceinstancebeans.ModelInfo;
72 import org.onap.so.serviceinstancebeans.ModelType;
73 import org.onap.so.serviceinstancebeans.Networks;
74 import org.onap.so.serviceinstancebeans.RelatedInstance;
75 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
76 import org.onap.so.serviceinstancebeans.RequestDetails;
77 import org.onap.so.serviceinstancebeans.Service;
78 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
79 import org.onap.so.serviceinstancebeans.VfModules;
80 import org.onap.so.serviceinstancebeans.Vnfs;
81 import org.slf4j.Logger;
82 import org.springframework.beans.factory.annotation.Autowired;
83 import org.springframework.core.env.Environment;
84 import org.springframework.stereotype.Component;
86 import com.fasterxml.jackson.databind.ObjectMapper;
89 public class WorkflowAction {
91 private static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage";
92 private static final String SERVICE_INSTANCES = "serviceInstances";
93 private static final String VF_MODULES = "vfModules";
94 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.";
95 private static final String G_ORCHESTRATION_FLOW = "gOrchestrationFlow";
96 private static final String G_ACTION = "requestAction";
97 private static final String G_CURRENT_SEQUENCE = "gCurrentSequence";
98 private static final String G_REQUEST_ID = "mso-request-id";
99 private static final String G_BPMN_REQUEST = "bpmnRequest";
100 private static final String G_ALACARTE = "aLaCarte";
101 private static final String G_APIVERSION = "apiVersion";
102 private static final String G_URI = "requestUri";
103 private static final String G_ISTOPLEVELFLOW = "isTopLevelFlow";
104 private static final String VNF_TYPE = "vnfType";
105 private static final String SERVICE = "Service";
106 private static final String VNF = "Vnf";
107 private static final String VFMODULE = "VfModule";
108 private static final String VOLUMEGROUP = "VolumeGroup";
109 private static final String NETWORK = "Network";
110 private static final String NETWORKCOLLECTION = "NetworkCollection";
111 private static final String CONFIGURATION = "Configuration";
112 private static final String ASSIGNINSTANCE = "assignInstance";
113 private static final String CREATEINSTANCE = "createInstance";
114 private static final String USERPARAMSERVICE = "service";
115 private static final String supportedTypes = "vnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups";
116 private static final String HOMINGSOLUTION = "Homing_Solution";
117 private static final String FABRIC_CONFIGURATION = "FabricConfiguration";
118 private static final String G_SERVICE_TYPE = "serviceType";
119 private static final String SERVICE_TYPE_TRANSPORT = "TRANSPORT";
120 private static final Logger logger = LoggerFactory.getLogger(WorkflowAction.class);
123 protected BBInputSetup bbInputSetup;
125 protected BBInputSetupUtils bbInputSetupUtils;
127 private ExceptionBuilder exceptionBuilder;
129 private CatalogDbClient catalogDbClient;
131 private AAIConfigurationResources aaiConfigurationResources;
133 private WorkflowActionExtractResourcesAAI workflowActionUtils;
136 private Environment environment;
137 private String defaultCloudOwner = "org.onap.so.cloud-owner";
139 public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
140 this.bbInputSetupUtils = bbInputSetupUtils;
143 public void setBbInputSetup(BBInputSetup bbInputSetup) {
144 this.bbInputSetup = bbInputSetup;
147 public void selectExecutionList(DelegateExecution execution) throws Exception {
148 final String requestAction = (String) execution.getVariable(G_ACTION);
149 final String requestId = (String) execution.getVariable(G_REQUEST_ID);
150 final String bpmnRequest = (String) execution.getVariable(G_BPMN_REQUEST);
151 final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
152 final String apiVersion = (String) execution.getVariable(G_APIVERSION);
153 final String uri = (String) execution.getVariable(G_URI);
154 final String vnfType = (String) execution.getVariable(VNF_TYPE);
155 String serviceInstanceId = (String) execution.getVariable("serviceInstanceId");
156 final String serviceType = Optional.ofNullable((String) execution.getVariable(G_SERVICE_TYPE)).orElse("");
158 List<OrchestrationFlow> orchFlows = (List<OrchestrationFlow>) execution.getVariable(G_ORCHESTRATION_FLOW);
159 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
160 WorkflowResourceIds workflowResourceIds = populateResourceIdsFromApiHandler(execution);
161 List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
162 List<Resource> resourceCounter = new ArrayList<>();
163 execution.setVariable("sentSyncResponse", false);
164 execution.setVariable("homing", false);
165 execution.setVariable("calledHoming", false);
168 ObjectMapper mapper = new ObjectMapper();
169 execution.setVariable(G_ISTOPLEVELFLOW, true);
170 ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
171 RequestDetails requestDetails = sIRequest.getRequestDetails();
172 String cloudOwner = "";
174 cloudOwner = requestDetails.getCloudConfiguration().getCloudOwner();
175 } catch (Exception ex) {
176 cloudOwner = environment.getProperty(defaultCloudOwner);
178 boolean suppressRollback = false;
180 suppressRollback = requestDetails.getRequestInfo().getSuppressRollback();
181 } catch (Exception ex) {
182 suppressRollback = false;
184 execution.setVariable("suppressRollback", suppressRollback);
185 Resource resource = extractResourceIdAndTypeFromUri(uri);
186 WorkflowType resourceType = resource.getResourceType();
187 execution.setVariable("resourceName", resourceType.toString());
188 String resourceId = "";
189 if (resource.isGenerated()) {
190 resourceId = validateResourceIdInAAI(resource.getResourceId(), resourceType,
191 sIRequest.getRequestDetails().getRequestInfo().getInstanceName(), sIRequest.getRequestDetails(),
192 workflowResourceIds);
194 resourceId = resource.getResourceId();
196 if((serviceInstanceId == null || serviceInstanceId.equals("")) && resourceType == WorkflowType.SERVICE){
197 serviceInstanceId = resourceId;
199 execution.setVariable("resourceId", resourceId);
200 execution.setVariable("resourceType", resourceType);
203 if (orchFlows == null || orchFlows.isEmpty()) {
204 orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, cloudOwner, serviceType);
207 ModelInfo modelInfo = sIRequest.getRequestDetails().getModelInfo();
208 if(modelInfo != null) {
209 if(modelInfo.getModelType().equals(ModelType.service)) {
210 key = modelInfo.getModelVersionId();
212 key = modelInfo.getModelCustomizationId();
215 boolean isConfiguration = isConfiguration(orchFlows);
216 Resource resourceKey = new Resource(resourceType, key, aLaCarte);
217 if(isConfiguration && !requestAction.equalsIgnoreCase(CREATEINSTANCE)) {
218 List<ExecuteBuildingBlock> configBuildingBlocks = getConfigBuildingBlocks(sIRequest, orchFlows, requestId, resourceKey, apiVersion, resourceId, requestAction, aLaCarte, vnfType,
219 workflowResourceIds, requestDetails, execution);
220 flowsToExecute.addAll(configBuildingBlocks);
222 orchFlows = orchFlows.stream().filter(item -> !item.getFlowName().contains(FABRIC_CONFIGURATION)).collect(Collectors.toList());
223 for (OrchestrationFlow orchFlow : orchFlows) {
224 ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, resourceId,
225 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false);
226 flowsToExecute.add(ebb);
229 boolean foundRelated = false;
230 boolean containsService = false;
231 if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(ASSIGNINSTANCE)) {
232 // SERVICE-MACRO-ASSIGN will always get user params with a
234 if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
235 List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters()
237 for (Map<String, Object> params : userParams) {
238 if (params.containsKey(USERPARAMSERVICE)) {
239 containsService = true;
242 if (containsService) {
243 traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction);
246 buildAndThrowException(execution,
247 "Service-Macro-Assign request details must contain user params with a service");
249 } else if (resourceType == WorkflowType.SERVICE
250 && requestAction.equalsIgnoreCase(CREATEINSTANCE)) {
251 // SERVICE-MACRO-CREATE will get user params with a service,
252 // a service with a network, a service with a
253 // networkcollection, OR an empty service.
254 // If user params is just a service or null and macro
255 // queries the SI and finds a VNF, macro fails.
257 if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
258 List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters()
260 for (Map<String, Object> params : userParams) {
261 if (params.containsKey(USERPARAMSERVICE)) {
262 containsService = true;
266 if (containsService) {
267 foundRelated = traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction);
270 traverseCatalogDbService(execution, sIRequest, resourceCounter);
272 } else if (resourceType == WorkflowType.SERVICE
273 && (requestAction.equalsIgnoreCase("activateInstance")
274 || requestAction.equalsIgnoreCase("unassignInstance")
275 || requestAction.equalsIgnoreCase("deleteInstance")
276 || requestAction.equalsIgnoreCase("activate" + FABRIC_CONFIGURATION))) {
277 // SERVICE-MACRO-ACTIVATE, SERVICE-MACRO-UNASSIGN, and
278 // SERVICE-MACRO-DELETE
279 // Will never get user params with service, macro will have
280 // to query the SI in AAI to find related instances.
281 traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds);
282 } else if (resourceType == WorkflowType.SERVICE
283 && requestAction.equalsIgnoreCase("deactivateInstance")) {
284 resourceCounter.add(new Resource(WorkflowType.SERVICE,"",false));
285 } else if (resourceType == WorkflowType.VNF && (requestAction.equalsIgnoreCase("replaceInstance") || (requestAction.equalsIgnoreCase("recreateInstance")))) {
286 traverseAAIVnf(execution, resourceCounter, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds);
288 buildAndThrowException(execution, "Current Macro Request is not supported");
290 String foundObjects = "";
291 for(WorkflowType type : WorkflowType.values()){
292 foundObjects = foundObjects + type + " - " + resourceCounter.stream().filter(x -> type.equals(x.getResourceType())).collect(Collectors.toList()).size() + " ";
294 logger.info("Found {}", foundObjects);
296 if (orchFlows == null || orchFlows.isEmpty()) {
297 orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, cloudOwner, serviceType);
299 flowsToExecute = buildExecuteBuildingBlockList(orchFlows, resourceCounter, requestId, apiVersion, resourceId,
300 resourceType, requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails);
301 if (!resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()).collect(Collectors.toList()).isEmpty()) {
302 logger.info("Sorting for Vlan Tagging");
303 flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction);
305 // By default, enable homing at VNF level for CREATEINSTANCE and ASSIGNINSTANCE
306 if (resourceType == WorkflowType.SERVICE
307 && (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE))
308 && !resourceCounter.stream().filter(x -> WorkflowType.VNF.equals(x.getResourceType())).collect(Collectors.toList()).isEmpty()) {
309 execution.setVariable("homing", true);
310 execution.setVariable("calledHoming", false);
312 if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) || requestAction.equalsIgnoreCase(CREATEINSTANCE))){
313 generateResourceIds(flowsToExecute, resourceCounter, serviceInstanceId);
315 updateResourceIdsFromAAITraversal(flowsToExecute, resourceCounter, aaiResourceIds, serviceInstanceId);
319 // If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is specified, enable it.
320 if (sIRequest.getRequestDetails().getRequestParameters() != null &&
321 sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
322 List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams();
323 for (Map<String, Object> params : userParams) {
324 if (params.containsKey(HOMINGSOLUTION)) {
325 if (params.get(HOMINGSOLUTION).equals("none")) {
326 execution.setVariable("homing", false);
328 execution.setVariable("homing", true);
334 if (flowsToExecute.isEmpty()) {
335 throw new IllegalStateException("Macro did not come up with a valid execution path.");
337 List<String> flowNames = new ArrayList<>();
338 logger.info("List of BuildingBlocks to execute:");
339 for (ExecuteBuildingBlock ebb : flowsToExecute) {
340 logger.info(ebb.getBuildingBlock().getBpmnFlowName());
341 flowNames.add(ebb.getBuildingBlock().getBpmnFlowName());
343 execution.setVariable("flowNames", flowNames);
344 execution.setVariable(G_CURRENT_SEQUENCE, 0);
345 execution.setVariable("retryCount", 0);
346 execution.setVariable("isRollback", false);
347 execution.setVariable("flowsToExecute", flowsToExecute);
348 execution.setVariable("isRollbackComplete", false);
350 } catch (Exception ex) {
351 buildAndThrowException(execution, "Exception in create execution list " + ex.getMessage(), ex);
355 protected <T> List<T> getRelatedResourcesInVfModule(String vnfId, String vfModuleId, Class<T> resultClass, AAIObjectType type) {
356 List<T> vnfcs = new ArrayList<>();
357 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId);
358 AAIResultWrapper vfModuleResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri);
359 Optional<Relationships> relationshipsOp = vfModuleResultsWrapper.getRelationships();
360 if (!relationshipsOp.isPresent()) {
361 logger.debug("No relationships were found for vfModule in AAI");
363 Relationships relationships = relationshipsOp.get();
364 List<AAIResultWrapper> vnfcResultWrappers = relationships.getByType(type);
365 for(AAIResultWrapper vnfcResultWrapper : vnfcResultWrappers) {
366 Optional<T> vnfcOp = vnfcResultWrapper.asBean(resultClass);
367 if(vnfcOp.isPresent()) {
368 vnfcs.add(vnfcOp.get());
375 protected <T> List<T> getRelatedResourcesInVnfc(Vnfc vnfc, Class<T> resultClass, AAIObjectType type) {
377 List<T> configurations = new ArrayList<>();
378 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VNFC, vnfc.getVnfcName());
379 AAIResultWrapper vnfcResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri);
380 Optional<Relationships> relationshipsOp = vnfcResultsWrapper.getRelationships();
381 if (!relationshipsOp.isPresent()) {
382 logger.debug("No relationships were found for VNFC in AAI");
384 Relationships relationships = relationshipsOp.get();
385 List<AAIResultWrapper> configurationResultWrappers = this.getResultWrappersFromRelationships(relationships, type);
386 for(AAIResultWrapper configurationResultWrapper : configurationResultWrappers) {
387 Optional<T> configurationOp = configurationResultWrapper.asBean(resultClass);
388 if(configurationOp.isPresent()) {
389 configurations.add(configurationOp.get());
393 return configurations;
396 protected List<AAIResultWrapper> getResultWrappersFromRelationships(Relationships relationships, AAIObjectType type){
397 return relationships.getByType(type);
400 protected boolean isConfiguration(List<OrchestrationFlow> orchFlows) {
401 for(OrchestrationFlow flow : orchFlows) {
402 if(flow.getFlowName().contains("Configuration")) {
409 protected List<ExecuteBuildingBlock> getConfigBuildingBlocks(ServiceInstancesRequest sIRequest, List<OrchestrationFlow> orchFlows, String requestId, Resource resourceKey,
410 String apiVersion, String resourceId, String requestAction, boolean aLaCarte, String vnfType,
411 WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, DelegateExecution execution) {
413 List<ExecuteBuildingBlock> flowsToExecuteConfigs = new ArrayList<>();
414 List<OrchestrationFlow> result = new ArrayList<>(orchFlows);
415 result = orchFlows.stream().filter(item -> item.getFlowName().contains(FABRIC_CONFIGURATION)).collect(Collectors.toList());
416 String vnfId = workflowResourceIds.getVnfId();
417 String vfModuleId = workflowResourceIds.getVfModuleId();
419 String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
420 String vfModuleCustomizationUUID = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
422 List<org.onap.aai.domain.yang.Vnfc> vnfcs = getRelatedResourcesInVfModule(vnfId, vfModuleId, org.onap.aai.domain.yang.Vnfc.class, AAIObjectType.VNFC);
423 for(org.onap.aai.domain.yang.Vnfc vnfc : vnfcs) {
424 List<org.onap.aai.domain.yang.Configuration> configurations = getRelatedResourcesInVnfc(vnfc, org.onap.aai.domain.yang.Configuration.class, AAIObjectType.CONFIGURATION);
425 if (configurations.size() > 1){
426 String multipleRelationshipsError = "Multiple relationships exist from VNFC "+vnfc.getVnfcName()+" to Configurations";
427 buildAndThrowException(execution, multipleRelationshipsError, new Exception(multipleRelationshipsError));
429 for(org.onap.aai.domain.yang.Configuration configuration : configurations) {
430 workflowResourceIds.setConfigurationId(configuration.getConfigurationId());
431 for(OrchestrationFlow orchFlow : result) {
432 resourceKey.setVfModuleCustomizationId(vfModuleCustomizationUUID);
433 resourceKey.setCvnfModuleCustomizationId(vnfc.getModelCustomizationId());
434 resourceKey.setVnfCustomizationId(vnfCustomizationUUID);
435 ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, resourceId,
436 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, true);
437 String vnfcName = getVnfcNameForConfiguration(configuration);
438 if(vnfcName == null || vnfcName.isEmpty()) {
439 buildAndThrowException(execution, "Exception in create execution list " + ": VnfcName does not exist or is null while there is a configuration for the vfModule", new Exception("Vnfc and Configuration do not match"));
441 ebb.getConfigurationResourceKeys().setVnfcName(vnfcName);
442 flowsToExecuteConfigs.add(ebb);
446 return flowsToExecuteConfigs;
449 protected String getVnfcNameForConfiguration(org.onap.aai.domain.yang.Configuration configuration) {
450 AAIResultWrapper wrapper = new AAIResultWrapper(configuration);
451 Optional<Relationships> relationshipsOp = wrapper.getRelationships();
452 if (!relationshipsOp.isPresent()) {
453 logger.debug("No relationships were found for Configuration in AAI");
456 Relationships relationships = relationshipsOp.get();
457 List<AAIResultWrapper> vnfcResultWrappers = relationships.getByType(AAIObjectType.VNFC);
458 if(vnfcResultWrappers.size() > 1 || vnfcResultWrappers.isEmpty()) {
459 logger.debug("Too many vnfcs or no vnfc found that are related to configuration");
461 Optional<Vnfc> vnfcOp = vnfcResultWrappers.get(0).asBean(Vnfc.class);
462 if(vnfcOp.isPresent()) {
463 return vnfcOp.get().getVnfcName();
470 protected List<Resource> sortVfModulesByBaseFirst(List<Resource> vfModuleResources) {
472 for(Resource resource : vfModuleResources){
473 if(resource.isBaseVfModule()){
474 Collections.swap(vfModuleResources, 0, count);
479 return vfModuleResources;
482 protected List<Resource> sortVfModulesByBaseLast(List<Resource> vfModuleResources) {
484 for(Resource resource : vfModuleResources){
485 if(resource.isBaseVfModule()){
486 Collections.swap(vfModuleResources, vfModuleResources.size()-1, count);
491 return vfModuleResources;
494 private void updateResourceIdsFromAAITraversal(List<ExecuteBuildingBlock> flowsToExecute,
495 List<Resource> resourceCounter, List<Pair<WorkflowType, String>> aaiResourceIds, String serviceInstanceId) {
496 for(Pair<WorkflowType,String> pair : aaiResourceIds){
497 logger.debug(pair.getValue0() + ", " + pair.getValue1());
500 Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)).forEach(type -> {
501 List<Resource> resources = resourceCounter.stream().filter(x -> type.equals(x.getResourceType())).collect(Collectors.toList());
502 for(int i = 0; i < resources.size(); i++){
503 updateWorkflowResourceIds(flowsToExecute, type, resources.get(i).getResourceId(), retrieveAAIResourceId(aaiResourceIds,type), null, serviceInstanceId);
508 private String retrieveAAIResourceId(List<Pair<WorkflowType, String>> aaiResourceIds, WorkflowType resource){
510 for(int i = 0; i<aaiResourceIds.size();i++){
511 if(aaiResourceIds.get(i).getValue0() == resource){
512 id = aaiResourceIds.get(i).getValue1();
513 aaiResourceIds.remove(i);
519 private void generateResourceIds(List<ExecuteBuildingBlock> flowsToExecute, List<Resource> resourceCounter, String serviceInstanceId) {
520 Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)).forEach(type -> {
521 List<Resource> resources = resourceCounter.stream().filter(x -> type.equals(x.getResourceType())).collect(Collectors.toList());
522 for(int i = 0; i < resources.size(); i++){
523 Resource resource = resourceCounter.stream().filter(x -> type.equals(x.getResourceType()))
524 .collect(Collectors.toList()).get(i);
525 updateWorkflowResourceIds(flowsToExecute, type, resource.getResourceId(), null, resource.getVirtualLinkKey(),serviceInstanceId);
530 protected void updateWorkflowResourceIds(List<ExecuteBuildingBlock> flowsToExecute, WorkflowType resource, String key, String id, String virtualLinkKey, String serviceInstanceId){
531 String resourceId = id;
532 if(resourceId==null){
533 resourceId = UUID.randomUUID().toString();
535 for(ExecuteBuildingBlock ebb : flowsToExecute){
536 if(key != null && key.equalsIgnoreCase(ebb.getBuildingBlock().getKey()) && ebb.getBuildingBlock().getBpmnFlowName().contains(resource.toString())){
537 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
538 workflowResourceIds.setServiceInstanceId(serviceInstanceId);
539 if(resource == WorkflowType.VNF){
540 workflowResourceIds.setVnfId(resourceId);
541 }else if(resource == WorkflowType.VFMODULE){
542 workflowResourceIds.setVfModuleId(resourceId);
543 }else if(resource == WorkflowType.VOLUMEGROUP){
544 workflowResourceIds.setVolumeGroupId(resourceId);
545 }else if(resource == WorkflowType.NETWORK){
546 workflowResourceIds.setNetworkId(resourceId);
547 }else if(resource == WorkflowType.NETWORKCOLLECTION){
548 workflowResourceIds.setNetworkCollectionId(resourceId);
549 }else if(resource == WorkflowType.CONFIGURATION){
550 workflowResourceIds.setConfigurationId(resourceId);
552 ebb.setWorkflowResourceIds(workflowResourceIds);
554 if(virtualLinkKey != null && ebb.getBuildingBlock().getIsVirtualLink()
555 && virtualLinkKey.equalsIgnoreCase(ebb.getBuildingBlock().getVirtualLinkKey())) {
556 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
557 workflowResourceIds.setServiceInstanceId(serviceInstanceId);
558 workflowResourceIds.setNetworkId(resourceId);
559 ebb.setWorkflowResourceIds(workflowResourceIds);
564 protected CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution, org.onap.so.db.catalog.beans.Service service) {
565 CollectionResourceCustomization networkCollection = null;
567 for(CollectionResourceCustomization collectionCust : service.getCollectionResourceCustomizations()){
568 if(catalogDbClient.getNetworkCollectionResourceCustomizationByID(collectionCust.getModelCustomizationUUID()) != null) {
569 networkCollection = collectionCust;
575 }else if(count > 1) {
576 buildAndThrowException(execution, "Found multiple Network Collections in the Service model, only one per Service is supported.");
578 return networkCollection;
581 protected void traverseCatalogDbService(DelegateExecution execution, ServiceInstancesRequest sIRequest,
582 List<Resource> resourceCounter) {
583 String modelUUID = sIRequest.getRequestDetails().getModelInfo().getModelVersionId();
584 org.onap.so.db.catalog.beans.Service service = catalogDbClient.getServiceByID(modelUUID);
585 if (service == null) {
586 buildAndThrowException(execution, "Could not find the service model in catalog db.");
588 resourceCounter.add(new Resource(WorkflowType.SERVICE,service.getModelUUID(),false));
589 if (service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty()) {
590 List<CollectionResourceCustomization> customizations = service.getCollectionResourceCustomizations();
591 if(customizations.isEmpty()) {
592 logger.debug("No Collections found. CollectionResourceCustomization list is empty.");
594 CollectionResourceCustomization collectionResourceCustomization = findCatalogNetworkCollection(execution, service);
595 if(collectionResourceCustomization!=null){
596 resourceCounter.add(new Resource(WorkflowType.NETWORKCOLLECTION,collectionResourceCustomization.getModelCustomizationUUID(),false));
597 logger.debug("Found a network collection");
598 if(collectionResourceCustomization.getCollectionResource()!=null){
599 if(collectionResourceCustomization.getCollectionResource().getInstanceGroup() != null){
600 String toscaNodeType = collectionResourceCustomization.getCollectionResource().getInstanceGroup().getToscaNodeType();
601 if (toscaNodeType != null && toscaNodeType.contains("NetworkCollection")) {
603 org.onap.so.db.catalog.beans.InstanceGroup instanceGroup = collectionResourceCustomization.getCollectionResource().getInstanceGroup();
604 CollectionResourceInstanceGroupCustomization collectionInstCust = null;
605 if(!instanceGroup.getCollectionInstanceGroupCustomizations().isEmpty()) {
606 for(CollectionResourceInstanceGroupCustomization collectionInstanceGroupTemp : instanceGroup.getCollectionInstanceGroupCustomizations()) {
607 if(collectionInstanceGroupTemp.getModelCustomizationUUID().equalsIgnoreCase(collectionResourceCustomization.getModelCustomizationUUID())) {
608 collectionInstCust = collectionInstanceGroupTemp;
612 if(collectionInstCust != null && collectionInstCust.getSubInterfaceNetworkQuantity() != null) {
613 minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity();
616 logger.debug("minNetworks: {}" , minNetworks);
617 CollectionNetworkResourceCustomization collectionNetworkResourceCust = null;
618 for(CollectionNetworkResourceCustomization collectionNetworkTemp : instanceGroup.getCollectionNetworkResourceCustomizations()) {
619 if(collectionNetworkTemp.getNetworkResourceCustomization().getModelCustomizationUUID().equalsIgnoreCase(collectionResourceCustomization.getModelCustomizationUUID())) {
620 collectionNetworkResourceCust = collectionNetworkTemp;
624 for (int i = 0; i < minNetworks; i++) {
625 if(collectionNetworkResourceCust != null && collectionInstCust != null) {
626 Resource resource = new Resource(WorkflowType.VIRTUAL_LINK,collectionNetworkResourceCust.getModelCustomizationUUID(),false);
627 resource.setVirtualLinkKey(Integer.toString(i));
628 resourceCounter.add(resource);
632 logger.debug("Instance Group tosca node type does not contain NetworkCollection: {}" , toscaNodeType);
635 logger.debug("No Instance Group found for network collection.");
638 logger.debug("No Network Collection found. collectionResource is null");
641 logger.debug("No Network Collection Customization found");
644 if (resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()).collect(Collectors.toList()).isEmpty()) {
645 if (service.getNetworkCustomizations() == null) {
646 logger.debug("No networks were found on this service model");
648 for (int i = 0; i < service.getNetworkCustomizations().size(); i++) {
649 resourceCounter.add(new Resource(WorkflowType.NETWORK,service.getNetworkCustomizations().get(i).getModelCustomizationUUID(),false));
654 buildAndThrowException(execution,
655 "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");
660 protected void traverseAAIService(DelegateExecution execution, List<Resource> resourceCounter, String resourceId, List<Pair<WorkflowType, String>> aaiResourceIds) {
662 ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
663 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = bbInputSetup
664 .getExistingServiceInstance(serviceInstanceAAI);
665 resourceCounter.add(new Resource(WorkflowType.SERVICE,serviceInstanceMSO.getServiceInstanceId(),false));
666 if (serviceInstanceMSO.getVnfs() != null) {
667 for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO
669 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VNF, vnf.getVnfId()));
670 resourceCounter.add(new Resource(WorkflowType.VNF,vnf.getVnfId(),false));
671 if (vnf.getVfModules() != null) {
672 for (VfModule vfModule : vnf.getVfModules()) {
673 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
674 resourceCounter.add(new Resource(WorkflowType.VFMODULE,vfModule.getVfModuleId(),false));
677 if (vnf.getVolumeGroups() != null) {
678 for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
679 .getVolumeGroups()) {
680 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
681 resourceCounter.add(new Resource(WorkflowType.VOLUMEGROUP,volumeGroup.getVolumeGroupId(),false));
686 if (serviceInstanceMSO.getNetworks() != null) {
687 for (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network : serviceInstanceMSO
689 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.NETWORK, network.getNetworkId()));
690 resourceCounter.add(new Resource(WorkflowType.NETWORK,network.getNetworkId(),false));
693 if (serviceInstanceMSO.getCollection() != null) {
694 logger.debug("found networkcollection");
695 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.NETWORKCOLLECTION, serviceInstanceMSO.getCollection().getId()));
696 resourceCounter.add(new Resource(WorkflowType.NETWORKCOLLECTION,serviceInstanceMSO.getCollection().getId(),false));
698 if (serviceInstanceMSO.getConfigurations() !=null) {
699 for(Configuration config : serviceInstanceMSO.getConfigurations()){
700 Optional<org.onap.aai.domain.yang.Configuration> aaiConfig = aaiConfigurationResources.getConfiguration(config.getConfigurationId());
701 if(aaiConfig.isPresent() && aaiConfig.get().getRelationshipList()!=null){
702 for(Relationship relationship : aaiConfig.get().getRelationshipList().getRelationship()){
703 if(relationship.getRelatedTo().contains("vnfc")){
704 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, config.getConfigurationId()));
705 resourceCounter.add(new Resource(WorkflowType.CONFIGURATION,config.getConfigurationId(),false));
712 } catch (Exception ex) {
713 buildAndThrowException(execution,
714 "Could not find existing Service Instance or related Instances to execute the request on.");
718 private void traverseAAIVnf(DelegateExecution execution, List<Resource> resourceCounter, String serviceId, String vnfId,
719 List<Pair<WorkflowType, String>> aaiResourceIds) {
721 ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId);
722 org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = bbInputSetup
723 .getExistingServiceInstance(serviceInstanceAAI);
724 resourceCounter.add(new Resource(WorkflowType.SERVICE,serviceInstanceMSO.getServiceInstanceId(),false));
725 if (serviceInstanceMSO.getVnfs() != null) {
726 for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO
728 if(vnf.getVnfId().equals(vnfId)){
729 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VNF, vnf.getVnfId()));
730 resourceCounter.add(new Resource(WorkflowType.VNF,vnf.getVnfId(),false));
731 if (vnf.getVfModules() != null) {
732 for (VfModule vfModule : vnf.getVfModules()) {
733 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
734 resourceCounter.add(new Resource(WorkflowType.VFMODULE,vfModule.getVfModuleId(),false));
735 findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(), resourceCounter, aaiResourceIds);
738 if (vnf.getVolumeGroups() != null) {
739 for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
740 .getVolumeGroups()) {
741 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
742 resourceCounter.add(new Resource(WorkflowType.VOLUMEGROUP,volumeGroup.getVolumeGroupId(),false));
749 } catch (Exception ex) {
750 buildAndThrowException(execution,
751 "Could not find existing Vnf or related Instances to execute the request on.");
755 private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, List<Resource> resourceCounter,
756 List<Pair<WorkflowType, String>> aaiResourceIds) {
758 org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId);
759 AAIResultWrapper vfModuleWrapper = new AAIResultWrapper(
760 new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule));
761 Optional<Relationships> relationshipsOp;
762 relationshipsOp = vfModuleWrapper.getRelationships();
763 if(relationshipsOp.isPresent()) {
764 relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get());
765 if(relationshipsOp.isPresent()){
766 Optional<Configuration> config = workflowActionUtils.extractRelationshipsConfiguration(relationshipsOp.get());
767 if(config.isPresent()){
768 aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, config.get().getConfigurationId()));
769 resourceCounter.add(new Resource(WorkflowType.CONFIGURATION, config.get().getConfigurationId(), false));
773 }catch (Exception ex){
774 buildAndThrowException(execution,
775 "Failed to find Configuration object from the vfModule.");
779 protected boolean traverseUserParamsService(DelegateExecution execution, List<Resource> resourceCounter,
780 ServiceInstancesRequest sIRequest, String requestAction)
782 boolean foundRelated = false;
783 boolean foundVfModuleOrVG = false;
784 String vnfCustomizationUUID = "";
785 String vfModuleCustomizationUUID = "";
786 if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
787 List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams();
788 for (Map<String, Object> params : userParams) {
789 if (params.containsKey(USERPARAMSERVICE)) {
790 ObjectMapper obj = new ObjectMapper();
791 String input = obj.writeValueAsString(params.get(USERPARAMSERVICE));
792 Service validate = obj.readValue(input, Service.class);
793 resourceCounter.add(new Resource(WorkflowType.SERVICE,validate.getModelInfo().getModelVersionId(),false));
794 if (validate.getResources().getVnfs() != null) {
795 for (Vnfs vnf : validate.getResources().getVnfs()) {
796 resourceCounter.add(new Resource(WorkflowType.VNF,vnf.getModelInfo().getModelCustomizationId(),false));
798 if(vnf.getModelInfo()!=null && vnf.getModelInfo().getModelCustomizationUuid()!=null){
799 vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid();
801 if (vnf.getVfModules() != null) {
802 for (VfModules vfModule : vnf.getVfModules()) {
803 VfModuleCustomization vfModuleCustomization = catalogDbClient
804 .getVfModuleCustomizationByModelCuztomizationUUID(
805 vfModule.getModelInfo().getModelCustomizationUuid());
806 if (vfModuleCustomization != null) {
808 if(vfModuleCustomization.getVfModule() != null && vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null && vfModuleCustomization.getVolumeHeatEnv() != null) {
809 resourceCounter.add(new Resource(WorkflowType.VOLUMEGROUP,vfModuleCustomization.getModelCustomizationUUID(),false));
811 foundVfModuleOrVG = true;
814 if(vfModuleCustomization.getVfModule() != null && vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null && vfModuleCustomization.getHeatEnvironment() != null){
816 foundVfModuleOrVG = true;
817 Resource resource = new Resource(WorkflowType.VFMODULE,vfModuleCustomization.getModelCustomizationUUID(),false);
818 if(vfModuleCustomization.getVfModule().getIsBase()!=null && vfModuleCustomization.getVfModule().getIsBase()){
819 resource.setBaseVfModule(true);
821 resource.setBaseVfModule(false);
823 resourceCounter.add(resource);
824 if(vfModule.getModelInfo()!=null && vfModule.getModelInfo().getModelCustomizationUuid()!=null){
825 vfModuleCustomizationUUID = vfModule.getModelInfo().getModelCustomizationUuid();
827 if(!vnfCustomizationUUID.equals("")&&!vfModuleCustomizationUUID.equals("")){
828 List<CvnfcConfigurationCustomization> configs = traverseCatalogDbForConfiguration(validate.getModelInfo().getModelVersionId(),vnfCustomizationUUID,vfModuleCustomizationUUID);
829 for(CvnfcConfigurationCustomization config : configs){
830 Resource configResource = new Resource(WorkflowType.CONFIGURATION,config.getConfigurationResource().getModelUUID(),false);
831 resource.setVnfCustomizationId(vnf.getModelInfo().getModelCustomizationId());
832 resource.setVfModuleCustomizationId(vfModule.getModelInfo().getModelCustomizationId());
833 resourceCounter.add(configResource);
837 if(!foundVfModuleOrVG){
838 buildAndThrowException(execution, "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null");
845 if (validate.getResources().getNetworks() != null) {
846 for (Networks network : validate.getResources().getNetworks()) {
847 resourceCounter.add(new Resource(WorkflowType.NETWORK,network.getModelInfo().getModelCustomizationId(),false));
850 if (requestAction.equals(CREATEINSTANCE)) {
851 String networkColCustId = queryCatalogDBforNetworkCollection(execution, sIRequest);
852 if (networkColCustId != null) {
853 resourceCounter.add(new Resource(WorkflowType.NETWORKCOLLECTION,networkColCustId,false));
865 protected List<CvnfcConfigurationCustomization> traverseCatalogDbForConfiguration(String serviceModelUUID, String vnfCustomizationUUID, String vfModuleCustomizationUUID) {
866 List<CvnfcConfigurationCustomization> configurations = new ArrayList<>();
868 List<CvnfcCustomization> cvnfcCustomizations = catalogDbClient.getCvnfcCustomization(serviceModelUUID,vnfCustomizationUUID, vfModuleCustomizationUUID);
869 for(CvnfcCustomization cvnfc : cvnfcCustomizations){
870 for(CvnfcConfigurationCustomization customization : cvnfc.getCvnfcConfigurationCustomization()){
871 if(customization.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)){
872 configurations.add(customization);
876 logger.debug("found {} fabric configuration(s)" , configurations.size() );
877 return configurations;
878 } catch (Exception ex){
879 logger.error("Error in finding configurations", ex);
880 return configurations;
884 protected String queryCatalogDBforNetworkCollection(DelegateExecution execution, ServiceInstancesRequest sIRequest) {
885 org.onap.so.db.catalog.beans.Service service = catalogDbClient
886 .getServiceByID(sIRequest.getRequestDetails().getModelInfo().getModelVersionId());
887 if (service != null) {
888 CollectionResourceCustomization networkCollection = this.findCatalogNetworkCollection(execution, service);
889 if(networkCollection != null) {
890 return networkCollection.getModelCustomizationUUID();
896 protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) {
897 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
898 workflowResourceIds.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
899 workflowResourceIds.setNetworkId((String) execution.getVariable("networkId"));
900 workflowResourceIds.setVfModuleId((String) execution.getVariable("vfModuleId"));
901 workflowResourceIds.setVnfId((String) execution.getVariable("vnfId"));
902 workflowResourceIds.setVolumeGroupId((String) execution.getVariable("volumeGroupId"));
903 workflowResourceIds.setInstanceGroupId((String) execution.getVariable("instanceGroupId"));
904 return workflowResourceIds;
907 protected Resource extractResourceIdAndTypeFromUri(String uri) {
908 Pattern patt = Pattern.compile(
909 "[vV]\\d+.*?(?:(?:/(?<type>" + supportedTypes + ")(?:/(?<id>[^/]+))?)(?:/(?<action>[^/]+))?)?$");
910 Matcher m = patt.matcher(uri);
911 Boolean generated = false;
914 logger.debug("found match on {} : {} " , uri , m);
915 String type = m.group("type");
916 String id = m.group("id");
917 String action = m.group("action");
919 throw new IllegalArgumentException("Uri could not be parsed. No type found. " + uri);
921 if (action == null) {
922 if (type.equals(SERVICE_INSTANCES) && (id == null || id.equals("assign"))) {
923 id = UUID.randomUUID().toString();
925 }else if (type.equals(VF_MODULES) && id.equals("scaleOut")) {
926 id = UUID.randomUUID().toString();
930 if (action.matches(supportedTypes)) {
931 id = UUID.randomUUID().toString();
936 return new Resource(WorkflowType.fromString(convertTypeFromPlural(type)), id, generated);
938 throw new IllegalArgumentException("Uri could not be parsed: " + uri);
942 protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName,
943 RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws Exception {
945 if ("SERVICE".equalsIgnoreCase(type.toString())) {
946 String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId();
947 String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType();
948 if (instanceName != null) {
949 Optional<ServiceInstance> serviceInstanceAAI = bbInputSetupUtils
950 .getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName);
951 if (serviceInstanceAAI.isPresent()) {
952 return serviceInstanceAAI.get().getServiceInstanceId();
955 } else if ("NETWORK".equalsIgnoreCase(type.toString())) {
956 Optional<L3Network> network = bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(
957 workflowResourceIds.getServiceInstanceId(), instanceName);
958 if (network.isPresent()) {
959 return network.get().getNetworkId();
961 } else if ("VNF".equalsIgnoreCase(type.toString())) {
962 Optional<GenericVnf> vnf = bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(
963 workflowResourceIds.getServiceInstanceId(), instanceName);
964 if (vnf.isPresent()) {
965 return vnf.get().getVnfId();
967 } else if ("VFMODULE".equalsIgnoreCase(type.toString())) {
968 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId());
969 if (vnf != null && vnf.getVfModules() != null) {
970 for (org.onap.aai.domain.yang.VfModule vfModule : vnf.getVfModules().getVfModule()) {
971 if (vfModule.getVfModuleName().equalsIgnoreCase(instanceName)) {
972 return vfModule.getVfModuleId();
976 } else if ("VOLUMEGROUP".equalsIgnoreCase(type.toString())) {
977 Optional<VolumeGroup> volumeGroup = bbInputSetupUtils
978 .getRelatedVolumeGroupByNameFromVnf(workflowResourceIds.getVnfId(), instanceName);
979 if (volumeGroup.isPresent()) {
980 return volumeGroup.get().getVolumeGroupId();
982 GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId());
983 if (vnf != null && vnf.getVfModules() != null) {
984 for (org.onap.aai.domain.yang.VfModule vfModule : vnf.getVfModules().getVfModule()) {
985 Optional<VolumeGroup> volumeGroupFromVfModule = bbInputSetupUtils
986 .getRelatedVolumeGroupByNameFromVfModule(vnf.getVnfId(), vfModule.getVfModuleId(), instanceName);
987 if (volumeGroupFromVfModule.isPresent()) {
988 return volumeGroupFromVfModule.get().getVolumeGroupId();
993 return generatedResourceId;
994 } catch (Exception ex) {
995 logger.error(WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI, ex);
996 throw new IllegalStateException(
997 WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI);
1001 protected String convertTypeFromPlural(String type) {
1002 if (!type.matches(supportedTypes)) {
1005 if (type.equals(SERVICE_INSTANCES)) {
1008 return type.substring(0, 1).toUpperCase() + type.substring(1, type.length() - 1);
1013 protected List<ExecuteBuildingBlock> sortExecutionPathByObjectForVlanTagging(List<ExecuteBuildingBlock> orchFlows,
1014 String requestAction) {
1015 List<ExecuteBuildingBlock> sortedOrchFlows = new ArrayList<>();
1016 if (requestAction.equals(CREATEINSTANCE)) {
1017 for (ExecuteBuildingBlock ebb : orchFlows) {
1018 if (ebb.getBuildingBlock().getBpmnFlowName().equals("AssignNetworkBB")) {
1019 String key = ebb.getBuildingBlock().getKey();
1020 boolean isVirtualLink = Boolean.TRUE.equals(ebb.getBuildingBlock().getIsVirtualLink());
1021 String virtualLinkKey = ebb.getBuildingBlock().getVirtualLinkKey();
1022 sortedOrchFlows.add(ebb);
1023 for (ExecuteBuildingBlock ebb2 : orchFlows) {
1024 if (!isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("CreateNetworkBB")
1025 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
1026 sortedOrchFlows.add(ebb2);
1029 if(isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("CreateNetworkBB")
1030 && ebb2.getBuildingBlock().getVirtualLinkKey().equalsIgnoreCase(virtualLinkKey)) {
1031 sortedOrchFlows.add(ebb2);
1035 for (ExecuteBuildingBlock ebb2 : orchFlows) {
1036 if (!isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("ActivateNetworkBB")
1037 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
1038 sortedOrchFlows.add(ebb2);
1041 if(isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals("ActivateNetworkBB")
1042 && ebb2.getBuildingBlock().getVirtualLinkKey().equalsIgnoreCase(virtualLinkKey)) {
1043 sortedOrchFlows.add(ebb2);
1047 } else if (ebb.getBuildingBlock().getBpmnFlowName().equals("CreateNetworkBB")
1048 || ebb.getBuildingBlock().getBpmnFlowName().equals("ActivateNetworkBB")) {
1050 } else if (!ebb.getBuildingBlock().getBpmnFlowName().equals("")) {
1051 sortedOrchFlows.add(ebb);
1054 } else if (requestAction.equals("deleteInstance")) {
1055 for (ExecuteBuildingBlock ebb : orchFlows) {
1056 if (ebb.getBuildingBlock().getBpmnFlowName().equals("DeactivateNetworkBB")) {
1057 sortedOrchFlows.add(ebb);
1058 String key = ebb.getBuildingBlock().getKey();
1059 for (ExecuteBuildingBlock ebb2 : orchFlows) {
1060 if (ebb2.getBuildingBlock().getBpmnFlowName().equals("DeleteNetworkBB")
1061 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
1062 sortedOrchFlows.add(ebb2);
1066 for (ExecuteBuildingBlock ebb2 : orchFlows) {
1067 if (ebb2.getBuildingBlock().getBpmnFlowName().equals("UnassignNetworkBB")
1068 && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
1069 sortedOrchFlows.add(ebb2);
1073 } else if (ebb.getBuildingBlock().getBpmnFlowName().equals("DeleteNetworkBB")
1074 || ebb.getBuildingBlock().getBpmnFlowName().equals("UnassignNetworkBB")) {
1076 } else if (!ebb.getBuildingBlock().getBpmnFlowName().equals("")) {
1077 sortedOrchFlows.add(ebb);
1081 return sortedOrchFlows;
1084 protected List<ExecuteBuildingBlock> buildExecuteBuildingBlockList(List<OrchestrationFlow> orchFlows,
1085 List<Resource> resourceCounter, String requestId, String apiVersion, String resourceId, WorkflowType resourceType,
1086 String requestAction, boolean aLaCarte, String vnfType,
1087 WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails) {
1088 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
1089 for (OrchestrationFlow orchFlow : orchFlows) {
1090 if (orchFlow.getFlowName().contains(SERVICE)) {
1091 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.SERVICE == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1092 workflowResourceIds.setServiceInstanceId(resourceId);
1093 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.SERVICE == x.getResourceType())
1094 .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1095 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1097 } else if (orchFlow.getFlowName().contains(VNF)) {
1098 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.VNF == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1099 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.VNF == x.getResourceType())
1100 .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1101 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1103 } else if (orchFlow.getFlowName().contains(NETWORK)
1104 && !orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
1105 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.NETWORK == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1106 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.NETWORK == x.getResourceType())
1107 .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1108 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1110 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.VIRTUAL_LINK == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1111 Resource resource = resourceCounter.stream().filter(x -> WorkflowType.VIRTUAL_LINK == x.getResourceType())
1112 .collect(Collectors.toList()).get(i);
1113 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource, apiVersion, resourceId,
1114 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, true, resource.getVirtualLinkKey(), false));
1116 } else if (orchFlow.getFlowName().contains(VFMODULE)) {
1117 List<Resource> vfModuleResourcesSorted = null;
1118 if(requestAction.equals("createInstance")||requestAction.equals("assignInstance")||requestAction.equals("activateInstance")){
1119 vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceCounter.stream().filter(x -> WorkflowType.VFMODULE == x.getResourceType())
1120 .collect(Collectors.toList()));
1122 vfModuleResourcesSorted = sortVfModulesByBaseLast(resourceCounter.stream().filter(x -> WorkflowType.VFMODULE == x.getResourceType())
1123 .collect(Collectors.toList()));
1125 for (int i = 0; i < vfModuleResourcesSorted.size(); i++) {
1126 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, vfModuleResourcesSorted.get(i), apiVersion, resourceId,
1127 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1129 } else if (orchFlow.getFlowName().contains(VOLUMEGROUP)) {
1130 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.VOLUMEGROUP == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1131 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.VOLUMEGROUP == x.getResourceType())
1132 .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1133 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1135 } else if (orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
1136 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1137 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType())
1138 .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1139 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1141 } else if (orchFlow.getFlowName().contains(CONFIGURATION)) {
1142 for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.CONFIGURATION == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
1143 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.CONFIGURATION == x.getResourceType())
1144 .collect(Collectors.toList()).get(i), apiVersion, resourceId,
1145 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, true));
1148 flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, null, apiVersion, resourceId,
1149 requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
1152 return flowsToExecute;
1155 protected ExecuteBuildingBlock buildExecuteBuildingBlock(OrchestrationFlow orchFlow, String requestId, Resource resource,
1156 String apiVersion, String resourceId, String requestAction, boolean aLaCarte, String vnfType,
1157 WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, boolean isVirtualLink, String virtualLinkKey, boolean isConfiguration) {
1158 ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
1159 BuildingBlock buildingBlock = new BuildingBlock();
1160 buildingBlock.setBpmnFlowName(orchFlow.getFlowName());
1161 buildingBlock.setMsoId(UUID.randomUUID().toString());
1162 if(resource == null){
1163 buildingBlock.setKey("");
1165 buildingBlock.setKey(resource.getResourceId());
1167 buildingBlock.setIsVirtualLink(isVirtualLink);
1168 buildingBlock.setVirtualLinkKey(virtualLinkKey);
1169 executeBuildingBlock.setApiVersion(apiVersion);
1170 executeBuildingBlock.setaLaCarte(aLaCarte);
1171 executeBuildingBlock.setRequestAction(requestAction);
1172 executeBuildingBlock.setResourceId(resourceId);
1173 executeBuildingBlock.setVnfType(vnfType);
1174 executeBuildingBlock.setWorkflowResourceIds(workflowResourceIds);
1175 executeBuildingBlock.setRequestId(requestId);
1176 executeBuildingBlock.setBuildingBlock(buildingBlock);
1177 executeBuildingBlock.setRequestDetails(requestDetails);
1178 if(resource != null && (isConfiguration || resource.getResourceType().equals(WorkflowType.CONFIGURATION))){
1179 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
1180 if (resource != null){
1181 configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId());
1182 configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId());
1183 configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId());
1185 executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys);
1187 return executeBuildingBlock;
1190 protected List<OrchestrationFlow> queryNorthBoundRequestCatalogDb(DelegateExecution execution, String requestAction,
1191 WorkflowType resourceName, boolean aLaCarte, String cloudOwner) {
1192 return this.queryNorthBoundRequestCatalogDb(execution, requestAction, resourceName, aLaCarte, cloudOwner, "");
1195 protected List<OrchestrationFlow> queryNorthBoundRequestCatalogDb(DelegateExecution execution, String requestAction,
1196 WorkflowType resourceName, boolean aLaCarte, String cloudOwner, String serviceType) {
1197 List<OrchestrationFlow> listToExecute = new ArrayList<>();
1198 NorthBoundRequest northBoundRequest = null;
1199 if (serviceType.equalsIgnoreCase(SERVICE_TYPE_TRANSPORT)) {
1200 northBoundRequest = catalogDbClient
1201 .getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwnerAndServiceType(requestAction,
1202 resourceName.toString(), aLaCarte, cloudOwner, serviceType);
1204 northBoundRequest = catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(
1205 requestAction, resourceName.toString(), aLaCarte, cloudOwner);
1207 if(northBoundRequest == null){
1209 buildAndThrowException(execution,"The request: ALaCarte " + resourceName + " " + requestAction + " is not supported by GR_API.");
1211 buildAndThrowException(execution,"The request: Macro " + resourceName + " " + requestAction + " is not supported by GR_API.");
1214 if(northBoundRequest.getIsToplevelflow()!=null){
1215 execution.setVariable(G_ISTOPLEVELFLOW, northBoundRequest.getIsToplevelflow());
1217 List<OrchestrationFlow> flows = northBoundRequest.getOrchestrationFlowList();
1219 flows = new ArrayList<>();
1220 for (OrchestrationFlow flow : flows) {
1221 if (!flow.getFlowName().contains("BB")) {
1222 List<OrchestrationFlow> macroQueryFlows = catalogDbClient
1223 .getOrchestrationFlowByAction(flow.getFlowName());
1224 for (OrchestrationFlow macroFlow : macroQueryFlows) {
1225 listToExecute.add(macroFlow);
1228 listToExecute.add(flow);
1232 return listToExecute;
1235 protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) {
1236 logger.error(msg, ex);
1237 execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg);
1238 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
1241 protected void buildAndThrowException(DelegateExecution execution, String msg) {
1243 execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg);
1244 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
1247 public void handleRuntimeException (DelegateExecution execution){
1248 StringBuilder wfeExpMsg = new StringBuilder("Runtime error ");
1249 String runtimeErrorMessage = null;
1251 String javaExpMsg = (String) execution.getVariable("BPMN_javaExpMsg");
1252 if (javaExpMsg != null && !javaExpMsg.isEmpty()) {
1253 wfeExpMsg = wfeExpMsg.append(": ").append(javaExpMsg);
1255 runtimeErrorMessage = wfeExpMsg.toString();
1256 logger.error(runtimeErrorMessage);
1257 execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, runtimeErrorMessage);
1258 } catch (Exception e){
1259 logger.error("Runtime error", e);
1260 //if runtime message was mulformed
1261 runtimeErrorMessage = "Runtime error";
1263 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, runtimeErrorMessage);