def test_get_comp_list(my_id, gl_id, gl_ip, gl_port): request = Req() node = ServiceInfo(gl_id, gl_ip, gl_port) con = request.connector(IoType.EVENTIO, node) resp = request.get_comp_list(my_id, con) if resp.status.get_status_code() == Resp.SUCCESS: print "Success" else: print "Failed" con.close()
class GlobalVariables: __metaclass__ = SingletonType def __init__(self, logger): self.logger = logger self.conn_obj = None self.__acc_updater_map_version = 0.0 self.__acc_map_version = 0.0 self.__cont_map_version = 0.0 self.__global_map_version = 0.0 self.__global_map = {} self.__acc_updater_map = [] self.__acc_map = [] self.__cont_map = [] self.__ownership_list = [] self.__get_comp_counter_queue = Queue.Queue() self.__container_sweeper_list = [] self.__condition = threading.Condition() self.__transfer_comp_list = [] #self.__getcmpmap = threading.Event() self.__complete_all_event = threading.Event() self.__transfer_cmp_event = threading.Event() self.__accept_cmp_event = threading.Event() self.request_handler = Req(self.logger) def put_into_Queue(self): self.__get_comp_counter_queue.put(True) def get_from_Queue(self): try: comp_counter = self.__get_comp_counter_queue.get(block=True, \ timeout=300) return comp_counter except Queue.Empty: self.logger.error("Queue is empty") raise Queue.Empty("Nothing in queue") def load_ownership(self): self.logger.info("Loading my ownership") retry = 3 counter = 0 self.ownership_status = False while counter < retry: counter += 1 try: self.gl_info = self.request_handler.get_gl_info() self.conn_obj = self.request_handler.connector(\ IoType.SOCKETIO, self.gl_info) if self.conn_obj != None: result = self.request_handler.get_comp_list(\ self.__service_id, self.conn_obj) if result.status.get_status_code() == Resp.SUCCESS: self.__ownership_list = result.message self.logger.debug("Ownership list:%s" % self.__ownership_list) self.ownership_status = True self.conn_obj.close() return else: self.logger.warning("get_comp_list() error code:%s msg:%s"\ % (result.status.get_status_code(), \ result.status.get_status_message())) self.conn_obj.close() except Exception as ex: self.logger.exception("Exception occured during load_ownership" ":%s" % ex) if self.conn_obj: self.conn_obj.close() self.logger.warning("Failed to get comp list, Retry: %s" % counter) time.sleep(10) def get_my_ownership(self): self.logger.info("Sending request for retrieving my ownership") self.load_ownership() if not self.ownership_status: self.logger.error("Get my ownership list failed") os._exit(130) while not self.__ownership_list: self.logger.debug( "Ownership list is empty, retry after 20 seconds ") time.sleep(20) self.load_ownership() def set_ownershipList(self, ownership_list): self.__ownership_list = ownership_list def get_ownershipList(self): return self.__ownership_list def load_gl_map(self): self.logger.info("Sending request for retrieving global map") retry = 3 counter = 0 while counter < retry: counter += 1 try: self.gl_info = self.request_handler.get_gl_info() self.conn_obj = self.request_handler.connector( IoType.SOCKETIO, self.gl_info) if self.conn_obj != None: result = self.request_handler.get_global_map( self.__service_id, self.conn_obj) if result.status.get_status_code() == Resp.SUCCESS: self.__global_map = result.message.map() self.__global_map_version = result.message.version() self.logger.info("Global map version: %s" % (self.__global_map_version)) self.__acc_updater_map = self.__global_map[ 'accountUpdater-server'][0] self.__acc_updater_map_version = self.__global_map[ 'accountUpdater-server'][1] self.__acc_map = self.__global_map['account-server'][0] self.__acc_map_version = self.__global_map[ 'account-server'][1] self.__cont_map = self.__global_map[ 'container-server'][0] self.__cont_map_version = self.__global_map[ 'container-server'][1] self.conn_obj.close() return True else: self.logger.warning("load_gl_map() error code: %s msg: %s" \ % (result.status.get_status_code(), \ result.status.get_status_message())) self.conn_obj.close() except Exception as ex: self.logger.exception("Exception occured during get_global_map" ":%s" % ex) if self.conn_obj: self.conn_obj.close() self.logger.warning("Failed to get global map, Retry: %s" % counter) self.logger.error("Failed to load global map") return False def get_account_map(self): while not self.__acc_map: self.load_gl_map() time.sleep(10) return self.__acc_map def get_container_map(self): while not self.__cont_map: self.load_gl_map() time.sleep(10) return self.__cont_map def get_acc_updater_map(self): while not self.__acc_updater_map: self.load_gl_map() time.sleep(10) return self.__acc_updater_map def get_acc_updater_map_version(self): return self.__acc_updater_map_version def get_global_map_version(self): return self.__global_map_version def set_service_id(self, service_id): self.__service_id = service_id def get_service_id(self): return self.__service_id def create_sweeper_list(self, comp_tuple): self.__container_sweeper_list.append(comp_tuple) def get_sweeper_list(self): return self.__container_sweeper_list def pop_from_sweeper_list(self, temp_list): self.__container_sweeper_list = temp_list def get_conditionVariable(self): return self.__condition def set_transferCompList(self, comp_list): self.__transfer_comp_list = comp_list def get_transferCompList(self): return self.__transfer_comp_list """ def get_componentGetEventObject(self): return self.__getcmpmap """ def get_complete_all_event(self): return self.__complete_all_event def get_accept_cmp_event(self): return self.__accept_cmp_event def get_transfer_cmp_event(self): return self.__transfer_cmp_event