summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java54
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java12
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();
}