Removing all policies from RIC when removed from configuration
Change-Id: I9f47f7369eef021b8d2a7e3fb73c4fc432fe7f56
Issue-ID: CCSDK-2502
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Rics.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Rics.java
index 75c16da..b6ec749 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Rics.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Rics.java
@@ -27,6 +27,7 @@
import java.util.Vector;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
+import org.springframework.lang.Nullable;
/**
* Dynamic representation of all Rics in the system.
@@ -54,8 +55,8 @@
return registeredRics.get(ricId);
}
- public synchronized void remove(String ricId) {
- registeredRics.remove(ricId);
+ public synchronized @Nullable Ric remove(String ricId) {
+ return registeredRics.remove(ricId);
}
public synchronized int size() {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
index 5da066f..b63a8ac 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
@@ -63,6 +63,7 @@
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
+import reactor.util.annotation.Nullable;
/**
* Regularly refreshes the configuration from Consul or from a local
@@ -195,6 +196,14 @@
return (filepath != null && (new File(filepath).exists()));
}
+ private void removePoliciciesInRic(@Nullable Ric ric) {
+ if (ric != null) {
+ RicSynchronizationTask synch =
+ new RicSynchronizationTask(this.a1ClientFactory, this.policyTypes, this.policies, this.services);
+ synch.run(ric);
+ }
+ }
+
private void handleUpdatedRicConfig(RicConfigUpdate updatedInfo) {
synchronized (this.rics) {
String ricId = updatedInfo.getRicConfig().ricId();
@@ -202,8 +211,9 @@
if (event == RicConfigUpdate.Type.ADDED) {
addRic(updatedInfo.getRicConfig());
} else if (event == RicConfigUpdate.Type.REMOVED) {
- rics.remove(ricId);
+ Ric ric = rics.remove(ricId);
this.policies.removePoliciesForRic(ricId);
+ removePoliciciesInRic(ric);
} else if (event == RicConfigUpdate.Type.CHANGED) {
Ric ric = this.rics.get(ricId);
if (ric == null) {