aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2024-07-22 11:30:48 +0100
committerlapentafd <francesco.lapenta@est.tech>2024-07-23 12:39:26 +0100
commit04a87c3395fde482cb458bc1422435b6a6a57fe1 (patch)
treef7775e6b4d257226f974a2b0b42c2122dea005e5
parentff95ae47d58dfc2ac01ccbfb994b615f975d1675 (diff)
Handle non transient policy deletion - London1.5.1
Issue-ID: CCSDK-4039 Change-Id: Iddb77444b5eb481cfe34b78bbbff865425223659 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java42
-rw-r--r--docs/tox.ini2
2 files changed, 36 insertions, 8 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java
index ed97820f..4bf543ed 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java
@@ -31,11 +31,13 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
+import java.lang.invoke.MethodHandles;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Map;
import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
@@ -43,6 +45,9 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Service;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -51,6 +56,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -70,6 +76,11 @@ public class ServiceController {
private static Gson gson = new GsonBuilder().create();
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Autowired
+ private PolicyController policyController;
+
ServiceController(Services services, Policies policies) {
this.services = services;
this.policies = policies;
@@ -163,14 +174,13 @@ public class ServiceController {
})
public ResponseEntity<Object> deleteService(//
- @PathVariable("service_id") String serviceId) {
+ @PathVariable("service_id") String serviceId, @RequestHeader Map<String, String> headers) {
try {
Service service = removeService(serviceId);
- // Remove the policies from the repo and let the consistency monitoring
- // do the rest.
- removePolicies(service);
+ removePolicies(service, headers);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
- } catch (ServiceException e) {
+ } catch (ServiceException | NullPointerException e) {
+ logger.warn("Exception caught during service deletion while deleting service {}: {}", serviceId, e.getMessage());
return ErrorResponse.create(e, HttpStatus.NOT_FOUND);
}
}
@@ -197,14 +207,32 @@ public class ServiceController {
private Service removeService(String name) throws ServiceException {
Service service = this.services.getService(name); // Just to verify that it exists
+ logger.trace("Service name to be deleted: {}", service.getName());
this.services.remove(service.getName());
return service;
}
- private void removePolicies(Service service) {
+ private void removePolicies(Service service, Map<String, String> headers) {
Collection<Policy> policyList = this.policies.getForService(service.getName());
+ logger.trace("Policies to be deleted: {}", policyList);
for (Policy policy : policyList) {
- this.policies.remove(policy);
+ try {
+ policyController.deletePolicy(policy.getId(), headers).doOnNext(resp -> {
+ if (resp.getStatusCode().is2xxSuccessful()) {
+ logger.trace("Deleting Policy '{}' when deleting Service '{}'", policy.getId(),
+ service.getName());
+ } else {
+ logger.warn("Possible problem deleting Policy '{}' when deleting Service '{}'. Continuing, "
+ + "but might trigger a re-sync with affected ric '{}'. Repsonse: \"{}\"",
+ policy.getId(), service.getName(), policy.getRic().getConfig().getRicId(),
+ resp.toString());
+ }
+ }).subscribe();
+ } catch (Exception e) {
+ logger.warn("Problem deleting Policy '{}' when deleting Service '{}'."
+ + " Continuing, but might trigger a re-sync with affected ric '{}'. Problem: \"{}\"",
+ policy.getId(), service.getName(), policy.getRic().getConfig().getRicId(), e.getMessage());
+ }
}
}
diff --git a/docs/tox.ini b/docs/tox.ini
index 00ec327c..fca054b9 100644
--- a/docs/tox.ini
+++ b/docs/tox.ini
@@ -9,7 +9,7 @@ skipsdist = true
basepython = python3.8
deps =
-r{toxinidir}/requirements-docs.txt
- -chttps://raw.githubusercontent.com/openstack/requirements/stable/yoga/upper-constraints.txt
+ -chttps://raw.githubusercontent.com/openstack/requirements/unmaintained/yoga/upper-constraints.txt
-chttps://git.onap.org/doc/plain/etc/upper-constraints.onap.txt
commands =
sphinx-build -W -b html -n -d {envtmpdir}/doctrees ./ {toxinidir}/_build/html