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.Customer;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
38 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
39 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
40 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
41 import org.onap.so.client.exception.BBObjectNotFoundException;
42 import org.onap.so.client.exception.ExceptionBuilder;
43 import org.onap.so.client.orchestration.AAINetworkResources;
44 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
45 import org.onap.so.client.orchestration.AAIVfModuleResources;
46 import org.onap.so.client.orchestration.AAIVnfResources;
47 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
48 import org.onap.so.client.orchestration.AAIVpnBindingResources;
49 import org.onap.so.db.catalog.beans.OrchestrationStatus;
50 import org.onap.so.logger.MessageEnum;
51 import org.onap.so.logger.MsoLogger;
52 import org.springframework.beans.factory.annotation.Autowired;
53 import org.springframework.stereotype.Component;
56 public class AAICreateTasks {
58 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAICreateTasks.class);
59 private static final String networkTypeProvider = "PROVIDER";
60 private static String NETWORK_COLLECTION_NAME = "networkCollectionName";
62 private AAIServiceInstanceResources aaiSIResources;
64 private AAIVnfResources aaiVnfResources;
66 private ExceptionBuilder exceptionUtil;
68 private ExtractPojosForBB extractPojosForBB;
70 private AAIVolumeGroupResources aaiVolumeGroupResources;
72 private AAIVfModuleResources aaiVfModuleResources;
74 private AAINetworkResources aaiNetworkResources;
76 private AAIVpnBindingResources aaiVpnBindingResources;
78 public void createServiceInstance(BuildingBlockExecution execution) {
80 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
81 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
82 aaiSIResources.createServiceInstance(serviceInstance, customer);
83 } catch (Exception ex) {
84 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
88 public void createServiceSubscription(BuildingBlockExecution execution){
90 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution,
91 ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
92 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
93 if (null == customer) {
94 String errorMessage = "Exception in creating ServiceSubscription. Customer not present for ServiceInstanceID: "
95 + serviceInstance.getServiceInstanceId();
96 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, errorMessage, "BPMN", MsoLogger.getServiceName(),
97 MsoLogger.ErrorCode.UnknownError, errorMessage);
98 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, errorMessage);
100 aaiSIResources.createServiceSubscription(customer);
101 } catch (BpmnError ex) {
104 catch (Exception ex) {
105 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
109 public void createProject(BuildingBlockExecution execution) {
111 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
112 Project project = serviceInstance.getProject();
113 if(project != null) {
114 if (project.getProjectName() == null || "".equals(project.getProjectName())) {
115 msoLogger.info("ProjectName is null in input. Skipping create project...");
117 aaiSIResources.createProjectandConnectServiceInstance(project, serviceInstance);
120 } catch (Exception ex) {
121 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
125 public void createOwningEntity(BuildingBlockExecution execution) {
127 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
128 OwningEntity owningEntity = serviceInstance.getOwningEntity();
129 String owningEntityId = owningEntity.getOwningEntityId();
130 String owningEntityName = owningEntity.getOwningEntityName();
131 if (owningEntityId == null || "".equals(owningEntityId)) {
132 String msg = "Exception in AAICreateOwningEntity. OwningEntityId is null.";
133 execution.setVariable("ErrorCreateOEAAI", msg);
134 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
136 if (aaiSIResources.existsOwningEntity(owningEntity)) {
137 aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
139 if (owningEntityName == null || "".equals(owningEntityName)) {
140 String msg = "Exception in AAICreateOwningEntity. Can't create an owningEntity with no owningEntityName.";
141 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(),
142 MsoLogger.ErrorCode.UnknownError, msg);
143 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
145 if(aaiSIResources.existsOwningEntityName(owningEntityName)){
146 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)";
147 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(),
148 MsoLogger.ErrorCode.UnknownError, msg);
149 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
151 aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
156 } catch (Exception ex) {
157 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
161 public void createVnf(BuildingBlockExecution execution) {
163 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
164 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
165 execution.setVariable("callHoming", Boolean.TRUE.equals(vnf.isCallHoming()));
166 aaiVnfResources.createVnfandConnectServiceInstance(vnf, serviceInstance);
167 } catch (Exception ex) {
168 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
172 public void createPlatform(BuildingBlockExecution execution) {
174 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
175 Platform platform = vnf.getPlatform();
176 if(platform != null) {
177 if (platform.getPlatformName() == null || "".equals(platform.getPlatformName())) {
178 msoLogger.debug("PlatformName is null in input. Skipping create platform...");
180 aaiVnfResources.createPlatformandConnectVnf(platform,vnf);
183 } catch (Exception ex) {
184 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
189 public void createLineOfBusiness(BuildingBlockExecution execution) {
191 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
192 LineOfBusiness lineOfBusiness = vnf.getLineOfBusiness();
193 if(lineOfBusiness != null) {
194 if (lineOfBusiness.getLineOfBusinessName() == null || "".equals(lineOfBusiness.getLineOfBusinessName())) {
195 msoLogger.info("lineOfBusiness is null in input. Skipping create lineOfBusiness...");
197 aaiVnfResources.createLineOfBusinessandConnectVnf(lineOfBusiness,vnf);
200 } catch (Exception ex) {
201 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
205 public void createVolumeGroup(BuildingBlockExecution execution) {
207 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
209 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
210 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
211 CloudRegion cloudRegion = gBBInput.getCloudRegion();
212 aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion);
213 aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion);
214 aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup,cloudRegion);
215 } catch (Exception ex) {
216 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
220 public void createVfModule(BuildingBlockExecution execution) {
222 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
223 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
224 aaiVfModuleResources.createVfModule(vfModule, vnf);
225 } catch (Exception ex) {
226 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
231 * BPMN access method to establish relationships in AAI
235 public void connectVfModuleToVolumeGroup(BuildingBlockExecution execution) {
237 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
238 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
239 VolumeGroup volumeGroup = null;
241 volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
242 } catch (BBObjectNotFoundException e){
243 msoLogger.info("VolumeGroup not found. Skipping Connect between VfModule and VolumeGroup");
245 if (volumeGroup != null) {
246 aaiVfModuleResources.connectVfModuleToVolumeGroup(vnf, vfModule, volumeGroup, execution.getGeneralBuildingBlock().getCloudRegion());
248 } catch (Exception ex) {
249 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
254 * BPMN access method to execute Create L3Network operation (PUT )in AAI
258 public void createNetwork(BuildingBlockExecution execution) {
260 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
261 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
262 //set default to false. ToBe updated by SDNC
263 l3network.setIsBoundToVpn(false);
264 //define is bound to vpn flag as true if NEUTRON_NETWORK_TYPE is PROVIDER
265 if (l3network.getModelInfoNetwork().getNeutronNetworkType().equalsIgnoreCase(networkTypeProvider))
266 l3network.setIsBoundToVpn(true);
267 //put network shell in AAI
268 aaiNetworkResources.createNetworkConnectToServiceInstance(l3network, serviceInstance);
269 } catch (Exception ex) {
270 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
273 public void createCustomer(BuildingBlockExecution execution) throws Exception {
275 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
277 aaiVpnBindingResources.createCustomer(customer);
278 } catch(Exception ex) {
279 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
284 * BPMN access method to execute NetworkCollection operation (PUT) in AAI
288 public void createNetworkCollection(BuildingBlockExecution execution) {
290 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
291 Collection networkCollection = serviceInstance.getCollection();
292 //pass name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
294 networkCollection.setName(execution.getVariable(NETWORK_COLLECTION_NAME));
295 aaiNetworkResources.createNetworkCollection(networkCollection);
296 } catch (Exception ex) {
297 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
302 * BPMN access method to execute NetworkCollectionInstanceGroup operation (PUT) in AAI
306 public void createNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
308 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
309 InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup();
310 //set name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
311 instanceGroup.setInstanceGroupName(execution.getVariable(NETWORK_COLLECTION_NAME));
313 aaiNetworkResources.createNetworkInstanceGroup(instanceGroup);
314 } catch (Exception ex) {
315 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
321 * BPMN access method to establish relationships in AAI
325 public void connectNetworkToTenant(BuildingBlockExecution execution) {
327 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
328 aaiNetworkResources.connectNetworkToTenant(l3network, execution.getGeneralBuildingBlock().getCloudRegion());
329 } catch (Exception ex) {
330 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
335 * BPMN access method to establish relationships in AAI
339 public void connectNetworkToCloudRegion(BuildingBlockExecution execution) {
341 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
342 aaiNetworkResources.connectNetworkToCloudRegion(l3network, execution.getGeneralBuildingBlock().getCloudRegion());
343 } catch (Exception ex) {
344 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
349 * BPMN access method to establish relationships in AAI
353 public void connectNetworkToNetworkCollectionServiceInstance(BuildingBlockExecution execution) {
355 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
356 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
357 aaiNetworkResources.connectNetworkToNetworkCollectionServiceInstance(l3network, serviceInstance);
358 } catch (Exception ex) {
359 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
364 * BPMN access method to establish relationships in AAI
368 public void connectNetworkToNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
370 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
371 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
372 //connect network only if Instance Group / Collection objects exist
373 if (serviceInstance.getCollection() != null && serviceInstance.getCollection().getInstanceGroup() != null)
374 aaiNetworkResources.connectNetworkToNetworkCollectionInstanceGroup(l3network, serviceInstance.getCollection().getInstanceGroup());
375 } catch (Exception ex) {
376 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);