Improvments of the producer API callbacks 38/4938/1
authorPatrikBuhr <patrik.buhr@est.tech>
Thu, 29 Oct 2020 09:01:13 +0000 (10:01 +0100)
committerPatrikBuhr <patrik.buhr@est.tech>
Thu, 29 Oct 2020 09:02:18 +0000 (10:02 +0100)
Change-Id: Ibf869dcc604b12fc4f80ba811e502613723efada
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Issue-ID: NONRTRIC-305

enrichment-coordinator-service/docs/api.json
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerCallbacks.java
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/repository/EiProducer.java
enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java
enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java

index d5cbad5..a8df3c7 100644 (file)
@@ -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",
             },
             "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,
             }],
             "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,
                 "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,
                 "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",
             "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"
             ],
                     "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"
                 }
             }
         },
index e00ac74..5a47b58 100644 (file)
@@ -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());
index 9bfa2d2..c670ea4 100644 (file)
@@ -290,8 +290,8 @@ public class ProducerController {
     }
 
     EiProducer createProducer(Collection<EiType> 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) {
index 859443d..3f78580 100644 (file)
@@ -62,26 +62,20 @@ public class ProducerRegistrationInfo {
     @JsonProperty(value = "supported_ei_types", required = true)
     public Collection<ProducerEiTypeRegistrationInfo> 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<ProducerEiTypeRegistrationInfo> types, String jobCreationCallbackUrl,
-        String jobDeletionCallbackUrl, String producerSupervisionCallbackUrl) {
+    public ProducerRegistrationInfo(Collection<ProducerEiTypeRegistrationInfo> types, String jobCallbackUrl,
+        String producerSupervisionCallbackUrl) {
         this.types = types;
-        this.jobCreationCallbackUrl = jobCreationCallbackUrl;
-        this.jobDeletionCallbackUrl = jobDeletionCallbackUrl;
+        this.jobCallbackUrl = jobCallbackUrl;
         this.producerSupervisionCallbackUrl = producerSupervisionCallbackUrl;
     }
 
index 99932a7..63e5d4c 100644 (file)
@@ -32,22 +32,18 @@ public class EiProducer {
     private final Collection<EiType> 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<EiType> eiTypes, String jobCreationCallbackUrl,
-        String jobDeletionCallbackUrl, String producerSupervisionCallbackUrl) {
+    public EiProducer(String id, Collection<EiType> eiTypes, String jobCallbackUrl,
+        String producerSupervisionCallbackUrl) {
         this.id = id;
         this.eiTypes = eiTypes;
-        this.jobCreationCallbackUrl = jobCreationCallbackUrl;
-        this.jobDeletionCallbackUrl = jobDeletionCallbackUrl;
+        this.jobCallbackUrl = jobCallbackUrl;
         this.producerSupervisionCallbackUrl = producerSupervisionCallbackUrl;
     }
 
index e707fb7..3dab460 100644 (file)
@@ -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<ProducerEiTypeRegistrationInfo> 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<ProducerEiTypeRegistrationInfo> 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 {
index cc61d21..2a3688c 100644 (file)
@@ -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<ProducerJobInfo> jobsStarted = Collections.synchronizedList(new ArrayList<ProducerJobInfo>());
-        public List<ProducerJobInfo> jobsStopped = Collections.synchronizedList(new ArrayList<ProducerJobInfo>());
+        public List<String> jobsStopped = Collections.synchronizedList(new ArrayList<String>());
         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<Object> 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 = { //