8 __author__ = "Basheeruddin Ahmed"
9 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
10 __license__ = "New-style BSD"
11 __email__ = "syedbahm@cisco.com"
15 shardName, numOfShards=3, numOfTries=3, sleepBetweenRetriesInSecs=3, port=8181, *ips
17 """Given a shardname (e.g. shard-inventory-config), number of shards and bunch of ips
19 determines what role each ip has in an Akka (Raft based) cluster
20 result would look like
21 {'10.194.126.118':'Leader', '10.194.126.118':'Follower', '10.194.126.117': None}
27 print("numOfShards => ", str(numOfShards))
28 while i <= numOfShards:
29 shardMemberName = "member-" + str(i) + "-" + shardName
31 print("j => ", str(j))
32 print("numOfTries => ", str(numOfTries))
33 while int(j) <= int(numOfTries):
34 print("Try number " + str(j))
37 "getting role of " + ip + " for shardName = " + shardMemberName
39 url = SettingsLibrary.getJolokiaURL(
40 ip, str(port), str(i), shardName
43 resp = UtilLibrary.get(url)
45 if resp.status_code != 200:
46 sleep(sleepBetweenRetriesInSecs)
49 data = json.loads(resp.text)
51 dataValue = data["value"]
52 print("datavalue RaftState is", dataValue["RaftState"])
53 dict[ip] = dataValue["RaftState"]
59 + ":An error occurred when finding leader on"
65 sleep(sleepBetweenRetriesInSecs)
69 if dict[ip] is not None:
76 role, shardName, ipAddress, numOfShards=3, numOfRetries=1, sleepFor=3, port=8181
78 """Given a role (Leader, Follower, Candidate, or IsolatedLeader),
79 shardname (e.g. shard-inventory-config), controller IP address,
80 and number of shards on the controller,this function determines if the controller,
81 has that role for the specified shard.
84 shardName, numOfShards, numOfRetries, sleepFor, port, ipAddress
87 if ip[ipAddress] == role:
93 shardName, numOfShards=3, numOfTries=3, sleepBetweenRetriesInSecs=1, port=8181, *ips
95 """Returns the leader of the shard given a set of IPs Or None"""
96 for i in range(3): # Try 3 times to find a leader
97 dict = getClusterRoles(
98 shardName, numOfShards, numOfTries, sleepBetweenRetriesInSecs, port, *ips
100 for ip in dict.keys():
101 if dict[ip] == "Leader":
107 shardName, numOfShards=3, numOfTries=3, sleepBetweenRetriesInSecs=1, port=8181, *ips
109 """Returns the follower list of a shard given a set of IPs Or []"""
110 for i in range(6): # Try 6 times to find all followers
111 dict = getClusterRoles(
112 shardName, numOfShards, numOfTries, sleepBetweenRetriesInSecs, port, *ips
116 for ip in dict.keys():
117 if dict[ip] == "Follower":
119 print("i=%s result=%s" % (i, result))
120 if len(result) == (len(ips) - 1):
126 def testGetClusterRoles():
127 dict = getClusterRoles(
128 "shard-inventory-config",
139 for ip in dict.keys():
140 if isRole("Leader", "shard-inventory-config", 3, 1, 1, 8181, ip):
141 print(ip + " is Leader")
142 elif isRole("Follower", "shard-inventory-config", 3, 1, 1, 8181, ip):
143 print(ip + " is follower")
145 print(ip + " seems to have value " + str(dict[ip]))
150 "shard-inventory-config",
163 def testGetFollowers():
164 followers = getFollowers(
165 "shard-inventory-config",
178 # testGetClusterRoles()