summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2024-07-22 11:16:11 +0100
committerlapentafd <francesco.lapenta@est.tech>2024-07-23 12:37:34 +0100
commitcc8cc210aea9c6b3ad2cb8b1623e0d74a4cea5a8 (patch)
tree24ee35e4fda75e68fc0d995a7f1e79057c4545cb
parent61426d2c61d4a21cafb70e442d7712df366d9506 (diff)
Handle non transient policy deletion - Montreal1.6.2
Issue-ID: CCSDK-4039 Change-Id: I14a6afbdcc7f38cba953c10475a99b73ddbd05fe 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.java43
-rw-r--r--docs/tox.ini2
2 files changed, 30 insertions, 15 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 da157db0..58b87c63 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
@@ -20,9 +20,6 @@
package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v2.ServiceRegistryAndSupervisionApi;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
@@ -33,14 +30,16 @@ 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.ResponseEntity;
-import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
+import java.lang.invoke.MethodHandles;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
@@ -62,10 +61,10 @@ public class ServiceController implements ServiceRegistryAndSupervisionApi {
private final Services services;
private final Policies policies;
- @Autowired
- private ObjectMapper objectMapper;
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private static Gson gson = new GsonBuilder().create();
+ @Autowired
+ private PolicyController policyController;
ServiceController(Services services, Policies policies) {
this.services = services;
@@ -137,32 +136,48 @@ public class ServiceController implements ServiceRegistryAndSupervisionApi {
public Mono<ResponseEntity<Object>> deleteService(final String serviceId, final ServerWebExchange exchange) {
try {
Service service = removeService(serviceId);
- // Remove the policies from the repo and let the consistency monitoring
- // do the rest.
- removePolicies(service);
+ removePolicies(service, exchange);
return Mono.just(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.createMono(e, HttpStatus.NOT_FOUND);
}
}
@Override
public Mono<ResponseEntity<Object>> keepAliveService(final String serviceId, final ServerWebExchange exchange) throws ServiceException {
-
services.getService(serviceId).keepAlive();
return Mono.just(new ResponseEntity<>(HttpStatus.OK));
}
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, ServerWebExchange exchange) {
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(), exchange).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 3fde8599..fa7db763 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?h=montreal
commands =
sphinx-build -W -b html -n -d {envtmpdir}/doctrees ./ {toxinidir}/_build/html