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.servicedecomposition.tasks;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import java.util.Optional;
30 import java.util.UUID;
31 import org.camunda.bpm.engine.delegate.DelegateExecution;
32 import org.camunda.bpm.engine.delegate.JavaDelegate;
33 import org.javatuples.Pair;
34 import org.onap.so.bpmn.common.BuildingBlockExecution;
35 import org.onap.so.bpmn.common.DelegateExecutionImpl;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
52 import org.onap.so.bpmn.servicedecomposition.bbobjects.Tenant;
53 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
54 import org.onap.so.bpmn.servicedecomposition.bbobjects.Vnfc;
55 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
56 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
57 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
58 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
59 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
60 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
61 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
62 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
63 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
64 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException;
65 import org.onap.so.client.aai.AAICommonObjectMapperProvider;
66 import org.onap.so.client.aai.AAIObjectType;
67 import org.onap.so.client.aai.entities.AAIResultWrapper;
68 import org.onap.so.client.aai.entities.Relationships;
69 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
70 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
71 import org.onap.so.client.exception.ExceptionBuilder;
72 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
73 import org.onap.so.db.catalog.beans.CollectionResource;
74 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
75 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
76 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
77 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
78 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
79 import org.onap.so.db.catalog.beans.OrchestrationStatus;
80 import org.onap.so.db.catalog.beans.Service;
81 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
82 import org.onap.so.db.catalog.beans.VfModuleCustomization;
83 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
84 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
85 import org.onap.so.db.request.beans.InfraActiveRequests;
86 import org.onap.so.serviceinstancebeans.CloudConfiguration;
87 import org.onap.so.serviceinstancebeans.ModelInfo;
88 import org.onap.so.serviceinstancebeans.ModelType;
89 import org.onap.so.serviceinstancebeans.Networks;
90 import org.onap.so.serviceinstancebeans.RelatedInstance;
91 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
92 import org.onap.so.serviceinstancebeans.RequestDetails;
93 import org.onap.so.serviceinstancebeans.RequestParameters;
94 import org.onap.so.serviceinstancebeans.Resources;
95 import org.onap.so.serviceinstancebeans.VfModules;
96 import org.onap.so.serviceinstancebeans.Vnfs;
97 import org.slf4j.Logger;
98 import org.slf4j.LoggerFactory;
99 import org.springframework.beans.factory.annotation.Autowired;
100 import org.springframework.stereotype.Component;
101 import com.fasterxml.jackson.databind.ObjectMapper;
102 import com.fasterxml.jackson.databind.SerializationFeature;
104 @Component("BBInputSetup")
105 public class BBInputSetup implements JavaDelegate {
107 private static final Logger logger = LoggerFactory.getLogger(BBInputSetup.class);
108 private static final String FLOW_VAR_NAME = "flowToBeCalled";
109 private static final String LOOKUP_KEY_MAP_VAR_NAME = "lookupKeyMap";
110 private static final String GBB_INPUT_VAR_NAME = "gBBInput";
111 private static final String EXECUTE_BB_VAR_NAME = "buildingBlock";
112 private static final String VOLUME_GROUP = "VolumeGroup";
113 private static final String VF_MODULE = "VfModule";
114 private static final String NETWORK = "Network";
115 private static final String VNF = "Vnf";
116 private static final String NETWORK_COLLECTION = "NetworkCollection";
117 private static final String PREPROV = "PREPROV";
120 private BBInputSetupUtils bbInputSetupUtils;
123 private BBInputSetupMapperLayer mapperLayer;
126 private CloudInfoFromAAI cloudInfoFromAAI;
129 private ExceptionBuilder exceptionUtil;
131 private ObjectMapper mapper = new ObjectMapper();
133 public BBInputSetupUtils getBbInputSetupUtils() {
134 return bbInputSetupUtils;
137 public void setCloudInfoFromAAI(CloudInfoFromAAI cloudInfoFromAAI) {
138 this.cloudInfoFromAAI = cloudInfoFromAAI;
141 public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
142 this.bbInputSetupUtils = bbInputSetupUtils;
145 public BBInputSetupMapperLayer getMapperLayer() {
149 public void setMapperLayer(BBInputSetupMapperLayer mapperLayer) {
150 this.mapperLayer = mapperLayer;
154 * This method is used for executing the building block.
156 * It will get the BB from the execution object by checking if the aLaCarte and homing is true.
158 * Then it will get the GBB and execute it.
165 public void execute(DelegateExecution execution) throws Exception {
167 GeneralBuildingBlock outputBB = null;
168 ExecuteBuildingBlock executeBB = this.getExecuteBBFromExecution(execution);
169 String resourceId = executeBB.getResourceId();
170 String requestAction = executeBB.getRequestAction();
171 String vnfType = executeBB.getVnfType();
172 boolean aLaCarte = Boolean.TRUE.equals(executeBB.isaLaCarte());
173 boolean homing = Boolean.TRUE.equals(executeBB.isHoming());
174 Map<ResourceKey, String> lookupKeyMap = new HashMap<>();
175 outputBB = this.getGBB(executeBB, lookupKeyMap, requestAction, aLaCarte, resourceId, vnfType);
176 ObjectMapper mapper = new ObjectMapper();
177 mapper.enable(SerializationFeature.INDENT_OUTPUT);
178 logger.debug("GeneralBB: " + mapper.writeValueAsString(outputBB));
180 setHomingFlag(outputBB, homing, lookupKeyMap);
182 execution.setVariable(FLOW_VAR_NAME, executeBB.getBuildingBlock().getBpmnFlowName());
183 execution.setVariable(GBB_INPUT_VAR_NAME, outputBB);
184 execution.setVariable(LOOKUP_KEY_MAP_VAR_NAME, lookupKeyMap);
186 BuildingBlockExecution gBuildingBlockExecution = new DelegateExecutionImpl(execution);
187 execution.setVariable("gBuildingBlockExecution", gBuildingBlockExecution);
188 execution.setVariable("RetryCount", 1);
189 execution.setVariable("handlingCode", "Success");
190 } catch (Exception e) {
191 logger.error("Exception occurred", e);
192 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage());
196 protected void setHomingFlag(GeneralBuildingBlock outputBB, boolean homing, Map<ResourceKey, String> lookupKeyMap) {
198 if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null && homing && outputBB != null) {
199 for (GenericVnf vnf : outputBB.getCustomer().getServiceSubscription().getServiceInstances().get(0)
201 if (vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
202 vnf.setCallHoming(homing);
208 protected ExecuteBuildingBlock getExecuteBBFromExecution(DelegateExecution execution) {
209 return (ExecuteBuildingBlock) execution.getVariable(EXECUTE_BB_VAR_NAME);
212 protected GeneralBuildingBlock getGBB(ExecuteBuildingBlock executeBB, Map<ResourceKey, String> lookupKeyMap,
213 String requestAction, boolean aLaCarte, String resourceId, String vnfType) throws Exception {
214 String requestId = executeBB.getRequestId();
215 this.populateLookupKeyMapWithIds(executeBB.getWorkflowResourceIds(), lookupKeyMap);
216 RequestDetails requestDetails = executeBB.getRequestDetails();
217 if (requestDetails == null) {
218 requestDetails = bbInputSetupUtils.getRequestDetails(requestId);
220 if (requestDetails.getModelInfo() == null) {
221 return this.getGBBCM(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId);
223 ModelType modelType = requestDetails.getModelInfo().getModelType();
224 if (aLaCarte && modelType.equals(ModelType.service)) {
225 return this.getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId);
226 } else if (aLaCarte && !modelType.equals(ModelType.service)) {
227 return this.getGBBALaCarteNonService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId,
230 return this.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType);
235 protected void populateLookupKeyMapWithIds(WorkflowResourceIds workflowResourceIds,
236 Map<ResourceKey, String> lookupKeyMap) {
237 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, workflowResourceIds.getServiceInstanceId());
238 lookupKeyMap.put(ResourceKey.NETWORK_ID, workflowResourceIds.getNetworkId());
239 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, workflowResourceIds.getVnfId());
240 lookupKeyMap.put(ResourceKey.VF_MODULE_ID, workflowResourceIds.getVfModuleId());
241 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, workflowResourceIds.getVolumeGroupId());
242 lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, workflowResourceIds.getConfigurationId());
243 lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, workflowResourceIds.getInstanceGroupId());
246 protected GeneralBuildingBlock getGBBALaCarteNonService(ExecuteBuildingBlock executeBB,
247 RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String requestAction,
248 String resourceId, String vnfType) throws Exception {
249 String bbName = executeBB.getBuildingBlock().getBpmnFlowName();
250 String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
251 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
252 if (serviceInstanceId != null) {
253 aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
255 Service service = null;
256 if (aaiServiceInstance != null) {
257 service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
259 if (aaiServiceInstance != null && service != null) {
260 ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
261 serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
262 this.populateObjectsOnAssignAndCreateFlows(requestDetails, service, bbName, serviceInstance, lookupKeyMap,
263 resourceId, vnfType, executeBB.getBuildingBlock().getKey(),
264 executeBB.getConfigurationResourceKeys());
265 return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction,
268 logger.debug("Related Service Instance from AAI: {}", aaiServiceInstance);
269 logger.debug("Related Service Instance Model Info from AAI: {}", service);
270 throw new Exception("Could not find relevant information for related Service Instance");
274 protected GeneralBuildingBlock getGBBCM(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
275 Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId) throws Exception {
276 ServiceInstance serviceInstance = new ServiceInstance();
277 String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
278 serviceInstance.setServiceInstanceId(serviceInstanceId);
279 Customer customer = new Customer();
280 List<GenericVnf> genericVnfs = serviceInstance.getVnfs();
282 String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
284 org.onap.aai.domain.yang.GenericVnf aaiGenericVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
285 GenericVnf genericVnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiGenericVnf);
286 genericVnfs.add(genericVnf);
289 String instanceGroupId = lookupKeyMap.get(ResourceKey.INSTANCE_GROUP_ID);
290 if (instanceGroupId != null) {
291 org.onap.aai.domain.yang.InstanceGroup aaiInstancegroup =
292 bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId);
293 InstanceGroup instanceGroup = this.mapperLayer.mapAAIInstanceGroupIntoInstanceGroup(aaiInstancegroup);
294 instanceGroup.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
296 if (serviceInstanceId == null) {
297 Optional<org.onap.aai.domain.yang.ServiceInstance> aaiServiceInstanceOpt =
298 bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup(instanceGroupId);
299 if (aaiServiceInstanceOpt.isPresent()) {
300 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = aaiServiceInstanceOpt.get();
301 serviceInstance = this.mapperLayer.mapAAIServiceInstanceIntoServiceInstance(aaiServiceInstance);
302 WorkflowResourceIds workflowResourceIds = executeBB.getWorkflowResourceIds();
303 workflowResourceIds.setServiceInstanceId(serviceInstance.getServiceInstanceId());
304 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, workflowResourceIds.getServiceInstanceId());
306 throw new NoServiceInstanceFoundException("Related ServiceInstance not found in A&AI.");
309 RelatedInstanceList[] relatedInstanceList = requestDetails.getRelatedInstanceList();
310 if (relatedInstanceList != null) {
311 for (RelatedInstanceList relatedInstList : relatedInstanceList) {
312 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
313 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
314 org.onap.aai.domain.yang.GenericVnf aaiVnf =
315 bbInputSetupUtils.getAAIGenericVnf(relatedInstance.getInstanceId());
316 GenericVnf vnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiVnf);
317 instanceGroup.getVnfs().add(vnf);
322 serviceInstance.getInstanceGroups().add(instanceGroup);
323 customer.setServiceSubscription(new ServiceSubscription());
325 return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction,
329 protected void populateObjectsOnAssignAndCreateFlows(RequestDetails requestDetails, Service service, String bbName,
330 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId, String vnfType,
331 String configurationKey, ConfigurationResourceKeys configurationResourceKeys) throws Exception {
332 ModelInfo modelInfo = requestDetails.getModelInfo();
333 String instanceName = requestDetails.getRequestInfo().getInstanceName();
334 String productFamilyId = requestDetails.getRequestInfo().getProductFamilyId();
335 ModelType modelType = modelInfo.getModelType();
336 RelatedInstanceList[] relatedInstanceList = requestDetails.getRelatedInstanceList();
338 org.onap.so.serviceinstancebeans.Platform platform = requestDetails.getPlatform();
339 org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness = requestDetails.getLineOfBusiness();
341 if (modelType.equals(ModelType.network)) {
342 lookupKeyMap.put(ResourceKey.NETWORK_ID, resourceId);
343 this.populateL3Network(instanceName, modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
345 } else if (modelType.equals(ModelType.vnf)) {
346 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, resourceId);
347 this.populateGenericVnf(modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance,
348 lookupKeyMap, relatedInstanceList, resourceId, vnfType, null, productFamilyId);
349 } else if (modelType.equals(ModelType.volumeGroup)) {
350 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, resourceId);
351 this.populateVolumeGroup(modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
352 relatedInstanceList, instanceName, vnfType, null);
353 } else if (modelType.equals(ModelType.vfModule)) {
354 if (bbName.contains("Configuration")) {
355 String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
356 ModelInfo configurationModelInfo = new ModelInfo();
357 configurationModelInfo.setModelCustomizationUuid(configurationKey);
358 populateConfiguration(configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap,
359 configurationId, instanceName, configurationResourceKeys, requestDetails);
361 lookupKeyMap.put(ResourceKey.VF_MODULE_ID, resourceId);
362 this.populateVfModule(modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
363 relatedInstanceList, instanceName, null, requestDetails.getCloudConfiguration());
365 } else if (modelType.equals(ModelType.instanceGroup)) {
366 lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, resourceId);
367 this.populateInstanceGroup(modelInfo, service, serviceInstance, resourceId, instanceName);
373 protected void populateInstanceGroup(ModelInfo modelInfo, Service service, ServiceInstance serviceInstance,
374 String instanceGroupId, String instanceName) {
375 InstanceGroup instanceGroup = new InstanceGroup();
376 instanceGroup.setId(instanceGroupId);
377 instanceGroup.setInstanceGroupName(instanceName);
378 mapCatalogInstanceGroup(instanceGroup, modelInfo, service);
379 serviceInstance.getInstanceGroups().add(instanceGroup);
382 protected void mapCatalogInstanceGroup(InstanceGroup instanceGroup, ModelInfo modelInfo, Service service) {
383 // @TODO: this will populate the instanceGroup model info.
384 // Dependent on MSO-5821 653458 US - MSO - Enhance Catalog DB Schema & Adapter to support VNF Groups
387 protected void populateConfiguration(ModelInfo modelInfo, Service service, String bbName,
388 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
389 String instanceName, ConfigurationResourceKeys configurationResourceKeys, RequestDetails requestDetails) {
390 Configuration configuration = null;
391 for (Configuration configurationTemp : serviceInstance.getConfigurations()) {
392 if ((bbName.contains("Fabric") && configurationTemp.getConfigurationSubType() != null
393 && configurationTemp.getConfigurationSubType().equalsIgnoreCase("Fabric Config"))
394 || (lookupKeyMap.get(ResourceKey.CONFIGURATION_ID) != null && configurationTemp.getConfigurationId()
395 .equalsIgnoreCase(lookupKeyMap.get(ResourceKey.CONFIGURATION_ID)))) {
396 lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, configurationTemp.getConfigurationId());
397 configuration = configurationTemp;
398 org.onap.aai.domain.yang.Configuration aaiConfiguration =
399 bbInputSetupUtils.getAAIConfiguration(configuration.getConfigurationId());
400 if (aaiConfiguration != null) {
401 modelInfo.setModelCustomizationUuid(aaiConfiguration.getModelCustomizationId());
405 if (configuration == null && (bbName.equalsIgnoreCase(AssignFlows.FABRIC_CONFIGURATION.toString())
406 || bbName.equalsIgnoreCase(AssignFlows.VRF_CONFIGURATION.toString()))) {
407 configuration = this.createConfiguration(lookupKeyMap, instanceName, resourceId);
408 serviceInstance.getConfigurations().add(configuration);
410 if (configuration != null && bbName.contains("Fabric")) {
411 Vnfc vnfc = getVnfcToConfiguration(configurationResourceKeys.getVnfcName());
412 configuration.setVnfc(vnfc);
413 this.mapCatalogConfiguration(configuration, modelInfo, service, configurationResourceKeys);
414 } else if (configuration != null && bbName.contains("Vrf")) {
415 configuration.setModelInfoConfiguration(mapperLayer.mapCatalogConfigurationToConfiguration(
416 findConfigurationResourceCustomization(modelInfo, service), null));
417 configuration.setConfigurationType(configuration.getModelInfoConfiguration().getConfigurationType());
418 configuration.setConfigurationSubType(configuration.getModelInfoConfiguration().getConfigurationRole());
422 protected Vnfc getVnfcToConfiguration(String vnfcName) {
423 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VNFC, vnfcName);
424 Optional<org.onap.aai.domain.yang.Vnfc> vnfcOp =
425 bbInputSetupUtils.getAAIResourceDepthOne(uri).asBean(org.onap.aai.domain.yang.Vnfc.class);
426 if (vnfcOp.isPresent()) {
427 org.onap.aai.domain.yang.Vnfc vnfcAAI = vnfcOp.get();
428 return this.mapperLayer.mapAAIVnfc(vnfcAAI);
434 protected Configuration createConfiguration(Map<ResourceKey, String> lookupKeyMap, String instanceName,
436 lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, resourceId);
437 Configuration configuration = new Configuration();
438 configuration.setConfigurationId(resourceId);
439 configuration.setConfigurationName(instanceName);
440 configuration.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
441 return configuration;
444 protected void mapCatalogConfiguration(Configuration configuration, ModelInfo modelInfo, Service service,
445 ConfigurationResourceKeys configurationResourceKeys) {
446 ConfigurationResourceCustomization configurationResourceCustomization =
447 findConfigurationResourceCustomization(modelInfo, service);
448 CvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization =
449 findVnfVfmoduleCvnfcConfigurationCustomization(service.getModelUUID(),
450 configurationResourceKeys.getVfModuleCustomizationUUID(),
451 configurationResourceKeys.getVnfResourceCustomizationUUID(),
452 configurationResourceKeys.getCvnfcCustomizationUUID(), configurationResourceCustomization);
453 if (configurationResourceCustomization != null && vnfVfmoduleCvnfcConfigurationCustomization != null) {
454 configuration.setModelInfoConfiguration(this.mapperLayer.mapCatalogConfigurationToConfiguration(
455 configurationResourceCustomization, vnfVfmoduleCvnfcConfigurationCustomization));
457 logger.debug("for Fabric configuration mapping by VF MODULE CUST UUID: "
458 + configurationResourceKeys.getVfModuleCustomizationUUID());
459 vnfVfmoduleCvnfcConfigurationCustomization = findVnfVfmoduleCvnfcConfigurationCustomization(
460 service.getModelUUID(), configurationResourceKeys.getVnfResourceCustomizationUUID(),
461 configurationResourceKeys.getVfModuleCustomizationUUID(),
462 configurationResourceKeys.getCvnfcCustomizationUUID());
463 if (vnfVfmoduleCvnfcConfigurationCustomization != null) {
464 configuration.setModelInfoConfiguration(this.mapperLayer
465 .mapCatalogConfigurationToConfiguration(vnfVfmoduleCvnfcConfigurationCustomization));
470 protected CvnfcConfigurationCustomization findVnfVfmoduleCvnfcConfigurationCustomization(String serviceModelUUID,
471 String vfModuleCustomizationUUID, String vnfResourceCustomizationUUID, String cvnfcCustomizationUUID,
472 ConfigurationResourceCustomization configurationResourceCustomization) {
473 return bbInputSetupUtils.getCvnfcConfigurationCustomization(serviceModelUUID, vnfResourceCustomizationUUID,
474 vfModuleCustomizationUUID, cvnfcCustomizationUUID);
477 protected ConfigurationResourceCustomization findConfigurationResourceCustomization(ModelInfo modelInfo,
479 for (ConfigurationResourceCustomization resourceCust : service.getConfigurationCustomizations()) {
480 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
487 protected CvnfcConfigurationCustomization findVnfVfmoduleCvnfcConfigurationCustomization(String serviceModelUUID,
488 String vnfResourceCustomizationUUID, String vfModuleCustomizationUUID, String cvnfcCustomizationUUID) {
489 return bbInputSetupUtils.getCvnfcConfigurationCustomization(serviceModelUUID, vnfResourceCustomizationUUID,
490 vfModuleCustomizationUUID, cvnfcCustomizationUUID);
493 protected void populateVfModule(ModelInfo modelInfo, Service service, String bbName,
494 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
495 RelatedInstanceList[] relatedInstanceList, String instanceName, List<Map<String, String>> instanceParams,
496 CloudConfiguration cloudConfiguration) throws Exception {
497 String vnfModelCustomizationUUID = null;
498 if (relatedInstanceList != null) {
499 for (RelatedInstanceList relatedInstList : relatedInstanceList) {
500 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
501 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
502 vnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
504 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.volumeGroup)) {
505 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, relatedInstance.getInstanceId());
509 GenericVnf vnf = null;
510 for (GenericVnf tempVnf : serviceInstance.getVnfs()) {
511 if (tempVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
513 vnfModelCustomizationUUID =
514 this.bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()).getModelCustomizationId();
515 ModelInfo vnfModelInfo = new ModelInfo();
516 vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
517 this.mapCatalogVnf(tempVnf, vnfModelInfo, service);
518 Optional<String> volumeGroupIdOp = getVolumeGroupIdRelatedToVfModule(tempVnf, modelInfo,
519 cloudConfiguration.getCloudOwner(), cloudConfiguration.getLcpCloudRegionId(), lookupKeyMap);
520 if (volumeGroupIdOp.isPresent()) {
521 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupIdOp.get());
527 VfModule vfModule = null;
528 for (VfModule vfModuleTemp : vnf.getVfModules()) {
529 if (lookupKeyMap.get(ResourceKey.VF_MODULE_ID) != null
530 && vfModuleTemp.getVfModuleId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VF_MODULE_ID))) {
531 vfModule = vfModuleTemp;
533 String vfModuleCustId = bbInputSetupUtils.getAAIVfModule(vnf.getVnfId(), vfModuleTemp.getVfModuleId())
534 .getModelCustomizationId();
535 ModelInfo modelInfoVfModule = new ModelInfo();
536 modelInfoVfModule.setModelCustomizationId(vfModuleCustId);
537 mapCatalogVfModule(vfModuleTemp, modelInfoVfModule, service, vnfModelCustomizationUUID);
539 if (vfModule == null && bbName.equalsIgnoreCase(AssignFlows.VF_MODULE.toString())) {
540 vfModule = createVfModule(lookupKeyMap, resourceId, instanceName, instanceParams);
541 vnf.getVfModules().add(vfModule);
542 mapCatalogVfModule(vfModule, modelInfo, service, vnfModelCustomizationUUID);
545 logger.debug("Related VNF instance Id not found: {}", lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID));
546 throw new Exception("Could not find relevant information for related VNF");
550 protected Optional<String> getVolumeGroupIdRelatedToVfModule(GenericVnf vnf, ModelInfo modelInfo, String cloudOwner,
551 String cloudRegionId, Map<ResourceKey, String> lookupKeyMap) {
552 if (lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID) == null) {
553 for (VolumeGroup volumeGroup : vnf.getVolumeGroups()) {
554 String volumeGroupCustId =
555 bbInputSetupUtils.getAAIVolumeGroup(cloudOwner, cloudRegionId, volumeGroup.getVolumeGroupId())
556 .getModelCustomizationId();
557 if (modelInfo.getModelCustomizationId().equalsIgnoreCase(volumeGroupCustId)) {
558 return Optional.of(volumeGroup.getVolumeGroupId());
562 return Optional.empty();
565 protected void mapCatalogVfModule(VfModule vfModule, ModelInfo modelInfo, Service service,
566 String vnfModelCustomizationUUID) {
567 if (modelInfo.getModelCustomizationUuid() != null) {
568 modelInfo.setModelCustomizationId(modelInfo.getModelCustomizationUuid());
570 VnfResourceCustomization vnfResourceCustomization = null;
571 for (VnfResourceCustomization resourceCust : service.getVnfCustomizations()) {
572 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(vnfModelCustomizationUUID)) {
573 vnfResourceCustomization = resourceCust;
577 if (vnfResourceCustomization != null) {
578 VfModuleCustomization vfResourceCustomization = vnfResourceCustomization.getVfModuleCustomizations()
579 .stream() // Convert to steam
580 .filter(x -> modelInfo.getModelCustomizationId().equalsIgnoreCase(x.getModelCustomizationUUID()))// find
584 .findAny() // If 'findAny' then return found
586 if (vfResourceCustomization != null) {
587 vfModule.setModelInfoVfModule(this.mapperLayer.mapCatalogVfModuleToVfModule(vfResourceCustomization));
592 protected VfModule createVfModule(Map<ResourceKey, String> lookupKeyMap, String vfModuleId, String instanceName,
593 List<Map<String, String>> instanceParams) {
594 lookupKeyMap.put(ResourceKey.VF_MODULE_ID, vfModuleId);
595 VfModule vfModule = new VfModule();
596 vfModule.setVfModuleId(vfModuleId);
597 vfModule.setVfModuleName(instanceName);
598 vfModule.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
599 if (instanceParams != null) {
600 for (Map<String, String> params : instanceParams) {
601 vfModule.getCloudParams().putAll(params);
607 protected void populateVolumeGroup(ModelInfo modelInfo, Service service, String bbName,
608 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
609 RelatedInstanceList[] relatedInstanceList, String instanceName, String vnfType,
610 List<Map<String, String>> instanceParams) throws Exception {
611 VolumeGroup volumeGroup = null;
612 GenericVnf vnf = null;
613 String vnfModelCustomizationUUID = null;
614 String generatedVnfType = vnfType;
615 if (generatedVnfType == null || generatedVnfType.isEmpty()) {
616 generatedVnfType = service.getModelName() + "/" + modelInfo.getModelCustomizationName();
618 if (relatedInstanceList != null) {
619 for (RelatedInstanceList relatedInstList : relatedInstanceList) {
620 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
621 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
622 vnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationUuid();
627 for (GenericVnf tempVnf : serviceInstance.getVnfs()) {
628 if (tempVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
630 vnfModelCustomizationUUID =
631 bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()).getModelCustomizationId();
632 ModelInfo vnfModelInfo = new ModelInfo();
633 vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
634 mapCatalogVnf(tempVnf, vnfModelInfo, service);
638 if (vnf != null && vnfModelCustomizationUUID != null) {
639 for (VolumeGroup volumeGroupTemp : vnf.getVolumeGroups()) {
640 if (lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID) != null && volumeGroupTemp.getVolumeGroupId()
641 .equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID))) {
642 volumeGroup = volumeGroupTemp;
646 if (volumeGroup == null && bbName.equalsIgnoreCase(AssignFlows.VOLUME_GROUP.toString())) {
648 createVolumeGroup(lookupKeyMap, resourceId, instanceName, generatedVnfType, instanceParams);
649 vnf.getVolumeGroups().add(volumeGroup);
651 if (volumeGroup != null) {
652 mapCatalogVolumeGroup(volumeGroup, modelInfo, service, vnfModelCustomizationUUID);
655 logger.debug("Related VNF instance Id not found: {}", lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID));
656 throw new Exception("Could not find relevant information for related VNF");
660 protected VolumeGroup createVolumeGroup(Map<ResourceKey, String> lookupKeyMap, String volumeGroupId,
661 String instanceName, String vnfType, List<Map<String, String>> instanceParams) {
662 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupId);
663 VolumeGroup volumeGroup = new VolumeGroup();
664 volumeGroup.setVolumeGroupId(volumeGroupId);
665 volumeGroup.setVolumeGroupName(instanceName);
666 volumeGroup.setVnfType(vnfType);
667 volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
668 if (instanceParams != null) {
669 for (Map<String, String> params : instanceParams) {
670 volumeGroup.getCloudParams().putAll(params);
676 protected void mapCatalogVolumeGroup(VolumeGroup volumeGroup, ModelInfo modelInfo, Service service,
677 String vnfModelCustomizationUUID) {
678 VfModuleCustomization vfResourceCustomization =
679 getVfResourceCustomization(modelInfo, service, vnfModelCustomizationUUID);
680 if (vfResourceCustomization != null) {
681 volumeGroup.setModelInfoVfModule(this.mapperLayer.mapCatalogVfModuleToVfModule(vfResourceCustomization));
685 protected VfModuleCustomization getVfResourceCustomization(ModelInfo modelInfo, Service service,
686 String vnfModelCustomizationUUID) {
687 VnfResourceCustomization vnfResourceCustomization = null;
688 for (VnfResourceCustomization resourceCust : service.getVnfCustomizations()) {
689 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(vnfModelCustomizationUUID)) {
690 vnfResourceCustomization = resourceCust;
694 if (vnfResourceCustomization != null) {
695 for (VfModuleCustomization vfResourceCust : vnfResourceCustomization.getVfModuleCustomizations()) {
696 if (vfResourceCust.getModelCustomizationUUID()
697 .equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
698 return vfResourceCust;
706 protected void populateGenericVnf(ModelInfo modelInfo, String instanceName,
707 org.onap.so.serviceinstancebeans.Platform platform,
708 org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, Service service, String bbName,
709 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap,
710 RelatedInstanceList[] relatedInstanceList, String resourceId, String vnfType,
711 List<Map<String, String>> instanceParams, String productFamilyId) {
712 GenericVnf vnf = null;
713 ModelInfo instanceGroupModelInfo = null;
714 String instanceGroupId = null;
715 String generatedVnfType = vnfType;
716 if (generatedVnfType == null || generatedVnfType.isEmpty()) {
717 generatedVnfType = service.getModelName() + "/" + modelInfo.getModelCustomizationName();
719 if (relatedInstanceList != null) {
720 for (RelatedInstanceList relatedInstList : relatedInstanceList) {
721 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
722 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.networkInstanceGroup)) {
723 instanceGroupModelInfo = relatedInstance.getModelInfo();
724 instanceGroupId = relatedInstance.getInstanceId();
728 for (GenericVnf vnfTemp : serviceInstance.getVnfs()) {
729 if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null
730 && vnfTemp.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
731 String vnfModelCustId =
732 bbInputSetupUtils.getAAIGenericVnf(vnfTemp.getVnfId()).getModelCustomizationId();
733 modelInfo.setModelCustomizationUuid(vnfModelCustId);
738 if (vnf == null && bbName.equalsIgnoreCase(AssignFlows.VNF.toString())) {
739 vnf = createGenericVnf(lookupKeyMap, instanceName, platform, lineOfBusiness, resourceId, generatedVnfType,
740 instanceParams, productFamilyId);
741 serviceInstance.getVnfs().add(vnf);
742 mapVnfcCollectionInstanceGroup(vnf, modelInfo, service);
745 mapCatalogVnf(vnf, modelInfo, service);
746 if (instanceGroupId != null && instanceGroupModelInfo != null
747 && instanceGroupModelInfo.getModelType().equals(ModelType.networkInstanceGroup)
748 && !instanceGroupInList(vnf, instanceGroupId)) {
749 mapNetworkCollectionInstanceGroup(vnf, instanceGroupId);
754 protected boolean instanceGroupInList(GenericVnf vnf, String instanceGroupId) {
755 for (InstanceGroup instanceGroup : vnf.getInstanceGroups()) {
756 if (instanceGroup.getId() != null && instanceGroup.getId().equalsIgnoreCase(instanceGroupId)) {
763 protected void mapVnfcCollectionInstanceGroup(GenericVnf genericVnf, ModelInfo modelInfo, Service service) {
764 VnfResourceCustomization vnfResourceCustomization = getVnfResourceCustomizationFromService(modelInfo, service);
765 if (vnfResourceCustomization != null) {
766 List<VnfcInstanceGroupCustomization> vnfcInstanceGroups =
767 vnfResourceCustomization.getVnfcInstanceGroupCustomizations();
768 for (VnfcInstanceGroupCustomization vnfcInstanceGroupCust : vnfcInstanceGroups) {
769 InstanceGroup instanceGroup = this.createInstanceGroup();
770 org.onap.so.db.catalog.beans.InstanceGroup catalogInstanceGroup = bbInputSetupUtils
771 .getCatalogInstanceGroup(vnfcInstanceGroupCust.getInstanceGroup().getModelUUID());
772 instanceGroup.setModelInfoInstanceGroup(
773 this.mapperLayer.mapCatalogInstanceGroupToInstanceGroup(null, catalogInstanceGroup));
774 instanceGroup.getModelInfoInstanceGroup().setFunction(vnfcInstanceGroupCust.getFunction());
775 instanceGroup.getModelInfoInstanceGroup().setDescription(vnfcInstanceGroupCust.getDescription());
776 genericVnf.getInstanceGroups().add(instanceGroup);
781 protected void mapNetworkCollectionInstanceGroup(GenericVnf genericVnf, String instanceGroupId) {
782 org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup =
783 bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId);
784 InstanceGroup instanceGroup = this.mapperLayer.mapAAIInstanceGroupIntoInstanceGroup(aaiInstanceGroup);
785 instanceGroup.setModelInfoInstanceGroup(this.mapperLayer.mapCatalogInstanceGroupToInstanceGroup(null,
786 this.bbInputSetupUtils.getCatalogInstanceGroup(aaiInstanceGroup.getModelVersionId())));
787 genericVnf.getInstanceGroups().add(instanceGroup);
790 protected GenericVnf createGenericVnf(Map<ResourceKey, String> lookupKeyMap, String instanceName,
791 org.onap.so.serviceinstancebeans.Platform platform,
792 org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, String vnfId, String vnfType,
793 List<Map<String, String>> instanceParams, String productFamilyId) {
794 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfId);
795 GenericVnf genericVnf = new GenericVnf();
796 genericVnf.setVnfId(vnfId);
797 genericVnf.setVnfName(instanceName);
798 genericVnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
799 genericVnf.setVnfType(vnfType);
800 genericVnf.setProvStatus(PREPROV);
801 genericVnf.setServiceId(productFamilyId);
802 if (platform != null) {
803 genericVnf.setPlatform(this.mapperLayer.mapRequestPlatform(platform));
805 if (lineOfBusiness != null) {
806 genericVnf.setLineOfBusiness(this.mapperLayer.mapRequestLineOfBusiness(lineOfBusiness));
808 if (instanceParams != null) {
809 for (Map<String, String> params : instanceParams) {
810 genericVnf.getCloudParams().putAll(params);
816 protected void mapCatalogVnf(GenericVnf genericVnf, ModelInfo modelInfo, Service service) {
817 VnfResourceCustomization vnfResourceCustomization = getVnfResourceCustomizationFromService(modelInfo, service);
818 if (vnfResourceCustomization != null) {
819 genericVnf.setModelInfoGenericVnf(this.mapperLayer.mapCatalogVnfToVnf(vnfResourceCustomization));
823 protected VnfResourceCustomization getVnfResourceCustomizationFromService(ModelInfo modelInfo, Service service) {
824 VnfResourceCustomization vnfResourceCustomization = null;
825 for (VnfResourceCustomization resourceCust : service.getVnfCustomizations()) {
826 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
827 vnfResourceCustomization = resourceCust;
831 return vnfResourceCustomization;
834 protected void populateL3Network(String instanceName, ModelInfo modelInfo, Service service, String bbName,
835 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
836 List<Map<String, String>> instanceParams) {
837 L3Network network = null;
838 for (L3Network networkTemp : serviceInstance.getNetworks()) {
839 if (lookupKeyMap.get(ResourceKey.NETWORK_ID) != null
840 && networkTemp.getNetworkId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.NETWORK_ID))) {
841 network = networkTemp;
845 if (network == null && (bbName.equalsIgnoreCase(AssignFlows.NETWORK_A_LA_CARTE.toString())
846 || bbName.equalsIgnoreCase(AssignFlows.NETWORK_MACRO.toString()))) {
847 network = createNetwork(lookupKeyMap, instanceName, resourceId, instanceParams);
848 serviceInstance.getNetworks().add(network);
850 if (network != null) {
851 mapCatalogNetwork(network, modelInfo, service);
855 protected L3Network createNetwork(Map<ResourceKey, String> lookupKeyMap, String instanceName, String networkId,
856 List<Map<String, String>> instanceParams) {
857 lookupKeyMap.put(ResourceKey.NETWORK_ID, networkId);
858 L3Network network = new L3Network();
859 network.setNetworkId(networkId);
860 network.setNetworkName(instanceName);
861 network.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
862 if (instanceParams != null) {
863 for (Map<String, String> params : instanceParams) {
864 network.getCloudParams().putAll(params);
870 protected void mapCatalogNetwork(L3Network network, ModelInfo modelInfo, Service service) {
871 NetworkResourceCustomization networkResourceCustomization = null;
872 for (NetworkResourceCustomization resourceCust : service.getNetworkCustomizations()) {
873 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
874 networkResourceCustomization = resourceCust;
878 if (networkResourceCustomization != null) {
879 network.setModelInfoNetwork(this.mapperLayer.mapCatalogNetworkToNetwork(networkResourceCustomization));
883 protected GeneralBuildingBlock getGBBALaCarteService(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
884 Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId) throws Exception {
885 Customer customer = getCustomerAndServiceSubscription(requestDetails, resourceId);
886 if (customer != null) {
887 Project project = null;
888 OwningEntity owningEntity = null;
890 if (requestDetails.getProject() != null)
891 project = mapperLayer.mapRequestProject(requestDetails.getProject());
892 if (requestDetails.getOwningEntity() != null)
893 owningEntity = mapperLayer.mapRequestOwningEntity(requestDetails.getOwningEntity());
897 bbInputSetupUtils.getCatalogServiceByModelUUID(requestDetails.getModelInfo().getModelVersionId());
898 if (service == null) {
899 service = bbInputSetupUtils.getCatalogServiceByModelVersionAndModelInvariantUUID(
900 requestDetails.getModelInfo().getModelVersion(),
901 requestDetails.getModelInfo().getModelInvariantId());
902 if (service == null) {
903 throw new Exception("Could not find service for model version Id: "
904 + requestDetails.getModelInfo().getModelVersionId() + " and for model invariant Id: "
905 + requestDetails.getModelInfo().getModelInvariantId());
908 ServiceInstance serviceInstance = this.getALaCarteServiceInstance(service, requestDetails, customer,
909 project, owningEntity, lookupKeyMap, resourceId, Boolean.TRUE.equals(executeBB.isaLaCarte()),
910 executeBB.getBuildingBlock().getBpmnFlowName());
911 return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction,
914 throw new Exception("Could not find customer");
918 protected Customer getCustomerAndServiceSubscription(RequestDetails requestDetails, String resourceId) {
920 if (requestDetails.getSubscriberInfo() != null) {
921 customer = this.getCustomerFromRequest(requestDetails);
923 customer = this.getCustomerFromURI(resourceId);
925 if (customer != null) {
926 ServiceSubscription serviceSubscription = null;
927 serviceSubscription = getServiceSubscription(requestDetails, customer);
928 if (serviceSubscription == null) {
929 serviceSubscription = getServiceSubscriptionFromURI(resourceId, customer);
931 customer.setServiceSubscription(serviceSubscription);
938 protected ServiceSubscription getServiceSubscriptionFromURI(String resourceId, Customer customer) {
939 Map<String, String> uriKeys = bbInputSetupUtils.getURIKeysFromServiceInstance(resourceId);
940 String subscriptionServiceType = uriKeys.get("service-type");
941 org.onap.aai.domain.yang.ServiceSubscription serviceSubscriptionAAI =
942 bbInputSetupUtils.getAAIServiceSubscription(customer.getGlobalCustomerId(), subscriptionServiceType);
943 if (serviceSubscriptionAAI != null) {
944 return mapperLayer.mapAAIServiceSubscription(serviceSubscriptionAAI);
950 protected Customer getCustomerFromURI(String resourceId) {
951 Map<String, String> uriKeys = bbInputSetupUtils.getURIKeysFromServiceInstance(resourceId);
952 String globalCustomerId = uriKeys.get("global-customer-id");
953 org.onap.aai.domain.yang.Customer customerAAI = this.bbInputSetupUtils.getAAICustomer(globalCustomerId);
954 if (customerAAI != null) {
955 return mapperLayer.mapAAICustomer(customerAAI);
961 protected GeneralBuildingBlock populateGBBWithSIAndAdditionalInfo(RequestDetails requestDetails,
962 ServiceInstance serviceInstance, ExecuteBuildingBlock executeBB, String requestAction, Customer customer)
964 GeneralBuildingBlock outputBB = new GeneralBuildingBlock();
965 OrchestrationContext orchContext = mapperLayer.mapOrchestrationContext(requestDetails);
966 RequestContext requestContext = mapperLayer.mapRequestContext(requestDetails);
967 requestContext.setAction(requestAction);
968 requestContext.setMsoRequestId(executeBB.getRequestId());
969 org.onap.aai.domain.yang.CloudRegion aaiCloudRegion =
970 bbInputSetupUtils.getCloudRegion(requestDetails.getCloudConfiguration());
971 CloudRegion cloudRegion = mapperLayer.mapCloudRegion(requestDetails.getCloudConfiguration(), aaiCloudRegion);
972 Tenant tenant = getTenant(requestDetails.getCloudConfiguration(), aaiCloudRegion);
973 outputBB.setOrchContext(orchContext);
974 outputBB.setRequestContext(requestContext);
975 outputBB.setCloudRegion(cloudRegion);
976 outputBB.setTenant(tenant);
977 if (customer == null) {
978 Map<String, String> uriKeys =
979 bbInputSetupUtils.getURIKeysFromServiceInstance(serviceInstance.getServiceInstanceId());
980 String globalCustomerId = uriKeys.get("global-customer-id");
981 String subscriptionServiceType = uriKeys.get("service-type");
982 customer = mapCustomer(globalCustomerId, subscriptionServiceType);
984 outputBB.setServiceInstance(serviceInstance);
985 if (customer.getServiceSubscription() != null) {
986 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
988 outputBB.setCustomer(customer);
992 protected Tenant getTenant(CloudConfiguration cloudConfiguration,
993 org.onap.aai.domain.yang.CloudRegion aaiCloudRegion) throws Exception {
994 Tenant tenant = new Tenant();
995 if (cloudConfiguration != null && cloudConfiguration.getTenantId() != null && aaiCloudRegion != null
996 && aaiCloudRegion.getTenants() != null) {
997 for (org.onap.aai.domain.yang.Tenant aaiTenant : aaiCloudRegion.getTenants().getTenant()) {
998 if (aaiTenant.getTenantId().equalsIgnoreCase(cloudConfiguration.getTenantId())) {
999 tenant = mapperLayer.mapTenant(aaiTenant);
1002 if (tenant.getTenantId() == null || tenant.getTenantName() == null) {
1003 throw new Exception("Invalid tenant information retrieved: tenantId = " + tenant.getTenantId()
1004 + " tenantName = " + tenant.getTenantName());
1010 protected ServiceSubscription getServiceSubscription(RequestDetails requestDetails, Customer customer) {
1011 org.onap.aai.domain.yang.ServiceSubscription aaiServiceSubscription =
1012 bbInputSetupUtils.getAAIServiceSubscription(customer.getGlobalCustomerId(),
1013 requestDetails.getRequestParameters().getSubscriptionServiceType());
1014 if (aaiServiceSubscription != null) {
1015 return mapperLayer.mapAAIServiceSubscription(aaiServiceSubscription);
1021 protected Customer getCustomerFromRequest(RequestDetails requestDetails) {
1022 org.onap.aai.domain.yang.Customer aaiCustomer =
1023 bbInputSetupUtils.getAAICustomer(requestDetails.getSubscriberInfo().getGlobalSubscriberId());
1024 if (aaiCustomer != null) {
1025 return mapperLayer.mapAAICustomer(aaiCustomer);
1031 protected ServiceInstance getALaCarteServiceInstance(Service service, RequestDetails requestDetails,
1032 Customer customer, Project project, OwningEntity owningEntity, Map<ResourceKey, String> lookupKeyMap,
1033 String serviceInstanceId, boolean aLaCarte, String bbName) throws Exception {
1034 ServiceInstance serviceInstance = this.getServiceInstanceHelper(requestDetails, customer, project, owningEntity,
1035 lookupKeyMap, serviceInstanceId, aLaCarte, service, bbName);
1036 org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = null;
1037 if (customer != null && customer.getServiceSubscription() != null) {
1038 serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(customer.getGlobalCustomerId(),
1039 customer.getServiceSubscription().getServiceType(), serviceInstanceId);
1041 serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
1043 if (serviceInstanceAAI != null
1044 && !serviceInstanceAAI.getModelVersionId().equalsIgnoreCase(service.getModelUUID())) {
1045 Service tempService =
1046 this.bbInputSetupUtils.getCatalogServiceByModelUUID(serviceInstanceAAI.getModelVersionId());
1047 if (tempService != null) {
1049 .setModelInfoServiceInstance(mapperLayer.mapCatalogServiceIntoServiceInstance(tempService));
1050 return serviceInstance;
1052 throw new Exception(
1053 "Could not find model of existing SI. Service Instance in AAI already exists with different model version id: "
1054 + serviceInstanceAAI.getModelVersionId());
1057 serviceInstance.setModelInfoServiceInstance(mapperLayer.mapCatalogServiceIntoServiceInstance(service));
1058 return serviceInstance;
1061 protected GeneralBuildingBlock getGBBMacro(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
1062 Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId, String vnfType)
1064 String bbName = executeBB.getBuildingBlock().getBpmnFlowName();
1065 String key = executeBB.getBuildingBlock().getKey();
1067 if (requestAction.equalsIgnoreCase("deleteInstance") || requestAction.equalsIgnoreCase("unassignInstance")
1068 || requestAction.equalsIgnoreCase("activateInstance")
1069 || requestAction.equalsIgnoreCase("activateFabricConfiguration")
1070 || requestAction.equalsIgnoreCase("recreateInstance")
1071 || requestAction.equalsIgnoreCase("replaceInstance")) {
1072 return getGBBMacroExistingService(executeBB, lookupKeyMap, bbName, requestAction,
1073 requestDetails.getCloudConfiguration());
1076 String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
1077 GeneralBuildingBlock gBB =
1078 this.getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, serviceInstanceId);
1079 RequestParameters requestParams = requestDetails.getRequestParameters();
1080 Service service = null;
1081 if (gBB != null && gBB.getServiceInstance() != null
1082 && gBB.getServiceInstance().getModelInfoServiceInstance() != null
1083 && gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid() != null) {
1084 service = bbInputSetupUtils.getCatalogServiceByModelUUID(
1085 gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid());
1087 throw new Exception("Could not get service instance for macro request");
1089 if (requestParams != null && requestParams.getUserParams() != null) {
1090 for (Map<String, Object> userParams : requestParams.getUserParams()) {
1091 if (userParams.containsKey("service")) {
1092 String input = mapper.writeValueAsString(userParams.get("service"));
1093 return getGBBMacroUserParams(executeBB, requestDetails, lookupKeyMap, vnfType, bbName, key, gBB,
1094 requestParams, service, input);
1098 if (requestAction.equalsIgnoreCase("deactivateInstance")) {
1100 } else if (requestAction.equalsIgnoreCase("createInstance")) {
1101 return getGBBMacroNoUserParamsCreate(executeBB, lookupKeyMap, bbName, key, gBB, service);
1103 throw new IllegalArgumentException(
1104 "No user params on requestAction: assignInstance. Please specify user params.");
1108 protected GeneralBuildingBlock getGBBMacroNoUserParamsCreate(ExecuteBuildingBlock executeBB,
1109 Map<ResourceKey, String> lookupKeyMap, String bbName, String key, GeneralBuildingBlock gBB, Service service)
1111 ServiceInstance serviceInstance = gBB.getServiceInstance();
1112 if (bbName.contains(NETWORK) && !bbName.contains(NETWORK_COLLECTION)) {
1113 String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
1114 ModelInfo networkModelInfo = new ModelInfo();
1115 if ((!Boolean.TRUE.equals(executeBB.getBuildingBlock().getIsVirtualLink()))) {
1116 NetworkResourceCustomization networkCust = getNetworkCustomizationByKey(key, service);
1117 if (networkCust != null) {
1118 networkModelInfo.setModelCustomizationUuid(networkCust.getModelCustomizationUUID());
1119 this.populateL3Network(null, networkModelInfo, service, bbName, serviceInstance, lookupKeyMap,
1122 logger.debug("Could not find a network customization with key: {}", key);
1125 logger.debug("Orchestrating on Collection Network Resource Customization");
1126 CollectionNetworkResourceCustomization collectionNetworkResourceCust =
1127 bbInputSetupUtils.getCatalogCollectionNetworkResourceCustByID(key);
1128 L3Network l3Network = getVirtualLinkL3Network(lookupKeyMap, bbName, key, networkId,
1129 collectionNetworkResourceCust, serviceInstance);
1130 NetworkResourceCustomization networkResourceCustomization = mapperLayer
1131 .mapCollectionNetworkResourceCustToNetworkResourceCust(collectionNetworkResourceCust);
1132 if (l3Network != null) {
1133 l3Network.setModelInfoNetwork(mapperLayer.mapCatalogNetworkToNetwork(networkResourceCustomization));
1136 } else if (bbName.contains("Configuration")) {
1137 String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
1138 ModelInfo configurationModelInfo = new ModelInfo();
1139 configurationModelInfo.setModelCustomizationUuid(key);
1140 this.populateConfiguration(configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap,
1141 configurationId, null, executeBB.getConfigurationResourceKeys(), executeBB.getRequestDetails());
1143 if (executeBB.getWorkflowResourceIds() != null) {
1144 this.populateNetworkCollectionAndInstanceGroupAssign(service, bbName, serviceInstance,
1145 executeBB.getWorkflowResourceIds().getNetworkCollectionId(), key);
1147 RelatedInstance relatedVpnBinding =
1148 bbInputSetupUtils.getRelatedInstanceByType(executeBB.getRequestDetails(), ModelType.vpnBinding);
1149 RelatedInstance relatedLocalNetwork =
1150 bbInputSetupUtils.getRelatedInstanceByType(executeBB.getRequestDetails(), ModelType.network);
1151 if (relatedVpnBinding != null && relatedLocalNetwork != null) {
1152 org.onap.aai.domain.yang.VpnBinding aaiVpnBinding =
1153 bbInputSetupUtils.getAAIVpnBinding(relatedVpnBinding.getInstanceId());
1154 org.onap.aai.domain.yang.L3Network aaiLocalNetwork =
1155 bbInputSetupUtils.getAAIL3Network(relatedLocalNetwork.getInstanceId());
1156 VpnBinding vpnBinding = mapperLayer.mapAAIVpnBinding(aaiVpnBinding);
1157 L3Network localNetwork = mapperLayer.mapAAIL3Network(aaiLocalNetwork);
1158 Optional<org.onap.aai.domain.yang.VpnBinding> aaiAICVpnBindingOp =
1159 bbInputSetupUtils.getAICVpnBindingFromNetwork(aaiLocalNetwork);
1160 if (aaiAICVpnBindingOp.isPresent()) {
1161 localNetwork.getVpnBindings().add(mapperLayer.mapAAIVpnBinding(aaiAICVpnBindingOp.get()));
1163 ServiceProxy serviceProxy = getServiceProxy(service);
1164 gBB.getServiceInstance().getServiceProxies().add(serviceProxy);
1165 gBB.getCustomer().getVpnBindings().add(vpnBinding);
1166 lookupKeyMap.put(ResourceKey.VPN_ID, vpnBinding.getVpnId());
1167 gBB.getServiceInstance().getNetworks().add(localNetwork);
1168 lookupKeyMap.put(ResourceKey.NETWORK_ID, localNetwork.getNetworkId());
1173 protected ServiceProxy getServiceProxy(Service service) {
1174 if (!service.getServiceProxyCustomizations().isEmpty()) {
1175 ServiceProxyResourceCustomization serviceProxyCatalog = getServiceProxyResourceCustomization(service);
1176 ServiceProxy serviceProxy = new ServiceProxy();
1177 serviceProxy.setModelInfoServiceProxy(
1178 mapperLayer.mapServiceProxyCustomizationToServiceProxy(serviceProxyCatalog));
1179 Service sourceService = serviceProxyCatalog.getSourceService();
1180 ServiceInstance sourceServiceShell = new ServiceInstance();
1182 .setModelInfoServiceInstance(mapperLayer.mapCatalogServiceIntoServiceInstance(sourceService));
1183 serviceProxy.setServiceInstance(sourceServiceShell);
1184 serviceProxy.setType(sourceService.getServiceType());
1185 return serviceProxy;
1191 protected ServiceProxyResourceCustomization getServiceProxyResourceCustomization(Service service) {
1192 ServiceProxyResourceCustomization serviceProxyCatalog = null;
1193 for (ServiceProxyResourceCustomization serviceProxyTemp : service.getServiceProxyCustomizations()) {
1194 if (serviceProxyTemp.getSourceService() != null
1195 && serviceProxyTemp.getSourceService().getServiceType().equalsIgnoreCase("TRANSPORT")) {
1196 serviceProxyCatalog = serviceProxyTemp;
1199 return serviceProxyCatalog;
1202 protected L3Network getVirtualLinkL3Network(Map<ResourceKey, String> lookupKeyMap, String bbName, String key,
1203 String networkId, CollectionNetworkResourceCustomization collectionNetworkResourceCust,
1204 ServiceInstance serviceInstance) {
1205 if (collectionNetworkResourceCust != null) {
1206 if ((bbName.equalsIgnoreCase(AssignFlows.NETWORK_A_LA_CARTE.toString())
1207 || bbName.equalsIgnoreCase(AssignFlows.NETWORK_MACRO.toString()))) {
1208 L3Network network = createNetwork(lookupKeyMap, null, networkId, null);
1209 serviceInstance.getNetworks().add(network);
1212 for (L3Network network : serviceInstance.getNetworks()) {
1213 if (network.getNetworkId().equalsIgnoreCase(networkId)) {
1222 protected NetworkResourceCustomization getNetworkCustomizationByKey(String key, Service service) {
1223 for (NetworkResourceCustomization networkCust : service.getNetworkCustomizations()) {
1224 if (networkCust.getModelCustomizationUUID().equalsIgnoreCase(key)) {
1231 protected GeneralBuildingBlock getGBBMacroExistingService(ExecuteBuildingBlock executeBB,
1232 Map<ResourceKey, String> lookupKeyMap, String bbName, String requestAction,
1233 CloudConfiguration cloudConfiguration) throws Exception {
1234 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
1235 String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
1236 RequestDetails requestDetails = executeBB.getRequestDetails();
1237 GeneralBuildingBlock gBB = null;
1238 if (serviceInstanceId != null) {
1239 aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
1241 Service service = null;
1242 if (aaiServiceInstance != null) {
1243 service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
1245 if (aaiServiceInstance != null && service != null) {
1246 ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
1247 serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
1248 gBB = populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null);
1250 logger.debug("Related Service Instance from AAI: {}", aaiServiceInstance);
1251 logger.debug("Related Service Instance Model Info from AAI: {}", service);
1252 throw new Exception("Could not find relevant information for related Service Instance");
1254 ServiceInstance serviceInstance = gBB.getServiceInstance();
1255 CloudRegion cloudRegion = null;
1256 if (cloudConfiguration == null) {
1257 Optional<CloudRegion> cloudRegionOp = cloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance);
1258 if (cloudRegionOp.isPresent()) {
1259 cloudRegion = cloudRegionOp.get();
1262 if (cloudConfiguration != null) {
1263 org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration);
1264 cloudRegion = mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion);
1266 gBB.setCloudRegion(cloudRegion);
1267 if (bbName.contains(VNF)) {
1268 for (GenericVnf genericVnf : serviceInstance.getVnfs()) {
1269 if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null
1270 && genericVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
1271 org.onap.aai.domain.yang.GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(genericVnf.getVnfId());
1272 ModelInfo modelInfo = new ModelInfo();
1274 modelInfo.setModelCustomizationUuid(vnf.getModelCustomizationId());
1276 this.mapCatalogVnf(genericVnf, modelInfo, service);
1279 } else if (bbName.contains(VF_MODULE)) {
1280 for (GenericVnf vnf : serviceInstance.getVnfs()) {
1281 for (VfModule vfModule : vnf.getVfModules()) {
1282 if (lookupKeyMap.get(ResourceKey.VF_MODULE_ID) != null
1283 && vfModule.getVfModuleId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VF_MODULE_ID))) {
1284 String vnfModelCustomizationUUID =
1285 this.bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()).getModelCustomizationId();
1286 ModelInfo vnfModelInfo = new ModelInfo();
1287 vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
1288 this.mapCatalogVnf(vnf, vnfModelInfo, service);
1289 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnf.getVnfId());
1290 String vfModuleCustomizationUUID = this.bbInputSetupUtils
1291 .getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()).getModelCustomizationId();
1292 ModelInfo vfModuleModelInfo = new ModelInfo();
1293 vfModuleModelInfo.setModelCustomizationId(vfModuleCustomizationUUID);
1294 this.mapCatalogVfModule(vfModule, vfModuleModelInfo, service, vnfModelCustomizationUUID);
1295 if (cloudRegion != null) {
1296 Optional<String> volumeGroupIdOp = getVolumeGroupIdRelatedToVfModule(vnf, vfModuleModelInfo,
1297 cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), lookupKeyMap);
1298 if (volumeGroupIdOp.isPresent()) {
1299 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupIdOp.get());
1306 } else if (bbName.contains(VOLUME_GROUP)) {
1307 for (GenericVnf vnf : serviceInstance.getVnfs()) {
1308 for (VolumeGroup volumeGroup : vnf.getVolumeGroups()) {
1309 if (lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID) != null && volumeGroup.getVolumeGroupId()
1310 .equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID))) {
1311 String vnfModelCustomizationUUID =
1312 this.bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()).getModelCustomizationId();
1313 ModelInfo vnfModelInfo = new ModelInfo();
1314 vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
1315 this.mapCatalogVnf(vnf, vnfModelInfo, service);
1316 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnf.getVnfId());
1317 if (cloudRegion != null) {
1318 String volumeGroupCustomizationUUID =
1319 this.bbInputSetupUtils
1320 .getAAIVolumeGroup(cloudRegion.getCloudOwner(),
1321 cloudRegion.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId())
1322 .getModelCustomizationId();
1323 ModelInfo volumeGroupModelInfo = new ModelInfo();
1324 volumeGroupModelInfo.setModelCustomizationId(volumeGroupCustomizationUUID);
1325 this.mapCatalogVolumeGroup(volumeGroup, volumeGroupModelInfo, service,
1326 vnfModelCustomizationUUID);
1332 } else if (bbName.contains(NETWORK)) {
1333 for (L3Network network : serviceInstance.getNetworks()) {
1334 if (lookupKeyMap.get(ResourceKey.NETWORK_ID) != null
1335 && network.getNetworkId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.NETWORK_ID))) {
1336 String networkCustomizationUUID =
1337 this.bbInputSetupUtils.getAAIL3Network(network.getNetworkId()).getModelCustomizationId();
1338 ModelInfo modelInfo = new ModelInfo();
1339 modelInfo.setModelCustomizationUuid(networkCustomizationUUID);
1340 this.mapCatalogNetwork(network, modelInfo, service);
1344 } else if (bbName.contains("Fabric")) {
1345 for (Configuration configuration : serviceInstance.getConfigurations()) {
1346 if (lookupKeyMap.get(ResourceKey.CONFIGURATION_ID) != null && configuration.getConfigurationId()
1347 .equalsIgnoreCase(lookupKeyMap.get(ResourceKey.CONFIGURATION_ID))) {
1348 String configurationCustUUID = this.bbInputSetupUtils
1349 .getAAIConfiguration(configuration.getConfigurationId()).getModelCustomizationId();
1350 ModelInfo modelInfo = new ModelInfo();
1351 modelInfo.setModelCustomizationUuid(configurationCustUUID);
1352 this.mapCatalogConfiguration(configuration, modelInfo, service,
1353 executeBB.getConfigurationResourceKeys());
1358 if (executeBB.getWorkflowResourceIds() != null) {
1359 this.populateNetworkCollectionAndInstanceGroupAssign(service, bbName, serviceInstance,
1360 executeBB.getWorkflowResourceIds().getNetworkCollectionId(), executeBB.getBuildingBlock().getKey());
1365 protected GeneralBuildingBlock getGBBMacroUserParams(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
1366 Map<ResourceKey, String> lookupKeyMap, String vnfType, String bbName, String key, GeneralBuildingBlock gBB,
1367 RequestParameters requestParams, Service service, String input) throws Exception {
1368 ServiceInstance serviceInstance = gBB.getServiceInstance();
1369 org.onap.so.serviceinstancebeans.Service serviceMacro =
1370 mapper.readValue(input, org.onap.so.serviceinstancebeans.Service.class);
1372 Resources resources = serviceMacro.getResources();
1374 VfModules vfModules = null;
1375 Networks networks = null;
1376 CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
1377 CloudRegion cloudRegion = getCloudRegionFromMacroRequest(cloudConfiguration, resources);
1378 gBB.setCloudRegion(cloudRegion);
1379 if (bbName.contains(VNF)) {
1380 vnfs = findVnfsByKey(key, resources, vnfs);
1381 String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
1382 // This stores the vnf id in request db to be retrieved later when
1383 // working on a vf module or volume group
1384 InfraActiveRequests request = this.bbInputSetupUtils.getInfraActiveRequest(executeBB.getRequestId());
1385 if (request != null) {
1386 this.bbInputSetupUtils.updateInfraActiveRequestVnfId(request, vnfId);
1388 String productFamilyId = requestDetails.getRequestInfo().getProductFamilyId();
1389 this.populateGenericVnf(vnfs.getModelInfo(), vnfs.getInstanceName(), vnfs.getPlatform(),
1390 vnfs.getLineOfBusiness(), service, bbName, serviceInstance, lookupKeyMap, null, vnfId, vnfType,
1391 vnfs.getInstanceParams(), productFamilyId);
1392 } else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP)) {
1393 Pair<Vnfs, VfModules> vnfsAndVfModules = getVfModulesAndItsVnfsByKey(key, resources);
1394 if (vnfsAndVfModules != null) {
1395 vfModules = vnfsAndVfModules.getValue1();
1396 vnfs = vnfsAndVfModules.getValue0();
1398 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, getVnfId(executeBB, lookupKeyMap));
1400 throw new Exception("Could not find Vnf to orchestrate VfModule");
1402 ModelInfo modelInfo = vfModules.getModelInfo();
1403 if (bbName.contains(VOLUME_GROUP)) {
1404 String volumeGroupId = lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID);
1405 this.populateVolumeGroup(modelInfo, service, bbName, serviceInstance, lookupKeyMap, volumeGroupId, null,
1406 vfModules.getVolumeGroupInstanceName(), vnfType, vfModules.getInstanceParams());
1408 String vfModuleId = lookupKeyMap.get(ResourceKey.VF_MODULE_ID);
1409 CloudConfiguration cloudConfig = new CloudConfiguration();
1410 cloudConfig.setLcpCloudRegionId(cloudRegion.getLcpCloudRegionId());
1411 cloudConfig.setCloudOwner(cloudRegion.getCloudOwner());
1412 this.populateVfModule(modelInfo, service, bbName, serviceInstance, lookupKeyMap, vfModuleId, null,
1413 vfModules.getInstanceName(), vfModules.getInstanceParams(), cloudConfig);
1415 } else if (bbName.contains(NETWORK)) {
1416 networks = findNetworksByKey(key, resources);
1417 String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
1418 if (networks != null) {
1419 this.populateL3Network(networks.getInstanceName(), networks.getModelInfo(), service, bbName,
1420 serviceInstance, lookupKeyMap, networkId, networks.getInstanceParams());
1422 } else if (bbName.contains("Configuration")) {
1423 String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
1424 ModelInfo configurationModelInfo = new ModelInfo();
1425 configurationModelInfo.setModelCustomizationUuid(key);
1426 ConfigurationResourceCustomization configurationCust =
1427 findConfigurationResourceCustomization(configurationModelInfo, service);
1428 if (configurationCust != null) {
1429 this.populateConfiguration(configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap,
1430 configurationId, null, executeBB.getConfigurationResourceKeys(), executeBB.getRequestDetails());
1432 logger.debug("Could not find a configuration customization with key: {}", key);
1438 protected Networks findNetworksByKey(String key, Resources resources) {
1439 for (Networks networks : resources.getNetworks()) {
1440 if (networks.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) {
1447 protected Pair<Vnfs, VfModules> getVfModulesAndItsVnfsByKey(String key, Resources resources) {
1448 for (Vnfs vnfs : resources.getVnfs()) {
1449 for (VfModules vfModules : vnfs.getVfModules()) {
1450 if (vfModules.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) {
1451 return new Pair<Vnfs, VfModules>(vnfs, vfModules);
1458 protected Vnfs findVnfsByKey(String key, Resources resources, Vnfs vnfs) {
1459 for (Vnfs tempVnfs : resources.getVnfs()) {
1460 if (tempVnfs.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) {
1468 protected CloudRegion getCloudRegionFromMacroRequest(CloudConfiguration cloudConfiguration, Resources resources) {
1469 if (cloudConfiguration == null) {
1470 for (Vnfs vnfs : resources.getVnfs()) {
1471 if (cloudConfiguration == null) {
1472 cloudConfiguration = vnfs.getCloudConfiguration();
1476 for (VfModules vfModules : vnfs.getVfModules()) {
1477 if (cloudConfiguration == null) {
1478 cloudConfiguration = vfModules.getCloudConfiguration();
1484 for (Networks networks : resources.getNetworks()) {
1485 if (cloudConfiguration == null) {
1486 cloudConfiguration = networks.getCloudConfiguration();
1492 if (cloudConfiguration != null) {
1493 org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration);
1494 return mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion);
1496 logger.debug("Could not find any cloud configuration for this request.");
1501 protected String getVnfId(ExecuteBuildingBlock executeBB, Map<ResourceKey, String> lookupKeyMap) {
1502 String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
1503 if (vnfId == null) {
1504 InfraActiveRequests request = this.bbInputSetupUtils.getInfraActiveRequest(executeBB.getRequestId());
1505 vnfId = request.getVnfId();
1511 protected String generateRandomUUID() {
1512 return UUID.randomUUID().toString();
1515 protected ServiceInstance getServiceInstanceHelper(RequestDetails requestDetails, Customer customer,
1516 Project project, OwningEntity owningEntity, Map<ResourceKey, String> lookupKeyMap, String serviceInstanceId,
1517 boolean aLaCarte, Service service, String bbName) throws Exception {
1518 if (requestDetails.getRequestInfo().getInstanceName() == null && aLaCarte
1519 && bbName.equalsIgnoreCase(AssignFlows.SERVICE_INSTANCE.toString())) {
1520 throw new Exception("Request invalid missing: RequestInfo:InstanceName");
1522 org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = null;
1523 if (aLaCarte && bbName.equalsIgnoreCase(AssignFlows.SERVICE_INSTANCE.toString())) {
1524 serviceInstanceAAI = bbInputSetupUtils
1525 .getAAIServiceInstanceByName(requestDetails.getRequestInfo().getInstanceName(), customer);
1527 if (serviceInstanceId != null && serviceInstanceAAI == null) {
1528 if (customer != null && customer.getServiceSubscription() != null) {
1529 serviceInstanceAAI =
1530 bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(customer.getGlobalCustomerId(),
1531 customer.getServiceSubscription().getServiceType(), serviceInstanceId);
1533 serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
1536 if (serviceInstanceAAI != null) {
1537 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstanceId);
1538 return this.getExistingServiceInstance(serviceInstanceAAI);
1540 return createServiceInstance(requestDetails, project, owningEntity, lookupKeyMap, serviceInstanceId);
1545 protected ServiceInstance createServiceInstance(RequestDetails requestDetails, Project project,
1546 OwningEntity owningEntity, Map<ResourceKey, String> lookupKeyMap, String serviceInstanceId) {
1547 ServiceInstance serviceInstance = new ServiceInstance();
1548 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstanceId);
1549 serviceInstance.setServiceInstanceId(serviceInstanceId);
1550 if (requestDetails.getRequestInfo() != null) {
1551 serviceInstance.setServiceInstanceName(requestDetails.getRequestInfo().getInstanceName());
1553 serviceInstance.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
1554 serviceInstance.setProject(project);
1555 serviceInstance.setOwningEntity(owningEntity);
1556 return serviceInstance;
1560 * This method is used for getting the existing service instance.
1562 * This will map the serviceInstanceAAI to serviceInstance and return the serviceInstance.
1565 * @return serviceInstance
1567 public ServiceInstance getExistingServiceInstance(org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI)
1569 ServiceInstance serviceInstance = mapperLayer.mapAAIServiceInstanceIntoServiceInstance(serviceInstanceAAI);
1570 if (serviceInstanceAAI.getRelationshipList() != null
1571 && serviceInstanceAAI.getRelationshipList().getRelationship() != null
1572 && !serviceInstanceAAI.getRelationshipList().getRelationship().isEmpty()) {
1573 addRelationshipsToSI(serviceInstanceAAI, serviceInstance);
1575 return serviceInstance;
1578 protected void populateNetworkCollectionAndInstanceGroupAssign(Service service, String bbName,
1579 ServiceInstance serviceInstance, String resourceId, String key) throws Exception {
1580 if (serviceInstance.getCollection() == null
1581 && bbName.equalsIgnoreCase(AssignFlows.NETWORK_COLLECTION.toString())) {
1582 Collection collection = this.createCollection(resourceId);
1583 serviceInstance.setCollection(collection);
1584 this.mapCatalogCollection(service, serviceInstance.getCollection(), key);
1585 if (isVlanTagging(service, key)) {
1586 InstanceGroup instanceGroup = this.createInstanceGroup();
1587 serviceInstance.getCollection().setInstanceGroup(instanceGroup);
1588 this.mapCatalogNetworkCollectionInstanceGroup(service,
1589 serviceInstance.getCollection().getInstanceGroup(), key);
1594 protected CollectionResourceCustomization findCatalogNetworkCollection(Service service, String key) {
1595 for (CollectionResourceCustomization collectionCust : service.getCollectionResourceCustomizations()) {
1596 if (collectionCust.getModelCustomizationUUID().equalsIgnoreCase(key)) {
1597 return collectionCust;
1603 protected boolean isVlanTagging(Service service, String key) {
1604 CollectionResourceCustomization collectionCust = findCatalogNetworkCollection(service, key);
1605 if (collectionCust != null) {
1606 CollectionResource collectionResource = collectionCust.getCollectionResource();
1607 if (collectionResource != null && collectionResource.getInstanceGroup() != null
1608 && collectionResource.getInstanceGroup().getToscaNodeType() != null
1609 && collectionResource.getInstanceGroup().getToscaNodeType().contains("NetworkCollection")) {
1616 protected void mapCatalogNetworkCollectionInstanceGroup(Service service, InstanceGroup instanceGroup, String key) {
1617 CollectionResourceCustomization collectionCust = this.findCatalogNetworkCollection(service, key);
1618 org.onap.so.db.catalog.beans.InstanceGroup catalogInstanceGroup = null;
1619 if (collectionCust != null) {
1620 catalogInstanceGroup = collectionCust.getCollectionResource().getInstanceGroup();
1622 instanceGroup.setModelInfoInstanceGroup(
1623 mapperLayer.mapCatalogInstanceGroupToInstanceGroup(collectionCust, catalogInstanceGroup));
1626 protected void mapCatalogCollection(Service service, Collection collection, String key) {
1627 CollectionResourceCustomization collectionCust = findCatalogNetworkCollection(service, key);
1628 if (collectionCust != null) {
1629 CollectionResource collectionResource = collectionCust.getCollectionResource();
1630 if (collectionResource != null) {
1631 collection.setModelInfoCollection(
1632 mapperLayer.mapCatalogCollectionToCollection(collectionCust, collectionResource));
1637 protected Collection createCollection(String collectionId) {
1638 Collection collection = new Collection();
1639 collection.setId(collectionId);
1640 collection.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
1644 protected InstanceGroup createInstanceGroup() {
1645 InstanceGroup instanceGroup = new InstanceGroup();
1646 String instanceGroupId = this.generateRandomUUID();
1647 instanceGroup.setId(instanceGroupId);
1648 return instanceGroup;
1651 protected void addRelationshipsToSI(org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI,
1652 ServiceInstance serviceInstance) throws Exception {
1653 AAIResultWrapper serviceInstanceWrapper = new AAIResultWrapper(
1654 new AAICommonObjectMapperProvider().getMapper().writeValueAsString(serviceInstanceAAI));
1655 Optional<Relationships> relationshipsOp = serviceInstanceWrapper.getRelationships();
1656 Relationships relationships = null;
1657 if (relationshipsOp.isPresent()) {
1658 relationships = relationshipsOp.get();
1663 this.mapProject(relationships.getByType(AAIObjectType.PROJECT), serviceInstance);
1664 this.mapOwningEntity(relationships.getByType(AAIObjectType.OWNING_ENTITY), serviceInstance);
1665 this.mapL3Networks(relationships.getRelatedAAIUris(AAIObjectType.L3_NETWORK), serviceInstance.getNetworks());
1666 this.mapGenericVnfs(relationships.getRelatedAAIUris(AAIObjectType.GENERIC_VNF), serviceInstance.getVnfs());
1667 this.mapCollection(relationships.getByType(AAIObjectType.COLLECTION), serviceInstance);
1668 this.mapConfigurations(relationships.getRelatedAAIUris(AAIObjectType.CONFIGURATION),
1669 serviceInstance.getConfigurations());
1672 protected void mapConfigurations(List<AAIResourceUri> relatedAAIUris, List<Configuration> configurations) {
1673 for (AAIResourceUri aaiResourceUri : relatedAAIUris) {
1674 configurations.add(mapConfiguration(aaiResourceUri));
1678 protected Configuration mapConfiguration(AAIResourceUri aaiResourceUri) {
1679 AAIResultWrapper aaiConfigurationWrapper = this.bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri);
1680 Optional<org.onap.aai.domain.yang.Configuration> aaiConfigurationOp =
1681 aaiConfigurationWrapper.asBean(org.onap.aai.domain.yang.Configuration.class);
1682 if (!aaiConfigurationOp.isPresent()) {
1686 return this.mapperLayer.mapAAIConfiguration(aaiConfigurationOp.get());
1689 protected void mapGenericVnfs(List<AAIResourceUri> list, List<GenericVnf> genericVnfs) {
1690 for (AAIResourceUri aaiResourceUri : list) {
1691 genericVnfs.add(this.mapGenericVnf(aaiResourceUri));
1695 protected GenericVnf mapGenericVnf(AAIResourceUri aaiResourceUri) {
1696 AAIResultWrapper aaiGenericVnfWrapper = this.bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri);
1697 Optional<org.onap.aai.domain.yang.GenericVnf> aaiGenericVnfOp =
1698 aaiGenericVnfWrapper.asBean(org.onap.aai.domain.yang.GenericVnf.class);
1699 if (!aaiGenericVnfOp.isPresent()) {
1703 GenericVnf genericVnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiGenericVnfOp.get());
1705 Optional<Relationships> relationshipsOp = aaiGenericVnfWrapper.getRelationships();
1706 if (relationshipsOp.isPresent()) {
1707 Relationships relationships = relationshipsOp.get();
1708 this.mapPlatform(relationships.getByType(AAIObjectType.PLATFORM), genericVnf);
1709 this.mapLineOfBusiness(relationships.getByType(AAIObjectType.LINE_OF_BUSINESS), genericVnf);
1710 genericVnf.getVolumeGroups().addAll(mapVolumeGroups(relationships.getByType(AAIObjectType.VOLUME_GROUP)));
1711 genericVnf.getInstanceGroups()
1712 .addAll(mapInstanceGroups(relationships.getByType(AAIObjectType.INSTANCE_GROUP)));
1718 protected List<InstanceGroup> mapInstanceGroups(List<AAIResultWrapper> instanceGroups) {
1719 List<InstanceGroup> instanceGroupsList = new ArrayList<>();
1720 for (AAIResultWrapper volumeGroupWrapper : instanceGroups) {
1721 instanceGroupsList.add(this.mapInstanceGroup(volumeGroupWrapper));
1723 return instanceGroupsList;
1726 protected InstanceGroup mapInstanceGroup(AAIResultWrapper instanceGroupWrapper) {
1727 Optional<org.onap.aai.domain.yang.InstanceGroup> aaiInstanceGroupOp =
1728 instanceGroupWrapper.asBean(org.onap.aai.domain.yang.InstanceGroup.class);
1729 org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup = null;
1731 if (!aaiInstanceGroupOp.isPresent()) {
1735 aaiInstanceGroup = aaiInstanceGroupOp.get();
1736 InstanceGroup instanceGroup = this.mapperLayer.mapAAIInstanceGroupIntoInstanceGroup(aaiInstanceGroup);
1737 instanceGroup.setModelInfoInstanceGroup(this.mapperLayer.mapCatalogInstanceGroupToInstanceGroup(null,
1738 this.bbInputSetupUtils.getCatalogInstanceGroup(aaiInstanceGroup.getModelVersionId())));
1739 return instanceGroup;
1742 protected List<VolumeGroup> mapVolumeGroups(List<AAIResultWrapper> volumeGroups) {
1743 List<VolumeGroup> volumeGroupsList = new ArrayList<>();
1744 for (AAIResultWrapper volumeGroupWrapper : volumeGroups) {
1745 volumeGroupsList.add(this.mapVolumeGroup(volumeGroupWrapper));
1747 return volumeGroupsList;
1750 protected VolumeGroup mapVolumeGroup(AAIResultWrapper volumeGroupWrapper) {
1751 Optional<org.onap.aai.domain.yang.VolumeGroup> aaiVolumeGroupOp =
1752 volumeGroupWrapper.asBean(org.onap.aai.domain.yang.VolumeGroup.class);
1753 org.onap.aai.domain.yang.VolumeGroup aaiVolumeGroup = null;
1755 if (!aaiVolumeGroupOp.isPresent()) {
1759 aaiVolumeGroup = aaiVolumeGroupOp.get();
1760 return this.mapperLayer.mapAAIVolumeGroup(aaiVolumeGroup);
1763 protected void mapLineOfBusiness(List<AAIResultWrapper> lineOfBusinesses, GenericVnf genericVnf) {
1764 if (!lineOfBusinesses.isEmpty()) {
1765 AAIResultWrapper lineOfBusinessWrapper = lineOfBusinesses.get(0);
1766 Optional<org.onap.aai.domain.yang.LineOfBusiness> aaiLineOfBusinessOp =
1767 lineOfBusinessWrapper.asBean(org.onap.aai.domain.yang.LineOfBusiness.class);
1768 org.onap.aai.domain.yang.LineOfBusiness aaiLineOfBusiness = null;
1769 if (!aaiLineOfBusinessOp.isPresent()) {
1772 aaiLineOfBusiness = aaiLineOfBusinessOp.get();
1774 LineOfBusiness lineOfBusiness = this.mapperLayer.mapAAILineOfBusiness(aaiLineOfBusiness);
1775 genericVnf.setLineOfBusiness(lineOfBusiness);
1779 protected void mapPlatform(List<AAIResultWrapper> platforms, GenericVnf genericVnf) {
1780 if (!platforms.isEmpty()) {
1781 AAIResultWrapper platformWrapper = platforms.get(0);
1782 Optional<org.onap.aai.domain.yang.Platform> aaiPlatformOp =
1783 platformWrapper.asBean(org.onap.aai.domain.yang.Platform.class);
1784 org.onap.aai.domain.yang.Platform aaiPlatform = null;
1785 if (!aaiPlatformOp.isPresent()) {
1788 aaiPlatform = aaiPlatformOp.get();
1790 Platform platform = this.mapperLayer.mapAAIPlatform(aaiPlatform);
1791 genericVnf.setPlatform(platform);
1795 protected void mapCollection(List<AAIResultWrapper> collections, ServiceInstance serviceInstance) {
1796 if (!collections.isEmpty()) {
1797 AAIResultWrapper collectionWrapper = collections.get(0);
1798 Optional<org.onap.aai.domain.yang.Collection> aaiCollectionOp =
1799 collectionWrapper.asBean(org.onap.aai.domain.yang.Collection.class);
1800 org.onap.aai.domain.yang.Collection aaiCollection = null;
1801 if (!aaiCollectionOp.isPresent()) {
1804 aaiCollection = aaiCollectionOp.get();
1806 Collection collection = this.mapperLayer.mapAAICollectionIntoCollection(aaiCollection);
1807 NetworkCollectionResourceCustomization collectionResourceCust = bbInputSetupUtils
1808 .getCatalogNetworkCollectionResourceCustByID(aaiCollection.getCollectionCustomizationId());
1809 collection.setModelInfoCollection(mapperLayer.mapCatalogCollectionToCollection(collectionResourceCust,
1810 collectionResourceCust.getCollectionResource()));
1811 Optional<Relationships> relationshipsOp = collectionWrapper.getRelationships();
1812 Relationships relationships = null;
1813 if (relationshipsOp.isPresent()) {
1814 relationships = relationshipsOp.get();
1816 serviceInstance.setCollection(collection);
1819 List<InstanceGroup> instanceGroupsList =
1820 mapInstanceGroups(relationships.getByType(AAIObjectType.INSTANCE_GROUP));
1821 if (!instanceGroupsList.isEmpty()) {
1822 collection.setInstanceGroup(instanceGroupsList.get(0));
1824 serviceInstance.setCollection(collection);
1828 protected void mapL3Networks(List<AAIResourceUri> list, List<L3Network> l3Networks) {
1829 for (AAIResourceUri aaiResourceUri : list) {
1830 l3Networks.add(this.mapL3Network(aaiResourceUri));
1834 protected L3Network mapL3Network(AAIResourceUri aaiResourceUri) {
1835 AAIResultWrapper aaiNetworkWrapper = this.bbInputSetupUtils.getAAIResourceDepthTwo(aaiResourceUri);
1836 Optional<org.onap.aai.domain.yang.L3Network> aaiL3NetworkOp =
1837 aaiNetworkWrapper.asBean(org.onap.aai.domain.yang.L3Network.class);
1838 org.onap.aai.domain.yang.L3Network aaiL3Network = null;
1840 if (!aaiL3NetworkOp.isPresent()) {
1844 aaiL3Network = aaiL3NetworkOp.get();
1845 L3Network network = this.mapperLayer.mapAAIL3Network(aaiL3Network);
1847 Optional<Relationships> relationshipsOp = aaiNetworkWrapper.getRelationships();
1848 if (relationshipsOp.isPresent()) {
1849 Relationships relationships = relationshipsOp.get();
1850 this.mapNetworkPolicies(relationships.getByType(AAIObjectType.NETWORK_POLICY),
1851 network.getNetworkPolicies());
1852 mapRouteTableReferences(relationships.getByType(AAIObjectType.ROUTE_TABLE_REFERENCE),
1853 network.getContrailNetworkRouteTableReferences());
1859 protected void mapNetworkPolicies(List<AAIResultWrapper> aaiNetworkPolicies, List<NetworkPolicy> networkPolicies) {
1860 for (AAIResultWrapper networkPolicyWrapper : aaiNetworkPolicies) {
1861 networkPolicies.add(this.mapNetworkPolicy(networkPolicyWrapper));
1865 protected NetworkPolicy mapNetworkPolicy(AAIResultWrapper networkPolicyWrapper) {
1866 Optional<org.onap.aai.domain.yang.NetworkPolicy> aaiNetworkPolicyOp =
1867 networkPolicyWrapper.asBean(org.onap.aai.domain.yang.NetworkPolicy.class);
1868 org.onap.aai.domain.yang.NetworkPolicy aaiNetworkPolicy = null;
1870 if (!aaiNetworkPolicyOp.isPresent()) {
1874 aaiNetworkPolicy = aaiNetworkPolicyOp.get();
1875 return this.mapperLayer.mapAAINetworkPolicy(aaiNetworkPolicy);
1878 protected void mapRouteTableReferences(List<AAIResultWrapper> routeTableReferences,
1879 List<RouteTableReference> contrailNetworkRouteTableReferences) {
1880 for (AAIResultWrapper routeTableReferenceWrapper : routeTableReferences) {
1881 contrailNetworkRouteTableReferences.add(this.mapRouteTableReference(routeTableReferenceWrapper));
1885 protected RouteTableReference mapRouteTableReference(AAIResultWrapper routeTableReferenceWrapper) {
1886 Optional<org.onap.aai.domain.yang.RouteTableReference> aaiRouteTableReferenceOp =
1887 routeTableReferenceWrapper.asBean(org.onap.aai.domain.yang.RouteTableReference.class);
1888 org.onap.aai.domain.yang.RouteTableReference aaiRouteTableReference = null;
1890 if (!aaiRouteTableReferenceOp.isPresent()) {
1894 aaiRouteTableReference = aaiRouteTableReferenceOp.get();
1895 return this.mapperLayer.mapAAIRouteTableReferenceIntoRouteTableReference(aaiRouteTableReference);
1898 protected void mapOwningEntity(List<AAIResultWrapper> owningEntities, ServiceInstance serviceInstance) {
1899 if (!owningEntities.isEmpty()) {
1900 AAIResultWrapper owningEntityWrapper = owningEntities.get(0);
1901 Optional<org.onap.aai.domain.yang.OwningEntity> aaiOwningEntityOp =
1902 owningEntityWrapper.asBean(org.onap.aai.domain.yang.OwningEntity.class);
1903 org.onap.aai.domain.yang.OwningEntity aaiOwningEntity = null;
1904 if (!aaiOwningEntityOp.isPresent()) {
1907 aaiOwningEntity = aaiOwningEntityOp.get();
1909 OwningEntity owningEntity = this.mapperLayer.mapAAIOwningEntity(aaiOwningEntity);
1910 serviceInstance.setOwningEntity(owningEntity);
1914 protected void mapProject(List<AAIResultWrapper> projects, ServiceInstance serviceInstance) {
1915 if (!projects.isEmpty()) {
1916 AAIResultWrapper projectWrapper = projects.get(0);
1917 Optional<org.onap.aai.domain.yang.Project> aaiProjectOp =
1918 projectWrapper.asBean(org.onap.aai.domain.yang.Project.class);
1919 org.onap.aai.domain.yang.Project aaiProject = null;
1920 if (!aaiProjectOp.isPresent()) {
1923 aaiProject = aaiProjectOp.get();
1925 Project project = this.mapperLayer.mapAAIProject(aaiProject);
1926 serviceInstance.setProject(project);
1930 protected Customer mapCustomer(String globalCustomerId, String subscriptionServiceType) {
1931 org.onap.aai.domain.yang.Customer aaiCustomer = this.bbInputSetupUtils.getAAICustomer(globalCustomerId);
1932 org.onap.aai.domain.yang.ServiceSubscription aaiServiceSubscription =
1933 this.bbInputSetupUtils.getAAIServiceSubscription(globalCustomerId, subscriptionServiceType);
1934 Customer customer = this.mapperLayer.mapAAICustomer(aaiCustomer);
1935 ServiceSubscription serviceSubscription = this.mapperLayer.mapAAIServiceSubscription(aaiServiceSubscription);
1936 if (serviceSubscription != null) {
1937 customer.setServiceSubscription(serviceSubscription);