From 6b0e6b3a95ceb566059351a9635e35e0c265ad1c Mon Sep 17 00:00:00 2001 From: mpriyank Date: Fri, 8 Mar 2024 12:50:53 +0000 Subject: [Bug] Removing inner TaskExecutor to call DMI - Removing TaskExecutor from cps-ncmp-service package as anyways the call coming over from the cps-ncmp-rest layer is managed by a different thread executor(CpsNcmpTaskExecutor) - Provided 60secs timeout value. - Spawning new thread from a different executor might not be needed - Removing @Async from a non spring managed method as its of no use Issue-ID: CPS-2150 Change-Id: Ic99632983aff2c40df81421d782cf98ec600fc41 Signed-off-by: mpriyank --- .../cps/ncmp/api/impl/executor/TaskExecutor.java | 47 ---------------------- .../api/impl/operations/DmiDataOperations.java | 16 ++++---- .../ResourceDataOperationRequestUtils.java | 2 - 3 files changed, 7 insertions(+), 58 deletions(-) delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/executor/TaskExecutor.java (limited to 'cps-ncmp-service/src/main/java/org') diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/executor/TaskExecutor.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/executor/TaskExecutor.java deleted file mode 100644 index 192062fde5..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/executor/TaskExecutor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation - * ================================================================================ - * 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.impl.executor; - -import static java.util.concurrent.TimeUnit.MILLISECONDS; - -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TaskExecutor { - - /** - * Execute task asynchronously. - * - * @param taskSupplier functional method is get() task need to executed asynchronously - * @param timeOutInMillis the timeout value in milliseconds - */ - public static CompletableFuture executeTask(final Supplier taskSupplier, - final long timeOutInMillis) { - return CompletableFuture.supplyAsync(taskSupplier::get) - .orTimeout(timeOutInMillis, MILLISECONDS); - } -} - - - diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java index a77e78a2e2..2a4bceca23 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation + * Copyright (C) 2021-2024 Nordix Foundation * Modifications Copyright (C) 2022 Bell Canada * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,7 +37,6 @@ import org.onap.cps.ncmp.api.NcmpResponseStatus; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration; import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException; -import org.onap.cps.ncmp.api.impl.executor.TaskExecutor; import org.onap.cps.ncmp.api.impl.inventory.CmHandleState; import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder; @@ -59,8 +58,6 @@ import org.springframework.web.util.UriComponentsBuilder; @Slf4j public class DmiDataOperations extends DmiOperations { - private static final long DEFAULT_ASYNC_TASK_EXECUTOR_TIMEOUT_IN_MILLISECONDS = 30000L; - public DmiDataOperations(final InventoryPersistence inventoryPersistence, final JsonObjectMapper jsonObjectMapper, final NcmpConfiguration.DmiProperties dmiProperties, @@ -259,11 +256,12 @@ public class DmiDataOperations extends DmiOperations { .operations(dmiDataOperationRequestBodies).build(); final String dmiDataOperationRequestAsJsonString = jsonObjectMapper.asJsonString(dmiDataOperationRequest); - TaskExecutor.executeTask(() -> dmiRestClient.postOperationWithJsonData(dataOperationResourceUrl, - dmiDataOperationRequestAsJsonString, READ, authorization), - DEFAULT_ASYNC_TASK_EXECUTOR_TIMEOUT_IN_MILLISECONDS) - .whenCompleteAsync((response, throwable) -> handleTaskCompletionException(throwable, - dataOperationResourceUrl, dmiDataOperationRequestBodies)); + try { + dmiRestClient.postOperationWithJsonData(dataOperationResourceUrl, dmiDataOperationRequestAsJsonString, READ, + authorization); + } catch (final Exception exception) { + handleTaskCompletionException(exception, dataOperationResourceUrl, dmiDataOperationRequestBodies); + } } private void handleTaskCompletionException(final Throwable throwable, diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/ResourceDataOperationRequestUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/ResourceDataOperationRequestUtils.java index f13c842b25..a8b4e286b6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/ResourceDataOperationRequestUtils.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/ResourceDataOperationRequestUtils.java @@ -45,7 +45,6 @@ import org.onap.cps.ncmp.api.impl.utils.context.CpsApplicationContext; import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; import org.onap.cps.ncmp.api.models.DataOperationDefinition; import org.onap.cps.ncmp.api.models.DataOperationRequest; -import org.springframework.scheduling.annotation.Async; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -123,7 +122,6 @@ public class ResourceDataOperationRequestUtils { * @param requestId unique identifier per request * @param cmHandleIdsPerResponseCodesPerOperation list of cm handle ids per operation with response code */ - @Async public static void publishErrorMessageToClientTopic(final String clientTopic, final String requestId, final MultiValueMap