Beispiel #1
0
 def __init__(self, log, workspace, server_port):
     self.cd_log = log
     self.cd_running = True
     self.cd_url_client = "tcp://*:" + str(server_port)
     self.cd_url_worker = "inproc://workers"
     self.cd_context = zmq.Context.instance()
     self.cd_client_socket = self.cd_context.socket(zmq.ROUTER)
     self.cd_client_socket.bind(self.cd_url_client)
     self.cd_worker_socket = self.cd_context.socket(zmq.DEALER)
     self.cd_worker_socket.bind(self.cd_url_worker)
     self.cd_workspace = workspace
     for worker_index in range(COPYTOOLD_WORKER_NUMBER):
         log.cl_info("starting worker thread [%d]", worker_index)
         utils.thread_start(self.cd_worker_thread, (worker_index, ))
    def cc_command(self, thread_log, cmd_line, command_reply):
        """
        Run command for a connection
        """
        # pylint: disable=broad-except
        thread_log.cl_info("running command [%s]", cmd_line)
        log = self.cc_command_log
        log.cl_debug("start running the command on server")
        self.cc_last_retval = log.cl_result.cr_exit_status
        log.cl_result.cr_clear()
        log.cl_abort = False

        utils.thread_start(self.cc_cmdline_thread, (cmd_line, ))
        self.cc_consume_command_log(thread_log, command_reply)
        thread_log.cl_debug("returned reply of command [%s]", cmd_line)
    def cdqos_start(self, log):
        """
        Start the QoS for the file system
        """
        lustrefs = self.cdqos_lustrefs
        fsname = lustrefs.lf_fsname

        ret = lustrefs.lf_set_jobid_var(log, lustre.JOBID_VAR_PROCNAME_UID)
        if ret:
            log.cl_error("failed to set the jobid_var to [%s]",
                         lustre.JOBID_VAR_PROCNAME_UID)
            return -1

        for host in lustrefs.lf_oss_list():
            ret = host.lsh_enable_ost_io_tbf(log, lustre.TBF_TYPE_GENERAL)
            if ret:
                log.cl_error(
                    "failed to enable TBF for ost_io on file system "
                    "[%s]", fsname)
                return -1

        for host in lustrefs.lf_mds_list():
            ret = host.lsh_enable_mdt_tbf(log, lustre.TBF_TYPE_GENERAL)
            if ret:
                log.cl_error(
                    "failed to enable TBF for all MDT services on file system "
                    "[%s]", fsname)
                return -1

        self.cdqos_thread = utils.thread_start(self.cdqos_thread_main, ())
        return 0
Beispiel #4
0
 def hr_thread_start(self, parent_log):
     """
     Start the thread
     """
     ret = utils.mkdir(self.hr_workspace)
     if ret:
         return ret
     self.hr_thread = utils.thread_start(self.hr_thread_main, (parent_log, ))
     return 0
Beispiel #5
0
 def hc_thread_start(self, log):
     """
     Start the thread
     """
     if utils.mkdir(self.hc_workspace):
         log.cl_error("failed to create directory [%s] on local host, "
                      "exiting the thread",
                      self.hc_workspace)
         self.hc_status = -1
         return
     self.hc_thread = utils.thread_start(self.hc_thread_main, (log, ))
 def __init__(self, log, server_port, instance):
     self.cs_log = log
     self.cs_running = True
     self.cs_instance = instance
     assert isinstance(instance, clownfish.ClownfishInstance)
     self.cs_url_client = "tcp://*:" + str(server_port)
     self.cs_url_worker = "inproc://workers"
     self.cs_context = zmq.Context.instance()
     self.cs_client_socket = self.cs_context.socket(zmq.ROUTER)
     self.cs_client_socket.bind(self.cs_url_client)
     self.cs_worker_socket = self.cs_context.socket(zmq.DEALER)
     self.cs_worker_socket.bind(self.cs_url_worker)
     # Sequence is protected by cs_condition
     self.cs_sequence = 0
     # The key is the sequence of the connection, protected by cs_condition
     self.cs_connections = {}
     self.cs_condition = threading.Condition()
     for worker_index in range(CLOWNFISH_WORKER_NUMBER):
         log.cl_info("starting worker thread [%d]", worker_index)
         utils.thread_start(self.cs_worker_thread, (worker_index, ))
     utils.thread_start(self.cs_connection_cleanup_thread, ())
    def cc_loop(self, cmdline=None):
        """
        Loop and execute the command
        """
        # pylint: disable=unused-variable
        log = self.cc_log

        readline.parse_and_bind("tab: complete")
        readline.parse_and_bind("set editing-mode vi")
        # This enables completer of options with prefix "-" or "--"
        # becase "-" is one of the delimiters by default
        readline.set_completer_delims(" \t\n")
        readline.set_completer(self.cc_completer)
        while self.cc_running:
            if cmdline is None:
                try:
                    log.cl_debug(self.cc_prompt)
                    cmd_line = raw_input(self.cc_prompt)
                except (KeyboardInterrupt, EOFError):
                    log.cl_debug("keryboard interrupt recieved")
                    log.cl_info("")
                    log.cl_info("Type q to exit")
                    continue
                log.cl_debug("input: %s", cmd_line)
                cmd_line = cmd_line.strip()
                if len(cmd_line) == 0:
                    continue
            else:
                cmd_line = cmdline

            self.cc_abort_event.clear()
            command_thread = utils.thread_start(self.cc_command,
                                                (log, cmd_line))
            while command_thread.is_alive():
                try:
                    command_thread.join(CLOWNFISH_CONSOLE_QUERY_INTERVAL)
                except (KeyboardInterrupt, EOFError):
                    log.cl_debug("keryboard interrupt recieved")
                    log.cl_stderr("aborting command [%s]", cmd_line)
                    self.cc_abort_event.set()
                    continue

            # The server told us to quit the connection
            if log.cl_abort:
                break
            # not interactive mode
            if cmdline is not None:
                break

        readline.set_completer(None)
        return int(log.cl_result.cr_exit_status)
    def cc_init(self):
        """
        Init the connection to server
        """
        log = self.cc_log

        client = self.cc_client
        server_url = self.cc_server_url

        sequence = 0

        message = ClownfishConsoleMessage(
            0, clownfish_pb2.ClownfishMessage.CMT_CONNECT_REQUEST,
            clownfish_pb2.ClownfishMessage.CMT_CONNECT_REPLY)
        message.ccm_request.cm_connect_request.ccrt_client_hash = sequence
        log.cl_debug("connecting to server [%s]", server_url)
        ret = message.ccm_communicate(log, self.cc_poll, client,
                                      CLOWNFISH_CONSOLE_CONNECT_TIMEOUT)
        if ret:
            log.cl_error("failed to connect to server [%s]", server_url)
            return -1
        elif ret == 1:
            log.cl_error("failed to connect to server [%s]: no response",
                         server_url)
            return -1

        if message.ccm_reply.cm_connect_reply.ccry_client_hash != sequence:
            log.cl_error("wrong client hash [%d] in reply, expected [%d]",
                         message.ccm_reply.cm_connect_reply.ccry_client_hash,
                         sequence)
            return -1

        self.cc_uuid = message.ccm_reply.cm_client_uuid
        log.cl_debug("connected to server [%s] successfully, UUID is [%s]",
                     server_url, self.cc_uuid)
        utils.thread_start(self.cc_ping_thread, ())
        return 0
Beispiel #9
0
    def pt_thread_start(self, parent_log):
        """
        Start the thread
        """
        ret = utils.mkdir(self.pt_workspace)
        if ret:
            parent_log.cl_error("failed to create directory [%s]",
                                self.pt_workspace)
            return -1

        # The log for this thread
        log = self.pt_parallel_execute.pe_log.cl_get_child(
            self.pt_id, resultsdir=self.pt_workspace)
        self.pt_log = log
        log.cl_result.cr_clear()
        log.cl_abort = False
        self.pt_status = ParallelThread.STATUS_RUNNING
        self.pt_thread = utils.thread_start(self.pt_main, ())
        return 0
Beispiel #10
0
 def mop_start(self, log):
     """
     Start the process of multiop
     """
     utils.thread_start(self._mop_thread_main, (log))