aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java4
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java35
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java34
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java9
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java38
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java34
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java33
8 files changed, 183 insertions, 7 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
index f1e8e711c4..418ba05abf 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
@@ -40,6 +40,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
+import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.apihandler.common.CommonConstants;
import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandler.common.RequestClientParameter;
@@ -56,7 +57,6 @@ import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.client.RequestsDbClient;
import org.onap.so.exceptions.ValidationException;
-import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.logger.MessageEnum;
import org.onap.so.serviceinstancebeans.CloudConfiguration;
import org.onap.so.serviceinstancebeans.ModelInfo;
@@ -823,7 +823,7 @@ public class ServiceInstances extends AbstractRestHandler {
sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
action = handleReplaceInstance(action, sir);
- requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams);
+ requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action);
String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri);
InfraActiveRequests currentActiveReq =
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 fee7a3a8f4..4e3d8736c2 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
@@ -9,6 +9,7 @@ import org.onap.aai.domain.yang.Tenant;
import org.onap.aai.domain.yang.VfModule;
import org.onap.aai.domain.yang.VolumeGroup;
import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.AAIResultWrapper;
@@ -76,6 +77,40 @@ public class AAIDataRetrieval {
});
}
+
+ public boolean isVolumeGroupRelatedToVFModule(String volumeGroupId) {
+ return this.getAaiResourcesClient().exists(AAIUriFactory
+ .createResourceUri(AAIObjectType.VOLUME_GROUP, volumeGroupId).relatedTo(AAIObjectPlurals.VF_MODULE));
+ }
+
+ public boolean isVnfRelatedToVolumes(String vnfId) {
+ return this.getAaiResourcesClient().exists(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
+ .relatedTo(AAIObjectPlurals.VOLUME_GROUP));
+ }
+
+ public boolean isNetworkRelatedToModules(String networkId) {
+ return this.getAaiResourcesClient().exists(AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId)
+ .relatedTo(AAIObjectPlurals.VF_MODULE));
+ }
+
+ public boolean isServiceRelatedToNetworks(String serviceInstanceId) {
+ return this.getAaiResourcesClient()
+ .exists(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
+ .relatedTo(AAIObjectPlurals.L3_NETWORK));
+ }
+
+ public boolean isServiceRelatedToGenericVnf(String serviceInstanceId) {
+ return this.getAaiResourcesClient()
+ .exists(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
+ .relatedTo(AAIObjectPlurals.GENERIC_VNF));
+ }
+
+ public boolean isServiceRelatedToConfiguration(String serviceInstanceId) {
+ return this.getAaiResourcesClient()
+ .exists(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
+ .relatedTo(AAIObjectPlurals.CONFIGURATION));
+ }
+
public Service getService(String serviceId) {
return this.getAaiResourcesClient()
.get(Service.class, AAIUriFactory.createResourceUri(AAIObjectType.SERVICE, serviceId)).orElseGet(() -> {
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java
new file mode 100644
index 0000000000..f75897dda1
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java
@@ -0,0 +1,34 @@
+package org.onap.so.apihandlerinfra.infra.rest.validators;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.Actions;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+
+public class NetworkDeleteValidator implements RequestValidator {
+
+ @Autowired
+ AAIDataRetrieval aaiDataRetrieval;
+
+ @Override
+ public boolean shouldRunFor(String requestUri, ServiceInstancesRequest request, Actions action) {
+ return Pattern.compile("[Vv][5-8]/serviceInstances/[^/]+/networks/[^/]+").matcher(requestUri).matches()
+ && action.equals(Action.deleteInstance);
+
+ }
+
+ @Override
+ public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request,
+ Map<String, String> queryParams) {
+ if (aaiDataRetrieval.isNetworkRelatedToModules(instanceIdMap.get("networkInstanceId"))) {
+ return Optional.of("Cannot delete network it is still related to existing vf-modules");
+ } else {
+ return Optional.empty();
+ }
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java
index 4aa60152dd..1dea57ad9c 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java
@@ -22,6 +22,7 @@ package org.onap.so.apihandlerinfra.infra.rest.validators;
import java.util.Map;
import java.util.Optional;
+import org.onap.so.apihandlerinfra.Actions;
import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
public interface RequestValidator {
@@ -32,7 +33,7 @@ public interface RequestValidator {
*
* @return
*/
- public boolean shouldRunFor(String uri, ServiceInstancesRequest request);
+ public boolean shouldRunFor(String uri, ServiceInstancesRequest request, Actions action);
public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request,
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java
index d689c6b7a5..3aba39b501 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java
@@ -28,6 +28,7 @@ import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.javatuples.Pair;
+import org.onap.so.apihandlerinfra.Actions;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.listener.ListenerRunner;
@@ -50,10 +51,10 @@ public class RequestValidatorListenerRunner extends ListenerRunner {
}
public boolean runValidations(String requestURI, Map<String, String> instanceIdMap, ServiceInstancesRequest request,
- Map<String, String> queryParams) throws ApiException {
+ Map<String, String> queryParams, Actions action) throws ApiException {
logger.info("Running local validations");
List<Pair<String, Optional<String>>> results =
- runValidations(requestValidators, instanceIdMap, request, queryParams, requestURI);
+ runValidations(requestValidators, instanceIdMap, request, queryParams, requestURI, action);
if (!results.isEmpty()) {
throw new ValidateException("Failed Validations:\n"
+ results.stream().map(item -> String.format("%s: %s", item.getValue0(), item.getValue1().get()))
@@ -66,10 +67,10 @@ public class RequestValidatorListenerRunner extends ListenerRunner {
protected List<Pair<String, Optional<String>>> runValidations(List<? extends RequestValidator> validators,
Map<String, String> instanceIdMap, ServiceInstancesRequest request, Map<String, String> queryParams,
- String requestURI) {
+ String requestURI, Actions action) {
List<? extends RequestValidator> filtered =
- filterListeners(validators, (item -> item.shouldRunFor(requestURI, request)));
+ filterListeners(validators, (item -> item.shouldRunFor(requestURI, request, action)));
List<Pair<String, Optional<String>>> results = new ArrayList<>();
filtered.forEach(item -> results
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java
new file mode 100644
index 0000000000..0c7ba65cf4
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java
@@ -0,0 +1,38 @@
+package org.onap.so.apihandlerinfra.infra.rest.validators;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.Actions;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.listener.Skip;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@Skip
+public class ServiceInstanceDeleteValidator implements RequestValidator {
+
+ @Autowired
+ AAIDataRetrieval aaiDataRetrieval;
+
+ @Override
+ public boolean shouldRunFor(String requestUri, ServiceInstancesRequest request, Actions action) {
+ return Pattern.compile("[Vv][5-8]/serviceInstances/[^/]+").matcher(requestUri).matches()
+ && action.equals(Action.deleteInstance);
+ }
+
+ @Override
+ public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request,
+ Map<String, String> queryParams) {
+ if (aaiDataRetrieval.isServiceRelatedToGenericVnf(instanceIdMap.get("serviceInstanceId"))) {
+ return Optional.of("Cannot delete service it is still related to existing vf-modules");
+ } else if (aaiDataRetrieval.isServiceRelatedToNetworks(instanceIdMap.get("serviceInstanceId"))) {
+ return Optional.of("Cannot delete service it is still related to existing networks");
+ } else if (aaiDataRetrieval.isServiceRelatedToConfiguration(instanceIdMap.get("serviceInstanceId"))) {
+ return Optional.of("Cannot delete service it is still related to existing configurations");
+ } 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
new file mode 100644
index 0000000000..d54e60d153
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java
@@ -0,0 +1,34 @@
+package org.onap.so.apihandlerinfra.infra.rest.validators;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.Actions;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+
+public class VnfDeleteValidator implements RequestValidator {
+
+ @Autowired
+ AAIDataRetrieval aaiDataRetrieval;
+
+ @Override
+ public boolean shouldRunFor(String requestUri, ServiceInstancesRequest request, Actions action) {
+ return Pattern.compile("[Vv][5-8]/serviceInstances/[^/]+/vnfs/[^/]+").matcher(requestUri).matches()
+ && action.equals(Action.deleteInstance);
+ }
+
+ @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");
+ } else {
+ return Optional.empty();
+ }
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java
new file mode 100644
index 0000000000..f010d47f70
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java
@@ -0,0 +1,33 @@
+package org.onap.so.apihandlerinfra.infra.rest.validators;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.Actions;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class VolumeGroupDeleteValidator implements RequestValidator {
+
+ @Autowired
+ AAIDataRetrieval aaiDataRetrieval;
+
+ @Override
+ public boolean shouldRunFor(String requestUri, ServiceInstancesRequest request, Actions action) {
+ return Pattern.compile("[Vv][5-8]/serviceInstances/[^/]+/volumeGroups/[^/]+").matcher(requestUri).matches()
+ && action.equals(Action.deleteInstance);
+ }
+
+ @Override
+ public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request,
+ Map<String, String> queryParams) {
+ if (aaiDataRetrieval.isVolumeGroupRelatedToVFModule(instanceIdMap.get("volumeGroupInstanceId"))) {
+ return Optional.of("Cannot delete volume group it is related to existing vf-modules");
+ } else {
+ return Optional.empty();
+ }
+ }
+
+}