From dbed81b6cece07c8950fa2f32f6f05eba3bb991e Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Thu, 13 Jun 2024 16:52:45 +0100 Subject: Introducing NCMP Facades - NetworkCmProxyDataService was polluted with many non-data operations - it is now split into: 1) NetworkCmProxyFacade, a single thin facade for the (main) controler to redirect calls to the correct services 2) CmHandleRegistrationService(Impl), methods related to registration only - introduced NetworkCmProxyInventoryFacade for the invenoty controller - renamed some services for consitency and clarification - Use facade to acces ncmp data request handlers (instead of direct from controller) - remove unnecesarry wrappings between request handlers and facade - split facades according to names: data & inventory (the REST controllers are not split properly so I think one rest controller will end up needing both facades) Issue-ID: CPS-2263 Change-Id: I250732aa16ec28b43ff642d2adf10ba36f67290e Signed-off-by: ToineSiebelink --- .../api/NetworkCmProxyCmHandleQueryService.java | 71 --- .../cps/ncmp/api/NetworkCmProxyDataService.java | 214 -------- .../api/ParameterizedCmHandleQueryService.java | 72 +++ .../ncmp/api/impl/CmHandleRegistrationService.java | 404 +++++++++++++++ ...CmHandleRegistrationServicePropertyHandler.java | 246 +++++++++ .../api/impl/NcmpCachedResourceRequestHandler.java | 12 +- .../ncmp/api/impl/NcmpDatastoreRequestHandler.java | 39 +- .../NcmpPassthroughResourceRequestHandler.java | 48 +- .../NetworkCmProxyCmHandleQueryServiceImpl.java | 286 ----------- .../api/impl/NetworkCmProxyDataServiceImpl.java | 568 --------------------- .../NetworkCmProxyDataServicePropertyHandler.java | 243 --------- .../cps/ncmp/api/impl/NetworkCmProxyFacade.java | 129 +++++ .../api/impl/NetworkCmProxyInventoryFacade.java | 207 ++++++++ .../ParameterizedCmHandleQueryServiceImpl.java | 286 +++++++++++ .../cps/ncmp/api/impl/client/DmiRestClient.java | 36 +- .../ncmp/api/impl/inventory/CmHandleQueries.java | 104 ---- .../api/impl/inventory/CmHandleQueriesImpl.java | 192 ------- .../api/impl/inventory/CmHandleQueryService.java | 105 ++++ .../impl/inventory/CmHandleQueryServiceImpl.java | 192 +++++++ .../impl/inventory/InventoryPersistenceImpl.java | 9 +- .../impl/inventory/sync/ModuleOperationsUtils.java | 23 +- .../api/impl/inventory/sync/ModuleSyncService.java | 6 +- .../api/impl/operations/DmiDataOperations.java | 41 +- .../api/impl/operations/DmiModelOperations.java | 3 +- .../dmiavailability/DmiPluginWatchDog.java | 6 +- 25 files changed, 1754 insertions(+), 1788 deletions(-) delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandleQueryService.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/ParameterizedCmHandleQueryService.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationService.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationServicePropertyHandler.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceImpl.java delete mode 100755 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacade.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacade.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/ParameterizedCmHandleQueryServiceImpl.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueries.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryService.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryServiceImpl.java (limited to 'cps-ncmp-service/src/main') diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandleQueryService.java deleted file mode 100644 index 06522f80cf..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandleQueryService.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022-2024 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; - -import java.util.Collection; -import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; -import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; - -public interface NetworkCmProxyCmHandleQueryService { - /** - * Query and return cm handle ids that match the given query parameters. - * Supported query types: - * public properties - * modules - * cps-path - * - * @param cmHandleQueryServiceParameters the cm handle query parameters - * @return collection of cm handle ids - */ - Collection queryCmHandleIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters); - - /** - * Query and return cm handle ids that match the given query parameters. - * Supported query types: - * public properties - * private (additional) properties - * dmi-names - * The inventory interface also allows conditions on private (additional) properties and dmi names - * - * @param cmHandleQueryServiceParameters the cm handle query parameters - * @return collection of cm handle ids - */ - Collection queryCmHandleIdsForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters); - - /** - * Query and return cm handle objects that match the given query parameters. - * Supported query types: - * public properties - * modules - * cps-path - * - * @param cmHandleQueryServiceParameters the cm handle query parameters - * @return collection of cm handles - */ - Collection queryCmHandles(CmHandleQueryServiceParameters cmHandleQueryServiceParameters); - - /** - * Query and return all cm handle objects. - * - * @return collection of cm handles - */ - Collection getAllCmHandles(); -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java deleted file mode 100644 index 73c8d96096..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 highstreet technologies GmbH - * Modifications Copyright (C) 2021-2024 Nordix Foundation - * Modifications Copyright (C) 2021 Pantheon.tech - * Modifications Copyright (C) 2022 Bell Canada - * ================================================================================ - * 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; - -import java.util.Collection; -import java.util.Map; -import org.onap.cps.ncmp.api.impl.inventory.CompositeState; -import org.onap.cps.ncmp.api.impl.operations.OperationType; -import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters; -import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; -import org.onap.cps.ncmp.api.models.CmResourceAddress; -import org.onap.cps.ncmp.api.models.DataOperationRequest; -import org.onap.cps.ncmp.api.models.DmiPluginRegistration; -import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse; -import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; -import org.onap.cps.spi.FetchDescendantsOption; -import org.onap.cps.spi.model.ModuleDefinition; -import org.onap.cps.spi.model.ModuleReference; -import reactor.core.publisher.Mono; - -/* - * Datastore interface for handling CPS data. - */ -public interface NetworkCmProxyDataService { - - /** - * Registration of New CM Handles. - * - * @param dmiPluginRegistration Dmi Plugin Registration - * @return dmiPluginRegistrationResponse - */ - DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(DmiPluginRegistration dmiPluginRegistration); - - /** - * Fetches resource data for a given data store using DMI (Data Management Interface). - * This method retrieves data based on the provided CmResourceAddress and additional query parameters. - * It supports asynchronous processing and handles authorization if required. - * - * @param cmResourceAddress The target data store, including the CM handle and resource identifier. - * This parameter must not be null. - * @param optionsParamInQuery Additional query parameters that may influence the data retrieval process, - * such as filters or limits. This parameter can be null. - * @param topicParamInQuery The topic name for triggering asynchronous responses. If specified, - * the response will be sent to this topic. This parameter can be null. - * @param requestId A unique identifier for the request, used for tracking and correlating - * asynchronous operations. This parameter must not be null. - * @param authorization The contents of the Authorization header. This parameter can be null - * if authorization is not required. - * @return {@code Mono} A reactive Mono that emits the resource data on successful retrieval - * or an error signal if the operation fails. The Mono represents a single asynchronous - * computation result. - */ - Mono getResourceDataForCmHandle(CmResourceAddress cmResourceAddress, - String optionsParamInQuery, - String topicParamInQuery, - String requestId, - String authorization); - - /** - * Get resource data for operational. - * - * @param cmResourceAddress target datastore, cm handle and resource identifier - * @Link FetchDescendantsOption fetch descendants option - * @return {@code Object} resource data - */ - Object getResourceDataForCmHandle(CmResourceAddress cmResourceAddress, - FetchDescendantsOption fetchDescendantsOption); - - /** - * Execute (async) data operation for group of cm handles using dmi. - * - * @param topicParamInQuery topic name for (triggering) async responses - * @param dataOperationRequest contains a list of operation definitions(multiple operations) - * @param requestId request ID - * @param authorization contents of Authorization header, or null if not present - */ - void executeDataOperationForCmHandles(String topicParamInQuery, - DataOperationRequest dataOperationRequest, - String requestId, - String authorization); - - - /** - * Write resource data for data store pass-through running using dmi for given cm-handle. - * - * @param cmHandleId cm handle identifier - * @param resourceIdentifier resource identifier - * @param operationType required operation type - * @param requestBody request body to create resource - * @param contentType content type in body - * @param authorization contents of Authorization header, or null if not present - * @return {@code Object} return data - */ - Object writeResourceDataPassThroughRunningForCmHandle(String cmHandleId, - String resourceIdentifier, - OperationType operationType, - String requestBody, - String contentType, - String authorization); - - /** - * Retrieve module references for the given cm handle. - * - * @param cmHandleId cm handle identifier - * @return a collection of modules names and revisions - */ - Collection getYangResourcesModuleReferences(String cmHandleId); - - /** - * Retrieve module definitions for the given cm handle. - * - * @param cmHandleId cm handle identifier - * @return a collection of module definition (moduleName, revision and yang resource content) - */ - Collection getModuleDefinitionsByCmHandleId(String cmHandleId); - - /** - * Get module definitions for the given parameters. - * - * @param cmHandleId cm-handle identifier - * @param moduleName module name - * @param moduleRevision the revision of the module - * @return list of module definitions (module name, revision, yang resource content) - */ - Collection getModuleDefinitionsByCmHandleAndModule(String cmHandleId, - String moduleName, - String moduleRevision); - - /** - * Query cm handle details by cm handle's name. - * - * @param cmHandleId cm handle identifier - * @return a collection of cm handle details. - */ - NcmpServiceCmHandle getNcmpServiceCmHandle(String cmHandleId); - - /** - * Get cm handle public properties by cm handle id. - * - * @param cmHandleId cm handle identifier - * @return a collection of cm handle public properties. - */ - Map getCmHandlePublicProperties(String cmHandleId); - - /** - * Get cm handle composite state by cm handle id. - * - * @param cmHandleId cm handle identifier - * @return a cm handle composite state - */ - CompositeState getCmHandleCompositeState(String cmHandleId); - - /** - * Query and return cm handles that match the given query parameters. - * - * @param cmHandleQueryApiParameters the cm handle query parameters - * @return collection of cm handles - */ - Collection executeCmHandleSearch(CmHandleQueryApiParameters cmHandleQueryApiParameters); - - /** - * Query and return cm handle ids that match the given query parameters. - * - * @param cmHandleQueryApiParameters the cm handle query parameters - * @return collection of cm handle ids - */ - Collection executeCmHandleIdSearch(CmHandleQueryApiParameters cmHandleQueryApiParameters); - - /** - * Set the data sync enabled flag, along with the data sync state to true or false based on the cm handle id. - * - * @param cmHandleId cm handle id - * @param dataSyncEnabled data sync enabled flag - */ - void setDataSyncEnabled(String cmHandleId, Boolean dataSyncEnabled); - - /** - * Get all cm handle IDs by DMI plugin identifier. - * - * @param dmiPluginIdentifier DMI plugin identifier - * @return collection of cm handle IDs - */ - Collection getAllCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier); - - /** - * Get all cm handle IDs by various search criteria. - * - * @param cmHandleQueryServiceParameters cm handle query parameters - * @return collection of cm handle IDs - */ - Collection executeCmHandleIdSearchForInventory(CmHandleQueryServiceParameters - cmHandleQueryServiceParameters); -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/ParameterizedCmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/ParameterizedCmHandleQueryService.java new file mode 100644 index 0000000000..a9ade24c72 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/ParameterizedCmHandleQueryService.java @@ -0,0 +1,72 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022-2024 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; + +import java.util.Collection; +import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; + +public interface ParameterizedCmHandleQueryService { + /** + * Query and return cm handle ids that match the given query parameters. + * Supported query types: + * public properties + * modules + * cps-path + * + * @param cmHandleQueryServiceParameters the cm handle query parameters + * @return collection of cm handle ids + */ + Collection queryCmHandleIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters); + + /** + * Query and return cm handle ids that match the given query parameters. + * Supported query types: + * public properties + * private (additional) properties + * dmi-names + * The inventory interface also allows conditions on private (additional) properties and dmi names + * + * @param cmHandleQueryServiceParameters the cm handle query parameters + * @return collection of cm handle ids + */ + Collection queryCmHandleIdsForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters); + + /** + * Query and return cm handle objects that match the given query parameters. + * Supported query types: + * public properties + * modules + * cps-path + * + * @param cmHandleQueryServiceParameters the cm handle query parameters + * @return collection of cm handles + */ + Collection queryCmHandles(CmHandleQueryServiceParameters cmHandleQueryServiceParameters); + + /** + * Get all cm handle objects. + * Note: it is similar to all the queries above but simply no conditions and hence not 'parameterized' + * + * @return collection of cm handles + */ + Collection getAllCmHandles(); +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationService.java new file mode 100644 index 0000000000..6f78e6cb34 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationService.java @@ -0,0 +1,404 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2024 Nordix Foundation + * Modifications Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2021-2022 Bell Canada + * Modifications Copyright (C) 2023 TechMahindra Ltd. + * ================================================================================ + * 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; + +import static org.onap.cps.ncmp.api.NcmpResponseStatus.ALTERNATE_ID_ALREADY_ASSOCIATED; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_READY; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID; +import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE; +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME; + +import com.google.common.collect.Lists; +import com.hazelcast.map.IMap; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.onap.cps.api.CpsDataService; +import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig; +import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler; +import org.onap.cps.ncmp.api.impl.inventory.CmHandleState; +import org.onap.cps.ncmp.api.impl.inventory.CompositeState; +import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder; +import org.onap.cps.ncmp.api.impl.inventory.CompositeStateUtils; +import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState; +import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; +import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleOperationsUtils; +import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; +import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager; +import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; +import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; +import org.onap.cps.ncmp.api.models.DmiPluginRegistration; +import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; +import org.onap.cps.spi.exceptions.AlreadyDefinedException; +import org.onap.cps.spi.exceptions.CpsException; +import org.onap.cps.spi.exceptions.DataNodeNotFoundException; +import org.onap.cps.spi.exceptions.DataValidationException; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class CmHandleRegistrationService { + + private static final int DELETE_BATCH_SIZE = 100; + + private final CmHandleRegistrationServicePropertyHandler cmHandleRegistrationServicePropertyHandler; + private final InventoryPersistence inventoryPersistence; + private final CpsDataService cpsDataService; + private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler; + private final IMap moduleSyncStartedOnCmHandles; + + @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN) + private final Map trustLevelPerDmiPlugin; + private final TrustLevelManager trustLevelManager; + + private final AlternateIdChecker alternateIdChecker; + + /** + * Registration of Created, Removed, Updated or Upgraded CM Handles. + * + * @param dmiPluginRegistration Dmi Plugin Registration details + * @return dmiPluginRegistrationResponse + */ + public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule( + final DmiPluginRegistration dmiPluginRegistration) { + + dmiPluginRegistration.validateDmiPluginRegistration(); + final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse(); + + setTrustLevelPerDmiPlugin(dmiPluginRegistration); + + processRemovedCmHandles(dmiPluginRegistration, dmiPluginRegistrationResponse); + + processCreatedCmHandles(dmiPluginRegistration, dmiPluginRegistrationResponse); + + processUpdatedCmHandles(dmiPluginRegistration, dmiPluginRegistrationResponse); + + processUpgradedCmHandles(dmiPluginRegistration, dmiPluginRegistrationResponse); + + return dmiPluginRegistrationResponse; + } + + /** + * Set the data sync enabled flag, along with the data sync state + * based on the data sync enabled boolean for the cm handle id provided. + * + * @param cmHandleId cm handle id + * @param dataSyncEnabledTargetValue data sync enabled flag + */ + public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) { + final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId); + if (dataSyncEnabledTargetValue.equals(compositeState.getDataSyncEnabled())) { + log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabledTargetValue); + return; + } + if (CmHandleState.READY.equals(compositeState.getCmHandleState())) { + final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores() + .getOperationalDataStore().getDataStoreSyncState(); + if (Boolean.FALSE.equals(dataSyncEnabledTargetValue) + && DataStoreSyncState.SYNCHRONIZED.equals(dataStoreSyncState)) { + // TODO : This is hard-coded for onap dmi that need to be addressed + cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, + "/netconf-state", OffsetDateTime.now()); + } + CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabledTargetValue, compositeState); + inventoryPersistence.saveCmHandleState(cmHandleId, compositeState); + } else { + throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: " + + compositeState.getCmHandleState()); + } + } + + protected void processRemovedCmHandles(final DmiPluginRegistration dmiPluginRegistration, + final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) { + final List tobeRemovedCmHandleIds = dmiPluginRegistration.getRemovedCmHandles(); + final List cmHandleRegistrationResponses = + new ArrayList<>(tobeRemovedCmHandleIds.size()); + final Collection yangModelCmHandles = + inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandleIds); + updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING); + + final Set notDeletedCmHandles = new HashSet<>(); + for (final List tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandleIds, DELETE_BATCH_SIZE)) { + try { + batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch); + tobeRemovedCmHandleBatch.forEach(cmHandleId -> + cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId))); + + } catch (final RuntimeException batchException) { + log.error("Unable to de-register cm-handle batch, retrying on each cm handle"); + for (final String cmHandleId : tobeRemovedCmHandleBatch) { + final CmHandleRegistrationResponse cmHandleRegistrationResponse = + deleteCmHandleAndGetCmHandleRegistrationResponse(cmHandleId); + cmHandleRegistrationResponses.add(cmHandleRegistrationResponse); + if (cmHandleRegistrationResponse.getStatus() != CmHandleRegistrationResponse.Status.SUCCESS) { + notDeletedCmHandles.add(cmHandleId); + } + } + } + } + yangModelCmHandles.removeIf(yangModelCmHandle -> notDeletedCmHandles.contains(yangModelCmHandle.getId())); + updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETED); + dmiPluginRegistrationResponse.setRemovedCmHandles(cmHandleRegistrationResponses); + } + + protected void processCreatedCmHandles(final DmiPluginRegistration dmiPluginRegistration, + final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) { + final List ncmpServiceCmHandles = dmiPluginRegistration.getCreatedCmHandles(); + final List failedCmHandleRegistrationResponses = new ArrayList<>(); + + try { + final Collection rejectedCmHandleIds + = checkAlternateIds(ncmpServiceCmHandles, failedCmHandleRegistrationResponses); + + final Collection succeededCmHandleIds = persistCmHandlesWithState(dmiPluginRegistration, + dmiPluginRegistrationResponse, ncmpServiceCmHandles, rejectedCmHandleIds); + + processTrustLevels(ncmpServiceCmHandles, succeededCmHandleIds); + + } catch (final AlreadyDefinedException alreadyDefinedException) { + failedCmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponsesFromXpaths( + alreadyDefinedException.getAlreadyDefinedObjectNames(), CM_HANDLE_ALREADY_EXIST)); + } catch (final Exception exception) { + final Collection cmHandleIds = + ncmpServiceCmHandles.stream().map(NcmpServiceCmHandle::getCmHandleId).collect(Collectors.toList()); + failedCmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse + .createFailureResponses(cmHandleIds, exception)); + } + final List mergedCmHandleRegistrationResponses + = new ArrayList<>(failedCmHandleRegistrationResponses); + mergedCmHandleRegistrationResponses.addAll(dmiPluginRegistrationResponse.getCreatedCmHandles()); + + dmiPluginRegistrationResponse.setCreatedCmHandles(mergedCmHandleRegistrationResponses); + } + + protected void processUpdatedCmHandles(final DmiPluginRegistration dmiPluginRegistration, + final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) { + dmiPluginRegistrationResponse.setUpdatedCmHandles(cmHandleRegistrationServicePropertyHandler + .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles())); + } + + protected void processUpgradedCmHandles( + final DmiPluginRegistration dmiPluginRegistration, + final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) { + + final List cmHandleIds = dmiPluginRegistration.getUpgradedCmHandles().getCmHandles(); + final String upgradedModuleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag(); + final Map acceptedCmHandleStatePerCmHandle + = new HashMap<>(cmHandleIds.size()); + final List cmHandleUpgradeResponses = new ArrayList<>(cmHandleIds.size()); + + for (final String cmHandleId : cmHandleIds) { + try { + final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); + if (yangModelCmHandle.getCompositeState().getCmHandleState() == CmHandleState.READY) { + if (moduleUpgradeCanBeSkipped(yangModelCmHandle, upgradedModuleSetTag)) { + cmHandleUpgradeResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)); + } else { + updateYangModelCmHandleForUpgrade(yangModelCmHandle, upgradedModuleSetTag); + acceptedCmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED); + } + } else { + cmHandleUpgradeResponses.add( + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_READY)); + } + } catch (final DataNodeNotFoundException dataNodeNotFoundException) { + log.error("Unable to find data node for cm handle id : {} , caused by : {}", + cmHandleId, dataNodeNotFoundException.getMessage()); + cmHandleUpgradeResponses.add( + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND)); + } catch (final DataValidationException dataValidationException) { + log.error("Unable to upgrade cm handle id: {}, caused by : {}", + cmHandleId, dataValidationException.getMessage()); + cmHandleUpgradeResponses.add( + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID)); + } + } + cmHandleUpgradeResponses.addAll(upgradeCmHandles(acceptedCmHandleStatePerCmHandle)); + dmiPluginRegistrationResponse.setUpgradedCmHandles(cmHandleUpgradeResponses); + } + + private void processTrustLevels(final Collection cmHandlesToBeCreated, + final Collection succeededCmHandleIds) { + final Map initialTrustLevelPerCmHandleId = new HashMap<>(cmHandlesToBeCreated.size()); + for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) { + if (succeededCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) { + initialTrustLevelPerCmHandleId.put(ncmpServiceCmHandle.getCmHandleId(), + ncmpServiceCmHandle.getRegistrationTrustLevel()); + } + } + trustLevelManager.handleInitialRegistrationOfTrustLevels(initialTrustLevelPerCmHandleId); + } + + private static boolean moduleUpgradeCanBeSkipped(final YangModelCmHandle yangModelCmHandle, + final String upgradedModuleSetTag) { + if (StringUtils.isBlank(upgradedModuleSetTag)) { + return false; + } + return yangModelCmHandle.getModuleSetTag().equals(upgradedModuleSetTag); + } + + private static void updateYangModelCmHandleForUpgrade(final YangModelCmHandle yangModelCmHandle, + final String upgradedModuleSetTag) { + final String lockReasonWithModuleSetTag = String.format(ModuleOperationsUtils.MODULE_SET_TAG_MESSAGE_FORMAT, + upgradedModuleSetTag); + yangModelCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.READY) + .withLockReason(MODULE_UPGRADE, lockReasonWithModuleSetTag).build()); + } + + private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) { + try { + deleteCmHandleFromDbAndModuleSyncMap(cmHandleId); + return CmHandleRegistrationResponse.createSuccessResponse(cmHandleId); + } catch (final DataNodeNotFoundException dataNodeNotFoundException) { + log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", + cmHandleId, dataNodeNotFoundException.getMessage()); + return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND); + } catch (final DataValidationException dataValidationException) { + log.error("Unable to de-register cm-handle id: {}, caused by: {}", + cmHandleId, dataValidationException.getMessage()); + return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID); + } catch (final Exception exception) { + log.error("Unable to de-register cm-handle id : {} , caused by : {}", cmHandleId, exception.getMessage()); + return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception); + } + } + + private void updateCmHandleStateBatch(final Collection yangModelCmHandles, + final CmHandleState cmHandleState) { + final Map cmHandleStatePerCmHandle = new HashMap<>(yangModelCmHandles.size()); + yangModelCmHandles.forEach(yangModelCmHandle -> cmHandleStatePerCmHandle.put(yangModelCmHandle, cmHandleState)); + lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); + } + + private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) { + inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId); + inventoryPersistence.deleteDataNode(NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']"); + removeDeletedCmHandleFromModuleSyncMap(cmHandleId); + } + + private void batchDeleteCmHandlesFromDbAndModuleSyncMap(final Collection cmHandleIds) { + inventoryPersistence.deleteSchemaSetsWithCascade(cmHandleIds); + inventoryPersistence.deleteDataNodes(mapCmHandleIdsToXpaths(cmHandleIds)); + cmHandleIds.forEach(this::removeDeletedCmHandleFromModuleSyncMap); + } + + private Collection mapCmHandleIdsToXpaths(final Collection cmHandles) { + return cmHandles.stream() + .map(cmHandleId -> NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']") + .collect(Collectors.toSet()); + } + + // CPS-1239 Robustness cleaning of in progress cache + private void removeDeletedCmHandleFromModuleSyncMap(final String cmHandleId) { + if (moduleSyncStartedOnCmHandles.remove(cmHandleId) != null) { + log.debug("{} removed from in progress map", cmHandleId); + } + } + + private List upgradeCmHandles(final Map + cmHandleStatePerCmHandle) { + final List cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle); + log.info("Moving cm handles : {} into locked (for upgrade) state.", cmHandleIds); + try { + lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); + return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds); + } catch (final Exception e) { + log.error("Unable to update cmHandleIds : {} , caused by : {}", cmHandleIds, e.getMessage()); + return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, e); + } + } + + private static List getCmHandleIds(final Map cmHandleStatePerCmHandle) { + return cmHandleStatePerCmHandle.keySet().stream().map(YangModelCmHandle::getId).toList(); + } + + private void setTrustLevelPerDmiPlugin(final DmiPluginRegistration dmiPluginRegistration) { + if (DmiPluginRegistration.isNullEmptyOrBlank(dmiPluginRegistration.getDmiDataPlugin())) { + trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiPlugin(), TrustLevel.COMPLETE); + } else { + trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiDataPlugin(), TrustLevel.COMPLETE); + } + } + + private Collection checkAlternateIds( + final List cmHandlesToBeCreated, + final List cmHandleRegistrationResponses) { + final Collection rejectedCmHandleIds = alternateIdChecker + .getIdsOfCmHandlesWithRejectedAlternateId(cmHandlesToBeCreated, AlternateIdChecker.Operation.CREATE); + cmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponses( + rejectedCmHandleIds, ALTERNATE_ID_ALREADY_ASSOCIATED)); + return rejectedCmHandleIds; + } + + private List persistCmHandlesWithState(final DmiPluginRegistration dmiPluginRegistration, + final DmiPluginRegistrationResponse dmiPluginRegistrationResponse, + final List cmHandlesToBeCreated, + final Collection rejectedCmHandleIds) { + final List succeededCmHandleIds = new ArrayList<>(cmHandlesToBeCreated.size()); + final List yangModelCmHandlesToRegister = new ArrayList<>(cmHandlesToBeCreated.size()); + final List cmHandleRegistrationResponses = + new ArrayList<>(cmHandlesToBeCreated.size()); + for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) { + if (!rejectedCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) { + yangModelCmHandlesToRegister.add(getYangModelCmHandle(dmiPluginRegistration, ncmpServiceCmHandle)); + cmHandleRegistrationResponses.add( + CmHandleRegistrationResponse.createSuccessResponse(ncmpServiceCmHandle.getCmHandleId())); + succeededCmHandleIds.add(ncmpServiceCmHandle.getCmHandleId()); + } + } + lcmEventsCmHandleStateHandler.initiateStateAdvised(yangModelCmHandlesToRegister); + dmiPluginRegistrationResponse.setCreatedCmHandles(cmHandleRegistrationResponses); + return succeededCmHandleIds; + } + + private YangModelCmHandle getYangModelCmHandle(final DmiPluginRegistration dmiPluginRegistration, + final NcmpServiceCmHandle ncmpServiceCmHandle) { + return YangModelCmHandle.toYangModelCmHandle( + dmiPluginRegistration.getDmiPlugin(), + dmiPluginRegistration.getDmiDataPlugin(), + dmiPluginRegistration.getDmiModelPlugin(), + ncmpServiceCmHandle, + ncmpServiceCmHandle.getModuleSetTag(), + ncmpServiceCmHandle.getAlternateId(), + ncmpServiceCmHandle.getDataProducerIdentifier()); + } + + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationServicePropertyHandler.java new file mode 100644 index 0000000000..1dac33f670 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationServicePropertyHandler.java @@ -0,0 +1,246 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022-2024 Nordix Foundation + * Modifications Copyright (C) 2022 Bell Canada + * Modifications Copyright (C) 2024 TechMahindra Ltd. + * ================================================================================ + * 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; + +import static org.onap.cps.ncmp.api.NcmpResponseStatus.ALTERNATE_ID_ALREADY_ASSOCIATED; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID; +import static org.onap.cps.ncmp.api.impl.CmHandleRegistrationServicePropertyHandler.PropertyType.DMI_PROPERTY; +import static org.onap.cps.ncmp.api.impl.CmHandleRegistrationServicePropertyHandler.PropertyType.PUBLIC_PROPERTY; +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME; +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR; +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; + +import com.google.common.collect.ImmutableMap; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.onap.cps.api.CpsDataService; +import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; +import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker; +import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; +import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; +import org.onap.cps.spi.exceptions.DataNodeNotFoundException; +import org.onap.cps.spi.exceptions.DataValidationException; +import org.onap.cps.spi.model.DataNode; +import org.onap.cps.spi.model.DataNodeBuilder; +import org.onap.cps.utils.ContentType; +import org.onap.cps.utils.JsonObjectMapper; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +@Slf4j +@Service +@RequiredArgsConstructor +//Accepting the security hotspot as the string checked is generated from inside code and not user input. +@SuppressWarnings("squid:S5852") +public class CmHandleRegistrationServicePropertyHandler { + + private final InventoryPersistence inventoryPersistence; + private final CpsDataService cpsDataService; + private final JsonObjectMapper jsonObjectMapper; + private final AlternateIdChecker alternateIdChecker; + + /** + * Iterates over incoming updatedNcmpServiceCmHandles and update the dataNodes based on the updated attributes. + * The attributes which are not passed will remain as is. + * + * @param updatedNcmpServiceCmHandles collection of CmHandles + */ + public List updateCmHandleProperties( + final Collection updatedNcmpServiceCmHandles) { + final Collection rejectedCmHandleIds = alternateIdChecker + .getIdsOfCmHandlesWithRejectedAlternateId(updatedNcmpServiceCmHandles, AlternateIdChecker.Operation.UPDATE); + final List failureResponses = + CmHandleRegistrationResponse.createFailureResponses(rejectedCmHandleIds, ALTERNATE_ID_ALREADY_ASSOCIATED); + final List cmHandleRegistrationResponses = new ArrayList<>(failureResponses); + for (final NcmpServiceCmHandle updatedNcmpServiceCmHandle : updatedNcmpServiceCmHandles) { + final String cmHandleId = updatedNcmpServiceCmHandle.getCmHandleId(); + if (!rejectedCmHandleIds.contains(cmHandleId)) { + try { + final DataNode existingCmHandleDataNode = inventoryPersistence + .getCmHandleDataNodeByCmHandleId(cmHandleId).iterator().next(); + processUpdates(existingCmHandleDataNode, updatedNcmpServiceCmHandle); + cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)); + } catch (final DataNodeNotFoundException e) { + log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandleId, + e.getMessage()); + cmHandleRegistrationResponses.add( + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND)); + } catch (final DataValidationException e) { + log.error("Unable to update cm handle : {}, caused by : {}", cmHandleId, e.getMessage()); + cmHandleRegistrationResponses.add( + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID)); + } catch (final Exception exception) { + log.error("Unable to update cmHandle : {} , caused by : {}", cmHandleId, exception.getMessage()); + cmHandleRegistrationResponses.add( + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception)); + } + } + } + return cmHandleRegistrationResponses; + } + + private void processUpdates(final DataNode existingCmHandleDataNode, + final NcmpServiceCmHandle updatedNcmpServiceCmHandle) { + setAndUpdateCmHandleField( + updatedNcmpServiceCmHandle.getCmHandleId(), "alternate-id", updatedNcmpServiceCmHandle.getAlternateId()); + updateDataProducerIdentifier(existingCmHandleDataNode, updatedNcmpServiceCmHandle); + if (!updatedNcmpServiceCmHandle.getPublicProperties().isEmpty()) { + updateProperties(existingCmHandleDataNode, PUBLIC_PROPERTY, + updatedNcmpServiceCmHandle.getPublicProperties()); + } + if (!updatedNcmpServiceCmHandle.getDmiProperties().isEmpty()) { + updateProperties(existingCmHandleDataNode, DMI_PROPERTY, updatedNcmpServiceCmHandle.getDmiProperties()); + } + } + + private void updateDataProducerIdentifier(final DataNode cmHandleDataNode, + final NcmpServiceCmHandle ncmpServiceCmHandle) { + final String newDataProducerIdentifier = ncmpServiceCmHandle.getDataProducerIdentifier(); + if (StringUtils.hasText(newDataProducerIdentifier)) { + final YangModelCmHandle yangModelCmHandle = + YangDataConverter.convertCmHandleToYangModel(cmHandleDataNode); + final String existingDataProducerIdentifier = yangModelCmHandle.getDataProducerIdentifier(); + if (StringUtils.hasText(existingDataProducerIdentifier)) { + if (!existingDataProducerIdentifier.equals(newDataProducerIdentifier)) { + log.warn("Unable to update dataProducerIdentifier for cmHandle {}. " + + "Value for dataProducerIdentifier has been set previously.", + ncmpServiceCmHandle.getCmHandleId()); + } else { + log.debug("dataProducerIdentifier for cmHandle {} is already set to {}.", + ncmpServiceCmHandle.getCmHandleId(), newDataProducerIdentifier); + } + } else { + setAndUpdateCmHandleField( + yangModelCmHandle.getId(), "data-producer-identifier", newDataProducerIdentifier); + } + } + } + + private void updateProperties(final DataNode existingCmHandleDataNode, final PropertyType propertyType, + final Map updatedProperties) { + final Collection replacementPropertyDataNodes = + getReplacementDataNodes(existingCmHandleDataNode, propertyType, updatedProperties); + replacementPropertyDataNodes.addAll( + getUnchangedPropertyDataNodes(existingCmHandleDataNode, propertyType, updatedProperties)); + if (replacementPropertyDataNodes.isEmpty()) { + removeAllProperties(existingCmHandleDataNode, propertyType); + } else { + inventoryPersistence.replaceListContent(existingCmHandleDataNode.getXpath(), replacementPropertyDataNodes); + } + } + + private void removeAllProperties(final DataNode existingCmHandleDataNode, final PropertyType propertyType) { + existingCmHandleDataNode.getChildDataNodes().forEach(dataNode -> { + final Matcher matcher = propertyType.propertyXpathPattern.matcher(dataNode.getXpath()); + if (matcher.find()) { + log.info("Deleting dataNode with xpath : [{}]", dataNode.getXpath()); + inventoryPersistence.deleteDataNode(dataNode.getXpath()); + } + }); + } + + private Collection getUnchangedPropertyDataNodes(final DataNode existingCmHandleDataNode, + final PropertyType propertyType, + final Map updatedProperties) { + final Collection unchangedPropertyDataNodes = new HashSet<>(); + for (final DataNode existingPropertyDataNode : existingCmHandleDataNode.getChildDataNodes()) { + final Matcher matcher = propertyType.propertyXpathPattern.matcher(existingPropertyDataNode.getXpath()); + if (matcher.find()) { + final String keyName = matcher.group(2); + if (!updatedProperties.containsKey(keyName)) { + unchangedPropertyDataNodes.add(existingPropertyDataNode); + } + } + } + return unchangedPropertyDataNodes; + } + + private Collection getReplacementDataNodes(final DataNode existingCmHandleDataNode, + final PropertyType propertyType, + final Map updatedProperties) { + final Collection replacementPropertyDataNodes = new HashSet<>(); + updatedProperties.forEach((updatedAttributeKey, updatedAttributeValue) -> { + final String propertyXpath = getAttributeXpath(existingCmHandleDataNode, propertyType, updatedAttributeKey); + if (updatedAttributeValue != null) { + log.info("Creating a new DataNode with xpath {} , key : {} and value : {}", propertyXpath, + updatedAttributeKey, updatedAttributeValue); + replacementPropertyDataNodes.add( + buildDataNode(propertyXpath, updatedAttributeKey, updatedAttributeValue)); + } + }); + return replacementPropertyDataNodes; + } + + private String getAttributeXpath(final DataNode cmHandle, final PropertyType propertyType, + final String attributeKey) { + return cmHandle.getXpath() + "/" + propertyType.xpathPrefix + String.format("[@name='%s']", attributeKey); + } + + private DataNode buildDataNode(final String xpath, final String attributeKey, final String attributeValue) { + final Map updatedLeaves = new LinkedHashMap<>(1); + updatedLeaves.put("name", attributeKey); + updatedLeaves.put("value", attributeValue); + log.debug("Building a new node with xpath {} with leaves (name : {} , value : {})", xpath, attributeKey, + attributeValue); + return new DataNodeBuilder().withXpath(xpath).withLeaves(ImmutableMap.copyOf(updatedLeaves)).build(); + } + + private void setAndUpdateCmHandleField(final String cmHandleIdToUpdate, final String fieldName, + final String newFieldValue) { + final Map> dmiRegistryData = new HashMap<>(1); + final Map cmHandleData = new HashMap<>(2); + cmHandleData.put("id", cmHandleIdToUpdate); + cmHandleData.put(fieldName, newFieldValue); + dmiRegistryData.put("cm-handles", cmHandleData); + cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT, + jsonObjectMapper.asJsonString(dmiRegistryData), OffsetDateTime.now(), ContentType.JSON); + log.debug("Updating {} for cmHandle {} with value : {})", fieldName, cmHandleIdToUpdate, newFieldValue); + } + + enum PropertyType { + DMI_PROPERTY("additional-properties"), PUBLIC_PROPERTY("public-properties"); + + private static final String LIST_INDEX_PATTERN = "\\[@(\\w+)[^\\/]'([^']+)']"; + + final String xpathPrefix; + final Pattern propertyXpathPattern; + + PropertyType(final String xpathPrefix) { + this.xpathPrefix = xpathPrefix; + this.propertyXpathPattern = Pattern.compile(xpathPrefix + LIST_INDEX_PATTERN); + } + } +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpCachedResourceRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpCachedResourceRequestHandler.java index eb43718f02..da230cf732 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpCachedResourceRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpCachedResourceRequestHandler.java @@ -22,7 +22,7 @@ package org.onap.cps.ncmp.api.impl; import java.util.Collection; import lombok.RequiredArgsConstructor; -import org.onap.cps.ncmp.api.NetworkCmProxyDataService; +import org.onap.cps.api.CpsDataService; import org.onap.cps.ncmp.api.NetworkCmProxyQueryService; import org.onap.cps.ncmp.api.models.CmResourceAddress; import org.onap.cps.spi.FetchDescendantsOption; @@ -34,7 +34,7 @@ import reactor.core.publisher.Mono; @RequiredArgsConstructor public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandler { - private final NetworkCmProxyDataService networkCmProxyDataService; + private final CpsDataService cpsDataService; private final NetworkCmProxyQueryService networkCmProxyQueryService; /** @@ -61,8 +61,12 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle final boolean includeDescendants, final String authorization) { final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants); - return Mono.fromSupplier( - () -> networkCmProxyDataService.getResourceDataForCmHandle(cmResourceAddress, fetchDescendantsOption)); + + final DataNode dataNode = cpsDataService.getDataNodes(cmResourceAddress.datastoreName(), + cmResourceAddress.cmHandleId(), + cmResourceAddress.resourceIdentifier(), + fetchDescendantsOption).iterator().next(); + return Mono.justOrEmpty(dataNode); } private static FetchDescendantsOption getFetchDescendantsOption(final boolean includeDescendants) { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java index dbd2bb4938..302ba449c7 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java @@ -45,46 +45,43 @@ public abstract class NcmpDatastoreRequestHandler { * Executes synchronous/asynchronous get request for given cm handle. * * @param cmResourceAddress the name of the datastore, cm handle and resource identifier - * @param optionsParamInQuery the options param in query - * @param topicParamInQuery the topic param in query + * @param options options to pass through to dmi client + * @param topic topic (optional) for asynchronous responses * @param includeDescendants whether include descendants * @param authorization contents of Authorization header, or null if not present * @return the result object, depends on use op topic. With topic a map object with request id is returned * otherwise the result of the request. */ public Object executeRequest(final CmResourceAddress cmResourceAddress, - final String optionsParamInQuery, - final String topicParamInQuery, - final boolean includeDescendants, - final String authorization) { + final String options, + final String topic, + final boolean includeDescendants, + final String authorization) { - final boolean asyncResponseRequested = topicParamInQuery != null; + final boolean asyncResponseRequested = topic != null; if (asyncResponseRequested && notificationFeatureEnabled) { - return fetchResourceDataAsynchronously(cmResourceAddress, optionsParamInQuery, topicParamInQuery, - includeDescendants, authorization); + return getResourceDataAsynchronously(cmResourceAddress, options, topic, includeDescendants, authorization); } if (asyncResponseRequested) { log.warn("Asynchronous request is unavailable as notification feature is currently disabled, " + "will use synchronous operation."); } - final Mono resourceDataMono = getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery, + final Mono resourceDataMono = getResourceDataForCmHandle(cmResourceAddress, options, NO_TOPIC, NO_REQUEST_ID, includeDescendants, authorization); return resourceDataMono.block(); } - private Map fetchResourceDataAsynchronously(final CmResourceAddress cmResourceAddress, - final String optionsParamInQuery, - final String topicParamInQuery, - final boolean includeDescendants, - final String authorization) { - TopicValidator.validateTopicName(topicParamInQuery); + private Map getResourceDataAsynchronously(final CmResourceAddress cmResourceAddress, + final String options, + final String topic, + final boolean includeDescendants, + final String authorization) { + TopicValidator.validateTopicName(topic); final String requestId = UUID.randomUUID().toString(); - getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery, topicParamInQuery, requestId, - includeDescendants, authorization) - .doOnSuccess(result -> log.debug("Async operation succeeded for request id {}: {}", requestId, result)) - .doOnError(error -> - log.error("Async operation failed for request id {}: {}", requestId, error.getMessage())) + getResourceDataForCmHandle(cmResourceAddress, options, topic, requestId, includeDescendants, authorization) + .doOnSuccess(result -> + log.debug("Async operation succeeded for request id {}: {}", requestId, result)) .subscribe(); log.debug("Received Async request with id {}", requestId); return Map.of("requestId", requestId); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java index 90d9a23d6d..0fd32501c3 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java @@ -26,9 +26,9 @@ import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ; import java.util.Map; import java.util.UUID; import lombok.RequiredArgsConstructor; -import org.onap.cps.ncmp.api.NetworkCmProxyDataService; import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException; import org.onap.cps.ncmp.api.impl.operations.DatastoreType; +import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations; import org.onap.cps.ncmp.api.impl.operations.OperationType; import org.onap.cps.ncmp.api.models.CmResourceAddress; import org.onap.cps.ncmp.api.models.DataOperationRequest; @@ -42,60 +42,60 @@ import reactor.core.publisher.Mono; @RequiredArgsConstructor public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestHandler { - private final NetworkCmProxyDataService networkCmProxyDataService; + private final DmiDataOperations dmiDataOperations; + private static final int MAXIMUM_CM_HANDLES_PER_OPERATION = 200; private static final String PAYLOAD_TOO_LARGE_TEMPLATE = "Operation '%s' affects too many (%d) cm handles"; /** * Executes asynchronous request for group of cm handles to resource data. * - * @param topicParamInQuery the topic param in query - * @param dataOperationRequest data operation request details for resource data - * @param authorization contents of Authorization header, or null if not present + * @param topic the topic param in query + * @param dataOperationRequest data operation request details for resource data + * @param authorization contents of Authorization header, or null if not present * @return a map with one entry of request Id for success or status and error when async feature is disabled */ - public Map executeRequest(final String topicParamInQuery, - final DataOperationRequest dataOperationRequest, - final String authorization) { - validateDataOperationRequest(topicParamInQuery, dataOperationRequest); + public Map executeAsynchronousRequest(final String topic, + final DataOperationRequest dataOperationRequest, + final String authorization) { + validateDataOperationRequest(topic, dataOperationRequest); if (!notificationFeatureEnabled) { return Map.of("status", "Asynchronous request is unavailable as notification feature is currently disabled."); } final String requestId = UUID.randomUUID().toString(); - networkCmProxyDataService.executeDataOperationForCmHandles(topicParamInQuery, dataOperationRequest, requestId, - authorization); + dmiDataOperations.requestResourceDataFromDmi(topic, dataOperationRequest, requestId, authorization); return Map.of("requestId", requestId); - } @Override protected Mono getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress, - final String optionsParamInQuery, - final String topicParamInQuery, + final String options, + final String topic, final String requestId, final boolean includeDescendants, final String authorization) { - return networkCmProxyDataService.getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery, - topicParamInQuery, requestId, authorization); + + return dmiDataOperations.getResourceDataFromDmi(cmResourceAddress, options, topic, requestId, authorization) + .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody())); } private void validateDataOperationRequest(final String topicParamInQuery, final DataOperationRequest dataOperationRequest) { TopicValidator.validateTopicName(topicParamInQuery); - dataOperationRequest.getDataOperationDefinitions().forEach(dataOperationDetail -> { - if (OperationType.fromOperationName(dataOperationDetail.getOperation()) != READ) { + dataOperationRequest.getDataOperationDefinitions().forEach(dataOperationDefinition -> { + if (OperationType.fromOperationName(dataOperationDefinition.getOperation()) != READ) { throw new OperationNotSupportedException( - dataOperationDetail.getOperation() + " operation not yet supported"); + dataOperationDefinition.getOperation() + " operation not yet supported"); } - if (DatastoreType.fromDatastoreName(dataOperationDetail.getDatastore()) == OPERATIONAL) { - throw new InvalidDatastoreException(dataOperationDetail.getDatastore() + if (DatastoreType.fromDatastoreName(dataOperationDefinition.getDatastore()) == OPERATIONAL) { + throw new InvalidDatastoreException(dataOperationDefinition.getDatastore() + " datastore is not supported"); } - if (dataOperationDetail.getCmHandleIds().size() > MAXIMUM_CM_HANDLES_PER_OPERATION) { + if (dataOperationDefinition.getCmHandleIds().size() > MAXIMUM_CM_HANDLES_PER_OPERATION) { final String errorMessage = String.format(PAYLOAD_TOO_LARGE_TEMPLATE, - dataOperationDetail.getOperationId(), - dataOperationDetail.getCmHandleIds().size()); + dataOperationDefinition.getOperationId(), + dataOperationDefinition.getCmHandleIds().size()); throw new PayloadTooLargeException(errorMessage); } }); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceImpl.java deleted file mode 100644 index 8890d14ae1..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceImpl.java +++ /dev/null @@ -1,286 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022-2024 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; - -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; -import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.HAS_ALL_MODULES; -import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.HAS_ALL_PROPERTIES; -import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.WITH_CPS_PATH; -import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.WITH_TRUST_LEVEL; -import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCpsPathConditionProperties; -import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateModuleNameConditionProperties; -import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle; -import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY; -import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.onap.cps.cpspath.parser.PathParsingException; -import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService; -import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries; -import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; -import org.onap.cps.ncmp.api.impl.inventory.enums.PropertyType; -import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions; -import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; -import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; -import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; -import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; -import org.onap.cps.spi.exceptions.DataValidationException; -import org.onap.cps.spi.model.ConditionProperties; -import org.onap.cps.spi.model.DataNode; -import org.springframework.stereotype.Service; - -@Service -@Slf4j -@RequiredArgsConstructor -public class NetworkCmProxyCmHandleQueryServiceImpl implements NetworkCmProxyCmHandleQueryService { - - private static final Collection NO_QUERY_TO_EXECUTE = null; - private final CmHandleQueries cmHandleQueries; - private final InventoryPersistence inventoryPersistence; - - @Override - public Collection queryCmHandleIds( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { - return executeQueries(cmHandleQueryServiceParameters, - this::executeCpsPathQuery, - this::queryCmHandlesByPublicProperties, - this::executeModuleNameQuery, - this::queryCmHandlesByTrustLevel); - } - - @Override - public Collection queryCmHandleIdsForInventory( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { - return executeQueries(cmHandleQueryServiceParameters, - this::queryCmHandlesByPublicProperties, - this::queryCmHandlesByPrivateProperties, - this::queryCmHandlesByDmiPlugin); - } - - @Override - public Collection queryCmHandles( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { - - if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) { - return getAllCmHandles(); - } - - final Collection cmHandleIds = queryCmHandleIds(cmHandleQueryServiceParameters); - - return getNcmpServiceCmHandles(cmHandleIds); - } - - @Override - public Collection getAllCmHandles() { - final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT).iterator().next(); - return dataNode.getChildDataNodes().stream().map(this::createNcmpServiceCmHandle).collect(Collectors.toSet()); - } - - private Collection queryCmHandlesByDmiPlugin( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { - final Map dmiPropertyQueryPairs = - getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), - InventoryQueryConditions.CM_HANDLE_WITH_DMI_PLUGIN.getName()); - if (dmiPropertyQueryPairs.isEmpty()) { - return NO_QUERY_TO_EXECUTE; - } - - final String dmiPluginIdentifierValue = dmiPropertyQueryPairs - .get(PropertyType.DMI_PLUGIN.getYangContainerName()); - - return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifierValue); - } - - private Collection queryCmHandlesByPrivateProperties( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { - - final Map privatePropertyQueryPairs = - getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), - InventoryQueryConditions.HAS_ALL_ADDITIONAL_PROPERTIES.getName()); - - if (privatePropertyQueryPairs.isEmpty()) { - return NO_QUERY_TO_EXECUTE; - } - return cmHandleQueries.queryCmHandleAdditionalProperties(privatePropertyQueryPairs); - } - - private Collection queryCmHandlesByPublicProperties( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { - - final Map publicPropertyQueryPairs = - getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), - HAS_ALL_PROPERTIES.getConditionName()); - - if (publicPropertyQueryPairs.isEmpty()) { - return NO_QUERY_TO_EXECUTE; - } - return cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs); - } - - private Collection queryCmHandlesByTrustLevel(final CmHandleQueryServiceParameters - cmHandleQueryServiceParameters) { - - final Map trustLevelPropertyQueryPairs = - getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), - WITH_TRUST_LEVEL.getConditionName()); - - if (trustLevelPropertyQueryPairs.isEmpty()) { - return NO_QUERY_TO_EXECUTE; - } - return cmHandleQueries.queryCmHandlesByTrustLevel(trustLevelPropertyQueryPairs); - } - - private Collection executeModuleNameQuery( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { - final Collection moduleNamesForQuery = - getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); - if (moduleNamesForQuery.isEmpty()) { - return NO_QUERY_TO_EXECUTE; - } - return inventoryPersistence.getCmHandleIdsWithGivenModules(moduleNamesForQuery); - } - - private Collection executeCpsPathQuery( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { - final Map cpsPathCondition - = getCpsPathCondition(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); - if (!validateCpsPathConditionProperties(cpsPathCondition)) { - return Collections.emptySet(); - } - final Collection cpsPathQueryResult; - if (cpsPathCondition.isEmpty()) { - return NO_QUERY_TO_EXECUTE; - } - try { - cpsPathQueryResult = collectCmHandleIdsFromDataNodes( - cmHandleQueries.queryCmHandleAncestorsByCpsPath( - cpsPathCondition.get("cpsPath"), OMIT_DESCENDANTS)); - } catch (final PathParsingException pathParsingException) { - throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(), - pathParsingException); - } - return cpsPathQueryResult; - } - - private Collection getModuleNamesForQuery(final List conditionProperties) { - final List result = new ArrayList<>(); - getConditions(conditionProperties, HAS_ALL_MODULES.getConditionName()).forEach( - conditionProperty -> { - validateModuleNameConditionProperties(conditionProperty); - result.add(conditionProperty.get("moduleName")); - }); - return result; - } - - private Map getCpsPathCondition(final List conditionProperties) { - final Map result = new HashMap<>(); - getConditions(conditionProperties, WITH_CPS_PATH.getConditionName()).forEach(result::putAll); - return result; - } - - private Map getPropertyPairs(final List conditionProperties, - final String queryProperty) { - final Map result = new HashMap<>(); - getConditions(conditionProperties, queryProperty).forEach(result::putAll); - return result; - } - - private List> getConditions(final List conditionProperties, - final String name) { - for (final ConditionProperties conditionProperty : conditionProperties) { - if (conditionProperty.getConditionName().equals(name)) { - return conditionProperty.getConditionParameters(); - } - } - return Collections.emptyList(); - } - - private Collection getAllCmHandleIds() { - final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT, DIRECT_CHILDREN_ONLY) - .iterator().next(); - return collectCmHandleIdsFromDataNodes(dataNode.getChildDataNodes()); - } - - private Collection getNcmpServiceCmHandles(final Collection cmHandleIds) { - final Collection yangModelcmHandles - = inventoryPersistence.getYangModelCmHandles(cmHandleIds); - - final Collection ncmpServiceCmHandles = new ArrayList<>(yangModelcmHandles.size()); - - yangModelcmHandles.forEach(yangModelcmHandle -> - ncmpServiceCmHandles.add(YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(yangModelcmHandle)) - ); - return ncmpServiceCmHandles; - } - - private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) { - return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter.convertCmHandleToYangModel(dataNode)); - } - - private Collection executeQueries(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, - final Function>... - queryFunctions) { - if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) { - return getAllCmHandleIds(); - } - Collection combinedQueryResult = NO_QUERY_TO_EXECUTE; - for (final Function> queryFunction : queryFunctions) { - final Collection queryResult = queryFunction.apply(cmHandleQueryServiceParameters); - if (noEntriesFoundCanStopQuerying(queryResult)) { - return Collections.emptySet(); - } - combinedQueryResult = combineCmHandleQueryResults(combinedQueryResult, queryResult); - } - return combinedQueryResult; - } - - private boolean noEntriesFoundCanStopQuerying(final Collection queryResult) { - return queryResult != NO_QUERY_TO_EXECUTE && queryResult.isEmpty(); - } - - private Collection combineCmHandleQueryResults(final Collection firstQuery, - final Collection secondQuery) { - if (firstQuery == NO_QUERY_TO_EXECUTE && secondQuery == NO_QUERY_TO_EXECUTE) { - return NO_QUERY_TO_EXECUTE; - } else if (firstQuery == NO_QUERY_TO_EXECUTE) { - return secondQuery; - } else if (secondQuery == NO_QUERY_TO_EXECUTE) { - return firstQuery; - } else { - firstQuery.retainAll(secondQuery); - return firstQuery; - } - } - - private Collection collectCmHandleIdsFromDataNodes(final Collection dataNodes) { - return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet()); - } - -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java deleted file mode 100755 index 754050947a..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java +++ /dev/null @@ -1,568 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 highstreet technologies GmbH - * Modifications Copyright (C) 2021-2024 Nordix Foundation - * Modifications Copyright (C) 2021 Pantheon.tech - * Modifications Copyright (C) 2021-2022 Bell Canada - * Modifications Copyright (C) 2023 TechMahindra Ltd. - * ================================================================================ - * 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; - -import static org.onap.cps.ncmp.api.NcmpResponseStatus.ALTERNATE_ID_ALREADY_ASSOCIATED; -import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND; -import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_READY; -import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST; -import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID; -import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE; -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME; -import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters; - -import com.google.common.collect.Lists; -import com.hazelcast.map.IMap; -import java.time.OffsetDateTime; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.onap.cps.api.CpsDataService; -import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService; -import org.onap.cps.ncmp.api.NetworkCmProxyDataService; -import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig; -import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler; -import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries; -import org.onap.cps.ncmp.api.impl.inventory.CmHandleState; -import org.onap.cps.ncmp.api.impl.inventory.CompositeState; -import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder; -import org.onap.cps.ncmp.api.impl.inventory.CompositeStateUtils; -import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState; -import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; -import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleOperationsUtils; -import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations; -import org.onap.cps.ncmp.api.impl.operations.OperationType; -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager; -import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker; -import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions; -import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions; -import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; -import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; -import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters; -import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; -import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; -import org.onap.cps.ncmp.api.models.CmResourceAddress; -import org.onap.cps.ncmp.api.models.DataOperationRequest; -import org.onap.cps.ncmp.api.models.DmiPluginRegistration; -import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse; -import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; -import org.onap.cps.spi.FetchDescendantsOption; -import org.onap.cps.spi.exceptions.AlreadyDefinedException; -import org.onap.cps.spi.exceptions.CpsException; -import org.onap.cps.spi.exceptions.DataNodeNotFoundException; -import org.onap.cps.spi.exceptions.DataValidationException; -import org.onap.cps.spi.model.ModuleDefinition; -import org.onap.cps.spi.model.ModuleReference; -import org.onap.cps.utils.JsonObjectMapper; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; - -@Slf4j -@Service -@RequiredArgsConstructor -public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService { - - private static final int DELETE_BATCH_SIZE = 100; - private final JsonObjectMapper jsonObjectMapper; - private final DmiDataOperations dmiDataOperations; - private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler; - private final InventoryPersistence inventoryPersistence; - private final CmHandleQueries cmHandleQueries; - private final NetworkCmProxyCmHandleQueryService networkCmProxyCmHandleQueryService; - private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler; - private final CpsDataService cpsDataService; - private final IMap moduleSyncStartedOnCmHandles; - - @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN) - private final Map trustLevelPerDmiPlugin; - - private final TrustLevelManager trustLevelManager; - private final AlternateIdChecker alternateIdChecker; - - @Override - public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule( - final DmiPluginRegistration dmiPluginRegistration) { - - dmiPluginRegistration.validateDmiPluginRegistration(); - final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse(); - - setTrustLevelPerDmiPlugin(dmiPluginRegistration); - - processRemovedCmHandles(dmiPluginRegistration, dmiPluginRegistrationResponse); - - processCreatedCmHandles(dmiPluginRegistration, dmiPluginRegistrationResponse); - - processUpdatedCmHandles(dmiPluginRegistration, dmiPluginRegistrationResponse); - - processUpgradedCmHandles(dmiPluginRegistration, dmiPluginRegistrationResponse); - - return dmiPluginRegistrationResponse; - } - - @Override - public Mono getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress, - final String optionsParamInQuery, - final String topicParamInQuery, - final String requestId, - final String authorization) { - return dmiDataOperations.getResourceDataFromDmi(cmResourceAddress, optionsParamInQuery, topicParamInQuery, - requestId, authorization) - .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody())); - } - - @Override - public Object getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress, - final FetchDescendantsOption fetchDescendantsOption) { - return cpsDataService.getDataNodes(cmResourceAddress.datastoreName(), - cmResourceAddress.cmHandleId(), - cmResourceAddress.resourceIdentifier(), - fetchDescendantsOption).iterator().next(); - } - - @Override - public void executeDataOperationForCmHandles(final String topicParamInQuery, - final DataOperationRequest dataOperationRequest, - final String requestId, - final String authorization) { - dmiDataOperations.requestResourceDataFromDmi(topicParamInQuery, dataOperationRequest, requestId, authorization); - } - - @Override - public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandleId, - final String resourceIdentifier, - final OperationType operationType, - final String requestData, - final String dataType, - final String authorization) { - return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier, - operationType, requestData, dataType, authorization); - } - - @Override - public Collection getYangResourcesModuleReferences(final String cmHandleId) { - return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId); - } - - @Override - public Collection getModuleDefinitionsByCmHandleId(final String cmHandleId) { - return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId); - } - - @Override - public Collection getModuleDefinitionsByCmHandleAndModule(final String cmHandleId, - final String moduleName, - final String moduleRevision) { - return inventoryPersistence.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, moduleRevision); - } - - /** - * Retrieve cm handles with details for the given query parameters. - * - * @param cmHandleQueryApiParameters cm handle query parameters - * @return cm handles with details - */ - @Override - public Collection executeCmHandleSearch( - final CmHandleQueryApiParameters cmHandleQueryApiParameters) { - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( - cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); - validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); - return networkCmProxyCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters); - } - - /** - * Retrieve cm handle ids for the given query parameters. - * - * @param cmHandleQueryApiParameters cm handle query parameters - * @return cm handle ids - */ - @Override - public Collection executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) { - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( - cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); - validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); - return networkCmProxyCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters); - } - - /** - * Set the data sync enabled flag, along with the data sync state - * based on the data sync enabled boolean for the cm handle id provided. - * - * @param cmHandleId cm handle id - * @param dataSyncEnabledTargetValue data sync enabled flag - */ - @Override - public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) { - final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId); - if (dataSyncEnabledTargetValue.equals(compositeState.getDataSyncEnabled())) { - log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabledTargetValue); - return; - } - if (CmHandleState.READY.equals(compositeState.getCmHandleState())) { - final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores() - .getOperationalDataStore().getDataStoreSyncState(); - if (Boolean.FALSE.equals(dataSyncEnabledTargetValue) - && DataStoreSyncState.SYNCHRONIZED.equals(dataStoreSyncState)) { - // TODO : This is hard-coded for onap dmi that need to be addressed - cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, - "/netconf-state", OffsetDateTime.now()); - } - CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabledTargetValue, compositeState); - inventoryPersistence.saveCmHandleState(cmHandleId, compositeState); - } else { - throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: " - + compositeState.getCmHandleState()); - } - } - - /** - * Get all cm handle IDs by DMI plugin identifier. - * - * @param dmiPluginIdentifier DMI plugin identifier - * @return set of cm handle IDs - */ - @Override - public Collection getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) { - return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier); - } - - /** - * Get all cm handle IDs by various properties. - * - * @param cmHandleQueryServiceParameters cm handle query parameters - * @return set of cm handle IDs - */ - @Override - public Collection executeCmHandleIdSearchForInventory( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { - validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES); - return networkCmProxyCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters); - } - - /** - * Retrieve cm handle details for a given cm handle. - * - * @param cmHandleId cm handle identifier - * @return cm handle details - */ - @Override - public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) { - return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle( - inventoryPersistence.getYangModelCmHandle(cmHandleId)); - } - - /** - * Get cm handle public properties for a given cm handle id. - * - * @param cmHandleId cm handle identifier - * @return cm handle public properties - */ - @Override - public Map getCmHandlePublicProperties(final String cmHandleId) { - final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); - final List yangModelPublicProperties = yangModelCmHandle.getPublicProperties(); - final Map cmHandlePublicProperties = new HashMap<>(); - YangDataConverter.asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties); - return cmHandlePublicProperties; - } - - /** - * Get cm handle composite state for a given cm handle id. - * - * @param cmHandleId cm handle identifier - * @return cm handle state - */ - @Override - public CompositeState getCmHandleCompositeState(final String cmHandleId) { - return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState(); - } - - protected void processRemovedCmHandles(final DmiPluginRegistration dmiPluginRegistration, - final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) { - final List tobeRemovedCmHandleIds = dmiPluginRegistration.getRemovedCmHandles(); - final List cmHandleRegistrationResponses = - new ArrayList<>(tobeRemovedCmHandleIds.size()); - final Collection yangModelCmHandles = - inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandleIds); - updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING); - - final Set notDeletedCmHandles = new HashSet<>(); - for (final List tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandleIds, DELETE_BATCH_SIZE)) { - try { - batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch); - tobeRemovedCmHandleBatch.forEach(cmHandleId -> - cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId))); - - } catch (final RuntimeException batchException) { - log.error("Unable to de-register cm-handle batch, retrying on each cm handle"); - for (final String cmHandleId : tobeRemovedCmHandleBatch) { - final CmHandleRegistrationResponse cmHandleRegistrationResponse = - deleteCmHandleAndGetCmHandleRegistrationResponse(cmHandleId); - cmHandleRegistrationResponses.add(cmHandleRegistrationResponse); - if (cmHandleRegistrationResponse.getStatus() != CmHandleRegistrationResponse.Status.SUCCESS) { - notDeletedCmHandles.add(cmHandleId); - } - } - } - } - yangModelCmHandles.removeIf(yangModelCmHandle -> notDeletedCmHandles.contains(yangModelCmHandle.getId())); - updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETED); - dmiPluginRegistrationResponse.setRemovedCmHandles(cmHandleRegistrationResponses); - } - - protected void processCreatedCmHandles(final DmiPluginRegistration dmiPluginRegistration, - final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) { - final List ncmpServiceCmHandles = dmiPluginRegistration.getCreatedCmHandles(); - final List failedCmHandleRegistrationResponses = new ArrayList<>(); - - try { - final Collection rejectedCmHandleIds - = checkAlternateIds(ncmpServiceCmHandles, failedCmHandleRegistrationResponses); - - final Collection succeededCmHandleIds = persistCmHandlesWithState(dmiPluginRegistration, - dmiPluginRegistrationResponse, ncmpServiceCmHandles, rejectedCmHandleIds); - - processTrustLevels(ncmpServiceCmHandles, succeededCmHandleIds); - - } catch (final AlreadyDefinedException alreadyDefinedException) { - failedCmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponsesFromXpaths( - alreadyDefinedException.getAlreadyDefinedObjectNames(), CM_HANDLE_ALREADY_EXIST)); - } catch (final Exception exception) { - final Collection cmHandleIds = - ncmpServiceCmHandles.stream().map(NcmpServiceCmHandle::getCmHandleId).collect(Collectors.toList()); - failedCmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse - .createFailureResponses(cmHandleIds, exception)); - } - final List mergedCmHandleRegistrationResponses - = new ArrayList<>(failedCmHandleRegistrationResponses); - mergedCmHandleRegistrationResponses.addAll(dmiPluginRegistrationResponse.getCreatedCmHandles()); - - dmiPluginRegistrationResponse.setCreatedCmHandles(mergedCmHandleRegistrationResponses); - } - - protected void processUpdatedCmHandles(final DmiPluginRegistration dmiPluginRegistration, - final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) { - dmiPluginRegistrationResponse.setUpdatedCmHandles(networkCmProxyDataServicePropertyHandler - .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles())); - } - - protected void processUpgradedCmHandles( - final DmiPluginRegistration dmiPluginRegistration, - final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) { - - final List cmHandleIds = dmiPluginRegistration.getUpgradedCmHandles().getCmHandles(); - final String upgradedModuleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag(); - final Map acceptedCmHandleStatePerCmHandle - = new HashMap<>(cmHandleIds.size()); - final List cmHandleUpgradeResponses = new ArrayList<>(cmHandleIds.size()); - - for (final String cmHandleId : cmHandleIds) { - try { - final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); - if (yangModelCmHandle.getCompositeState().getCmHandleState() == CmHandleState.READY) { - if (moduleUpgradeCanBeSkipped(yangModelCmHandle, upgradedModuleSetTag)) { - cmHandleUpgradeResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)); - } else { - updateYangModelCmHandleForUpgrade(yangModelCmHandle, upgradedModuleSetTag); - acceptedCmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED); - } - } else { - cmHandleUpgradeResponses.add( - CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_READY)); - } - } catch (final DataNodeNotFoundException dataNodeNotFoundException) { - log.error("Unable to find data node for cm handle id : {} , caused by : {}", - cmHandleId, dataNodeNotFoundException.getMessage()); - cmHandleUpgradeResponses.add( - CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND)); - } catch (final DataValidationException dataValidationException) { - log.error("Unable to upgrade cm handle id: {}, caused by : {}", - cmHandleId, dataValidationException.getMessage()); - cmHandleUpgradeResponses.add( - CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID)); - } - } - cmHandleUpgradeResponses.addAll(upgradeCmHandles(acceptedCmHandleStatePerCmHandle)); - dmiPluginRegistrationResponse.setUpgradedCmHandles(cmHandleUpgradeResponses); - } - - private Collection checkAlternateIds( - final List cmHandlesToBeCreated, - final List cmHandleRegistrationResponses) { - final Collection rejectedCmHandleIds = alternateIdChecker - .getIdsOfCmHandlesWithRejectedAlternateId(cmHandlesToBeCreated, AlternateIdChecker.Operation.CREATE); - cmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponses( - rejectedCmHandleIds, ALTERNATE_ID_ALREADY_ASSOCIATED)); - return rejectedCmHandleIds; - } - - private List persistCmHandlesWithState(final DmiPluginRegistration dmiPluginRegistration, - final DmiPluginRegistrationResponse dmiPluginRegistrationResponse, - final List cmHandlesToBeCreated, - final Collection rejectedCmHandleIds) { - final List succeededCmHandleIds = new ArrayList<>(cmHandlesToBeCreated.size()); - final List yangModelCmHandlesToRegister = new ArrayList<>(cmHandlesToBeCreated.size()); - final List cmHandleRegistrationResponses = - new ArrayList<>(cmHandlesToBeCreated.size()); - for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) { - if (!rejectedCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) { - yangModelCmHandlesToRegister.add(getYangModelCmHandle(dmiPluginRegistration, ncmpServiceCmHandle)); - cmHandleRegistrationResponses.add( - CmHandleRegistrationResponse.createSuccessResponse(ncmpServiceCmHandle.getCmHandleId())); - succeededCmHandleIds.add(ncmpServiceCmHandle.getCmHandleId()); - } - } - lcmEventsCmHandleStateHandler.initiateStateAdvised(yangModelCmHandlesToRegister); - dmiPluginRegistrationResponse.setCreatedCmHandles(cmHandleRegistrationResponses); - return succeededCmHandleIds; - } - - private YangModelCmHandle getYangModelCmHandle(final DmiPluginRegistration dmiPluginRegistration, - final NcmpServiceCmHandle ncmpServiceCmHandle) { - return YangModelCmHandle.toYangModelCmHandle( - dmiPluginRegistration.getDmiPlugin(), - dmiPluginRegistration.getDmiDataPlugin(), - dmiPluginRegistration.getDmiModelPlugin(), - ncmpServiceCmHandle, - ncmpServiceCmHandle.getModuleSetTag(), - ncmpServiceCmHandle.getAlternateId(), - ncmpServiceCmHandle.getDataProducerIdentifier()); - } - - private void processTrustLevels(final Collection cmHandlesToBeCreated, - final Collection succeededCmHandleIds) { - final Map initialTrustLevelPerCmHandleId = new HashMap<>(cmHandlesToBeCreated.size()); - for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) { - if (succeededCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) { - initialTrustLevelPerCmHandleId.put(ncmpServiceCmHandle.getCmHandleId(), - ncmpServiceCmHandle.getRegistrationTrustLevel()); - } - } - trustLevelManager.handleInitialRegistrationOfTrustLevels(initialTrustLevelPerCmHandleId); - } - - private static boolean moduleUpgradeCanBeSkipped(final YangModelCmHandle yangModelCmHandle, - final String upgradedModuleSetTag) { - if (StringUtils.isBlank(upgradedModuleSetTag)) { - return false; - } - return yangModelCmHandle.getModuleSetTag().equals(upgradedModuleSetTag); - } - - private static void updateYangModelCmHandleForUpgrade(final YangModelCmHandle yangModelCmHandle, - final String upgradedModuleSetTag) { - final String lockReasonWithModuleSetTag = String.format(ModuleOperationsUtils.MODULE_SET_TAG_MESSAGE_FORMAT, - upgradedModuleSetTag); - yangModelCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.READY) - .withLockReason(MODULE_UPGRADE, lockReasonWithModuleSetTag).build()); - } - - private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) { - try { - deleteCmHandleFromDbAndModuleSyncMap(cmHandleId); - return CmHandleRegistrationResponse.createSuccessResponse(cmHandleId); - } catch (final DataNodeNotFoundException dataNodeNotFoundException) { - log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", - cmHandleId, dataNodeNotFoundException.getMessage()); - return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND); - } catch (final DataValidationException dataValidationException) { - log.error("Unable to de-register cm-handle id: {}, caused by: {}", - cmHandleId, dataValidationException.getMessage()); - return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID); - } catch (final Exception exception) { - log.error("Unable to de-register cm-handle id : {} , caused by : {}", cmHandleId, exception.getMessage()); - return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception); - } - } - - private void updateCmHandleStateBatch(final Collection yangModelCmHandles, - final CmHandleState cmHandleState) { - final Map cmHandleStatePerCmHandle = new HashMap<>(yangModelCmHandles.size()); - yangModelCmHandles.forEach(yangModelCmHandle -> cmHandleStatePerCmHandle.put(yangModelCmHandle, cmHandleState)); - lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); - } - - private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) { - inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId); - inventoryPersistence.deleteDataNode(NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']"); - removeDeletedCmHandleFromModuleSyncMap(cmHandleId); - } - - private void batchDeleteCmHandlesFromDbAndModuleSyncMap(final Collection cmHandleIds) { - inventoryPersistence.deleteSchemaSetsWithCascade(cmHandleIds); - inventoryPersistence.deleteDataNodes(mapCmHandleIdsToXpaths(cmHandleIds)); - cmHandleIds.forEach(this::removeDeletedCmHandleFromModuleSyncMap); - } - - private Collection mapCmHandleIdsToXpaths(final Collection cmHandles) { - return cmHandles.stream() - .map(cmHandleId -> NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']") - .collect(Collectors.toSet()); - } - - // CPS-1239 Robustness cleaning of in progress cache - private void removeDeletedCmHandleFromModuleSyncMap(final String cmHandleId) { - if (moduleSyncStartedOnCmHandles.remove(cmHandleId) != null) { - log.debug("{} removed from in progress map", cmHandleId); - } - } - - private List upgradeCmHandles(final Map - cmHandleStatePerCmHandle) { - final List cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle); - log.info("Moving cm handles : {} into locked (for upgrade) state.", cmHandleIds); - try { - lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); - return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds); - } catch (final Exception e) { - log.error("Unable to update cmHandleIds : {} , caused by : {}", cmHandleIds, e.getMessage()); - return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, e); - } - } - - private static List getCmHandleIds(final Map cmHandleStatePerCmHandle) { - return cmHandleStatePerCmHandle.keySet().stream().map(YangModelCmHandle::getId).toList(); - } - - private void setTrustLevelPerDmiPlugin(final DmiPluginRegistration dmiPluginRegistration) { - if (DmiPluginRegistration.isNullEmptyOrBlank(dmiPluginRegistration.getDmiDataPlugin())) { - trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiPlugin(), TrustLevel.COMPLETE); - } else { - trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiDataPlugin(), TrustLevel.COMPLETE); - } - } - -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java deleted file mode 100644 index 11c58235ec..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022-2024 Nordix Foundation - * Modifications Copyright (C) 2022 Bell Canada - * Modifications Copyright (C) 2024 TechMahindra Ltd. - * ================================================================================ - * 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; - -import static org.onap.cps.ncmp.api.NcmpResponseStatus.ALTERNATE_ID_ALREADY_ASSOCIATED; -import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND; -import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID; -import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.DMI_PROPERTY; -import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.PUBLIC_PROPERTY; -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME; -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR; -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; - -import com.google.common.collect.ImmutableMap; -import java.time.OffsetDateTime; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.onap.cps.api.CpsDataService; -import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; -import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker; -import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; -import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; -import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; -import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; -import org.onap.cps.spi.exceptions.DataNodeNotFoundException; -import org.onap.cps.spi.exceptions.DataValidationException; -import org.onap.cps.spi.model.DataNode; -import org.onap.cps.spi.model.DataNodeBuilder; -import org.onap.cps.utils.ContentType; -import org.onap.cps.utils.JsonObjectMapper; -import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; - -@Slf4j -@Service -@RequiredArgsConstructor -//Accepting the security hotspot as the string checked is generated from inside code and not user input. -@SuppressWarnings("squid:S5852") -public class NetworkCmProxyDataServicePropertyHandler { - - private final InventoryPersistence inventoryPersistence; - private final CpsDataService cpsDataService; - private final JsonObjectMapper jsonObjectMapper; - private final AlternateIdChecker alternateIdChecker; - - /** - * Iterates over incoming updatedNcmpServiceCmHandles and update the dataNodes based on the updated attributes. - * The attributes which are not passed will remain as is. - * - * @param updatedNcmpServiceCmHandles collection of CmHandles - */ - public List updateCmHandleProperties( - final Collection updatedNcmpServiceCmHandles) { - final Collection rejectedCmHandleIds = alternateIdChecker - .getIdsOfCmHandlesWithRejectedAlternateId(updatedNcmpServiceCmHandles, AlternateIdChecker.Operation.UPDATE); - final List failureResponses = - CmHandleRegistrationResponse.createFailureResponses(rejectedCmHandleIds, ALTERNATE_ID_ALREADY_ASSOCIATED); - final List cmHandleRegistrationResponses = new ArrayList<>(failureResponses); - for (final NcmpServiceCmHandle updatedNcmpServiceCmHandle : updatedNcmpServiceCmHandles) { - final String cmHandleId = updatedNcmpServiceCmHandle.getCmHandleId(); - if (!rejectedCmHandleIds.contains(cmHandleId)) { - try { - final DataNode existingCmHandleDataNode = inventoryPersistence - .getCmHandleDataNodeByCmHandleId(cmHandleId).iterator().next(); - processUpdates(existingCmHandleDataNode, updatedNcmpServiceCmHandle); - cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)); - } catch (final DataNodeNotFoundException e) { - log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandleId, - e.getMessage()); - cmHandleRegistrationResponses.add( - CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND)); - } catch (final DataValidationException e) { - log.error("Unable to update cm handle : {}, caused by : {}", cmHandleId, e.getMessage()); - cmHandleRegistrationResponses.add( - CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID)); - } catch (final Exception exception) { - log.error("Unable to update cmHandle : {} , caused by : {}", cmHandleId, exception.getMessage()); - cmHandleRegistrationResponses.add( - CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception)); - } - } - } - return cmHandleRegistrationResponses; - } - - private void processUpdates(final DataNode existingCmHandleDataNode, - final NcmpServiceCmHandle updatedNcmpServiceCmHandle) { - setAndUpdateCmHandleField( - updatedNcmpServiceCmHandle.getCmHandleId(), "alternate-id", updatedNcmpServiceCmHandle.getAlternateId()); - updateDataProducerIdentifier(existingCmHandleDataNode, updatedNcmpServiceCmHandle); - if (!updatedNcmpServiceCmHandle.getPublicProperties().isEmpty()) { - updateProperties(existingCmHandleDataNode, PUBLIC_PROPERTY, - updatedNcmpServiceCmHandle.getPublicProperties()); - } - if (!updatedNcmpServiceCmHandle.getDmiProperties().isEmpty()) { - updateProperties(existingCmHandleDataNode, DMI_PROPERTY, updatedNcmpServiceCmHandle.getDmiProperties()); - } - } - - private void updateDataProducerIdentifier(final DataNode cmHandleDataNode, - final NcmpServiceCmHandle ncmpServiceCmHandle) { - final String newDataProducerIdentifier = ncmpServiceCmHandle.getDataProducerIdentifier(); - if (StringUtils.hasText(newDataProducerIdentifier)) { - final YangModelCmHandle yangModelCmHandle = - YangDataConverter.convertCmHandleToYangModel(cmHandleDataNode); - final String existingDataProducerIdentifier = yangModelCmHandle.getDataProducerIdentifier(); - if (StringUtils.hasText(existingDataProducerIdentifier)) { - if (!existingDataProducerIdentifier.equals(newDataProducerIdentifier)) { - log.warn("Unable to update dataProducerIdentifier for cmHandle {}. " - + "Value for dataProducerIdentifier has been set previously.", - ncmpServiceCmHandle.getCmHandleId()); - } - } else { - setAndUpdateCmHandleField( - yangModelCmHandle.getId(), "data-producer-identifier", newDataProducerIdentifier); - } - } - } - - private void updateProperties(final DataNode existingCmHandleDataNode, final PropertyType propertyType, - final Map updatedProperties) { - final Collection replacementPropertyDataNodes = - getReplacementDataNodes(existingCmHandleDataNode, propertyType, updatedProperties); - replacementPropertyDataNodes.addAll( - getUnchangedPropertyDataNodes(existingCmHandleDataNode, propertyType, updatedProperties)); - if (replacementPropertyDataNodes.isEmpty()) { - removeAllProperties(existingCmHandleDataNode, propertyType); - } else { - inventoryPersistence.replaceListContent(existingCmHandleDataNode.getXpath(), replacementPropertyDataNodes); - } - } - - private void removeAllProperties(final DataNode existingCmHandleDataNode, final PropertyType propertyType) { - existingCmHandleDataNode.getChildDataNodes().forEach(dataNode -> { - final Matcher matcher = propertyType.propertyXpathPattern.matcher(dataNode.getXpath()); - if (matcher.find()) { - log.info("Deleting dataNode with xpath : [{}]", dataNode.getXpath()); - inventoryPersistence.deleteDataNode(dataNode.getXpath()); - } - }); - } - - private Collection getUnchangedPropertyDataNodes(final DataNode existingCmHandleDataNode, - final PropertyType propertyType, - final Map updatedProperties) { - final Collection unchangedPropertyDataNodes = new HashSet<>(); - for (final DataNode existingPropertyDataNode : existingCmHandleDataNode.getChildDataNodes()) { - final Matcher matcher = propertyType.propertyXpathPattern.matcher(existingPropertyDataNode.getXpath()); - if (matcher.find()) { - final String keyName = matcher.group(2); - if (!updatedProperties.containsKey(keyName)) { - unchangedPropertyDataNodes.add(existingPropertyDataNode); - } - } - } - return unchangedPropertyDataNodes; - } - - private Collection getReplacementDataNodes(final DataNode existingCmHandleDataNode, - final PropertyType propertyType, - final Map updatedProperties) { - final Collection replacementPropertyDataNodes = new HashSet<>(); - updatedProperties.forEach((updatedAttributeKey, updatedAttributeValue) -> { - final String propertyXpath = getAttributeXpath(existingCmHandleDataNode, propertyType, updatedAttributeKey); - if (updatedAttributeValue != null) { - log.info("Creating a new DataNode with xpath {} , key : {} and value : {}", propertyXpath, - updatedAttributeKey, updatedAttributeValue); - replacementPropertyDataNodes.add( - buildDataNode(propertyXpath, updatedAttributeKey, updatedAttributeValue)); - } - }); - return replacementPropertyDataNodes; - } - - private String getAttributeXpath(final DataNode cmHandle, final PropertyType propertyType, - final String attributeKey) { - return cmHandle.getXpath() + "/" + propertyType.xpathPrefix + String.format("[@name='%s']", attributeKey); - } - - private DataNode buildDataNode(final String xpath, final String attributeKey, final String attributeValue) { - final Map updatedLeaves = new LinkedHashMap<>(1); - updatedLeaves.put("name", attributeKey); - updatedLeaves.put("value", attributeValue); - log.debug("Building a new node with xpath {} with leaves (name : {} , value : {})", xpath, attributeKey, - attributeValue); - return new DataNodeBuilder().withXpath(xpath).withLeaves(ImmutableMap.copyOf(updatedLeaves)).build(); - } - - private void setAndUpdateCmHandleField(final String cmHandleIdToUpdate, final String fieldName, - final String newFieldValue) { - final Map> dmiRegistryData = new HashMap<>(1); - final Map cmHandleData = new HashMap<>(2); - cmHandleData.put("id", cmHandleIdToUpdate); - cmHandleData.put(fieldName, newFieldValue); - dmiRegistryData.put("cm-handles", cmHandleData); - cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT, - jsonObjectMapper.asJsonString(dmiRegistryData), OffsetDateTime.now(), ContentType.JSON); - log.debug("Updating {} for cmHandle {} with value : {})", fieldName, cmHandleIdToUpdate, newFieldValue); - } - - enum PropertyType { - DMI_PROPERTY("additional-properties"), PUBLIC_PROPERTY("public-properties"); - - private static final String LIST_INDEX_PATTERN = "\\[@(\\w+)[^\\/]'([^']+)']"; - - final String xpathPrefix; - final Pattern propertyXpathPattern; - - PropertyType(final String xpathPrefix) { - this.xpathPrefix = xpathPrefix; - this.propertyXpathPattern = Pattern.compile(xpathPrefix + LIST_INDEX_PATTERN); - } - } -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacade.java new file mode 100644 index 0000000000..a24b18446e --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacade.java @@ -0,0 +1,129 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 highstreet technologies GmbH + * Modifications Copyright (C) 2021-2024 Nordix Foundation + * Modifications Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2021-2022 Bell Canada + * Modifications Copyright (C) 2023 TechMahindra Ltd. + * ================================================================================ + * 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; + +import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL; + +import java.util.Collection; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.impl.operations.DatastoreType; +import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations; +import org.onap.cps.ncmp.api.impl.operations.OperationType; +import org.onap.cps.ncmp.api.models.CmResourceAddress; +import org.onap.cps.ncmp.api.models.DataOperationRequest; +import org.onap.cps.spi.model.DataNode; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class NetworkCmProxyFacade { + + private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler; + private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler; + private final DmiDataOperations dmiDataOperations; + + /** + * Fetches resource data for a given data store using DMI (Data Management Interface). + * This method retrieves data based on the provided CmResourceAddress and additional query parameters. + * It supports asynchronous processing and handles authorization if required. + * + * @param cmResourceAddress The target data store, including the CM handle and resource identifier. + * This parameter must not be null. + * @param options Additional query parameters that may influence the data retrieval process, + * such as filters or limits. This parameter can be null. + * @param topic The topic name for triggering asynchronous responses. If specified, + * the response will be sent to this topic. This parameter can be null. + * @param includeDescendants include (all) descendants or not + * @param authorization The contents of the Authorization header. This parameter can be null + * if authorization is not required. + * @return the result object, depends on use op topic. With topic a map object with request id is returned + * otherwise the result of the request. + */ + public Object getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress, + final String options, + final String topic, + final Boolean includeDescendants, + final String authorization) { + final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler + = getNcmpDatastoreRequestHandler(cmResourceAddress.datastoreName()); + + return ncmpDatastoreRequestHandler.executeRequest(cmResourceAddress, options, topic, includeDescendants, + authorization); + } + + /** + * Executes asynchronous request for group of cm handles to resource data. + * + * @param topic the topic param in query + * @param dataOperationRequest data operation request details for resource data + * @param authorization contents of Authorization header, or null if not present + * @return a map with one entry of request Id for success or status and error when async feature is disabled + */ + public Object executeDataOperationForCmHandles(final String topic, + final DataOperationRequest dataOperationRequest, + final String authorization) { + return ncmpPassthroughResourceRequestHandler.executeAsynchronousRequest(topic, + dataOperationRequest, + authorization); + } + + public Collection queryResourceDataForCmHandle(final String cmHandle, + final String cpsPath, + final Boolean includeDescendants) { + return ncmpCachedResourceRequestHandler.executeRequest(cmHandle, cpsPath, includeDescendants); + } + + /** + * Write resource data for data store pass-through running using dmi for given cm-handle. + * + * @param cmHandleId cm handle identifier + * @param resourceIdentifier resource identifier + * @param operationType required operation type + * @param requestData request body to create resource + * @param dataType content type in body + * @param authorization contents of Authorization header, or null if not present + * @return {@code Object} return data + */ + public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandleId, + final String resourceIdentifier, + final OperationType operationType, + final String requestData, + final String dataType, + final String authorization) { + return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier, + operationType, requestData, dataType, authorization); + } + + + private NcmpDatastoreRequestHandler getNcmpDatastoreRequestHandler(final String datastoreName) { + if (OPERATIONAL.equals(DatastoreType.fromDatastoreName(datastoreName))) { + return ncmpCachedResourceRequestHandler; + } + return ncmpPassthroughResourceRequestHandler; + } + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacade.java new file mode 100644 index 0000000000..5b439ebcfe --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacade.java @@ -0,0 +1,207 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 highstreet technologies GmbH + * Modifications Copyright (C) 2021-2024 Nordix Foundation + * Modifications Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2021-2022 Bell Canada + * Modifications Copyright (C) 2023 TechMahindra Ltd. + * ================================================================================ + * 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; + +import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.ParameterizedCmHandleQueryService; +import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService; +import org.onap.cps.ncmp.api.impl.inventory.CompositeState; +import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; +import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions; +import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions; +import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; +import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters; +import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; +import org.onap.cps.ncmp.api.models.DmiPluginRegistration; +import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; +import org.onap.cps.spi.model.ModuleDefinition; +import org.onap.cps.spi.model.ModuleReference; +import org.onap.cps.utils.JsonObjectMapper; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class NetworkCmProxyInventoryFacade { + + private final CmHandleRegistrationService cmHandleRegistrationService; + private final CmHandleQueryService cmHandleQueryService; + private final ParameterizedCmHandleQueryService parameterizedCmHandleQueryService; + private final InventoryPersistence inventoryPersistence; + private final JsonObjectMapper jsonObjectMapper; + + /** + * Registration of Created, Removed, Updated or Upgraded CM Handles. + * + * @param dmiPluginRegistration Dmi Plugin Registration details + * @return dmiPluginRegistrationResponse + */ + + public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule( + final DmiPluginRegistration dmiPluginRegistration) { + return cmHandleRegistrationService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration); + } + + /** + * Get all cm handle IDs by DMI plugin identifier. + * + * @param dmiPluginIdentifier DMI plugin identifier + * @return collection of cm handle IDs + */ + public Collection getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) { + return cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier); + } + + /** + * Get all cm handle IDs by various properties. + * + * @param cmHandleQueryServiceParameters cm handle query parameters + * @return collection of cm handle IDs + */ + public Collection executeParameterizedCmHandleIdSearch( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES); + return parameterizedCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters); + } + + + /** + * Retrieve module references for the given cm handle. + * + * @param cmHandleId cm handle identifier + * @return a collection of modules names and revisions + */ + public Collection getYangResourcesModuleReferences(final String cmHandleId) { + return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId); + } + + /** + * Retrieve module definitions for the given cm handle. + * + * @param cmHandleId cm handle identifier + * @return a collection of module definition (moduleName, revision and yang resource content) + */ + public Collection getModuleDefinitionsByCmHandleId(final String cmHandleId) { + return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId); + } + + /** + * Get module definitions for the given parameters. + * + * @param cmHandleId cm-handle identifier + * @param moduleName module name + * @param moduleRevision the revision of the module + * @return list of module definitions (module name, revision, yang resource content) + */ + public Collection getModuleDefinitionsByCmHandleAndModule(final String cmHandleId, + final String moduleName, + final String moduleRevision) { + return inventoryPersistence.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, moduleRevision); + } + + /** + * Retrieve cm handles with details for the given query parameters. + * + * @param cmHandleQueryApiParameters cm handle query parameters + * @return cm handles with details + */ + public Collection executeCmHandleSearch( + final CmHandleQueryApiParameters cmHandleQueryApiParameters) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( + cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); + validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); + return parameterizedCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters); + } + + /** + * Retrieve cm handle ids for the given query parameters. + * + * @param cmHandleQueryApiParameters cm handle query parameters + * @return cm handle ids + */ + public Collection executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( + cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); + validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); + return parameterizedCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters); + } + + /** + * Set the data sync enabled flag, along with the data sync state + * based on the data sync enabled boolean for the cm handle id provided. + * + * @param cmHandleId cm handle id + * @param dataSyncEnabledTargetValue data sync enabled flag + */ + public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) { + cmHandleRegistrationService.setDataSyncEnabled(cmHandleId, dataSyncEnabledTargetValue); + } + + /** + * Retrieve cm handle details for a given cm handle. + * + * @param cmHandleId cm handle identifier + * @return cm handle details + */ + public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) { + return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle( + inventoryPersistence.getYangModelCmHandle(cmHandleId)); + } + + /** + * Get cm handle public properties for a given cm handle id. + * + * @param cmHandleId cm handle identifier + * @return cm handle public properties + */ + public Map getCmHandlePublicProperties(final String cmHandleId) { + final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); + final List yangModelPublicProperties = yangModelCmHandle.getPublicProperties(); + final Map cmHandlePublicProperties = new HashMap<>(); + YangDataConverter.asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties); + return cmHandlePublicProperties; + } + + /** + * Get cm handle composite state for a given cm handle id. + * + * @param cmHandleId cm handle identifier + * @return cm handle state + */ + public CompositeState getCmHandleCompositeState(final String cmHandleId) { + return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState(); + } + + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/ParameterizedCmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/ParameterizedCmHandleQueryServiceImpl.java new file mode 100644 index 0000000000..b8418bea33 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/ParameterizedCmHandleQueryServiceImpl.java @@ -0,0 +1,286 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022-2024 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; + +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; +import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.HAS_ALL_MODULES; +import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.HAS_ALL_PROPERTIES; +import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.WITH_CPS_PATH; +import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.WITH_TRUST_LEVEL; +import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCpsPathConditionProperties; +import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateModuleNameConditionProperties; +import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle; +import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY; +import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.onap.cps.cpspath.parser.PathParsingException; +import org.onap.cps.ncmp.api.ParameterizedCmHandleQueryService; +import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService; +import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; +import org.onap.cps.ncmp.api.impl.inventory.enums.PropertyType; +import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions; +import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; +import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; +import org.onap.cps.spi.exceptions.DataValidationException; +import org.onap.cps.spi.model.ConditionProperties; +import org.onap.cps.spi.model.DataNode; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +@RequiredArgsConstructor +public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHandleQueryService { + + private static final Collection NO_QUERY_TO_EXECUTE = null; + private final CmHandleQueryService cmHandleQueryService; + private final InventoryPersistence inventoryPersistence; + + @Override + public Collection queryCmHandleIds( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + return executeQueries(cmHandleQueryServiceParameters, + this::executeCpsPathQuery, + this::queryCmHandlesByPublicProperties, + this::executeModuleNameQuery, + this::queryCmHandlesByTrustLevel); + } + + @Override + public Collection queryCmHandleIdsForInventory( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + return executeQueries(cmHandleQueryServiceParameters, + this::queryCmHandlesByPublicProperties, + this::queryCmHandlesByPrivateProperties, + this::queryCmHandlesByDmiPlugin); + } + + @Override + public Collection queryCmHandles( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + + if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) { + return getAllCmHandles(); + } + + final Collection cmHandleIds = queryCmHandleIds(cmHandleQueryServiceParameters); + + return getNcmpServiceCmHandles(cmHandleIds); + } + + @Override + public Collection getAllCmHandles() { + final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT).iterator().next(); + return dataNode.getChildDataNodes().stream().map(this::createNcmpServiceCmHandle).collect(Collectors.toSet()); + } + + private Collection queryCmHandlesByDmiPlugin( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + final Map dmiPropertyQueryPairs = + getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), + InventoryQueryConditions.CM_HANDLE_WITH_DMI_PLUGIN.getName()); + if (dmiPropertyQueryPairs.isEmpty()) { + return NO_QUERY_TO_EXECUTE; + } + + final String dmiPluginIdentifierValue = dmiPropertyQueryPairs + .get(PropertyType.DMI_PLUGIN.getYangContainerName()); + + return cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifierValue); + } + + private Collection queryCmHandlesByPrivateProperties( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + + final Map privatePropertyQueryPairs = + getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), + InventoryQueryConditions.HAS_ALL_ADDITIONAL_PROPERTIES.getName()); + + if (privatePropertyQueryPairs.isEmpty()) { + return NO_QUERY_TO_EXECUTE; + } + return cmHandleQueryService.queryCmHandleAdditionalProperties(privatePropertyQueryPairs); + } + + private Collection queryCmHandlesByPublicProperties( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + + final Map publicPropertyQueryPairs = + getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), + HAS_ALL_PROPERTIES.getConditionName()); + + if (publicPropertyQueryPairs.isEmpty()) { + return NO_QUERY_TO_EXECUTE; + } + return cmHandleQueryService.queryCmHandlePublicProperties(publicPropertyQueryPairs); + } + + private Collection queryCmHandlesByTrustLevel(final CmHandleQueryServiceParameters + cmHandleQueryServiceParameters) { + + final Map trustLevelPropertyQueryPairs = + getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), + WITH_TRUST_LEVEL.getConditionName()); + + if (trustLevelPropertyQueryPairs.isEmpty()) { + return NO_QUERY_TO_EXECUTE; + } + return cmHandleQueryService.queryCmHandlesByTrustLevel(trustLevelPropertyQueryPairs); + } + + private Collection executeModuleNameQuery( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + final Collection moduleNamesForQuery = + getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); + if (moduleNamesForQuery.isEmpty()) { + return NO_QUERY_TO_EXECUTE; + } + return inventoryPersistence.getCmHandleIdsWithGivenModules(moduleNamesForQuery); + } + + private Collection executeCpsPathQuery( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + final Map cpsPathCondition + = getCpsPathCondition(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); + if (!validateCpsPathConditionProperties(cpsPathCondition)) { + return Collections.emptySet(); + } + final Collection cpsPathQueryResult; + if (cpsPathCondition.isEmpty()) { + return NO_QUERY_TO_EXECUTE; + } + try { + cpsPathQueryResult = collectCmHandleIdsFromDataNodes( + cmHandleQueryService.queryCmHandleAncestorsByCpsPath( + cpsPathCondition.get("cpsPath"), OMIT_DESCENDANTS)); + } catch (final PathParsingException pathParsingException) { + throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(), + pathParsingException); + } + return cpsPathQueryResult; + } + + private Collection getModuleNamesForQuery(final List conditionProperties) { + final List result = new ArrayList<>(); + getConditions(conditionProperties, HAS_ALL_MODULES.getConditionName()).forEach( + conditionProperty -> { + validateModuleNameConditionProperties(conditionProperty); + result.add(conditionProperty.get("moduleName")); + }); + return result; + } + + private Map getCpsPathCondition(final List conditionProperties) { + final Map result = new HashMap<>(); + getConditions(conditionProperties, WITH_CPS_PATH.getConditionName()).forEach(result::putAll); + return result; + } + + private Map getPropertyPairs(final List conditionProperties, + final String queryProperty) { + final Map result = new HashMap<>(); + getConditions(conditionProperties, queryProperty).forEach(result::putAll); + return result; + } + + private List> getConditions(final List conditionProperties, + final String name) { + for (final ConditionProperties conditionProperty : conditionProperties) { + if (conditionProperty.getConditionName().equals(name)) { + return conditionProperty.getConditionParameters(); + } + } + return Collections.emptyList(); + } + + private Collection getAllCmHandleIds() { + final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT, DIRECT_CHILDREN_ONLY) + .iterator().next(); + return collectCmHandleIdsFromDataNodes(dataNode.getChildDataNodes()); + } + + private Collection getNcmpServiceCmHandles(final Collection cmHandleIds) { + final Collection yangModelcmHandles + = inventoryPersistence.getYangModelCmHandles(cmHandleIds); + + final Collection ncmpServiceCmHandles = new ArrayList<>(yangModelcmHandles.size()); + + yangModelcmHandles.forEach(yangModelcmHandle -> + ncmpServiceCmHandles.add(YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(yangModelcmHandle)) + ); + return ncmpServiceCmHandles; + } + + private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) { + return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter.convertCmHandleToYangModel(dataNode)); + } + + private Collection executeQueries(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, + final Function>... + queryFunctions) { + if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) { + return getAllCmHandleIds(); + } + Collection combinedQueryResult = NO_QUERY_TO_EXECUTE; + for (final Function> queryFunction : queryFunctions) { + final Collection queryResult = queryFunction.apply(cmHandleQueryServiceParameters); + if (noEntriesFoundCanStopQuerying(queryResult)) { + return Collections.emptySet(); + } + combinedQueryResult = combineCmHandleQueryResults(combinedQueryResult, queryResult); + } + return combinedQueryResult; + } + + private boolean noEntriesFoundCanStopQuerying(final Collection queryResult) { + return queryResult != NO_QUERY_TO_EXECUTE && queryResult.isEmpty(); + } + + private Collection combineCmHandleQueryResults(final Collection firstQuery, + final Collection secondQuery) { + if (firstQuery == NO_QUERY_TO_EXECUTE && secondQuery == NO_QUERY_TO_EXECUTE) { + return NO_QUERY_TO_EXECUTE; + } else if (firstQuery == NO_QUERY_TO_EXECUTE) { + return secondQuery; + } else if (secondQuery == NO_QUERY_TO_EXECUTE) { + return firstQuery; + } else { + firstQuery.retainAll(secondQuery); + return firstQuery; + } + } + + private Collection collectCmHandleIdsFromDataNodes(final Collection dataNodes) { + return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet()); + } + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java index 5811cf97da..d4c5d16a4c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java @@ -71,7 +71,7 @@ public class DmiRestClient { private final WebClient healthChecksWebClient; /** - * Sends a POST operation to the DMI with a JSON body containing module references. + * Sends a synchronous (blocking) POST operation to the DMI with a JSON body containing module references. * * @param requiredDmiService Determines if the required service is for a data or model operation. * @param dmiUrl The DMI resource URL. @@ -81,17 +81,18 @@ public class DmiRestClient { * @return ResponseEntity containing the response from the DMI. * @throws DmiClientRequestException If there is an error during the DMI request. */ - public ResponseEntity postOperationWithJsonData(final RequiredDmiService requiredDmiService, - final String dmiUrl, - final String requestBodyAsJsonString, - final OperationType operationType, - final String authorization) { - try { - return postOperationWithJsonDataAsync(requiredDmiService, dmiUrl, requestBodyAsJsonString, operationType, - authorization).block(); - } catch (final HttpServerErrorException e) { - throw handleDmiClientException(e, operationType.getOperationName()); - } + public ResponseEntity synchronousPostOperationWithJsonData(final RequiredDmiService requiredDmiService, + final String dmiUrl, + final String requestBodyAsJsonString, + final OperationType operationType, + final String authorization) { + final Mono> responseEntityMono = + asynchronousPostOperationWithJsonData(requiredDmiService, + dmiUrl, + requestBodyAsJsonString, + operationType, + authorization); + return responseEntityMono.block(); } /** @@ -105,11 +106,12 @@ public class DmiRestClient { * @param authorization The authorization token to be added to the request headers. * @return A Mono emitting the response entity containing the server's response. */ - public Mono> postOperationWithJsonDataAsync(final RequiredDmiService requiredDmiService, - final String dmiUrl, - final String requestBodyAsJsonString, - final OperationType operationType, - final String authorization) { + public Mono> asynchronousPostOperationWithJsonData( + final RequiredDmiService requiredDmiService, + final String dmiUrl, + final String requestBodyAsJsonString, + final OperationType operationType, + final String authorization) { final WebClient webClient = getWebClient(requiredDmiService); return webClient.post() .uri(toUri(dmiUrl)) diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueries.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueries.java deleted file mode 100644 index 81467dbb3e..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueries.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022-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.inventory; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.onap.cps.spi.FetchDescendantsOption; -import org.onap.cps.spi.model.DataNode; - -public interface CmHandleQueries { - - /** - * Query CmHandles based on additional (private) properties. - * - * @param additionalPropertyQueryPairs private properties for query - * @return Ids of CmHandles which have these private properties - */ - Collection queryCmHandleAdditionalProperties(Map additionalPropertyQueryPairs); - - /** - * Query CmHandles based on public properties. - * - * @param publicPropertyQueryPairs public properties for query - * @return CmHandles which have these public properties - */ - Collection queryCmHandlePublicProperties(Map publicPropertyQueryPairs); - - /** - * Query CmHandles based on Trust Level. - * - * @param trustLevelPropertyQueryPairs trust level properties for query - * @return CmHandles which have desired trust level - */ - Collection queryCmHandlesByTrustLevel(Map trustLevelPropertyQueryPairs); - - /** - * Method which returns cm handles by the cm handles state. - * - * @param cmHandleState cm handle state - * @return a list of cm handles - */ - List queryCmHandlesByState(CmHandleState cmHandleState); - - /** - * Method to return data nodes with ancestor representing the cm handles. - * - * @param cpsPath cps path for which the cmHandle is requested - * @return a list of data nodes representing the cm handles. - */ - List queryCmHandleAncestorsByCpsPath(String cpsPath, - FetchDescendantsOption fetchDescendantsOption); - - /** - * Method to return data nodes representing the cm handles. - * - * @param cpsPath cps path for which the cmHandle is requested - * @return a list of data nodes representing the cm handles. - */ - List queryNcmpRegistryByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption); - - /** - * Method to check the state of a cm handle with given id. - * - * @param cmHandleId cm handle id - * @param requiredCmHandleState the required state of the cm handle - * @return a boolean, true if the state is equal to the required state - */ - boolean cmHandleHasState(String cmHandleId, CmHandleState requiredCmHandleState); - - /** - * Method which returns cm handles by the operational sync state of cm handle. - * - * @param dataStoreSyncState sync state - * @return a list of cm handles - */ - List queryCmHandlesByOperationalSyncState(DataStoreSyncState dataStoreSyncState); - - /** - * Get all cm handles ids by DMI plugin identifier. - * - * @param dmiPluginIdentifier DMI plugin identifier - * @return collection of cm handles - */ - Collection getCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier); -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java deleted file mode 100644 index 6cffb4d274..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022-2024 Nordix Foundation - * Modifications Copyright (C) 2023 TechMahindra Ltd. - * ================================================================================ - * 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.inventory; - -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME; -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR; -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; -import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS; -import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig; -import org.onap.cps.ncmp.api.impl.inventory.enums.PropertyType; -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; -import org.onap.cps.spi.CpsDataPersistenceService; -import org.onap.cps.spi.FetchDescendantsOption; -import org.onap.cps.spi.model.DataNode; -import org.onap.cps.spi.utils.CpsValidator; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -@RequiredArgsConstructor -@Component -public class CmHandleQueriesImpl implements CmHandleQueries { - - private static final String DESCENDANT_PATH = "//"; - private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles"; - private final CpsDataPersistenceService cpsDataPersistenceService; - - @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN) - private final Map trustLevelPerDmiPlugin; - - @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_CM_HANDLE) - private final Map trustLevelPerCmHandle; - - private final CpsValidator cpsValidator; - - @Override - public Collection queryCmHandleAdditionalProperties(final Map privatePropertyQueryPairs) { - return queryCmHandleAnyProperties(privatePropertyQueryPairs, PropertyType.ADDITIONAL); - } - - @Override - public Collection queryCmHandlePublicProperties(final Map publicPropertyQueryPairs) { - return queryCmHandleAnyProperties(publicPropertyQueryPairs, PropertyType.PUBLIC); - } - - @Override - public Collection queryCmHandlesByTrustLevel(final Map trustLevelPropertyQueryPairs) { - final String trustLevelProperty = trustLevelPropertyQueryPairs.values().iterator().next(); - final TrustLevel targetTrustLevel = TrustLevel.valueOf(trustLevelProperty); - - return getCmHandleIdsByTrustLevel(targetTrustLevel); - } - - @Override - public List queryCmHandlesByState(final CmHandleState cmHandleState) { - return queryCmHandleAncestorsByCpsPath("//state[@cm-handle-state=\"" + cmHandleState + "\"]", - INCLUDE_ALL_DESCENDANTS); - } - - @Override - public List queryNcmpRegistryByCpsPath(final String cpsPath, - final FetchDescendantsOption fetchDescendantsOption) { - return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - cpsPath, fetchDescendantsOption); - } - - @Override - public List queryCmHandleAncestorsByCpsPath(final String cpsPath, - final FetchDescendantsOption fetchDescendantsOption) { - return queryNcmpRegistryByCpsPath(cpsPath + ANCESTOR_CM_HANDLES, fetchDescendantsOption); - } - - @Override - public boolean cmHandleHasState(final String cmHandleId, final CmHandleState requiredCmHandleState) { - final DataNode stateDataNode = getCmHandleState(cmHandleId); - final String cmHandleStateAsString = (String) stateDataNode.getLeaves().get("cm-handle-state"); - return CmHandleState.valueOf(cmHandleStateAsString).equals(requiredCmHandleState); - } - - @Override - public List queryCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) { - return queryCmHandleAncestorsByCpsPath("//state/datastores" + "/operational[@sync-state=\"" - + dataStoreSyncState + "\"]", FetchDescendantsOption.OMIT_DESCENDANTS); - } - - @Override - public Collection getCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) { - final Collection cmHandleIds = new HashSet<>(); - for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) { - for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty( - dmiPluginIdentifier, - modelledDmiServiceLeaf.getLeafName())) { - cmHandleIds.add(cmHandleAsDataNode.getLeaves().get("id").toString()); - } - } - return cmHandleIds; - } - - private Collection getCmHandleIdsByTrustLevel(final TrustLevel targetTrustLevel) { - final Collection selectedCmHandleIds = new HashSet<>(); - - for (final Map.Entry mapEntry : trustLevelPerDmiPlugin.entrySet()) { - final String dmiPluginIdentifier = mapEntry.getKey(); - final TrustLevel dmiTrustLevel = mapEntry.getValue(); - final Collection candidateCmHandleIds = getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier); - for (final String candidateCmHandleId : candidateCmHandleIds) { - final TrustLevel candidateCmHandleTrustLevel = trustLevelPerCmHandle.get(candidateCmHandleId); - final TrustLevel effectiveTrustlevel = - candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); - if (targetTrustLevel.equals(effectiveTrustlevel)) { - selectedCmHandleIds.add(candidateCmHandleId); - } - } - } - - return selectedCmHandleIds; - } - - private Collection collectCmHandleIdsFromDataNodes(final Collection dataNodes) { - return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet()); - } - - private Collection queryCmHandleAnyProperties( - final Map propertyQueryPairs, - final PropertyType propertyType) { - if (propertyQueryPairs.isEmpty()) { - return Collections.emptySet(); - } - Collection cmHandleIds = null; - for (final Map.Entry publicPropertyQueryPair : propertyQueryPairs.entrySet()) { - final String cpsPath = DESCENDANT_PATH + propertyType.getYangContainerName() + "[@name=\"" - + publicPropertyQueryPair.getKey() - + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]"; - - final Collection dataNodes = queryCmHandleAncestorsByCpsPath(cpsPath, - OMIT_DESCENDANTS); - if (cmHandleIds == null) { - cmHandleIds = collectCmHandleIdsFromDataNodes(dataNodes); - } else { - final Collection cmHandleIdsToRetain = collectCmHandleIdsFromDataNodes(dataNodes); - cmHandleIds.retainAll(cmHandleIdsToRetain); - } - if (cmHandleIds.isEmpty()) { - break; - } - } - return cmHandleIds; - } - - private List getCmHandlesByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier, - final String dmiProperty) { - return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@" + dmiProperty + "='" + dmiPluginIdentifier + "']", - OMIT_DESCENDANTS); - } - - private DataNode getCmHandleState(final String cmHandleId) { - cpsValidator.validateNameCharacters(cmHandleId); - final String xpath = NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']/state"; - return cpsDataPersistenceService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - xpath, OMIT_DESCENDANTS).iterator().next(); - } -} - - diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryService.java new file mode 100644 index 0000000000..970c36bb63 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryService.java @@ -0,0 +1,105 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022-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.inventory; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import org.onap.cps.spi.FetchDescendantsOption; +import org.onap.cps.spi.model.DataNode; + +public interface CmHandleQueryService { + + /** + * Query Cm Handles based on additional (private) properties. + * + * @param additionalPropertyQueryPairs private properties for query + * @return Ids of Cm Handles which have these private properties + */ + Collection queryCmHandleAdditionalProperties(Map additionalPropertyQueryPairs); + + /** + * Query Cm Handles based on public properties. + * + * @param publicPropertyQueryPairs public properties for query + * @return CmHandles which have these public properties + */ + Collection queryCmHandlePublicProperties(Map publicPropertyQueryPairs); + + /** + * Query Cm Handles based on Trust Level. + * + * @param trustLevelPropertyQueryPairs trust level properties for query + * @return Ids of Cm Handles which have desired trust level + */ + Collection queryCmHandlesByTrustLevel(Map trustLevelPropertyQueryPairs); + + /** + * Method which returns cm handles by the cm handles state. + * + * @param cmHandleState cm handle state + * @return a list of data nodes representing the cm handles. + */ + List queryCmHandlesByState(CmHandleState cmHandleState); + + /** + * Method to return data nodes with ancestor representing the cm handles. + * + * @param cpsPath cps path for which the cmHandle is requested + * @return a list of data nodes representing the cm handles. + */ + List queryCmHandleAncestorsByCpsPath(String cpsPath, + FetchDescendantsOption fetchDescendantsOption); + + /** + * Method to return data nodes representing the cm handles. + * + * @param cpsPath cps path for which the cmHandle is requested + * @return a list of data nodes representing the cm handles. + */ + List queryNcmpRegistryByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption); + + /** + * Method to check the state of a cm handle with given id. + * + * @param cmHandleId cm handle id + * @param requiredCmHandleState the required state of the cm handle + * @return a boolean, true if the state is equal to the required state + */ + boolean cmHandleHasState(String cmHandleId, CmHandleState requiredCmHandleState); + + /** + * Method which returns cm handles by the operational sync state of cm handle. + * + * @param dataStoreSyncState sync state + * @return a list of data nodes representing the cm handles. + */ + List queryCmHandlesByOperationalSyncState(DataStoreSyncState dataStoreSyncState); + + /** + * Get all cm handles ids by DMI plugin identifier. + * + * @param dmiPluginIdentifier DMI plugin identifier + * @return collection of cm handle ids + */ + Collection getCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier); + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryServiceImpl.java new file mode 100644 index 0000000000..4350cc6fdf --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryServiceImpl.java @@ -0,0 +1,192 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022-2024 Nordix Foundation + * Modifications Copyright (C) 2023 TechMahindra Ltd. + * ================================================================================ + * 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.inventory; + +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME; +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR; +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; +import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS; +import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig; +import org.onap.cps.ncmp.api.impl.inventory.enums.PropertyType; +import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; +import org.onap.cps.spi.CpsDataPersistenceService; +import org.onap.cps.spi.FetchDescendantsOption; +import org.onap.cps.spi.model.DataNode; +import org.onap.cps.spi.utils.CpsValidator; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +@RequiredArgsConstructor +@Component +public class CmHandleQueryServiceImpl implements CmHandleQueryService { + + private static final String DESCENDANT_PATH = "//"; + private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles"; + private final CpsDataPersistenceService cpsDataPersistenceService; + + @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN) + private final Map trustLevelPerDmiPlugin; + + @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_CM_HANDLE) + private final Map trustLevelPerCmHandle; + + private final CpsValidator cpsValidator; + + @Override + public Collection queryCmHandleAdditionalProperties(final Map privatePropertyQueryPairs) { + return queryCmHandleAnyProperties(privatePropertyQueryPairs, PropertyType.ADDITIONAL); + } + + @Override + public Collection queryCmHandlePublicProperties(final Map publicPropertyQueryPairs) { + return queryCmHandleAnyProperties(publicPropertyQueryPairs, PropertyType.PUBLIC); + } + + @Override + public Collection queryCmHandlesByTrustLevel(final Map trustLevelPropertyQueryPairs) { + final String trustLevelProperty = trustLevelPropertyQueryPairs.values().iterator().next(); + final TrustLevel targetTrustLevel = TrustLevel.valueOf(trustLevelProperty); + + return getCmHandleIdsByTrustLevel(targetTrustLevel); + } + + @Override + public List queryCmHandlesByState(final CmHandleState cmHandleState) { + return queryCmHandleAncestorsByCpsPath("//state[@cm-handle-state=\"" + cmHandleState + "\"]", + INCLUDE_ALL_DESCENDANTS); + } + + @Override + public List queryNcmpRegistryByCpsPath(final String cpsPath, + final FetchDescendantsOption fetchDescendantsOption) { + return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, + cpsPath, fetchDescendantsOption); + } + + @Override + public List queryCmHandleAncestorsByCpsPath(final String cpsPath, + final FetchDescendantsOption fetchDescendantsOption) { + return queryNcmpRegistryByCpsPath(cpsPath + ANCESTOR_CM_HANDLES, fetchDescendantsOption); + } + + @Override + public boolean cmHandleHasState(final String cmHandleId, final CmHandleState requiredCmHandleState) { + final DataNode stateDataNode = getCmHandleState(cmHandleId); + final String cmHandleStateAsString = (String) stateDataNode.getLeaves().get("cm-handle-state"); + return CmHandleState.valueOf(cmHandleStateAsString).equals(requiredCmHandleState); + } + + @Override + public List queryCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) { + return queryCmHandleAncestorsByCpsPath("//state/datastores" + "/operational[@sync-state=\"" + + dataStoreSyncState + "\"]", FetchDescendantsOption.OMIT_DESCENDANTS); + } + + @Override + public Collection getCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) { + final Collection cmHandleIds = new HashSet<>(); + for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) { + for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty( + dmiPluginIdentifier, + modelledDmiServiceLeaf.getLeafName())) { + cmHandleIds.add(cmHandleAsDataNode.getLeaves().get("id").toString()); + } + } + return cmHandleIds; + } + + private Collection getCmHandleIdsByTrustLevel(final TrustLevel targetTrustLevel) { + final Collection selectedCmHandleIds = new HashSet<>(); + + for (final Map.Entry mapEntry : trustLevelPerDmiPlugin.entrySet()) { + final String dmiPluginIdentifier = mapEntry.getKey(); + final TrustLevel dmiTrustLevel = mapEntry.getValue(); + final Collection candidateCmHandleIds = getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier); + for (final String candidateCmHandleId : candidateCmHandleIds) { + final TrustLevel candidateCmHandleTrustLevel = trustLevelPerCmHandle.get(candidateCmHandleId); + final TrustLevel effectiveTrustlevel = + candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); + if (targetTrustLevel.equals(effectiveTrustlevel)) { + selectedCmHandleIds.add(candidateCmHandleId); + } + } + } + + return selectedCmHandleIds; + } + + private Collection collectCmHandleIdsFromDataNodes(final Collection dataNodes) { + return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet()); + } + + private Collection queryCmHandleAnyProperties( + final Map propertyQueryPairs, + final PropertyType propertyType) { + if (propertyQueryPairs.isEmpty()) { + return Collections.emptySet(); + } + Collection cmHandleIds = null; + for (final Map.Entry publicPropertyQueryPair : propertyQueryPairs.entrySet()) { + final String cpsPath = DESCENDANT_PATH + propertyType.getYangContainerName() + "[@name=\"" + + publicPropertyQueryPair.getKey() + + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]"; + + final Collection dataNodes = queryCmHandleAncestorsByCpsPath(cpsPath, + OMIT_DESCENDANTS); + if (cmHandleIds == null) { + cmHandleIds = collectCmHandleIdsFromDataNodes(dataNodes); + } else { + final Collection cmHandleIdsToRetain = collectCmHandleIdsFromDataNodes(dataNodes); + cmHandleIds.retainAll(cmHandleIdsToRetain); + } + if (cmHandleIds.isEmpty()) { + break; + } + } + return cmHandleIds; + } + + private List getCmHandlesByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier, + final String dmiProperty) { + return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, + NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@" + dmiProperty + "='" + dmiPluginIdentifier + "']", + OMIT_DESCENDANTS); + } + + private DataNode getCmHandleState(final String cmHandleId) { + cpsValidator.validateNameCharacters(cmHandleId); + final String xpath = NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']/state"; + return cpsDataPersistenceService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, + xpath, OMIT_DESCENDANTS).iterator().next(); + } +} + + diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java index c4cab31ab3..55fe35de2f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java @@ -57,7 +57,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv private final CpsModuleService cpsModuleService; private final CpsAnchorService cpsAnchorService; private final CpsValidator cpsValidator; - private final CmHandleQueries cmHandleQueries; + private final CmHandleQueryService cmHandleQueryService; /** * initialize an inventory persistence object. @@ -70,12 +70,13 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv */ public InventoryPersistenceImpl(final JsonObjectMapper jsonObjectMapper, final CpsDataService cpsDataService, final CpsModuleService cpsModuleService, final CpsValidator cpsValidator, - final CpsAnchorService cpsAnchorService, final CmHandleQueries cmHandleQueries) { + final CpsAnchorService cpsAnchorService, + final CmHandleQueryService cmHandleQueryService) { super(jsonObjectMapper, cpsDataService, cpsModuleService, cpsValidator); this.cpsModuleService = cpsModuleService; this.cpsAnchorService = cpsAnchorService; this.cpsValidator = cpsValidator; - this.cmHandleQueries = cmHandleQueries; + this.cmHandleQueryService = cmHandleQueryService; } @@ -170,7 +171,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv @Override public DataNode getCmHandleDataNodeByAlternateId(final String alternateId) { final String cpsPathForCmHandleByAlternateId = getCpsPathForCmHandleByAlternateId(alternateId); - final Collection dataNodes = cmHandleQueries + final Collection dataNodes = cmHandleQueryService .queryNcmpRegistryByCpsPath(cpsPathForCmHandleByAlternateId, OMIT_DESCENDANTS); if (dataNodes.isEmpty()) { throw new DataNodeNotFoundException(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java index 794ca5b1b6..e00a49f57a 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java @@ -21,8 +21,6 @@ package org.onap.cps.ncmp.api.impl.inventory.sync; -import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL; - import com.fasterxml.jackson.databind.JsonNode; import java.time.Duration; import java.time.OffsetDateTime; @@ -38,7 +36,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries; +import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService; import org.onap.cps.ncmp.api.impl.inventory.CmHandleState; import org.onap.cps.ncmp.api.impl.inventory.CompositeState; import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState; @@ -57,7 +55,7 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class ModuleOperationsUtils { - private final CmHandleQueries cmHandleQueries; + private final CmHandleQueryService cmHandleQueryService; private final DmiDataOperations dmiDataOperations; private final JsonObjectMapper jsonObjectMapper; private static final String RETRY_ATTEMPT_KEY = "attempt"; @@ -78,7 +76,8 @@ public class ModuleOperationsUtils { * @return cm handles (data nodes) in ADVISED state (empty list if none found) */ public List getAdvisedCmHandles() { - final List advisedCmHandlesAsDataNodes = cmHandleQueries.queryCmHandlesByState(CmHandleState.ADVISED); + final List advisedCmHandlesAsDataNodes = + cmHandleQueryService.queryCmHandlesByState(CmHandleState.ADVISED); log.debug("Total number of fetched advised cm handle(s) is (are) {}", advisedCmHandlesAsDataNodes.size()); return advisedCmHandlesAsDataNodes; } @@ -91,13 +90,13 @@ public class ModuleOperationsUtils { * return empty list if not found */ public List getUnsynchronizedReadyCmHandles() { - final List unsynchronizedCmHandles = cmHandleQueries + final List unsynchronizedCmHandles = cmHandleQueryService .queryCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED); final List yangModelCmHandles = new ArrayList<>(); for (final DataNode unsynchronizedCmHandle : unsynchronizedCmHandles) { final String cmHandleId = unsynchronizedCmHandle.getLeaves().get("id").toString(); - if (cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY)) { + if (cmHandleQueryService.cmHandleHasState(cmHandleId, CmHandleState.READY)) { yangModelCmHandles.addAll(convertCmHandlesDataNodesToYangModelCmHandles( Collections.singletonList(unsynchronizedCmHandle))); } @@ -113,7 +112,7 @@ public class ModuleOperationsUtils { */ public List getCmHandlesThatFailedModelSyncOrUpgrade() { final List lockedCmHandlesAsDataNodeList - = cmHandleQueries.queryCmHandleAncestorsByCpsPath(CPS_PATH_CM_HANDLES_MODEL_SYNC_FAILED_OR_UPGRADE, + = cmHandleQueryService.queryCmHandleAncestorsByCpsPath(CPS_PATH_CM_HANDLES_MODEL_SYNC_FAILED_OR_UPGRADE, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); return convertCmHandlesDataNodesToYangModelCmHandles(lockedCmHandlesAsDataNodeList); } @@ -198,16 +197,14 @@ public class ModuleOperationsUtils { } /** - * Get the Resourece Data from Node through DMI Passthrough service. + * Get the Resource Data from Node through DMI Passthrough service. * * @param cmHandleId cm handle id * @return optional string containing the resource data */ public String getResourceData(final String cmHandleId) { - final ResponseEntity resourceDataResponseEntity = dmiDataOperations.getResourceDataFromDmi( - PASSTHROUGH_OPERATIONAL.getDatastoreName(), - cmHandleId, - UUID.randomUUID().toString()); + final ResponseEntity resourceDataResponseEntity = dmiDataOperations.getAllResourceDataFromDmi( + cmHandleId, UUID.randomUUID().toString()); if (resourceDataResponseEntity.getStatusCode().is2xxSuccessful()) { return getFirstResource(resourceDataResponseEntity.getBody()); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java index 45156ce88e..a5f0ba017f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java @@ -38,7 +38,7 @@ import org.apache.commons.lang3.StringUtils; import org.onap.cps.api.CpsAnchorService; import org.onap.cps.api.CpsDataService; import org.onap.cps.api.CpsModuleService; -import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries; +import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService; import org.onap.cps.ncmp.api.impl.inventory.CmHandleState; import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations; import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; @@ -59,7 +59,7 @@ public class ModuleSyncService { private final DmiModelOperations dmiModelOperations; private final CpsModuleService cpsModuleService; - private final CmHandleQueries cmHandleQueries; + private final CmHandleQueryService cmHandleQueryService; private final CpsDataService cpsDataService; private final CpsAnchorService cpsAnchorService; private final JsonObjectMapper jsonObjectMapper; @@ -136,7 +136,7 @@ public class ModuleSyncService { return null; } final String escapedModuleSetTag = moduleSetTag.replace("'", "''"); - final List dataNodes = cmHandleQueries.queryNcmpRegistryByCpsPath( + final List dataNodes = cmHandleQueryService.queryNcmpRegistryByCpsPath( NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@module-set-tag='" + escapedModuleSetTag + "']", FetchDescendantsOption.DIRECT_CHILDREN_ONLY); return dataNodes.stream().map(YangDataConverter::convertCmHandleToYangModel) 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 3db84556e9..7359518dc9 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 @@ -21,6 +21,7 @@ package org.onap.cps.ncmp.api.impl.operations; +import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL; import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING; import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ; import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA; @@ -69,49 +70,48 @@ public class DmiDataOperations { * This method fetches the resource data from the operational data store for a given CM handle * identifier on the specified resource using the DMI client. * - * @param cmResourceAddress Target datastore, CM handle, and resource identifier. - * @param optionsParamInQuery Options query string. - * @param topicParamInQuery Topic name for triggering asynchronous responses. - * @param requestId Request ID for asynchronous responses. - * @param authorization Contents of the Authorization header, or null if not present. + * @param cmResourceAddress Target datastore, CM handle, and resource identifier. + * @param options Options query string. + * @param topic Topic name for triggering asynchronous responses. + * @param requestId Request ID for asynchronous responses. + * @param authorization Contents of the Authorization header, or null if not present. * @return {@code Mono>} A reactive type representing the response entity. */ @Timed(value = "cps.ncmp.dmi.get", description = "Time taken to fetch the resource data from operational data store for given cm handle " + "identifier on given resource using dmi client") public Mono> getResourceDataFromDmi(final CmResourceAddress cmResourceAddress, - final String optionsParamInQuery, - final String topicParamInQuery, - final String requestId, - final String authorization) { + final String options, + final String topic, + final String requestId, + final String authorization) { final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmResourceAddress.cmHandleId()); final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState(); validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState); final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle); final String dmiUrl = getDmiResourceDataUrl(cmResourceAddress.datastoreName(), yangModelCmHandle, - cmResourceAddress.resourceIdentifier(), optionsParamInQuery, topicParamInQuery); - return dmiRestClient.postOperationWithJsonDataAsync(DATA, dmiUrl, jsonRequestBody, READ, authorization); + cmResourceAddress.resourceIdentifier(), options, topic); + return dmiRestClient.asynchronousPostOperationWithJsonData(DATA, dmiUrl, jsonRequestBody, READ, authorization); } /** * This method fetches all the resource data from operational data store for given cm handle * identifier using dmi client. + * Note: this method is only used for DataSync * - * @param datastoreName data store name * @param cmHandleId network resource identifier * @param requestId requestId for async responses * @return {@code ResponseEntity} response entity */ - public ResponseEntity getResourceDataFromDmi(final String datastoreName, - final String cmHandleId, - final String requestId) { + public ResponseEntity getAllResourceDataFromDmi(final String cmHandleId, final String requestId) { final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmHandleId); final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState(); validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState); final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle); - final String dmiUrl = getDmiResourceDataUrl(datastoreName, yangModelCmHandle, "/", null, null); - return dmiRestClient.postOperationWithJsonData(DATA, dmiUrl, jsonRequestBody, READ, null); + final String dmiUrl = + getDmiResourceDataUrl(PASSTHROUGH_OPERATIONAL.getDatastoreName(), yangModelCmHandle, "/", null, null); + return dmiRestClient.synchronousPostOperationWithJsonData(DATA, dmiUrl, jsonRequestBody, READ, null); } /** @@ -168,7 +168,8 @@ public class DmiDataOperations { yangModelCmHandle); final String dmiUrl = getDmiResourceDataUrl(PASSTHROUGH_RUNNING.getDatastoreName(), yangModelCmHandle, resourceId, null, null); - return dmiRestClient.postOperationWithJsonData(DATA, dmiUrl, jsonRequestBody, operationType, authorization); + return dmiRestClient.synchronousPostOperationWithJsonData(DATA, dmiUrl, jsonRequestBody, + operationType, authorization); } private YangModelCmHandle getYangModelCmHandle(final String cmHandleId) { @@ -256,7 +257,7 @@ public class DmiDataOperations { final String authorization) { final String dmiDataOperationRequestAsJsonString = createDmiDataOperationRequestAsJsonString(dmiDataOperationRequestBodies); - return dmiRestClient.postOperationWithJsonDataAsync(DATA, dmiUrl, dmiDataOperationRequestAsJsonString, + return dmiRestClient.asynchronousPostOperationWithJsonData(DATA, dmiUrl, dmiDataOperationRequestAsJsonString, READ, authorization) .then() .onErrorResume(DmiClientRequestException.class, dmiClientRequestException -> { @@ -293,4 +294,4 @@ public class DmiDataOperations { ResourceDataOperationRequestUtils.publishErrorMessageToClientTopic(topicName, requestId, cmHandleIdsPerResponseCodesPerOperation); } -} \ No newline at end of file +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java index 77dfcb7a20..82dccc66da 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java @@ -21,6 +21,7 @@ package org.onap.cps.ncmp.api.impl.operations; +import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ; import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL; import com.google.gson.JsonArray; @@ -111,7 +112,7 @@ public class DmiModelOperations { .variablePathSegment("cmHandleId", cmHandle) .variablePathSegment("resourceName", resourceName) .build(dmiServiceName, dmiProperties.getDmiBasePath()); - return dmiRestClient.postOperationWithJsonData(MODEL, dmiUrl, jsonRequestBody, OperationType.READ, null); + return dmiRestClient.synchronousPostOperationWithJsonData(MODEL, dmiUrl, jsonRequestBody, READ, null); } private static String getRequestBodyToFetchYangResources(final Collection newModuleReferences, diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java index d6d6fd6bc1..1022512a6c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java @@ -24,9 +24,9 @@ import java.util.Collection; import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.onap.cps.ncmp.api.NetworkCmProxyDataService; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig; +import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService; import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager; import org.springframework.beans.factory.annotation.Qualifier; @@ -39,7 +39,7 @@ import org.springframework.stereotype.Service; public class DmiPluginWatchDog { private final DmiRestClient dmiRestClient; - private final NetworkCmProxyDataService networkCmProxyDataService; + private final CmHandleQueryService cmHandleQueryService; private final TrustLevelManager trustLevelManager; @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN) @@ -68,7 +68,7 @@ public class DmiPluginWatchDog { log.debug("The Dmi Plugin: {} has already the same trust level: {}", dmiServiceName, newDmiTrustLevel); } else { final Collection cmHandleIds = - networkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier(dmiServiceName); + cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiServiceName); trustLevelManager.handleUpdateOfDmiTrustLevel(dmiServiceName, cmHandleIds, newDmiTrustLevel); } }); -- cgit 1.2.3-korg