summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org/onap
diff options
context:
space:
mode:
authorJoseph Keenan <joseph.keenan@est.tech>2022-08-02 12:26:46 +0000
committerGerrit Code Review <gerrit@onap.org>2022-08-02 12:26:46 +0000
commit7a75eea4e388a04d8b67610ef53ed16db75489e6 (patch)
tree75664b32b00cb5df106ec58a15e4c3e0f337b8a3 /cps-ncmp-service/src/main/java/org/onap
parentb3c2b74c5a90750978a051cc9c8a6933f77e7948 (diff)
parent82a550f6b080cb50912d93f7b13ba0fc97a95470 (diff)
Merge "Query CmHandles using CPS path"
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java144
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java165
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java65
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java25
5 files changed, 256 insertions, 147 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 a62a009ce7..d784bcdeac 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,8 @@
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.INCLUDE_ALL_DESCENDANTS;
+import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties;
import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateModuleNameConditionProperties;
import java.util.ArrayList;
@@ -31,17 +33,22 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.cpspath.parser.PathParsingException;
import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
+import org.onap.cps.ncmp.api.inventory.CmHandleQueries;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
import org.onap.cps.spi.model.ConditionProperties;
import org.onap.cps.spi.model.DataNode;
+import org.onap.cps.utils.ValidQueryProperties;
import org.springframework.stereotype.Service;
@Service
@@ -49,9 +56,8 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCmHandlerQueryService {
- private static final String PROPERTY_QUERY_NAME = "hasAllProperties";
- private static final String MODULE_QUERY_NAME = "hasAllModules";
- private static final Map<String, NcmpServiceCmHandle> NO_QUERY_EXECUTED = null;
+ private static final Map<String, NcmpServiceCmHandle> NO_QUERY_TO_EXECUTE = null;
+ private final CmHandleQueries cmHandleQueries;
private final InventoryPersistence inventoryPersistence;
/**
@@ -68,14 +74,10 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
return getAllCmHandles();
}
- final Map<String, NcmpServiceCmHandle> publicPropertyQueryResult
- = executePublicPropertyQueries(cmHandleQueryServiceParameters);
+ final Map<String, NcmpServiceCmHandle> combinedQueryResult = executeInventoryQueries(
+ cmHandleQueryServiceParameters);
- final Map<String, NcmpServiceCmHandle> combinedQueryResult =
- combineWithModuleNameQuery(cmHandleQueryServiceParameters, publicPropertyQueryResult);
-
- return combinedQueryResult == NO_QUERY_EXECUTED
- ? Collections.emptySet() : new HashSet<>(combinedQueryResult.values());
+ return new HashSet<>(combineWithModuleNameQuery(cmHandleQueryServiceParameters, combinedQueryResult).values());
}
/**
@@ -92,52 +94,24 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
return getAllCmHandleIds();
}
- final Map<String, NcmpServiceCmHandle> publicPropertyQueryResult
- = executePublicPropertyQueries(cmHandleQueryServiceParameters);
+ final Map<String, NcmpServiceCmHandle> combinedQueryResult = executeInventoryQueries(
+ cmHandleQueryServiceParameters);
final Collection<String> moduleNamesForQuery =
getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
if (moduleNamesForQuery.isEmpty()) {
- return publicPropertyQueryResult == NO_QUERY_EXECUTED
- ? Collections.emptySet() : publicPropertyQueryResult.keySet();
+ return combinedQueryResult.keySet();
}
final Set<String> moduleNameQueryResult = getNamesOfAnchorsWithGivenModules(moduleNamesForQuery);
- if (publicPropertyQueryResult == NO_QUERY_EXECUTED) {
+ if (combinedQueryResult == NO_QUERY_TO_EXECUTE) {
return moduleNameQueryResult;
}
- moduleNameQueryResult.retainAll(publicPropertyQueryResult.keySet());
+ moduleNameQueryResult.retainAll(combinedQueryResult.keySet());
return moduleNameQueryResult;
}
- private Map<String, NcmpServiceCmHandle> executePublicPropertyQueries(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
- final Map<String, String> publicPropertyQueryPairs =
- getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
- if (publicPropertyQueryPairs.isEmpty()) {
- return NO_QUERY_EXECUTED;
- }
- Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandles = null;
- for (final Map.Entry<String, String> entry : publicPropertyQueryPairs.entrySet()) {
- final String cpsPath = "//public-properties[@name='" + entry.getKey() + "' and @value='"
- + entry.getValue() + "']/ancestor::cm-handles";
-
- final Collection<DataNode> dataNodes = inventoryPersistence.queryDataNodes(cpsPath);
- if (cmHandleIdToNcmpServiceCmHandles == NO_QUERY_EXECUTED) {
- cmHandleIdToNcmpServiceCmHandles = collectDataNodesToNcmpServiceCmHandles(dataNodes);
- } else {
- final Collection<String> cmHandleIdsToRetain = dataNodes.parallelStream()
- .map(dataNode -> dataNode.getLeaves().get("id").toString()).collect(Collectors.toSet());
- cmHandleIdToNcmpServiceCmHandles.keySet().retainAll(cmHandleIdsToRetain);
- }
- if (cmHandleIdToNcmpServiceCmHandles.isEmpty()) {
- break;
- }
- }
- return cmHandleIdToNcmpServiceCmHandles;
- }
-
private Map<String, NcmpServiceCmHandle> combineWithModuleNameQuery(
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
final Map<String, NcmpServiceCmHandle> previousQueryResult) {
@@ -151,7 +125,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
return Collections.emptyMap();
}
final Map<String, NcmpServiceCmHandle> queryResult = new HashMap<>(cmHandleIdsByModuleName.size());
- if (previousQueryResult == NO_QUERY_EXECUTED) {
+ if (previousQueryResult == NO_QUERY_TO_EXECUTE) {
cmHandleIdsByModuleName.forEach(cmHandleId ->
queryResult.put(cmHandleId, createNcmpServiceCmHandle(
inventoryPersistence.getDataNode("/dmi-registry/cm-handles[@id='" + cmHandleId + "']")))
@@ -163,19 +137,68 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
return queryResult;
}
+ private Map<String, NcmpServiceCmHandle> executeInventoryQueries(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final Map<String, String> cpsPath = getCpsPath(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+ if (!validateCpsPathConditionProperties(cpsPath)) {
+ return Collections.emptyMap();
+ }
+ final Map<String, NcmpServiceCmHandle> cpsPathQueryResult;
+ if (cpsPath.isEmpty()) {
+ cpsPathQueryResult = NO_QUERY_TO_EXECUTE;
+ } else {
+ try {
+ cpsPathQueryResult = cmHandleQueries.getCmHandleDataNodesByCpsPath(
+ 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);
+ }
+ if (cpsPathQueryResult.isEmpty()) {
+ return Collections.emptyMap();
+ }
+ }
+
+ final Map<String, String> publicPropertyQueryPairs =
+ getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+ final Map<String, NcmpServiceCmHandle> propertiesQueryResult = publicPropertyQueryPairs.isEmpty()
+ ? NO_QUERY_TO_EXECUTE : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs);
+
+ return cmHandleQueries.combineCmHandleQueries(cpsPathQueryResult, propertiesQueryResult);
+ }
+
private Set<String> getNamesOfAnchorsWithGivenModules(final Collection<String> moduleNamesForQuery) {
final Collection<Anchor> anchors = inventoryPersistence.queryAnchors(moduleNamesForQuery);
return anchors.parallelStream().map(Anchor::getName).collect(Collectors.toSet());
}
- private Map<String, NcmpServiceCmHandle> collectDataNodesToNcmpServiceCmHandles(
- final Collection<DataNode> dataNodes) {
- final Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandle = new HashMap<>();
- dataNodes.forEach(dataNode -> {
- final NcmpServiceCmHandle ncmpServiceCmHandle = createNcmpServiceCmHandle(dataNode);
- cmHandleIdToNcmpServiceCmHandle.put(ncmpServiceCmHandle.getCmHandleId(), ncmpServiceCmHandle);
- });
- return cmHandleIdToNcmpServiceCmHandle;
+ private Collection<String> getModuleNamesForQuery(final List<ConditionProperties> conditionProperties) {
+ final List<String> result = new ArrayList<>();
+ getConditions(conditionProperties, ValidQueryProperties.HAS_ALL_MODULES.getQueryProperty())
+ .parallelStream().forEach(
+ conditionProperty -> {
+ validateModuleNameConditionProperties(conditionProperty);
+ result.add(conditionProperty.get("moduleName"));
+ }
+ );
+ return result;
+ }
+
+ 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);
+ 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);
+ return result;
}
private List<Map<String, String>> getConditions(final List<ConditionProperties> conditionProperties,
@@ -188,23 +211,6 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
return Collections.emptyList();
}
- private Collection<String> getModuleNamesForQuery(final List<ConditionProperties> conditionProperties) {
- final List<String> result = new ArrayList<>();
- getConditions(conditionProperties, MODULE_QUERY_NAME).parallelStream().forEach(
- conditionProperty -> {
- validateModuleNameConditionProperties(conditionProperty);
- result.add(conditionProperty.get("moduleName"));
- }
- );
- return result;
- }
-
- private Map<String, String> getPublicPropertyPairs(final List<ConditionProperties> conditionProperties) {
- final Map<String, String> result = new HashMap<>();
- getConditions(conditionProperties, PROPERTY_QUERY_NAME).forEach(result::putAll);
- return result;
- }
-
private Set<NcmpServiceCmHandle> getAllCmHandles() {
return inventoryPersistence.getDataNode("/dmi-registry")
.getChildDataNodes().stream().map(this::createNcmpServiceCmHandle).collect(Collectors.toSet());
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index 8d32c1ade5..28cbf2cc24 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -271,7 +271,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle,
CmHandleState.DELETING);
- deleteSchemaSetAndListElementByCmHandleId(cmHandleId);
+ deleteCmHandleByCmHandleId(cmHandleId);
cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId));
lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle,
CmHandleState.DELETED);
@@ -295,7 +295,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return cmHandleRegistrationResponses;
}
- private void deleteSchemaSetAndListElementByCmHandleId(final String cmHandleId) {
+ private void deleteCmHandleByCmHandleId(final String cmHandleId) {
inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId);
inventoryPersistence.deleteListOrListElement("/dmi-registry/cm-handles[@id='" + cmHandleId + "']");
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java
new file mode 100644
index 0000000000..92387bab32
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java
@@ -0,0 +1,165 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.inventory;
+
+import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle;
+import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import lombok.RequiredArgsConstructor;
+import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.spi.CpsDataPersistenceService;
+import org.onap.cps.spi.FetchDescendantsOption;
+import org.onap.cps.spi.model.DataNode;
+import org.springframework.stereotype.Component;
+
+@RequiredArgsConstructor
+@Component
+public class CmHandleQueries {
+
+ private static final String NCMP_DATASPACE_NAME = "NCMP-Admin";
+ private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
+
+ private final CpsDataPersistenceService cpsDataPersistenceService;
+ private static final Map<String, NcmpServiceCmHandle> NO_QUERY_TO_EXECUTE = null;
+ private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
+
+
+ /**
+ * Query CmHandles based on PublicProperties.
+ *
+ * @param publicPropertyQueryPairs public properties for query
+ * @return CmHandles which have these public properties
+ */
+ public Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(
+ final Map<String, String> publicPropertyQueryPairs) {
+ if (publicPropertyQueryPairs.isEmpty()) {
+ return Collections.emptyMap();
+ }
+ Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandles = null;
+ for (final Map.Entry<String, String> publicPropertyQueryPair : publicPropertyQueryPairs.entrySet()) {
+ final String cpsPath = "//public-properties[@name=\"" + publicPropertyQueryPair.getKey()
+ + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
+
+ final Collection<DataNode> dataNodes = getCmHandleDataNodesByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS);
+ if (cmHandleIdToNcmpServiceCmHandles == null) {
+ cmHandleIdToNcmpServiceCmHandles = collectDataNodesToNcmpServiceCmHandles(dataNodes);
+ } else {
+ final Collection<String> cmHandleIdsToRetain = dataNodes.parallelStream()
+ .map(dataNode -> dataNode.getLeaves().get("id").toString()).collect(Collectors.toSet());
+ cmHandleIdToNcmpServiceCmHandles.keySet().retainAll(cmHandleIdsToRetain);
+ }
+ if (cmHandleIdToNcmpServiceCmHandles.isEmpty()) {
+ break;
+ }
+ }
+ return cmHandleIdToNcmpServiceCmHandles;
+ }
+
+ /**
+ * Combine Maps of CmHandles.
+ *
+ * @param firstQuery first CmHandles Map
+ * @param secondQuery second CmHandles Map
+ * @return combined Map of CmHandles
+ */
+ public Map<String, NcmpServiceCmHandle> combineCmHandleQueries(
+ final Map<String, NcmpServiceCmHandle> firstQuery,
+ final Map<String, NcmpServiceCmHandle> secondQuery) {
+ if (firstQuery == NO_QUERY_TO_EXECUTE && secondQuery == NO_QUERY_TO_EXECUTE) {
+ return Collections.emptyMap();
+ } else if (firstQuery == NO_QUERY_TO_EXECUTE) {
+ return secondQuery;
+ } else if (secondQuery == NO_QUERY_TO_EXECUTE) {
+ return firstQuery;
+ } else {
+ firstQuery.keySet().retainAll(secondQuery.keySet());
+ return firstQuery;
+ }
+ }
+
+ /**
+ * Method which returns cm handles by the cm handles state.
+ *
+ * @param cmHandleState cm handle state
+ * @return a list of cm handles
+ */
+ public List<DataNode> getCmHandlesByState(final CmHandleState cmHandleState) {
+ return getCmHandleDataNodesByCpsPath("//state[@cm-handle-state=\"" + cmHandleState + "\"]",
+ INCLUDE_ALL_DESCENDANTS);
+ }
+
+ /**
+ * Method to return data nodes representing the cm handles.
+ *
+ * @param cpsPath cps path for which the cmHandle is requested
+ * @return a list of data nodes representing the cm handles.
+ */
+ public List<DataNode> getCmHandleDataNodesByCpsPath(final String cpsPath,
+ final FetchDescendantsOption fetchDescendantsOption) {
+ return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ cpsPath + ANCESTOR_CM_HANDLES, fetchDescendantsOption);
+ }
+
+ /**
+ * Method which returns cm handles by the cm handle id and state.
+ * @param cmHandleId cm handle id
+ * @param cmHandleState cm handle state
+ * @return a list of cm handles
+ */
+ public List<DataNode> getCmHandlesByIdAndState(final String cmHandleId, final CmHandleState cmHandleState) {
+ return getCmHandleDataNodesByCpsPath("//cm-handles[@id='" + cmHandleId + "']/state[@cm-handle-state=\""
+ + cmHandleState + "\"]", FetchDescendantsOption.OMIT_DESCENDANTS);
+ }
+
+ /**
+ * Method which returns cm handles by the operational sync state of cm handle.
+ * @param dataStoreSyncState sync state
+ * @return a list of cm handles
+ */
+ public List<DataNode> getCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) {
+ return getCmHandleDataNodesByCpsPath("//state/datastores" + "/operational[@sync-state=\""
+ + dataStoreSyncState + "\"]", FetchDescendantsOption.OMIT_DESCENDANTS);
+ }
+
+ private Map<String, NcmpServiceCmHandle> collectDataNodesToNcmpServiceCmHandles(
+ final Collection<DataNode> dataNodes) {
+ final Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandle = new HashMap<>();
+ dataNodes.forEach(dataNode -> {
+ final NcmpServiceCmHandle ncmpServiceCmHandle = createNcmpServiceCmHandle(dataNode);
+ cmHandleIdToNcmpServiceCmHandle.put(ncmpServiceCmHandle.getCmHandleId(), ncmpServiceCmHandle);
+ });
+ return cmHandleIdToNcmpServiceCmHandle;
+ }
+
+ private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) {
+ return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter
+ .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString()));
+ }
+}
+
+
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 be26a58d58..14fc6d698a 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
@@ -28,7 +28,6 @@ import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
import java.time.OffsetDateTime;
import java.util.Collection;
-import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsDataService;
@@ -60,8 +59,6 @@ public class InventoryPersistence {
private static final String CM_HANDLE_XPATH_TEMPLATE = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
- private static final String ANCESTOR_CM_HANDLES = "\"]/ancestor::cm-handles";
-
private final JsonObjectMapper jsonObjectMapper;
private final CpsDataService cpsDataService;
@@ -100,57 +97,6 @@ public class InventoryPersistence {
}
/**
- * Method which returns cm handles by the cm handles state.
- *
- * @param cmHandleState cm handle state
- * @return a list of cm handles
- */
- public List<DataNode> getCmHandlesByState(final CmHandleState cmHandleState) {
- return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
- NCMP_DMI_REGISTRY_ANCHOR, "//state[@cm-handle-state=\""
- + cmHandleState + ANCESTOR_CM_HANDLES,
- FetchDescendantsOption.OMIT_DESCENDANTS);
- }
-
- /**
- * Method to return data nodes representing the cm handles.
- *
- * @param cpsPath cps path for which the cmHandle is requested
- * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
- * @return a list of data nodes representing the cm handles.
- */
- public List<DataNode> getCmHandleDataNodesByCpsPath(final String cpsPath,
- final FetchDescendantsOption fetchDescendantsOption) {
- return cpsDataPersistenceService.queryDataNodes(
- NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, fetchDescendantsOption);
- }
-
- /**
- * Method which returns cm handles by the cm handle id and state.
- * @param cmHandleId cm handle id
- * @param cmHandleState cm handle state
- * @return a list of cm handles
- */
- public List<DataNode> getCmHandlesByIdAndState(final String cmHandleId, final CmHandleState cmHandleState) {
- return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
- NCMP_DMI_REGISTRY_ANCHOR, "//cm-handles[@id='" + cmHandleId + "']/state[@cm-handle-state=\""
- + cmHandleState + ANCESTOR_CM_HANDLES,
- FetchDescendantsOption.OMIT_DESCENDANTS);
- }
-
- /**
- * Method which returns cm handles by the operational sync state of cm handle.
- * @param dataStoreSyncState sync state
- * @return a list of cm handles
- */
- public List<DataNode> getCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) {
- return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
- NCMP_DMI_REGISTRY_ANCHOR, "//state/datastores"
- + "/operational[@sync-state=\"" + dataStoreSyncState + ANCESTOR_CM_HANDLES,
- FetchDescendantsOption.OMIT_DESCENDANTS);
- }
-
- /**
* This method retrieves DMI service name, DMI properties and the state for a given cm handle.
* @param cmHandleId the id of the cm handle
* @return yang model cm handle
@@ -219,17 +165,6 @@ public class InventoryPersistence {
}
/**
- * Query data nodes via cps path.
- *
- * @param cpsPath cps path
- * @return List of data nodes
- */
- public List<DataNode> queryDataNodes(final String cpsPath) {
- return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cpsPath, INCLUDE_ALL_DESCENDANTS);
- }
-
- /**
* Get data node via xpath.
*
* @param xpath xpath
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
index 467fd8f608..2b7d3c99cb 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
@@ -40,6 +40,7 @@ import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
import org.onap.cps.ncmp.api.impl.operations.DmiOperations;
import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
+import org.onap.cps.ncmp.api.inventory.CmHandleQueries;
import org.onap.cps.ncmp.api.inventory.CmHandleState;
import org.onap.cps.ncmp.api.inventory.CompositeState;
import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
@@ -57,6 +58,8 @@ import org.springframework.stereotype.Service;
public class SyncUtils {
private final InventoryPersistence inventoryPersistence;
+ private final CmHandleQueries cmHandleQueries;
+
private final DmiDataOperations dmiDataOperations;
private final JsonObjectMapper jsonObjectMapper;
@@ -70,7 +73,7 @@ public class SyncUtils {
*/
public List<YangModelCmHandle> getAdvisedCmHandles() {
final List<DataNode> advisedCmHandlesAsDataNodeList = new ArrayList<>(
- inventoryPersistence.getCmHandlesByState(CmHandleState.ADVISED));
+ cmHandleQueries.getCmHandlesByState(CmHandleState.ADVISED));
log.info("Total number of fetched advised cm handle(s) is (are) {}", advisedCmHandlesAsDataNodeList.size());
if (advisedCmHandlesAsDataNodeList.isEmpty()) {
return Collections.emptyList();
@@ -87,16 +90,16 @@ public class SyncUtils {
* return null if not found
*/
public YangModelCmHandle getAnUnSynchronizedReadyCmHandle() {
- final List<DataNode> unSynchronizedCmHandles = inventoryPersistence
- .getCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED);
+ final List<DataNode> unSynchronizedCmHandles = cmHandleQueries
+ .getCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED);
if (unSynchronizedCmHandles.isEmpty()) {
return null;
}
Collections.shuffle(unSynchronizedCmHandles);
for (final DataNode cmHandle : unSynchronizedCmHandles) {
final String cmHandleId = cmHandle.getLeaves().get("id").toString();
- final List<DataNode> readyCmHandles = inventoryPersistence
- .getCmHandlesByIdAndState(cmHandleId, CmHandleState.READY);
+ final List<DataNode> readyCmHandles = cmHandleQueries
+ .getCmHandlesByIdAndState(cmHandleId, CmHandleState.READY);
if (!readyCmHandles.isEmpty()) {
return inventoryPersistence.getYangModelCmHandle(cmHandleId);
}
@@ -110,8 +113,8 @@ public class SyncUtils {
* @return a random LOCKED yang model cm handle, return null if not found
*/
public List<YangModelCmHandle> getModuleSyncFailedCmHandles() {
- final List<DataNode> lockedCmHandlesAsDataNodeList = inventoryPersistence.getCmHandleDataNodesByCpsPath(
- "//lock-reason[@reason=\"LOCKED_MODULE_SYNC_FAILED\"]/ancestor::cm-handles",
+ final List<DataNode> lockedCmHandlesAsDataNodeList = cmHandleQueries.getCmHandleDataNodesByCpsPath(
+ "//lock-reason[@reason=\"LOCKED_MODULE_SYNC_FAILED\"]",
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
return convertCmHandlesDataNodesToYangModelCmHandles(lockedCmHandlesAsDataNodeList);
}
@@ -171,8 +174,8 @@ public class SyncUtils {
*/
public String getResourceData(final String cmHandleId) {
final ResponseEntity<Object> resourceDataResponseEntity = dmiDataOperations.getResourceDataFromDmi(
- cmHandleId, DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL,
- UUID.randomUUID().toString());
+ cmHandleId, DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL,
+ UUID.randomUUID().toString());
if (resourceDataResponseEntity.getStatusCode().is2xxSuccessful()) {
return getFirstResource(resourceDataResponseEntity.getBody());
}
@@ -188,8 +191,8 @@ public class SyncUtils {
}
private List<YangModelCmHandle> convertCmHandlesDataNodesToYangModelCmHandles(
- final List<DataNode> cmHandlesAsDataNodeList) {
+ final List<DataNode> cmHandlesAsDataNodeList) {
return cmHandlesAsDataNodeList.stream().map(dataNode -> YangDataConverter.convertCmHandleToYangModel(dataNode,
- dataNode.getLeaves().get("id").toString())).collect(Collectors.toList());
+ dataNode.getLeaves().get("id").toString())).collect(Collectors.toList());
}
}