From 08d483a877c24c3668f77dc8404ee54cd1e041ab Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Thu, 29 Oct 2020 10:01:13 +0100 Subject: [PATCH] Improvments of the producer API callbacks Change-Id: Ibf869dcc604b12fc4f80ba811e502613723efada Signed-off-by: PatrikBuhr Issue-ID: NONRTRIC-305 --- enrichment-coordinator-service/docs/api.json | 119 ++++++++++----------- .../controllers/producer/ProducerCallbacks.java | 13 +-- .../controllers/producer/ProducerController.java | 7 +- .../producer/ProducerRegistrationInfo.java | 20 ++-- .../oransc/enrichment/repository/EiProducer.java | 12 +-- .../org/oransc/enrichment/ApplicationTest.java | 9 +- .../controller/ProducerSimulatorController.java | 28 ++--- 7 files changed, 94 insertions(+), 114 deletions(-) diff --git a/enrichment-coordinator-service/docs/api.json b/enrichment-coordinator-service/docs/api.json index d5cbad59..a8df3c7c 100644 --- a/enrichment-coordinator-service/docs/api.json +++ b/enrichment-coordinator-service/docs/api.json @@ -1,21 +1,27 @@ { "basePath": "/", "paths": { - "/producer_simulator/supervision": {"get": { - "summary": "Producer supervision", + "/producer_simulator/ei_job": {"post": { + "summary": "Callback for EI job creation", "deprecated": false, "produces": ["application/json"], - "operationId": "producerSupervisionUsingGET", + "operationId": "jobCreatedCallbackUsingPOST", "responses": { - "200": { - "schema": {"type": "string"}, - "description": "OK" - }, + "200": {"description": "OK"}, + "201": {"description": "Created"}, "401": {"description": "Unauthorized"}, "403": {"description": "Forbidden"}, "404": {"description": "Not Found"} }, - "tags": ["Producer Callbacks"] + "parameters": [{ + "schema": {"$ref": "#/definitions/producer_ei_job_request"}, + "in": "body", + "name": "request", + "description": "request", + "required": true + }], + "tags": ["Producer Callbacks"], + "consumes": ["application/json"] }}, "/A1-EI/v1/eitypes/{eiTypeId}": {"get": { "summary": "Individual EI type", @@ -112,28 +118,6 @@ }, "tags": ["A1-EI (enrichment information)"] }}, - "/producer_simulator/job_deleted": {"post": { - "summary": "Callback for EI job deletion", - "deprecated": false, - "produces": ["application/json"], - "operationId": "jobDeletedCallbackUsingPOST", - "responses": { - "200": {"description": "OK"}, - "201": {"description": "Created"}, - "401": {"description": "Unauthorized"}, - "403": {"description": "Forbidden"}, - "404": {"description": "Not Found"} - }, - "parameters": [{ - "schema": {"$ref": "#/definitions/producer_ei_job_request"}, - "in": "body", - "name": "request", - "description": "request", - "required": true - }], - "tags": ["Producer Callbacks"], - "consumes": ["application/json"] - }}, "/ei-producer/v1/eiproducers/{eiProducerId}/status": {"get": { "summary": "EI producer status", "deprecated": false, @@ -160,6 +144,26 @@ }], "tags": ["Enrichment Data Producer API"] }}, + "/producer_simulator/ei_job/{eiJobId}": {"delete": { + "summary": "Callback for EI job deletion", + "deprecated": false, + "produces": ["application/json"], + "operationId": "jobDeletedCallbackUsingDELETE", + "responses": { + "200": {"description": "OK"}, + "401": {"description": "Unauthorized"}, + "204": {"description": "No Content"}, + "403": {"description": "Forbidden"} + }, + "parameters": [{ + "in": "path", + "name": "eiJobId", + "description": "eiJobId", + "type": "string", + "required": true + }], + "tags": ["Producer Callbacks"] + }}, "/ei-producer/v1/eiproducers": {"get": { "summary": "EI producer identifiers", "deprecated": false, @@ -390,6 +394,22 @@ "consumes": ["application/json"] } }, + "/producer_simulator/health_check": {"get": { + "summary": "Producer supervision", + "deprecated": false, + "produces": ["application/json"], + "operationId": "producerSupervisionUsingGET", + "responses": { + "200": { + "schema": {"type": "string"}, + "description": "OK" + }, + "401": {"description": "Unauthorized"}, + "403": {"description": "Forbidden"}, + "404": {"description": "Not Found"} + }, + "tags": ["Producer Callbacks"] + }}, "/ei-producer/v1/eiproducers/{eiProducerId}/eijobs": {"get": { "summary": "EI job definitions", "deprecated": false, @@ -486,31 +506,9 @@ "required": true }], "tags": ["A1-EI (enrichment information)"] - }}, - "/producer_simulator/job_created": {"post": { - "summary": "Callback for EI job creation", - "deprecated": false, - "produces": ["application/json"], - "operationId": "jobCreatedCallbackUsingPOST", - "responses": { - "200": {"description": "OK"}, - "201": {"description": "Created"}, - "401": {"description": "Unauthorized"}, - "403": {"description": "Forbidden"}, - "404": {"description": "Not Found"} - }, - "parameters": [{ - "schema": {"$ref": "#/definitions/producer_ei_job_request"}, - "in": "body", - "name": "request", - "description": "request", - "required": true - }], - "tags": ["Producer Callbacks"], - "consumes": ["application/json"] }} }, - "host": "localhost:38499", + "host": "localhost:41549", "definitions": { "producer_ei_job_request": { "description": "The body of the EI producer callbacks for EI job creation and deletion", @@ -607,8 +605,7 @@ "type": "object", "title": "producer_registration_info", "required": [ - "ei_job_creation_callback_url", - "ei_job_deletion_callback_url", + "ei_job_callback_url", "ei_producer_supervision_callback_url", "supported_ei_types" ], @@ -618,17 +615,13 @@ "type": "array", "items": {"$ref": "#/definitions/producer_ei_type_registration_info"} }, - "ei_job_creation_callback_url": { - "description": "callback for job creation", - "type": "string" - }, - "ei_job_deletion_callback_url": { - "description": "callback for job deletion", - "type": "string" - }, "ei_producer_supervision_callback_url": { "description": "callback for producer supervision", "type": "string" + }, + "ei_job_callback_url": { + "description": "callback for EI job", + "type": "string" } } }, diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerCallbacks.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerCallbacks.java index e00ac74d..5a47b58f 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerCallbacks.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerCallbacks.java @@ -62,12 +62,13 @@ public class ProducerCallbacks { } public void notifyProducersJobDeleted(EiJob eiJob) { - ProducerJobInfo request = new ProducerJobInfo(eiJob); - String body = gson.toJson(request); for (EiProducer producer : getProducers(eiJob)) { - restClient.post(producer.getJobDeletionCallbackUrl(), body) // - .subscribe(notUsed -> logger.debug("Job deleted OK {}", producer.getId()), // - throwable -> logger.warn("Job delete failed {}", producer.getId(), throwable.toString()), null); + String url = producer.getJobCallbackUrl() + "/" + eiJob.id(); + restClient.delete(url) // + .subscribe(notUsed -> logger.debug("Producer job deleted OK {}", producer.getId()), // + throwable -> logger.warn("Producer job delete failed {} {}", producer.getId(), + throwable.getMessage()), + null); } } @@ -95,7 +96,7 @@ public class ProducerCallbacks { ProducerJobInfo request = new ProducerJobInfo(eiJob); String body = gson.toJson(request); - return restClient.post(producer.getJobCreationCallbackUrl(), body) + return restClient.post(producer.getJobCallbackUrl(), body) .doOnNext(resp -> logger.debug("Job subscription started OK {}", producer.getId())) .onErrorResume(throwable -> { logger.warn("Job subscription failed {}", producer.getId(), throwable.toString()); diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java index 9bfa2d20..c670ea4a 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java @@ -290,8 +290,8 @@ public class ProducerController { } EiProducer createProducer(Collection types, String producerId, ProducerRegistrationInfo registrationInfo) { - return new EiProducer(producerId, types, registrationInfo.jobCreationCallbackUrl, - registrationInfo.jobDeletionCallbackUrl, registrationInfo.producerSupervisionCallbackUrl); + return new EiProducer(producerId, types, registrationInfo.jobCallbackUrl, + registrationInfo.producerSupervisionCallbackUrl); } private EiProducer registerProducer(String producerId, ProducerRegistrationInfo registrationInfo) { @@ -317,8 +317,7 @@ public class ProducerController { for (EiType type : p.getEiTypes()) { types.add(toEiTypeRegistrationInfo(type)); } - return new ProducerRegistrationInfo(types, p.getJobCreationCallbackUrl(), p.getJobDeletionCallbackUrl(), - p.getProducerSupervisionCallbackUrl()); + return new ProducerRegistrationInfo(types, p.getJobCallbackUrl(), p.getProducerSupervisionCallbackUrl()); } private ProducerEiTypeRegistrationInfo toEiTypeRegistrationInfo(EiType type) { diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java index 859443d6..3f785803 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java @@ -62,26 +62,20 @@ public class ProducerRegistrationInfo { @JsonProperty(value = "supported_ei_types", required = true) public Collection types; - @ApiModelProperty(value = "callback for job creation", required = true) - @SerializedName("ei_job_creation_callback_url") - @JsonProperty(value = "ei_job_creation_callback_url", required = true) - public String jobCreationCallbackUrl; - - @ApiModelProperty(value = "callback for job deletion", required = true) - @SerializedName("ei_job_deletion_callback_url") - @JsonProperty(value = "ei_job_deletion_callback_url", required = true) - public String jobDeletionCallbackUrl; + @ApiModelProperty(value = "callback for EI job", required = true) + @SerializedName("ei_job_callback_url") + @JsonProperty(value = "ei_job_callback_url", required = true) + public String jobCallbackUrl; @ApiModelProperty(value = "callback for producer supervision", required = true) @SerializedName("ei_producer_supervision_callback_url") @JsonProperty(value = "ei_producer_supervision_callback_url", required = true) public String producerSupervisionCallbackUrl; - public ProducerRegistrationInfo(Collection types, String jobCreationCallbackUrl, - String jobDeletionCallbackUrl, String producerSupervisionCallbackUrl) { + public ProducerRegistrationInfo(Collection types, String jobCallbackUrl, + String producerSupervisionCallbackUrl) { this.types = types; - this.jobCreationCallbackUrl = jobCreationCallbackUrl; - this.jobDeletionCallbackUrl = jobDeletionCallbackUrl; + this.jobCallbackUrl = jobCallbackUrl; this.producerSupervisionCallbackUrl = producerSupervisionCallbackUrl; } diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/repository/EiProducer.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/repository/EiProducer.java index 99932a72..63e5d4c9 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/repository/EiProducer.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/repository/EiProducer.java @@ -32,22 +32,18 @@ public class EiProducer { private final Collection eiTypes; @Getter - private final String jobCreationCallbackUrl; - - @Getter - private final String jobDeletionCallbackUrl; + private final String jobCallbackUrl; @Getter private final String producerSupervisionCallbackUrl; private int unresponsiveCounter = 0; - public EiProducer(String id, Collection eiTypes, String jobCreationCallbackUrl, - String jobDeletionCallbackUrl, String producerSupervisionCallbackUrl) { + public EiProducer(String id, Collection eiTypes, String jobCallbackUrl, + String producerSupervisionCallbackUrl) { this.id = id; this.eiTypes = eiTypes; - this.jobCreationCallbackUrl = jobCreationCallbackUrl; - this.jobDeletionCallbackUrl = jobDeletionCallbackUrl; + this.jobCallbackUrl = jobCallbackUrl; this.producerSupervisionCallbackUrl = producerSupervisionCallbackUrl; } diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java index e707fb78..3dab4608 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java @@ -258,7 +258,7 @@ class ApplicationTest { ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults(); await().untilAsserted(() -> assertThat(simulatorResults.jobsStopped.size()).isEqualTo(1)); - assertThat(simulatorResults.jobsStopped.get(0).id).isEqualTo("jobId"); + assertThat(simulatorResults.jobsStopped.get(0)).isEqualTo("jobId"); } @Test @@ -558,8 +558,7 @@ class ApplicationTest { Collection types = new ArrayList<>(); types.add(producerEiTypeRegistrationInfo(typeId)); return new ProducerRegistrationInfo(types, // - baseUrl() + ProducerSimulatorController.JOB_CREATED_ERROR_URL, - baseUrl() + ProducerSimulatorController.JOB_DELETED_ERROR_URL, + baseUrl() + ProducerSimulatorController.JOB_ERROR_URL, baseUrl() + ProducerSimulatorController.SUPERVISION_ERROR_URL); } @@ -568,9 +567,7 @@ class ApplicationTest { Collection types = new ArrayList<>(); types.add(producerEiTypeRegistrationInfo(typeId)); return new ProducerRegistrationInfo(types, // - baseUrl() + ProducerSimulatorController.JOB_CREATED_URL, - baseUrl() + ProducerSimulatorController.JOB_DELETED_URL, - baseUrl() + ProducerSimulatorController.SUPERVISION_URL); + baseUrl() + ProducerSimulatorController.JOB_URL, baseUrl() + ProducerSimulatorController.SUPERVISION_URL); } private ConsumerEiJobInfo eiJobInfo() throws JsonMappingException, JsonProcessingException { diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java index cc61d21d..2a3688cf 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java @@ -40,7 +40,9 @@ import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -51,18 +53,16 @@ public class ProducerSimulatorController { private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - public static final String JOB_CREATED_URL = "/producer_simulator/job_created"; - public static final String JOB_DELETED_URL = "/producer_simulator/job_deleted"; - public static final String JOB_CREATED_ERROR_URL = "/producer_simulator/job_created_error"; - public static final String JOB_DELETED_ERROR_URL = "/producer_simulator/job_deleted_error"; + public static final String JOB_URL = "/producer_simulator/ei_job"; + public static final String JOB_ERROR_URL = "/producer_simulator/ei_job_error"; - public static final String SUPERVISION_URL = "/producer_simulator/supervision"; - public static final String SUPERVISION_ERROR_URL = "/producer_simulator/supervision_error"; + public static final String SUPERVISION_URL = "/producer_simulator/health_check"; + public static final String SUPERVISION_ERROR_URL = "/producer_simulator/health_check_error"; public static class TestResults { public List jobsStarted = Collections.synchronizedList(new ArrayList()); - public List jobsStopped = Collections.synchronizedList(new ArrayList()); + public List jobsStopped = Collections.synchronizedList(new ArrayList()); public int noOfRejectedCreate = 0; public int noOfRejectedDelete = 0; public boolean errorFound = false; @@ -82,7 +82,7 @@ public class ProducerSimulatorController { @Getter private TestResults testResults = new TestResults(); - @PostMapping(path = JOB_CREATED_URL, produces = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(path = JOB_URL, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "Callback for EI job creation", notes = "") @ApiResponses( value = { // @@ -103,24 +103,24 @@ public class ProducerSimulatorController { } } - @PostMapping(path = JOB_DELETED_URL, produces = MediaType.APPLICATION_JSON_VALUE) + @DeleteMapping(path = "/producer_simulator/ei_job/{eiJobId}", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "Callback for EI job deletion", notes = "") @ApiResponses( value = { // @ApiResponse(code = 200, message = "OK", response = VoidResponse.class)}// ) public ResponseEntity jobDeletedCallback( // - @RequestBody ProducerJobInfo request) { + @PathVariable("eiJobId") String eiJobId) { try { - logger.info("Job deleted callback {}", request.id); - this.testResults.jobsStopped.add(request); + logger.info("Job deleted callback {}", eiJobId); + this.testResults.jobsStopped.add(eiJobId); return new ResponseEntity<>(HttpStatus.OK); } catch (Exception e) { return ErrorResponse.create(e, HttpStatus.NOT_FOUND); } } - @PostMapping(path = JOB_CREATED_ERROR_URL, produces = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(path = JOB_ERROR_URL, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "Callback for EI job creation, returns error", notes = "", hidden = true) @ApiResponses( value = { // @@ -133,7 +133,7 @@ public class ProducerSimulatorController { return ErrorResponse.create("Producer returns error on create job", HttpStatus.NOT_FOUND); } - @PostMapping(path = JOB_DELETED_ERROR_URL, produces = MediaType.APPLICATION_JSON_VALUE) + @DeleteMapping(path = JOB_ERROR_URL + "/{eiJobId}", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "Callback for EI job creation, returns error", notes = "", hidden = true) @ApiResponses( value = { // -- 2.16.6