2 * Copyright © 2018-2019 AT&T Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.core.service
19 import java.time.Duration
20 import java.util.Properties
22 interface BluePrintClusterService {
24 /** Start the cluster with [clusterInfo], By default clustering service is disabled.
25 * Application module has to start cluster */
26 suspend fun <T> startCluster(configuration: T)
28 fun clusterJoined(): Boolean
30 fun isClient(): Boolean
32 fun isLiteMember(): Boolean
34 /** Returns [partitionGroup] master member */
35 suspend fun masterMember(partitionGroup: String): ClusterMember
37 /** Returns all the data cluster members */
38 suspend fun allMembers(): Set<ClusterMember>
41 * Returns application cluster members for [appName] joined as server or lite member,
42 * Node joined as client won't be visible. Here the assumption is node-id is combination of
43 * application id and replica number, for an example Application cds-cluster then the node ids will be
44 * cds-cluster-1, cds-cluster-2, cds-cluster-3
46 suspend fun applicationMembers(appName: String): Set<ClusterMember>
48 /** Create and get or get the distributed data map store with [name] */
49 suspend fun <T> clusterMapStore(name: String): MutableMap<String, T>
51 /** Create and get the distributed lock with [name] */
52 suspend fun clusterLock(name: String): ClusterLock
54 /** Shut down the cluster with [duration] */
55 suspend fun shutDown(duration: Duration)
58 data class ClusterInfo(
61 var joinAsClient: Boolean = false,
62 var properties: Properties?,
63 var configFile: String
66 data class ClusterMember(
69 val memberAddress: String?,
70 val state: String? = null
73 interface ClusterLock {
76 suspend fun fenceLock(): String
77 suspend fun tryLock(timeout: Long): Boolean
78 suspend fun tryFenceLock(timeout: Long): String
80 fun isLocked(): Boolean
84 const val CDS_LOCK_GROUP = "cds-lock"