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 org.camunda.bpm.engine.delegate.BpmnError;
24 import org.onap.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
39 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
40 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
41 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
42 import org.onap.so.client.exception.BBObjectNotFoundException;
43 import org.onap.so.client.exception.ExceptionBuilder;
44 import org.onap.so.client.orchestration.AAIConfigurationResources;
45 import org.onap.so.client.orchestration.AAINetworkResources;
46 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
47 import org.onap.so.client.orchestration.AAIVfModuleResources;
48 import org.onap.so.client.orchestration.AAIVnfResources;
49 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
50 import org.onap.so.client.orchestration.AAIVpnBindingResources;
51 import org.onap.so.db.catalog.beans.OrchestrationStatus;
52 import org.onap.so.logger.MessageEnum;
53 import org.onap.so.logger.MsoLogger;
54 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.stereotype.Component;
58 public class AAICreateTasks {
60 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAICreateTasks.class);
61 private static final String networkTypeProvider = "PROVIDER";
62 private static String NETWORK_COLLECTION_NAME = "networkCollectionName";
64 private AAIServiceInstanceResources aaiSIResources;
66 private AAIVnfResources aaiVnfResources;
68 private ExceptionBuilder exceptionUtil;
70 private ExtractPojosForBB extractPojosForBB;
72 private AAIVolumeGroupResources aaiVolumeGroupResources;
74 private AAIVfModuleResources aaiVfModuleResources;
76 private AAINetworkResources aaiNetworkResources;
78 private AAIVpnBindingResources aaiVpnBindingResources;
80 private AAIConfigurationResources aaiConfigurationResources;
82 public void createServiceInstance(BuildingBlockExecution execution) {
84 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
85 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
86 aaiSIResources.createServiceInstance(serviceInstance, customer);
87 } catch (Exception ex) {
88 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
92 public void createServiceSubscription(BuildingBlockExecution execution){
94 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution,
95 ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
96 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
97 if (null == customer) {
98 String errorMessage = "Exception in creating ServiceSubscription. Customer not present for ServiceInstanceID: "
99 + serviceInstance.getServiceInstanceId();
100 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, errorMessage, "BPMN", MsoLogger.getServiceName(),
101 MsoLogger.ErrorCode.UnknownError, errorMessage);
102 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, errorMessage);
104 aaiSIResources.createServiceSubscription(customer);
105 } catch (BpmnError ex) {
108 catch (Exception ex) {
109 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
113 public void createProject(BuildingBlockExecution execution) {
115 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
116 Project project = serviceInstance.getProject();
117 if(project != null) {
118 if (project.getProjectName() == null || "".equals(project.getProjectName())) {
119 msoLogger.info("ProjectName is null in input. Skipping create project...");
121 aaiSIResources.createProjectandConnectServiceInstance(project, serviceInstance);
124 } catch (Exception ex) {
125 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
129 public void createOwningEntity(BuildingBlockExecution execution) {
131 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
132 OwningEntity owningEntity = serviceInstance.getOwningEntity();
133 String owningEntityId = owningEntity.getOwningEntityId();
134 String owningEntityName = owningEntity.getOwningEntityName();
135 if (owningEntityId == null || "".equals(owningEntityId)) {
136 String msg = "Exception in AAICreateOwningEntity. OwningEntityId is null.";
137 execution.setVariable("ErrorCreateOEAAI", msg);
138 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
140 if (aaiSIResources.existsOwningEntity(owningEntity)) {
141 aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
143 if (owningEntityName == null || "".equals(owningEntityName)) {
144 String msg = "Exception in AAICreateOwningEntity. Can't create an owningEntity with no owningEntityName.";
145 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(),
146 MsoLogger.ErrorCode.UnknownError, msg);
147 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
149 if(aaiSIResources.existsOwningEntityName(owningEntityName)){
150 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)";
151 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(),
152 MsoLogger.ErrorCode.UnknownError, msg);
153 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
155 aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
160 } catch (Exception ex) {
161 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
165 public void createVnf(BuildingBlockExecution execution) {
167 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
168 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
169 execution.setVariable("callHoming", Boolean.TRUE.equals(vnf.isCallHoming()));
170 aaiVnfResources.createVnfandConnectServiceInstance(vnf, serviceInstance);
171 } catch (Exception ex) {
172 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
176 public void createPlatform(BuildingBlockExecution execution) {
178 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
179 Platform platform = vnf.getPlatform();
180 if(platform != null) {
181 if (platform.getPlatformName() == null || "".equals(platform.getPlatformName())) {
182 msoLogger.debug("PlatformName is null in input. Skipping create platform...");
184 aaiVnfResources.createPlatformandConnectVnf(platform,vnf);
187 } catch (Exception ex) {
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
193 public void createLineOfBusiness(BuildingBlockExecution execution) {
195 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
196 LineOfBusiness lineOfBusiness = vnf.getLineOfBusiness();
197 if(lineOfBusiness != null) {
198 if (lineOfBusiness.getLineOfBusinessName() == null || "".equals(lineOfBusiness.getLineOfBusinessName())) {
199 msoLogger.info("lineOfBusiness is null in input. Skipping create lineOfBusiness...");
201 aaiVnfResources.createLineOfBusinessandConnectVnf(lineOfBusiness,vnf);
204 } catch (Exception ex) {
205 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
209 public void createVolumeGroup(BuildingBlockExecution execution) {
211 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
213 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
214 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
215 CloudRegion cloudRegion = gBBInput.getCloudRegion();
216 aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion);
217 aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion);
218 aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup,cloudRegion);
219 } catch (Exception ex) {
220 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
224 public void createVfModule(BuildingBlockExecution execution) {
226 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
227 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
228 aaiVfModuleResources.createVfModule(vfModule, vnf);
229 } catch (Exception ex) {
230 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
235 * BPMN access method to establish relationships in AAI
239 public void connectVfModuleToVolumeGroup(BuildingBlockExecution execution) {
241 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
242 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
243 VolumeGroup volumeGroup = null;
245 volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
246 } catch (BBObjectNotFoundException e){
247 msoLogger.info("VolumeGroup not found. Skipping Connect between VfModule and VolumeGroup");
249 if (volumeGroup != null) {
250 aaiVfModuleResources.connectVfModuleToVolumeGroup(vnf, vfModule, volumeGroup, execution.getGeneralBuildingBlock().getCloudRegion());
252 } catch (Exception ex) {
253 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
258 * BPMN access method to execute Create L3Network operation (PUT )in AAI
262 public void createNetwork(BuildingBlockExecution execution) {
264 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
265 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
266 //set default to false. ToBe updated by SDNC
267 l3network.setIsBoundToVpn(false);
268 //define is bound to vpn flag as true if NEUTRON_NETWORK_TYPE is PROVIDER
269 if (l3network.getModelInfoNetwork().getNeutronNetworkType().equalsIgnoreCase(networkTypeProvider))
270 l3network.setIsBoundToVpn(true);
271 //put network shell in AAI
272 aaiNetworkResources.createNetworkConnectToServiceInstance(l3network, serviceInstance);
273 } catch (Exception ex) {
274 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
277 public void createCustomer(BuildingBlockExecution execution) throws Exception {
279 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
281 aaiVpnBindingResources.createCustomer(customer);
282 } catch(Exception ex) {
283 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
288 * BPMN access method to execute NetworkCollection operation (PUT) in AAI
292 public void createNetworkCollection(BuildingBlockExecution execution) {
294 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
295 Collection networkCollection = serviceInstance.getCollection();
296 //pass name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
298 networkCollection.setName(execution.getVariable(NETWORK_COLLECTION_NAME));
299 aaiNetworkResources.createNetworkCollection(networkCollection);
300 } catch (Exception ex) {
301 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
306 * BPMN access method to execute NetworkCollectionInstanceGroup operation (PUT) in AAI
310 public void createNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
312 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
313 InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup();
314 //set name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
315 instanceGroup.setInstanceGroupName(execution.getVariable(NETWORK_COLLECTION_NAME));
317 aaiNetworkResources.createNetworkInstanceGroup(instanceGroup);
318 } catch (Exception ex) {
319 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
325 * BPMN access method to establish relationships in AAI
329 public void connectNetworkToTenant(BuildingBlockExecution execution) {
331 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
332 aaiNetworkResources.connectNetworkToTenant(l3network, execution.getGeneralBuildingBlock().getCloudRegion());
333 } catch (Exception ex) {
334 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
339 * BPMN access method to establish relationships in AAI
343 public void connectNetworkToCloudRegion(BuildingBlockExecution execution) {
345 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
346 aaiNetworkResources.connectNetworkToCloudRegion(l3network, execution.getGeneralBuildingBlock().getCloudRegion());
347 } catch (Exception ex) {
348 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
353 * BPMN access method to establish relationships in AAI
357 public void connectNetworkToNetworkCollectionServiceInstance(BuildingBlockExecution execution) {
359 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
360 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
361 aaiNetworkResources.connectNetworkToNetworkCollectionServiceInstance(l3network, serviceInstance);
362 } catch (Exception ex) {
363 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
368 * BPMN access method to establish relationships in AAI
372 public void connectNetworkToNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
374 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
375 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
376 //connect network only if Instance Group / Collection objects exist
377 if (serviceInstance.getCollection() != null && serviceInstance.getCollection().getInstanceGroup() != null)
378 aaiNetworkResources.connectNetworkToNetworkCollectionInstanceGroup(l3network, serviceInstance.getCollection().getInstanceGroup());
379 } catch (Exception ex) {
380 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
384 public void createConfiguration(BuildingBlockExecution execution){
386 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID, execution.getLookupMap().get(ResourceKey.CONFIGURATION_ID));
387 aaiConfigurationResources.createConfiguration(configuration);
388 } catch (Exception ex) {
389 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);