From: elinuxhenrik Date: Fri, 3 Apr 2020 07:24:52 +0000 (+0200) Subject: Change name of policy ID in API X-Git-Tag: 2.0.0~90^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=f85d5640c9e3ebec82f6de62d0f1c9d70efe8945;hp=d3920fdf9938291fcd01388deea763d097b0d6c8;p=nonrtric.git Change name of policy ID in API In some methods the policy ID parameter was named "instance". It is changed to "id". Change-Id: Id267fba84e62a2e6d3ff52ffb3d728561178b337 Issue-ID: NONRTRIC-152 Signed-off-by: elinuxhenrik --- diff --git a/docs/policy-agent-api.rst b/docs/policy-agent-api.rst index e3354e45..8a46fc71 100644 --- a/docs/policy-agent-api.rst +++ b/docs/policy-agent-api.rst @@ -634,12 +634,12 @@ GET Returns a policy configuration. **URL path:** - /policy?instance= + /policy?id= **Parameters:** - instance: (*Required*) - The ID/name of the policy instance. + id: (*Required*) + The ID of the policy instance. **Responses:** @@ -647,7 +647,7 @@ GET JSON object containing policy information. :: { - "id": "string", (ID/name of policy) + "id": "string", (ID of policy) "json": "object", (JSON with policy data speified by the type) "ownerServiceName": "string", (Name of the service that created the policy) "ric": "string", (Name of the Near |nbh| RT |nbsp| RIC where the policy resides) @@ -662,7 +662,7 @@ GET Call: :: - curl -X GET "http://localhost:8081/policy?instance=Policy 1" + curl -X GET "http://localhost:8081/policy?id=Policy 1" Result: 200: :: @@ -696,7 +696,7 @@ GET Call: :: - curl -X GET "http://localhost:8081/policy?instance=nonexistent" + curl -X GET "http://localhost:8081/policy?id=nonexistent" Result: 404: :: @@ -710,12 +710,12 @@ PUT "*Keep Alive Interval*" registered. **URL path:** - /policy?instance=&ric=&service=&type= + /policy?id=&ric=&service=&type= **Parameters:** - instance: (*Required*) - The ID/name of the policy instance. + id: (*Required*) + The ID of the policy instance. ric: (*Required*) The name of the Near |nbh| RT |nbsp| RIC where the policy will be created. @@ -747,7 +747,7 @@ PUT Call: :: - curl -X PUT "http://localhost:8081/policy?instance=Policy%201&ric=ric1&service=Service%201&type=STD_PolicyModelUnconstrained_0.2.0" + curl -X PUT "http://localhost:8081/policy?id=Policy%201&ric=ric1&service=Service%201&type=STD_PolicyModelUnconstrained_0.2.0" -H "Content-Type: application/json" -d "{ \"scope\": { @@ -779,12 +779,12 @@ DELETE "*Keep Alive Interval*" registered. **URL path:** - /policy?instance= + /policy?id= **Parameters:** - instance: (*Required*) - The ID/name of the policy instance. + id: (*Required*) + The ID of the policy instance. **Responses:** @@ -798,7 +798,7 @@ DELETE Call: :: - curl -X DELETE "http://localhost:8081/policy?instance=Policy 1" + curl -X DELETE "http://localhost:8081/policy?id=Policy 1" Result: 204 @@ -866,12 +866,12 @@ GET Returns the status of a policy. **URL path:** - /policy_status?instance= + /policy_status?id= **Parameters:** - instance: (*Required*) - The ID/name of the policy. + id: (*Required*) + The ID of the policy. **Responses:** diff --git a/policy-agent/docs/api.yaml b/policy-agent/docs/api.yaml index 5800f0f8..3ea913d5 100644 --- a/policy-agent/docs/api.yaml +++ b/policy-agent/docs/api.yaml @@ -64,9 +64,9 @@ paths: produces: - '*/*' parameters: - - name: instance + - name: id in: query - description: instance + description: id required: true type: string responses: @@ -91,9 +91,9 @@ paths: produces: - '*/*' parameters: - - name: instance + - name: id in: query - description: instance + description: id required: true type: string - in: body @@ -147,9 +147,9 @@ paths: produces: - '*/*' parameters: - - name: instance + - name: id in: query - description: instance + description: id required: true type: string responses: @@ -281,9 +281,9 @@ paths: produces: - '*/*' parameters: - - name: instance + - name: id in: query - description: instance + description: id required: true type: string responses: diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java index 5ae54ef0..09916057 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java @@ -155,9 +155,9 @@ public class PolicyController { @ApiResponse(code = 404, message = "Policy is not found")} // ) public ResponseEntity getPolicy( // - @RequestParam(name = "instance", required = true) String instance) { + @RequestParam(name = "id", required = true) String id) { try { - Policy p = policies.getPolicy(instance); + Policy p = policies.getPolicy(id); return new ResponseEntity<>(p.json(), HttpStatus.OK); } catch (ServiceException e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND); @@ -172,7 +172,7 @@ public class PolicyController { @ApiResponse(code = 404, message = "Policy is not found", response = String.class), @ApiResponse(code = 423, message = "RIC is not operational", response = String.class)}) public Mono> deletePolicy( // - @RequestParam(name = "instance", required = true) String id) { + @RequestParam(name = "id", required = true) String id) { try { Policy policy = policies.getPolicy(id); keepServiceAlive(policy.ownerServiceName()); @@ -202,7 +202,7 @@ public class PolicyController { }) public Mono> putPolicy( // @RequestParam(name = "type", required = false, defaultValue = "") String typeName, // - @RequestParam(name = "instance", required = true) String instanceId, // + @RequestParam(name = "id", required = true) String instanceId, // @RequestParam(name = "ric", required = true) String ricName, // @RequestParam(name = "service", required = true) String service, // @RequestBody Object jsonBody) { @@ -328,9 +328,9 @@ public class PolicyController { @ApiResponse(code = 404, message = "Policy is not found", response = String.class)} // ) public Mono> getPolicyStatus( // - @RequestParam(name = "instance", required = true) String instance) { + @RequestParam(name = "id", required = true) String id) { try { - Policy policy = policies.getPolicy(instance); + Policy policy = policies.getPolicy(id); return a1ClientFactory.createA1Client(policy.ric()) // .flatMap(client -> client.getPolicyStatus(policy)) // diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java index b7e9a4b2..1784fea7 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -247,9 +247,9 @@ public class ApplicationTest { private String putPolicyUrl(String serviceName, String ricName, String policyTypeName, String policyInstanceId) { if (policyTypeName.isEmpty()) { - return "/policy?instance=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName; + return "/policy?id=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName; } else { - return "/policy?instance=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName + "&type=" + return "/policy?id=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName + "&type=" + policyTypeName; } } @@ -320,17 +320,17 @@ public class ApplicationTest { // DELETE POLICY this.addPolicy("instance1", "type1", "service1", "ric1"); doReturn(Mono.error(a1Exception)).when(a1Client).deletePolicy(any()); - testErrorCode(restClient().delete("/policy?instance=instance1"), httpStatus, responseBody); + testErrorCode(restClient().delete("/policy?id=instance1"), httpStatus, responseBody); // GET STATUS this.addPolicy("instance1", "type1", "service1", "ric1"); doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any()); - testErrorCode(restClient().get("/policy_status?instance=instance1"), httpStatus, responseBody); + testErrorCode(restClient().get("/policy_status?id=instance1"), httpStatus, responseBody); // Check that empty response body is OK a1Exception = new WebClientResponseException(httpStatus.value(), "", null, null, null, null); doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any()); - testErrorCode(restClient().get("/policy_status?instance=instance1"), httpStatus); + testErrorCode(restClient().get("/policy_status?id=instance1"), httpStatus); } @Test @@ -363,7 +363,7 @@ public class ApplicationTest { @Test public void testGetPolicy() throws Exception { - String url = "/policy?instance=id"; + String url = "/policy?id=id"; Policy policy = addPolicy("id", "typeName", "service1", "ric1"); { String rsp = restClient().get(url).block(); @@ -380,7 +380,7 @@ public class ApplicationTest { addPolicy("id", "typeName", "service1", "ric1"); assertThat(policies.size()).isEqualTo(1); - String url = "/policy?instance=id"; + String url = "/policy?id=id"; ResponseEntity entity = restClient().deleteForEntity(url).block(); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); @@ -584,12 +584,12 @@ public class ApplicationTest { addPolicy("id", "typeName", "service1", "ric1"); assertThat(policies.size()).isEqualTo(1); - String url = "/policy_status?instance=id"; + String url = "/policy_status?id=id"; String rsp = restClient().get(url).block(); assertThat(rsp.equals("OK")).isTrue(); // GET non existing policy status - url = "/policy_status?instance=XXX"; + url = "/policy_status?id=XXX"; testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND); } diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java b/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java index 26e20912..f3aaa24d 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java @@ -115,12 +115,12 @@ class ConcurrencyTestRunnable implements Runnable { } private void putPolicy(String name) { - String putUrl = baseUrl + "/policy?type=type1&instance=" + name + "&ric=ric&service=service1"; + String putUrl = baseUrl + "/policy?type=type1&id=" + name + "&ric=ric&service=service1"; restTemplate.put(putUrl, createJsonHttpEntity("{}")); } private void deletePolicy(String name) { - String deleteUrl = baseUrl + "/policy?instance=" + name; + String deleteUrl = baseUrl + "/policy?id=" + name; restTemplate.delete(deleteUrl); }