From: PatrikBuhr Date: Fri, 7 Oct 2022 12:22:31 +0000 (+0200) Subject: NONRTRIC - added NBI feature X-Git-Tag: 1.4.0~6 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F99%2F9199%2F3;p=nonrtric%2Fplt%2Finformationcoordinatorservice.git NONRTRIC - added NBI feature Remove all jobs for one producer. Signed-off-by: PatrikBuhr Issue-ID: NONRTRIC-810 Change-Id: I02860756c9703d36fbf8b31ab262c1994988b3a5 --- diff --git a/api/ics-api.json b/api/ics-api.json index 8e5c982..3dece23 100644 --- a/api/ics-api.json +++ b/api/ics-api.json @@ -608,41 +608,60 @@ }}, "tags": ["Actuator"] }}, - "/data-consumer/v1/info-jobs": {"get": { - "summary": "Information Job identifiers", - "description": "query for information job identifiers", - "operationId": "getJobIds", - "responses": { - "200": { - "description": "Information information job identifiers", - "content": {"application/json": {"schema": { - "type": "array", - "items": {"type": "string"} - }}} + "/data-consumer/v1/info-jobs": { + "get": { + "summary": "Information Job identifiers", + "description": "query for information job identifiers", + "operationId": "getJobIds", + "responses": { + "200": { + "description": "Information information job identifiers", + "content": {"application/json": {"schema": { + "type": "array", + "items": {"type": "string"} + }}} + }, + "404": { + "description": "Information type is not found", + "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}} + } }, - "404": { - "description": "Information type is not found", - "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}} - } + "parameters": [ + { + "schema": {"type": "string"}, + "in": "query", + "name": "infoTypeId", + "description": "selects subscription jobs of matching information type", + "required": false + }, + { + "schema": {"type": "string"}, + "in": "query", + "name": "owner", + "description": "selects result for one owner", + "required": false + } + ], + "tags": ["Data consumer"] }, - "parameters": [ - { - "schema": {"type": "string"}, - "in": "query", - "name": "infoTypeId", - "description": "selects subscription jobs of matching information type", - "required": false - }, - { + "delete": { + "summary": "Information Jobs", + "description": "delete all jobs for one owner", + "operationId": "deleteJobsForOwner", + "responses": {"204": { + "description": "No Content", + "content": {"application/json": {"schema": {"type": "object"}}} + }}, + "parameters": [{ "schema": {"type": "string"}, "in": "query", "name": "owner", "description": "selects result for one owner", - "required": false - } - ], - "tags": ["Data consumer"] - }}, + "required": true + }], + "tags": ["Data consumer"] + } + }, "/actuator/loggers/{name}": { "post": { "summary": "Actuator web endpoint 'loggers-name'", diff --git a/api/ics-api.yaml b/api/ics-api.yaml index 9548822..653f529 100644 --- a/api/ics-api.yaml +++ b/api/ics-api.yaml @@ -456,6 +456,28 @@ paths: application/json: schema: $ref: '#/components/schemas/ProblemDetails' + delete: + tags: + - Data consumer + summary: Information Jobs + description: delete all jobs for one owner + operationId: deleteJobsForOwner + parameters: + - name: owner + in: query + description: selects result for one owner + required: true + style: form + explode: true + schema: + type: string + responses: + 204: + description: No Content + content: + application/json: + schema: + type: object /actuator/loggers/{name}: get: tags: diff --git a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java index 2690974..e8b6dff 100644 --- a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java +++ b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java @@ -183,6 +183,28 @@ public class ConsumerController { } } + @DeleteMapping(path = "/info-jobs", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Information Jobs", description = "delete all jobs for one owner") + @ApiResponses( + value = { // + @ApiResponse(responseCode = "204") // + }) + public ResponseEntity deleteJobsForOwner( // + + @Parameter( + name = ConsumerConsts.OWNER_PARAM, + required = true, // + description = ConsumerConsts.OWNER_PARAM_DESCRIPTION) // + @RequestParam(name = ConsumerConsts.OWNER_PARAM, required = true) String owner) { + + for (InfoJob job : this.infoJobs.getJobsForOwner(owner)) { + + logger.debug("DELETE info jobs, id: {}, type: {}, owner: {}", job.getId(), job.getTypeId(), owner); + this.infoJobs.remove(job, this.infoProducers); + } + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + @GetMapping(path = "/info-jobs/{infoJobId}", produces = MediaType.APPLICATION_JSON_VALUE) // @Operation(summary = ConsumerConsts.INDIVIDUAL_JOB, description = "") // @ApiResponses( diff --git a/src/test/java/org/oransc/ics/ApplicationTest.java b/src/test/java/org/oransc/ics/ApplicationTest.java index b08c455..73a79ee 100644 --- a/src/test/java/org/oransc/ics/ApplicationTest.java +++ b/src/test/java/org/oransc/ics/ApplicationTest.java @@ -220,6 +220,23 @@ class ApplicationTest { assertThat(rsp).isEqualTo("[\"test\"]"); } + @Test + void consumerDeleteJobsForOneOwner() throws Exception { + putInfoProducerWithOneType("producer1", TYPE_ID); + putInfoJob(TYPE_ID, "jobId1"); + putInfoJob(TYPE_ID, "jobId2"); + putInfoJob(TYPE_ID, "jobId3", "otherOwner"); + assertThat(this.infoJobs.size()).isEqualTo(3); + String url = ConsumerConsts.API_ROOT + "/info-jobs?owner=owner"; + restClient().delete(url).block(); + assertThat(this.infoJobs.size()).isEqualTo(1); + + assertThat(this.producerSimulator.getTestResults().jobsStarted).hasSize(3); + + await().untilAsserted(() -> assertThat(this.producerSimulator.getTestResults().jobsStopped).hasSize(2)); + + } + @Test void a1eGetEiTypesEmpty() throws Exception { String url = A1eConsts.API_ROOT + "/eitypes"; @@ -586,8 +603,7 @@ class ApplicationTest { } @Test - void producerPutProducerWithOneType_rejecting() - throws JsonMappingException, JsonProcessingException, ServiceException { + void producerPutProducerWithOneType_rejecting() throws Exception { putInfoProducerWithOneTypeRejecting("simulateProducerError", TYPE_ID); String url = A1eConsts.API_ROOT + "/eijobs/" + EI_JOB_ID; String body = gson.toJson(infoJobInfo()); @@ -683,7 +699,7 @@ class ApplicationTest { } @Test - void producerGetInfoJobsForProducer() throws JsonMappingException, JsonProcessingException, ServiceException { + void producerGetInfoJobsForProducer() throws Exception { putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID); putInfoJob(TYPE_ID, "jobId1"); putInfoJob(TYPE_ID, "jobId2"); @@ -729,7 +745,7 @@ class ApplicationTest { } @Test - void a1eJobStatusNotifications() throws JsonMappingException, JsonProcessingException, ServiceException { + void a1eJobStatusNotifications() throws Exception { A1eCallbacksSimulatorController.TestResults consumerCalls = this.a1eCallbacksSimulator.getTestResults(); ProducerSimulatorController.TestResults producerCalls = this.producerSimulator.getTestResults(); @@ -753,7 +769,7 @@ class ApplicationTest { } @Test - void a1eJobStatusNotifications2() throws JsonMappingException, JsonProcessingException, ServiceException { + void a1eJobStatusNotifications2() throws Exception { // Test replacing a producer with new and removed types // Create a job @@ -803,7 +819,7 @@ class ApplicationTest { } @Test - void producerSupervision() throws JsonMappingException, JsonProcessingException, ServiceException { + void producerSupervision() throws Exception { A1eCallbacksSimulatorController.TestResults consumerResults = this.a1eCallbacksSimulator.getTestResults(); putInfoProducerWithOneTypeRejecting("simulateProducerError", TYPE_ID); @@ -847,7 +863,7 @@ class ApplicationTest { } @Test - void producerSupervision2() throws JsonMappingException, JsonProcessingException, ServiceException { + void producerSupervision2() throws Exception { // Test that supervision enables not enabled jobs and sends a notification when // suceeded @@ -1127,12 +1143,17 @@ class ApplicationTest { baseUrl() + A1eCallbacksSimulatorController.getJobStatusUrl(infoJobId)); } - private A1eEiJobInfo infoJobInfo() throws JsonMappingException, JsonProcessingException { + private A1eEiJobInfo infoJobInfo() throws Exception { return infoJobInfo(TYPE_ID, EI_JOB_ID); } - A1eEiJobInfo infoJobInfo(String typeId, String infoJobId) throws JsonMappingException, JsonProcessingException { - return new A1eEiJobInfo(typeId, jsonObject(), "owner", "https://junk.com", + A1eEiJobInfo infoJobInfo(String typeId, String infoJobId) throws Exception { + return infoJobInfo(typeId, infoJobId, "owner"); + + } + + A1eEiJobInfo infoJobInfo(String typeId, String infoJobId, String owner) throws Exception { + return new A1eEiJobInfo(typeId, jsonObject(), owner, "https://junk.com", baseUrl() + A1eCallbacksSimulatorController.getJobStatusUrl(infoJobId)); } @@ -1169,8 +1190,16 @@ class ApplicationTest { return jsonObject("{ " + EI_JOB_PROPERTY + " : \"value\" }"); } - private InfoJob putInfoJob(String infoTypeId, String jobId) - throws JsonMappingException, JsonProcessingException, ServiceException { + private InfoJob putInfoJob(String infoTypeId, String jobId, String owner) throws Exception { + String url = A1eConsts.API_ROOT + "/eijobs/" + jobId; + String body = gson.toJson(infoJobInfo(infoTypeId, jobId, owner)); + restClient().putForEntity(url, body).block(); + + return this.infoJobs.getJob(jobId); + + } + + private InfoJob putInfoJob(String infoTypeId, String jobId) throws Exception { String url = A1eConsts.API_ROOT + "/eijobs/" + jobId; String body = gson.toJson(infoJobInfo(infoTypeId, jobId));