2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Modifications Copyright (c) 2020 Nokia
10 * ================================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 * ============LICENSE_END=========================================================
25 package org.onap.so.bpmn.infrastructure.aai.tasks;
27 import java.util.Arrays;
28 import java.util.List;
29 import java.util.Optional;
30 import java.util.TreeSet;
31 import java.util.UUID;
32 import java.util.stream.Collectors;
33 import java.util.stream.Stream;
34 import org.camunda.bpm.engine.delegate.BpmnError;
35 import org.onap.so.bpmn.common.BuildingBlockExecution;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
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.GeneralBuildingBlock;
53 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
54 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
55 import org.onap.aaiclient.client.aai.AAIObjectPlurals;
56 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri;
57 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
58 import org.onap.so.client.exception.BBObjectNotFoundException;
59 import org.onap.so.client.exception.ExceptionBuilder;
60 import org.onap.so.client.orchestration.AAIConfigurationResources;
61 import org.onap.so.client.orchestration.AAIInstanceGroupResources;
62 import org.onap.so.client.orchestration.AAINetworkResources;
63 import org.onap.so.client.orchestration.AAIPnfResources;
64 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
65 import org.onap.so.client.orchestration.AAIVfModuleResources;
66 import org.onap.so.client.orchestration.AAIVnfResources;
67 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
68 import org.onap.so.client.orchestration.AAIVpnBindingResources;
69 import org.onap.logging.filter.base.ErrorCode;
70 import org.onap.so.logger.LoggingAnchor;
71 import org.onap.so.logger.MessageEnum;
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
74 import org.springframework.beans.factory.annotation.Autowired;
75 import org.springframework.core.env.Environment;
76 import org.springframework.stereotype.Component;
77 import com.google.common.base.Strings;
80 public class AAICreateTasks {
82 private static final Logger logger = LoggerFactory.getLogger(AAICreateTasks.class);
83 private static final String networkTypeProvider = "PROVIDER";
84 private static String NETWORK_COLLECTION_NAME = "networkCollectionName";
85 private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList";
86 private static String HEAT_STACK_ID = "heatStackId";
87 private static String NETWORK_POLICY_FQDN_PARAM = "network-policy-fqdn";
89 private AAIServiceInstanceResources aaiSIResources;
91 private AAIVnfResources aaiVnfResources;
93 private AAIPnfResources aaiPnfResources;
95 private ExceptionBuilder exceptionUtil;
97 private ExtractPojosForBB extractPojosForBB;
99 private AAIVolumeGroupResources aaiVolumeGroupResources;
101 private AAIVfModuleResources aaiVfModuleResources;
103 private AAINetworkResources aaiNetworkResources;
105 private AAIVpnBindingResources aaiVpnBindingResources;
107 private AAIConfigurationResources aaiConfigurationResources;
109 private AAIInstanceGroupResources aaiInstanceGroupResources;
111 private Environment env;
114 * This method is used for creating the service instance in A&AI.
116 * It will check the alaCarte and create the service instance in A&AI.
121 public void createServiceInstance(BuildingBlockExecution execution) {
123 ServiceInstance serviceInstance =
124 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
125 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
126 aaiSIResources.createServiceInstance(serviceInstance, customer);
127 } catch (Exception ex) {
128 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
133 * This method is used for creating and subscribing the service in A&AI.
138 public void createServiceSubscription(BuildingBlockExecution execution) {
140 ServiceInstance serviceInstance =
141 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
142 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
143 if (null == customer) {
144 String errorMessage =
145 "Exception in creating ServiceSubscription. Customer not present for ServiceInstanceID: "
146 + serviceInstance.getServiceInstanceId();
147 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), errorMessage,
148 "BPMN", ErrorCode.UnknownError.getValue(), errorMessage);
149 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, errorMessage);
151 aaiSIResources.createServiceSubscription(customer);
152 } catch (BpmnError ex) {
154 } catch (Exception ex) {
155 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
160 * This method is used for creation of the project A&AI.
165 public void createProject(BuildingBlockExecution execution) {
167 ServiceInstance serviceInstance =
168 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
169 Project project = serviceInstance.getProject();
170 if (project != null) {
171 if (project.getProjectName() == null || "".equals(project.getProjectName())) {
172 logger.info("ProjectName is null in input. Skipping create project...");
174 aaiSIResources.createProjectandConnectServiceInstance(project, serviceInstance);
177 } catch (Exception ex) {
178 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
183 * This method is used for creating OwningEntity A&AI.
188 public void createOwningEntity(BuildingBlockExecution execution) {
190 ServiceInstance serviceInstance =
191 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
192 OwningEntity owningEntity = serviceInstance.getOwningEntity();
193 if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId())
194 && Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
195 String msg = "Exception in AAICreateOwningEntity. OwningEntityId and Name are null.";
196 execution.setVariable("ErrorCreateOEAAI", msg);
197 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
198 } else if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId())
199 && !Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
200 if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) {
201 org.onap.aai.domain.yang.OwningEntity aaiEntity =
202 aaiSIResources.getOwningEntityByName(owningEntity.getOwningEntityName());
203 owningEntity.setOwningEntityId(aaiEntity.getOwningEntityId());
204 owningEntity.setOwningEntityName(owningEntity.getOwningEntityName());
205 aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
207 owningEntity.setOwningEntityId(UUID.randomUUID().toString());
208 aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
211 if (aaiSIResources.existsOwningEntity(owningEntity)) {
212 aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
214 if (Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
216 "Exception in AAICreateOwningEntity. Can't create an owningEntity with no owningEntityName.";
217 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
218 ErrorCode.UnknownError.getValue(), msg);
219 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
221 if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) {
223 "Exception in AAICreateOwningEntity. Can't create OwningEntity as name already exists in AAI associated with a different owning-entity-id (name must be unique)";
224 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg,
225 "BPMN", ErrorCode.UnknownError.getValue(), msg);
226 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
228 aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
233 } catch (Exception ex) {
234 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
239 * This method is used for creating Vnf in A&AI.
241 * It will check if the Vnf Name is exits in A&AI then it will throw the duplicate name exception.
243 * Otherwise it will create the vnf amd connect to the serviceinstance.
248 public void createVnf(BuildingBlockExecution execution) {
250 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
251 ServiceInstance serviceInstance =
252 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
253 execution.setVariable("homing", Boolean.TRUE.equals(vnf.isCallHoming()));
254 aaiVnfResources.createVnfandConnectServiceInstance(vnf, serviceInstance);
255 } catch (Exception ex) {
256 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
260 public void createPnf(BuildingBlockExecution execution) {
262 Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF);
263 ServiceInstance serviceInstance =
264 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
265 aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance);
266 } catch (BBObjectNotFoundException e) {
267 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
272 * This method is used for separating (,) from the string.
277 public void createPlatformForNetwork(BuildingBlockExecution execution) {
279 L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
280 if (network != null) {
281 createPlatformNetwork(network);
283 } catch (Exception ex) {
284 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
289 * This method is used for separating (,) from the string.
294 public void createPlatform(BuildingBlockExecution execution) {
296 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
298 createPlatformVnf(vnf);
300 } catch (Exception ex) {
301 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
306 protected void createPlatformVnf(GenericVnf vnf) {
307 Platform platform = vnf.getPlatform();
308 if (Strings.isNullOrEmpty(platform.getPlatformName())) {
309 logger.debug("PlatformName is null in input. Skipping create platform...");
311 List<String> platforms = splitCDL(platform.getPlatformName());
312 platforms.stream().forEach(
313 platformName -> aaiVnfResources.createPlatformandConnectVnf(new Platform(platformName), vnf));
317 protected void createPlatformNetwork(L3Network network) {
318 Platform platform = network.getPlatform();
319 if (platform != null) {
320 if (Strings.isNullOrEmpty(platform.getPlatformName())) {
321 logger.debug("PlatformName is null in input. Skipping create platform...");
323 List<String> platforms = splitCDL(platform.getPlatformName());
324 platforms.stream().forEach(platformName -> aaiNetworkResources
325 .createPlatformAndConnectNetwork(new Platform(platformName), network));
331 * This method is used for separating (,) from the string.
336 public List<String> splitCDL(String str) {
337 return Stream.of(str.split(",")).map(String::trim).map(elem -> new String(elem)).collect(Collectors.toList());
341 * This method is used for creating the type of business in A&AI.
346 public void createLineOfBusiness(BuildingBlockExecution execution) {
348 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
350 createLineOfBusinessVnf(vnf);
352 } catch (Exception ex) {
353 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
357 public void createLineOfBusinessForNetwork(BuildingBlockExecution execution) {
359 L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
360 if (network != null) {
361 createLineOfBusinessNetwork(network);
363 } catch (Exception ex) {
364 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
368 protected void createLineOfBusinessVnf(GenericVnf vnf) {
369 LineOfBusiness lineOfBusiness = vnf.getLineOfBusiness();
370 if (lineOfBusiness != null) {
371 if (Strings.isNullOrEmpty(lineOfBusiness.getLineOfBusinessName())) {
372 logger.info("lineOfBusiness is null in input. Skipping create lineOfBusiness...");
374 List<String> lineOfBussinesses = splitCDL(lineOfBusiness.getLineOfBusinessName());
375 lineOfBussinesses.stream().forEach(
376 lobName -> aaiVnfResources.createLineOfBusinessandConnectVnf(new LineOfBusiness(lobName), vnf));
381 protected void createLineOfBusinessNetwork(L3Network network) {
382 LineOfBusiness lineOfBusiness = network.getLineOfBusiness();
383 if (lineOfBusiness != null) {
384 if (Strings.isNullOrEmpty(lineOfBusiness.getLineOfBusinessName())) {
385 logger.info("lineOfBusiness is null in input. Skipping create lineOfBusiness...");
387 List<String> lineOfBussinesses = splitCDL(lineOfBusiness.getLineOfBusinessName());
388 lineOfBussinesses.stream().forEach(lobName -> aaiNetworkResources
389 .createLineOfBusinessAndConnectNetwork(new LineOfBusiness(lobName), network));
395 * This method is used for creating the volume group in A&AI.
400 public void createVolumeGroup(BuildingBlockExecution execution) {
402 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
404 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
405 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
406 CloudRegion cloudRegion = gBBInput.getCloudRegion();
407 aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion);
408 aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion);
409 aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup, cloudRegion);
410 } catch (Exception ex) {
411 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
416 * This method is used for creating the vfModule in A&AI.
421 public void createVfModule(BuildingBlockExecution execution) {
423 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
424 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
426 if (vfModule.getModelInfoVfModule() != null
427 && !Boolean.TRUE.equals(vfModule.getModelInfoVfModule().getIsBaseBoolean())) {
428 moduleIndex = this.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, vfModule);
430 vfModule.setModuleIndex(moduleIndex);
431 aaiVfModuleResources.createVfModule(vfModule, vnf);
432 } catch (Exception ex) {
433 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
438 * BPMN access method to establish relationships in AAI
443 public void connectVfModuleToVolumeGroup(BuildingBlockExecution execution) {
445 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
446 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
447 VolumeGroup volumeGroup = null;
449 volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
450 } catch (BBObjectNotFoundException e) {
451 logger.info("VolumeGroup not found. Skipping Connect between VfModule and VolumeGroup");
453 if (volumeGroup != null) {
454 logger.debug("Connecting VfModule to VolumGroup");
455 aaiVfModuleResources.connectVfModuleToVolumeGroup(vnf, vfModule, volumeGroup,
456 execution.getGeneralBuildingBlock().getCloudRegion());
458 } catch (Exception ex) {
459 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
464 * BPMN access method to execute Create L3Network operation (PUT )in AAI
469 public void createNetwork(BuildingBlockExecution execution) {
471 ServiceInstance serviceInstance =
472 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
473 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
474 // set default to false. ToBe updated by SDNC
475 l3network.setIsBoundToVpn(false);
476 // define is bound to vpn flag as true if NEUTRON_NETWORK_TYPE is PROVIDER
477 if (l3network.getModelInfoNetwork().getNeutronNetworkType().equalsIgnoreCase(networkTypeProvider))
478 l3network.setIsBoundToVpn(true);
479 // put network shell in AAI
480 aaiNetworkResources.createNetworkConnectToServiceInstance(l3network, serviceInstance);
481 } catch (Exception ex) {
482 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
487 * This method is used for creating the customer in A&AI.
492 public void createCustomer(BuildingBlockExecution execution) throws Exception {
494 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
496 aaiVpnBindingResources.createCustomer(customer);
497 } catch (Exception ex) {
498 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
503 * BPMN access method to execute NetworkCollection operation (PUT) in AAI
508 public void createNetworkCollection(BuildingBlockExecution execution) {
510 ServiceInstance serviceInstance =
511 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
512 Collection networkCollection = serviceInstance.getCollection();
513 // pass name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
515 networkCollection.setName(execution.getVariable(NETWORK_COLLECTION_NAME));
516 aaiNetworkResources.createNetworkCollection(networkCollection);
517 } catch (Exception ex) {
518 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
523 * BPMN access method to execute NetworkCollectionInstanceGroup operation (PUT) in AAI
528 public void createNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
530 ServiceInstance serviceInstance =
531 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
532 InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup();
533 // set name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
534 instanceGroup.setInstanceGroupName(execution.getVariable(NETWORK_COLLECTION_NAME));
536 aaiNetworkResources.createNetworkInstanceGroup(instanceGroup);
537 } catch (Exception ex) {
538 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
544 * BPMN access method to establish relationships in AAI
549 public void connectNetworkToTenant(BuildingBlockExecution execution) {
551 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
552 aaiNetworkResources.connectNetworkToTenant(l3network, execution.getGeneralBuildingBlock().getCloudRegion());
553 } catch (Exception ex) {
554 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
559 * BPMN access method to establish relationships in AAI
564 public void connectNetworkToCloudRegion(BuildingBlockExecution execution) {
566 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
567 aaiNetworkResources.connectNetworkToCloudRegion(l3network,
568 execution.getGeneralBuildingBlock().getCloudRegion());
569 } catch (Exception ex) {
570 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
575 * BPMN access method to establish relationships in AAI
580 public void connectVnfToCloudRegion(BuildingBlockExecution execution) {
582 boolean cloudRegionsToSkip = false;
583 String[] cloudRegions = env.getProperty("mso.bpmn.cloudRegionIdsToSkipAddingVnfEdgesTo", String[].class);
584 if (cloudRegions != null) {
585 cloudRegionsToSkip = Arrays.stream(cloudRegions)
586 .anyMatch(execution.getGeneralBuildingBlock().getCloudRegion().getLcpCloudRegionId()::equals);
588 if (!cloudRegionsToSkip) {
589 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
590 aaiVnfResources.connectVnfToCloudRegion(vnf, execution.getGeneralBuildingBlock().getCloudRegion());
592 } catch (Exception ex) {
593 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
598 * BPMN access method to establish relationships in AAI
603 public void connectVnfToTenant(BuildingBlockExecution execution) {
605 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
606 aaiVnfResources.connectVnfToTenant(vnf, execution.getGeneralBuildingBlock().getCloudRegion());
607 } catch (Exception ex) {
608 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
613 * BPMN access method to establish relationships in AAI
618 public void connectNetworkToNetworkCollectionServiceInstance(BuildingBlockExecution execution) {
620 ServiceInstance serviceInstance =
621 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
622 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
623 aaiNetworkResources.connectNetworkToNetworkCollectionServiceInstance(l3network, serviceInstance);
624 } catch (Exception ex) {
625 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
630 * BPMN access method to establish relationships in AAI
635 public void connectNetworkToNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
637 ServiceInstance serviceInstance =
638 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
639 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
640 // connect network only if Instance Group / Collection objects exist
641 if (serviceInstance.getCollection() != null && serviceInstance.getCollection().getInstanceGroup() != null)
642 aaiNetworkResources.connectNetworkToNetworkCollectionInstanceGroup(l3network,
643 serviceInstance.getCollection().getInstanceGroup());
644 } catch (Exception ex) {
645 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
650 * This method is used for configuring the service in A&AI.
652 * @param execution @throws
654 public void createConfiguration(BuildingBlockExecution execution) {
656 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
657 aaiConfigurationResources.createConfiguration(configuration);
658 } catch (Exception ex) {
659 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
664 * This method is used for creating vnf instance group in A&AI.
666 * @param execution @throws
668 public void createInstanceGroupVnf(BuildingBlockExecution execution) {
670 ServiceInstance serviceInstance =
671 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
672 InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
673 aaiInstanceGroupResources.createInstanceGroupandConnectServiceInstance(instanceGroup, serviceInstance);
674 } catch (Exception ex) {
675 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
680 * This method is used to put the network policy in A&AI.
682 * @param execution @throws
684 public void createNetworkPolicies(BuildingBlockExecution execution) {
686 String fqdns = execution.getVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST);
687 if (fqdns != null && !fqdns.isEmpty()) {
688 String fqdnList[] = fqdns.split(",");
689 int fqdnCount = fqdnList.length;
691 for (int i = 0; i < fqdnCount; i++) {
692 String fqdn = fqdnList[i];
693 AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY);
694 uri.queryParam(NETWORK_POLICY_FQDN_PARAM, fqdn);
695 Optional<org.onap.aai.domain.yang.NetworkPolicy> oNetPolicy =
696 aaiNetworkResources.getNetworkPolicy(uri);
697 if (!oNetPolicy.isPresent()) {
698 logger.debug("This network policy FQDN is not in AAI yet: {}", fqdn);
699 String networkPolicyId = UUID.randomUUID().toString();
700 logger.debug("Adding network-policy with network-policy-id {}", networkPolicyId);
701 NetworkPolicy networkPolicy = new NetworkPolicy();
702 networkPolicy.setNetworkPolicyId(networkPolicyId);
703 networkPolicy.setNetworkPolicyFqdn(fqdn);
704 networkPolicy.setHeatStackId(execution.getVariable(HEAT_STACK_ID));
706 aaiNetworkResources.createNetworkPolicy(networkPolicy);
711 } catch (Exception ex) {
712 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
717 * Groups existing vf modules by the model uuid of our new vf module and returns the lowest unused index
719 * if we have a module type A, and there are 3 instances of those, and then module type B has 2 instances, if we are
720 * adding a new module type A, the vf-module-index should be 3 assuming contiguous indices (not 5, or 2)
723 protected int getLowestUnusedVfModuleIndexFromAAIVnfResponse(GenericVnf genericVnf, VfModule newVfModule) {
725 String newVfModuleModelInvariantUUID = null;
726 if (newVfModule.getModelInfoVfModule() != null) {
727 newVfModuleModelInvariantUUID = newVfModule.getModelInfoVfModule().getModelInvariantUUID();
731 if (genericVnf != null && genericVnf.getVfModules() != null && !genericVnf.getVfModules().isEmpty()) {
732 List<VfModule> modules = genericVnf.getVfModules().stream()
733 .filter(item -> !item.getVfModuleId().equals(newVfModule.getVfModuleId()))
734 .collect(Collectors.toList());
735 TreeSet<Integer> moduleIndices = new TreeSet<>();
736 int nullIndexFound = 0;
737 for (VfModule vfModule : modules) {
738 if (vfModule.getModelInfoVfModule() != null) {
739 if (vfModule.getModelInfoVfModule().getModelInvariantUUID().equals(newVfModuleModelInvariantUUID)) {
740 if (vfModule.getModuleIndex() != null) {
741 moduleIndices.add(vfModule.getModuleIndex());
744 logger.warn("Found null index for vf-module-id {} and model-invariant-uuid {}",
745 vfModule.getVfModuleId(), vfModule.getModelInfoVfModule().getModelInvariantUUID());
751 return calculateUnusedIndex(moduleIndices, nullIndexFound);
757 protected int calculateUnusedIndex(TreeSet<Integer> moduleIndices, int nullIndexFound) {
758 // pad array with nulls
759 Integer[] temp = new Integer[moduleIndices.size() + nullIndexFound];
760 Integer[] array = moduleIndices.toArray(temp);
762 // when a null is found skip that potential value
763 // effectively creates something like, [0,1,3,null,null] -> [0,1,null(2),3,null(4)]
764 for (int i = 0; i < array.length; i++, result++) {
765 if (Integer.valueOf(result) != array[i]) {
766 if (nullIndexFound > 0) {