Get data job result 83/138583/6
authorleventecsanyi <levente.csanyi@est.tech>
Fri, 26 Jul 2024 11:25:12 +0000 (13:25 +0200)
committerleventecsanyi <levente.csanyi@est.tech>
Fri, 26 Jul 2024 14:41:38 +0000 (16:41 +0200)
    - extended openapi
    - added not-implemented http error for result endpoint
    - added testware
    - added stub implementation
    - fixed writeDataJob bug in stub

Issue-ID: CPS-2296
Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
Change-Id: I9398cb73b635bec360df886372690187ff54e0d4

dmi-service/openapi/openapi-datajob.yml
dmi-service/src/main/java/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestController.java
dmi-service/src/test/groovy/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestControllerSpec.groovy
dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java
docs/api/swagger/openapi-datajob.yaml

index 68ee3ec..aa93623 100644 (file)
@@ -74,6 +74,20 @@ paths:
       responses:
         "501":
           $ref: '#/components/responses/NotImplemented'
+  /v1/dataJob/{requestId}/dataProducerJob/{dataProducerJobId}/result:
+    get:
+      description: Retrieve the result of a data job.
+      operationId: getDataJobResult
+      parameters:
+        - $ref: '#/components/parameters/requestIdInPath'
+        - $ref: '#/components/parameters/dataProducerJobIdInPath'
+        - $ref: '#/components/parameters/dataProducerIdInQuery'
+        - $ref: '#/components/parameters/destinationInQuery'
+      tags:
+        - dmi-datajob
+      responses:
+        "501":
+          $ref: '#/components/responses/NotImplemented'
 
 components:
   parameters:
@@ -101,6 +115,14 @@ components:
       schema:
         type: string
         example: some-data-producer-identifier
+    destinationInQuery:
+      name: destination
+      in: query
+      description: The destination of the results (Kafka topic name or s3 bucket name)
+      required: true
+      schema:
+        type: string
+        example: some-destination
   schemas:
     ErrorMessage:
       type: object
index 8cf9f1f..928ec6b 100644 (file)
@@ -34,13 +34,13 @@ public class DmiDatajobsRestController implements DmiDatajobApi {
     /**
      * This method is not implemented for ONAP DMI plugin.
      *
-     * @param requestId Identifier for the overall Datajob (required)
-     * @param subjobReadRequest Operation body (optional)
-     * @return (@ code ResponseEntity) response entity
+     * @param requestId                Identifier for the overall Datajob (required)
+     * @param subjobReadRequest        Operation body (optional)
+     * @return (@ code ResponseEntity) Response entity
      */
     @Override
     public ResponseEntity<Void> readDataJob(final String requestId,
-                                              final SubjobReadRequest subjobReadRequest) {
+                                            final SubjobReadRequest subjobReadRequest) {
 
         return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
     }
@@ -48,23 +48,23 @@ public class DmiDatajobsRestController implements DmiDatajobApi {
     /**
      * This method is not implemented for ONAP DMI plugin.
      *
-     * @param requestId Identifier for the overall Datajob (required)
-     * @param subjobWriteRequest Operation body (optional)
-     * @return (@ code ResponseEntity) response entity
+     * @param requestId                Identifier for the overall Datajob (required)
+     * @param subjobWriteRequest       Operation body (optional)
+     * @return (@ code ResponseEntity) Response entity
      */
     @Override
     public ResponseEntity<Void> writeDataJob(final String requestId,
-                                                               final SubjobWriteRequest subjobWriteRequest) {
+                                             final SubjobWriteRequest subjobWriteRequest) {
         return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
     }
 
     /**
      * This method is not implemented for ONAP DMI plugin.
      *
-     * @param requestId Identifier for the overall Datajob (required)
-     * @param dataProducerJobId Identifier for the data producer job (required)
-     * @param dataProducerId Identifier for the data producer as a query parameter (required)
-     * @return ResponseEntity(Void) response entity indicating the method is not implemented
+     * @param requestId             Identifier for the overall Datajob (required)
+     * @param dataProducerJobId     Identifier for the data producer job (required)
+     * @param dataProducerId        Identifier for the data producer as a query parameter (required)
+     * @return ResponseEntity       Response entity indicating the method is not implemented
      */
     @Override
     public ResponseEntity<Void> getDataJobStatus(final String requestId,
@@ -72,4 +72,21 @@ public class DmiDatajobsRestController implements DmiDatajobApi {
                                                  final String dataProducerId) {
         return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
     }
+
+    /**
+     * This method is not implemented for ONAP DMI plugin.
+     *
+     * @param requestId             Identifier for the overall Datajob (required)
+     * @param dataProducerJobId     Identifier for the data producer job (required)
+     * @param dataProducerId        Identifier for the data producer as a query parameter (required)
+     * @param destination           The destination of the results, Kafka topic name or s3 bucket name (required)
+     * @return ResponseEntity       Response entity indicating the method is not implemented
+     */
+    @Override
+    public ResponseEntity<Void> getDataJobResult(final String requestId,
+                                                 final String dataProducerJobId,
+                                                 final String dataProducerId,
+                                                 final String destination) {
+        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+    }
 }
index 69d2ebd..6c05f6f 100644 (file)
@@ -79,4 +79,16 @@ class DmiDatajobsRestControllerSpec extends Specification{
         then: 'response value is Not Implemented'
             response.status == HttpStatus.NOT_IMPLEMENTED.value()
     }
+
+    def 'get result request should return 501 HTTP Status' () {
+        given: 'URL to get the result of a data job'
+            def getStatus = "${basePathV1}/dataJob/some-identifier/dataProducerJob/some-producer-job-identifier/result?dataProducerId=some-data-producer-identifier&destination=some-destination"
+        when: 'the request is performed'
+            def response = mvc.perform(
+                    get(getStatus)
+                            .contentType('application/json')
+            ).andReturn().response
+        then: 'response value is Not Implemented'
+            response.status == HttpStatus.NOT_IMPLEMENTED.value()
+    }
 }
index b8b46f0..5021ae7 100644 (file)
@@ -89,7 +89,7 @@ public class DmiRestStubController {
     private long readDataForCmHandleDelayMs;
     @Value("${delay.write-data-for-cm-handle-delay-ms}")
     private long writeDataForCmHandleDelayMs;
-    private AtomicInteger subJobWriteRequestCounter;
+    private final AtomicInteger subJobWriteRequestCounter = new AtomicInteger();
 
     /**
      * This code defines a REST API endpoint for adding new the module set tag mapping. The endpoint receives the
@@ -293,6 +293,27 @@ public class DmiRestStubController {
         return ResponseEntity.ok("FINISHED");
     }
 
+    /**
+     * Retrieves the result of a given data job identified by {@code requestId} and {@code dataProducerJobId}.
+     *
+     * @param requestId             Identifier for the overall Datajob (required)
+     * @param dataProducerJobId     Identifier for the data producer job (required)
+     * @param dataProducerId        Identifier for the data producer as a query parameter (required)
+     * @param destination           The destination of the results, Kafka topic name or s3 bucket name (required)
+     * @return A ResponseEntity with HTTP status 200 (OK) and the data job's result as an Object.
+     */
+    @GetMapping("/v1/dataJob/{requestId}/dataProducerJob/{dataProducerJobId}/result")
+    public ResponseEntity<Object> retrieveDataJobResult(
+            @PathVariable("requestId") final String requestId,
+            @PathVariable("dataProducerJobId") final String dataProducerJobId,
+            @RequestParam(name = "dataProducerId") String dataProducerId,
+            @RequestParam(name = "destination") String destination) {
+        log.debug("Received request to retrieve data job result. Request ID: {}, Data Producer Job ID: {}, " +
+                        "Data Producer ID: {}, Destination: {}",
+                requestId, dataProducerJobId, dataProducerId, destination);
+        return ResponseEntity.ok(Map.of("result", "some status"));
+    }
+
     private CloudEvent buildAndGetCloudEvent(final String topic, final String requestId,
                                              final DataOperationEvent dataOperationEvent) {
         CloudEvent cloudEvent = null;
index a0b6d4f..18efbc3 100644 (file)
@@ -121,6 +121,60 @@ paths:
           description: Not Implemented
       tags:
         - dmi-datajob
+  /v1/dataJob/{requestId}/dataProducerJob/{dataProducerJobId}/result:
+    get:
+      description: Retrieve the result of a data job.
+      operationId: getDataJobResult
+      parameters:
+        - description: Identifier for the overall Datajob
+          explode: false
+          in: path
+          name: requestId
+          required: true
+          schema:
+            example: some-identifier
+            type: string
+          style: simple
+        - description: Identifier for the data producer job
+          explode: false
+          in: path
+          name: dataProducerJobId
+          required: true
+          schema:
+            example: some-producer-job-identifier
+            type: string
+          style: simple
+        - description: Identifier for the data producer
+          explode: true
+          in: query
+          name: dataProducerId
+          required: true
+          schema:
+            example: some-data-producer-identifier
+            type: string
+          style: form
+        - description: The destination of the results (Kafka topic name or s3 bucket name)
+          explode: true
+          in: query
+          name: destination
+          required: true
+          schema:
+            example: some-destination
+            type: string
+          style: form
+      responses:
+        "501":
+          content:
+            application/json:
+              example:
+                status: 501
+                message: Not Implemented
+                details: Method Not Implemented
+              schema:
+                $ref: '#/components/schemas/ErrorMessage'
+          description: Not Implemented
+      tags:
+        - dmi-datajob
 components:
   parameters:
     requestIdInPath:
@@ -153,6 +207,16 @@ components:
         example: some-data-producer-identifier
         type: string
       style: form
+    destinationInQuery:
+      description: The destination of the results (Kafka topic name or s3 bucket name)
+      explode: true
+      in: query
+      name: destination
+      required: true
+      schema:
+        example: some-destination
+        type: string
+      style: form
   responses:
     NotImplemented:
       content: