2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.servicedecomposition.tasks;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.Optional;
28 import java.util.UUID;
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.camunda.bpm.engine.delegate.JavaDelegate;
32 import org.javatuples.Pair;
33 import org.onap.so.bpmn.common.BuildingBlockExecution;
34 import org.onap.so.bpmn.common.DelegateExecutionImpl;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
52 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
53 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
54 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
55 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
56 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
57 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
58 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
59 import org.onap.so.client.aai.AAICommonObjectMapperProvider;
60 import org.onap.so.client.aai.AAIObjectType;
61 import org.onap.so.client.aai.entities.AAIResultWrapper;
62 import org.onap.so.client.aai.entities.Relationships;
63 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
64 import org.onap.so.client.exception.ExceptionBuilder;
65 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
66 import org.onap.so.db.catalog.beans.CollectionResource;
67 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
68 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
69 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
70 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
71 import org.onap.so.db.catalog.beans.OrchestrationStatus;
72 import org.onap.so.db.catalog.beans.Service;
73 import org.onap.so.db.catalog.beans.VfModuleCustomization;
74 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
75 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
76 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
77 import org.onap.so.db.request.beans.InfraActiveRequests;
78 import org.onap.so.logger.MsoLogger;
79 import org.onap.so.serviceinstancebeans.CloudConfiguration;
80 import org.onap.so.serviceinstancebeans.ModelInfo;
81 import org.onap.so.serviceinstancebeans.ModelType;
82 import org.onap.so.serviceinstancebeans.Networks;
83 import org.onap.so.serviceinstancebeans.RelatedInstance;
84 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
85 import org.onap.so.serviceinstancebeans.RequestDetails;
86 import org.onap.so.serviceinstancebeans.RequestParameters;
87 import org.onap.so.serviceinstancebeans.Resources;
88 import org.onap.so.serviceinstancebeans.VfModules;
89 import org.onap.so.serviceinstancebeans.Vnfs;
90 import org.springframework.beans.factory.annotation.Autowired;
91 import org.springframework.stereotype.Component;
93 import com.fasterxml.jackson.core.JsonProcessingException;
94 import com.fasterxml.jackson.databind.ObjectMapper;
95 import com.fasterxml.jackson.databind.SerializationFeature;
97 @Component("BBInputSetup")
98 public class BBInputSetup implements JavaDelegate {
100 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, BBInputSetup.class);
101 private static final String FLOW_VAR_NAME = "flowToBeCalled";
102 private static final String LOOKUP_KEY_MAP_VAR_NAME = "lookupKeyMap";
103 private static final String GBB_INPUT_VAR_NAME = "gBBInput";
104 private static final String EXECUTE_BB_VAR_NAME = "buildingBlock";
105 private static final String VOLUME_GROUP = "VolumeGroup";
106 private static final String VF_MODULE = "VfModule";
107 private static final String NETWORK = "Network";
108 private static final String VNF = "Vnf";
109 private static final String NETWORK_COLLECTION = "NetworkCollection";
112 private BBInputSetupUtils bbInputSetupUtils;
115 private BBInputSetupMapperLayer mapperLayer;
118 private CloudInfoFromAAI cloudInfoFromAAI;
121 private ExceptionBuilder exceptionUtil;
123 private ObjectMapper mapper = new ObjectMapper();
125 public BBInputSetupUtils getBbInputSetupUtils() {
126 return bbInputSetupUtils;
129 public void setCloudInfoFromAAI(CloudInfoFromAAI cloudInfoFromAAI) {
130 this.cloudInfoFromAAI = cloudInfoFromAAI;
133 public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
134 this.bbInputSetupUtils = bbInputSetupUtils;
137 public BBInputSetupMapperLayer getMapperLayer() {
141 public void setMapperLayer(BBInputSetupMapperLayer mapperLayer) {
142 this.mapperLayer = mapperLayer;
146 public void execute(DelegateExecution execution) throws Exception {
148 GeneralBuildingBlock outputBB = null;
149 ExecuteBuildingBlock executeBB = this.getExecuteBBFromExecution(execution);
150 String resourceId = executeBB.getResourceId();
151 String requestAction = executeBB.getRequestAction();
152 String vnfType = executeBB.getVnfType();
153 boolean aLaCarte = Boolean.TRUE.equals(executeBB.isaLaCarte());
154 boolean homing = Boolean.TRUE.equals(executeBB.isHoming());
155 Map<ResourceKey, String> lookupKeyMap = new HashMap<>();
156 outputBB = this.getGBB(executeBB, lookupKeyMap, requestAction, aLaCarte, resourceId, vnfType);
157 ObjectMapper mapper = new ObjectMapper();
158 mapper.enable(SerializationFeature.INDENT_OUTPUT);
159 msoLogger.debug("GeneralBB: " + mapper.writeValueAsString(outputBB));
161 setHomingFlag(outputBB, homing, lookupKeyMap);
163 execution.setVariable(FLOW_VAR_NAME, executeBB.getBuildingBlock().getBpmnFlowName());
164 execution.setVariable(GBB_INPUT_VAR_NAME, outputBB);
165 execution.setVariable(LOOKUP_KEY_MAP_VAR_NAME, lookupKeyMap);
167 BuildingBlockExecution gBuildingBlockExecution = new DelegateExecutionImpl(execution);
168 execution.setVariable("gBuildingBlockExecution", gBuildingBlockExecution);
169 execution.setVariable("RetryCount", 1);
170 execution.setVariable("handlingCode", "Success");
171 } catch (Exception e) {
173 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage());
177 protected void setHomingFlag(GeneralBuildingBlock outputBB, boolean homing, Map<ResourceKey, String> lookupKeyMap) {
179 if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null && homing && outputBB != null) {
180 for (GenericVnf vnf : outputBB.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs()) {
181 if (vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
182 vnf.setCallHoming(homing);
188 protected ExecuteBuildingBlock getExecuteBBFromExecution(DelegateExecution execution) {
189 return (ExecuteBuildingBlock) execution.getVariable(EXECUTE_BB_VAR_NAME);
192 protected GeneralBuildingBlock getGBB(ExecuteBuildingBlock executeBB, Map<ResourceKey, String> lookupKeyMap,
193 String requestAction, boolean aLaCarte, String resourceId, String vnfType) throws Exception {
194 String requestId = executeBB.getRequestId();
195 this.populateLookupKeyMapWithIds(executeBB.getWorkflowResourceIds(), lookupKeyMap);
196 RequestDetails requestDetails = executeBB.getRequestDetails();
197 if(requestDetails == null) {
198 requestDetails = bbInputSetupUtils.getRequestDetails(requestId);
200 if (requestDetails.getModelInfo() == null) {
201 return this.getGBBCM(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId);
204 ModelType modelType = requestDetails.getModelInfo().getModelType();
205 if (aLaCarte && modelType.equals(ModelType.service)) {
206 return this.getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId);
207 } else if (aLaCarte && !modelType.equals(ModelType.service)) {
208 return this.getGBBALaCarteNonService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId,
211 return this.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType);
216 protected void populateLookupKeyMapWithIds(WorkflowResourceIds workflowResourceIds,
217 Map<ResourceKey, String> lookupKeyMap) {
218 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, workflowResourceIds.getServiceInstanceId());
219 lookupKeyMap.put(ResourceKey.NETWORK_ID, workflowResourceIds.getNetworkId());
220 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, workflowResourceIds.getVnfId());
221 lookupKeyMap.put(ResourceKey.VF_MODULE_ID, workflowResourceIds.getVfModuleId());
222 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, workflowResourceIds.getVolumeGroupId());
223 lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, workflowResourceIds.getConfigurationId());
226 protected GeneralBuildingBlock getGBBALaCarteNonService(ExecuteBuildingBlock executeBB,
227 RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String requestAction,
228 String resourceId, String vnfType) throws Exception {
229 String bbName = executeBB.getBuildingBlock().getBpmnFlowName();
230 String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
231 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
232 if (serviceInstanceId != null) {
233 aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
235 Service service = null;
236 if (aaiServiceInstance != null) {
237 service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
239 if (aaiServiceInstance != null && service != null) {
240 ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
241 serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
242 this.populateObjectsOnAssignAndCreateFlows(requestDetails, service, bbName, serviceInstance, lookupKeyMap,
243 resourceId, vnfType);
244 return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null);
246 msoLogger.debug("Related Service Instance from AAI: " + aaiServiceInstance);
247 msoLogger.debug("Related Service Instance Model Info from AAI: " + service);
248 throw new Exception("Could not find relevant information for related Service Instance");
252 protected GeneralBuildingBlock getGBBCM(ExecuteBuildingBlock executeBB,
253 RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String requestAction,
254 String resourceId) throws Exception {
255 ServiceInstance serviceInstance = new ServiceInstance();
256 String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
257 serviceInstance.setServiceInstanceId(serviceInstanceId);
259 List<GenericVnf> genericVnfs = serviceInstance.getVnfs();
261 String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
262 org.onap.aai.domain.yang.GenericVnf aaiGenericVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
264 GenericVnf genericVnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiGenericVnf);
265 genericVnfs.add(genericVnf);
267 return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, new Customer());
271 protected void populateObjectsOnAssignAndCreateFlows(RequestDetails requestDetails, Service service, String bbName,
272 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId, String vnfType)
274 ModelInfo modelInfo = requestDetails.getModelInfo();
275 String instanceName = requestDetails.getRequestInfo().getInstanceName();
276 ModelType modelType = modelInfo.getModelType();
277 RelatedInstanceList[] relatedInstanceList = requestDetails.getRelatedInstanceList();
279 org.onap.so.serviceinstancebeans.Platform platform = requestDetails.getPlatform();
280 org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness = requestDetails.getLineOfBusiness();
282 if (modelType.equals(ModelType.network)) {
283 lookupKeyMap.put(ResourceKey.NETWORK_ID, resourceId);
284 this.populateL3Network(instanceName, modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId, null);
285 } else if (modelType.equals(ModelType.vnf)) {
286 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, resourceId);
287 this.populateGenericVnf(modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance,
288 lookupKeyMap, relatedInstanceList, resourceId, vnfType, null);
289 } else if (modelType.equals(ModelType.volumeGroup)) {
290 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, resourceId);
291 this.populateVolumeGroup(modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
292 relatedInstanceList, instanceName, vnfType, null);
293 } else if (modelType.equals(ModelType.vfModule)) {
294 lookupKeyMap.put(ResourceKey.VF_MODULE_ID, resourceId);
295 this.populateVfModule(modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
296 relatedInstanceList, instanceName, null, requestDetails.getCloudConfiguration());
302 protected void populateConfiguration(ModelInfo modelInfo, Service service, String bbName,
303 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId, String instanceName, ConfigurationResourceKeys configurationResourceKeys) {
304 Configuration configuration = null;
305 for (Configuration configurationTemp : serviceInstance.getConfigurations()) {
306 if (lookupKeyMap.get(ResourceKey.CONFIGURATION_ID) != null
307 && configurationTemp.getConfigurationId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.CONFIGURATION_ID))) {
308 configuration = configurationTemp;
309 org.onap.aai.domain.yang.Configuration aaiConfiguration = bbInputSetupUtils.getAAIConfiguration(configuration.getConfigurationId());
310 if(aaiConfiguration!=null){
311 modelInfo.setModelCustomizationUuid(aaiConfiguration.getModelCustomizationId());
315 if (configuration == null && bbName.equalsIgnoreCase(AssignFlows.FABRIC_CONFIGURATION.toString())) {
316 configuration = this.createConfiguration(lookupKeyMap, instanceName, resourceId);
317 serviceInstance.getConfigurations().add(configuration);
319 if(configuration != null) {
320 this.mapCatalogConfiguration(configuration, modelInfo, service, configurationResourceKeys);
324 protected Configuration createConfiguration(Map<ResourceKey, String> lookupKeyMap,
325 String instanceName, String resourceId) {
326 lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, resourceId);
327 Configuration configuration = new Configuration();
328 configuration.setConfigurationId(resourceId);
329 configuration.setConfigurationName(instanceName);
330 configuration.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
331 return configuration;
334 protected void mapCatalogConfiguration(Configuration configuration, ModelInfo modelInfo, Service service, ConfigurationResourceKeys configurationResourceKeys) {
335 ConfigurationResourceCustomization configurationResourceCustomization = findConfigurationResourceCustomization(modelInfo, service);
336 VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization =
337 findVnfVfmoduleCvnfcConfigurationCustomization(configurationResourceKeys.getVfModuleCustomizationUUID(),
338 configurationResourceKeys.getVnfResourceCustomizationUUID(), configurationResourceKeys.getCvnfcCustomizationUUID(), configurationResourceCustomization);
339 if (configurationResourceCustomization != null && vnfVfmoduleCvnfcConfigurationCustomization != null) {
340 configuration.setModelInfoConfiguration(this.mapperLayer.mapCatalogConfigurationToConfiguration(configurationResourceCustomization
341 , vnfVfmoduleCvnfcConfigurationCustomization));
345 protected VnfVfmoduleCvnfcConfigurationCustomization findVnfVfmoduleCvnfcConfigurationCustomization(String vfModuleCustomizationUUID,
346 String vnfResourceCustomizationUUID, String cvnfcCustomizationUUID, ConfigurationResourceCustomization configurationResourceCustomization) {
348 if(configurationResourceCustomization.getConfigurationResource() != null)
349 for(VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization :
350 configurationResourceCustomization.getConfigurationResource().getVnfVfmoduleCvnfcConfigurationCustomization()) {
351 if(vnfVfmoduleCvnfcConfigurationCustomization.getVfModuleCustomization().getModelCustomizationUUID().equalsIgnoreCase(vfModuleCustomizationUUID)
352 && vnfVfmoduleCvnfcConfigurationCustomization.getVnfResourceCustomization().getModelCustomizationUUID().equalsIgnoreCase(vnfResourceCustomizationUUID)
353 && vnfVfmoduleCvnfcConfigurationCustomization.getCvnfcCustomization().getModelCustomizationUUID().equalsIgnoreCase(cvnfcCustomizationUUID)) {
354 return vnfVfmoduleCvnfcConfigurationCustomization;
360 protected ConfigurationResourceCustomization findConfigurationResourceCustomization(ModelInfo modelInfo, Service service) {
361 for (ConfigurationResourceCustomization resourceCust : service.getConfigurationCustomizations()) {
362 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
369 protected void populateVfModule(ModelInfo modelInfo, Service service, String bbName,
370 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
371 RelatedInstanceList[] relatedInstanceList, String instanceName, List<Map<String, String>> instanceParams, CloudConfiguration cloudConfiguration) throws Exception {
372 String vnfModelCustomizationUUID = null;
373 if (relatedInstanceList != null) {
374 for (RelatedInstanceList relatedInstList : relatedInstanceList) {
375 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
376 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
377 vnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
379 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.volumeGroup)) {
380 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, relatedInstance.getInstanceId());
384 GenericVnf vnf = null;
385 for (GenericVnf tempVnf : serviceInstance.getVnfs()) {
386 if (tempVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
388 vnfModelCustomizationUUID = this.bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId())
389 .getModelCustomizationId();
390 ModelInfo vnfModelInfo = new ModelInfo();
391 vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
392 this.mapCatalogVnf(tempVnf, vnfModelInfo, service);
393 Optional<String> volumeGroupIdOp = getVolumeGroupIdRelatedToVfModule(tempVnf, modelInfo, cloudConfiguration.getCloudOwner(),
394 cloudConfiguration.getLcpCloudRegionId(), lookupKeyMap);
395 if(volumeGroupIdOp.isPresent()) {
396 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupIdOp.get());
402 VfModule vfModule = null;
403 for (VfModule vfModuleTemp : vnf.getVfModules()) {
404 if (lookupKeyMap.get(ResourceKey.VF_MODULE_ID) != null
405 && vfModuleTemp.getVfModuleId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VF_MODULE_ID))) {
406 vfModule = vfModuleTemp;
407 String vfModuleCustId = bbInputSetupUtils.getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()).getModelCustomizationId();
408 modelInfo.setModelCustomizationId(vfModuleCustId);
412 if (vfModule == null && bbName.equalsIgnoreCase(AssignFlows.VF_MODULE.toString())) {
413 vfModule = createVfModule(lookupKeyMap,
414 resourceId, instanceName, instanceParams);
415 vnf.getVfModules().add(vfModule);
417 if(vfModule != null) {
418 mapCatalogVfModule(vfModule, modelInfo, service, vnfModelCustomizationUUID);
421 msoLogger.debug("Related VNF instance Id not found: " + lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID));
422 throw new Exception("Could not find relevant information for related VNF");
426 protected Optional<String> getVolumeGroupIdRelatedToVfModule(GenericVnf vnf, ModelInfo modelInfo,
427 String cloudOwner, String cloudRegionId, Map<ResourceKey, String> lookupKeyMap) {
428 if (lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID) == null) {
429 for(VolumeGroup volumeGroup : vnf.getVolumeGroups()) {
430 String volumeGroupCustId =
431 bbInputSetupUtils.getAAIVolumeGroup(cloudOwner,
432 cloudRegionId, volumeGroup.getVolumeGroupId()).getModelCustomizationId();
433 if(modelInfo.getModelCustomizationId().equalsIgnoreCase(volumeGroupCustId)) {
434 return Optional.of(volumeGroup.getVolumeGroupId());
438 return Optional.empty();
441 protected void mapCatalogVfModule(VfModule vfModule, ModelInfo modelInfo, Service service,
442 String vnfModelCustomizationUUID) {
443 if(modelInfo.getModelCustomizationUuid() != null) {
444 modelInfo.setModelCustomizationId(modelInfo.getModelCustomizationUuid());
446 VnfResourceCustomization vnfResourceCustomization = null;
447 for (VnfResourceCustomization resourceCust : service.getVnfCustomizations()) {
448 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(vnfModelCustomizationUUID)) {
449 vnfResourceCustomization = resourceCust;
453 if (vnfResourceCustomization != null) {
454 VfModuleCustomization vfResourceCustomization = vnfResourceCustomization.getVfModuleCustomizations()
455 .stream() // Convert to steam
456 .filter(x -> modelInfo.getModelCustomizationId().equalsIgnoreCase(x.getModelCustomizationUUID()))// find
460 .findAny() // If 'findAny' then return found
462 if (vfResourceCustomization != null) {
463 vfModule.setModelInfoVfModule(this.mapperLayer.mapCatalogVfModuleToVfModule(vfResourceCustomization));
468 protected VfModule createVfModule(Map<ResourceKey, String> lookupKeyMap, String vfModuleId, String instanceName, List<Map<String, String>> instanceParams) {
469 lookupKeyMap.put(ResourceKey.VF_MODULE_ID, vfModuleId);
470 VfModule vfModule = new VfModule();
471 vfModule.setVfModuleId(vfModuleId);
472 vfModule.setVfModuleName(instanceName);
473 vfModule.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
474 if(instanceParams != null) {
475 for(Map<String, String> params : instanceParams) {
476 vfModule.getCloudParams().putAll(params);
482 protected void populateVolumeGroup(ModelInfo modelInfo, Service service, String bbName,
483 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
484 RelatedInstanceList[] relatedInstanceList, String instanceName, String vnfType, List<Map<String, String>> instanceParams) throws Exception {
485 VolumeGroup volumeGroup = null;
486 GenericVnf vnf = null;
487 String vnfModelCustomizationUUID = null;
488 String generatedVnfType = vnfType;
489 if (generatedVnfType == null || generatedVnfType.isEmpty()) {
490 generatedVnfType = service.getModelName() + "/" + modelInfo.getModelCustomizationName();
492 if (relatedInstanceList != null) {
493 for (RelatedInstanceList relatedInstList : relatedInstanceList) {
494 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
495 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
496 vnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationUuid();
501 for (GenericVnf tempVnf : serviceInstance.getVnfs()) {
502 if (tempVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
504 vnfModelCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId())
505 .getModelCustomizationId();
506 ModelInfo vnfModelInfo = new ModelInfo();
507 vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
508 mapCatalogVnf(tempVnf, vnfModelInfo, service);
512 if (vnf != null && vnfModelCustomizationUUID != null) {
513 for (VolumeGroup volumeGroupTemp : vnf.getVolumeGroups()) {
514 if (lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID) != null && volumeGroupTemp.getVolumeGroupId()
515 .equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID))) {
516 volumeGroup = volumeGroupTemp;
520 if (volumeGroup == null && bbName.equalsIgnoreCase(AssignFlows.VOLUME_GROUP.toString())) {
521 volumeGroup = createVolumeGroup(lookupKeyMap, resourceId, instanceName, generatedVnfType, instanceParams);
522 vnf.getVolumeGroups().add(volumeGroup);
524 if(volumeGroup != null) {
525 mapCatalogVolumeGroup(volumeGroup, modelInfo, service, vnfModelCustomizationUUID);
528 msoLogger.debug("Related VNF instance Id not found: " + lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID));
529 throw new Exception("Could not find relevant information for related VNF");
533 protected VolumeGroup createVolumeGroup(Map<ResourceKey, String> lookupKeyMap, String volumeGroupId, String instanceName, String vnfType, List<Map<String, String>> instanceParams) {
534 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupId);
535 VolumeGroup volumeGroup = new VolumeGroup();
536 volumeGroup.setVolumeGroupId(volumeGroupId);
537 volumeGroup.setVolumeGroupName(instanceName);
538 volumeGroup.setVnfType(vnfType);
539 volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
540 if(instanceParams != null) {
541 for(Map<String, String> params : instanceParams) {
542 volumeGroup.getCloudParams().putAll(params);
548 protected void mapCatalogVolumeGroup(VolumeGroup volumeGroup, ModelInfo modelInfo, Service service,
549 String vnfModelCustomizationUUID) {
550 VfModuleCustomization vfResourceCustomization = getVfResourceCustomization(modelInfo, service,
551 vnfModelCustomizationUUID);
552 if (vfResourceCustomization != null) {
553 volumeGroup.setModelInfoVfModule(this.mapperLayer.mapCatalogVfModuleToVfModule(vfResourceCustomization));
557 protected VfModuleCustomization getVfResourceCustomization(ModelInfo modelInfo, Service service,
558 String vnfModelCustomizationUUID) {
559 VnfResourceCustomization vnfResourceCustomization = null;
560 for (VnfResourceCustomization resourceCust : service.getVnfCustomizations()) {
561 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(vnfModelCustomizationUUID)) {
562 vnfResourceCustomization = resourceCust;
566 if (vnfResourceCustomization != null) {
567 for (VfModuleCustomization vfResourceCust : vnfResourceCustomization.getVfModuleCustomizations()) {
568 if (vfResourceCust.getModelCustomizationUUID()
569 .equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
570 return vfResourceCust;
578 protected void populateGenericVnf(ModelInfo modelInfo, String instanceName,
579 org.onap.so.serviceinstancebeans.Platform platform,
580 org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, Service service, String bbName,
581 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap,
582 RelatedInstanceList[] relatedInstanceList, String resourceId, String vnfType, List<Map<String, String>> instanceParams) {
583 GenericVnf vnf = null;
584 ModelInfo instanceGroupModelInfo = null;
585 String instanceGroupId = null;
586 String generatedVnfType = vnfType;
587 if (generatedVnfType == null || generatedVnfType.isEmpty()) {
588 generatedVnfType = service.getModelName() + "/" + modelInfo.getModelCustomizationName();
590 if (relatedInstanceList != null) {
591 for (RelatedInstanceList relatedInstList : relatedInstanceList) {
592 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
593 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.networkInstanceGroup)) {
594 instanceGroupModelInfo = relatedInstance.getModelInfo();
595 instanceGroupId = relatedInstance.getInstanceId();
599 for (GenericVnf vnfTemp : serviceInstance.getVnfs()) {
600 if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null
601 && vnfTemp.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
602 String vnfModelCustId = bbInputSetupUtils.getAAIGenericVnf(vnfTemp.getVnfId()).getModelCustomizationId();
603 modelInfo.setModelCustomizationUuid(vnfModelCustId);
608 if (vnf == null && bbName.equalsIgnoreCase(AssignFlows.VNF.toString())) {
609 vnf = createGenericVnf(lookupKeyMap, instanceName, platform, lineOfBusiness,
610 resourceId, generatedVnfType, instanceParams);
611 serviceInstance.getVnfs().add(vnf);
612 mapVnfcCollectionInstanceGroup(vnf, modelInfo, service);
615 mapCatalogVnf(vnf, modelInfo, service);
616 if (instanceGroupId != null && instanceGroupModelInfo != null
617 && instanceGroupModelInfo.getModelType().equals(ModelType.networkInstanceGroup)
618 && !instanceGroupInList(vnf, instanceGroupId)) {
619 mapNetworkCollectionInstanceGroup(vnf, instanceGroupId);
624 protected boolean instanceGroupInList(GenericVnf vnf, String instanceGroupId) {
625 for(InstanceGroup instanceGroup : vnf.getInstanceGroups()) {
626 if(instanceGroup.getId() != null && instanceGroup.getId().equalsIgnoreCase(instanceGroupId)) {
633 protected void mapVnfcCollectionInstanceGroup(GenericVnf genericVnf, ModelInfo modelInfo, Service service) {
634 VnfResourceCustomization vnfResourceCustomization = getVnfResourceCustomizationFromService(modelInfo, service);
635 if(vnfResourceCustomization != null) {
636 List<VnfcInstanceGroupCustomization> vnfcInstanceGroups = vnfResourceCustomization
637 .getVnfcInstanceGroupCustomizations();
638 for (VnfcInstanceGroupCustomization vnfcInstanceGroupCust : vnfcInstanceGroups) {
639 InstanceGroup instanceGroup = this.createInstanceGroup();
640 org.onap.so.db.catalog.beans.InstanceGroup catalogInstanceGroup = bbInputSetupUtils.getCatalogInstanceGroup(vnfcInstanceGroupCust.getModelUUID());
641 instanceGroup.setModelInfoInstanceGroup(this.mapperLayer
642 .mapCatalogInstanceGroupToInstanceGroup(null, catalogInstanceGroup));
643 instanceGroup.getModelInfoInstanceGroup().setFunction(vnfcInstanceGroupCust.getFunction());
644 instanceGroup.setDescription(vnfcInstanceGroupCust.getDescription());
645 genericVnf.getInstanceGroups().add(instanceGroup);
650 protected void mapNetworkCollectionInstanceGroup(GenericVnf genericVnf, String instanceGroupId) {
651 org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup = bbInputSetupUtils
652 .getAAIInstanceGroup(instanceGroupId);
653 InstanceGroup instanceGroup = this.mapperLayer.mapAAIInstanceGroupIntoInstanceGroup(aaiInstanceGroup);
654 instanceGroup.setModelInfoInstanceGroup(this.mapperLayer.mapCatalogInstanceGroupToInstanceGroup(
655 null, this.bbInputSetupUtils.getCatalogInstanceGroup(aaiInstanceGroup.getModelVersionId())));
656 genericVnf.getInstanceGroups().add(instanceGroup);
659 protected GenericVnf createGenericVnf(Map<ResourceKey, String> lookupKeyMap, String instanceName,
660 org.onap.so.serviceinstancebeans.Platform platform,
661 org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, String vnfId, String vnfType, List<Map<String, String>> instanceParams) {
662 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfId);
663 GenericVnf genericVnf = new GenericVnf();
664 genericVnf.setVnfId(vnfId);
665 genericVnf.setVnfName(instanceName);
666 genericVnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
667 genericVnf.setVnfType(vnfType);
668 if (platform != null) {
669 genericVnf.setPlatform(this.mapperLayer.mapRequestPlatform(platform));
671 if (lineOfBusiness != null) {
672 genericVnf.setLineOfBusiness(this.mapperLayer.mapRequestLineOfBusiness(lineOfBusiness));
674 if(instanceParams != null) {
675 for(Map<String, String> params : instanceParams) {
676 genericVnf.getCloudParams().putAll(params);
682 protected void mapCatalogVnf(GenericVnf genericVnf, ModelInfo modelInfo, Service service) {
683 VnfResourceCustomization vnfResourceCustomization = getVnfResourceCustomizationFromService(modelInfo, service);
684 if (vnfResourceCustomization != null) {
685 genericVnf.setModelInfoGenericVnf(this.mapperLayer.mapCatalogVnfToVnf(vnfResourceCustomization));
689 protected VnfResourceCustomization getVnfResourceCustomizationFromService(ModelInfo modelInfo, Service service) {
690 VnfResourceCustomization vnfResourceCustomization = null;
691 for (VnfResourceCustomization resourceCust : service.getVnfCustomizations()) {
692 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
693 vnfResourceCustomization = resourceCust;
697 return vnfResourceCustomization;
700 protected void populateL3Network(String instanceName, ModelInfo modelInfo, Service service, String bbName,
701 ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId, List<Map<String, String>> instanceParams) {
702 L3Network network = null;
703 for (L3Network networkTemp : serviceInstance.getNetworks()) {
704 if (lookupKeyMap.get(ResourceKey.NETWORK_ID) != null
705 && networkTemp.getNetworkId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.NETWORK_ID))) {
706 network = networkTemp;
711 && (bbName.equalsIgnoreCase(AssignFlows.NETWORK_A_LA_CARTE.toString())
712 || bbName.equalsIgnoreCase(AssignFlows.NETWORK_MACRO.toString()))) {
713 network = createNetwork(lookupKeyMap, instanceName, resourceId, instanceParams);
714 serviceInstance.getNetworks().add(network);
716 if(network != null) {
717 mapCatalogNetwork(network, modelInfo, service);
721 protected L3Network createNetwork(Map<ResourceKey, String> lookupKeyMap, String instanceName,
722 String networkId, List<Map<String, String>> instanceParams) {
723 lookupKeyMap.put(ResourceKey.NETWORK_ID, networkId);
724 L3Network network = new L3Network();
725 network.setNetworkId(networkId);
726 network.setNetworkName(instanceName);
727 network.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
728 if(instanceParams != null) {
729 for(Map<String, String> params : instanceParams) {
730 network.getCloudParams().putAll(params);
736 protected void mapCatalogNetwork(L3Network network, ModelInfo modelInfo, Service service) {
737 NetworkResourceCustomization networkResourceCustomization = null;
738 for (NetworkResourceCustomization resourceCust : service.getNetworkCustomizations()) {
739 if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
740 networkResourceCustomization = resourceCust;
744 if (networkResourceCustomization != null) {
745 network.setModelInfoNetwork(this.mapperLayer.mapCatalogNetworkToNetwork(networkResourceCustomization));
749 protected GeneralBuildingBlock getGBBALaCarteService(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
750 Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId) throws Exception {
751 Customer customer = getCustomerAndServiceSubscription(requestDetails, resourceId);
752 if (customer != null) {
753 Project project = null;
754 OwningEntity owningEntity = null;
756 if (requestDetails.getProject() != null)
757 project = mapperLayer.mapRequestProject(requestDetails.getProject());
758 if (requestDetails.getOwningEntity() != null)
759 owningEntity = mapperLayer.mapRequestOwningEntity(requestDetails.getOwningEntity());
762 Service service = bbInputSetupUtils
763 .getCatalogServiceByModelUUID(requestDetails.getModelInfo().getModelVersionId());
764 if (service == null) {
765 service = bbInputSetupUtils.getCatalogServiceByModelVersionAndModelInvariantUUID(
766 requestDetails.getModelInfo().getModelVersion(),
767 requestDetails.getModelInfo().getModelInvariantId());
768 if(service == null) {
769 throw new Exception("Could not find service for model version Id: "
770 + requestDetails.getModelInfo().getModelVersionId() + " and for model invariant Id: "
771 + requestDetails.getModelInfo().getModelInvariantId());
774 ServiceInstance serviceInstance = this.getALaCarteServiceInstance(service, requestDetails, customer,
775 project, owningEntity, lookupKeyMap, resourceId, Boolean.TRUE.equals(executeBB.isaLaCarte()),
776 executeBB.getBuildingBlock().getBpmnFlowName());
777 return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, customer);
779 throw new Exception("Could not find customer");
783 protected Customer getCustomerAndServiceSubscription(RequestDetails requestDetails, String resourceId) {
785 if (requestDetails.getSubscriberInfo() != null) {
786 customer = this.getCustomerFromRequest(requestDetails);
788 customer = this.getCustomerFromURI(resourceId);
790 if (customer != null) {
791 ServiceSubscription serviceSubscription = null;
792 serviceSubscription = getServiceSubscription(requestDetails, customer);
793 if (serviceSubscription == null) {
794 serviceSubscription = getServiceSubscriptionFromURI(resourceId, customer);
796 customer.setServiceSubscription(serviceSubscription);
803 protected ServiceSubscription getServiceSubscriptionFromURI(String resourceId, Customer customer) {
804 Map<String, String> uriKeys = bbInputSetupUtils.getURIKeysFromServiceInstance(resourceId);
805 String subscriptionServiceType = uriKeys.get("service-type");
806 org.onap.aai.domain.yang.ServiceSubscription serviceSubscriptionAAI = bbInputSetupUtils
807 .getAAIServiceSubscription(customer.getGlobalCustomerId(), subscriptionServiceType);
808 if (serviceSubscriptionAAI != null) {
809 return mapperLayer.mapAAIServiceSubscription(serviceSubscriptionAAI);
815 protected Customer getCustomerFromURI(String resourceId) {
816 Map<String, String> uriKeys = bbInputSetupUtils.getURIKeysFromServiceInstance(resourceId);
817 String globalCustomerId = uriKeys.get("global-customer-id");
818 org.onap.aai.domain.yang.Customer customerAAI = this.bbInputSetupUtils.getAAICustomer(globalCustomerId);
819 if (customerAAI != null) {
820 return mapperLayer.mapAAICustomer(customerAAI);
826 protected GeneralBuildingBlock populateGBBWithSIAndAdditionalInfo(RequestDetails requestDetails,
827 ServiceInstance serviceInstance, ExecuteBuildingBlock executeBB, String requestAction, Customer customer) {
828 GeneralBuildingBlock outputBB = new GeneralBuildingBlock();
829 OrchestrationContext orchContext = mapperLayer.mapOrchestrationContext(requestDetails);
830 RequestContext requestContext = mapperLayer.mapRequestContext(requestDetails);
831 requestContext.setAction(requestAction);
832 requestContext.setMsoRequestId(executeBB.getRequestId());
833 org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils
834 .getCloudRegion(requestDetails.getCloudConfiguration());
835 CloudRegion cloudRegion = mapperLayer.mapCloudRegion(requestDetails.getCloudConfiguration(), aaiCloudRegion);
836 outputBB.setOrchContext(orchContext);
837 outputBB.setRequestContext(requestContext);
838 outputBB.setCloudRegion(cloudRegion);
839 if(customer == null){
840 Map<String, String> uriKeys = bbInputSetupUtils.getURIKeysFromServiceInstance(serviceInstance.getServiceInstanceId());
841 String globalCustomerId = uriKeys.get("global-customer-id");
842 String subscriptionServiceType = uriKeys.get("service-type");
843 customer = mapCustomer(globalCustomerId, subscriptionServiceType);
845 outputBB.setServiceInstance(serviceInstance);
846 if (customer.getServiceSubscription() != null) {
847 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
849 outputBB.setCustomer(customer);
853 protected ServiceSubscription getServiceSubscription(RequestDetails requestDetails, Customer customer) {
854 org.onap.aai.domain.yang.ServiceSubscription aaiServiceSubscription = bbInputSetupUtils
855 .getAAIServiceSubscription(customer.getGlobalCustomerId(),
856 requestDetails.getRequestParameters().getSubscriptionServiceType());
857 if (aaiServiceSubscription != null) {
858 return mapperLayer.mapAAIServiceSubscription(aaiServiceSubscription);
864 protected Customer getCustomerFromRequest(RequestDetails requestDetails) {
865 org.onap.aai.domain.yang.Customer aaiCustomer = bbInputSetupUtils
866 .getAAICustomer(requestDetails.getSubscriberInfo().getGlobalSubscriberId());
867 if (aaiCustomer != null) {
868 return mapperLayer.mapAAICustomer(aaiCustomer);
874 protected ServiceInstance getALaCarteServiceInstance(Service service, RequestDetails requestDetails,
875 Customer customer, Project project, OwningEntity owningEntity, Map<ResourceKey, String> lookupKeyMap,
876 String serviceInstanceId, boolean aLaCarte, String bbName) throws Exception {
877 ServiceInstance serviceInstance = this.getServiceInstanceHelper(requestDetails, customer, project, owningEntity,
878 lookupKeyMap, serviceInstanceId, aLaCarte, service, bbName);
879 org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = null;
880 if(customer != null && customer.getServiceSubscription() != null) {
881 serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(customer.getGlobalCustomerId(),
882 customer.getServiceSubscription().getServiceType(), serviceInstanceId);
884 serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
886 if (serviceInstanceAAI != null
887 && !serviceInstanceAAI.getModelVersionId().equalsIgnoreCase(service.getModelUUID())) {
888 Service tempService = this.bbInputSetupUtils
889 .getCatalogServiceByModelUUID(serviceInstanceAAI.getModelVersionId());
890 if (tempService != null) {
892 .setModelInfoServiceInstance(mapperLayer.mapCatalogServiceIntoServiceInstance(tempService));
893 return serviceInstance;
896 "Could not find model of existing SI. Service Instance in AAI already exists with different model version id: "
897 + serviceInstanceAAI.getModelVersionId());
900 serviceInstance.setModelInfoServiceInstance(mapperLayer.mapCatalogServiceIntoServiceInstance(service));
901 return serviceInstance;
904 protected GeneralBuildingBlock getGBBMacro(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
905 Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId, String vnfType)
907 String bbName = executeBB.getBuildingBlock().getBpmnFlowName();
908 String key = executeBB.getBuildingBlock().getKey();
910 if (requestAction.equalsIgnoreCase("deleteInstance")
911 || requestAction.equalsIgnoreCase("unassignInstance")
912 || requestAction.equalsIgnoreCase("activateInstance")
913 || requestAction.equalsIgnoreCase("activateFabricConfiguration")
914 || requestAction.equalsIgnoreCase("recreateInstance")
915 || requestAction.equalsIgnoreCase("replaceInstance")) {
916 return getGBBMacroExistingService(executeBB, lookupKeyMap, bbName, requestAction,
917 requestDetails.getCloudConfiguration());
920 String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
921 GeneralBuildingBlock gBB = this.getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction,
923 RequestParameters requestParams = requestDetails.getRequestParameters();
924 Service service = null;
925 if (gBB != null && gBB.getServiceInstance() != null
926 && gBB.getServiceInstance().getModelInfoServiceInstance() != null
927 && gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid() != null) {
928 service = bbInputSetupUtils.getCatalogServiceByModelUUID(
929 gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid());
931 throw new Exception("Could not get service instance for macro request");
933 if (requestParams != null && requestParams.getUserParams() != null) {
934 for(Map<String, Object> userParams : requestParams.getUserParams()) {
935 if(userParams.containsKey("service")) {
936 String input = mapper.writeValueAsString(userParams.get("service"));
937 return getGBBMacroUserParams(executeBB, requestDetails, lookupKeyMap, vnfType, bbName, key, gBB,
938 requestParams, service, input);
942 if (requestAction.equalsIgnoreCase("deactivateInstance")) {
944 } else if (requestAction.equalsIgnoreCase("createInstance")) {
945 return getGBBMacroNoUserParamsCreate(executeBB, lookupKeyMap, bbName, key, gBB, service);
947 throw new IllegalArgumentException(
948 "No user params on requestAction: assignInstance. Please specify user params.");
952 protected GeneralBuildingBlock getGBBMacroNoUserParamsCreate(ExecuteBuildingBlock executeBB,
953 Map<ResourceKey, String> lookupKeyMap, String bbName, String key, GeneralBuildingBlock gBB, Service service)
955 ServiceInstance serviceInstance = gBB.getServiceInstance();
956 if (bbName.contains(NETWORK) && !bbName.contains(NETWORK_COLLECTION)) {
957 String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
958 ModelInfo networkModelInfo = new ModelInfo();
959 if((!Boolean.TRUE.equals(executeBB.getBuildingBlock().getIsVirtualLink()))) {
960 NetworkResourceCustomization networkCust = getNetworkCustomizationByKey(key, service);
961 if (networkCust != null) {
962 networkModelInfo.setModelCustomizationUuid(networkCust.getModelCustomizationUUID());
963 this.populateL3Network(null, networkModelInfo, service, bbName, serviceInstance, lookupKeyMap,
966 msoLogger.debug("Could not find a network customization with key: " + key);
969 msoLogger.debug("Orchestrating on Collection Network Resource Customization");
970 CollectionNetworkResourceCustomization collectionNetworkResourceCust = bbInputSetupUtils.getCatalogCollectionNetworkResourceCustByID(key);
971 L3Network l3Network = getVirtualLinkL3Network(lookupKeyMap, bbName, key, networkId, collectionNetworkResourceCust, serviceInstance);
972 NetworkResourceCustomization networkResourceCustomization =
973 mapperLayer.mapCollectionNetworkResourceCustToNetworkResourceCust(collectionNetworkResourceCust);
974 if(l3Network != null) {
975 l3Network.setModelInfoNetwork(mapperLayer.mapCatalogNetworkToNetwork(networkResourceCustomization));
978 } else if(bbName.contains("Configuration")) {
979 String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
980 ModelInfo configurationModelInfo = new ModelInfo();
981 configurationModelInfo.setModelCustomizationUuid(key);
982 this.populateConfiguration(configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap, configurationId, null, executeBB.getConfigurationResourceKeys());
984 if (executeBB.getWorkflowResourceIds() != null) {
985 this.populateNetworkCollectionAndInstanceGroupAssign(service, bbName, serviceInstance,
986 executeBB.getWorkflowResourceIds().getNetworkCollectionId(), key);
991 protected L3Network getVirtualLinkL3Network(Map<ResourceKey, String> lookupKeyMap, String bbName, String key,
992 String networkId, CollectionNetworkResourceCustomization collectionNetworkResourceCust, ServiceInstance serviceInstance) {
993 if(collectionNetworkResourceCust != null) {
994 if((bbName.equalsIgnoreCase(AssignFlows.NETWORK_A_LA_CARTE.toString())
995 || bbName.equalsIgnoreCase(AssignFlows.NETWORK_MACRO.toString()))) {
996 L3Network network = createNetwork(lookupKeyMap, null, networkId, null);
997 serviceInstance.getNetworks().add(network);
1000 for (L3Network network : serviceInstance.getNetworks()) {
1001 if (network.getNetworkId().equalsIgnoreCase(networkId)) {
1010 protected NetworkResourceCustomization getNetworkCustomizationByKey(String key, Service service) {
1011 for (NetworkResourceCustomization networkCust : service.getNetworkCustomizations()) {
1012 if (networkCust.getModelCustomizationUUID().equalsIgnoreCase(key)) {
1019 protected GeneralBuildingBlock getGBBMacroExistingService(ExecuteBuildingBlock executeBB,
1020 Map<ResourceKey, String> lookupKeyMap, String bbName, String requestAction, CloudConfiguration cloudConfiguration) throws Exception {
1021 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
1022 String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
1023 RequestDetails requestDetails = executeBB.getRequestDetails();
1024 GeneralBuildingBlock gBB = null;
1025 if (serviceInstanceId != null) {
1026 aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
1028 Service service = null;
1029 if (aaiServiceInstance != null) {
1030 service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
1032 if (aaiServiceInstance != null && service != null) {
1033 ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
1034 serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
1035 gBB = populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null);
1037 msoLogger.debug("Related Service Instance from AAI: " + aaiServiceInstance);
1038 msoLogger.debug("Related Service Instance Model Info from AAI: " + service);
1039 throw new Exception("Could not find relevant information for related Service Instance");
1041 ServiceInstance serviceInstance = gBB.getServiceInstance();
1042 CloudRegion cloudRegion = null;
1043 if(cloudConfiguration == null) {
1044 Optional<CloudRegion> cloudRegionOp = cloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance);
1045 if(cloudRegionOp.isPresent()) {
1046 cloudRegion = cloudRegionOp.get();
1049 if (cloudConfiguration != null) {
1050 org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration);
1051 cloudRegion = mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion);
1053 gBB.setCloudRegion(cloudRegion);
1054 if (bbName.contains(VNF)) {
1055 for (GenericVnf genericVnf : serviceInstance.getVnfs()) {
1056 if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null
1057 && genericVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
1058 org.onap.aai.domain.yang.GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(genericVnf.getVnfId());
1059 ModelInfo modelInfo = new ModelInfo();
1061 modelInfo.setModelCustomizationUuid(vnf.getModelCustomizationId());
1063 this.mapCatalogVnf(genericVnf, modelInfo, service);
1066 } else if (bbName.contains(VF_MODULE)) {
1067 for (GenericVnf vnf : serviceInstance.getVnfs()) {
1068 for (VfModule vfModule : vnf.getVfModules()) {
1069 if (lookupKeyMap.get(ResourceKey.VF_MODULE_ID) != null
1070 && vfModule.getVfModuleId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VF_MODULE_ID))) {
1071 String vnfModelCustomizationUUID = this.bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId())
1072 .getModelCustomizationId();
1073 ModelInfo vnfModelInfo = new ModelInfo();
1074 vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
1075 this.mapCatalogVnf(vnf, vnfModelInfo, service);
1076 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnf.getVnfId());
1077 String vfModuleCustomizationUUID = this.bbInputSetupUtils
1078 .getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()).getModelCustomizationId();
1079 ModelInfo vfModuleModelInfo = new ModelInfo();
1080 vfModuleModelInfo.setModelCustomizationId(vfModuleCustomizationUUID);
1081 this.mapCatalogVfModule(vfModule, vfModuleModelInfo, service, vnfModelCustomizationUUID);
1082 if(cloudRegion != null) {
1083 Optional<String> volumeGroupIdOp = getVolumeGroupIdRelatedToVfModule(vnf, vfModuleModelInfo, cloudRegion.getCloudOwner(),
1084 cloudRegion.getLcpCloudRegionId(), lookupKeyMap);
1085 if(volumeGroupIdOp.isPresent()) {
1086 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupIdOp.get());
1093 } else if (bbName.contains(VOLUME_GROUP)) {
1094 for (GenericVnf vnf : serviceInstance.getVnfs()) {
1095 for (VolumeGroup volumeGroup : vnf.getVolumeGroups()) {
1096 if (lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID) != null && volumeGroup.getVolumeGroupId()
1097 .equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID))) {
1098 String vnfModelCustomizationUUID = this.bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId())
1099 .getModelCustomizationId();
1100 ModelInfo vnfModelInfo = new ModelInfo();
1101 vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
1102 this.mapCatalogVnf(vnf, vnfModelInfo, service);
1103 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnf.getVnfId());
1104 if (cloudRegion != null) {
1105 String volumeGroupCustomizationUUID = this.bbInputSetupUtils.getAAIVolumeGroup(cloudRegion.getCloudOwner(),
1106 cloudRegion.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId())
1107 .getModelCustomizationId();
1108 ModelInfo volumeGroupModelInfo = new ModelInfo();
1109 volumeGroupModelInfo.setModelCustomizationId(volumeGroupCustomizationUUID);
1110 this.mapCatalogVolumeGroup(volumeGroup, volumeGroupModelInfo, service,
1111 vnfModelCustomizationUUID);
1117 } else if (bbName.contains(NETWORK)) {
1118 for (L3Network network : serviceInstance.getNetworks()) {
1119 if (lookupKeyMap.get(ResourceKey.NETWORK_ID) != null
1120 && network.getNetworkId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.NETWORK_ID))) {
1121 String networkCustomizationUUID = this.bbInputSetupUtils.getAAIL3Network(network.getNetworkId())
1122 .getModelCustomizationId();
1123 ModelInfo modelInfo = new ModelInfo();
1124 modelInfo.setModelCustomizationUuid(networkCustomizationUUID);
1125 this.mapCatalogNetwork(network, modelInfo, service);
1129 } else if (bbName.contains("Fabric")) {
1130 for(Configuration configuration : serviceInstance.getConfigurations()) {
1131 if(lookupKeyMap.get(ResourceKey.CONFIGURATION_ID) != null
1132 && configuration.getConfigurationId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.CONFIGURATION_ID))) {
1133 String configurationCustUUID = this.bbInputSetupUtils.getAAIConfiguration(configuration.getConfigurationId())
1134 .getModelCustomizationId();
1135 ModelInfo modelInfo = new ModelInfo();
1136 modelInfo.setModelCustomizationUuid(configurationCustUUID);
1137 this.mapCatalogConfiguration(configuration, modelInfo, service, executeBB.getConfigurationResourceKeys());
1142 if (executeBB.getWorkflowResourceIds() != null) {
1143 this.populateNetworkCollectionAndInstanceGroupAssign(service, bbName, serviceInstance,
1144 executeBB.getWorkflowResourceIds().getNetworkCollectionId(), executeBB.getBuildingBlock().getKey());
1149 protected GeneralBuildingBlock getGBBMacroUserParams(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
1150 Map<ResourceKey, String> lookupKeyMap, String vnfType, String bbName, String key, GeneralBuildingBlock gBB,
1151 RequestParameters requestParams, Service service, String input) throws Exception {
1152 ServiceInstance serviceInstance = gBB.getServiceInstance();
1153 org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue(input,
1154 org.onap.so.serviceinstancebeans.Service.class);
1156 Resources resources = serviceMacro.getResources();
1158 VfModules vfModules = null;
1159 Networks networks = null;
1160 CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
1161 CloudRegion cloudRegion = getCloudRegionFromMacroRequest(cloudConfiguration, resources);
1162 gBB.setCloudRegion(cloudRegion);
1163 if (bbName.contains(VNF)) {
1164 vnfs = findVnfsByKey(key, resources, vnfs);
1165 String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
1166 // This stores the vnf id in request db to be retrieved later when
1167 // working on a vf module or volume group
1168 InfraActiveRequests request = this.bbInputSetupUtils.getInfraActiveRequest(executeBB.getRequestId());
1169 if (request != null) {
1170 this.bbInputSetupUtils.updateInfraActiveRequestVnfId(request, vnfId);
1172 this.populateGenericVnf(vnfs.getModelInfo(), vnfs.getInstanceName(), vnfs.getPlatform(),
1173 vnfs.getLineOfBusiness(), service, bbName, serviceInstance, lookupKeyMap, null, vnfId, vnfType, vnfs.getInstanceParams());
1174 } else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP)) {
1175 Pair<Vnfs, VfModules> vnfsAndVfModules = getVfModulesAndItsVnfsByKey(key, resources);
1176 vfModules = vnfsAndVfModules.getValue1();
1177 vnfs = vnfsAndVfModules.getValue0();
1178 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, getVnfId(executeBB, lookupKeyMap));
1180 throw new Exception("Could not find Vnf to orchestrate VfModule");
1182 ModelInfo modelInfo = vfModules.getModelInfo();
1183 if (bbName.contains(VOLUME_GROUP)) {
1184 String volumeGroupId = lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID);
1185 this.populateVolumeGroup(modelInfo, service, bbName, serviceInstance, lookupKeyMap, volumeGroupId, null,
1186 vfModules.getVolumeGroupInstanceName(), vnfType, vfModules.getInstanceParams());
1188 String vfModuleId = lookupKeyMap.get(ResourceKey.VF_MODULE_ID);
1189 CloudConfiguration cloudConfig = new CloudConfiguration();
1190 cloudConfig.setLcpCloudRegionId(cloudRegion.getLcpCloudRegionId());
1191 cloudConfig.setCloudOwner(cloudRegion.getCloudOwner());
1192 this.populateVfModule(modelInfo, service, bbName, serviceInstance, lookupKeyMap, vfModuleId, null,
1193 vfModules.getInstanceName(), vfModules.getInstanceParams(), cloudConfig);
1195 } else if (bbName.contains(NETWORK)) {
1196 networks = findNetworksByKey(key, resources);
1197 String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
1198 this.populateL3Network(networks.getInstanceName(), networks.getModelInfo(), service, bbName,
1199 serviceInstance, lookupKeyMap, networkId, networks.getInstanceParams());
1200 } else if (bbName.contains("Configuration")) {
1201 String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
1202 ModelInfo configurationModelInfo = new ModelInfo();
1203 configurationModelInfo.setModelCustomizationUuid(key);
1204 ConfigurationResourceCustomization configurationCust = findConfigurationResourceCustomization(configurationModelInfo, service);
1205 if(configurationCust != null) {
1206 this.populateConfiguration(configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap, configurationId, null, executeBB.getConfigurationResourceKeys());
1208 msoLogger.debug("Could not find a configuration customization with key: " + key);
1214 protected Networks findNetworksByKey(String key, Resources resources) {
1215 for (Networks networks : resources.getNetworks()) {
1216 if (networks.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) {
1223 protected Pair<Vnfs, VfModules> getVfModulesAndItsVnfsByKey(String key, Resources resources) {
1224 for (Vnfs vnfs : resources.getVnfs()) {
1225 for (VfModules vfModules : vnfs.getVfModules()) {
1226 if (vfModules.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) {
1227 return new Pair<Vnfs, VfModules>(vnfs, vfModules);
1234 protected Vnfs findVnfsByKey(String key, Resources resources, Vnfs vnfs) {
1235 for (Vnfs tempVnfs : resources.getVnfs()) {
1236 if (tempVnfs.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) {
1244 protected CloudRegion getCloudRegionFromMacroRequest(CloudConfiguration cloudConfiguration, Resources resources) {
1245 if(cloudConfiguration == null) {
1246 for(Vnfs vnfs : resources.getVnfs()) {
1247 if(cloudConfiguration == null) {
1248 cloudConfiguration = vnfs.getCloudConfiguration();
1252 for(VfModules vfModules : vnfs.getVfModules()) {
1253 if(cloudConfiguration == null) {
1254 cloudConfiguration = vfModules.getCloudConfiguration();
1260 for(Networks networks : resources.getNetworks()) {
1261 if(cloudConfiguration == null) {
1262 cloudConfiguration = networks.getCloudConfiguration();
1268 if(cloudConfiguration != null) {
1269 org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration);
1270 return mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion);
1272 msoLogger.debug("Could not find any cloud configuration for this request.");
1277 protected String getVnfId(ExecuteBuildingBlock executeBB, Map<ResourceKey, String> lookupKeyMap) {
1278 String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
1279 if (vnfId == null) {
1280 InfraActiveRequests request = this.bbInputSetupUtils.getInfraActiveRequest(executeBB.getRequestId());
1281 vnfId = request.getVnfId();
1287 protected String generateRandomUUID() {
1288 return UUID.randomUUID().toString();
1291 protected ServiceInstance getServiceInstanceHelper(RequestDetails requestDetails, Customer customer,
1292 Project project, OwningEntity owningEntity, Map<ResourceKey, String> lookupKeyMap, String serviceInstanceId,
1293 boolean aLaCarte, Service service, String bbName) throws Exception {
1294 if (requestDetails.getRequestInfo().getInstanceName() == null && aLaCarte
1295 && bbName.equalsIgnoreCase(AssignFlows.SERVICE_INSTANCE.toString())) {
1296 throw new Exception("Request invalid missing: RequestInfo:InstanceName");
1298 org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = null;
1299 if (aLaCarte && bbName.equalsIgnoreCase(AssignFlows.SERVICE_INSTANCE.toString())) {
1300 serviceInstanceAAI = bbInputSetupUtils
1301 .getAAIServiceInstanceByName(requestDetails.getRequestInfo().getInstanceName(), customer);
1303 if (serviceInstanceId != null && serviceInstanceAAI == null) {
1304 if(customer != null && customer.getServiceSubscription() != null) {
1305 serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(customer.getGlobalCustomerId(),
1306 customer.getServiceSubscription().getServiceType(), serviceInstanceId);
1308 serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
1311 if (serviceInstanceAAI != null) {
1312 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstanceId);
1313 return this.getExistingServiceInstance(serviceInstanceAAI);
1315 return createServiceInstance(requestDetails, project, owningEntity, lookupKeyMap,
1321 protected ServiceInstance createServiceInstance(RequestDetails requestDetails, Project project,
1322 OwningEntity owningEntity, Map<ResourceKey, String> lookupKeyMap, String serviceInstanceId) {
1323 ServiceInstance serviceInstance = new ServiceInstance();
1324 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstanceId);
1325 serviceInstance.setServiceInstanceId(serviceInstanceId);
1326 if(requestDetails.getRequestInfo() != null) {
1327 serviceInstance.setServiceInstanceName(requestDetails.getRequestInfo().getInstanceName());
1329 serviceInstance.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
1330 serviceInstance.setProject(project);
1331 serviceInstance.setOwningEntity(owningEntity);
1332 return serviceInstance;
1335 public ServiceInstance getExistingServiceInstance(org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI)
1337 ServiceInstance serviceInstance = mapperLayer.mapAAIServiceInstanceIntoServiceInstance(serviceInstanceAAI);
1338 if (serviceInstanceAAI.getRelationshipList() != null
1339 && serviceInstanceAAI.getRelationshipList().getRelationship() != null
1340 && !serviceInstanceAAI.getRelationshipList().getRelationship().isEmpty()) {
1341 addRelationshipsToSI(serviceInstanceAAI, serviceInstance);
1343 return serviceInstance;
1346 protected void populateNetworkCollectionAndInstanceGroupAssign(Service service, String bbName,
1347 ServiceInstance serviceInstance, String resourceId, String key) throws Exception {
1348 if (serviceInstance.getCollection() == null
1349 && bbName.equalsIgnoreCase(AssignFlows.NETWORK_COLLECTION.toString())) {
1350 Collection collection = this.createCollection(resourceId);
1351 serviceInstance.setCollection(collection);
1352 this.mapCatalogCollection(service, serviceInstance.getCollection(), key);
1353 if(isVlanTagging(service, key)) {
1354 InstanceGroup instanceGroup = this.createInstanceGroup();
1355 serviceInstance.getCollection().setInstanceGroup(instanceGroup);
1356 this.mapCatalogNetworkCollectionInstanceGroup(service,
1357 serviceInstance.getCollection().getInstanceGroup(), key);
1362 protected CollectionResourceCustomization findCatalogNetworkCollection(Service service, String key) {
1363 for(CollectionResourceCustomization collectionCust : service.getCollectionResourceCustomizations()){
1364 if(collectionCust.getModelCustomizationUUID().equalsIgnoreCase(key)) {
1365 return collectionCust;
1371 protected boolean isVlanTagging(Service service, String key) {
1372 CollectionResourceCustomization collectionCust = findCatalogNetworkCollection(service, key);
1373 if (collectionCust != null) {
1374 CollectionResource collectionResource = collectionCust.getCollectionResource();
1375 if (collectionResource != null
1376 && collectionResource.getInstanceGroup() != null
1377 && collectionResource.getInstanceGroup().getToscaNodeType() != null
1378 && collectionResource.getInstanceGroup().getToscaNodeType().contains("NetworkCollection")) {
1385 protected void mapCatalogNetworkCollectionInstanceGroup(Service service, InstanceGroup instanceGroup, String key) {
1386 CollectionResourceCustomization collectionCust = this.findCatalogNetworkCollection(service, key);
1387 org.onap.so.db.catalog.beans.InstanceGroup catalogInstanceGroup = collectionCust.getCollectionResource().getInstanceGroup();
1388 instanceGroup.setModelInfoInstanceGroup(
1389 mapperLayer.mapCatalogInstanceGroupToInstanceGroup(collectionCust, catalogInstanceGroup));
1392 protected void mapCatalogCollection(Service service, Collection collection, String key) {
1393 CollectionResourceCustomization collectionCust = findCatalogNetworkCollection(service, key);
1394 if (collectionCust != null) {
1395 CollectionResource collectionResource = collectionCust.getCollectionResource();
1396 if (collectionResource != null) {
1397 collection.setModelInfoCollection(
1398 mapperLayer.mapCatalogCollectionToCollection(collectionCust, collectionResource));
1403 protected Collection createCollection(String collectionId) {
1404 Collection collection = new Collection();
1405 collection.setId(collectionId);
1406 collection.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
1410 protected InstanceGroup createInstanceGroup() {
1411 InstanceGroup instanceGroup = new InstanceGroup();
1412 String instanceGroupId = this.generateRandomUUID();
1413 instanceGroup.setId(instanceGroupId);
1414 return instanceGroup;
1417 protected void addRelationshipsToSI(org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI,
1418 ServiceInstance serviceInstance) throws Exception {
1419 AAIResultWrapper serviceInstanceWrapper = new AAIResultWrapper(
1420 new AAICommonObjectMapperProvider().getMapper().writeValueAsString(serviceInstanceAAI));
1421 Optional<Relationships> relationshipsOp = serviceInstanceWrapper.getRelationships();
1422 Relationships relationships = null;
1423 if (relationshipsOp.isPresent()) {
1424 relationships = relationshipsOp.get();
1429 this.mapProject(relationships.getByType(AAIObjectType.PROJECT), serviceInstance);
1430 this.mapOwningEntity(relationships.getByType(AAIObjectType.OWNING_ENTITY), serviceInstance);
1431 this.mapL3Networks(relationships.getRelatedAAIUris(AAIObjectType.L3_NETWORK), serviceInstance.getNetworks());
1432 this.mapGenericVnfs(relationships.getRelatedAAIUris(AAIObjectType.GENERIC_VNF), serviceInstance.getVnfs());
1433 this.mapCollection(relationships.getByType(AAIObjectType.COLLECTION), serviceInstance);
1434 this.mapConfigurations(relationships.getRelatedAAIUris(AAIObjectType.CONFIGURATION), serviceInstance.getConfigurations());
1437 protected void mapConfigurations(List<AAIResourceUri> relatedAAIUris, List<Configuration> configurations) {
1438 for (AAIResourceUri aaiResourceUri : relatedAAIUris) {
1439 configurations.add(mapConfiguration(aaiResourceUri));
1443 protected Configuration mapConfiguration(AAIResourceUri aaiResourceUri) {
1444 AAIResultWrapper aaiConfigurationWrapper = this.bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri);
1445 Optional<org.onap.aai.domain.yang.Configuration> aaiConfigurationOp = aaiConfigurationWrapper
1446 .asBean(org.onap.aai.domain.yang.Configuration.class);
1447 if (!aaiConfigurationOp.isPresent()) {
1451 return this.mapperLayer.mapAAIConfiguration(aaiConfigurationOp.get());
1454 protected void mapGenericVnfs(List<AAIResourceUri> list, List<GenericVnf> genericVnfs) {
1455 for (AAIResourceUri aaiResourceUri : list) {
1456 genericVnfs.add(this.mapGenericVnf(aaiResourceUri));
1460 protected GenericVnf mapGenericVnf(AAIResourceUri aaiResourceUri) {
1461 AAIResultWrapper aaiGenericVnfWrapper = this.bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri);
1462 Optional<org.onap.aai.domain.yang.GenericVnf> aaiGenericVnfOp = aaiGenericVnfWrapper
1463 .asBean(org.onap.aai.domain.yang.GenericVnf.class);
1464 if (!aaiGenericVnfOp.isPresent()) {
1468 GenericVnf genericVnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiGenericVnfOp.get());
1470 Optional<Relationships> relationshipsOp = aaiGenericVnfWrapper.getRelationships();
1471 if (relationshipsOp.isPresent()) {
1472 Relationships relationships = relationshipsOp.get();
1473 this.mapPlatform(relationships.getByType(AAIObjectType.PLATFORM), genericVnf);
1474 this.mapLineOfBusiness(relationships.getByType(AAIObjectType.LINE_OF_BUSINESS), genericVnf);
1475 genericVnf.getVolumeGroups().addAll(mapVolumeGroups(relationships.getByType(AAIObjectType.VOLUME_GROUP)));
1476 genericVnf.getInstanceGroups().addAll(mapInstanceGroups(relationships.getByType(AAIObjectType.INSTANCE_GROUP)));
1482 protected List<InstanceGroup> mapInstanceGroups(List<AAIResultWrapper> instanceGroups) {
1483 List<InstanceGroup> instanceGroupsList = new ArrayList<>();
1484 for (AAIResultWrapper volumeGroupWrapper : instanceGroups) {
1485 instanceGroupsList.add(this.mapInstanceGroup(volumeGroupWrapper));
1487 return instanceGroupsList;
1490 protected InstanceGroup mapInstanceGroup(AAIResultWrapper instanceGroupWrapper) {
1491 Optional<org.onap.aai.domain.yang.InstanceGroup> aaiInstanceGroupOp = instanceGroupWrapper
1492 .asBean(org.onap.aai.domain.yang.InstanceGroup.class);
1493 org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup = null;
1495 if (!aaiInstanceGroupOp.isPresent()) {
1499 aaiInstanceGroup = aaiInstanceGroupOp.get();
1500 InstanceGroup instanceGroup = this.mapperLayer.mapAAIInstanceGroupIntoInstanceGroup(aaiInstanceGroup);
1501 instanceGroup.setModelInfoInstanceGroup(this.mapperLayer.mapCatalogInstanceGroupToInstanceGroup(null,
1502 this.bbInputSetupUtils.getCatalogInstanceGroup(aaiInstanceGroup.getModelVersionId())));
1503 return instanceGroup;
1506 protected List<VolumeGroup> mapVolumeGroups(List<AAIResultWrapper> volumeGroups) {
1507 List<VolumeGroup> volumeGroupsList = new ArrayList<>();
1508 for (AAIResultWrapper volumeGroupWrapper : volumeGroups) {
1509 volumeGroupsList.add(this.mapVolumeGroup(volumeGroupWrapper));
1511 return volumeGroupsList;
1514 protected VolumeGroup mapVolumeGroup(AAIResultWrapper volumeGroupWrapper) {
1515 Optional<org.onap.aai.domain.yang.VolumeGroup> aaiVolumeGroupOp = volumeGroupWrapper
1516 .asBean(org.onap.aai.domain.yang.VolumeGroup.class);
1517 org.onap.aai.domain.yang.VolumeGroup aaiVolumeGroup = null;
1519 if (!aaiVolumeGroupOp.isPresent()) {
1523 aaiVolumeGroup = aaiVolumeGroupOp.get();
1524 return this.mapperLayer.mapAAIVolumeGroup(aaiVolumeGroup);
1527 protected void mapLineOfBusiness(List<AAIResultWrapper> lineOfBusinesses, GenericVnf genericVnf) {
1528 if (!lineOfBusinesses.isEmpty()) {
1529 AAIResultWrapper lineOfBusinessWrapper = lineOfBusinesses.get(0);
1530 Optional<org.onap.aai.domain.yang.LineOfBusiness> aaiLineOfBusinessOp = lineOfBusinessWrapper
1531 .asBean(org.onap.aai.domain.yang.LineOfBusiness.class);
1532 org.onap.aai.domain.yang.LineOfBusiness aaiLineOfBusiness = null;
1533 if (!aaiLineOfBusinessOp.isPresent()) {
1536 aaiLineOfBusiness = aaiLineOfBusinessOp.get();
1538 LineOfBusiness lineOfBusiness = this.mapperLayer.mapAAILineOfBusiness(aaiLineOfBusiness);
1539 genericVnf.setLineOfBusiness(lineOfBusiness);
1543 protected void mapPlatform(List<AAIResultWrapper> platforms, GenericVnf genericVnf) {
1544 if (!platforms.isEmpty()) {
1545 AAIResultWrapper platformWrapper = platforms.get(0);
1546 Optional<org.onap.aai.domain.yang.Platform> aaiPlatformOp = platformWrapper
1547 .asBean(org.onap.aai.domain.yang.Platform.class);
1548 org.onap.aai.domain.yang.Platform aaiPlatform = null;
1549 if (!aaiPlatformOp.isPresent()) {
1552 aaiPlatform = aaiPlatformOp.get();
1554 Platform platform = this.mapperLayer.mapAAIPlatform(aaiPlatform);
1555 genericVnf.setPlatform(platform);
1559 protected void mapCollection(List<AAIResultWrapper> collections, ServiceInstance serviceInstance) {
1560 if (!collections.isEmpty()) {
1561 AAIResultWrapper collectionWrapper = collections.get(0);
1562 Optional<org.onap.aai.domain.yang.Collection> aaiCollectionOp = collectionWrapper
1563 .asBean(org.onap.aai.domain.yang.Collection.class);
1564 org.onap.aai.domain.yang.Collection aaiCollection = null;
1565 if (!aaiCollectionOp.isPresent()) {
1568 aaiCollection = aaiCollectionOp.get();
1570 Collection collection = this.mapperLayer.mapAAICollectionIntoCollection(aaiCollection);
1571 NetworkCollectionResourceCustomization collectionResourceCust =
1572 bbInputSetupUtils.getCatalogNetworkCollectionResourceCustByID(aaiCollection.getCollectionCustomizationId());
1573 collection.setModelInfoCollection(mapperLayer.mapCatalogCollectionToCollection(collectionResourceCust, collectionResourceCust.getCollectionResource()));
1574 Optional<Relationships> relationshipsOp = collectionWrapper.getRelationships();
1575 Relationships relationships = null;
1576 if (relationshipsOp.isPresent()) {
1577 relationships = relationshipsOp.get();
1579 serviceInstance.setCollection(collection);
1582 List<InstanceGroup> instanceGroupsList = mapInstanceGroups(relationships.getByType(AAIObjectType.INSTANCE_GROUP));
1583 if(!instanceGroupsList.isEmpty()) {
1584 collection.setInstanceGroup(instanceGroupsList.get(0));
1586 serviceInstance.setCollection(collection);
1590 protected void mapL3Networks(List<AAIResourceUri> list, List<L3Network> l3Networks) {
1591 for (AAIResourceUri aaiResourceUri : list) {
1592 l3Networks.add(this.mapL3Network(aaiResourceUri));
1596 protected L3Network mapL3Network(AAIResourceUri aaiResourceUri) {
1597 AAIResultWrapper aaiNetworkWrapper = this.bbInputSetupUtils.getAAIResourceDepthTwo(aaiResourceUri);
1598 Optional<org.onap.aai.domain.yang.L3Network> aaiL3NetworkOp = aaiNetworkWrapper
1599 .asBean(org.onap.aai.domain.yang.L3Network.class);
1600 org.onap.aai.domain.yang.L3Network aaiL3Network = null;
1602 if (!aaiL3NetworkOp.isPresent()) {
1606 aaiL3Network = aaiL3NetworkOp.get();
1607 L3Network network = this.mapperLayer.mapAAIL3Network(aaiL3Network);
1609 Optional<Relationships> relationshipsOp = aaiNetworkWrapper.getRelationships();
1610 if (relationshipsOp.isPresent()) {
1611 Relationships relationships = relationshipsOp.get();
1612 this.mapNetworkPolicies(relationships.getByType(AAIObjectType.NETWORK_POLICY),
1613 network.getNetworkPolicies());
1614 mapRouteTableReferences(relationships.getByType(AAIObjectType.ROUTE_TABLE_REFERENCE),
1615 network.getContrailNetworkRouteTableReferences());
1621 protected void mapNetworkPolicies(List<AAIResultWrapper> aaiNetworkPolicies, List<NetworkPolicy> networkPolicies) {
1622 for (AAIResultWrapper networkPolicyWrapper : aaiNetworkPolicies) {
1623 networkPolicies.add(this.mapNetworkPolicy(networkPolicyWrapper));
1627 protected NetworkPolicy mapNetworkPolicy(AAIResultWrapper networkPolicyWrapper) {
1628 Optional<org.onap.aai.domain.yang.NetworkPolicy> aaiNetworkPolicyOp = networkPolicyWrapper
1629 .asBean(org.onap.aai.domain.yang.NetworkPolicy.class);
1630 org.onap.aai.domain.yang.NetworkPolicy aaiNetworkPolicy = null;
1632 if (!aaiNetworkPolicyOp.isPresent()) {
1636 aaiNetworkPolicy = aaiNetworkPolicyOp.get();
1637 return this.mapperLayer.mapAAINetworkPolicy(aaiNetworkPolicy);
1640 protected void mapRouteTableReferences(List<AAIResultWrapper> routeTableReferences,
1641 List<RouteTableReference> contrailNetworkRouteTableReferences) {
1642 for (AAIResultWrapper routeTableReferenceWrapper : routeTableReferences) {
1643 contrailNetworkRouteTableReferences.add(this.mapRouteTableReference(routeTableReferenceWrapper));
1647 protected RouteTableReference mapRouteTableReference(AAIResultWrapper routeTableReferenceWrapper) {
1648 Optional<org.onap.aai.domain.yang.RouteTableReference> aaiRouteTableReferenceOp = routeTableReferenceWrapper
1649 .asBean(org.onap.aai.domain.yang.RouteTableReference.class);
1650 org.onap.aai.domain.yang.RouteTableReference aaiRouteTableReference = null;
1652 if (!aaiRouteTableReferenceOp.isPresent()) {
1656 aaiRouteTableReference = aaiRouteTableReferenceOp.get();
1657 return this.mapperLayer.mapAAIRouteTableReferenceIntoRouteTableReference(aaiRouteTableReference);
1660 protected void mapOwningEntity(List<AAIResultWrapper> owningEntities, ServiceInstance serviceInstance) {
1661 if (!owningEntities.isEmpty()) {
1662 AAIResultWrapper owningEntityWrapper = owningEntities.get(0);
1663 Optional<org.onap.aai.domain.yang.OwningEntity> aaiOwningEntityOp = owningEntityWrapper
1664 .asBean(org.onap.aai.domain.yang.OwningEntity.class);
1665 org.onap.aai.domain.yang.OwningEntity aaiOwningEntity = null;
1666 if (!aaiOwningEntityOp.isPresent()) {
1669 aaiOwningEntity = aaiOwningEntityOp.get();
1671 OwningEntity owningEntity = this.mapperLayer.mapAAIOwningEntity(aaiOwningEntity);
1672 serviceInstance.setOwningEntity(owningEntity);
1676 protected void mapProject(List<AAIResultWrapper> projects, ServiceInstance serviceInstance) {
1677 if (!projects.isEmpty()) {
1678 AAIResultWrapper projectWrapper = projects.get(0);
1679 Optional<org.onap.aai.domain.yang.Project> aaiProjectOp = projectWrapper
1680 .asBean(org.onap.aai.domain.yang.Project.class);
1681 org.onap.aai.domain.yang.Project aaiProject = null;
1682 if (!aaiProjectOp.isPresent()) {
1685 aaiProject = aaiProjectOp.get();
1687 Project project = this.mapperLayer.mapAAIProject(aaiProject);
1688 serviceInstance.setProject(project);
1691 protected Customer mapCustomer(String globalCustomerId, String subscriptionServiceType) {
1692 org.onap.aai.domain.yang.Customer aaiCustomer = this.bbInputSetupUtils.getAAICustomer(globalCustomerId);
1693 org.onap.aai.domain.yang.ServiceSubscription aaiServiceSubscription = this.bbInputSetupUtils
1694 .getAAIServiceSubscription(globalCustomerId, subscriptionServiceType);
1695 Customer customer = this.mapperLayer.mapAAICustomer(aaiCustomer);
1696 ServiceSubscription serviceSubscription = this.mapperLayer.mapAAIServiceSubscription(aaiServiceSubscription);
1697 if(serviceSubscription != null){
1698 customer.setServiceSubscription(serviceSubscription);