aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/main/java')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java33
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java33
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java40
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationSemaphoresConfig.java68
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/constants/DmiRegistryConstants.java6
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java139
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java3
7 files changed, 226 insertions, 96 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 000627bec..a62a009ce 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
@@ -20,10 +20,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;
import java.util.ArrayList;
@@ -39,9 +36,8 @@ 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.inventory.InventoryPersistence;
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;
@@ -56,8 +52,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
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 final CpsDataPersistenceService cpsDataPersistenceService;
- private final CpsAdminPersistenceService cpsAdminPersistenceService;
+ private final InventoryPersistence inventoryPersistence;
/**
* Query and return cm handles that match the given query parameters.
@@ -128,7 +123,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
final String cpsPath = "//public-properties[@name='" + entry.getKey() + "' and @value='"
+ entry.getValue() + "']/ancestor::cm-handles";
- final Collection<DataNode> dataNodes = queryDataNodes(cpsPath);
+ final Collection<DataNode> dataNodes = inventoryPersistence.queryDataNodes(cpsPath);
if (cmHandleIdToNcmpServiceCmHandles == NO_QUERY_EXECUTED) {
cmHandleIdToNcmpServiceCmHandles = collectDataNodesToNcmpServiceCmHandles(dataNodes);
} else {
@@ -159,7 +154,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
if (previousQueryResult == NO_QUERY_EXECUTED) {
cmHandleIdsByModuleName.forEach(cmHandleId ->
queryResult.put(cmHandleId, createNcmpServiceCmHandle(
- getDataNode("/dmi-registry/cm-handles[@id='" + cmHandleId + "']")))
+ inventoryPersistence.getDataNode("/dmi-registry/cm-handles[@id='" + cmHandleId + "']")))
);
return queryResult;
}
@@ -169,8 +164,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
}
private Set<String> getNamesOfAnchorsWithGivenModules(final Collection<String> moduleNamesForQuery) {
- final Collection<Anchor> anchors =
- cpsAdminPersistenceService.queryAnchors("NFP-Operational", moduleNamesForQuery);
+ final Collection<Anchor> anchors = inventoryPersistence.queryAnchors(moduleNamesForQuery);
return anchors.parallelStream().map(Anchor::getName).collect(Collectors.toSet());
}
@@ -212,23 +206,12 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
}
private Set<NcmpServiceCmHandle> getAllCmHandles() {
- return getDataNode("/dmi-registry").getChildDataNodes().stream()
- .map(this::createNcmpServiceCmHandle).collect(Collectors.toSet());
+ return inventoryPersistence.getDataNode("/dmi-registry")
+ .getChildDataNodes().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 cpsPath) {
- return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cpsPath, INCLUDE_ALL_DESCENDANTS);
- }
-
- private DataNode getDataNode(final String cpsPath) {
- return cpsDataPersistenceService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cpsPath, INCLUDE_ALL_DESCENDANTS);
+ return inventoryPersistence.getAnchors().parallelStream().map(Anchor::getName).collect(Collectors.toSet());
}
private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) {
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 044a5a44f..d827d465c 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
@@ -23,13 +23,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.constants.DmiRegistryConstants.NCMP_DMI_REGISTRY_PARENT;
-import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
-import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP;
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum;
-import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED;
import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters;
import java.util.ArrayList;
@@ -41,8 +35,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsDataService;
-import org.onap.cps.api.CpsModuleService;
import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
@@ -61,7 +53,6 @@ import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
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;
@@ -75,14 +66,10 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
- private final CpsDataService cpsDataService;
-
private final JsonObjectMapper jsonObjectMapper;
private final DmiDataOperations dmiDataOperations;
- private final CpsModuleService cpsModuleService;
-
private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler;
private final InventoryPersistence inventoryPersistence;
@@ -147,11 +134,10 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
requestData, dataType);
}
-
@Override
public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
CpsValidator.validateNameCharacters(cmHandleId);
- return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
+ return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId);
}
@Override
@@ -279,9 +265,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
for (final String cmHandle : tobeRemovedCmHandles) {
try {
CpsValidator.validateNameCharacters(cmHandle);
- deleteSchemaSetWithCascade(cmHandle);
- cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- "/dmi-registry/cm-handles[@id='" + cmHandle + "']", NO_TIMESTAMP);
+ inventoryPersistence.deleteSchemaSetWithCascade(cmHandle);
+ inventoryPersistence.deleteListOrListElement("/dmi-registry/cm-handles[@id='" + cmHandle + "']");
cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandle));
} catch (final DataNodeNotFoundException dataNodeNotFoundException) {
log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
@@ -303,21 +288,11 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return cmHandleRegistrationResponses;
}
- private void deleteSchemaSetWithCascade(final String schemaSetName) {
- try {
- cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName,
- CASCADE_DELETE_ALLOWED);
- } catch (final SchemaSetNotFoundException schemaSetNotFoundException) {
- log.warn("Schema set {} does not exist or already deleted", schemaSetName);
- }
- }
-
private CmHandleRegistrationResponse registerNewCmHandle(final YangModelCmHandle yangModelCmHandle) {
try {
final String cmHandleJsonData = String.format("{\"cm-handles\":[%s]}",
jsonObjectMapper.asJsonString(yangModelCmHandle));
- cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
- cmHandleJsonData, NO_TIMESTAMP);
+ inventoryPersistence.saveListElements(cmHandleJsonData);
return CmHandleRegistrationResponse.createSuccessResponse(yangModelCmHandle.getId());
} catch (final AlreadyDefinedException alreadyDefinedException) {
return CmHandleRegistrationResponse.createFailureResponse(
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java
index aae2f209a..d9aeaf258 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java
@@ -23,10 +23,6 @@ package org.onap.cps.ncmp.api.impl;
import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.DMI_PROPERTY;
import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.PUBLIC_PROPERTY;
-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.constants.DmiRegistryConstants.NCMP_DMI_REGISTRY_PARENT;
-import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
@@ -39,11 +35,10 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsDataService;
+import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.model.DataNode;
@@ -58,9 +53,7 @@ import org.springframework.stereotype.Service;
@SuppressWarnings("squid:S5852")
public class NetworkCmProxyDataServicePropertyHandler {
- private static final String CM_HANDLE_XPATH_TEMPLATE = NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='%s']";
-
- private final CpsDataService cpsDataService;
+ private final InventoryPersistence inventoryPersistence;
/**
* Iterates over incoming ncmpServiceCmHandles and update the dataNodes based on the updated attributes.
@@ -72,31 +65,28 @@ public class NetworkCmProxyDataServicePropertyHandler {
final Collection<NcmpServiceCmHandle> ncmpServiceCmHandles) {
final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses = new ArrayList<>();
for (final NcmpServiceCmHandle ncmpServiceCmHandle : ncmpServiceCmHandles) {
- final String cmHandle = ncmpServiceCmHandle.getCmHandleId();
+ final String cmHandleId = ncmpServiceCmHandle.getCmHandleId();
try {
- CpsValidator.validateNameCharacters(cmHandle);
- final String cmHandleXpath = String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandle);
- final DataNode existingCmHandleDataNode =
- cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cmHandleXpath,
- FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
+ CpsValidator.validateNameCharacters(cmHandleId);
+ final DataNode existingCmHandleDataNode = inventoryPersistence.getCmHandleDataNode(cmHandleId);
processUpdates(existingCmHandleDataNode, ncmpServiceCmHandle);
- cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandle));
+ cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId));
} catch (final DataNodeNotFoundException e) {
log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
- cmHandle, e.getMessage());
+ cmHandleId, e.getMessage());
cmHandleRegistrationResponses.add(CmHandleRegistrationResponse
- .createFailureResponse(cmHandle, RegistrationError.CM_HANDLE_DOES_NOT_EXIST));
+ .createFailureResponse(cmHandleId, RegistrationError.CM_HANDLE_DOES_NOT_EXIST));
} catch (final DataValidationException e) {
log.error("Unable to update cm handle : {}, caused by : {}",
- cmHandle, e.getMessage());
+ cmHandleId, e.getMessage());
cmHandleRegistrationResponses.add(
- CmHandleRegistrationResponse.createFailureResponse(cmHandle,
+ CmHandleRegistrationResponse.createFailureResponse(cmHandleId,
RegistrationError.CM_HANDLE_INVALID_ID));
} catch (final Exception exception) {
log.error("Unable to update cmHandle : {} , caused by : {}",
- cmHandle, exception.getMessage());
+ cmHandleId, exception.getMessage());
cmHandleRegistrationResponses.add(
- CmHandleRegistrationResponse.createFailureResponse(cmHandle, exception));
+ CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception));
}
}
return cmHandleRegistrationResponses;
@@ -120,8 +110,7 @@ public class NetworkCmProxyDataServicePropertyHandler {
if (replacementPropertyDataNodes.isEmpty()) {
removeAllProperties(existingCmHandleDataNode, propertyType);
} else {
- cpsDataService.replaceListContent(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- existingCmHandleDataNode.getXpath(), replacementPropertyDataNodes, NO_TIMESTAMP);
+ inventoryPersistence.replaceListContent(existingCmHandleDataNode.getXpath(), replacementPropertyDataNodes);
}
}
@@ -130,8 +119,7 @@ public class NetworkCmProxyDataServicePropertyHandler {
final Matcher matcher = propertyType.propertyXpathPattern.matcher(dataNode.getXpath());
if (matcher.find()) {
log.info("Deleting dataNode with xpath : [{}]", dataNode.getXpath());
- cpsDataService.deleteDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, dataNode.getXpath(),
- NO_TIMESTAMP);
+ inventoryPersistence.deleteDataNode(dataNode.getXpath());
}
});
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationSemaphoresConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationSemaphoresConfig.java
new file mode 100644
index 000000000..978c3d16b
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationSemaphoresConfig.java
@@ -0,0 +1,68 @@
+/*
+ * ============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.impl.config.embeddedcache;
+
+import com.hazelcast.config.Config;
+import com.hazelcast.config.MapConfig;
+import com.hazelcast.core.Hazelcast;
+import java.util.Map;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Core infrastructure of the hazelcast distributed map for Module Sync and Data Sync use cases.
+ */
+@Configuration
+public class SynchronizationSemaphoresConfig {
+
+ /**
+ * Module Sync Distributed Map Instance.
+ * @return Instance of Map
+ */
+ @Bean
+ public Map<String, String> moduleSyncSemaphore() {
+ return Hazelcast.newHazelcastInstance(
+ initializeDefaultMapConfig("moduleSyncSemaphore", "moduleSyncSemaphoreConfig"))
+ .getMap("moduleSyncSemaphore");
+ }
+
+ /**
+ * Data Sync Distributed Map Instance.
+ * @return Instance of Map
+ */
+ @Bean
+ public Map<String, String> dataSyncSemaphore() {
+ return Hazelcast.newHazelcastInstance(
+ initializeDefaultMapConfig("dataSyncSemaphore", "dataSyncSemaphoreConfig"))
+ .getMap("dataSyncSemaphore");
+ }
+
+ private Config initializeDefaultMapConfig(final String instanceName, final String configName) {
+ final Config config = new Config(instanceName);
+ final MapConfig mapConfig = new MapConfig(configName);
+ mapConfig.setTimeToLiveSeconds(30);
+ mapConfig.setBackupCount(3);
+ mapConfig.setAsyncBackupCount(3);
+ config.addMapConfig(mapConfig);
+ config.setClusterName("synchronization-semaphores");
+ return config;
+ }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/constants/DmiRegistryConstants.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/constants/DmiRegistryConstants.java
index c29c725d7..a133cfb80 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/constants/DmiRegistryConstants.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/constants/DmiRegistryConstants.java
@@ -32,11 +32,5 @@ public final class DmiRegistryConstants {
public static final String NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME = "NFP-Operational";
- public static final String NCMP_DATASPACE_NAME = "NCMP-Admin";
-
- public static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
-
- public static final String NCMP_DMI_REGISTRY_PARENT = "/dmi-registry";
-
public static final OffsetDateTime NO_TIMESTAMP = null;
}
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 d47da6c0c..af01fb439 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
@@ -22,23 +22,32 @@
package org.onap.cps.ncmp.api.inventory;
import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP;
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED;
+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;
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.CpsAdminPersistenceService;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
+import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
+import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.model.DataNode;
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;
import org.springframework.stereotype.Component;
+@Slf4j
@RequiredArgsConstructor
@Component
public class InventoryPersistence {
@@ -47,7 +56,9 @@ public class InventoryPersistence {
private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
- private String xpathCmHandle = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
+ private static final String NCMP_DMI_REGISTRY_PARENT = "/dmi-registry";
+
+ private static final String CM_HANDLE_XPATH_TEMPLATE = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
private static final String ANCESTOR_CM_HANDLES = "\"]/ancestor::cm-handles";
@@ -59,6 +70,8 @@ public class InventoryPersistence {
private final CpsDataPersistenceService cpsDataPersistenceService;
+ private final CpsAdminPersistenceService cpsAdminPersistenceService;
+
/**
* Get the Cm Handle Composite State from the data node.
*
@@ -67,7 +80,7 @@ public class InventoryPersistence {
*/
public CompositeState getCmHandleState(final String cmHandleId) {
final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(xpathCmHandle, cmHandleId) + "/state",
+ String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId) + "/state",
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build();
}
@@ -82,7 +95,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(xpathCmHandle, cmHandleId),
+ String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId),
cmHandleJsonData, OffsetDateTime.now());
}
@@ -157,11 +170,121 @@ public class InventoryPersistence {
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(xpathCmHandle, cmHandle),
- FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
+ /**
+ * Method to return module references by cmHandleId.
+ *
+ * @param cmHandleId cm handle ID
+ * @return a collection of module references (moduleName and revision)
+ */
+ public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
+ CpsValidator.validateNameCharacters(cmHandleId);
+ return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
}
+ /**
+ * Method to save list elements.
+ *
+ * @param cmHandleJsonData cmHandle JSON data
+ */
+ public void saveListElements(final String cmHandleJsonData) {
+ cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
+ cmHandleJsonData, NO_TIMESTAMP);
+ }
+
+ /**
+ * Method to delete a list or a list element.
+ *
+ * @param listElementXpath list element xPath
+ */
+ public void deleteListOrListElement(final String listElementXpath) {
+ cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ listElementXpath, NO_TIMESTAMP);
+ }
+
+ /**
+ * Method to delete a schema set.
+ *
+ * @param schemaSetName schema set name
+ */
+ public void deleteSchemaSetWithCascade(final String schemaSetName) {
+ try {
+ CpsValidator.validateNameCharacters(schemaSetName);
+ cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName,
+ CASCADE_DELETE_ALLOWED);
+ } catch (final SchemaSetNotFoundException schemaSetNotFoundException) {
+ log.warn("Schema set {} does not exist or already deleted", schemaSetName);
+ }
+ }
+
+ /**
+ * 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
+ * @return data node
+ */
+ public DataNode getDataNode(final String xpath) {
+ return cpsDataPersistenceService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ xpath, INCLUDE_ALL_DESCENDANTS);
+ }
+
+ /**
+ * Get data node of given cm handle.
+ *
+ * @param cmHandleId cmHandle ID
+ * @return data node
+ */
+ public DataNode getCmHandleDataNode(final String cmHandleId) {
+ return this.getDataNode(String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId));
+ }
+
+ /**
+ * Query anchors via module names.
+ *
+ * @param moduleNamesForQuery module names
+ * @return Collection of anchors
+ */
+ public Collection<Anchor> queryAnchors(final Collection<String> moduleNamesForQuery) {
+ return cpsAdminPersistenceService.queryAnchors(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
+ }
+
+ /**
+ * Method to get all anchors.
+ *
+ * @return Collection of anchors
+ */
+ public Collection<Anchor> getAnchors() {
+ return cpsAdminPersistenceService.getAnchors(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME);
+ }
+
+ /**
+ * Replaces list content by removing all existing elements and inserting the given new elements as data nodes.
+ *
+ * @param parentNodeXpath parent node xpath
+ * @param dataNodes datanodes representing the updated data
+ */
+ public void replaceListContent(final String parentNodeXpath, final Collection<DataNode> dataNodes) {
+ cpsDataService.replaceListContent(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ parentNodeXpath, dataNodes, NO_TIMESTAMP);
+ }
+
+ /**
+ * Deletes data node for given anchor and dataspace.
+ *
+ * @param dataNodeXpath data node xpath
+ */
+ public void deleteDataNode(final String dataNodeXpath) {
+ cpsDataService.deleteDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, dataNodeXpath,
+ NO_TIMESTAMP);
+ }
} \ No newline at end of file
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 046a116ef..2b80b9d53 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
@@ -22,7 +22,6 @@
package org.onap.cps.ncmp.api.inventory.sync;
import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.collect.ImmutableMap;
import java.security.SecureRandom;
import java.time.Duration;
import java.time.OffsetDateTime;
@@ -190,6 +189,6 @@ public class SyncUtils {
final JsonNode overallJsonNode = jsonObjectMapper.convertToJsonNode(jsonObjectAsString);
final Iterator<Map.Entry<String, JsonNode>> overallJsonTreeMap = overallJsonNode.fields();
final Map.Entry<String, JsonNode> firstElement = overallJsonTreeMap.next();
- return jsonObjectMapper.asJsonString(ImmutableMap.of(firstElement.getKey(), firstElement.getValue()));
+ return jsonObjectMapper.asJsonString(Map.of(firstElement.getKey(), firstElement.getValue()));
}
}