diff options
author | Bonkur, Venkat <venkat.bonkur@att.com> | 2020-05-23 17:33:33 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@att.com> | 2020-05-23 17:33:34 -0400 |
commit | 6541778af571666e11cfaea4953749bef94ca212 (patch) | |
tree | 3d27ed39ddeeb28b611a7f9aec8e9ff151d7a389 /mso-api-handlers/mso-api-handler-infra/src/main | |
parent | 2109b159bb28fc8eff6613b227fe7e5d5d8ae915 (diff) |
Capture ids of vfModule and volumegroups
Capture ids of vfModule and volumegroups
Issue-ID: SO-2951
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: Ibe8af16c899a66ef007f74eb2c4e42afb0c2b42f
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
2 files changed, 64 insertions, 2 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java index a87e94a6e0..fc0048bacf 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java @@ -1,7 +1,10 @@ package org.onap.so.apihandlerinfra.infra.rest; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.L3Network; import org.onap.aai.domain.yang.LInterface; @@ -9,13 +12,16 @@ import org.onap.aai.domain.yang.Service; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aai.domain.yang.Tenant; import org.onap.aai.domain.yang.VfModule; +import org.onap.aai.domain.yang.VfModules; import org.onap.aai.domain.yang.VolumeGroup; +import org.onap.aai.domain.yang.VolumeGroups; import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound; import org.onap.aaiclient.client.aai.AAIDSLQueryClient; import org.onap.aaiclient.client.aai.AAIObjectPlurals; import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; +import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.graphinventory.entities.DSLQuery; import org.onap.aaiclient.client.graphinventory.entities.DSLQueryBuilder; @@ -164,4 +170,52 @@ public class AAIDataRetrieval { return aaiResourcesClient; } + public boolean isVnfRelatedToVFModule(String vnfId) { + return !getVfModulesOfVnf(vnfId).isEmpty(); + } + + public List<VfModule> getVfModulesOfVnf(String vnfId) { + List<VfModule> vfModuleList = new ArrayList<VfModule>(); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, vnfId); + Optional<VfModules> vfModules = getAaiResourcesClient().get(VfModules.class, uri); + if (!vfModules.isPresent() || vfModules.get().getVfModule().isEmpty()) { + logger.debug("No VfModules attached to Vnf in AAI : {}", vnfId); + } else { + vfModuleList = vfModules.get().getVfModule(); + } + return vfModuleList; + } + + public Optional<String> getVfModuleIdsByVnfId(String vnfId) { + List<VfModule> vfModulesList = getVfModulesOfVnf(vnfId); + if (!vfModulesList.isEmpty()) { + return Optional.of(vfModulesList.stream().map(item -> item.getVfModuleId()).collect(Collectors.toList()) + .stream().sorted().collect(Collectors.joining(","))); + } else { + return Optional.empty(); + } + } + + public List<VolumeGroup> getVolumeGroupsOfVnf(String vnfId) { + List<VolumeGroup> volumeGroupList = new ArrayList<VolumeGroup>(); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId) + .relatedTo(AAIObjectPlurals.VOLUME_GROUP); + Optional<VolumeGroups> volumeGroups = getAaiResourcesClient().get(VolumeGroups.class, uri); + if (!volumeGroups.isPresent() || volumeGroups.get().getVolumeGroup().isEmpty()) { + logger.debug("No VolumeGroups attached to Vnf in AAI : {}", vnfId); + } else { + volumeGroupList = volumeGroups.get().getVolumeGroup(); + } + return volumeGroupList; + } + + public Optional<String> getVolumeGroupIdsByVnfId(String vnfId) { + List<VolumeGroup> volumeGroupList = getVolumeGroupsOfVnf(vnfId); + if (!volumeGroupList.isEmpty()) { + return Optional.of(volumeGroupList.stream().map(item -> item.getVolumeGroupId()) + .collect(Collectors.toList()).stream().sorted().collect(Collectors.joining(","))); + } else { + return Optional.empty(); + } + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java index 37e3f0cb2e..a48fca8d0f 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java @@ -25,8 +25,16 @@ public class VnfDeleteValidator implements RequestValidator { @Override public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request, Map<String, String> queryParams) { - if (aaiDataRetrieval.isVnfRelatedToVolumes(instanceIdMap.get("vnfInstanceId"))) { - return Optional.of("Cannot delete vnf it is still related to existing volume groups"); + final Optional<String> volumeGroupIds = + aaiDataRetrieval.getVolumeGroupIdsByVnfId(instanceIdMap.get("vnfInstanceId")); + final Optional<String> vfModuleIds = aaiDataRetrieval.getVfModuleIdsByVnfId(instanceIdMap.get("vnfInstanceId")); + + if (volumeGroupIds.isPresent()) { + return Optional.of(String.format("Cannot delete vnf it is still related to existing volume group Ids - %s", + volumeGroupIds.get())); + } else if (vfModuleIds.isPresent()) { + return Optional.of(String.format("Cannot delete vnf it is still related to existing vfModule Ids - %s", + vfModuleIds.get())); } else { return Optional.empty(); } |