コード例 #1
0
ファイル: q.py プロジェクト: maciejlach/yak
    def interactive(self):
        if self.configuration.q_path:
            path = os.environ.get("PATH", "")
            os.environ["PATH"] = self.configuration.q_path + os.pathsep + path

        try:
            if self.configuration.cpu_affinity:
                osutil.set_affinity(os.getpid(), self.configuration.cpu_affinity)

            if self.configuration.u_file and not os.path.isfile(self.configuration.u_file):
                raise ComponentError("Cannot locate uFile: {0}".format(self.configuration.u_file))

            env = self._bootstrap_environment()

            # overwrite logging configuration for interactive mode
            env["EC_LOG_DEST"] = "FILE,STDERR,CONSOLE"
            env["EC_LOG_LEVEL"] = "DEBUG"

            self.executed_cmd = str(self.configuration.full_cmd)
            p = subprocess.Popen(shlex.split(self.configuration.full_cmd, posix = False),
                                 cwd = self.configuration.bin_path,
                                 env = env
                                 )
            self.pid = p.pid
            super(QComponent, self).save_status()

            p.communicate()

            self.stopped = super(QComponent, self).timestamp()

            if p.returncode:
                raise ComponentError("Component {0} finished prematurely with code {1}".format(self.uid, p.returncode))
        finally:
            if self.configuration.q_path:
                os.environ["PATH"] = path
コード例 #2
0
    def _start(self, uid, **kwargs):
        """
        Starts component with given uid. If component is already running, nothing happens.
        @param uid: identifier of the component
        @return: True if component has been started, False if the component is already running.
        @raise ComponentError: if component cannot be started.
        """
        component = self._components[uid]
        component_cfg = self._configuration[
            uid] if uid in self._configuration else dict()

        if component.is_alive:
            return False

        self._validate_preconditions(component_cfg)

        overrides_arguments = kwargs and 'arguments' in kwargs and kwargs[
            'arguments'] is not None
        if overrides_arguments:
            arguments_copy = component_cfg.command_args
            component_cfg.command_args = kwargs['arguments']

        try:
            component.initialize()
            component.execute()
            self._components[uid] = component
            return True
        except:
            raise ComponentError("Error while executing: '{0}'\n{1}".format(
                component_cfg.full_cmd,
                sys.exc_info()[1]))
        finally:
            self._persistance.save_status(component)
            if overrides_arguments:
                component_cfg.command_args = arguments_copy
コード例 #3
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))
コード例 #4
0
ファイル: q.py プロジェクト: maciejlach/yak
    def execute(self):
        if self.configuration.q_path:
            path = os.environ.get("PATH", "")
            os.environ["PATH"] = self.configuration.q_path + os.pathsep + path

        try:
            if self.configuration.u_file and not os.path.isfile(self.configuration.u_file):
                raise ComponentError("Cannot locate uFile: {0}".format(self.configuration.u_file))

            super(QComponent, self).execute()
        finally:
            if self.configuration.q_path:
                os.environ["PATH"] = path
            self.log = None