diff options
27 files changed, 304 insertions, 189 deletions
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy index b998a16b2d..be7f449326 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy @@ -32,7 +32,7 @@ import groovy.json.JsonSlurper import org.mapstruct.factory.Mappers import org.onap.cps.TestUtils import org.onap.cps.events.EventsPublisher -import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import org.onap.cps.ncmp.api.inventory.models.CompositeState import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle import org.onap.cps.ncmp.api.inventory.models.TrustLevel @@ -91,7 +91,7 @@ class NetworkCmProxyControllerSpec extends Specification { NetworkCmProxyFacade mockNetworkCmProxyFacade = Mock() @SpringBean - NetworkCmProxyInventoryFacade mockNetworkCmProxyInventoryFacade = Mock() + NetworkCmProxyInventoryFacadeImpl mockNetworkCmProxyInventoryFacade = Mock() @SpringBean AlternateIdMatcher mockAlternateIdMatcher = Mock() diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy index 59307640ef..9d79922478 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy @@ -23,7 +23,7 @@ package org.onap.cps.ncmp.rest.controller import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.TestUtils -import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration @@ -55,7 +55,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { MockMvc mvc @SpringBean - NetworkCmProxyInventoryFacade mockNetworkCmProxyInventoryFacade = Mock() + NetworkCmProxyInventoryFacadeImpl mockNetworkCmProxyInventoryFacade = Mock() @SpringBean NcmpRestInputMapper ncmpRestInputMapper = Mock() diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy index 26060a02d2..aad04a18ae 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy @@ -31,7 +31,7 @@ import org.onap.cps.ncmp.api.exceptions.DmiRequestException import org.onap.cps.ncmp.api.exceptions.PayloadTooLargeException import org.onap.cps.ncmp.api.exceptions.PolicyExecutorException import org.onap.cps.ncmp.api.exceptions.ServerNcmpException -import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import org.onap.cps.ncmp.impl.data.NcmpCachedResourceRequestHandler import org.onap.cps.ncmp.impl.data.NcmpPassthroughResourceRequestHandler import org.onap.cps.ncmp.impl.data.NetworkCmProxyFacade @@ -76,7 +76,7 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { NetworkCmProxyFacade mockNetworkCmProxyFacade = Mock() @SpringBean - NetworkCmProxyInventoryFacade mockNetworkCmProxyInventoryFacade = Mock() + NetworkCmProxyInventoryFacadeImpl mockNetworkCmProxyInventoryFacade = Mock() @SpringBean InventoryPersistence mockInventoryPersistence = Mock() diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java index 64bec06fec..9bfb775d55 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java @@ -1,10 +1,6 @@ /* * ============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. + * Copyright (C) 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. @@ -24,47 +20,18 @@ package org.onap.cps.ncmp.api.inventory; -import static org.onap.cps.ncmp.impl.inventory.CmHandleQueryParametersValidator.validateCmHandleQueryParameters; - import java.util.Collection; -import java.util.Collections; import java.util.Map; -import lombok.RequiredArgsConstructor; import org.onap.cps.api.model.ModuleDefinition; import org.onap.cps.api.model.ModuleReference; -import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException; import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryApiParameters; import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters; import org.onap.cps.ncmp.api.inventory.models.CompositeState; import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration; import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistrationResponse; import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; -import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService; -import org.onap.cps.ncmp.impl.inventory.CmHandleRegistrationService; -import org.onap.cps.ncmp.impl.inventory.InventoryPersistence; -import org.onap.cps.ncmp.impl.inventory.ParameterizedCmHandleQueryService; -import org.onap.cps.ncmp.impl.inventory.models.CmHandleQueryConditions; -import org.onap.cps.ncmp.impl.inventory.models.InventoryQueryConditions; -import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; -import org.onap.cps.ncmp.impl.inventory.trustlevel.TrustLevelManager; -import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher; -import org.onap.cps.ncmp.impl.utils.YangDataConverter; -import org.onap.cps.utils.JsonObjectMapper; -import org.springframework.stereotype.Service; - -@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; - private final TrustLevelManager trustLevelManager; - private final AlternateIdMatcher alternateIdMatcher; - +public interface NetworkCmProxyInventoryFacade { /** * Registration of Created, Removed, Updated or Upgraded CM Handles. @@ -72,9 +39,7 @@ public class NetworkCmProxyInventoryFacade { * @param dmiPluginRegistration Dmi Plugin Registration details * @return dmiPluginRegistrationResponse */ - public DmiPluginRegistrationResponse updateDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) { - return cmHandleRegistrationService.updateDmiRegistration(dmiPluginRegistration); - } + DmiPluginRegistrationResponse updateDmiRegistration(final DmiPluginRegistration dmiPluginRegistration); /** * Get all cm handle references by DMI plugin identifier. @@ -84,10 +49,8 @@ public class NetworkCmProxyInventoryFacade { * cm handle id (false) or alternate id (true) * @return collection of cm handle references */ - public Collection<String> getAllCmHandleReferencesByDmiPluginIdentifier(final String dmiPluginIdentifier, - final boolean outputAlternateId) { - return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifier, outputAlternateId); - } + Collection<String> getAllCmHandleReferencesByDmiPluginIdentifier(final String dmiPluginIdentifier, + final boolean outputAlternateId); /** * Get all cm handle IDs by various properties. @@ -97,14 +60,9 @@ public class NetworkCmProxyInventoryFacade { * cm handle id (false) or alternate id (true) * @return collection of cm handle references */ - public Collection<String> executeParameterizedCmHandleIdSearch( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) { - validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES); - - return parameterizedCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters, - outputAlternateId); - } - + Collection<String> executeParameterizedCmHandleIdSearch(final CmHandleQueryServiceParameters + cmHandleQueryServiceParameters, + final boolean outputAlternateId); /** * Retrieve module references for the given cm handle reference. @@ -112,14 +70,7 @@ public class NetworkCmProxyInventoryFacade { * @param cmHandleReference cm handle or alternate id identifier * @return a collection of modules names and revisions */ - public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleReference) { - try { - final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); - return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId); - } catch (final CmHandleNotFoundException cmHandleNotFoundException) { - return Collections.emptyList(); - } - } + Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleReference); /** * Retrieve module definitions for the given cm handle. @@ -127,14 +78,7 @@ public class NetworkCmProxyInventoryFacade { * @param cmHandleReference cm handle or alternate id identifier * @return a collection of module definition (moduleName, revision and yang resource content) */ - public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleReference(final String cmHandleReference) { - try { - final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); - return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId); - } catch (final CmHandleNotFoundException cmHandleNotFoundException) { - return Collections.emptyList(); - } - } + Collection<ModuleDefinition> getModuleDefinitionsByCmHandleReference(final String cmHandleReference); /** * Get module definitions for the given parameters. @@ -144,16 +88,9 @@ public class NetworkCmProxyInventoryFacade { * @param moduleRevision the revision of the module * @return list of module definitions (module name, revision, yang resource content) */ - public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleAndModule(final String cmHandleReference, - final String moduleName, - final String moduleRevision) { - try { - final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); - return inventoryPersistence.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, moduleRevision); - } catch (final CmHandleNotFoundException cmHandleNotFoundException) { - return Collections.emptyList(); - } - } + Collection<ModuleDefinition> getModuleDefinitionsByCmHandleAndModule(final String cmHandleReference, + final String moduleName, + final String moduleRevision); /** * Retrieve cm handles with details for the given query parameters. @@ -161,16 +98,7 @@ public class NetworkCmProxyInventoryFacade { * @param cmHandleQueryApiParameters cm handle query parameters * @return cm handles with details */ - public Collection<NcmpServiceCmHandle> executeCmHandleSearch( - final CmHandleQueryApiParameters cmHandleQueryApiParameters) { - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( - cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); - validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); - final Collection<NcmpServiceCmHandle> ncmpServiceCmHandles = - parameterizedCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters); - trustLevelManager.applyEffectiveTrustLevels(ncmpServiceCmHandles); - return ncmpServiceCmHandles; - } + Collection<NcmpServiceCmHandle> executeCmHandleSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters); /** * Retrieve cm handle ids for the given query parameters. @@ -179,14 +107,8 @@ public class NetworkCmProxyInventoryFacade { * @param outputAlternateId boolean for cm handle reference type either cmHandleId (false) or AlternateId (true) * @return cm handle ids */ - public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters, - final boolean outputAlternateId) { - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( - cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); - validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); - return parameterizedCmHandleQueryService.queryCmHandleReferenceIds(cmHandleQueryServiceParameters, - outputAlternateId); - } + Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters, + final boolean outputAlternateId); /** * Set the data sync enabled flag, along with the data sync state @@ -195,9 +117,7 @@ public class NetworkCmProxyInventoryFacade { * @param cmHandleId cm handle id * @param dataSyncEnabledTargetValue data sync enabled flag */ - public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) { - cmHandleRegistrationService.setDataSyncEnabled(cmHandleId, dataSyncEnabledTargetValue); - } + void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue); /** * Retrieve cm handle details for a given cm handle reference. @@ -205,13 +125,7 @@ public class NetworkCmProxyInventoryFacade { * @param cmHandleReference cm handle or alternate identifier * @return cm handle details */ - public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleReference) { - final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); - final NcmpServiceCmHandle ncmpServiceCmHandle = YangDataConverter.toNcmpServiceCmHandle( - inventoryPersistence.getYangModelCmHandle(cmHandleId)); - trustLevelManager.applyEffectiveTrustLevel(ncmpServiceCmHandle); - return ncmpServiceCmHandle; - } + NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleReference); /** * Get cm handle public properties for a given cm handle or alternate id. @@ -219,11 +133,7 @@ public class NetworkCmProxyInventoryFacade { * @param cmHandleReference cm handle or alternate identifier * @return cm handle public properties */ - public Map<String, String> getCmHandlePublicProperties(final String cmHandleReference) { - final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); - final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); - return YangDataConverter.toPropertiesMap(yangModelCmHandle.getPublicProperties()); - } + Map<String, String> getCmHandlePublicProperties(final String cmHandleReference); /** * Get cm handle composite state for a given cm handle id. @@ -231,9 +141,5 @@ public class NetworkCmProxyInventoryFacade { * @param cmHandleReference cm handle or alternate identifier * @return cm handle state */ - public CompositeState getCmHandleCompositeState(final String cmHandleReference) { - final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); - return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState(); - } - + CompositeState getCmHandleCompositeState(final String cmHandleReference); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/NetworkCmProxyInventoryFacadeImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/NetworkCmProxyInventoryFacadeImpl.java new file mode 100644 index 0000000000..118c2bba70 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/NetworkCmProxyInventoryFacadeImpl.java @@ -0,0 +1,169 @@ +/* + * ============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.impl; + +import static org.onap.cps.ncmp.impl.inventory.CmHandleQueryParametersValidator.validateCmHandleQueryParameters; + +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import lombok.RequiredArgsConstructor; +import org.onap.cps.api.model.ModuleDefinition; +import org.onap.cps.api.model.ModuleReference; +import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException; +import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade; +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryApiParameters; +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters; +import org.onap.cps.ncmp.api.inventory.models.CompositeState; +import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration; +import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistrationResponse; +import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; +import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService; +import org.onap.cps.ncmp.impl.inventory.CmHandleRegistrationService; +import org.onap.cps.ncmp.impl.inventory.InventoryPersistence; +import org.onap.cps.ncmp.impl.inventory.ParameterizedCmHandleQueryService; +import org.onap.cps.ncmp.impl.inventory.models.CmHandleQueryConditions; +import org.onap.cps.ncmp.impl.inventory.models.InventoryQueryConditions; +import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; +import org.onap.cps.ncmp.impl.inventory.trustlevel.TrustLevelManager; +import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher; +import org.onap.cps.ncmp.impl.utils.YangDataConverter; +import org.onap.cps.utils.JsonObjectMapper; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class NetworkCmProxyInventoryFacadeImpl implements NetworkCmProxyInventoryFacade { + + private final CmHandleRegistrationService cmHandleRegistrationService; + private final CmHandleQueryService cmHandleQueryService; + private final ParameterizedCmHandleQueryService parameterizedCmHandleQueryService; + private final InventoryPersistence inventoryPersistence; + private final JsonObjectMapper jsonObjectMapper; + private final TrustLevelManager trustLevelManager; + private final AlternateIdMatcher alternateIdMatcher; + + @Override + public DmiPluginRegistrationResponse updateDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) { + return cmHandleRegistrationService.updateDmiRegistration(dmiPluginRegistration); + } + + @Override + public Collection<String> getAllCmHandleReferencesByDmiPluginIdentifier(final String dmiPluginIdentifier, + final boolean outputAlternateId) { + return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifier, outputAlternateId); + } + + @Override + public Collection<String> executeParameterizedCmHandleIdSearch( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) { + validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES); + + return parameterizedCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters, + outputAlternateId); + } + + @Override + public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleReference) { + try { + final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); + return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId); + } catch (final CmHandleNotFoundException cmHandleNotFoundException) { + return Collections.emptyList(); + } + } + + @Override + public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleReference(final String cmHandleReference) { + try { + final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); + return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId); + } catch (final CmHandleNotFoundException cmHandleNotFoundException) { + return Collections.emptyList(); + } + } + + @Override + public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleAndModule(final String cmHandleReference, + final String moduleName, + final String moduleRevision) { + try { + final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); + return inventoryPersistence.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, moduleRevision); + } catch (final CmHandleNotFoundException cmHandleNotFoundException) { + return Collections.emptyList(); + } + } + + @Override + public Collection<NcmpServiceCmHandle> executeCmHandleSearch( + final CmHandleQueryApiParameters cmHandleQueryApiParameters) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( + cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); + validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); + final Collection<NcmpServiceCmHandle> ncmpServiceCmHandles = + parameterizedCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters); + trustLevelManager.applyEffectiveTrustLevels(ncmpServiceCmHandles); + return ncmpServiceCmHandles; + } + + @Override + public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters, + final boolean outputAlternateId) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( + cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); + validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); + return parameterizedCmHandleQueryService.queryCmHandleReferenceIds(cmHandleQueryServiceParameters, + outputAlternateId); + } + + @Override + public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) { + cmHandleRegistrationService.setDataSyncEnabled(cmHandleId, dataSyncEnabledTargetValue); + } + + @Override + public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleReference) { + final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); + final NcmpServiceCmHandle ncmpServiceCmHandle = YangDataConverter.toNcmpServiceCmHandle( + inventoryPersistence.getYangModelCmHandle(cmHandleId)); + trustLevelManager.applyEffectiveTrustLevel(ncmpServiceCmHandle); + return ncmpServiceCmHandle; + } + + @Override + public Map<String, String> getCmHandlePublicProperties(final String cmHandleReference) { + final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); + final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); + return YangDataConverter.toPropertiesMap(yangModelCmHandle.getPublicProperties()); + } + + @Override + public CompositeState getCmHandleCompositeState(final String cmHandleReference) { + final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference); + return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState(); + } + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java index 770dde1c08..75007e2e35 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java @@ -23,6 +23,7 @@ package org.onap.cps.ncmp.impl.cache; import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.config.NamedConfig; +import com.hazelcast.config.NearCacheConfig; import com.hazelcast.config.QueueConfig; import com.hazelcast.config.RestEndpointGroup; import com.hazelcast.config.SetConfig; @@ -94,6 +95,21 @@ public class HazelcastCacheConfig { return mapConfig; } + protected static MapConfig createMapConfigWithTimeToLiveInSeconds(final String configName, + final int timeToLiveInSeconds) { + final MapConfig mapConfig = new MapConfig(configName); + mapConfig.setBackupCount(1); + mapConfig.setTimeToLiveSeconds(timeToLiveInSeconds); + return mapConfig; + } + + protected static MapConfig createNearCacheMapConfig(final String configName) { + final MapConfig mapConfig = new MapConfig(configName); + mapConfig.setBackupCount(1); + mapConfig.setNearCacheConfig(new NearCacheConfig(configName)); + return mapConfig; + } + protected static QueueConfig createQueueConfig(final String configName) { final QueueConfig commonQueueConfig = new QueueConfig(configName); commonQueueConfig.setBackupCount(1); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java index 5610013863..c1291632de 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java @@ -26,6 +26,7 @@ import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DATASPACE_NA import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR; import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; +import com.hazelcast.map.IMap; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -59,10 +60,10 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { private final CpsQueryService cpsQueryService; @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN) - private final Map<String, TrustLevel> trustLevelPerDmiPlugin; + private final IMap<String, TrustLevel> trustLevelPerDmiPlugin; @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_CM_HANDLE) - private final Map<String, TrustLevel> trustLevelPerCmHandleId; + private final IMap<String, TrustLevel> trustLevelPerCmHandleId; private final CpsValidator cpsValidator; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java index daac63fce4..281d64edb4 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java @@ -319,7 +319,8 @@ public class CmHandleRegistrationService { // CPS-1239 Robustness cleaning of in progress cache private void removeDeletedCmHandleFromModuleSyncMap(final String cmHandleId) { - if (moduleSyncStartedOnCmHandles.remove(cmHandleId) != null) { + if (moduleSyncStartedOnCmHandles.containsKey(cmHandleId)) { + moduleSyncStartedOnCmHandles.removeAsync(cmHandleId); log.debug("{} removed from in progress map", cmHandleId); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java index c97b284bf1..0d618cfa40 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java @@ -125,7 +125,8 @@ public class ModuleSyncTasks { } private void removeResetCmHandleFromModuleSyncMap(final String resetCmHandleId) { - if (moduleSyncStartedOnCmHandles.remove(resetCmHandleId) != null) { + if (moduleSyncStartedOnCmHandles.containsKey(resetCmHandleId)) { + moduleSyncStartedOnCmHandles.removeAsync(resetCmHandleId); log.info("{} removed from in progress map", resetCmHandleId); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdog.java index 74bef43d0b..3f2bb4f4ef 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdog.java @@ -139,8 +139,7 @@ public class ModuleSyncWatchdog { log.info("nextBatchCandidates size : {}", nextBatchCandidates.size()); for (final String cmHandleId : nextBatchCandidates) { final boolean alreadyAddedToInProgressMap = VALUE_FOR_HAZELCAST_IN_PROGRESS_MAP.equals( - moduleSyncStartedOnCmHandles.putIfAbsent(cmHandleId, VALUE_FOR_HAZELCAST_IN_PROGRESS_MAP, - SynchronizationCacheConfig.MODULE_SYNC_STARTED_TTL_SECS, TimeUnit.SECONDS)); + moduleSyncStartedOnCmHandles.putIfAbsent(cmHandleId, VALUE_FOR_HAZELCAST_IN_PROGRESS_MAP)); if (alreadyAddedToInProgressMap) { log.info("module sync for {} already in progress by other instance", cmHandleId); } else { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfig.java index 671e791ac2..def8f37eb7 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfig.java @@ -43,7 +43,8 @@ public class SynchronizationCacheConfig extends HazelcastCacheConfig { public static final int DATA_SYNC_SEMAPHORE_TTL_SECS = 1800; private static final QueueConfig commonQueueConfig = createQueueConfig("defaultQueueConfig"); - private static final MapConfig moduleSyncStartedConfig = createMapConfig("moduleSyncStartedConfig"); + private static final MapConfig moduleSyncStartedConfig = + createMapConfigWithTimeToLiveInSeconds("moduleSyncStartedConfig", MODULE_SYNC_STARTED_TTL_SECS); private static final MapConfig dataSyncSemaphoresConfig = createMapConfig("dataSyncSemaphoresConfig"); private static final SetConfig moduleSetTagsBeingProcessedConfig = createSetConfig("moduleSetTagsBeingProcessedConfig"); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java index aca485f53d..044e2b5553 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java @@ -20,8 +20,8 @@ package org.onap.cps.ncmp.impl.inventory.trustlevel; +import com.hazelcast.map.IMap; import java.util.Collection; -import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.inventory.models.TrustLevel; @@ -43,7 +43,7 @@ public class DmiPluginTrustLevelWatchDog { private final TrustLevelManager trustLevelManager; @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN) - private final Map<String, TrustLevel> trustLevelPerDmiPlugin; + private final IMap<String, TrustLevel> trustLevelPerDmiPlugin; /** * This class monitors the trust level of all DMI plugin by checking the health status diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java index f9ad3ff937..a11dec7ba6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java @@ -34,7 +34,7 @@ public class TrustLevelCacheConfig extends HazelcastCacheConfig { public static final String TRUST_LEVEL_PER_CM_HANDLE = "trustLevelPerCmHandle"; private static final MapConfig trustLevelPerCmHandleIdCacheConfig = - createMapConfig("trustLevelPerCmHandleCacheConfig"); + createNearCacheMapConfig("trustLevelPerCmHandleCacheConfig"); private static final MapConfig trustLevelPerDmiPluginCacheConfig = createMapConfig("trustLevelPerDmiPluginCacheConfig"); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManager.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManager.java index b61e53854e..6e896620c6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManager.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManager.java @@ -64,7 +64,7 @@ public class TrustLevelManager { public void registerDmiPlugin(final DmiPluginRegistration dmiPluginRegistration) { final String dmiServiceName = DmiServiceNameResolver.resolveDmiServiceName(RequiredDmiService.DATA, dmiPluginRegistration); - trustLevelPerDmiPlugin.put(dmiServiceName, TrustLevel.COMPLETE); + trustLevelPerDmiPlugin.putAsync(dmiServiceName, TrustLevel.COMPLETE); } /** @@ -73,24 +73,22 @@ public class TrustLevelManager { * @param cmHandlesToBeCreated a list of cmHandles being created */ public void registerCmHandles(final Map<String, TrustLevel> cmHandlesToBeCreated) { + final Map<String, TrustLevel> trustLevelPerCmHandleIdForCache = new HashMap<>(); for (final Map.Entry<String, TrustLevel> entry : cmHandlesToBeCreated.entrySet()) { final String cmHandleId = entry.getKey(); - if (trustLevelPerCmHandleId.containsKey(cmHandleId)) { - log.warn("Cm handle: {} already registered", cmHandleId); - } else { - TrustLevel initialTrustLevel = entry.getValue(); - if (initialTrustLevel == null) { - initialTrustLevel = TrustLevel.COMPLETE; - } - trustLevelPerCmHandleId.put(cmHandleId, initialTrustLevel); - if (TrustLevel.NONE.equals(initialTrustLevel)) { - cmAvcEventPublisher.publishAvcEvent(cmHandleId, + TrustLevel initialTrustLevel = entry.getValue(); + if (initialTrustLevel == null) { + initialTrustLevel = TrustLevel.COMPLETE; + } + trustLevelPerCmHandleIdForCache.put(cmHandleId, initialTrustLevel); + if (TrustLevel.NONE.equals(initialTrustLevel)) { + cmAvcEventPublisher.publishAvcEvent(cmHandleId, AVC_CHANGED_ATTRIBUTE_NAME, AVC_NO_OLD_VALUE, initialTrustLevel.name()); - } } } + trustLevelPerCmHandleId.putAllAsync(trustLevelPerCmHandleIdForCache); } /** @@ -105,7 +103,7 @@ public class TrustLevelManager { final Collection<String> affectedCmHandleIds, final TrustLevel newDmiTrustLevel) { final TrustLevel oldDmiTrustLevel = trustLevelPerDmiPlugin.get(dmiServiceName); - trustLevelPerDmiPlugin.put(dmiServiceName, newDmiTrustLevel); + trustLevelPerDmiPlugin.putAsync(dmiServiceName, newDmiTrustLevel); for (final String affectedCmHandleId : affectedCmHandleIds) { final TrustLevel cmHandleTrustLevel = trustLevelPerCmHandleId.get(affectedCmHandleId); final TrustLevel oldEffectiveTrustLevel = cmHandleTrustLevel.getEffectiveTrustLevel(oldDmiTrustLevel); @@ -131,7 +129,7 @@ public class TrustLevelManager { final TrustLevel oldEffectiveTrustLevel = oldCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); final TrustLevel newEffectiveTrustLevel = newCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); - trustLevelPerCmHandleId.put(cmHandleId, newCmHandleTrustLevel); + trustLevelPerCmHandleId.putAsync(cmHandleId, newCmHandleTrustLevel); sendAvcNotificationIfRequired(cmHandleId, oldEffectiveTrustLevel, newEffectiveTrustLevel); } @@ -174,10 +172,11 @@ public class TrustLevelManager { * @param cmHandleIds cm handle ids to be removed from the cache */ public void removeCmHandles(final Collection<String> cmHandleIds) { - for (final String cmHandleId : cmHandleIds) { - if (trustLevelPerCmHandleId.remove(cmHandleId) == null) { - log.debug("Removed Cm handle: {} is not in trust level cache", cmHandleId); - } + final Set<String> cmHandlesToRemove = trustLevelPerCmHandleId.keySet().stream() + .filter(cmHandleIds::contains) + .collect(Collectors.toSet()); + for (final String cmHandleId : cmHandlesToRemove) { + trustLevelPerCmHandleId.removeAsync(cmHandleId); } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy index d19081cee5..7ac2b2cded 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy @@ -21,6 +21,9 @@ package org.onap.cps.ncmp.impl.inventory +import com.hazelcast.config.Config +import com.hazelcast.core.Hazelcast +import com.hazelcast.instance.impl.HazelcastInstanceFactory import org.onap.cps.api.CpsDataService import org.onap.cps.api.CpsQueryService import org.onap.cps.impl.utils.CpsValidator @@ -39,11 +42,17 @@ class CmHandleQueryServiceImplSpec extends Specification { def mockCpsQueryService = Mock(CpsQueryService) def mockCpsDataService = Mock(CpsDataService) - def trustLevelPerDmiPlugin = [:] - def trustLevelPerCmHandleId = [ 'PNFDemo': TrustLevel.COMPLETE, 'PNFDemo2': TrustLevel.NONE, 'PNFDemo4': TrustLevel.NONE ] + def trustLevelPerDmiPlugin = HazelcastInstanceFactory + .getOrCreateHazelcastInstance(new Config('hazelcastInstanceName')) + .getMap('trustLevelPerDmiPlugin') + def trustLevelPerCmHandleId = HazelcastInstanceFactory + .getOrCreateHazelcastInstance(new Config('hazelcastInstanceName')) + .getMap('trustLevelPerCmHandleId') def mockCpsValidator = Mock(CpsValidator) - def objectUnderTest = new CmHandleQueryServiceImpl(mockCpsDataService, mockCpsQueryService, trustLevelPerDmiPlugin, trustLevelPerCmHandleId, mockCpsValidator) + + def objectUnderTest = new CmHandleQueryServiceImpl(mockCpsDataService, mockCpsQueryService, + trustLevelPerDmiPlugin, trustLevelPerCmHandleId, mockCpsValidator) def static sampleDataNodes = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-1']"), new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-2']")] @@ -56,6 +65,16 @@ class CmHandleQueryServiceImplSpec extends Specification { def static pnfDemo4 = createDataNode('PNFDemo4') def static pnfDemo5 = createDataNode('PNFDemo5') + def setup() { + trustLevelPerCmHandleId.put("PNFDemo", TrustLevel.COMPLETE) + trustLevelPerCmHandleId.put("PNFDemo2", TrustLevel.NONE) + trustLevelPerCmHandleId.put("PNFDemo4", TrustLevel.NONE) + } + + def cleanupSpec() { + Hazelcast.getHazelcastInstanceByName('hazelcastInstanceName').shutdown() + } + def 'Query CmHandles with public properties query pair.'() { given: 'the DataNodes queried for a given cpsPath are returned from the persistence service.' mockResponses() diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy index 67778fc0a3..faa193ea33 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy @@ -64,7 +64,7 @@ class CmHandleRegistrationServiceSpec extends Specification { def objectUnderTest = Spy(new CmHandleRegistrationService( mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCpsDataService, mockLcmEventsCmHandleStateHandler, - mockModuleSyncStartedOnCmHandles, mockTrustLevelManager, mockAlternateIdChecker)) + mockModuleSyncStartedOnCmHandles as IMap<String, Object>, mockTrustLevelManager, mockAlternateIdChecker)) def setup() { // always accept all cm handles @@ -86,14 +86,14 @@ class CmHandleRegistrationServiceSpec extends Specification { mockInventoryPersistence.getYangModelCmHandle('cmhandle-3') >> new YangModelCmHandle(id: 'cmhandle-3', moduleSetTag: '', compositeState: new CompositeState(cmHandleState: CmHandleState.READY)) and: 'cm handle is in READY state' mockCmHandleQueries.cmHandleHasState('cmhandle-3', CmHandleState.READY) >> true + and: 'cm handle to be removed is in progress map' + mockModuleSyncStartedOnCmHandles.containsKey('cmhandle-2') >> true when: 'registration is processed' objectUnderTest.updateDmiRegistration(dmiRegistration) then: 'cm-handles are removed first' 1 * objectUnderTest.processRemovedCmHandles(*_) and: 'de-registered cm handle entry is removed from in progress map' - 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle-2') - then: 'cm-handles are created' - 1 * objectUnderTest.processCreatedCmHandles(*_) + 1 * mockModuleSyncStartedOnCmHandles.removeAsync('cmhandle-2') then: 'cm-handles are updated' 1 * objectUnderTest.processUpdatedCmHandles(*_) 1 * mockNetworkCmProxyDataServicePropertyHandler.updateCmHandleProperties(*_) >> [] @@ -310,6 +310,9 @@ class CmHandleRegistrationServiceSpec extends Specification { given: 'a registration with three cm-handles to be deleted' def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server', removedCmHandles: ['cmhandle1', 'cmhandle2', 'cmhandle3']) + and: 'cm handles to be deleted in the progress map' + mockModuleSyncStartedOnCmHandles.containsKey("cmhandle1") >> true + mockModuleSyncStartedOnCmHandles.containsKey("cmhandle3") >> true and: 'cm-handle deletion fails on batch' mockInventoryPersistence.deleteDataNodes(_) >> { throw new RuntimeException("Failed") } and: 'cm-handle deletion is successful for 1st and 3rd; failed for 2nd' @@ -321,11 +324,12 @@ class CmHandleRegistrationServiceSpec extends Specification { and: 'a response is received for all cm-handles' response.removedCmHandles.size() == 3 and: 'successfully de-registered cm handle 1 is removed from in progress map' - 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle1') + 1 * mockModuleSyncStartedOnCmHandles.removeAsync('cmhandle1') and: 'successfully de-registered cm handle 3 is removed from in progress map even though it was already being removed' - 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle3') >> 'already in progress' + 1 * mockModuleSyncStartedOnCmHandles.removeAsync('cmhandle3') and: 'failed de-registered cm handle entries should NOT be removed from in progress map' - 0 * mockModuleSyncStartedOnCmHandles.remove('cmhandle2') + 0 * mockModuleSyncStartedOnCmHandles.containsKey('cmhandle2') + 0 * mockModuleSyncStartedOnCmHandles.removeAsync('cmhandle2') and: '1st and 3rd cm-handle deletes successfully' with(response.removedCmHandles[0]) { assert it.status == Status.SUCCESS @@ -349,7 +353,6 @@ class CmHandleRegistrationServiceSpec extends Specification { }) and: 'No cm handles state updates for "upgraded cm handles"' 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch([:]) - } def 'Remove CmHandle Error Handling: Schema Set Deletion failed'() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy index ae2554762f..c62a87f5c3 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy @@ -24,7 +24,7 @@ package org.onap.cps.ncmp.impl.inventory import com.fasterxml.jackson.databind.ObjectMapper -import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.api.model.ConditionProperties import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryApiParameters import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters import org.onap.cps.ncmp.api.inventory.models.CompositeState @@ -32,12 +32,12 @@ import org.onap.cps.ncmp.api.inventory.models.ConditionApiProperties import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle import org.onap.cps.ncmp.api.inventory.models.TrustLevel +import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import org.onap.cps.ncmp.impl.inventory.models.CmHandleState import org.onap.cps.ncmp.impl.inventory.models.LockReasonCategory import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle import org.onap.cps.ncmp.impl.inventory.trustlevel.TrustLevelManager import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher -import org.onap.cps.api.model.ConditionProperties import org.onap.cps.utils.JsonObjectMapper import spock.lang.Specification @@ -50,7 +50,7 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { def mockInventoryPersistence = Mock(InventoryPersistence) def mockTrustLevelManager = Mock(TrustLevelManager) def mockAlternateIdMatcher = Mock(AlternateIdMatcher) - def objectUnderTest = new NetworkCmProxyInventoryFacade(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper, mockTrustLevelManager, mockAlternateIdMatcher) + def objectUnderTest = new NetworkCmProxyInventoryFacadeImpl(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper, mockTrustLevelManager, mockAlternateIdMatcher) def 'Update DMI Registration'() { given: 'an (updated) dmi plugin registration' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy index 32f4503005..097387c038 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy @@ -20,6 +20,9 @@ package org.onap.cps.ncmp.impl.inventory.trustlevel +import com.hazelcast.config.Config +import com.hazelcast.core.Hazelcast +import com.hazelcast.instance.impl.HazelcastInstanceFactory import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.onap.cps.ncmp.impl.dmi.DmiRestClient import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService @@ -32,11 +35,16 @@ class DmiPluginTrustLevelWatchDogSpec extends Specification { def mockDmiRestClient = Mock(DmiRestClient) def mockCmHandleQueryService = Mock(CmHandleQueryService) def mockTrustLevelManager = Mock(TrustLevelManager) - def trustLevelPerDmiPlugin = [:] - + def trustLevelPerDmiPlugin = HazelcastInstanceFactory + .getOrCreateHazelcastInstance(new Config('hazelcastInstanceName')) + .getMap('trustLevelPerDmiPlugin') def objectUnderTest = new DmiPluginTrustLevelWatchDog(mockDmiRestClient, mockCmHandleQueryService, mockTrustLevelManager, trustLevelPerDmiPlugin) + def cleanupSpec() { + Hazelcast.getHazelcastInstanceByName('hazelcastInstanceName').shutdown() + } + def 'watch dmi plugin health status for #dmiHealhStatus'() { given: 'the cache has been initialised and "knows" about dmi-1' trustLevelPerDmiPlugin.put('dmi-1', dmiOldTrustLevel) diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy index 1088ca8e06..1ab517cdcf 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy @@ -77,19 +77,6 @@ class TrustLevelManagerSpec extends Specification { assert trustLevelPerCmHandleId.get('ch-2') == TrustLevel.COMPLETE } - def 'Initial cm handle registration where a cm handle is already in the cache'() { - given: 'a trusted cm handle' - def cmHandleModelsToBeCreated = ['ch-1': TrustLevel.NONE] - and: 'the cm handle id already in the cache' - trustLevelPerCmHandleId.put('ch-1', TrustLevel.COMPLETE) - when: 'method to register to the cache is called' - objectUnderTest.registerCmHandles(cmHandleModelsToBeCreated) - then: 'no notification sent' - 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) - and: 'cm handle cache is not updated' - assert trustLevelPerCmHandleId.get('ch-1') == TrustLevel.COMPLETE - } - def 'Initial cm handle registration with a cm handle that is not trusted'() { given: 'a not trusted cm handle' def cmHandleModelsToBeCreated = ['ch-2': TrustLevel.NONE] diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy index 0725fe82d0..9fc36331e2 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy @@ -30,7 +30,7 @@ import org.onap.cps.api.CpsModuleService import org.onap.cps.api.CpsQueryService import org.onap.cps.integration.DatabaseTestContainer import org.onap.cps.integration.KafkaTestContainer -import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle import org.onap.cps.ncmp.impl.data.NetworkCmProxyFacade @@ -108,7 +108,7 @@ abstract class CpsIntegrationSpecBase extends Specification { NetworkCmProxyFacade networkCmProxyFacade @Autowired - NetworkCmProxyInventoryFacade NetworkCmProxyInventoryFacade + NetworkCmProxyInventoryFacadeImpl NetworkCmProxyInventoryFacade @Autowired NetworkCmProxyQueryService networkCmProxyQueryService diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleCreateSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleCreateSpec.groovy index ffcba025e8..e9fac48676 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleCreateSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleCreateSpec.groovy @@ -25,7 +25,7 @@ import org.apache.kafka.common.serialization.StringDeserializer import org.onap.cps.integration.KafkaTestContainer import org.onap.cps.integration.base.CpsIntegrationSpecBase import org.onap.cps.ncmp.api.NcmpResponseStatus -import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle @@ -38,7 +38,7 @@ import java.time.Duration class CmHandleCreateSpec extends CpsIntegrationSpecBase { - NetworkCmProxyInventoryFacade objectUnderTest + NetworkCmProxyInventoryFacadeImpl objectUnderTest def uniqueId = 'ch-unique-id-for-create-test' static KafkaConsumer kafkaConsumer diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleUpdateSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleUpdateSpec.groovy index 67011f811b..f2593ce587 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleUpdateSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleUpdateSpec.groovy @@ -22,14 +22,14 @@ package org.onap.cps.integration.functional.ncmp import org.onap.cps.integration.base.CpsIntegrationSpecBase import org.onap.cps.ncmp.api.NcmpResponseStatus -import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle class CmHandleUpdateSpec extends CpsIntegrationSpecBase { - NetworkCmProxyInventoryFacade objectUnderTest + NetworkCmProxyInventoryFacadeImpl objectUnderTest def setup() { objectUnderTest = networkCmProxyInventoryFacade diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleUpgradeSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleUpgradeSpec.groovy index a5e3daf289..5ce5658c1b 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleUpgradeSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleUpgradeSpec.groovy @@ -21,7 +21,7 @@ package org.onap.cps.integration.functional.ncmp import org.onap.cps.integration.base.CpsIntegrationSpecBase -import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.UpgradedCmHandles @@ -31,7 +31,7 @@ import spock.util.concurrent.PollingConditions class CmHandleUpgradeSpec extends CpsIntegrationSpecBase { - NetworkCmProxyInventoryFacade objectUnderTest + NetworkCmProxyInventoryFacadeImpl objectUnderTest def cmHandleId = 'ch-1' def cmHandleIdWithExistingModuleSetTag = 'ch-2' diff --git a/k6-tests/ncmp/common/utils.js b/k6-tests/ncmp/common/utils.js index 589a2482e6..8e68edd438 100644 --- a/k6-tests/ncmp/common/utils.js +++ b/k6-tests/ncmp/common/utils.js @@ -24,6 +24,7 @@ export const testConfig = JSON.parse(open(`../config/${__ENV.TEST_PROFILE}.json` export const KAFKA_BOOTSTRAP_SERVERS = testConfig.hosts.kafkaBootstrapServer; export const NCMP_BASE_URL = testConfig.hosts.ncmpBaseUrl; export const DMI_PLUGIN_URL = testConfig.hosts.dmiStubUrl; +export const CONTAINER_UP_TIME_IN_SECONDS = testConfig.hosts.containerUpTimeInSeconds; export const LEGACY_BATCH_TOPIC_NAME = 'legacy_batch_topic'; export const TOTAL_CM_HANDLES = 20000; export const REGISTRATION_BATCH_SIZE = 100; diff --git a/k6-tests/ncmp/config/endurance.json b/k6-tests/ncmp/config/endurance.json index d215d0a1e1..d4893a45cc 100644 --- a/k6-tests/ncmp/config/endurance.json +++ b/k6-tests/ncmp/config/endurance.json @@ -2,7 +2,8 @@ "hosts": { "ncmpBaseUrl": "http://localhost:8884", "dmiStubUrl": "http://ncmp-dmi-plugin-demo-and-csit-stub:8092", - "kafkaBootstrapServer": "localhost:9093" + "kafkaBootstrapServer": "localhost:9093", + "containerUpTimeInSeconds": 420 }, "scenarios": { "passthrough_read_scenario": { diff --git a/k6-tests/ncmp/config/kpi.json b/k6-tests/ncmp/config/kpi.json index 2318702449..eed041de85 100644 --- a/k6-tests/ncmp/config/kpi.json +++ b/k6-tests/ncmp/config/kpi.json @@ -2,7 +2,8 @@ "hosts": { "ncmpBaseUrl": "http://localhost:8883", "dmiStubUrl": "http://ncmp-dmi-plugin-demo-and-csit-stub:8092", - "kafkaBootstrapServer": "localhost:9092" + "kafkaBootstrapServer": "localhost:9092", + "containerUpTimeInSeconds": 300 }, "scenarios": { "passthrough_read_scenario": { diff --git a/k6-tests/ncmp/ncmp-test-runner.js b/k6-tests/ncmp/ncmp-test-runner.js index e33ff1852a..9ab326c44c 100644 --- a/k6-tests/ncmp/ncmp-test-runner.js +++ b/k6-tests/ncmp/ncmp-test-runner.js @@ -18,14 +18,14 @@ * ============LICENSE_END========================================================= */ -import { check } from 'k6'; +import { check, sleep } from 'k6'; import { Trend } from 'k6/metrics'; import { Reader } from 'k6/x/kafka'; import { TOTAL_CM_HANDLES, READ_DATA_FOR_CM_HANDLE_DELAY_MS, WRITE_DATA_FOR_CM_HANDLE_DELAY_MS, makeCustomSummaryReport, makeBatchOfCmHandleIds, LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE, REGISTRATION_BATCH_SIZE, LEGACY_BATCH_THROUGHPUT_TEST_NUMBER_OF_REQUESTS, KAFKA_BOOTSTRAP_SERVERS, - LEGACY_BATCH_TOPIC_NAME, testConfig + LEGACY_BATCH_TOPIC_NAME, CONTAINER_UP_TIME_IN_SECONDS, testConfig } from './common/utils.js'; import { createCmHandles, deleteCmHandles, waitForAllCmHandlesToBeReady } from './common/cmhandle-crud.js'; import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js'; @@ -97,6 +97,8 @@ export function teardown() { const totalDeregistrationTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0; cmHandlesDeletedPerSecondTrend.add(DEREGISTERED_CM_HANDLES / totalDeregistrationTimeInSeconds); + + sleep(CONTAINER_UP_TIME_IN_SECONDS); } export function passthroughReadScenario() { |