From: sourabh_sourabh Date: Thu, 27 Mar 2025 10:15:46 +0000 (+0000) Subject: Add 'unpublished' REST interface for DataJobs Write to allow K6 testing X-Git-Tag: 3.6.2~15 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=01d6d18217e37c4a78e70f7b453dfa2a6bfaa0db;p=cps.git Add 'unpublished' REST interface for DataJobs Write to allow K6 testing - Created a new hidden REST endpoint to use write job for internal testing like KPI and endurence. Issue-ID: CPS-2718 Change-Id: I1c4c7bc145dd522d344bd98ea04f05068b3e43eb Signed-off-by: sourabh_sourabh --- diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/DataJobControllerForTest.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/DataJobControllerForTest.java new file mode 100644 index 0000000000..d259d91796 --- /dev/null +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/DataJobControllerForTest.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.rest.controller; + +import io.swagger.v3.oas.annotations.Hidden; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.datajobs.DataJobService; +import org.onap.cps.ncmp.api.datajobs.models.DataJobMetadata; +import org.onap.cps.ncmp.api.datajobs.models.DataJobRequest; +import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest; +import org.onap.cps.ncmp.api.datajobs.models.SubJobWriteResponse; +import org.springframework.http.ResponseEntity; +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.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Controller responsible for handling data job write operations. + * This class exposes an API endpoint that accepts a write request for a data job and processes it. + */ +@Slf4j +@RestController +@RequestMapping("/do-not-use/dataJobs") +@RequiredArgsConstructor +public class DataJobControllerForTest { + + private final DataJobService dataJobService; + + /** + * Handles POST requests to write a data job. This endpoint is unsupported and intended for testing purposes only. + * This internal endpoint processes a data job write request by extracting necessary metadata and data + * from the request body and delegating the operation to the {@link DataJobService}. + *

Note: The {@link DataJobRequest} parameter is created and used for testing purposes only. + * In a production environment, data job write operations are not triggered through internal workflows.

+ * + * @param authorization The optional authorization token sent in the request header. + * @param dataJobId The unique identifier for the data job, extracted from the URL path. + * @param dataJobRequest The request payload containing metadata and data for the data job write operation. + * @return A {@link ResponseEntity} containing a list of {@link SubJobWriteResponse} objects representing the + * status of each sub-job within the data job, or an error response with an appropriate HTTP status code. + */ + @PostMapping("/{dataJobId}/write") + @Hidden + public ResponseEntity> writeDataJob(@RequestHeader(value = "Authorization", + required = false) final String authorization, + @PathVariable("dataJobId") final String dataJobId, + @RequestBody final DataJobRequest dataJobRequest) { + log.info("Internal API: writeDataJob invoked for {}", dataJobId); + final DataJobMetadata dataJobMetadata = dataJobRequest.dataJobMetadata(); + final DataJobWriteRequest dataJobWriteRequest = dataJobRequest.dataJobWriteRequest(); + final List subJobWriteResponses = dataJobService.writeDataJob(authorization, dataJobId, + dataJobMetadata, dataJobWriteRequest); + return ResponseEntity.ok(subJobWriteResponses); + } +} + diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/DataJobControllerForTestSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/DataJobControllerForTestSpec.groovy new file mode 100644 index 0000000000..6fc4a699e5 --- /dev/null +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/DataJobControllerForTestSpec.groovy @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.rest.controller + +import org.onap.cps.ncmp.api.datajobs.DataJobService +import org.onap.cps.ncmp.api.datajobs.models.DataJobMetadata +import org.onap.cps.ncmp.api.datajobs.models.DataJobRequest +import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest +import org.onap.cps.ncmp.api.datajobs.models.WriteOperation +import org.springframework.http.HttpStatus +import spock.lang.Specification + +class DataJobControllerForTestSpec extends Specification { + + DataJobService mockDataJobService = Mock() + + def objectUnderTest = new DataJobControllerForTest(mockDataJobService) + + def 'Write Data Job request'() { + given: 'a valid datajob write request' + def dataJobMetadata = new DataJobMetadata('some destination', 'some accept type', 'some content type') + def writeOperations = [ new WriteOperation('/path/to/node', 'create', 'op123', 'value1') ] + def dataJobWriteRequest = new DataJobWriteRequest(writeOperations) + def dataJobRequest = new DataJobRequest(dataJobMetadata, dataJobWriteRequest) + when: 'write data job is called' + def result = objectUnderTest.writeDataJob('my authorization', 'my job', dataJobRequest) + then: 'response is 200 OK' + assert result.statusCode == HttpStatus.OK + and: 'the service method is called once with expected parameters' + 1 * mockDataJobService.writeDataJob('my authorization', 'my job', dataJobMetadata, dataJobWriteRequest) + } +} diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy index aad04a18ae..3a9a0bb09c 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021 highstreet technologies GmbH - * Modifications Copyright (C) 2021-2024 Nordix Foundation + * Modifications Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -102,6 +102,9 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { @SpringBean NcmpPassthroughResourceRequestHandler StubbedNcmpPassthroughResourceRequestHandler = Stub() + @SpringBean + DataJobControllerForTest stubbedDataJobControllerForTest = Stub() + @Value('${rest.api.ncmp-base-path}') def basePathNcmp diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/DataJobRequest.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/DataJobRequest.java new file mode 100644 index 0000000000..fe73a601b9 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/DataJobRequest.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.api.datajobs.models; + +public record DataJobRequest(DataJobMetadata dataJobMetadata, DataJobWriteRequest dataJobWriteRequest) { +}