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 org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.BlueprintClusterTopic
20 import org.springframework.context.ApplicationEvent
21 import java.time.Duration
22 import java.util.Properties
25 interface BluePrintClusterService {
27 /** Start the cluster with [clusterInfo], By default clustering service is disabled.
28 * Application module has to start cluster */
29 suspend fun <T> startCluster(configuration: T)
31 fun clusterJoined(): Boolean
33 fun isClient(): Boolean
35 fun isLiteMember(): Boolean
37 /** Returns [partitionGroup] master member */
38 suspend fun masterMember(partitionGroup: String): ClusterMember
40 /** Returns all the data cluster members */
41 suspend fun allMembers(): Set<ClusterMember>
44 * Returns application cluster members for [appName] joined as server or lite member,
45 * Node joined as client won't be visible. Here the assumption is node-id is combination of
46 * application id and replica number, for an example Application cds-cluster then the node ids will be
47 * cds-cluster-1, cds-cluster-2, cds-cluster-3
49 suspend fun applicationMembers(appName: String): Set<ClusterMember>
51 /** Create and get or get the distributed data map store with [name] */
52 suspend fun <T> clusterMapStore(name: String): MutableMap<String, T>
54 /** Create and get the distributed lock with [name] */
55 suspend fun clusterLock(name: String): ClusterLock
57 /** Shut down the cluster with [duration] */
58 suspend fun shutDown(duration: Duration)
60 /** Send [message] to the listener(s) of a [topic] */
61 suspend fun <T> sendMessage(topic: BlueprintClusterTopic, message: T)
63 /** Register a [listener] to a [topic] and returns his UUID */
64 fun <T> addBlueprintClusterMessageListener(topic: BlueprintClusterTopic, listener: BlueprintClusterMessageListener<T>): UUID
66 /** Unregister a listener from a [topic] using his [uuid] and returns true if it succeeded */
67 fun removeBlueprintClusterMessageListener(topic: BlueprintClusterTopic, uuid: UUID): Boolean
70 data class ClusterInfo(
73 var joinAsClient: Boolean = false,
74 var properties: Properties?,
75 var configFile: String
78 data class ClusterMember(
81 val memberAddress: String?,
82 val state: String? = null
85 interface ClusterLock {
89 suspend fun fenceLock(): String
90 suspend fun tryLock(timeout: Long): Boolean
91 suspend fun tryFenceLock(timeout: Long): String
93 fun isLocked(): Boolean
94 fun isLockedByCurrentThread(): Boolean
98 class BluePrintClusterMessage<E>(val topic: BlueprintClusterTopic, val payload: E, publishTime: Long, clusterMember: ClusterMember)
100 interface BlueprintClusterMessageListener<E> {
101 fun onMessage(message: BluePrintClusterMessage<E>?)
104 class ClusterJoinedEvent(source: Any) : ApplicationEvent(source)
106 const val CDS_LOCK_GROUP = "cds-lock"