/*
* ============LICENSE_START========================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-2023 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.hazelcast.config.QueueConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
-import java.util.Map;
+import com.hazelcast.map.IMap;
import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
import org.onap.cps.spi.model.DataNode;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Core infrastructure of the hazelcast distributed caches for Module Sync and Data Sync use cases.
*/
+@Slf4j
@Configuration
public class SynchronizationCacheConfig {
+ public static final int MODULE_SYNC_STARTED_TTL_SECS = 600;
+ public static final int DATA_SYNC_SEMAPHORE_TTL_SECS = 1800;
+
+ @Value("${hazelcast.mode.kubernetes.enabled}")
+ private boolean cacheKubernetesEnabled;
+
+ @Value("${hazelcast.mode.kubernetes.service-name}")
+ private String cacheKubernetesServiceName;
+
private static final QueueConfig commonQueueConfig = createQueueConfig();
- private static final MapConfig moduleSyncStartedConfig =
- createMapConfig("moduleSyncStartedConfig", TimeUnit.MINUTES.toSeconds(1));
- private static final MapConfig dataSyncSemaphoresConfig =
- createMapConfig("dataSyncSemaphoresConfig", TimeUnit.MINUTES.toSeconds(30));
+ private static final MapConfig moduleSyncStartedConfig = createMapConfig("moduleSyncStartedConfig");
+ private static final MapConfig dataSyncSemaphoresConfig = createMapConfig("dataSyncSemaphoresConfig");
/**
* Module Sync Distributed Queue Instance.
* @return Map of cm handles (ids) and objects (not used really) for which module sync has started or been completed
*/
@Bean
- public Map<String, Object> moduleSyncStartedOnCmHandles() {
+ public IMap<String, Object> moduleSyncStartedOnCmHandles() {
return createHazelcastInstance("moduleSyncStartedOnCmHandles", moduleSyncStartedConfig)
.getMap("moduleSyncStartedOnCmHandles");
}
* @return configured map of data sync semaphores
*/
@Bean
- public Map<String, Boolean> dataSyncSemaphores() {
+ public IMap<String, Boolean> dataSyncSemaphores() {
return createHazelcastInstance("dataSyncSemaphores", dataSyncSemaphoresConfig)
.getMap("dataSyncSemaphores");
}
config.addQueueConfig((QueueConfig) namedConfig);
}
config.setClusterName("synchronization-caches");
+ updateDiscoveryMode(config);
return config;
}
return commonQueueConfig;
}
- private static MapConfig createMapConfig(final String configName, final long timeToLiveSeconds) {
+ private static MapConfig createMapConfig(final String configName) {
final MapConfig mapConfig = new MapConfig(configName);
mapConfig.setBackupCount(3);
mapConfig.setAsyncBackupCount(3);
- mapConfig.setTimeToLiveSeconds((int) timeToLiveSeconds);
return mapConfig;
}
+ private void updateDiscoveryMode(final Config config) {
+ if (cacheKubernetesEnabled) {
+ log.info("Enabling kubernetes mode with service-name : {}", cacheKubernetesServiceName);
+ config.getNetworkConfig().getJoin().getKubernetesConfig().setEnabled(true)
+ .setProperty("service-name", cacheKubernetesServiceName);
+ }
+ }
+
}