From e31db7316963f7554c493c1e65ff21df37f8f0b2 Mon Sep 17 00:00:00 2001 From: leventecsanyi Date: Thu, 8 Aug 2024 16:21:07 +0200 Subject: Refactored Data Job interfaces -modified writejob & status endpoints Issue-ID: CPS-2360 Change-Id: I87647f59493886593825f5175c6ed708e55b3e30 Signed-off-by: leventecsanyi --- .../cps/ncmp/api/datajobs/DataJobStatusService.java | 8 +++----- .../api/datajobs/models/SubJobWriteRequest.java | 5 ++++- .../impl/datajobs/DataJobStatusServiceImpl.java | 21 ++++++++++----------- .../ncmp/impl/datajobs/DmiSubJobRequestHandler.java | 17 +++++++++++------ .../org/onap/cps/ncmp/impl/dmi/DmiRestClient.java | 2 +- .../datajobs/DataJobStatusServiceImplSpec.groovy | 7 +++---- .../datajobs/DmiSubJobRequestHandlerSpec.groovy | 2 +- 7 files changed, 33 insertions(+), 29 deletions(-) (limited to 'cps-ncmp-service') diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobStatusService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobStatusService.java index 50d96f858c..9cfc49f1d4 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobStatusService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobStatusService.java @@ -31,15 +31,13 @@ public interface DataJobStatusService { * * @param authorization The authorization header from the REST request. * @param dmiServiceName The name of the DMI Service relevant to the data job. - * @param requestId The unique identifier for the overall data job request. - * @param dataProducerJobId The identifier of the data producer job within the DMI system. * @param dataProducerId The ID of the producer registered by DMI, used for operations related to this request. * This could include alternate IDs or specific identifiers. + * @param dataProducerJobId The identifier of the data producer job within the DMI system. * @return The current status of the data job as a String. */ String getDataJobStatus(final String authorization, final String dmiServiceName, - final String requestId, - final String dataProducerJobId, - final String dataProducerId); + final String dataProducerId, + final String dataProducerJobId); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/SubJobWriteRequest.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/SubJobWriteRequest.java index 0e0498ec49..a7a6573279 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/SubJobWriteRequest.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/SubJobWriteRequest.java @@ -25,17 +25,20 @@ import java.util.Collection; /** * Request data for a write operation by the DMI Plugin. * + * @param destination The destination of the results. ( e.g. S3 Bucket) * @param dataAcceptType Define the data response accept type. * e.g. "application/vnd.3gpp.object-tree-hierarchical+json", * "application/vnd.3gpp.object-tree-flat+json" etc. * @param dataContentType Define the data request content type. * e.g. "application/3gpp-json-patch+json" etc. * @param dataProducerId Identifier of the data producer. - * + * @param dataJobId Identifier for the overall Datajob * @param data A collection of outgoing write operations. */ public record SubJobWriteRequest ( + String destination, String dataAcceptType, String dataContentType, String dataProducerId, + String dataJobId, Collection data) {} \ No newline at end of file diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImpl.java index a6ecaa1097..fb17f066ce 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImpl.java @@ -42,26 +42,25 @@ public class DataJobStatusServiceImpl implements DataJobStatusService { @Override public String getDataJobStatus(final String authorization, final String dmiServiceName, - final String requestId, - final String dataProducerJobId, - final String dataProducerId) { + final String dataProducerId, + final String dataProducerJobId) { - final UrlTemplateParameters urlTemplateParameters = buildUrlParameters(dmiServiceName, requestId, - dataProducerJobId, dataProducerId); + final UrlTemplateParameters urlTemplateParameters = buildUrlParameters(dmiServiceName, + dataProducerId, + dataProducerJobId); return dmiRestClient.getDataJobStatus(urlTemplateParameters, authorization).block(); } private UrlTemplateParameters buildUrlParameters(final String dmiServiceName, - final String requestId, - final String dataProducerJobId, - final String dataProducerId) { + final String dataProducerId, + final String dataProducerJobId) { return DmiServiceUrlTemplateBuilder.newInstance() - .fixedPathSegment("dataJob") - .variablePathSegment("requestId", requestId) + .fixedPathSegment("cmwriteJob") + .fixedPathSegment("dataProducer") + .variablePathSegment("dataProducerId", dataProducerId) .fixedPathSegment("dataProducerJob") .variablePathSegment("dataProducerJobId", dataProducerJobId) .fixedPathSegment("status") - .queryParameter("dataProducerId", dataProducerId) .createUrlTemplateParameters(dmiServiceName, dmiProperties.getDmiBasePath()); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java index c93709ce75..0d14dace5e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java @@ -64,10 +64,15 @@ public class DmiSubJobRequestHandler { final Map> dmiWriteOperationsPerProducerKey) { final List subJobWriteResponses = new ArrayList<>(dmiWriteOperationsPerProducerKey.size()); dmiWriteOperationsPerProducerKey.forEach((producerKey, dmi3ggpWriteOperations) -> { - final SubJobWriteRequest subJobWriteRequest = new SubJobWriteRequest(dataJobMetadata.dataAcceptType(), - dataJobMetadata.dataContentType(), producerKey.dataProducerIdentifier(), dmi3ggpWriteOperations); + final SubJobWriteRequest subJobWriteRequest = new SubJobWriteRequest(dataJobMetadata.destination(), + dataJobMetadata.dataAcceptType(), + dataJobMetadata.dataContentType(), + producerKey.dataProducerIdentifier(), + dataJobId, + dmi3ggpWriteOperations); - final UrlTemplateParameters urlTemplateParameters = getUrlTemplateParameters(dataJobId, producerKey); + final UrlTemplateParameters urlTemplateParameters = getUrlTemplateParameters(dataJobMetadata.destination(), + producerKey); final ResponseEntity responseEntity = dmiRestClient.synchronousPostOperationWithJsonData( RequiredDmiService.DATA, urlTemplateParameters, @@ -82,10 +87,10 @@ public class DmiSubJobRequestHandler { return subJobWriteResponses; } - private UrlTemplateParameters getUrlTemplateParameters(final String dataJobId, final ProducerKey producerKey) { + private UrlTemplateParameters getUrlTemplateParameters(final String destination, final ProducerKey producerKey) { return DmiServiceUrlTemplateBuilder.newInstance() - .fixedPathSegment("writeJob") - .variablePathSegment("requestId", dataJobId) + .fixedPathSegment("cmwriteJob") + .queryParameter("destination", destination) .createUrlTemplateParameters(producerKey.dmiServiceName(), dmiProperties.getDmiBasePath()); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java index ba6bba9c53..177b4b0bf2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java @@ -160,7 +160,7 @@ public class DmiRestClient { .headers(httpHeaders -> configureHttpHeaders(httpHeaders, authorization)) .retrieve() .bodyToMono(JsonNode.class) - .map(responseHealthStatus -> responseHealthStatus.path("status").asText()) + .map(jsonNode -> jsonNode.path("status").asText()) .onErrorMap(throwable -> handleDmiClientException(throwable, OperationType.READ.getOperationName())); } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImplSpec.groovy index cc042988f6..d231dfa755 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImplSpec.groovy @@ -39,15 +39,14 @@ class DataJobStatusServiceImplSpec extends Specification { def 'Forward a data job status query to DMI.' () { given: 'the required parameters for querying' def dmiServiceName = 'some-dmi-service' - def requestId = 'some-request-id' + def dataProducerId = 'some-data-producer-id' def dataProducerJobId = 'some-data-producer-job-id' - def dataJobId = 'some-data-job-id' def authorization = 'my authorization header' - def urlParams = new UrlTemplateParameters('some-dmi-service/dmi/v1/dataJob/{requestId}/dataProducerJob/{dataProducerJobId}/status?dataProducerId={dataProducerId}', ['dataProducerJobId':'some-data-producer-job-id', 'dataProducerId':'some-data-job-id', 'requestId':'some-request-id']) + def urlParams = new UrlTemplateParameters('some-dmi-service/dmi/v1/cmwriteJob/dataProducer/{dataProducerId}/dataProducerJob/{dataProducerJobId}/status', ['dataProducerId':'some-data-producer-id', 'dataProducerJobId':'some-data-producer-job-id']) and: 'the rest client returns a status for the given parameters' mockDmiRestClient.getDataJobStatus(urlParams, authorization) >> Mono.just('some status') when: 'the job status is queried' - def status = objectUnderTest.getDataJobStatus(authorization, dmiServiceName, requestId, dataProducerJobId, dataJobId) + def status = objectUnderTest.getDataJobStatus(authorization, dmiServiceName, dataProducerId, dataProducerJobId) then: 'the status from the rest client is returned' assert status == 'some status' } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy index b3dd02dec3..041fbd95ee 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy @@ -30,7 +30,7 @@ class DmiSubJobRequestHandlerSpec extends Specification { def authorization = 'my authorization header' and: 'the dmi rest client will return a response (for the correct parameters)' def responseEntity = new ResponseEntity<>(new SubJobWriteResponse('my-sub-job-id', 'dmi1', 'prod1'), HttpStatus.OK) - def expectedJson = '{"dataAcceptType":"t1","dataContentType":"t2","dataProducerId":"prod1","data":[{"path":"p","op":"operation","moduleSetTag":"tag","value":null,"operationId":"o1","privateProperties":{}}]}' + def expectedJson = '{"destination":"d1","dataAcceptType":"t1","dataContentType":"t2","dataProducerId":"prod1","dataJobId":"some-job-id","data":[{"path":"p","op":"operation","moduleSetTag":"tag","value":null,"operationId":"o1","privateProperties":{}}]}' mockDmiRestClient.synchronousPostOperationWithJsonData(RequiredDmiService.DATA, _, expectedJson, OperationType.CREATE, authorization) >> responseEntity when: 'sending request to DMI invoked' objectUnderTest.sendRequestsToDmi(authorization, dataJobId, dataJobMetadata, dmiWriteOperationsPerProducerKey) -- cgit 1.2.3-korg