diff options
Diffstat (limited to 'cps-ncmp-service/src/main')
5 files changed, 81 insertions, 46 deletions
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 794bc238f4..6f51a8d011 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 @@ -36,7 +36,6 @@ 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.api.inventory.models.TrustLevel; import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService; import org.onap.cps.ncmp.impl.inventory.CmHandleRegistrationService; import org.onap.cps.ncmp.impl.inventory.InventoryPersistence; @@ -44,12 +43,11 @@ 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.TrustLevelCacheConfig; +import org.onap.cps.ncmp.impl.inventory.trustlevel.TrustLevelManager; import org.onap.cps.ncmp.impl.utils.YangDataConverter; 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; @Slf4j @@ -62,9 +60,7 @@ public class NetworkCmProxyInventoryFacade { private final ParameterizedCmHandleQueryService parameterizedCmHandleQueryService; private final InventoryPersistence inventoryPersistence; private final JsonObjectMapper jsonObjectMapper; - - @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_CM_HANDLE) - private final Map<String, TrustLevel> trustLevelPerCmHandle; + private final TrustLevelManager trustLevelManager; /** * Registration of Created, Removed, Updated or Upgraded CM Handles. @@ -72,7 +68,6 @@ public class NetworkCmProxyInventoryFacade { * @param dmiPluginRegistration Dmi Plugin Registration details * @return dmiPluginRegistrationResponse */ - public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule( final DmiPluginRegistration dmiPluginRegistration) { return cmHandleRegistrationService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration); @@ -211,7 +206,8 @@ public class NetworkCmProxyInventoryFacade { } private void applyCurrentTrustLevel(final NcmpServiceCmHandle ncmpServiceCmHandle) { - ncmpServiceCmHandle.setCurrentTrustLevel(trustLevelPerCmHandle.get(ncmpServiceCmHandle.getCmHandleId())); + ncmpServiceCmHandle.setCurrentTrustLevel(trustLevelManager + .getEffectiveTrustLevel(ncmpServiceCmHandle.getCmHandleId())); } 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 d6ddd108ea..d9f7e38993 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 @@ -37,6 +37,7 @@ import com.hazelcast.map.IMap; import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -58,13 +59,11 @@ import org.onap.cps.ncmp.impl.inventory.models.CmHandleState; import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; import org.onap.cps.ncmp.impl.inventory.sync.ModuleOperationsUtils; import org.onap.cps.ncmp.impl.inventory.sync.lcm.LcmEventsCmHandleStateHandler; -import org.onap.cps.ncmp.impl.inventory.trustlevel.TrustLevelCacheConfig; import org.onap.cps.ncmp.impl.inventory.trustlevel.TrustLevelManager; 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 @@ -79,11 +78,7 @@ public class CmHandleRegistrationService { private final CpsDataService cpsDataService; private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler; private final IMap<String, Object> moduleSyncStartedOnCmHandles; - - @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN) - private final Map<String, TrustLevel> trustLevelPerDmiPlugin; private final TrustLevelManager trustLevelManager; - private final AlternateIdChecker alternateIdChecker; /** @@ -98,7 +93,7 @@ public class CmHandleRegistrationService { dmiPluginRegistration.validateDmiPluginRegistration(); final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse(); - setTrustLevelPerDmiPlugin(dmiPluginRegistration); + trustLevelManager.registerDmiPlugin(dmiPluginRegistration); processRemovedCmHandles(dmiPluginRegistration, dmiPluginRegistrationResponse); @@ -153,7 +148,7 @@ public class CmHandleRegistrationService { final Set<String> notDeletedCmHandles = new HashSet<>(); for (final List<String> tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandleIds, DELETE_BATCH_SIZE)) { try { - batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch); + batchDeleteCmHandlesFromDbAndCaches(tobeRemovedCmHandleBatch); tobeRemovedCmHandleBatch.forEach(cmHandleId -> cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId))); @@ -259,7 +254,7 @@ public class CmHandleRegistrationService { ncmpServiceCmHandle.getRegistrationTrustLevel()); } } - trustLevelManager.handleInitialRegistrationOfTrustLevels(initialTrustLevelPerCmHandleId); + trustLevelManager.registerCmHandles(initialTrustLevelPerCmHandleId); } private static boolean moduleUpgradeCanBeSkipped(final YangModelCmHandle yangModelCmHandle, @@ -280,7 +275,7 @@ public class CmHandleRegistrationService { private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) { try { - deleteCmHandleFromDbAndModuleSyncMap(cmHandleId); + deleteCmHandleFromDbAndCaches(cmHandleId); return CmHandleRegistrationResponse.createSuccessResponse(cmHandleId); } catch (final DataNodeNotFoundException dataNodeNotFoundException) { log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", @@ -303,15 +298,17 @@ public class CmHandleRegistrationService { lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); } - private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) { + private void deleteCmHandleFromDbAndCaches(final String cmHandleId) { inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId); inventoryPersistence.deleteDataNode(NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']"); + trustLevelManager.removeCmHandles(Collections.singleton(cmHandleId)); removeDeletedCmHandleFromModuleSyncMap(cmHandleId); } - private void batchDeleteCmHandlesFromDbAndModuleSyncMap(final Collection<String> cmHandleIds) { + private void batchDeleteCmHandlesFromDbAndCaches(final Collection<String> cmHandleIds) { inventoryPersistence.deleteSchemaSetsWithCascade(cmHandleIds); inventoryPersistence.deleteDataNodes(mapCmHandleIdsToXpaths(cmHandleIds)); + trustLevelManager.removeCmHandles(cmHandleIds); cmHandleIds.forEach(this::removeDeletedCmHandleFromModuleSyncMap); } @@ -345,14 +342,6 @@ public class CmHandleRegistrationService { 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<String> checkAlternateIds( final List<NcmpServiceCmHandle> cmHandlesToBeCreated, final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses) { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumer.java index 617fe7f01d..efcbb78ace 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumer.java @@ -52,7 +52,7 @@ public class DeviceTrustLevelMessageConsumer { final DeviceTrustLevel deviceTrustLevel = CloudEventMapper.toTargetEvent(consumerRecord.value(), DeviceTrustLevel.class); final String trustLevelAsString = deviceTrustLevel.getData().getTrustLevel(); - trustLevelManager.handleUpdateOfDeviceTrustLevel(cmHandleId, TrustLevel.valueOf(trustLevelAsString)); + trustLevelManager.updateCmHandleTrustLevel(cmHandleId, TrustLevel.valueOf(trustLevelAsString)); } } 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 c81e9b7840..94e493d8bf 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 @@ -67,7 +67,7 @@ public class DmiPluginTrustLevelWatchDog { } else { final Collection<String> cmHandleIds = cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiServiceName); - trustLevelManager.handleUpdateOfDmiTrustLevel(dmiServiceName, cmHandleIds, newDmiTrustLevel); + trustLevelManager.updateDmi(dmiServiceName, cmHandleIds, newDmiTrustLevel); } }); } 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 44079c0bc9..50f97a0f4d 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 @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration; import org.onap.cps.ncmp.api.inventory.models.TrustLevel; import org.onap.cps.ncmp.impl.inventory.InventoryPersistence; import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; @@ -49,11 +50,26 @@ public class TrustLevelManager { private static final String AVC_NO_OLD_VALUE = null; /** + * Add dmi plugins to the cache. + * + * @param dmiPluginRegistration a dmi plugin being registered + */ + public void registerDmiPlugin(final DmiPluginRegistration dmiPluginRegistration) { + final String dmiServiceName; + if (DmiPluginRegistration.isNullEmptyOrBlank(dmiPluginRegistration.getDmiDataPlugin())) { + dmiServiceName = dmiPluginRegistration.getDmiPlugin(); + } else { + dmiServiceName = dmiPluginRegistration.getDmiDataPlugin(); + } + trustLevelPerDmiPlugin.put(dmiServiceName, TrustLevel.COMPLETE); + } + + /** * Add cmHandles to the cache and publish notification for initial trust level of cmHandles if it is NONE. * * @param cmHandlesToBeCreated a list of cmHandles being created */ - public void handleInitialRegistrationOfTrustLevels(final Map<String, TrustLevel> cmHandlesToBeCreated) { + public void registerCmHandles(final Map<String, TrustLevel> cmHandlesToBeCreated) { for (final Map.Entry<String, TrustLevel> entry : cmHandlesToBeCreated.entrySet()) { final String cmHandleId = entry.getKey(); if (trustLevelPerCmHandle.containsKey(cmHandleId)) { @@ -82,15 +98,15 @@ public class TrustLevelManager { * @param affectedCmHandleIds cm handle ids belonging to dmi service name * @param newDmiTrustLevel new trust level of the dmi plugin */ - public void handleUpdateOfDmiTrustLevel(final String dmiServiceName, - final Collection<String> affectedCmHandleIds, - final TrustLevel newDmiTrustLevel) { + public void updateDmi(final String dmiServiceName, + final Collection<String> affectedCmHandleIds, + final TrustLevel newDmiTrustLevel) { final TrustLevel oldDmiTrustLevel = trustLevelPerDmiPlugin.get(dmiServiceName); trustLevelPerDmiPlugin.put(dmiServiceName, newDmiTrustLevel); for (final String affectedCmHandleId : affectedCmHandleIds) { - final TrustLevel deviceTrustLevel = trustLevelPerCmHandle.get(affectedCmHandleId); - final TrustLevel oldEffectiveTrustLevel = deviceTrustLevel.getEffectiveTrustLevel(oldDmiTrustLevel); - final TrustLevel newEffectiveTrustLevel = deviceTrustLevel.getEffectiveTrustLevel(newDmiTrustLevel); + final TrustLevel cmHandleTrustLevel = trustLevelPerCmHandle.get(affectedCmHandleId); + final TrustLevel oldEffectiveTrustLevel = cmHandleTrustLevel.getEffectiveTrustLevel(oldDmiTrustLevel); + final TrustLevel newEffectiveTrustLevel = cmHandleTrustLevel.getEffectiveTrustLevel(newDmiTrustLevel); sendAvcNotificationIfRequired(affectedCmHandleId, oldEffectiveTrustLevel, newEffectiveTrustLevel); } } @@ -100,23 +116,57 @@ public class TrustLevelManager { * changed. * * @param cmHandleId cm handle id - * @param newDeviceTrustLevel new trust level of the device + * @param newCmHandleTrustLevel new trust level of the device */ - public void handleUpdateOfDeviceTrustLevel(final String cmHandleId, - final TrustLevel newDeviceTrustLevel) { - final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); - final String dmiServiceName = yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA); + public void updateCmHandleTrustLevel(final String cmHandleId, + final TrustLevel newCmHandleTrustLevel) { + final String dmiServiceName = getDmiServiceName(cmHandleId); final TrustLevel dmiTrustLevel = trustLevelPerDmiPlugin.get(dmiServiceName); - final TrustLevel oldDeviceTrustLevel = trustLevelPerCmHandle.get(cmHandleId); + final TrustLevel oldCmHandleTrustLevel = trustLevelPerCmHandle.get(cmHandleId); - final TrustLevel oldEffectiveTrustLevel = oldDeviceTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); - final TrustLevel newEffectiveTrustLevel = newDeviceTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); + final TrustLevel oldEffectiveTrustLevel = oldCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); + final TrustLevel newEffectiveTrustLevel = newCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); - trustLevelPerCmHandle.put(cmHandleId, newDeviceTrustLevel); + trustLevelPerCmHandle.put(cmHandleId, newCmHandleTrustLevel); sendAvcNotificationIfRequired(cmHandleId, oldEffectiveTrustLevel, newEffectiveTrustLevel); } + /** + * Select effective trust level among device and dmi plugin. + * + * @param cmHandleId cm handle id + * @return TrustLevel effective trust level + */ + public TrustLevel getEffectiveTrustLevel(final String cmHandleId) { + final String dmiServiceName = getDmiServiceName(cmHandleId); + final TrustLevel dmiTrustLevel = trustLevelPerDmiPlugin.get(dmiServiceName); + final TrustLevel cmHandleTrustLevel = trustLevelPerCmHandle.get(cmHandleId); + return dmiTrustLevel.getEffectiveTrustLevel(cmHandleTrustLevel); + } + + /** + * Remove cm handle trust level from the cache and publish notification for trust level of cmHandles + * if it is COMPLETE. + * + * @param cmHandleIds cm handle ids to be removed from the cache + */ + public void removeCmHandles(final Collection<String> cmHandleIds) { + for (final String cmHandleId : cmHandleIds) { + if (trustLevelPerCmHandle.containsKey(cmHandleId)) { + final TrustLevel oldTrustLevel = trustLevelPerCmHandle.remove(cmHandleId); + sendAvcNotificationIfRequired(cmHandleId, oldTrustLevel, TrustLevel.NONE); + } else { + log.debug("Removed Cm handle: {} is not in trust level cache", cmHandleId); + } + } + } + + private String getDmiServiceName(final String cmHandleId) { + final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); + return yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA); + } + private void sendAvcNotificationIfRequired(final String notificationCandidateCmHandleId, final TrustLevel oldEffectiveTrustLevel, final TrustLevel newEffectiveTrustLevel) { |