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.infrastructure.aai.tasks;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.stream.Collectors;
27 import org.camunda.bpm.engine.delegate.BpmnError;
28 import org.onap.so.bpmn.common.BuildingBlockExecution;
29 import org.onap.so.bpmn.core.UrnPropertiesReader;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
44 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
45 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
46 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
47 import org.onap.so.client.exception.BBObjectNotFoundException;
48 import org.onap.so.client.exception.ExceptionBuilder;
49 import org.onap.so.client.orchestration.AAIConfigurationResources;
50 import org.onap.so.client.orchestration.AAINetworkResources;
51 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
52 import org.onap.so.client.orchestration.AAIVfModuleResources;
53 import org.onap.so.client.orchestration.AAIVnfResources;
54 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
55 import org.onap.so.client.orchestration.AAIVpnBindingResources;
56 import org.onap.so.db.catalog.beans.OrchestrationStatus;
57 import org.onap.so.logger.MessageEnum;
58 import org.onap.so.logger.MsoLogger;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.core.env.Environment;
61 import org.springframework.stereotype.Component;
64 public class AAICreateTasks {
66 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAICreateTasks.class);
67 private static final String networkTypeProvider = "PROVIDER";
68 private static String NETWORK_COLLECTION_NAME = "networkCollectionName";
70 private AAIServiceInstanceResources aaiSIResources;
72 private AAIVnfResources aaiVnfResources;
74 private ExceptionBuilder exceptionUtil;
76 private ExtractPojosForBB extractPojosForBB;
78 private AAIVolumeGroupResources aaiVolumeGroupResources;
80 private AAIVfModuleResources aaiVfModuleResources;
82 private AAINetworkResources aaiNetworkResources;
84 private AAIVpnBindingResources aaiVpnBindingResources;
86 private AAIConfigurationResources aaiConfigurationResources;
88 private Environment env;
90 public void createServiceInstance(BuildingBlockExecution execution) {
92 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
93 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
94 aaiSIResources.createServiceInstance(serviceInstance, customer);
95 } catch (Exception ex) {
96 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
100 public void createServiceSubscription(BuildingBlockExecution execution){
102 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution,
103 ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
104 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
105 if (null == customer) {
106 String errorMessage = "Exception in creating ServiceSubscription. Customer not present for ServiceInstanceID: "
107 + serviceInstance.getServiceInstanceId();
108 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, errorMessage, "BPMN", MsoLogger.getServiceName(),
109 MsoLogger.ErrorCode.UnknownError, errorMessage);
110 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, errorMessage);
112 aaiSIResources.createServiceSubscription(customer);
113 } catch (BpmnError ex) {
116 catch (Exception ex) {
117 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
121 public void createProject(BuildingBlockExecution execution) {
123 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
124 Project project = serviceInstance.getProject();
125 if(project != null) {
126 if (project.getProjectName() == null || "".equals(project.getProjectName())) {
127 msoLogger.info("ProjectName is null in input. Skipping create project...");
129 aaiSIResources.createProjectandConnectServiceInstance(project, serviceInstance);
132 } catch (Exception ex) {
133 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
137 public void createOwningEntity(BuildingBlockExecution execution) {
139 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
140 OwningEntity owningEntity = serviceInstance.getOwningEntity();
141 String owningEntityId = owningEntity.getOwningEntityId();
142 String owningEntityName = owningEntity.getOwningEntityName();
143 if (owningEntityId == null || "".equals(owningEntityId)) {
144 String msg = "Exception in AAICreateOwningEntity. OwningEntityId is null.";
145 execution.setVariable("ErrorCreateOEAAI", msg);
146 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
148 if (aaiSIResources.existsOwningEntity(owningEntity)) {
149 aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
151 if (owningEntityName == null || "".equals(owningEntityName)) {
152 String msg = "Exception in AAICreateOwningEntity. Can't create an owningEntity with no owningEntityName.";
153 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(),
154 MsoLogger.ErrorCode.UnknownError, msg);
155 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
157 if(aaiSIResources.existsOwningEntityName(owningEntityName)){
158 String msg = "Exception in AAICreateOwningEntity. Can't create OwningEntity as name already exists in AAI associated with a different owning-entity-id (name must be unique)";
159 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(),
160 MsoLogger.ErrorCode.UnknownError, msg);
161 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
163 aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
168 } catch (Exception ex) {
169 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
173 public void createVnf(BuildingBlockExecution execution) {
175 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
176 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
177 execution.setVariable("callHoming", Boolean.TRUE.equals(vnf.isCallHoming()));
178 aaiVnfResources.createVnfandConnectServiceInstance(vnf, serviceInstance);
179 } catch (Exception ex) {
180 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
184 public void createPlatform(BuildingBlockExecution execution) {
186 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
187 Platform platform = vnf.getPlatform();
188 if(platform != null) {
189 if (platform.getPlatformName() == null || "".equals(platform.getPlatformName())) {
190 msoLogger.debug("PlatformName is null in input. Skipping create platform...");
192 aaiVnfResources.createPlatformandConnectVnf(platform,vnf);
195 } catch (Exception ex) {
196 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
201 public void createLineOfBusiness(BuildingBlockExecution execution) {
203 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
204 LineOfBusiness lineOfBusiness = vnf.getLineOfBusiness();
205 if(lineOfBusiness != null) {
206 if (lineOfBusiness.getLineOfBusinessName() == null || "".equals(lineOfBusiness.getLineOfBusinessName())) {
207 msoLogger.info("lineOfBusiness is null in input. Skipping create lineOfBusiness...");
209 aaiVnfResources.createLineOfBusinessandConnectVnf(lineOfBusiness,vnf);
212 } catch (Exception ex) {
213 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
217 public void createVolumeGroup(BuildingBlockExecution execution) {
219 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
221 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
222 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
223 CloudRegion cloudRegion = gBBInput.getCloudRegion();
224 aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion);
225 aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion);
226 aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup,cloudRegion);
227 } catch (Exception ex) {
228 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
232 public void createVfModule(BuildingBlockExecution execution) {
234 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
235 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
236 aaiVfModuleResources.createVfModule(vfModule, vnf);
237 } catch (Exception ex) {
238 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
243 * BPMN access method to establish relationships in AAI
247 public void connectVfModuleToVolumeGroup(BuildingBlockExecution execution) {
249 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
250 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
251 VolumeGroup volumeGroup = null;
253 volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
254 } catch (BBObjectNotFoundException e){
255 msoLogger.info("VolumeGroup not found. Skipping Connect between VfModule and VolumeGroup");
257 if (volumeGroup != null) {
258 aaiVfModuleResources.connectVfModuleToVolumeGroup(vnf, vfModule, volumeGroup, execution.getGeneralBuildingBlock().getCloudRegion());
260 } catch (Exception ex) {
261 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
266 * BPMN access method to execute Create L3Network operation (PUT )in AAI
270 public void createNetwork(BuildingBlockExecution execution) {
272 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
273 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
274 //set default to false. ToBe updated by SDNC
275 l3network.setIsBoundToVpn(false);
276 //define is bound to vpn flag as true if NEUTRON_NETWORK_TYPE is PROVIDER
277 if (l3network.getModelInfoNetwork().getNeutronNetworkType().equalsIgnoreCase(networkTypeProvider))
278 l3network.setIsBoundToVpn(true);
279 //put network shell in AAI
280 aaiNetworkResources.createNetworkConnectToServiceInstance(l3network, serviceInstance);
281 } catch (Exception ex) {
282 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
285 public void createCustomer(BuildingBlockExecution execution) throws Exception {
287 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
289 aaiVpnBindingResources.createCustomer(customer);
290 } catch(Exception ex) {
291 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
296 * BPMN access method to execute NetworkCollection operation (PUT) in AAI
300 public void createNetworkCollection(BuildingBlockExecution execution) {
302 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
303 Collection networkCollection = serviceInstance.getCollection();
304 //pass name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
306 networkCollection.setName(execution.getVariable(NETWORK_COLLECTION_NAME));
307 aaiNetworkResources.createNetworkCollection(networkCollection);
308 } catch (Exception ex) {
309 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
314 * BPMN access method to execute NetworkCollectionInstanceGroup operation (PUT) in AAI
318 public void createNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
320 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
321 InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup();
322 //set name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
323 instanceGroup.setInstanceGroupName(execution.getVariable(NETWORK_COLLECTION_NAME));
325 aaiNetworkResources.createNetworkInstanceGroup(instanceGroup);
326 } catch (Exception ex) {
327 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
333 * BPMN access method to establish relationships in AAI
337 public void connectNetworkToTenant(BuildingBlockExecution execution) {
339 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
340 aaiNetworkResources.connectNetworkToTenant(l3network, execution.getGeneralBuildingBlock().getCloudRegion());
341 } catch (Exception ex) {
342 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
347 * BPMN access method to establish relationships in AAI
351 public void connectNetworkToCloudRegion(BuildingBlockExecution execution) {
353 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
354 aaiNetworkResources.connectNetworkToCloudRegion(l3network, execution.getGeneralBuildingBlock().getCloudRegion());
355 } catch (Exception ex) {
356 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
361 * BPMN access method to establish relationships in AAI
365 public void connectVnfToCloudRegion(BuildingBlockExecution execution) {
367 boolean cloudRegionsToSkip = false;
368 String[] cloudRegions = env.getProperty("mso.bpmn.cloudRegionIdsToSkipAddingVnfEdgesTo", String[].class);
369 if (cloudRegions != null){
370 cloudRegionsToSkip = Arrays.stream(cloudRegions).anyMatch(execution.getGeneralBuildingBlock().getCloudRegion().getLcpCloudRegionId()::equals);
372 if(!cloudRegionsToSkip) {
373 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
374 aaiVnfResources.connectVnfToCloudRegion(vnf, execution.getGeneralBuildingBlock().getCloudRegion());
376 } catch (Exception ex) {
377 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
382 * BPMN access method to establish relationships in AAI
386 public void connectVnfToTenant(BuildingBlockExecution execution) {
388 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
389 aaiVnfResources.connectVnfToTenant(vnf, execution.getGeneralBuildingBlock().getCloudRegion());
390 } catch (Exception ex) {
391 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
396 * BPMN access method to establish relationships in AAI
400 public void connectNetworkToNetworkCollectionServiceInstance(BuildingBlockExecution execution) {
402 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
403 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
404 aaiNetworkResources.connectNetworkToNetworkCollectionServiceInstance(l3network, serviceInstance);
405 } catch (Exception ex) {
406 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
411 * BPMN access method to establish relationships in AAI
415 public void connectNetworkToNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
417 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
418 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
419 //connect network only if Instance Group / Collection objects exist
420 if (serviceInstance.getCollection() != null && serviceInstance.getCollection().getInstanceGroup() != null)
421 aaiNetworkResources.connectNetworkToNetworkCollectionInstanceGroup(l3network, serviceInstance.getCollection().getInstanceGroup());
422 } catch (Exception ex) {
423 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
427 public void createConfiguration(BuildingBlockExecution execution){
429 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID, execution.getLookupMap().get(ResourceKey.CONFIGURATION_ID));
430 aaiConfigurationResources.createConfiguration(configuration);
431 } catch (Exception ex) {
432 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);