summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/main')
-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.java36
4 files changed, 109 insertions, 41 deletions
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 aae2f209ae..d9aeaf2589 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 0000000000..978c3d16b7
--- /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 c29c725d79..a133cfb80d 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 19cf225985..af01fb4398 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
@@ -58,7 +58,7 @@ public class InventoryPersistence {
private static final String NCMP_DMI_REGISTRY_PARENT = "/dmi-registry";
- private String xpathCmHandle = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
+ private static final String CM_HANDLE_XPATH_TEMPLATE = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
private static final String ANCESTOR_CM_HANDLES = "\"]/ancestor::cm-handles";
@@ -80,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();
}
@@ -95,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());
}
@@ -241,14 +241,11 @@ public class InventoryPersistence {
/**
* Get data node of given cm handle.
*
- * @param cmHandle cm handle
+ * @param cmHandleId cmHandle ID
* @return data node
*/
- private DataNode getCmHandleDataNode(final String cmHandle) {
- return cpsDataService.getDataNode(NCMP_DATASPACE_NAME,
- NCMP_DMI_REGISTRY_ANCHOR,
- String.format(xpathCmHandle, cmHandle),
- FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
+ public DataNode getCmHandleDataNode(final String cmHandleId) {
+ return this.getDataNode(String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId));
}
/**
@@ -269,4 +266,25 @@ public class InventoryPersistence {
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