Cluster partition master API
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / processor-core / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / core / service / BluePrintClusterService.kt
1 /*
2  * Copyright © 2018-2019 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.core.service
18
19 import java.time.Duration
20
21 interface BluePrintClusterService {
22
23     /** Start the cluster with [clusterInfo], By default clustering service is disabled.
24      * Application module has to start cluster */
25     suspend fun startCluster(clusterInfo: ClusterInfo)
26
27     fun clusterJoined(): Boolean
28
29     /** Returns [partitionGroup] master member */
30     suspend fun masterMember(partitionGroup: String): ClusterMember
31
32     /** Returns all the data cluster members */
33     suspend fun allMembers(): Set<ClusterMember>
34
35     /** Returns data cluster members starting with prefix */
36     suspend fun clusterMembersForPrefix(memberPrefix: String): Set<ClusterMember>
37
38     /** Create and get or get the distributed data map store with [name] */
39     suspend fun <T> clusterMapStore(name: String): MutableMap<String, T>
40
41     /** Create and get the distributed lock with [name] */
42     suspend fun clusterLock(name: String): ClusterLock
43
44     /** Shut down the cluster with [duration] */
45     suspend fun shutDown(duration: Duration)
46 }
47
48 data class ClusterInfo(
49     val id: String,
50     var configFile: String? = null,
51     val nodeId: String,
52     val nodeAddress: String,
53     var clusterMembers: List<String>,
54     var storagePath: String
55 )
56
57 data class ClusterMember(val id: String, val memberAddress: String?, val state: String? = null)
58
59 interface ClusterLock {
60     suspend fun lock()
61     suspend fun tryLock(timeout: Long): Boolean
62     suspend fun unLock()
63     fun isLocked(): Boolean
64     fun close()
65 }