diff options
author | 2025-03-29 15:26:06 +0000 | |
---|---|---|
committer | 2025-04-01 15:37:53 +0100 | |
commit | b9f363ac09dd281b201651efe5ba3ecf54cb631c (patch) | |
tree | 130325ba1cba6b15876d99b1589855f289e40e2b | |
parent | 45ec6b1d785a271d90f7d0243e22dae05a2573f2 (diff) |
Added logging around write job operation to verify request and response details, with a focus on the number of jobs involved
Issue-ID: CPS-2735
Change-Id: I8dd6260556b4949bda5695d22f3f862c0786e385
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
2 files changed, 41 insertions, 16 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java index 04c3ad2fc6..56352c1c81 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * Copyright (C) 2024-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. @@ -31,6 +31,7 @@ import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest; import org.onap.cps.ncmp.api.datajobs.models.DmiWriteOperation; import org.onap.cps.ncmp.api.datajobs.models.ProducerKey; import org.onap.cps.ncmp.api.datajobs.models.SubJobWriteResponse; +import org.onap.cps.utils.JsonObjectMapper; import org.springframework.stereotype.Service; @Slf4j @@ -40,6 +41,7 @@ public class DataJobServiceImpl implements DataJobService { private final DmiSubJobRequestHandler dmiSubJobClient; private final WriteRequestExaminer writeRequestExaminer; + private final JsonObjectMapper jsonObjectMapper; @Override public void readDataJob(final String authorization, @@ -54,14 +56,25 @@ public class DataJobServiceImpl implements DataJobService { final String dataJobId, final DataJobMetadata dataJobMetadata, final DataJobWriteRequest dataJobWriteRequest) { - log.info("data job id for write operation is: {}", dataJobId); + + log.info("Data Job ID: {} - Total operations received: {}", dataJobId, dataJobWriteRequest.data().size()); + logJsonRepresentation("Initiating WRITE operation for Data Job ID: " + dataJobId, dataJobWriteRequest); final Map<ProducerKey, List<DmiWriteOperation>> dmiWriteOperationsPerProducerKey = writeRequestExaminer.splitDmiWriteOperationsFromRequest(dataJobId, dataJobWriteRequest); - return dmiSubJobClient.sendRequestsToDmi(authorization, - dataJobId, - dataJobMetadata, - dmiWriteOperationsPerProducerKey); + final List<SubJobWriteResponse> subJobWriteResponses = dmiSubJobClient.sendRequestsToDmi(authorization, + dataJobId, dataJobMetadata, dmiWriteOperationsPerProducerKey); + + log.info("Data Job ID: {} - Received {} sub-job(s) from DMI.", dataJobId, subJobWriteResponses.size()); + logJsonRepresentation("Finalized subJobWriteResponses for Data Job ID: " + dataJobId, subJobWriteResponses); + return subJobWriteResponses; + } + + private void logJsonRepresentation(final String description, final Object object) { + if (log.isDebugEnabled()) { + final String objectAsJsonString = jsonObjectMapper.asJsonString(object); + log.debug("{} (JSON): {}", description, objectAsJsonString); + } } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy index 4b536b9710..9f0e134466 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * Copyright (C) 2024-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. @@ -29,6 +29,7 @@ import org.onap.cps.ncmp.api.datajobs.models.DataJobReadRequest import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest import org.onap.cps.ncmp.api.datajobs.models.ReadOperation import org.onap.cps.ncmp.api.datajobs.models.WriteOperation +import org.onap.cps.utils.JsonObjectMapper import org.slf4j.LoggerFactory import spock.lang.Specification @@ -36,8 +37,9 @@ class DataJobServiceImplSpec extends Specification { def mockWriteRequestExaminer = Mock(WriteRequestExaminer) def mockDmiSubJobRequestHandler = Mock(DmiSubJobRequestHandler) + def mockJsonObjectMapper = Mock(JsonObjectMapper) - def objectUnderTest = new DataJobServiceImpl(mockDmiSubJobRequestHandler, mockWriteRequestExaminer) + def objectUnderTest = new DataJobServiceImpl(mockDmiSubJobRequestHandler, mockWriteRequestExaminer, mockJsonObjectMapper) def myDataJobMetadata = new DataJobMetadata('', '', '') def authorization = 'my authorization header' @@ -45,7 +47,7 @@ class DataJobServiceImplSpec extends Specification { def logger = Spy(ListAppender<ILoggingEvent>) def setup() { - setupLogger() + setupLogger(Level.DEBUG) } def cleanup() { @@ -62,22 +64,32 @@ class DataJobServiceImplSpec extends Specification { assert loggingEvent.formattedMessage.contains('data job id for read operation is: my-job-id') } - def 'Write data-job request.'() { + def 'Write data-job request and verify logging when info enabled.'() { given: 'data job metadata and write request' def dataJobWriteRequest = new DataJobWriteRequest([new WriteOperation('', '', '', null)]) - and: 'a map of producer key and dmi 3gpp write operation' + and: 'a map of producer key and DMI 3GPP write operations' def dmiWriteOperationsPerProducerKey = [:] - when: 'write data job request is processed' + and: 'mocking the splitDmiWriteOperationsFromRequest method to return the expected data' + mockWriteRequestExaminer.splitDmiWriteOperationsFromRequest(_, _) >> dmiWriteOperationsPerProducerKey + and: 'mocking the sendRequestsToDmi method to simulate empty sub-job responses from the DMI request handler' + mockDmiSubJobRequestHandler.sendRequestsToDmi(authorization, 'my-job-id', myDataJobMetadata, dmiWriteOperationsPerProducerKey) >> [] + when: 'the write data job request is processed' objectUnderTest.writeDataJob(authorization, 'my-job-id', myDataJobMetadata, dataJobWriteRequest) then: 'the examiner service is called and a map is returned' 1 * mockWriteRequestExaminer.splitDmiWriteOperationsFromRequest('my-job-id', dataJobWriteRequest) >> dmiWriteOperationsPerProducerKey - and: 'the dmi request handler is called with the result from the examiner' - 1 * mockDmiSubJobRequestHandler.sendRequestsToDmi(authorization, 'my-job-id', myDataJobMetadata, dmiWriteOperationsPerProducerKey) + and: 'write operation details are logged at debug level' + with(logger.list.find { it.level == Level.DEBUG }) { + assert it.formattedMessage.contains("Initiating WRITE operation for Data Job ID: my-job-id") + } + and: 'number of operations are logged at info level' + with(logger.list.find { it.level == Level.INFO }) { + assert it.formattedMessage.contains("Data Job ID: my-job-id - Total operations received: 1") + } } - def setupLogger() { + def setupLogger(Level level) { def setupLogger = ((Logger) LoggerFactory.getLogger(DataJobServiceImpl.class)) - setupLogger.setLevel(Level.DEBUG) + setupLogger.setLevel(level) setupLogger.addAppender(logger) logger.start() } |