Cluster co-ordination with Hazelcast.
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / processor-core / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / core / service / BluePrintClusterService.kt
index f994628..53f18d3 100644 (file)
 package org.onap.ccsdk.cds.blueprintsprocessor.core.service
 
 import java.time.Duration
+import java.util.Properties
 
 interface BluePrintClusterService {
 
     /** Start the cluster with [clusterInfo], By default clustering service is disabled.
      * Application module has to start cluster */
-    suspend fun startCluster(clusterInfo: ClusterInfo)
+    suspend fun <T> startCluster(configuration: T)
 
     fun clusterJoined(): Boolean
 
+    fun isClient(): Boolean
+
+    fun isLiteMember(): Boolean
+
     /** Returns [partitionGroup] master member */
     suspend fun masterMember(partitionGroup: String): ClusterMember
 
     /** Returns all the data cluster members */
     suspend fun allMembers(): Set<ClusterMember>
 
-    /** Returns data cluster members starting with prefix */
-    suspend fun clusterMembersForPrefix(memberPrefix: String): Set<ClusterMember>
+    /**
+     * Returns application cluster members for [appName] joined as server or lite member,
+     * Node joined as client won't be visible. Here the assumption is node-id is combination of
+     * application id and replica number, for an example Application cds-cluster then the node ids will be
+     * cds-cluster-1, cds-cluster-2, cds-cluster-3
+     */
+    suspend fun applicationMembers(appName: String): Set<ClusterMember>
 
     /** Create and get or get the distributed data map store with [name] */
     suspend fun <T> clusterMapStore(name: String): MutableMap<String, T>
@@ -47,19 +57,25 @@ interface BluePrintClusterService {
 
 data class ClusterInfo(
     val id: String,
-    var configFile: String? = null,
     val nodeId: String,
-    val nodeAddress: String,
-    var clusterMembers: List<String>,
-    var storagePath: String
+    var joinAsClient: Boolean = false,
+    var properties: Properties?,
+    var configFile: String
 )
 
-data class ClusterMember(val id: String, val memberAddress: String?, val state: String? = null)
+data class ClusterMember(
+    val id: String,
+    val name: String,
+    val memberAddress: String?,
+    val state: String? = null
+)
 
 interface ClusterLock {
     fun name(): String
     suspend fun lock()
+    suspend fun fenceLock(): String
     suspend fun tryLock(timeout: Long): Boolean
+    suspend fun tryFenceLock(timeout: Long): String
     suspend fun unLock()
     fun isLocked(): Boolean
     fun close()