def run(self): self.logger.log("Starting thread %s" % self.thread_id) ## connect to the vbs server and create populate the vb_array ## that contains the mapping between vb_id belonging to this server ## and the ip address of the membase server on which that vbucket ## resides try: host, port = self.vbs_host.split(':') except: host = self.vbs_host port = 14000 #default VBS port vbs_agent.vbs_config_ptr = vbs_agent.create_vbs_config(host, int(port)) vbs_start_status = vbs_agent.start_vbs_config(vbs_agent.vbs_config_ptr) if vbs_start_status == -1: self.logger.log("Fatal: Failed to connect to VBS server %s" % vbs_host) sys.exit(-1) while (1): sleep(5) #dummy stuff TODO vbs_map_string = vbs_agent.get_current_config() if vbs_map_string == None: self.logger.log("Failure: Cannot get vbucket map") continue try: vbs_map_string = json.loads(vbs_map_string) server_config = vbs_map_string[0]['vBucketServerMap'] vb_list = server_config['vBucketMap'] server_list = server_config['serverList'] except: self.logger.log("Failure: Unable to parse vbucket map") vb_id = 0 vbs_map = {} for server_id in vb_list: # need to connect to the replica vbucket index = 0 if len(server_id) > 1: index = 1 serv_index = server_id[index] # Skip vbuckets or servers in maintenance stages if serv_index >= 0 and server_list[serv_index] != "0.0.0.0": vbs_map[vb_id] = server_list[serv_index] vb_id = vb_id + 1 self.update_map(vbs_map) if self.vbs_map_ready == 0: doneEvent.set() doneEvent.clear() self.vbs_map_ready = 1
def run(self): self.logger.log("Starting thread %s" %self.thread_id) ## connect to the vbs server and create populate the vb_array ## that contains the mapping between vb_id belonging to this server ## and the ip address of the membase server on which that vbucket ## resides try: host, port = self.vbs_host.split(':') except: host = self.vbs_host port = 14000 #default VBS port vbs_agent.vbs_config_ptr = vbs_agent.create_vbs_config(host, int(port)) vbs_start_status = vbs_agent.start_vbs_config(vbs_agent.vbs_config_ptr) if vbs_start_status == -1: self.logger.log("Fatal: Failed to connect to VBS server %s" %vbs_host) sys.exit(-1) while (1): sleep(5) #dummy stuff TODO vbs_map_string = vbs_agent.get_current_config() if vbs_map_string == None: self.logger.log("Failure: Cannot get vbucket map") continue try: vbs_map_string = json.loads(vbs_map_string) server_config = vbs_map_string[0]['vBucketServerMap'] vb_list = server_config['vBucketMap'] server_list = server_config['serverList'] except: self.logger.log("Failure: Unable to parse vbucket map") vb_id = 0 vbs_map = {} for server_id in vb_list: # need to connect to the replica vbucket index = 0 if len(server_id) > 1: index = 1 serv_index = server_id[index] # Skip vbuckets or servers in maintenance stages if serv_index >= 0 and server_list[serv_index] != "0.0.0.0": vbs_map[vb_id] = server_list[serv_index] vb_id = vb_id + 1 self.update_map(vbs_map) if self.vbs_map_ready == 0: doneEvent.set() doneEvent.clear() self.vbs_map_ready = 1
import vbs_agent import time import json import pdb vbs_agent.vbs_config_ptr = vbs_agent.create_vbs_config("localhost", 14000) vbs_agent.start_vbs_config(vbs_agent.vbs_config_ptr) while 1: time.sleep(100) config_data = vbs_agent.get_current_config() json_string = json.loads(config_data)