From aa4d6e27a7488ff06aae8b97aac9b45d3e4d3bfe Mon Sep 17 00:00:00 2001 From: leventecsanyi Date: Thu, 18 Jul 2024 13:45:35 +0200 Subject: Added DataJob related stub implementations - updated pom.xml - added dataJob related code to DMI Stub controller - uplifted swagger core dependency Issue-ID: CPS-2323 Signed-off-by: leventecsanyi Change-Id: If30e1fad31daec004ad67dd3f2be1815aeb538b2 --- dmi-service/openapi/openapi-datajob.yml | 20 ++++++- dmi-service/pom.xml | 2 +- .../dmi-plugin-demo-and-csit-stub-service/pom.xml | 5 ++ .../stub/controller/DmiRestStubController.java | 36 +++++++++++++ dmi-stub/pom.xml | 62 +++++++++++++++++++--- docs/api/swagger/openapi-datajob.yaml | 19 +++++++ 6 files changed, 135 insertions(+), 9 deletions(-) diff --git a/dmi-service/openapi/openapi-datajob.yml b/dmi-service/openapi/openapi-datajob.yml index 989218d9..31a76bbd 100644 --- a/dmi-service/openapi/openapi-datajob.yml +++ b/dmi-service/openapi/openapi-datajob.yml @@ -240,6 +240,25 @@ components: type: string Object: type: object + SubjobWriteResponse: + type: object + required: + - subJobId + - dmiServiceName + - dataProducerId + properties: + subJobId: + description: Unique identifier for the sub-job + example: my-sub-job-id + type: string + dmiServiceName: + description: Name of the relevant DMI Service + example: my-dmi-service + type: string + dataProducerId: + description: ID of the producer registered by DMI for the paths in the operations in this request + example: my-data-producer-identifier + type: string responses: NotImplemented: description: Not Implemented @@ -251,4 +270,3 @@ components: status: 501 message: Not Implemented details: Method Not Implemented - diff --git a/dmi-service/pom.xml b/dmi-service/pom.xml index 033fd53d..a2a1f054 100644 --- a/dmi-service/pom.xml +++ b/dmi-service/pom.xml @@ -44,7 +44,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.10 + 2.2.22 io.cloudevents diff --git a/dmi-stub/dmi-plugin-demo-and-csit-stub-service/pom.xml b/dmi-stub/dmi-plugin-demo-and-csit-stub-service/pom.xml index 78b56852..7118a616 100644 --- a/dmi-stub/dmi-plugin-demo-and-csit-stub-service/pom.xml +++ b/dmi-stub/dmi-plugin-demo-and-csit-stub-service/pom.xml @@ -93,6 +93,11 @@ cps-ncmp-events 3.4.9 + + io.swagger.core.v3 + swagger-annotations + + org.spockframework diff --git a/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java b/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java index d97173ce..b8b46f06 100644 --- a/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java +++ b/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java @@ -32,11 +32,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import org.onap.cps.ncmp.dmi.datajobs.model.SubjobWriteRequest; +import org.onap.cps.ncmp.dmi.datajobs.model.SubjobWriteResponse; import org.onap.cps.ncmp.dmi.rest.stub.model.data.operational.DataOperationRequest; import org.onap.cps.ncmp.dmi.rest.stub.model.data.operational.DmiDataOperationRequest; import org.onap.cps.ncmp.dmi.rest.stub.model.data.operational.DmiOperationCmHandle; @@ -86,6 +89,7 @@ public class DmiRestStubController { private long readDataForCmHandleDelayMs; @Value("${delay.write-data-for-cm-handle-delay-ms}") private long writeDataForCmHandleDelayMs; + private AtomicInteger subJobWriteRequestCounter; /** * This code defines a REST API endpoint for adding new the module set tag mapping. The endpoint receives the @@ -257,6 +261,38 @@ public class DmiRestStubController { return new ResponseEntity<>(HttpStatus.ACCEPTED); } + /** + * Consume sub-job write requests from NCMP. + * + * @param requestId requestId generated by NCMP as an ack for client. + * @param subJobWriteRequest contains a collection of write requests and metadata. + * @return (@ code ResponseEntity) response for the write request. + */ + @PostMapping("/v1/writeJob/{requestId}") + public ResponseEntity consumeWriteSubJobs(@PathVariable("requestId") final String requestId, + @RequestBody final SubjobWriteRequest subJobWriteRequest) { + log.debug("Request ID: {}", requestId); + log.debug("Request body: {}", subJobWriteRequest); + return ResponseEntity.ok(new SubjobWriteResponse(String.valueOf(subJobWriteRequestCounter.incrementAndGet()), + "some-dmi-service-name", "my-data-producer-id")); + } + + /** + * Retrieves the status of a given data job identified by {@code requestId} and {@code dataProducerJobId}. + * + * @param requestId Unique identifier for the outgoing request. + * @param dataProducerJobId Identifier of the data producer job. + * @return A ResponseEntity with HTTP status 200 (OK) and the data job's status as a string. + */ + @GetMapping("/v1/dataJob/{requestId}/dataProducerJob/{dataProducerJobId}/status") + public ResponseEntity retrieveDataJobStatus( + @PathVariable("requestId") final String requestId, + @PathVariable("dataProducerJobId") final String dataProducerJobId) { + log.info("Received request to retrieve data job status. Request ID: {}, Data Producer Job ID: {}", + requestId, dataProducerJobId); + return ResponseEntity.ok("FINISHED"); + } + private CloudEvent buildAndGetCloudEvent(final String topic, final String requestId, final DataOperationEvent dataOperationEvent) { CloudEvent cloudEvent = null; diff --git a/dmi-stub/pom.xml b/dmi-stub/pom.xml index 379d873d..17def900 100644 --- a/dmi-stub/pom.xml +++ b/dmi-stub/pom.xml @@ -41,13 +41,61 @@ - - org.onap.cps - cps-dependencies - 3.5.1 - pom - import - + + org.onap.cps + cps-dependencies + 3.5.1 + pom + import + + + + + org.openapitools + openapi-generator-maven-plugin + 6.6.0 + + + code-gen + + generate + + + ${maven.multiModuleProjectDirectory}/docs/api/swagger/openapi-datajob.yaml + org.onap.cps.ncmp.dmi.datajobs.model + org.onap.cps.ncmp.dmi.datajobs.rest.api + spring + false + + src/gen/java + java11 + true + true + true + false + true + + + + + openapi-yaml-gen + + generate + + compile + + ${maven.multiModuleProjectDirectory}/docs/api/swagger/openapi-datajob.yaml + openapi-yaml + + openapi-datajob.yaml + + + + + + + + \ No newline at end of file diff --git a/docs/api/swagger/openapi-datajob.yaml b/docs/api/swagger/openapi-datajob.yaml index e58591e0..284b372e 100644 --- a/docs/api/swagger/openapi-datajob.yaml +++ b/docs/api/swagger/openapi-datajob.yaml @@ -282,3 +282,22 @@ components: - op - path type: object + SubjobWriteResponse: + type: object + required: + - subJobId + - dmiServiceName + - dataProducerId + properties: + subJobId: + description: Unique identifier for the sub-job + example: my-sub-job-id + type: string + dmiServiceName: + description: Name of the relevant DMI Service + example: my-dmi-service + type: string + dataProducerId: + description: ID of the producer registered by DMI for the paths in the operations in this request + example: my-data-producer-identifier + type: string -- cgit 1.2.3-korg