From 2a5028d0d6b1d4b809ab72beafd95c65ea26c662 Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Mon, 9 Nov 2020 13:42:09 +0100 Subject: Bugfix, GET policy V2 Did not return transient flag. Improved somew unittests Skipped unwanted service callback when RIC is removed Change-Id: I3ca3be5d4592c2a1b31d3b1a23fe601d1d3f85a2 Issue-ID: CCSDK-2502 Signed-off-by: PatrikBuhr --- .../controllers/v2/PolicyController.java | 7 +------ .../a1policymanagementservice/controllers/v2/PolicyInfo.java | 8 +++++--- .../a1policymanagementservice/tasks/RefreshConfigTask.java | 11 +++++++---- .../oran/a1policymanagementservice/tasks/RicSupervision.java | 2 +- .../tasks/RicSynchronizationTask.java | 9 ++++++++- 5 files changed, 22 insertions(+), 15 deletions(-) (limited to 'a1-policy-management/src/main/java') diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java index ec776042..ea047cb5 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java @@ -262,12 +262,6 @@ public class PolicyController { return Mono.just("{}"); } - private void assertRicStateIdleSync(Ric ric) throws ServiceException { - if (ric.getState() != Ric.RicState.AVAILABLE) { - throw new ServiceException("Near-RT RIC: " + ric.id() + " is " + ric.getState()); - } - } - private Mono assertRicStateIdle(Ric ric) { if (ric.getState() == Ric.RicState.AVAILABLE) { return Mono.just("{}"); @@ -408,6 +402,7 @@ public class PolicyController { policyInfo.ricId = p.ric().id(); policyInfo.policyTypeId = p.type().id(); policyInfo.serviceId = p.ownerServiceId(); + policyInfo.isTransient = p.isTransient(); if (!p.statusNotificationUri().isEmpty()) { policyInfo.statusNotificationUri = p.statusNotificationUri(); } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyInfo.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyInfo.java index c032e3ad..43684a33 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyInfo.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyInfo.java @@ -57,10 +57,12 @@ public class PolicyInfo { @SerializedName("service_id") public String serviceId; - @ApiModelProperty(value = "the name of the service owning the policy", required = false) - @JsonProperty(value = "transient", required = false) + @ApiModelProperty( + value = "if true, the policy is deleted at RIC restart. If false, its value is maintained by this service until explicitly deleted. Default false.", + required = false) + @JsonProperty(value = "transient", required = false, defaultValue = "false") @SerializedName("transient") - public boolean isTransient; + public boolean isTransient = false; @ApiModelProperty(value = "Callback URI for policy status updates", required = false) @JsonProperty(value = "status_notification_uri", required = false) 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 e4d7d8d7..dc364faf 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 @@ -201,8 +201,8 @@ public class RefreshConfigTask { private void removePoliciciesInRic(@Nullable Ric ric) { if (ric != null) { - RicSynchronizationTask synch = - new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, restClientFactory); + RicSynchronizationTask synch = new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, + restClientFactory, rics); synch.run(ric); } } @@ -212,15 +212,18 @@ public class RefreshConfigTask { String ricId = updatedInfo.getRicConfig().ricId(); RicConfigUpdate.Type event = updatedInfo.getType(); if (event == RicConfigUpdate.Type.ADDED) { + logger.debug("RIC added {}", ricId); addRic(updatedInfo.getRicConfig()); } else if (event == RicConfigUpdate.Type.REMOVED) { + logger.debug("RIC removed {}", ricId); Ric ric = rics.remove(ricId); this.policies.removePoliciesForRic(ricId); removePoliciciesInRic(ric); } else if (event == RicConfigUpdate.Type.CHANGED) { + logger.debug("RIC config updated {}", ricId); Ric ric = this.rics.get(ricId); if (ric == null) { - // Should not happen,just for robustness + logger.error("An non existing RIC config is changed, should not happen (just for robustness)"); addRic(updatedInfo.getRicConfig()); } else { ric.setRicConfig(updatedInfo.getRicConfig()); @@ -237,7 +240,7 @@ public class RefreshConfigTask { void runRicSynchronization(Ric ric) { RicSynchronizationTask synchronizationTask = - new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, restClientFactory); + new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, restClientFactory, rics); synchronizationTask.run(ric); } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java index cae257cd..c13df8c3 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java @@ -211,6 +211,6 @@ public class RicSupervision { } RicSynchronizationTask createSynchronizationTask() { - return new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, restClientFactory); + return new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, restClientFactory, rics); } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java index 825418b5..b38a36b2 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java @@ -33,6 +33,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy; import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType; import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,15 +65,17 @@ public class RicSynchronizationTask { private final PolicyTypes policyTypes; private final Policies policies; private final Services services; + private final Rics rics; private final AsyncRestClientFactory restClientFactory; public RicSynchronizationTask(A1ClientFactory a1ClientFactory, PolicyTypes policyTypes, Policies policies, - Services services, AsyncRestClientFactory restClientFactory) { + Services services, AsyncRestClientFactory restClientFactory, Rics rics) { this.a1ClientFactory = a1ClientFactory; this.policyTypes = policyTypes; this.policies = policies; this.services = services; this.restClientFactory = restClientFactory; + this.rics = rics; } public void run(Ric ric) { @@ -129,6 +132,10 @@ public class RicSynchronizationTask { } private void onSynchronizationComplete(Ric ric) { + if (this.rics.get(ric.id()) == null) { + logger.debug("Policies removed in removed ric: {}", ric.id()); + return; + } logger.debug("Synchronization completed for: {}", ric.id()); ric.setState(RicState.AVAILABLE); notifyServices(ric); -- cgit 1.2.3-korg