示例#1
0
    def restart(
            self, suite_name=None, host=None, gcontrol_mode=None, args=None):
        """Restart a "cylc" suite."""
        # Check suite engine specific compatibility
        self.suite_engine_proc.check_global_conf_compat()

        if not suite_name:
            suite_name = get_suite_name(self.event_handler)

        suite_dir = self.suite_engine_proc.get_suite_dir(suite_name)
        if not os.path.exists(suite_dir):
            raise SuiteNotFoundError(suite_dir)

        # Ensure suite is not running
        self.suite_engine_proc.check_suite_not_running(suite_name)

        # Restart the suite
        self.suite_engine_proc.run(suite_name, host, "restart", args)

        # Launch the monitoring tool
        # Note: maybe use os.ttyname(sys.stdout.fileno())?
        if gcontrol_mode:
            self.suite_engine_proc.gcontrol(suite_name)

        return
示例#2
0
    def restart(self,
                suite_name=None,
                host=None,
                gcontrol_mode=None,
                args=None):
        """Restart a "cylc" suite."""
        # Check suite engine specific compatibility
        self.suite_engine_proc.check_global_conf_compat()

        if not suite_name:
            suite_name = get_suite_name(self.event_handler)

        suite_dir = self.suite_engine_proc.get_suite_dir(suite_name)
        if not os.path.exists(suite_dir):
            raise SuiteNotFoundError(suite_dir)

        # Ensure suite is not running
        self.suite_engine_proc.check_suite_not_running(suite_name)

        # Restart the suite
        self.suite_engine_proc.run(suite_name, host, "restart", args)

        # Launch the monitoring tool
        # Note: maybe use os.ttyname(sys.stdout.fileno())?
        if gcontrol_mode:
            self.suite_engine_proc.gcontrol(suite_name)

        return
示例#3
0
    def restart(self,
                suite_name=None,
                host=None,
                gcontrol_mode=None,
                args=None):
        """Restart a "cylc" suite."""
        # Check suite engine specific compatibility
        self.suite_engine_proc.check_global_conf_compat()

        if not suite_name:
            suite_name = get_suite_name(self.event_handler)

        suite_dir = self.suite_engine_proc.get_suite_dir(suite_name)
        if not os.path.exists(suite_dir):
            raise SuiteNotFoundError(suite_dir)

        # Ensure suite is not running
        self.suite_engine_proc.check_suite_not_running(suite_name)

        # Determine suite host to restart suite
        if host:
            hosts = [host]
        else:
            hosts = []
            val = ResourceLocator.default().get_conf().get_value(
                ["rose-suite-run", "hosts"], "localhost")
            for known_host in val.split():
                if known_host not in hosts:
                    hosts.append(known_host)

        if hosts == ["localhost"]:
            host = hosts[0]
        else:
            host = self.host_selector(hosts)[0][0]
        self.handle_event(SuiteHostSelectEvent(suite_name, "restart", host))

        # Suite host environment
        run_conf_file_name = self.suite_engine_proc.get_suite_dir(
            suite_name, "log", "rose-suite-run.conf")
        try:
            run_conf = ConfigLoader().load(run_conf_file_name)
        except (ConfigSyntaxError, IOError):
            environ = None
        else:
            run_conf_tree = ConfigTree()
            run_conf_tree.node = run_conf
            environ = self.config_pm(run_conf_tree, "env")

        # Restart the suite
        self.suite_engine_proc.run(suite_name, host, environ, "restart", args)

        # Launch the monitoring tool
        # Note: maybe use os.ttyname(sys.stdout.fileno())?
        if os.getenv("DISPLAY") and host and gcontrol_mode:
            self.suite_engine_proc.gcontrol(suite_name, host)

        return
示例#4
0
文件: suite_log.py 项目: kinow/rose
def suite_log_view(opts, args, event_handler=None):
    """Implement "rose suite-log" CLI functionality."""
    suite_engine_proc = SuiteEngineProcessor.get_processor(
        event_handler=event_handler)
    opts.update_mode = (opts.update_mode or opts.archive_mode
                        or opts.force_mode)
    if opts.force_mode:
        args = ["*"]
    if not opts.name:
        opts.name = get_suite_name(event_handler)
        if not opts.update_mode and not opts.user:
            opts.user = pwd.getpwuid(os.stat(".").st_uid).pw_name
    if opts.archive_mode:
        suite_engine_proc.job_logs_archive(opts.name, args)
    elif opts.update_mode:
        suite_engine_proc.job_logs_pull_remote(opts.name, args,
                                               opts.prune_remote_mode,
                                               opts.force_mode)
    if opts.view_mode or not opts.update_mode:
        n_tries_left = 1
        is_rose_bush_started = False
        url = suite_engine_proc.get_suite_log_url(opts.user, opts.name)
        if url.startswith("file://"):
            if (opts.non_interactive or
                    raw_input("Start rose bush? [y/n] (default=n) ") == "y"):
                suite_engine_proc.popen.run_bg("rose",
                                               "bush",
                                               "start",
                                               preexec_fn=os.setpgrp)
                is_rose_bush_started = True
                n_tries_left = 5  # Give the server a chance to start
        while n_tries_left:
            n_tries_left -= 1
            if n_tries_left:
                url = suite_engine_proc.get_suite_log_url(opts.user, opts.name)
                if url.startswith("file://"):
                    sleep(1)
                    continue
            suite_engine_proc.launch_suite_log_browser(opts.user, opts.name)
            break
        if is_rose_bush_started:
            status = suite_engine_proc.popen("rose", "bush")[0]
            event_handler(RoseBushStartEvent(status))
    return
示例#5
0
def suite_log_view(opts, args, event_handler=None):
    """Implement "rose suite-log" CLI functionality."""
    suite_engine_proc = SuiteEngineProcessor.get_processor(
        event_handler=event_handler)
    opts.update_mode = (
        opts.update_mode or opts.archive_mode or opts.force_mode)
    if opts.force_mode:
        args = ["*"]
    if not opts.name:
        opts.name = get_suite_name(event_handler)
        if not opts.update_mode and not opts.user:
            opts.user = pwd.getpwuid(os.stat(".").st_uid).pw_name
    if opts.archive_mode:
        suite_engine_proc.job_logs_archive(opts.name, args)
    elif opts.update_mode:
        suite_engine_proc.job_logs_pull_remote(
            opts.name, args, opts.prune_remote_mode, opts.force_mode)
    if opts.view_mode or not opts.update_mode:
        n_tries_left = 1
        is_rose_bush_started = False
        url = suite_engine_proc.get_suite_log_url(opts.user, opts.name)
        if url.startswith("file://"):
            if (opts.non_interactive or
                    raw_input("Start rose bush? [y/n] (default=n) ") == "y"):
                suite_engine_proc.popen.run_bg(
                    "rose", "bush", "start", preexec_fn=os.setpgrp)
                is_rose_bush_started = True
                n_tries_left = 5  # Give the server a chance to start
        while n_tries_left:
            n_tries_left -= 1
            if n_tries_left:
                url = suite_engine_proc.get_suite_log_url(opts.user, opts.name)
                if url.startswith("file://"):
                    sleep(1)
                    continue
            suite_engine_proc.launch_suite_log_browser(opts.user, opts.name)
            break
        if is_rose_bush_started:
            status = suite_engine_proc.popen("rose", "bush")[0]
            event_handler(RoseBushStartEvent(status))
    return
示例#6
0
    def restart(
            self, suite_name=None, host=None, gcontrol_mode=None, args=None):
        """Restart a "cylc" suite."""
        # Check suite engine specific compatibility
        self.suite_engine_proc.check_global_conf_compat()

        if not suite_name:
            suite_name = get_suite_name(self.event_handler)

        suite_dir = self.suite_engine_proc.get_suite_dir(suite_name)
        if not os.path.exists(suite_dir):
            raise SuiteNotFoundError(suite_dir)

        # Ensure suite is not running
        hosts = []
        if host:
            hosts.append(host)
        self.suite_engine_proc.check_suite_not_running(suite_name, hosts)

        # Determine suite host to restart suite
        if host:
            hosts = [host]
        else:
            hosts = []
            val = ResourceLocator.default().get_conf().get_value(
                ["rose-suite-run", "hosts"], "localhost")
            known_hosts = self.host_selector.expand(val.split())[0]
            for known_host in known_hosts:
                if known_host not in hosts:
                    hosts.append(known_host)

        if hosts == ["localhost"]:
            host = hosts[0]
        else:
            host = self.host_selector(hosts)[0][0]
        self.handle_event(SuiteHostSelectEvent(suite_name, "restart", host))

        # Suite host environment
        run_conf_file_name = self.suite_engine_proc.get_suite_dir(
            suite_name, "log", "rose-suite-run.conf")
        try:
            run_conf = ConfigLoader().load(run_conf_file_name)
        except (ConfigSyntaxError, IOError):
            environ = None
        else:
            run_conf_tree = ConfigTree()
            run_conf_tree.node = run_conf
            environ = self.config_pm(run_conf_tree, "env")

        # Restart the suite
        self.suite_engine_proc.run(suite_name, host, environ, "restart", args)

        # Write suite host name to host file
        host_file_name = self.suite_engine_proc.get_suite_dir(
            suite_name, "log", "rose-suite-run.host")
        open(host_file_name, "w").write(host + "\n")

        # Launch the monitoring tool
        # Note: maybe use os.ttyname(sys.stdout.fileno())?
        if os.getenv("DISPLAY") and host and gcontrol_mode:
            self.suite_engine_proc.gcontrol(suite_name, host)

        return