summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/main/java/org')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java14
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java9
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java196
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java27
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java9
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/DataStoreSyncState.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/SyncState.java)2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java41
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java19
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java39
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java4
11 files changed, 239 insertions, 123 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java
index 92b1e82c3e..faf58b95bf 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java
@@ -20,9 +20,9 @@
package org.onap.cps.ncmp.api;
-import java.util.Collection;
+import java.util.Set;
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
-import org.onap.cps.spi.model.DataNode;
public interface NetworkCmProxyCmHandlerQueryService {
/**
@@ -31,5 +31,13 @@ public interface NetworkCmProxyCmHandlerQueryService {
* @param cmHandleQueryServiceParameters the cm handle query parameters
* @return collection of cm handles
*/
- Collection<DataNode> queryCmHandles(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+ Set<NcmpServiceCmHandle> queryCmHandles(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+
+ /**
+ * Query and return cm handles that match the given query parameters.
+ *
+ * @param cmHandleQueryServiceParameters the cm handle query parameters
+ * @return collection of cm handle ids
+ */
+ Set<String> queryCmHandleIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
index 1ad61e6a6d..ea27d4a1e9 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
@@ -33,6 +33,7 @@ import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
/*
@@ -107,6 +108,14 @@ public interface NetworkCmProxyDataService {
Collection<ModuleReference> getYangResourcesModuleReferences(String cmHandleId);
/**
+ * Retrieve module definitions for the given cm handle.
+ *
+ * @param cmHandleId cm handle identifier
+ * @return a collection of module definition (moduleName, revision and yang resource content)
+ */
+ Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(String cmHandleId);
+
+ /**
* Query cm handle details by cm handle's name.
*
* @param cmHandleId cm handle identifier
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 3deaa7d237..d64dfb4a63 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
@@ -22,6 +22,7 @@ package org.onap.cps.ncmp.api.impl;
import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DATASPACE_NAME;
import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DMI_REGISTRY_ANCHOR;
+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.validateModuleNameConditionProperties;
@@ -29,20 +30,22 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
+import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.CpsDataPersistenceService;
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.spi.model.DataNodeIdentifier;
-import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.stereotype.Service;
@Service
@@ -52,9 +55,9 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
private static final String PROPERTY_QUERY_NAME = "hasAllProperties";
private static final String MODULE_QUERY_NAME = "hasAllModules";
+ private static final Object NO_QUERY_EXECUTED = null;
private final CpsDataPersistenceService cpsDataPersistenceService;
private final CpsAdminPersistenceService cpsAdminPersistenceService;
- private final JsonObjectMapper jsonObjectMapper;
/**
* Query and return cm handles that match the given query parameters.
@@ -63,86 +66,124 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
* @return collection of cm handles
*/
@Override
- public Collection<DataNode> queryCmHandles(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ public Set<NcmpServiceCmHandle> queryCmHandles(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
return getAllCmHandles();
}
- final Collection<DataNodeIdentifier> amalgamatedQueryResultIdentifiers = new ArrayList<>();
- final Map<DataNodeIdentifier, DataNode> amalgamatedQueryResults = new HashMap<>();
+ final Map<String, NcmpServiceCmHandle> publicPropertyQueryResult
+ = executePublicPropertyQueries(cmHandleQueryServiceParameters);
- final boolean firstQuery = moduleNameQuery(cmHandleQueryServiceParameters,
- amalgamatedQueryResultIdentifiers, amalgamatedQueryResults);
+ final Map<String, NcmpServiceCmHandle> combinedQueryResult =
+ combineWithModuleNameQuery(cmHandleQueryServiceParameters, publicPropertyQueryResult);
- publicPropertyQuery(cmHandleQueryServiceParameters, amalgamatedQueryResultIdentifiers,
- amalgamatedQueryResults, firstQuery);
+ return combinedQueryResult == NO_QUERY_EXECUTED
+ ? Collections.emptySet() : new HashSet<NcmpServiceCmHandle>(combinedQueryResult.values());
+ }
- final Collection<DataNode> filteredDataNodes = new ArrayList<>();
- amalgamatedQueryResultIdentifiers.forEach(amalgamatedQueryResultIdentifier ->
- filteredDataNodes.add(amalgamatedQueryResults.get(amalgamatedQueryResultIdentifier))
- );
+ /**
+ * Query and return cm handles that match the given query parameters.
+ *
+ * @param cmHandleQueryServiceParameters the cm handle query parameters
+ * @return collection of cm handle ids
+ */
+ @Override
+ public Set<String> queryCmHandleIds(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+
+ if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
+ return getAllCmHandleIds();
+ }
+
+ final Map<String, NcmpServiceCmHandle> publicPropertyQueryResult
+ = executePublicPropertyQueries(cmHandleQueryServiceParameters);
+
+ final Collection<String> moduleNamesForQuery =
+ getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+ if (moduleNamesForQuery.isEmpty()) {
+ return publicPropertyQueryResult == NO_QUERY_EXECUTED
+ ? Collections.emptySet() : publicPropertyQueryResult.keySet();
+ }
+ final Set<String> moduleNameQueryResult = getNamesOfAnchorsWithGivenModules(moduleNamesForQuery);
+
+ if (publicPropertyQueryResult == NO_QUERY_EXECUTED) {
+ return moduleNameQueryResult;
+ }
- return filteredDataNodes;
+ moduleNameQueryResult.retainAll(publicPropertyQueryResult.keySet());
+ return moduleNameQueryResult;
}
- private void publicPropertyQuery(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
- final Collection<DataNodeIdentifier> amalgamatedQueryResultIdentifiers,
- final Map<DataNodeIdentifier, DataNode> amalgamatedQueryResults,
- boolean firstQuery) {
- for (final Map.Entry<String, String> entry :
- getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters()).entrySet()) {
- final String cmHandlePath = "//public-properties[@name='" + entry.getKey() + "' " + "and @value='"
- + entry.getValue() + "']" + "/ancestor::cm-handles";
-
- final Collection<DataNode> dataNodes = getDataNodes(cmHandlePath);
-
- if (firstQuery) {
- firstQuery = false;
- dataNodes.forEach(dataNode -> {
- final DataNodeIdentifier dataNodeIdentifier =
- jsonObjectMapper.convertToValueType(dataNode, DataNodeIdentifier.class);
- amalgamatedQueryResultIdentifiers.add(dataNodeIdentifier);
- amalgamatedQueryResults.put(dataNodeIdentifier, dataNode);
- });
+ private Map<String, NcmpServiceCmHandle> executePublicPropertyQueries(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final Map<String, String> publicPropertyQueryPairs =
+ getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+ if (publicPropertyQueryPairs.isEmpty()) {
+ return null;
+ }
+ Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandles = null;
+ for (final Map.Entry<String, String> entry : publicPropertyQueryPairs.entrySet()) {
+ final String cmHandlePath = "//public-properties[@name='" + entry.getKey() + "' and @value='"
+ + entry.getValue() + "']/ancestor::cm-handles";
+
+ final Collection<DataNode> dataNodes = queryDataNodes(cmHandlePath);
+ if (cmHandleIdToNcmpServiceCmHandles == NO_QUERY_EXECUTED) {
+ cmHandleIdToNcmpServiceCmHandles = collectDataNodesToNcmpServiceCmHandles(dataNodes);
} else {
- final Collection<DataNodeIdentifier> singleConditionQueryDataNodeIdentifiers = new ArrayList<>();
- dataNodes.forEach(dataNode -> {
- final DataNodeIdentifier dataNodeIdentifier =
- jsonObjectMapper.convertToValueType(dataNode, DataNodeIdentifier.class);
- singleConditionQueryDataNodeIdentifiers.add(dataNodeIdentifier);
- amalgamatedQueryResults.put(dataNodeIdentifier, dataNode);
- });
- amalgamatedQueryResultIdentifiers.retainAll(singleConditionQueryDataNodeIdentifiers);
+ final Collection<String> cmHandleIdsToRetain = dataNodes.parallelStream()
+ .map(dataNode -> dataNode.getLeaves().get("id").toString()).collect(Collectors.toSet());
+ cmHandleIdToNcmpServiceCmHandles.keySet().retainAll(cmHandleIdsToRetain);
}
-
- if (amalgamatedQueryResultIdentifiers.isEmpty()) {
+ if (cmHandleIdToNcmpServiceCmHandles.isEmpty()) {
break;
}
}
+ return cmHandleIdToNcmpServiceCmHandles;
}
- private boolean moduleNameQuery(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
- final Collection<DataNodeIdentifier> amalgamatedQueryResultIdentifiers,
- final Map<DataNodeIdentifier, DataNode> amalgamatedQueryResults) {
- boolean firstQuery = true;
- if (!getModuleNames(cmHandleQueryServiceParameters.getCmHandleQueryParameters()).isEmpty()) {
- final Collection<String> anchorNames = cpsAdminPersistenceService.queryAnchors("NFP-Operational",
- getModuleNames(cmHandleQueryServiceParameters.getCmHandleQueryParameters()))
- .parallelStream().map(Anchor::getName).collect(Collectors.toList());
-
- getAllCmHandles().forEach(dataNode -> {
- if (anchorNames.contains(dataNode.getLeaves().get("id").toString())) {
- final DataNodeIdentifier dataNodeIdentifier =
- jsonObjectMapper.convertToValueType(dataNode, DataNodeIdentifier.class);
- amalgamatedQueryResultIdentifiers.add(dataNodeIdentifier);
- amalgamatedQueryResults.put(dataNodeIdentifier, dataNode);
+ private Map<String, NcmpServiceCmHandle> combineWithModuleNameQuery(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+ final Map<String, NcmpServiceCmHandle> previousQueryResult) {
+ final Collection<String> moduleNamesForQuery =
+ getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+ if (moduleNamesForQuery.isEmpty()) {
+ return previousQueryResult;
+ }
+ final Collection<String> cmHandleIdsByModuleName = getNamesOfAnchorsWithGivenModules(moduleNamesForQuery);
+ if (cmHandleIdsByModuleName.isEmpty()) {
+ return Collections.emptyMap();
+ }
+ final Map<String, NcmpServiceCmHandle> queryResult = new HashMap<>(cmHandleIdsByModuleName.size());
+ if (previousQueryResult == NO_QUERY_EXECUTED) {
+ //TODO Discuss performance/scaling of getting ALL cmHandles here
+ getAllCmHandles().forEach(ncmpServiceCmHandle -> {
+ if (cmHandleIdsByModuleName.contains(ncmpServiceCmHandle.getCmHandleId())) {
+ queryResult.put(ncmpServiceCmHandle.getCmHandleId(), ncmpServiceCmHandle);
}
});
-
- firstQuery = false;
+ return queryResult;
}
- return firstQuery;
+ previousQueryResult.keySet().retainAll(cmHandleIdsByModuleName);
+ queryResult.putAll(previousQueryResult);
+ return queryResult;
+ }
+
+ private Set<String> getNamesOfAnchorsWithGivenModules(final Collection<String> moduleNamesForQuery) {
+ final Collection<Anchor> anchors =
+ cpsAdminPersistenceService.queryAnchors("NFP-Operational", 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 List<Map<String, String>> getConditions(final List<ConditionProperties> conditionProperties,
@@ -155,13 +196,13 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
return Collections.emptyList();
}
- private List<String> getModuleNames(final List<ConditionProperties> conditionProperties) {
+ 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"));
- }
+ conditionProperty -> {
+ validateModuleNameConditionProperties(conditionProperty);
+ result.add(conditionProperty.get("moduleName"));
+ }
);
return result;
}
@@ -172,12 +213,23 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
return result;
}
- private Collection<DataNode> getAllCmHandles() {
- return getDataNodes("//public-properties/ancestor::cm-handles");
+ private Set<NcmpServiceCmHandle> getAllCmHandles() {
+ return queryDataNodes("/dmi-registry/cm-handles").stream()
+ .map(this::createNcmpServiceCmHandle).collect(Collectors.toSet());
+ }
+
+ private Set<String> getAllCmHandleIds() {
+ return cpsAdminPersistenceService.getAnchors("NFP-Operational")
+ .parallelStream().map(Anchor::getName).collect(Collectors.toSet());
+ }
+
+ private List<DataNode> queryDataNodes(final String cmHandlePath) {
+ return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ cmHandlePath, INCLUDE_ALL_DESCENDANTS);
}
- private List<DataNode> getDataNodes(final String cmHandlePath) {
- return cpsDataPersistenceService.queryDataNodes(
- NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cmHandlePath, INCLUDE_ALL_DESCENDANTS);
+ 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/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index bfc740786e..044a5a44f9 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
@@ -41,7 +41,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
@@ -53,7 +52,6 @@ import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.inventory.CmHandleState;
import org.onap.cps.ncmp.api.inventory.CompositeState;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
-import org.onap.cps.ncmp.api.inventory.sync.ModuleSyncService;
import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError;
@@ -65,6 +63,7 @@ import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.utils.CpsValidator;
import org.onap.cps.utils.JsonObjectMapper;
@@ -84,14 +83,10 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private final CpsModuleService cpsModuleService;
- private final CpsAdminService cpsAdminService;
-
private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler;
private final InventoryPersistence inventoryPersistence;
- private final ModuleSyncService moduleSyncService;
-
private final NetworkCmProxyCmHandlerQueryService networkCmProxyCmHandlerQueryService;
@Override
@@ -159,6 +154,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
}
+ @Override
+ public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
+ CpsValidator.validateNameCharacters(cmHandleId);
+ return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId);
+ }
+
/**
* Retrieve cm handles with details for the given query parameters.
*
@@ -167,16 +168,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
*/
@Override
public Set<NcmpServiceCmHandle> executeCmHandleSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
-
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
validateCmHandleQueryParameters(cmHandleQueryServiceParameters);
- return networkCmProxyCmHandlerQueryService.queryCmHandles(cmHandleQueryServiceParameters).stream()
- .map(dataNode -> YangDataConverter
- .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString()))
- .map(YangDataConverter::convertYangModelCmHandleToNcmpServiceCmHandle).collect(Collectors.toSet());
+ return networkCmProxyCmHandlerQueryService.queryCmHandles(cmHandleQueryServiceParameters);
}
/**
@@ -187,8 +184,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
*/
@Override
public Set<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
- return executeCmHandleSearch(cmHandleQueryApiParameters).stream().map(NcmpServiceCmHandle::getCmHandleId)
- .collect(Collectors.toSet());
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
+ cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
+
+ validateCmHandleQueryParameters(cmHandleQueryServiceParameters);
+
+ return networkCmProxyCmHandlerQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
}
/**
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java
index df303b5daa..e8fcaabe91 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java
@@ -94,7 +94,7 @@ public class CompositeState {
public static class Operational {
@JsonProperty("sync-state")
- private SyncState syncState;
+ private DataStoreSyncState dataStoreSyncState;
@JsonProperty("last-sync-time")
private String lastSyncTime;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java
index 91e92ea6f9..a0fc0c3a91 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java
@@ -94,13 +94,14 @@ public class CompositeStateBuilder {
/**
* To use attributes for creating {@link CompositeState}.
*
- * @param syncState for the locked state
+ * @param dataStoreSyncState for the locked state
* @param lastSyncTime for the locked state
* @return CompositeStateBuilder
*/
- public CompositeStateBuilder withOperationalDataStores(final SyncState syncState, final String lastSyncTime) {
+ public CompositeStateBuilder withOperationalDataStores(final DataStoreSyncState dataStoreSyncState,
+ final String lastSyncTime) {
this.datastores = DataStores.builder().operationalDataStore(
- Operational.builder().syncState(syncState).lastSyncTime(lastSyncTime).build()).build();
+ Operational.builder().dataStoreSyncState(dataStoreSyncState).lastSyncTime(lastSyncTime).build()).build();
return this;
}
@@ -133,7 +134,7 @@ public class CompositeStateBuilder {
private Operational getOperationalDataStore(final DataNode dataStoreNodes) {
return Operational.builder()
- .syncState(SyncState.valueOf((String) dataStoreNodes.getLeaves().get("sync-state")))
+ .dataStoreSyncState(DataStoreSyncState.valueOf((String) dataStoreNodes.getLeaves().get("sync-state")))
.lastSyncTime((String) dataStoreNodes.getLeaves().get("last-sync-time"))
.build();
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/SyncState.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/DataStoreSyncState.java
index 9c7a476183..4dbedf5f1c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/SyncState.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/DataStoreSyncState.java
@@ -20,6 +20,6 @@
package org.onap.cps.ncmp.api.inventory;
-public enum SyncState {
+public enum DataStoreSyncState {
SYNCHRONIZED, UNSYNCHRONIZED, NONE_REQUESTED
}
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 c24063cb45..d47da6c0cf 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
@@ -21,15 +21,20 @@
package org.onap.cps.ncmp.api.inventory;
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
+
import java.time.OffsetDateTime;
+import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.onap.cps.api.CpsDataService;
+import org.onap.cps.api.CpsModuleService;
import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.utils.CpsValidator;
import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.stereotype.Component;
@@ -42,15 +47,17 @@ public class InventoryPersistence {
private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
- private static final String XPATH_TO_CM_HANDLE = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
+ private String xpathCmHandle = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
+
+ private static final String ANCESTOR_CM_HANDLES = "\"]/ancestor::cm-handles";
private final JsonObjectMapper jsonObjectMapper;
private final CpsDataService cpsDataService;
- private final CpsDataPersistenceService cpsDataPersistenceService;
+ private final CpsModuleService cpsModuleService;
- private static final CompositeStateBuilder compositeStateBuilder = new CompositeStateBuilder();
+ private final CpsDataPersistenceService cpsDataPersistenceService;
/**
* Get the Cm Handle Composite State from the data node.
@@ -60,9 +67,9 @@ public class InventoryPersistence {
*/
public CompositeState getCmHandleState(final String cmHandleId) {
final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(XPATH_TO_CM_HANDLE, cmHandleId) + "/state",
+ String.format(xpathCmHandle, cmHandleId) + "/state",
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
- return compositeStateBuilder.fromDataNode(stateAsDataNode).build();
+ return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build();
}
/**
@@ -75,7 +82,7 @@ public class InventoryPersistence {
final String cmHandleJsonData = String.format("{\"state\":%s}",
jsonObjectMapper.asJsonString(compositeState));
cpsDataService.replaceNodeTree(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(XPATH_TO_CM_HANDLE, cmHandleId),
+ String.format(xpathCmHandle, cmHandleId),
cmHandleJsonData, OffsetDateTime.now());
}
@@ -88,7 +95,7 @@ public class InventoryPersistence {
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",
+ + cmHandleState + ANCESTOR_CM_HANDLES,
FetchDescendantsOption.OMIT_DESCENDANTS);
}
@@ -114,19 +121,19 @@ public class InventoryPersistence {
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",
+ + cmHandleState + ANCESTOR_CM_HANDLES,
FetchDescendantsOption.OMIT_DESCENDANTS);
}
/**
* Method which returns cm handles by the operational sync state of cm handle.
- * @param syncState sync state
+ * @param dataStoreSyncState sync state
* @return a list of cm handles
*/
- public List<DataNode> getCmHandlesByOperationalSyncState(final SyncState syncState) {
+ public List<DataNode> getCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) {
return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR, "//state/datastores"
- + "/operational[@sync-state=\"" + syncState + "\"]/ancestor::cm-handles",
+ + "/operational[@sync-state=\"" + dataStoreSyncState + ANCESTOR_CM_HANDLES,
FetchDescendantsOption.OMIT_DESCENDANTS);
}
@@ -140,10 +147,20 @@ public class InventoryPersistence {
return YangDataConverter.convertCmHandleToYangModel(getCmHandleDataNode(cmHandleId), cmHandleId);
}
+ /**
+ * Method to return module definitions by cmHandleId.
+ *
+ * @param cmHandleId cm handle ID
+ * @return a collection of module definitions (moduleName, revision and yang resource content)
+ */
+ public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
+ return cpsModuleService.getModuleDefinitionsByAnchorName(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
+ }
+
private DataNode getCmHandleDataNode(final String cmHandle) {
return cpsDataService.getDataNode(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR,
- String.format(XPATH_TO_CM_HANDLE, cmHandle),
+ String.format(xpathCmHandle, cmHandle),
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
}
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 553db65dd0..adfa33ad81 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
@@ -21,13 +21,14 @@
package org.onap.cps.ncmp.api.inventory.sync;
import java.time.OffsetDateTime;
+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.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.inventory.CompositeState;
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
-import org.onap.cps.ncmp.api.inventory.SyncState;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@@ -60,15 +61,21 @@ public class DataSyncWatchdog {
} else {
cpsDataService.saveData("NFP-Operational", cmHandleId,
resourceData, OffsetDateTime.now());
+ setSyncStateToSynchronized().accept(compositeState);
+ inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
}
+ unSynchronizedReadyCmHandle = syncUtils.getAnUnSynchronizedReadyCmHandle();
+ }
+ log.debug("No Cm-Handles currently found in an READY State and Operational Sync State is UNSYNCHRONIZED");
+ }
+
+ private Consumer<CompositeState> setSyncStateToSynchronized() {
+ return compositeState -> {
compositeState.setLastUpdateTimeNow();
compositeState.getDataStores()
.setOperationalDataStore(CompositeState.Operational.builder()
- .syncState(SyncState.SYNCHRONIZED)
+ .dataStoreSyncState(DataStoreSyncState.SYNCHRONIZED)
.lastSyncTime(CompositeState.nowInSyncTimeFormat()).build());
- inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
- unSynchronizedReadyCmHandle = syncUtils.getAnUnSynchronizedReadyCmHandle();
- }
- log.debug("No Cm-Handles currently found in an READY State and Operational Sync State is UNSYNCHRONIZED");
+ };
}
}
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 9383ac1ef7..6ec44197d2 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
@@ -22,11 +22,13 @@
package org.onap.cps.ncmp.api.inventory.sync;
import java.util.List;
+import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.inventory.CmHandleState;
import org.onap.cps.ncmp.api.inventory.CompositeState;
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.inventory.LockReasonCategory;
import org.springframework.scheduling.annotation.Scheduled;
@@ -55,17 +57,14 @@ public class ModuleSyncWatchdog {
try {
moduleSyncService.deleteSchemaSetIfExists(advisedCmHandle);
moduleSyncService.syncAndCreateSchemaSetAndAnchor(advisedCmHandle);
- compositeState.setCmHandleState(CmHandleState.READY);
+ setCompositeStateToReadyWithInitialDataStoreSyncState().accept(compositeState);
} catch (final Exception e) {
- compositeState.setCmHandleState(CmHandleState.LOCKED);
+ setCompositeStateToLocked().accept(compositeState);
syncUtils.updateLockReasonDetailsAndAttempts(compositeState,
- LockReasonCategory.LOCKED_MISBEHAVING,
- e.getMessage());
+ LockReasonCategory.LOCKED_MISBEHAVING, e.getMessage());
}
- compositeState.setLastUpdateTimeNow();
inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
- log.info("{} is now in {} state", cmHandleId,
- advisedCmHandle.getCompositeState().getCmHandleState());
+ log.debug("{} is now in {} state", cmHandleId, compositeState.getCmHandleState().name());
advisedCmHandle = syncUtils.getAnAdvisedCmHandle();
}
log.debug("No Cm-Handles currently found in an ADVISED state");
@@ -88,11 +87,33 @@ public class ModuleSyncWatchdog {
}
}
+ private Consumer<CompositeState> setCompositeStateToLocked() {
+ return compositeState -> {
+ compositeState.setCmHandleState(CmHandleState.LOCKED);
+ compositeState.setLastUpdateTimeNow();
+ };
+ }
+
+ private Consumer<CompositeState> setCompositeStateToReadyWithInitialDataStoreSyncState() {
+ return compositeState -> {
+ compositeState.setCmHandleState(CmHandleState.READY);
+ final CompositeState.Operational operational = CompositeState.Operational.builder()
+ .dataStoreSyncState(DataStoreSyncState.UNSYNCHRONIZED)
+ .lastSyncTime(CompositeState.nowInSyncTimeFormat())
+ .build();
+ final CompositeState.DataStores dataStores = CompositeState.DataStores.builder()
+ .operationalDataStore(operational)
+ .build();
+ compositeState.setDataStores(dataStores);
+ };
+ }
+
private void setCompositeStateToAdvisedAndRetainOldLockReasonDetails(final CompositeState compositeState) {
compositeState.setCmHandleState(CmHandleState.ADVISED);
compositeState.setLastUpdateTimeNow();
final String oldLockReasonDetails = compositeState.getLockReason().getDetails();
- compositeState.setLockReason(CompositeState.LockReason.builder()
- .details(oldLockReasonDetails).build());
+ final CompositeState.LockReason lockReason = CompositeState.LockReason.builder()
+ .details(oldLockReasonDetails).build();
+ compositeState.setLockReason(lockReason);
}
}
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 8b7dfe6b81..0c3af6aaeb 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
@@ -43,9 +43,9 @@ 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.CmHandleState;
import org.onap.cps.ncmp.api.inventory.CompositeState;
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.inventory.LockReasonCategory;
-import org.onap.cps.ncmp.api.inventory.SyncState;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
import org.onap.cps.utils.JsonObjectMapper;
@@ -92,7 +92,7 @@ public class SyncUtils {
*/
public YangModelCmHandle getAnUnSynchronizedReadyCmHandle() {
final List<DataNode> unSynchronizedCmHandles = inventoryPersistence
- .getCmHandlesByOperationalSyncState(SyncState.UNSYNCHRONIZED);
+ .getCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED);
if (unSynchronizedCmHandles.isEmpty()) {
return null;
}