14
14
NUM_SLOTS = 16384
15
15
16
16
17
- def make_parts (n ):
17
+ def _make_parts (n ):
18
18
p = NUM_SLOTS / n
19
19
remain = NUM_SLOTS - (p * n )
20
20
@@ -34,6 +34,28 @@ def make_parts(n):
34
34
return partitions
35
35
36
36
37
+ def _map_cluster (node_host , node_port ):
38
+ cluster = {}
39
+ slaves = []
40
+ node_port = int (node_port )
41
+ nodes , master = redistrib .command .list_nodes (node_host , node_port )
42
+ for node in nodes :
43
+ if 'master' in node .role_in_cluster :
44
+ if node .node_id not in cluster :
45
+ cluster [node .node_id ] = {'self' : node , 'slaves' : []}
46
+ else :
47
+ slaves .append (node )
48
+
49
+ for slave in slaves :
50
+ cluster [slave .master_id ]['slaves' ].append (slave )
51
+
52
+ if slaves :
53
+ cluster_replication_factor = int (len (cluster ) / len (slaves ))
54
+ else :
55
+ cluster_replication_factor = 0
56
+ return cluster , slaves , cluster_replication_factor
57
+
58
+
37
59
def create (new_nodes , replicas = 0 ):
38
60
"""
39
61
Function to create a new cluster ONLY from nodes not already initialized. NOTE: this function replicates
@@ -80,28 +102,6 @@ def create(new_nodes, replicas=0):
80
102
return True
81
103
82
104
83
- def _map_cluster (node_host , node_port ):
84
- cluster = {}
85
- slaves = []
86
- node_port = int (node_port )
87
- nodes , master = redistrib .command .list_nodes (node_host , node_port )
88
- for node in nodes :
89
- if 'master' in node .role_in_cluster :
90
- if node .node_id not in cluster :
91
- cluster [node .node_id ] = {'self' : node , 'slaves' : []}
92
- else :
93
- slaves .append (node )
94
-
95
- for slave in slaves :
96
- cluster [slave .master_id ]['slaves' ].append (slave )
97
-
98
- if slaves :
99
- cluster_replication_factor = int (len (cluster ) / len (slaves ))
100
- else :
101
- cluster_replication_factor = 0
102
- return cluster , slaves , cluster_replication_factor
103
-
104
-
105
105
def expand_cluster (master_host , master_port , new_nodes , num_new_masters = None ):
106
106
"""
107
107
function to add a set of nodes to an existing cluster. NOTE: this function presumes that the list of new nodes are
@@ -205,7 +205,7 @@ def expand_cluster(master_host, master_port, new_nodes, num_new_masters=None):
205
205
new_master_node ['host' ], int (new_master_node ['port' ]))
206
206
207
207
208
- def validate_and_run (new_hosts , replication_factor = None , new_masters = None ):
208
+ def _validate_and_run (new_hosts , replication_factor = None , new_masters = None ):
209
209
new_nodes = []
210
210
cluster_nodes = []
211
211
@@ -269,7 +269,7 @@ def remove_cluster(cluster_nodes):
269
269
reset_node (master ['self' ])
270
270
271
271
272
- def decode_hosts (host_list ):
272
+ def _decode_hosts (host_list ):
273
273
hosts = []
274
274
for host in host_list :
275
275
try :
@@ -285,7 +285,7 @@ def decode_hosts(host_list):
285
285
286
286
287
287
# from http://stackoverflow.com/questions/14117415
288
- def check_negative (value ):
288
+ def _check_negative (value ):
289
289
ivalue = int (value )
290
290
if ivalue < 0 :
291
291
raise argparse .ArgumentTypeError ("%s is an invalid positive int value" % value )
@@ -322,16 +322,16 @@ def main():
322
322
args = parser .parse_args ()
323
323
324
324
if args .replication_factor :
325
- args .replication_factor = check_negative (args .replication_factor )
325
+ args .replication_factor = _check_negative (args .replication_factor )
326
326
327
327
if args .new_masters :
328
- args .new_masters = check_negative (args .new_masters )
328
+ args .new_masters = _check_negative (args .new_masters )
329
329
330
330
if not args .clear_cluster :
331
- new_hosts = decode_hosts (args .new_hosts )
332
- validate_and_run (new_hosts , args .replication_factor , args .new_masters )
331
+ new_hosts = _decode_hosts (args .new_hosts )
332
+ _validate_and_run (new_hosts , args .replication_factor , args .new_masters )
333
333
else :
334
- hosts = decode_hosts (args .new_hosts )
334
+ hosts = _decode_hosts (args .new_hosts )
335
335
remove_cluster (hosts )
336
336
337
337
0 commit comments