aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2024-09-10 16:12:28 +0100
committermpriyank <priyank.maheshwari@est.tech>2024-10-10 12:46:36 +0100
commit8e46da6c3a7b46a067bf72ebae0be1811ea7f9d0 (patch)
tree658d87fcc8d14f6101b78c08c5df785586c92cfc /cps-ncmp-service/src/main/java
parente2517a8b993ed884edb251b91ce600d0a1a9fefe (diff)
use one hazelcast instance per jvm
- updated all the cache(distributed datastructures) to use the same instance config now. - there will be just one instance per JVM now - Better cleanup of hz instance in the testware - Refactored the testware to verify the configs - Expected Impact on lowering the memory usage, less number of TCP communications between members - NOTE: we need to do a full regression as the changes impacts all the use cases which involves cache Issue-ID: CPS-2408 Change-Id: I7564992a9990f44ef3defb4f50cb7d094cad7b92 Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java34
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfig.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfig.java6
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java5
4 files changed, 32 insertions, 17 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java
index d911fc61b9..ad8025b5dc 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java
@@ -40,19 +40,30 @@ public class HazelcastCacheConfig {
@Value("${hazelcast.cluster-name}")
protected String clusterName;
+ @Value("${hazelcast.instance-config-name}")
+ protected String instanceConfigName;
+
@Value("${hazelcast.mode.kubernetes.enabled}")
protected boolean cacheKubernetesEnabled;
@Value("${hazelcast.mode.kubernetes.service-name}")
protected String cacheKubernetesServiceName;
- protected HazelcastInstance createHazelcastInstance(final String hazelcastInstanceName,
- final NamedConfig namedConfig) {
- return Hazelcast.newHazelcastInstance(initializeConfig(hazelcastInstanceName, namedConfig));
+ protected HazelcastInstance getOrCreateHazelcastInstance(final NamedConfig namedConfig) {
+ return Hazelcast.getOrCreateHazelcastInstance(defineInstanceConfig(instanceConfigName, namedConfig));
+ }
+
+ private Config defineInstanceConfig(final String instanceConfigName, final NamedConfig namedConfig) {
+ final Config config = getHazelcastInstanceConfig(instanceConfigName);
+ config.setClusterName(clusterName);
+ config.setClassLoader(org.onap.cps.spi.model.Dataspace.class.getClassLoader());
+ dataStructuresConfig(namedConfig, config);
+ exposeClusterInformation(config);
+ updateDiscoveryMode(config);
+ return config;
}
- private Config initializeConfig(final String instanceName, final NamedConfig namedConfig) {
- final Config config = new Config(instanceName);
+ private static void dataStructuresConfig(final NamedConfig namedConfig, final Config config) {
if (namedConfig instanceof MapConfig) {
config.addMapConfig((MapConfig) namedConfig);
}
@@ -62,11 +73,16 @@ public class HazelcastCacheConfig {
if (namedConfig instanceof SetConfig) {
config.addSetConfig((SetConfig) namedConfig);
}
+ }
- config.setClusterName(clusterName);
- config.setClassLoader(org.onap.cps.spi.model.Dataspace.class.getClassLoader());
- exposeClusterInformation(config);
- updateDiscoveryMode(config);
+ private Config getHazelcastInstanceConfig(final String instanceConfigName) {
+ final HazelcastInstance hazelcastInstance = Hazelcast.getHazelcastInstanceByName(instanceConfigName);
+ Config config = null;
+ if (hazelcastInstance != null) {
+ config = hazelcastInstance.getConfig();
+ } else {
+ config = new Config(instanceConfigName);
+ }
return config;
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfig.java
index e890d7288c..cb5102063e 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfig.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfig.java
@@ -43,7 +43,7 @@ public class CmSubscriptionConfig extends HazelcastCacheConfig {
*/
@Bean
public IMap<String, Map<String, DmiCmSubscriptionDetails>> cmNotificationSubscriptionCache() {
- return createHazelcastInstance("hazelCastInstanceCmNotificationSubscription",
- cmNotificationSubscriptionCacheMapConfig).getMap("cmNotificationSubscriptionCache");
+ return getOrCreateHazelcastInstance(cmNotificationSubscriptionCacheMapConfig).getMap(
+ "cmNotificationSubscriptionCache");
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfig.java
index 8ef98bc32a..c5fae0d166 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfig.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfig.java
@@ -51,7 +51,7 @@ public class SynchronizationCacheConfig extends HazelcastCacheConfig {
*/
@Bean
public BlockingQueue<DataNode> moduleSyncWorkQueue() {
- return createHazelcastInstance("moduleSyncWorkQueue", commonQueueConfig).getQueue("moduleSyncWorkQueue");
+ return getOrCreateHazelcastInstance(commonQueueConfig).getQueue("moduleSyncWorkQueue");
}
/**
@@ -61,7 +61,7 @@ public class SynchronizationCacheConfig extends HazelcastCacheConfig {
*/
@Bean
public IMap<String, Object> moduleSyncStartedOnCmHandles() {
- return createHazelcastInstance("moduleSyncStartedOnCmHandles", moduleSyncStartedConfig).getMap(
+ return getOrCreateHazelcastInstance(moduleSyncStartedConfig).getMap(
"moduleSyncStartedOnCmHandles");
}
@@ -72,6 +72,6 @@ public class SynchronizationCacheConfig extends HazelcastCacheConfig {
*/
@Bean
public IMap<String, Boolean> dataSyncSemaphores() {
- return createHazelcastInstance("dataSyncSemaphores", dataSyncSemaphoresConfig).getMap("dataSyncSemaphores");
+ return getOrCreateHazelcastInstance(dataSyncSemaphoresConfig).getMap("dataSyncSemaphores");
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java
index 0e9eaf5090..06ca67e57e 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java
@@ -46,8 +46,7 @@ public class TrustLevelCacheConfig extends HazelcastCacheConfig {
*/
@Bean(TRUST_LEVEL_PER_CM_HANDLE)
public Map<String, TrustLevel> trustLevelPerCmHandle() {
- return createHazelcastInstance("hazelcastInstanceTrustLevelPerCmHandleMap",
- trustLevelPerCmHandleCacheConfig).getMap(TRUST_LEVEL_PER_CM_HANDLE);
+ return getOrCreateHazelcastInstance(trustLevelPerCmHandleCacheConfig).getMap(TRUST_LEVEL_PER_CM_HANDLE);
}
/**
@@ -57,7 +56,7 @@ public class TrustLevelCacheConfig extends HazelcastCacheConfig {
*/
@Bean(TRUST_LEVEL_PER_DMI_PLUGIN)
public Map<String, TrustLevel> trustLevelPerDmiPlugin() {
- return createHazelcastInstance("hazelcastInstanceTrustLevelPerDmiPluginMap",
+ return getOrCreateHazelcastInstance(
trustLevelPerDmiPluginCacheConfig).getMap(TRUST_LEVEL_PER_DMI_PLUGIN);
}