From 74cf06f7af65c699187f9e268db58023db2e2a62 Mon Sep 17 00:00:00 2001 From: mpriyank Date: Fri, 28 Apr 2023 15:02:00 +0100 Subject: Align the hazelcast cluster names - We need to align the hazelcast cluster names as members of the same cluster can join each other. We will still have exclusivity as the instance names and configs are different for each distributed object. - Exposing env variable to override the cluster name depending on the env it is run on. - Modified test cases to validate the cluster names as well Issue-ID: CPS-1637 Change-Id: Ib0f8c80dc9b2268f976b0c2d3ccd6d64792d4781 Signed-off-by: mpriyank --- .../main/java/org/onap/cps/cache/AnchorDataCacheConfig.java | 3 +-- .../src/main/java/org/onap/cps/cache/HazelcastCacheConfig.java | 10 ++++++---- .../groovy/org/onap/cps/cache/AnchorDataCacheConfigSpec.groovy | 8 +++++--- cps-service/src/test/resources/application.yml | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) (limited to 'cps-service') diff --git a/cps-service/src/main/java/org/onap/cps/cache/AnchorDataCacheConfig.java b/cps-service/src/main/java/org/onap/cps/cache/AnchorDataCacheConfig.java index 5ee6b3804..efe19c6cb 100644 --- a/cps-service/src/main/java/org/onap/cps/cache/AnchorDataCacheConfig.java +++ b/cps-service/src/main/java/org/onap/cps/cache/AnchorDataCacheConfig.java @@ -40,7 +40,6 @@ public class AnchorDataCacheConfig extends HazelcastCacheConfig { */ @Bean public IMap anchorDataCache() { - return createHazelcastInstance("hazelCastInstanceCpsCore", anchorDataCacheMapConfig, "cps-service-caches") - .getMap("anchorDataCache"); + return createHazelcastInstance("hazelCastInstanceCpsCore", anchorDataCacheMapConfig).getMap("anchorDataCache"); } } diff --git a/cps-service/src/main/java/org/onap/cps/cache/HazelcastCacheConfig.java b/cps-service/src/main/java/org/onap/cps/cache/HazelcastCacheConfig.java index 4aebceae0..405e6e2a8 100644 --- a/cps-service/src/main/java/org/onap/cps/cache/HazelcastCacheConfig.java +++ b/cps-service/src/main/java/org/onap/cps/cache/HazelcastCacheConfig.java @@ -35,6 +35,9 @@ import org.springframework.beans.factory.annotation.Value; @Slf4j public class HazelcastCacheConfig { + @Value("${hazelcast.cluster-name}") + protected String clusterName; + @Value("${hazelcast.mode.kubernetes.enabled}") protected boolean cacheKubernetesEnabled; @@ -42,12 +45,11 @@ public class HazelcastCacheConfig { protected String cacheKubernetesServiceName; protected HazelcastInstance createHazelcastInstance(final String hazelcastInstanceName, - final NamedConfig namedConfig, final String clusterName) { - return Hazelcast.newHazelcastInstance(initializeConfig(hazelcastInstanceName, namedConfig, clusterName)); + final NamedConfig namedConfig) { + return Hazelcast.newHazelcastInstance(initializeConfig(hazelcastInstanceName, namedConfig)); } - private Config initializeConfig(final String instanceName, final NamedConfig namedConfig, - final String clusterName) { + private Config initializeConfig(final String instanceName, final NamedConfig namedConfig) { final Config config = new Config(instanceName); if (namedConfig instanceof MapConfig) { config.addMapConfig((MapConfig) namedConfig); diff --git a/cps-service/src/test/groovy/org/onap/cps/cache/AnchorDataCacheConfigSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/cache/AnchorDataCacheConfigSpec.groovy index 76b534553..e219945d8 100644 --- a/cps-service/src/test/groovy/org/onap/cps/cache/AnchorDataCacheConfigSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/cache/AnchorDataCacheConfigSpec.groovy @@ -46,10 +46,12 @@ class AnchorDataCacheConfigSpec extends Specification { def 'Verify configs for Distributed Caches'(){ given: 'the Anchor Data Cache config' - def anchorDataCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelCastInstanceCpsCore').config.mapConfigs.get('anchorDataCacheMapConfig') + def anchorDataCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelCastInstanceCpsCore').config + def anchorDataCacheMapConfig = anchorDataCacheConfig.mapConfigs.get('anchorDataCacheMapConfig') expect: 'system created instance with correct config' - assert anchorDataCacheConfig.backupCount == 3 - assert anchorDataCacheConfig.asyncBackupCount == 3 + assert anchorDataCacheConfig.clusterName == 'cps-and-ncmp-test-caches' + assert anchorDataCacheMapConfig.backupCount == 3 + assert anchorDataCacheMapConfig.asyncBackupCount == 3 } def 'Verify deployment network configs for Distributed Caches'() { diff --git a/cps-service/src/test/resources/application.yml b/cps-service/src/test/resources/application.yml index 21f374533..dc100667b 100644 --- a/cps-service/src/test/resources/application.yml +++ b/cps-service/src/test/resources/application.yml @@ -51,6 +51,7 @@ logging: # Custom Hazelcast Config. hazelcast: + cluster-name: "cps-and-ncmp-test-caches" mode: kubernetes: enabled: false -- cgit 1.2.3-korg