コード例 #1
0
ファイル: component.py プロジェクト: exxeleron/yak
    def initialize(self, init_std_paths = True):
        self.started = self.timestamp()
        self.started_by = osutil.get_username()

        self.stopped = None
        self.stopped_by = None

        self.data_path = self.configuration.data_path
        self.log_path = self.configuration.log_path

        tstamp = self.started.strftime(DT_FORMAT)

        if not os.path.exists(self.data_path):
            os.makedirs(self.data_path)
        if not os.path.exists(self.log_path):
            os.makedirs(self.log_path)

        if init_std_paths:
            if not self.configuration.silent:
                self.stdout = os.path.join(self.log_path, "{0}_{1}.out".format(self.uid, tstamp))
                self.stderr = os.path.join(self.log_path, "{0}_{1}.err".format(self.uid, tstamp))
                self.stdenv = os.path.join(self.log_path, "{0}_{1}.env".format(self.uid, tstamp))
            else:
                self.stdout = os.devnull
                self.stderr = os.devnull
                self.stdenv = os.devnull
コード例 #2
0
ファイル: component.py プロジェクト: bigxyt/yak
    def initialize(self, init_std_paths=True):
        self.started = self.timestamp()
        self.started_by = osutil.get_username()

        self.stopped = None
        self.stopped_by = None

        self.data_path = self.configuration.data_path
        self.log_path = self.configuration.log_path

        tstamp = self.started.strftime(DT_FORMAT)

        if not os.path.exists(self.data_path):
            os.makedirs(self.data_path)
        if not os.path.exists(self.log_path):
            os.makedirs(self.log_path)

        if init_std_paths:
            if not self.configuration.silent:
                self.stdout = os.path.join(
                    self.log_path, "{0}_{1}.out".format(self.uid, tstamp))
                self.stderr = os.path.join(
                    self.log_path, "{0}_{1}.err".format(self.uid, tstamp))
                self.stdenv = os.path.join(
                    self.log_path, "{0}_{1}.env".format(self.uid, tstamp))
            else:
                self.stdout = os.devnull
                self.stderr = os.devnull
                self.stdenv = os.devnull
コード例 #3
0
 def tracked_command(self, args):
     try:
         return f(self, args)
     except:
         print get_short_exc_info()
         ComponentManagerShell.logger.error(
             get_full_exc_info(), extra={"user": get_username()})
         return 1
コード例 #4
0
 def status_callback(component_uid, status):
     if status is None:
         print "\t{0:<30}\t.".format(component_uid)
     elif not isinstance(status, Exception):
         print "\t{0:<30}\t{1}".format(component_uid,
                                       "OK" if status else "Skipped")
     else:
         print "\t{0:<30}\tFailed".format(component_uid)
         ComponentManagerShell.logger.error(
             get_full_exc_info(), extra={"user": get_username()})
コード例 #5
0
ファイル: manager.py プロジェクト: SKolodynski/yak
    def _validate_preconditions(self, component_cfg):
        uname = get_username()
        if component_cfg.sys_user and not uname in component_cfg.sys_user:
            raise ComponentError("User {1} is not allowed to start component {0}".format(component_cfg.uid, uname))

        for required_uid in component_cfg.requires:
            if self._components.has_key(required_uid):
                required_component = self._components[required_uid]
                if not required_component.is_alive:
                    raise ComponentError("Cannot start component {0}, required component {1} not running".format(component_cfg.uid, required_uid))
            else:
                raise ComponentError("Cannot start component {0}, required component {1} not found".format(component_cfg.uid, required_uid))
コード例 #6
0
ファイル: manager.py プロジェクト: bigxyt/yak
    def _validate_preconditions(self, component_cfg):
        uname = get_username()
        if component_cfg.sys_user and not uname in component_cfg.sys_user:
            raise ComponentError("User {1} is not allowed to start component {0}".format(component_cfg.uid, uname))

        for required_uid in component_cfg.requires:
            if self._components.has_key(required_uid):
                required_component = self._components[required_uid]
                if not required_component.is_alive:
                    raise DependencyError("Cannot start component {0}, required component {1} not running".format(component_cfg.uid, required_uid))
            else:
                raise DependencyError("Cannot start component {0}, required component {1} not found".format(component_cfg.uid, required_uid))
コード例 #7
0
 def single_component_command(self, identifiers, params):
     ComponentManagerShell.logger.info("%s %s %s",
                                       f.func_name[3:],
                                       identifiers,
                                       params,
                                       extra={"user": get_username()})
     components = self._get_components_list(identifiers)
     if len(components) != 1:
         raise ComponentManagerShellError(
             "Command: '{0}' can only be performed on single component".
             format(f.__name__[3:]))
     self._manager.reload()
     return f(self, components[0], params)
コード例 #8
0
 def multi_components_command(self, identifiers, params):
     if identifiers:
         ComponentManagerShell.logger.info(
             "%s %s %s",
             f.func_name[3:],
             identifiers,
             params,
             extra={"user": get_username()})
         self._manager.reload()
         return f(self, self._get_components_list(identifiers), params)
     else:
         raise ComponentManagerShellError(
             "Command: '{0}' requires group, namespace or component id(s)"
             .format(f.__name__[3:]))
コード例 #9
0
ファイル: status.py プロジェクト: maciejlach/yak
 def _init_db_(self):
     connection = self._connection_()
     with connection:
         current_schema = connection.execute(
             "PRAGMA user_version").fetchone()[0]
         target_schema = max(self.__DB_UPGRADE_STEPS__)
         if current_schema < target_schema:
             connection.isolation_level = "EXCLUSIVE"
             logger = logging.getLogger("yak")
             for step in range(current_schema + 1, target_schema + 1):
                 if step in self.__DB_UPGRADE_STEPS__:
                     logger.info("Upgrading status file db schema: [%d/%d]",
                                 step,
                                 target_schema,
                                 extra={"user": get_username()})
                     connection.execute("BEGIN EXCLUSIVE")
                     connection.executescript(
                         self.__DB_UPGRADE_STEPS__[step])
                     connection.execute(
                         "PRAGMA user_version={:d}".format(step))
                     connection.commit()
コード例 #10
0
ファイル: yak.py プロジェクト: exxeleron/yak
 def status_callback(component_uid, status):
     if status is None:
         print "\t{0:<30}\t.".format(component_uid)
     elif not isinstance(status, Exception):
         print "\t{0:<30}\t{1}".format(component_uid, "OK" if status else "Skipped")
     else:
         print "\t{0:<30}\tFailed".format(component_uid)
         ComponentManagerShell.logger.error(get_full_exc_info(), extra = {"user": get_username()})
コード例 #11
0
ファイル: yak.py プロジェクト: exxeleron/yak
 def single_component_command(self, identifiers, params):
     ComponentManagerShell.logger.info("%s %s %s", f.func_name[3:], identifiers, params, extra = {"user": get_username()})
     components = self._get_components_list(identifiers)
     if len(components) != 1:
         raise ComponentManagerShellError("Command: '{0}' can only be performed on single component".format(f.__name__[3:]))
     self._manager.reload()
     return f(self, components[0], params)
コード例 #12
0
ファイル: yak.py プロジェクト: SKolodynski/yak
 def multi_components_command(self, args):
     if args :
         ComponentManagerShell.logger.info("%s %s", f.func_name[3:], args, extra = {"user": get_username()})
         self._manager.reload()
         return f(self, *self._get_components_list_and_params(args))
     else :
         raise ComponentManagerShellError("Group, namespace or component id required")
コード例 #13
0
ファイル: yak.py プロジェクト: exxeleron/yak
 def tracked_command(self, args):
     try:
         return f(self, args)
     except:
         print get_short_exc_info()
         ComponentManagerShell.logger.error(get_full_exc_info(), extra = {"user": get_username()})
         return 1
コード例 #14
0
ファイル: component.py プロジェクト: bigxyt/yak
 def terminate(self, force=False):
     osutil.terminate(self.pid, force)
     self.stopped = self.timestamp()
     self.stopped_by = osutil.get_username()
     self.pid = None
コード例 #15
0
ファイル: yak.py プロジェクト: SKolodynski/yak
    def _apply_command(self, command, components):
        failed = []
        for component_uid in components:
            try:
                status = command(component_uid)
                print "\t{0:<30}\t{1}".format(component_uid, "OK" if status else "Skipped")
            except:
                failed.append(component_uid)
                print "\t{0:<30}\tFailed: {1}".format(component_uid, get_short_exc_info())
                ComponentManagerShell.logger.error(get_full_exc_info(), extra = {"user": get_username()})

        if failed:
            for component_uid in failed:
                print HLINE
                print "stderr for component: {0}".format(component_uid)
                show_file(self._manager.components[component_uid].stderr, True)

            print HLINE
            return 1
コード例 #16
0
ファイル: yak.py プロジェクト: SKolodynski/yak
 def single_component_command(self, arg):
     ComponentManagerShell.logger.info("%s %s", f.func_name[3:], arg, extra = {"user": get_username()})
     components, params = self._get_components_list_and_params(arg)
     if len(components) != 1:
         raise ComponentManagerShellError("Operation can only be performed on single component")
     self._manager.reload()
     return f(self, components[0], params)
コード例 #17
0
ファイル: component.py プロジェクト: exxeleron/yak
 def terminate(self, force = False):
     osutil.terminate(self.pid, force)
     self.stopped = self.timestamp()
     self.stopped_by = osutil.get_username()
     self.pid = None
コード例 #18
0
ファイル: yak.py プロジェクト: exxeleron/yak
 def multi_components_command(self, identifiers, params):
     if identifiers:
         ComponentManagerShell.logger.info("%s %s %s", f.func_name[3:], identifiers, params, extra = {"user": get_username()})
         self._manager.reload()
         return f(self, self._get_components_list(identifiers), params)
     else:
         raise ComponentManagerShellError("Command: '{0}' requires group, namespace or component id(s)".format(f.__name__[3:]))