diff options
Diffstat (limited to 'cps-ncmp-service/src/main/java')
6 files changed, 62 insertions, 42 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java index f8836e6bf..1674c52fc 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java @@ -21,6 +21,7 @@ package org.onap.cps.ncmp.api.impl; import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle; +import static org.onap.cps.spi.FetchDescendantsOption.FETCH_DIRECT_CHILDREN_ONLY; import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS; import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties; import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateModuleNameConditionProperties; @@ -68,14 +69,14 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm */ @Override public Set<NcmpServiceCmHandle> queryCmHandles( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) { return getAllCmHandles(); } final Map<String, NcmpServiceCmHandle> combinedQueryResult = executeInventoryQueries( - cmHandleQueryServiceParameters); + cmHandleQueryServiceParameters); return new HashSet<>(combineWithModuleNameQuery(cmHandleQueryServiceParameters, combinedQueryResult).values()); } @@ -88,17 +89,17 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm */ @Override public Set<String> queryCmHandleIds( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) { return getAllCmHandleIds(); } final Map<String, NcmpServiceCmHandle> combinedQueryResult = executeInventoryQueries( - cmHandleQueryServiceParameters); + cmHandleQueryServiceParameters); final Collection<String> moduleNamesForQuery = - getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); + getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); if (moduleNamesForQuery.isEmpty()) { return combinedQueryResult.keySet(); } @@ -113,10 +114,10 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm } private Map<String, NcmpServiceCmHandle> combineWithModuleNameQuery( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, - final Map<String, NcmpServiceCmHandle> previousQueryResult) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, + final Map<String, NcmpServiceCmHandle> previousQueryResult) { final Collection<String> moduleNamesForQuery = - getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); + getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); if (moduleNamesForQuery.isEmpty()) { return previousQueryResult; } @@ -138,7 +139,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm } private Map<String, NcmpServiceCmHandle> executeInventoryQueries( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { final Map<String, String> cpsPath = getCpsPath(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); if (!validateCpsPathConditionProperties(cpsPath)) { return Collections.emptyMap(); @@ -149,13 +150,13 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm } else { try { cpsPathQueryResult = cmHandleQueries.queryCmHandleDataNodesByCpsPath( - cpsPath.get("cpsPath"), INCLUDE_ALL_DESCENDANTS) - .stream().map(this::createNcmpServiceCmHandle) - .collect(Collectors.toMap(NcmpServiceCmHandle::getCmHandleId, - Function.identity())); + cpsPath.get("cpsPath"), INCLUDE_ALL_DESCENDANTS) + .stream().map(this::createNcmpServiceCmHandle) + .collect(Collectors.toMap(NcmpServiceCmHandle::getCmHandleId, + Function.identity())); } catch (final PathParsingException pathParsingException) { throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(), - pathParsingException); + pathParsingException); } if (cpsPathQueryResult.isEmpty()) { return Collections.emptyMap(); @@ -163,9 +164,9 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm } final Map<String, String> publicPropertyQueryPairs = - getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); + getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); final Map<String, NcmpServiceCmHandle> propertiesQueryResult = publicPropertyQueryPairs.isEmpty() - ? NO_QUERY_TO_EXECUTE : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs); + ? NO_QUERY_TO_EXECUTE : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs); return cmHandleQueries.combineCmHandleQueries(cpsPathQueryResult, propertiesQueryResult); } @@ -190,14 +191,14 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm private Map<String, String> getCpsPath(final List<ConditionProperties> conditionProperties) { final Map<String, String> result = new HashMap<>(); getConditions(conditionProperties, ValidQueryProperties.WITH_CPS_PATH.getQueryProperty()).forEach( - result::putAll); + result::putAll); return result; } private Map<String, String> getPublicPropertyPairs(final List<ConditionProperties> conditionProperties) { final Map<String, String> result = new HashMap<>(); getConditions(conditionProperties, - ValidQueryProperties.HAS_ALL_PROPERTIES.getQueryProperty()).forEach(result::putAll); + ValidQueryProperties.HAS_ALL_PROPERTIES.getQueryProperty()).forEach(result::putAll); return result; } @@ -213,17 +214,17 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm private Set<NcmpServiceCmHandle> getAllCmHandles() { return inventoryPersistence.getDataNode("/dmi-registry") - .getChildDataNodes().stream().map(this::createNcmpServiceCmHandle).collect(Collectors.toSet()); + .getChildDataNodes().stream().map(this::createNcmpServiceCmHandle).collect(Collectors.toSet()); } private Set<String> getAllCmHandleIds() { - return inventoryPersistence.getDataNode("/dmi-registry") - .getChildDataNodes().stream().map(dataNode -> dataNode.getLeaves().get("id").toString()) - .collect(Collectors.toSet()); + return inventoryPersistence.getDataNode("/dmi-registry", FETCH_DIRECT_CHILDREN_ONLY) + .getChildDataNodes().stream().map(dataNode -> dataNode.getLeaves().get("id").toString()) + .collect(Collectors.toSet()); } private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) { return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter - .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString())); + .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString())); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfig.java index c89388b29..5154be799 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfig.java @@ -28,7 +28,6 @@ import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.map.IMap; import java.util.concurrent.BlockingQueue; -import java.util.concurrent.TimeUnit; import org.onap.cps.spi.model.DataNode; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -39,11 +38,12 @@ import org.springframework.context.annotation.Configuration; @Configuration public class SynchronizationCacheConfig { + public static final int MODULE_SYNC_STARTED_TTL_SECS = 60; + public static final int DATA_SYNC_SEMAPHORE_TTL_SECS = 1800; + private static final QueueConfig commonQueueConfig = createQueueConfig(); - private static final MapConfig moduleSyncStartedConfig = - createMapConfig("moduleSyncStartedConfig", TimeUnit.MINUTES.toSeconds(1)); - private static final MapConfig dataSyncSemaphoresConfig = - createMapConfig("dataSyncSemaphoresConfig", TimeUnit.MINUTES.toSeconds(30)); + private static final MapConfig moduleSyncStartedConfig = createMapConfig("moduleSyncStartedConfig"); + private static final MapConfig dataSyncSemaphoresConfig = createMapConfig("dataSyncSemaphoresConfig"); /** * Module Sync Distributed Queue Instance. @@ -102,11 +102,10 @@ public class SynchronizationCacheConfig { return commonQueueConfig; } - private static MapConfig createMapConfig(final String configName, final long timeToLiveSeconds) { + private static MapConfig createMapConfig(final String configName) { final MapConfig mapConfig = new MapConfig(configName); mapConfig.setBackupCount(3); mapConfig.setAsyncBackupCount(3); - mapConfig.setTimeToLiveSeconds((int) timeToLiveSeconds); return mapConfig; } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java index bfc3a9ac0..b29825e7c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java @@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api.inventory; import java.util.Collection; import java.util.Map; import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; +import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.Anchor; import org.onap.cps.spi.model.DataNode; import org.onap.cps.spi.model.ModuleDefinition; @@ -114,6 +115,15 @@ public interface InventoryPersistence { DataNode getDataNode(String xpath); /** + * Get data node via xpath. + * + * @param xpath xpath + * @param fetchDescendantsOption fetch descendants option + * @return data node + */ + DataNode getDataNode(String xpath, FetchDescendantsOption fetchDescendantsOption); + + /** * Get data node of given cm handle. * * @param cmHandleId cmHandle ID diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java index 99edfdb0f..eed47edda 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java @@ -76,18 +76,18 @@ public class InventoryPersistenceImpl implements InventoryPersistence { @Override public CompositeState getCmHandleState(final String cmHandleId) { final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId) + "/state", - FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); + String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId) + "/state", + FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build(); } @Override public void saveCmHandleState(final String cmHandleId, final CompositeState compositeState) { final String cmHandleJsonData = String.format("{\"state\":%s}", - jsonObjectMapper.asJsonString(compositeState)); + jsonObjectMapper.asJsonString(compositeState)); cpsDataService.updateDataNodeAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId), - cmHandleJsonData, OffsetDateTime.now()); + String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId), + cmHandleJsonData, OffsetDateTime.now()); } @Override @@ -153,8 +153,13 @@ public class InventoryPersistenceImpl implements InventoryPersistence { @Override public DataNode getDataNode(final String xpath) { + return getDataNode(xpath, INCLUDE_ALL_DESCENDANTS); + } + + @Override + public DataNode getDataNode(final String xpath, final FetchDescendantsOption fetchDescendantsOption) { return cpsDataPersistenceService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - xpath, INCLUDE_ALL_DESCENDANTS); + xpath, fetchDescendantsOption); } @Override @@ -164,7 +169,7 @@ public class InventoryPersistenceImpl implements InventoryPersistence { @Override public Collection<Anchor> queryAnchors(final Collection<String> moduleNamesForQuery) { - return cpsAdminPersistenceService.queryAnchors(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery); + return cpsAdminPersistenceService.queryAnchors(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery); } @Override diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java index 9336c3b21..9fa75a0d0 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java @@ -20,12 +20,14 @@ package org.onap.cps.ncmp.api.inventory.sync; +import com.hazelcast.map.IMap; import java.time.OffsetDateTime; -import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsDataService; +import org.onap.cps.ncmp.api.impl.config.embeddedcache.SynchronizationCacheConfig; import org.onap.cps.ncmp.api.inventory.CompositeState; import org.onap.cps.ncmp.api.inventory.DataStoreSyncState; import org.onap.cps.ncmp.api.inventory.InventoryPersistence; @@ -46,7 +48,7 @@ public class DataSyncWatchdog { private final SyncUtils syncUtils; - private final Map<String, Boolean> dataSyncSemaphores; + private final IMap<String, Boolean> dataSyncSemaphores; /** * Execute Cm Handle poll which queries the cm handle state in 'READY' and Operational Datastore Sync State in @@ -92,6 +94,7 @@ public class DataSyncWatchdog { } private boolean hasPushedIntoSemaphoreMap(final String cmHandleId) { - return dataSyncSemaphores.putIfAbsent(cmHandleId, DATA_SYNC_IN_PROGRESS) == null; + return dataSyncSemaphores.putIfAbsent(cmHandleId, DATA_SYNC_IN_PROGRESS, + SynchronizationCacheConfig.DATA_SYNC_SEMAPHORE_TTL_SECS, TimeUnit.SECONDS) == null; } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java index b96889fc5..f629b71d2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java @@ -31,6 +31,7 @@ import java.util.concurrent.atomic.AtomicInteger; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.impl.config.embeddedcache.SynchronizationCacheConfig; import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; import org.onap.cps.ncmp.api.inventory.sync.executor.AsyncTaskExecutor; import org.onap.cps.spi.model.DataNode; @@ -117,8 +118,9 @@ public class ModuleSyncWatchdog { log.debug("nextBatchCandidates size : {}", nextBatchCandidates.size()); for (final DataNode batchCandidate : nextBatchCandidates) { final String cmHandleId = String.valueOf(batchCandidate.getLeaves().get("id")); - final boolean alreadyAddedToInProgressMap = VALUE_FOR_HAZELCAST_IN_PROGRESS_MAP - .equals(moduleSyncStartedOnCmHandles.putIfAbsent(cmHandleId, VALUE_FOR_HAZELCAST_IN_PROGRESS_MAP)); + 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)); if (alreadyAddedToInProgressMap) { log.debug("module sync for {} already in progress by other instance", cmHandleId); } else { |