diff options
author | PatrikBuhr <patrik.buhr@est.tech> | 2022-11-28 09:40:36 +0100 |
---|---|---|
committer | Patrik Buhr <patrik.buhr@est.tech> | 2022-12-06 14:44:33 +0000 |
commit | c7f757e98066775ed2fdeb67f3d31777e8430624 (patch) | |
tree | 117bb2b39183b9c59a5a7935e1057391ec90cb58 /a1-policy-management/src | |
parent | bf5e4cd0b2b2ad91238a34c558ba888c38117376 (diff) |
A1-PMS, make service id optional in PUT Policy
Improved API documentation.
Fixed a bug that lead to that a policy could be connected to several services if the service_id was changed.
Change-Id: I211f5db32747fc912b7ba85bfbc15ce50ee725dd
Issue-ID: CCSDK-3819
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management/src')
6 files changed, 76 insertions, 19 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/SwaggerConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/SwaggerConfig.java index 4e4ec2d5..4c3a0c79 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/SwaggerConfig.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/SwaggerConfig.java @@ -83,7 +83,10 @@ public class SwaggerConfig { + H3 + StatusController.API_NAME + H3_END + // "<p>API used for supervision of the PMS component.</p>" + // H3 + ServiceController.API_NAME + H3_END + // - "<p>API used for registering services that uses PMS. Each A1 policy is owned by a service. PMS can supervise each registered service and will automatically remove policies for unavailable services.</p>"; + "<p>" + "API used for registering services that uses PMS." + + " Each A1 policy is optionally owned by a service. PMS can supervise each registered service by a heart-beat supervision and will automatically remove policies for unavailable services." + + " Note that a service does not need to be registered in order to create A1 Policies. This is a feature that is optional to use." + + "</p>"; public static final String VERSION = "1.1.0"; } 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 55a9343d..a3870b2c 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 @@ -48,19 +48,24 @@ public class PolicyInfo { @SerializedName("policy_data") public Object policyData; - @Schema(name = "service_id", description = "the identity of the service owning the policy", required = true) - @JsonProperty(value = "service_id", required = true) + private static final String SERVICE_ID_DESCRIPTION = "the identity of the service owning the policy." + + " This can be used to group the policies (it is possible to get all policies associated to a service)." + + " Note that the service does not need to be registerred."; + + @Schema(name = "service_id", description = SERVICE_ID_DESCRIPTION, required = false, defaultValue = "") + @JsonProperty(value = "service_id", required = false) @SerializedName("service_id") - public String serviceId; + public String serviceId = ""; @Schema(name = "transient", description = "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) + required = false, defaultValue = "false", example = "false") @JsonProperty(value = "transient", required = false, defaultValue = "false") @SerializedName("transient") public boolean isTransient = false; - @Schema(name = "status_notification_uri", description = "Callback URI for policy status updates", required = false) + @Schema(name = "status_notification_uri", description = "Callback URI for policy status updates", required = false, + defaultValue = "") @JsonProperty(value = "status_notification_uri", required = false) @SerializedName("status_notification_uri") public String statusNotificationUri = ""; 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 faa152ca..c3f41768 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 @@ -128,10 +128,10 @@ public class ServiceController { private static final String REGISTER_SERVICE_DETAILS = "Registering a service is needed to:" // + "<ul>" // - + "<li>Get callbacks.</li>" // - + "<li>Activate supervision of the service. If a service is inactive, its policies will be deleted.</li>"// + + "<li>Get callbacks about available NearRT RICs.</li>" // + + "<li>Activate supervision of the service. If a service is inactive, its policies will automatically be deleted.</li>"// + "</ul>" // - ; + + "Policies can be created even if the service is not registerred. This is a feature which it is optional to use."; @PutMapping(Consts.V2_API_ROOT + "/services") @Operation(summary = "Register a service", description = REGISTER_SERVICE_DETAILS) diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceRegistrationInfo.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceRegistrationInfo.java index 0f975c24..c016b6fb 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceRegistrationInfo.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceRegistrationInfo.java @@ -42,7 +42,7 @@ public class ServiceRegistrationInfo { @JsonProperty("keep_alive_interval_seconds") public long keepAliveIntervalSeconds = 0; - @Schema(description = "callback for notifying of Near-RT RIC state changes", required = false) + @Schema(description = "callback for notifying of Near-RT RIC state changes", required = false, defaultValue = "") @SerializedName("callback_url") @JsonProperty("callback_url") public String callbackUrl = ""; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Policies.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Policies.java index 09f59ca4..6161fbd9 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Policies.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Policies.java @@ -97,6 +97,11 @@ public class Policies { } public synchronized void put(Policy policy) { + Policy previousDef = this.get(policy.getId()); + if (previousDef != null) { + removeFromMaps(previousDef); + } + policiesId.put(policy.getId(), policy); policiesRic.put(policy.getRic().id(), policy.getId(), policy); policiesService.put(policy.getOwnerServiceId(), policy.getId(), policy); @@ -150,10 +155,7 @@ public class Policies { if (!policy.isTransient()) { dataStore.deleteObject(getPath(policy)).subscribe(); } - policiesId.remove(policy.getId()); - policiesRic.remove(policy.getRic().id(), policy.getId()); - policiesService.remove(policy.getOwnerServiceId(), policy.getId()); - policiesType.remove(policy.getType().getId(), policy.getId()); + removeFromMaps(policy); } public synchronized void removePoliciesForRic(String ricId) { @@ -189,7 +191,7 @@ public class Policies { dataStore.deleteAllObjects().onErrorResume(t -> Mono.empty()).subscribe(); } - public void store(Policy policy) { + private void store(Policy policy) { byte[] bytes = gson.toJson(toStorageObject(policy)).getBytes(); this.dataStore.writeObject(this.getPath(policy), bytes) // @@ -197,6 +199,13 @@ public class Policies { .subscribe(); } + private void removeFromMaps(Policy policy) { + policiesId.remove(policy.getId()); + policiesRic.remove(policy.getRic().id(), policy.getId()); + policiesService.remove(policy.getOwnerServiceId(), policy.getId()); + policiesType.remove(policy.getType().getId(), policy.getId()); + } + private boolean isMatch(String filterValue, String actualValue) { return filterValue == null || actualValue.equals(filterValue); } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java index 76838bb8..bec55735 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java @@ -434,7 +434,7 @@ class ApplicationTest { } private String putPolicyBody(String serviceName, String ricId, String policyTypeName, String policyInstanceId, - boolean isTransient) { + boolean isTransient, String statusNotificationUri) { PolicyInfo info = new PolicyInfo(); info.policyId = policyInstanceId; info.policyTypeId = policyTypeName; @@ -445,12 +445,12 @@ class ApplicationTest { if (isTransient) { info.isTransient = isTransient; } - info.statusNotificationUri = "statusNotificationUri"; + info.statusNotificationUri = statusNotificationUri; return gson.toJson(info); } private String putPolicyBody(String serviceName, String ricId, String policyTypeName, String policyInstanceId) { - return putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, false); + return putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, false, "statusUri"); } @Test @@ -465,7 +465,7 @@ class ApplicationTest { // PUT a transient policy String url = "/policies"; - String policyBody = putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, true); + String policyBody = putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, true, "statusNotif"); this.rics.getRic(ricId).setState(Ric.RicState.AVAILABLE); restClient().put(url, policyBody).block(); @@ -507,6 +507,27 @@ class ApplicationTest { } @Test + void testPutPolicy_NoServiceNoStatusUri() throws Exception { + String ricId = "ric.1"; + String policyTypeName = "type1_1.2.3"; + String policyInstanceId = "instance_1.2.3"; + + addPolicyType(policyTypeName, ricId); + + // PUT a transient policy + String url = "/policies"; + String policyBody = putPolicyBody(null, ricId, policyTypeName, policyInstanceId, true, null); + this.rics.getRic(ricId).setState(Ric.RicState.AVAILABLE); + + restClient().put(url, policyBody).block(); + + Policy policy = policies.getPolicy(policyInstanceId); + assertThat(policy).isNotNull(); + assertThat(policy.getOwnerServiceId()).isBlank(); + assertThat(policy.getStatusNotificationUri()).isBlank(); + } + + @Test /** * Test that HttpStatus and body from failing REST call to A1 is passed on to * the caller. @@ -554,6 +575,25 @@ class ApplicationTest { } @Test + void testUpdateService() throws Exception { + this.addRic("ric1"); + this.addPolicy("p", "type1", "", "ric1"); + + String url = "/policies?service_id="; + String resp = restClient().get(url).block(); + assertThat(resp).contains("[\"p\"]"); + + this.addPolicy("p", "type1", "service", "ric1"); + url = "/policies?service_id="; + resp = restClient().get(url).block(); + assertThat(resp).contains("[]"); + + url = "/policies?service_id=service"; + resp = restClient().get(url).block(); + assertThat(resp).contains("[\"p\"]"); + } + + @Test void testRefuseToUpdatePolicy() throws Exception { // Test that only the json can be changed for a already created policy // In this case service is attempted to be changed |