@@ -6,9 +6,7 @@ import model.config.KeygroupConfig
6
6
import model.config.NodeConfig
7
7
import model.config.ReplicaNodeConfig
8
8
import model.config.TriggerNodeConfig
9
- import model.data.ClientID
10
- import model.data.KeygroupID
11
- import model.data.NodeID
9
+ import model.data.*
12
10
import org.apache.log4j.Logger
13
11
import java.io.File
14
12
@@ -23,8 +21,8 @@ private val logger = Logger.getLogger(Client::class.java.name)
23
21
class Client (val address : String , val port : Int ) {
24
22
25
23
/* *
26
- * Adds the given information to the Keygroup with [keygroupId] ; creates the keygroup if it did not exist yet.
27
- * If information is already present in the keygroup, this piece of information is ignored.
24
+ * Adds the given information to the specified keygroup ; creates the keygroup if it did not exist yet.
25
+ * If a piece of information is already present in the keygroup, this specific piece of information is ignored.
28
26
*
29
27
* Note, that all clients and nodes have to be registered at the naming service before they can be added.
30
28
*
@@ -39,7 +37,7 @@ class Client(val address: String, val port: Int) {
39
37
triggerNodeIds : List <String > = emptyList()) {
40
38
41
39
// check whether valid keygroupID
42
- val keygroupID = KeygroupID .createFromString(keygroupId)? : run {
40
+ val keygroupID = KeygroupID .createFromString(keygroupId) ? : run {
43
41
logger.warn(" Cannot update keygroup with the id $keygroupId as the id is not valid" )
44
42
return
45
43
}
@@ -92,19 +90,27 @@ class Client(val address: String, val port: Int) {
92
90
}
93
91
}
94
92
93
+ /* *
94
+ * Removes the given information from the specified keygroup, if it exists.
95
+ *
96
+ * @param keygroupId - the id of the keygroup
97
+ * @param clientIds - list of to be removed client ids
98
+ * @param replicaNodeIds - list of to be removed replica node ids
99
+ * @param triggerNodeIds - list of to be removed trigger node ids
100
+ */
95
101
fun removeFromKeygroup (keygroupId : String , clientIds : List <String > = emptyList(),
96
102
replicaNodeIds : List <String > = emptyList(), triggerNodeIds : List <String > = emptyList()) {
97
103
98
104
// check whether valid keygroupID
99
- val keygroupID = KeygroupID .createFromString(keygroupId)? : run {
105
+ val keygroupID = KeygroupID .createFromString(keygroupId) ? : run {
100
106
logger.warn(" Cannot remove items from keygroup with the id $keygroupId as the id is not valid" )
101
107
return
102
108
}
103
109
104
110
val request = KeygroupRequest (address, port)
105
111
106
112
// get current config first, return if not null
107
- val keygroupConfig = request.updateLocalKeygroupConfig(keygroupID)? : run {
113
+ val keygroupConfig = request.updateLocalKeygroupConfig(keygroupID) ? : run {
108
114
logger.warn(" Keygroup $keygroupId does not exist" )
109
115
return
110
116
}
@@ -143,6 +149,38 @@ class Client(val address: String, val port: Int) {
143
149
}
144
150
}
145
151
152
+ /* *
153
+ * Stores a data record of the keygroup with the given [keygroupId]. If a data record with the same [dataId] already
154
+ * exists in the keygroup, it is overwritten.
155
+ */
156
+ fun putData (keygroupId : String , dataId : String , key : String = "", value : String ) {
157
+ // check whether valid keygroupID
158
+ val keygroupID = KeygroupID .createFromString(keygroupId) ? : run {
159
+ logger.warn(" Cannot remove items from keygroup with the id $keygroupId as the id is not valid" )
160
+ return
161
+ }
162
+
163
+ val request = RecordRequest (address, port)
164
+ logger.debug(" Added data to keygroup $keygroupID $:" + request.putDataRecord(DataRecord (DataIdentifier (keygroupID,
165
+ dataId), mapOf (key to value))))
166
+ }
167
+
168
+ /* *
169
+ * Stores a data record of the keygroup with the given [keygroupId]. If a data record with the same [dataId] already
170
+ * exists in the keygroup, it is overwritten.
171
+ */
172
+ fun putData (keygroupId : String , dataId : String , valueMap : Map <String , String >) {
173
+ // check whether valid keygroupID
174
+ val keygroupID = KeygroupID .createFromString(keygroupId) ? : run {
175
+ logger.warn(" Cannot remove items from keygroup with the id $keygroupId as the id is not valid" )
176
+ return
177
+ }
178
+
179
+ val request = RecordRequest (address, port)
180
+ logger.debug(" Added data to keygroup $keygroupID : " + request.putDataRecord(DataRecord (DataIdentifier (keygroupID,
181
+ dataId), valueMap)))
182
+ }
183
+
146
184
}
147
185
148
186
fun main (args : Array <String >) {
@@ -159,6 +197,7 @@ fun main(args: Array<String>) {
159
197
nr.createNodeConfig(nodeConfig)
160
198
161
199
c.addToKeygroup(keygroupId, replicaNodeIds = listOf (" N2" ), ttl = 120 )
200
+ c.putData(keygroupId, " D1" , value = " Testvalue" )
162
201
163
202
// remove N3 (must fail)
164
203
c.removeFromKeygroup(keygroupId, replicaNodeIds = listOf (" N3" ))
0 commit comments