2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.aai.tasks;
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Optional;
28 import java.util.TreeSet;
29 import java.util.UUID;
30 import java.util.stream.Collectors;
31 import java.util.stream.Stream;
32 import org.onap.so.logger.LoggingAnchor;
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.onap.so.bpmn.common.BuildingBlockExecution;
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.ServiceInstance;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
50 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
51 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
52 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
53 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException;
54 import org.onap.so.client.aai.AAIObjectPlurals;
55 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
56 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
57 import org.onap.so.client.exception.BBObjectNotFoundException;
58 import org.onap.so.client.exception.ExceptionBuilder;
59 import org.onap.so.client.orchestration.AAIConfigurationResources;
60 import org.onap.so.client.orchestration.AAIInstanceGroupResources;
61 import org.onap.so.client.orchestration.AAINetworkResources;
62 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
63 import org.onap.so.client.orchestration.AAIVfModuleResources;
64 import org.onap.so.client.orchestration.AAIVnfResources;
65 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
66 import org.onap.so.client.orchestration.AAIVpnBindingResources;
67 import org.onap.so.logger.ErrorCode;
68 import org.onap.so.logger.MessageEnum;
69 import org.slf4j.Logger;
70 import org.slf4j.LoggerFactory;
71 import org.springframework.beans.factory.annotation.Autowired;
72 import org.springframework.core.env.Environment;
73 import org.springframework.stereotype.Component;
76 public class AAICreateTasks {
78 private static final Logger logger = LoggerFactory.getLogger(AAICreateTasks.class);
79 private static final String networkTypeProvider = "PROVIDER";
80 private static String NETWORK_COLLECTION_NAME = "networkCollectionName";
81 private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList";
82 private static String HEAT_STACK_ID = "heatStackId";
83 private static String NETWORK_POLICY_FQDN_PARAM = "network-policy-fqdn";
85 private AAIServiceInstanceResources aaiSIResources;
87 private AAIVnfResources aaiVnfResources;
89 private ExceptionBuilder exceptionUtil;
91 private ExtractPojosForBB extractPojosForBB;
93 private AAIVolumeGroupResources aaiVolumeGroupResources;
95 private AAIVfModuleResources aaiVfModuleResources;
97 private AAINetworkResources aaiNetworkResources;
99 private AAIVpnBindingResources aaiVpnBindingResources;
101 private AAIConfigurationResources aaiConfigurationResources;
103 private AAIInstanceGroupResources aaiInstanceGroupResources;
105 private Environment env;
108 * This method is used for creating the service instance in A&AI.
110 * It will check the alaCarte and create the service instance in A&AI.
115 public void createServiceInstance(BuildingBlockExecution execution) {
117 ServiceInstance serviceInstance =
118 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
119 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
120 aaiSIResources.createServiceInstance(serviceInstance, customer);
121 } catch (Exception ex) {
122 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
127 * This method is used for creating and subscribing the service in A&AI.
132 public void createServiceSubscription(BuildingBlockExecution execution) {
134 ServiceInstance serviceInstance =
135 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
136 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
137 if (null == customer) {
138 String errorMessage =
139 "Exception in creating ServiceSubscription. Customer not present for ServiceInstanceID: "
140 + serviceInstance.getServiceInstanceId();
141 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), errorMessage,
142 "BPMN", ErrorCode.UnknownError.getValue(), errorMessage);
143 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, errorMessage);
145 aaiSIResources.createServiceSubscription(customer);
146 } catch (BpmnError ex) {
148 } catch (Exception ex) {
149 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
154 * This method is used for creation of the project A&AI.
159 public void createProject(BuildingBlockExecution execution) {
161 ServiceInstance serviceInstance =
162 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
163 Project project = serviceInstance.getProject();
164 if (project != null) {
165 if (project.getProjectName() == null || "".equals(project.getProjectName())) {
166 logger.info("ProjectName is null in input. Skipping create project...");
168 aaiSIResources.createProjectandConnectServiceInstance(project, serviceInstance);
171 } catch (Exception ex) {
172 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
177 * This method is used for creating OwningEntity A&AI.
182 public void createOwningEntity(BuildingBlockExecution execution) {
184 ServiceInstance serviceInstance =
185 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
186 OwningEntity owningEntity = serviceInstance.getOwningEntity();
187 String owningEntityId = owningEntity.getOwningEntityId();
188 String owningEntityName = owningEntity.getOwningEntityName();
189 if (owningEntityId == null || "".equals(owningEntityId)) {
190 String msg = "Exception in AAICreateOwningEntity. OwningEntityId is null.";
191 execution.setVariable("ErrorCreateOEAAI", msg);
192 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
194 if (aaiSIResources.existsOwningEntity(owningEntity)) {
195 aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
197 if (owningEntityName == null || "".equals(owningEntityName)) {
199 "Exception in AAICreateOwningEntity. Can't create an owningEntity with no owningEntityName.";
200 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
201 ErrorCode.UnknownError.getValue(), msg);
202 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
204 if (aaiSIResources.existsOwningEntityName(owningEntityName)) {
206 "Exception in AAICreateOwningEntity. Can't create OwningEntity as name already exists in AAI associated with a different owning-entity-id (name must be unique)";
207 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg,
208 "BPMN", ErrorCode.UnknownError.getValue(), msg);
209 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
211 aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
216 } catch (Exception ex) {
217 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
222 * This method is used for creating Vnf in A&AI.
224 * It will check if the Vnf Name is exits in A&AI then it will throw the duplicate name exception.
226 * Otherwise it will create the vnf amd connect to the serviceinstance.
231 public void createVnf(BuildingBlockExecution execution) {
233 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
234 ServiceInstance serviceInstance =
235 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
236 execution.setVariable("homing", Boolean.TRUE.equals(vnf.isCallHoming()));
237 aaiVnfResources.createVnfandConnectServiceInstance(vnf, serviceInstance);
238 } catch (Exception ex) {
239 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
244 * This method is used for separating (,) from the string.
249 public void createPlatform(BuildingBlockExecution execution) {
251 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
252 Platform platform = vnf.getPlatform();
253 if (platform != null) {
254 if (platform.getPlatformName() == null || "".equals(platform.getPlatformName())) {
255 logger.debug("PlatformName is null in input. Skipping create platform...");
257 List<String> platforms = splitCDL(platform.getPlatformName());
258 platforms.stream().forEach(platformName -> aaiVnfResources
259 .createPlatformandConnectVnf(new Platform(platformName), vnf));
262 } catch (Exception ex) {
263 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
269 * This method is used for separating (,) from the string.
274 public List<String> splitCDL(String str) {
275 return Stream.of(str.split(",")).map(String::trim).map(elem -> new String(elem)).collect(Collectors.toList());
279 * This method is used for creating the type of business in A&AI.
284 public void createLineOfBusiness(BuildingBlockExecution execution) {
286 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
287 LineOfBusiness lineOfBusiness = vnf.getLineOfBusiness();
288 if (lineOfBusiness != null) {
289 if (lineOfBusiness.getLineOfBusinessName() == null
290 || "".equals(lineOfBusiness.getLineOfBusinessName())) {
291 logger.info("lineOfBusiness is null in input. Skipping create lineOfBusiness...");
293 List<String> lineOfBussinesses = splitCDL(lineOfBusiness.getLineOfBusinessName());
294 lineOfBussinesses.stream().forEach(lobName -> aaiVnfResources
295 .createLineOfBusinessandConnectVnf(new LineOfBusiness(lobName), vnf));
298 } catch (Exception ex) {
299 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
304 * This method is used for creating the volume group in A&AI.
309 public void createVolumeGroup(BuildingBlockExecution execution) {
311 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
313 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
314 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
315 CloudRegion cloudRegion = gBBInput.getCloudRegion();
316 aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion);
317 aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion);
318 aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup, cloudRegion);
319 } catch (Exception ex) {
320 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
325 * This method is used for creating the vfModule in A&AI.
330 public void createVfModule(BuildingBlockExecution execution) {
332 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
333 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
335 if (vfModule.getModelInfoVfModule() != null
336 && !Boolean.TRUE.equals(vfModule.getModelInfoVfModule().getIsBaseBoolean())) {
337 moduleIndex = this.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, vfModule);
339 vfModule.setModuleIndex(moduleIndex);
340 aaiVfModuleResources.createVfModule(vfModule, vnf);
341 } catch (Exception ex) {
342 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
347 * BPMN access method to establish relationships in AAI
352 public void connectVfModuleToVolumeGroup(BuildingBlockExecution execution) {
354 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
355 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
356 VolumeGroup volumeGroup = null;
358 volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
359 } catch (BBObjectNotFoundException e) {
360 logger.info("VolumeGroup not found. Skipping Connect between VfModule and VolumeGroup");
362 if (volumeGroup != null) {
363 aaiVfModuleResources.connectVfModuleToVolumeGroup(vnf, vfModule, volumeGroup,
364 execution.getGeneralBuildingBlock().getCloudRegion());
366 } catch (Exception ex) {
367 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
372 * BPMN access method to execute Create L3Network operation (PUT )in AAI
377 public void createNetwork(BuildingBlockExecution execution) {
379 ServiceInstance serviceInstance =
380 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
381 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
382 // set default to false. ToBe updated by SDNC
383 l3network.setIsBoundToVpn(false);
384 // define is bound to vpn flag as true if NEUTRON_NETWORK_TYPE is PROVIDER
385 if (l3network.getModelInfoNetwork().getNeutronNetworkType().equalsIgnoreCase(networkTypeProvider))
386 l3network.setIsBoundToVpn(true);
387 // put network shell in AAI
388 aaiNetworkResources.createNetworkConnectToServiceInstance(l3network, serviceInstance);
389 } catch (Exception ex) {
390 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
395 * This method is used for creating the customer in A&AI.
400 public void createCustomer(BuildingBlockExecution execution) throws Exception {
402 Customer customer = execution.getGeneralBuildingBlock().getCustomer();
404 aaiVpnBindingResources.createCustomer(customer);
405 } catch (Exception ex) {
406 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
411 * BPMN access method to execute NetworkCollection operation (PUT) in AAI
416 public void createNetworkCollection(BuildingBlockExecution execution) {
418 ServiceInstance serviceInstance =
419 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
420 Collection networkCollection = serviceInstance.getCollection();
421 // pass name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
423 networkCollection.setName(execution.getVariable(NETWORK_COLLECTION_NAME));
424 aaiNetworkResources.createNetworkCollection(networkCollection);
425 } catch (Exception ex) {
426 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
431 * BPMN access method to execute NetworkCollectionInstanceGroup operation (PUT) in AAI
436 public void createNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
438 ServiceInstance serviceInstance =
439 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
440 InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup();
441 // set name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
442 instanceGroup.setInstanceGroupName(execution.getVariable(NETWORK_COLLECTION_NAME));
444 aaiNetworkResources.createNetworkInstanceGroup(instanceGroup);
445 } catch (Exception ex) {
446 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
452 * BPMN access method to establish relationships in AAI
457 public void connectNetworkToTenant(BuildingBlockExecution execution) {
459 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
460 aaiNetworkResources.connectNetworkToTenant(l3network, execution.getGeneralBuildingBlock().getCloudRegion());
461 } catch (Exception ex) {
462 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
467 * BPMN access method to establish relationships in AAI
472 public void connectNetworkToCloudRegion(BuildingBlockExecution execution) {
474 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
475 aaiNetworkResources.connectNetworkToCloudRegion(l3network,
476 execution.getGeneralBuildingBlock().getCloudRegion());
477 } catch (Exception ex) {
478 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
483 * BPMN access method to establish relationships in AAI
488 public void connectVnfToCloudRegion(BuildingBlockExecution execution) {
490 boolean cloudRegionsToSkip = false;
491 String[] cloudRegions = env.getProperty("mso.bpmn.cloudRegionIdsToSkipAddingVnfEdgesTo", String[].class);
492 if (cloudRegions != null) {
493 cloudRegionsToSkip = Arrays.stream(cloudRegions)
494 .anyMatch(execution.getGeneralBuildingBlock().getCloudRegion().getLcpCloudRegionId()::equals);
496 if (!cloudRegionsToSkip) {
497 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
498 aaiVnfResources.connectVnfToCloudRegion(vnf, execution.getGeneralBuildingBlock().getCloudRegion());
500 } catch (Exception ex) {
501 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
506 * BPMN access method to establish relationships in AAI
511 public void connectVnfToTenant(BuildingBlockExecution execution) {
513 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
514 aaiVnfResources.connectVnfToTenant(vnf, execution.getGeneralBuildingBlock().getCloudRegion());
515 } catch (Exception ex) {
516 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
521 * BPMN access method to establish relationships in AAI
526 public void connectNetworkToNetworkCollectionServiceInstance(BuildingBlockExecution execution) {
528 ServiceInstance serviceInstance =
529 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
530 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
531 aaiNetworkResources.connectNetworkToNetworkCollectionServiceInstance(l3network, serviceInstance);
532 } catch (Exception ex) {
533 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
538 * BPMN access method to establish relationships in AAI
543 public void connectNetworkToNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
545 ServiceInstance serviceInstance =
546 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
547 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
548 // connect network only if Instance Group / Collection objects exist
549 if (serviceInstance.getCollection() != null && serviceInstance.getCollection().getInstanceGroup() != null)
550 aaiNetworkResources.connectNetworkToNetworkCollectionInstanceGroup(l3network,
551 serviceInstance.getCollection().getInstanceGroup());
552 } catch (Exception ex) {
553 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
558 * This method is used for configuring the service in A&AI.
560 * @param execution @throws
562 public void createConfiguration(BuildingBlockExecution execution) {
564 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
565 aaiConfigurationResources.createConfiguration(configuration);
566 } catch (Exception ex) {
567 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
572 * This method is used for creating vnf instance group in A&AI.
574 * @param execution @throws
576 public void createInstanceGroupVnf(BuildingBlockExecution execution) {
578 ServiceInstance serviceInstance =
579 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
580 InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
581 aaiInstanceGroupResources.createInstanceGroupandConnectServiceInstance(instanceGroup, serviceInstance);
582 } catch (Exception ex) {
583 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
588 * This method is used to put the network policy in A&AI.
590 * @param execution @throws
592 public void createNetworkPolicies(BuildingBlockExecution execution) {
594 String fqdns = execution.getVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST);
595 if (fqdns != null && !fqdns.isEmpty()) {
596 String fqdnList[] = fqdns.split(",");
597 int fqdnCount = fqdnList.length;
599 for (int i = 0; i < fqdnCount; i++) {
600 String fqdn = fqdnList[i];
601 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY);
602 uri.queryParam(NETWORK_POLICY_FQDN_PARAM, fqdn);
603 Optional<org.onap.aai.domain.yang.NetworkPolicy> oNetPolicy =
604 aaiNetworkResources.getNetworkPolicy(uri);
605 if (!oNetPolicy.isPresent()) {
606 logger.debug("This network policy FQDN is not in AAI yet: {}", fqdn);
607 String networkPolicyId = UUID.randomUUID().toString();
608 logger.debug("Adding network-policy with network-policy-id {}", networkPolicyId);
609 NetworkPolicy networkPolicy = new NetworkPolicy();
610 networkPolicy.setNetworkPolicyId(networkPolicyId);
611 networkPolicy.setNetworkPolicyFqdn(fqdn);
612 networkPolicy.setHeatStackId(execution.getVariable(HEAT_STACK_ID));
614 aaiNetworkResources.createNetworkPolicy(networkPolicy);
619 } catch (Exception ex) {
620 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
625 * Groups existing vf modules by the model uuid of our new vf module and returns the lowest unused index
627 * 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
628 * adding a new module type A, the vf-module-index should be 3 assuming contiguous indices (not 5, or 2)
631 protected int getLowestUnusedVfModuleIndexFromAAIVnfResponse(GenericVnf genericVnf, VfModule newVfModule) {
633 String newVfModuleModelInvariantUUID = null;
634 if (newVfModule.getModelInfoVfModule() != null) {
635 newVfModuleModelInvariantUUID = newVfModule.getModelInfoVfModule().getModelInvariantUUID();
639 if (genericVnf != null && genericVnf.getVfModules() != null && !genericVnf.getVfModules().isEmpty()) {
640 List<VfModule> modules = genericVnf.getVfModules().stream()
641 .filter(item -> !item.getVfModuleId().equals(newVfModule.getVfModuleId()))
642 .collect(Collectors.toList());
643 TreeSet<Integer> moduleIndices = new TreeSet<>();
644 int nullIndexFound = 0;
645 for (VfModule vfModule : modules) {
646 if (vfModule.getModelInfoVfModule() != null) {
647 if (vfModule.getModelInfoVfModule().getModelInvariantUUID().equals(newVfModuleModelInvariantUUID)) {
648 if (vfModule.getModuleIndex() != null) {
649 moduleIndices.add(vfModule.getModuleIndex());
652 logger.warn("Found null index for vf-module-id {} and model-invariant-uuid {}",
653 vfModule.getVfModuleId(), vfModule.getModelInfoVfModule().getModelInvariantUUID());
659 return calculateUnusedIndex(moduleIndices, nullIndexFound);
665 protected int calculateUnusedIndex(TreeSet<Integer> moduleIndices, int nullIndexFound) {
666 // pad array with nulls
667 Integer[] temp = new Integer[moduleIndices.size() + nullIndexFound];
668 Integer[] array = moduleIndices.toArray(temp);
670 // when a null is found skip that potential value
671 // effectively creates something like, [0,1,3,null,null] -> [0,1,null(2),3,null(4)]
672 for (int i = 0; i < array.length; i++, result++) {
673 if (Integer.valueOf(result) != array[i]) {
674 if (nullIndexFound > 0) {