def handle_resolve(self,tokens): if len(tokens) < 1: print um.MISSING_ARGS else: _ip = self.cluster.nodes[tokens[0]] rsp = dataHelper.make_request(_ip,"nodes/resolve/") print rsp
def handle_chain(self,tokens): if len(tokens) < 1: print um.MISSING_ARGS else: _ip = self.cluster.nodes[tokens[0]] rsp = dataHelper.make_request(_ip,"crash/",tokens) print rsp
def handle_get_data(self): for ip in self.cluster.routes: rsp = dataHelper.make_request(ip, "getKeyStore") keys = ["Endpoint", "Term", "Commit Index", "Data"] for key in keys: print key + ":", rsp[key] print
def handle_update(self, tokens): if len(tokens) < 2: print um.MISSING_ARGS else: self.cluster.find_leader() rsp = dataHelper.make_request(self.cluster.leader, "update/", tokens) keys = ["Total Logs", "Key", "Value", "State", "Term"] for key in keys: print key + ":", rsp[key]
def print_cluster(self): data = [] for url in self.routes: tmp = [] try: rsp = dh.make_request(url) for key in self.default_keys: tmp.append(rsp[key]) except Exception: tmp = ["DEAD"] * len(self.default_keys) data.append(tmp) print tabulate(data, headers=self.default_keys)
def find_leader(self): if len(self.routes) > 0: while not self.leader: for url in self.urls: try: rsp = dh.make_request(url) if rsp['State'] == 'LEADER': self.leader = "http://" + rsp['IP Address'] + ":" + str(rsp['Endpoint Port']) except urllib2.HTTPError, e: print('HTTPError = ' + str(e.code)) except urllib2.URLError, e: print('URLError = ' + str(e.reason)) print url + " not reachable" except Exception, e: print e
def handle_crash(self, tokens): if len(tokens) < 1: print um.MISSING_ARGS else: rsp = dataHelper.make_request(self.cluster.leader, "crash/", tokens)