From c7f757e98066775ed2fdeb67f3d31777e8430624 Mon Sep 17 00:00:00 2001
From: PatrikBuhr
Date: Mon, 28 Nov 2022 09:40:36 +0100
Subject: 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
---
a1-policy-management/api/pms-api.json | 12 +++---
a1-policy-management/api/pms-api.yaml | 21 ++++++----
.../a1policymanagementservice/SwaggerConfig.java | 5 ++-
.../controllers/v2/PolicyInfo.java | 15 ++++---
.../controllers/v2/ServiceController.java | 6 +--
.../controllers/v2/ServiceRegistrationInfo.java | 2 +-
.../repository/Policies.java | 19 ++++++---
.../controllers/v2/ApplicationTest.java | 48 ++++++++++++++++++++--
8 files changed, 96 insertions(+), 32 deletions(-)
(limited to 'a1-policy-management')
diff --git a/a1-policy-management/api/pms-api.json b/a1-policy-management/api/pms-api.json
index a81070f7..ce2d9aa8 100644
--- a/a1-policy-management/api/pms-api.json
+++ b/a1-policy-management/api/pms-api.json
@@ -199,8 +199,7 @@
"policy_data",
"policy_id",
"policytype_id",
- "ric_id",
- "service_id"
+ "ric_id"
],
"properties": {
"ric_id": {
@@ -214,12 +213,13 @@
"example": null
},
"transient": {
+ "default": false,
"description": "if true, the policy is deleted at RIC restart. If false, its value is maintained by this service until explicitly deleted. Default false.",
"type": "boolean",
- "example": null
+ "example": false
},
"service_id": {
- "description": "the identity of the service owning the policy",
+ "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.",
"type": "string",
"example": null
},
@@ -881,7 +881,7 @@
}},
"required": true
},
- "description": "Registering a service is needed to:- Get callbacks.<\/li>
- Activate supervision of the service. If a service is inactive, its policies will be deleted.<\/li><\/ul>",
+ "description": "Registering a service is needed to:
license:
name: Copyright (C) 2020-2022 Nordix Foundation. Licensed under the Apache License.
url: http://www.apache.org/licenses/LICENSE-2.0
@@ -539,9 +541,11 @@ paths:
tags:
- Service Registry and Supervision
summary: Register a service
- description: Registering a service is needed to:- Get callbacks.
- Activate
- supervision of the service. If a service is inactive, its policies will be
- deleted.
+ description: Registering a service is needed to:- Get callbacks about
+ available NearRT RICs.
- Activate supervision of the service. If a service
+ is inactive, its policies will automatically be deleted.
Policies
+ can be created even if the service is not registerred. This is a feature which
+ it is optional to use.
operationId: putService
requestBody:
content:
@@ -977,7 +981,6 @@ components:
- policy_id
- policytype_id
- ric_id
- - service_id
type: object
properties:
ric_id:
@@ -991,9 +994,13 @@ components:
description: if true, the policy is deleted at RIC restart. If false, its
value is maintained by this service until explicitly deleted. Default
false.
+ example: false
+ default: false
service_id:
type: string
- description: the identity of the service owning the policy
+ 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.
policy_data:
type: object
description: the configuration of the policy
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 + //
"API used for supervision of the PMS component.
" + //
H3 + ServiceController.API_NAME + H3_END + //
- "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.
";
+ "" + "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."
+ + "
";
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:" //
+ "" //
- + "- Get callbacks.
" //
- + "- Activate supervision of the service. If a service is inactive, its policies will be deleted.
"//
+ + "- Get callbacks about available NearRT RICs.
" //
+ + "- Activate supervision of the service. If a service is inactive, its policies will automatically be deleted.
"//
+ "
" //
- ;
+ + "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();
@@ -506,6 +506,27 @@ class ApplicationTest {
this.rics.getRic(ricId).setState(Ric.RicState.AVAILABLE);
}
+ @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
@@ -553,6 +574,25 @@ class ApplicationTest {
assertThat(policyInfo.policyTypeId).isEmpty();
}
+ @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
--
cgit 1.2.3-korg