Ejemplo n.º 1
0
    def do_STOP_SERVICE(self):
        """
        Handle COMPLETE ALL REQUEST HTTP request
        """
        self.logger = SimpleLogger(conf=None).get_logger_object()
        self.conf = SimpleLogger(conf=None).get_conf()
        self.msg = GlobalVariables(self.logger)
        all_transfer_event_received = []
        self.logger.info("Account-updater received STOP_SERVICE request")

        complete_all_request_event = self.msg.get_complete_all_event()
        complete_all_request_event.set()
        try:
            while len(all_transfer_event_received) != 4:
                all_transfer_event_received.append(self.msg.get_from_Queue())

            self.logger.info("Completed STOP_SERVICE request")
            self.send_header('Message-Type', typeEnums.BLOCK_NEW_REQUESTS_ACK)
            self.send_header('Ownership-List', self.msg.get_ownershipList())
            self.send_response(HTTP_OK)
            self.end_headers()
            self.wfile.write(self.msg.get_ownershipList())
            return
        except Exception as err:
            self.logger.exception('Exception raised in' \
                ' STOP_SERVICE error :%s' % err)
            self.send_response(HTTP_INTERNAL_SERVER_ERROR)
            self.end_headers()
Ejemplo n.º 2
0
    def __init__(self, conf, logger=None):
        """
        constructor for account updater
        :param conf: configuration of account-updater 
        """
        self.logger = logger or SimpleLogger(conf).get_logger_object()
        Daemon.__init__(self, conf, self.logger)
        libraryUtils.OSDLoggerImpl(
            "account-updater-monitoring").initialize_logger()
        create_recovery_file('account-updater-server')
        self.conf = conf
        self.__interval = int(conf.get('interval', 1800))
        self.__ll_port = int(conf.get('llport', 61014))
        self.__account_updater_port = int(\
            conf.get('account_updater_port', 61009))
        self.__service_id = gethostname() + "_" + str(self.__ll_port) + \
            "_account-updater-server"
        self.__param = self.__get_param(conf)
        self.msg = GlobalVariables(self.logger)
        self.msg.set_service_id(self.__service_id)
        self.walker_map = WalkerMap()
        self.reader_map = ReaderMap()

        # Start sending health to local leader
        self.logger.info("Loading health monitoring library")
        self.health_instance = healthMonitoring(self.__get_node_ip\
            (gethostname()), self.__account_updater_port, \
            self.__ll_port, self.__service_id)
        self.logger.info("Loaded health monitoring library")
        remove_recovery_file('account-updater-server')

        # load global map
        if not self.msg.load_gl_map():
            sys.exit(130)
        self.logger.info("Account updater started")
Ejemplo n.º 3
0
    def do_TRANSFER_COMPONENTS(self):
        """
        Handle TRANSFER COMPONENTS HTTP request
        """
        self.logger = SimpleLogger(conf=None).get_logger_object()
        self.conf = SimpleLogger(conf=None).get_conf()
        self.msg = GlobalVariables(self.logger)
        self._request_handler = Req()
        transfer_component_timeout = int(
            self.conf.get('\
            transfer_component_timeout', 600))
        self.ll_port = int(self.conf.get('llport', 61014))
        self.service_id = self.msg.get_service_id()
        self.deleted_comp_list = []
        transfer_component_map = {
        }  #dictionary containing{'(dest_node_obj)':'[comp_list]'}
        #eg: {('169.254.1.12', '61009', 'HN0101_61014_account-updater'):'['1', '2']'}
        self.final_transfer_status_list = [
        ]  #final component status list which will be send to GL
        #[(1, True),(2, False),(3, True)]
        self.final_status = False  #final response to GL
        self.check_transfer_component_map = {
        }  # to check if component transfer completed or failed:
        #{dest_node_obj1:True, dest_node_obj2:"Failed", dest_node_obj3:False}
        all_transfer_event_received = []
        self.protocol_version = "HTTP/1.1"
        self.logger.info("Account-updater received Transfer component request")
        try:
            content_length = int(self.headers['Content-Length'])
            #sending acknowledgement of TRANSFER_COMPONENT to GL
            self.send_response(HTTP_CONTINUE, "Continue\r\n\r\n")

            data = self.rfile.read(content_length)
            message = TransferCompMessage()
            message.de_serialize(data)
            transfer_component_map = message.service_comp_map()
            self.logger.info("Deserialized transfer component map:%s" \
                %transfer_component_map)
        except Exception, ex:
            self.logger.error("Exception: %s" % ex)
            self.send_header('Message-Type', \
                typeEnums.TRANSFER_COMPONENT_RESPONSE)
            self.send_response(HTTP_INTERNAL_SERVER_ERROR)
            self.end_headers()
            return
Ejemplo n.º 4
0
    def do_ACCEPT_COMPONENT_TRANSFER(self):
        """
        Handle ACCEPT COMPONENT TRANSFER HTTP request
        """
        try:
            self.logger = SimpleLogger(conf=None).get_logger_object()
            self.conf = SimpleLogger(conf=None).get_conf()
            self.msg = GlobalVariables(self.logger)
            self.ll_port = int(self.conf.get('llport', 61014))
            self.logger.info("Account-updater received ACCEPT_COMPONENT_" \
                "TRANSFER request")
            length = int(self.headers['Content-Length'])
            self.logger.debug("Headers:%s" % self.headers)
            #sending intemediate (connection created) acknowledgement
            #to source node
            self.send_response(HTTP_CONTINUE)
            self.end_headers()

            #receiving new ownership list
            pickled_string = self.rfile.read(length)
            add_comp_list = ast.literal_eval(pickled_string)
            self.logger.info("Accepting new component ownership: %s" %
                             add_comp_list)

            #updating global map for new onwership
            thread = threading.Thread(target = self.update_my_ownership, \
                                    args=(add_comp_list,))
            thread.start()

            self.logger.info("Completed ACCEPT_COMPONENTS_TRANSFER request")
            self.send_response(HTTP_OK)
            self.end_headers()
            return
        except Exception as err:
            self.logger.exception('Exception raised in' \
                'ACCEPT_COMPONENTS_TRANSFER error :%s' % err)
            self.send_response(HTTP_INTERNAL_SERVER_ERROR)
            self.end_headers()
Ejemplo n.º 5
0
def run_daemon(server, conf, section_name="", **kwargs):
    if section_name is '':
        section_name = sub(r'([a-z])([A-Z])', r'\1-\2',
                           server.__name__).lower()
    conf = readconf(conf, section_name, log_name=kwargs.get('log_name'))

    logger = SimpleLogger(conf).get_logger_object()
    os.environ['TZ'] = time.strftime("%z", time.gmtime())

    try:
        server(conf, logger).run()
    except KeyboardInterrupt:
        logger.info('User quit')
    logger.info('Exited')
Ejemplo n.º 6
0
class HttpListener(BaseHTTPRequestHandler):
    def do_STOP_SERVICE(self):
        """
        Handle COMPLETE ALL REQUEST HTTP request
        """
        self.logger = SimpleLogger(conf=None).get_logger_object()
        self.conf = SimpleLogger(conf=None).get_conf()
        self.msg = GlobalVariables(self.logger)
        all_transfer_event_received = []
        self.logger.info("Account-updater received STOP_SERVICE request")

        complete_all_request_event = self.msg.get_complete_all_event()
        complete_all_request_event.set()
        try:
            while len(all_transfer_event_received) != 4:
                all_transfer_event_received.append(self.msg.get_from_Queue())

            self.logger.info("Completed STOP_SERVICE request")
            self.send_header('Message-Type', typeEnums.BLOCK_NEW_REQUESTS_ACK)
            self.send_header('Ownership-List', self.msg.get_ownershipList())
            self.send_response(HTTP_OK)
            self.end_headers()
            self.wfile.write(self.msg.get_ownershipList())
            return
        except Exception as err:
            self.logger.exception('Exception raised in' \
                ' STOP_SERVICE error :%s' % err)
            self.send_response(HTTP_INTERNAL_SERVER_ERROR)
            self.end_headers()

    def do_ACCEPT_COMPONENT_TRANSFER(self):
        """
        Handle ACCEPT COMPONENT TRANSFER HTTP request
        """
        try:
            self.logger = SimpleLogger(conf=None).get_logger_object()
            self.conf = SimpleLogger(conf=None).get_conf()
            self.msg = GlobalVariables(self.logger)
            self.ll_port = int(self.conf.get('llport', 61014))
            self.logger.info("Account-updater received ACCEPT_COMPONENT_" \
                "TRANSFER request")
            length = int(self.headers['Content-Length'])
            self.logger.debug("Headers:%s" % self.headers)
            #sending intemediate (connection created) acknowledgement
            #to source node
            self.send_response(HTTP_CONTINUE)
            self.end_headers()

            #receiving new ownership list
            pickled_string = self.rfile.read(length)
            add_comp_list = ast.literal_eval(pickled_string)
            self.logger.info("Accepting new component ownership: %s" %
                             add_comp_list)

            #updating global map for new onwership
            thread = threading.Thread(target = self.update_my_ownership, \
                                    args=(add_comp_list,))
            thread.start()

            self.logger.info("Completed ACCEPT_COMPONENTS_TRANSFER request")
            self.send_response(HTTP_OK)
            self.end_headers()
            return
        except Exception as err:
            self.logger.exception('Exception raised in' \
                'ACCEPT_COMPONENTS_TRANSFER error :%s' % err)
            self.send_response(HTTP_INTERNAL_SERVER_ERROR)
            self.end_headers()

    def do_TRANSFER_COMPONENTS(self):
        """
        Handle TRANSFER COMPONENTS HTTP request
        """
        self.logger = SimpleLogger(conf=None).get_logger_object()
        self.conf = SimpleLogger(conf=None).get_conf()
        self.msg = GlobalVariables(self.logger)
        self._request_handler = Req()
        transfer_component_timeout = int(
            self.conf.get('\
            transfer_component_timeout', 600))
        self.ll_port = int(self.conf.get('llport', 61014))
        self.service_id = self.msg.get_service_id()
        self.deleted_comp_list = []
        transfer_component_map = {
        }  #dictionary containing{'(dest_node_obj)':'[comp_list]'}
        #eg: {('169.254.1.12', '61009', 'HN0101_61014_account-updater'):'['1', '2']'}
        self.final_transfer_status_list = [
        ]  #final component status list which will be send to GL
        #[(1, True),(2, False),(3, True)]
        self.final_status = False  #final response to GL
        self.check_transfer_component_map = {
        }  # to check if component transfer completed or failed:
        #{dest_node_obj1:True, dest_node_obj2:"Failed", dest_node_obj3:False}
        all_transfer_event_received = []
        self.protocol_version = "HTTP/1.1"
        self.logger.info("Account-updater received Transfer component request")
        try:
            content_length = int(self.headers['Content-Length'])
            #sending acknowledgement of TRANSFER_COMPONENT to GL
            self.send_response(HTTP_CONTINUE, "Continue\r\n\r\n")

            data = self.rfile.read(content_length)
            message = TransferCompMessage()
            message.de_serialize(data)
            transfer_component_map = message.service_comp_map()
            self.logger.info("Deserialized transfer component map:%s" \
                %transfer_component_map)
        except Exception, ex:
            self.logger.error("Exception: %s" % ex)
            self.send_header('Message-Type', \
                typeEnums.TRANSFER_COMPONENT_RESPONSE)
            self.send_response(HTTP_INTERNAL_SERVER_ERROR)
            self.end_headers()
            return

        #if transfer_component_map is empty then send HTTP_OK to GL
        if not transfer_component_map:
            self.logger.info(
                "Deserialized transfer component map is empty, return HTTP OK!"
            )
            comp_transfer_response = TransferCompResponseMessage(\
                self.final_transfer_status_list, True)
            serialized_body = comp_transfer_response.serialize()

            self.send_header('Message-Type', \
                typeEnums.TRANSFER_COMPONENT_RESPONSE)
            self.send_header('Content-Length', len(serialized_body))
            self.send_response(HTTP_OK)
            self.end_headers()
            self.wfile.write(serialized_body)
            return

        for dest_node_obj, comp_list in transfer_component_map.items():
            for comp in comp_list:
                self.deleted_comp_list.append(comp)
                self.final_transfer_status_list.append((comp, False))
            self.check_transfer_component_map[dest_node_obj] = False
        self.logger.debug("Ownership for components:%s will be removed" %
                          self.deleted_comp_list)
        self.delete_self_ownership()
        transfer_comp_event = self.msg.get_transfer_cmp_event()
        transfer_comp_event.set()

        try:
            #sending accept component request to other nodes
            self.logger.info("Sending accept component request to " \
                "destination nodes")
            for target_service_obj, comp_list in transfer_component_map.items(
            ):
                thread_connecting_node = threading.Thread(target = \
                    self.send_accept_component_request, args = \
                    ("ACCEPT_COMPONENT_TRANSFER", target_service_obj, \
                    comp_list, ))
                thread_connecting_node.setDaemon(True)
                thread_connecting_node.start()

            #Checking if transfer component completed and intermediate
            #response sent or not
            self.logger.info("Checking if transfer component completed")
            thread_check_transfer_status = threading.Thread(target = \
                self.check_component_transfer_completion)
            thread_check_transfer_status.setDaemon(True)
            thread_check_transfer_status.start()
            thread_check_transfer_status.join(transfer_component_timeout)

            # sending final response to GL
            self.logger.info("Sending final response to GL :%s" \
                % self.final_transfer_status_list)
            if self.final_transfer_status_list:
                for comp_status_tuple in self.final_transfer_status_list:
                    if not comp_status_tuple[1]:
                        self.logger.warning("Final transfer component list having failed" \
                            "component:%s, %s" %(comp_status_tuple[0], comp_status_tuple[1]))
                        self.msg.set_ownershipList(self.old_ownership_list)
                        break
                else:
                    self.final_status = True
            comp_transfer_response = TransferCompResponseMessage(\
                self.final_transfer_status_list, self.final_status)
            serialized_body = comp_transfer_response.serialize()

            while len(all_transfer_event_received) != 4:
                all_transfer_event_received.append(self.msg.get_from_Queue())

            self.logger.info("Completed TRANSFER_COMPONENTS request")
            self.send_header('Message-Type', \
                typeEnums.TRANSFER_COMPONENT_RESPONSE)
            self.send_header('Content-Length', len(serialized_body))
            self.send_response(HTTP_OK)
            self.end_headers()
            self.wfile.write(serialized_body)
            transfer_comp_event.clear()
            return
        except Exception as ex:
            self.logger.error("Exception raised: %s" % ex)
            transfer_comp_event.clear()
            self.msg.set_ownershipList(self.old_ownership_list)
            self.logger.error("old_ownership_list:%s" %
                              self.old_ownership_list)
            self.send_header('Message-Type', \
                typeEnums.TRANSFER_COMPONENT_RESPONSE)
            self.send_response(HTTP_INTERNAL_SERVER_ERROR)
            self.end_headers()
Ejemplo n.º 7
0
    'node_timeout': 10,
    'osd_dir': '/texport/osd_meta_config',
    'reader_max_count': 10,
    'max_update_files': 10,
    'log_file': 'accountUpdater.log',
    'log_facility': 'LOG_LOCAL6',
    'log_level': 'debug',
    'log_path': '/remote/hydra042/anishaj/osd/objectStorage_accUpdater_logger',
    'log_backup_count': 3,
    'll_port': 61014,
    'account_updater_port': 3128,
    'max_thread': 10,
    'client_timeout': 10,
    'max_files_stored_in_cache': 100
}
logger = SimpleLogger(conf).get_logger_object()
acc_map = list()
cont_map = list()
obj_map = list()
au_map = list()
acc_id = list()
acc_ip = list()
acc_port = list()
cont_id = list()
cont_ip = list()
cont_port = list()
obj_id = list()
obj_ip = list()
obj_port = list()
au_id = list()
au_ip = list()