Esempio n. 1
0
    def pause(self):
        """
        暂停状态机

        :return: None
        :raises EStatusMismatch: 状态不匹配
        """
        if self._status == self.Status.RUNNING:
            self._status = self.Status.PAUSED
        else:
            raise exception.EStatusMismatch(
                "Only in running status can call this method. "
                "current status:{}".format(self._status))
Esempio n. 2
0
    def resume(self):
        """
        恢复状态机

        :return: None
        :raises EStatusMismatch: 状态不匹配
        """
        if self._status == self.Status.PAUSED:
            self._status = self.Status.RUNNING
        else:
            raise exception.EStatusMismatch(
                "Only in paused status can call this method."
                "current status:{}".format(self._status))
Esempio n. 3
0
    def prepare(self):
        """
        状态机创建之后初次检查, 并设置当前状态节点

        :return: None
        :raises EUnInited: 未初始化
        :raises EStatusMismatch: 状态不匹配
        """
        if self._status != self.Status.CREATED \
                and self._status != self.Status.INITED:
            raise exception.EStatusMismatch(
                "Only in created or inited status can call "
                "this method.current status:{}".format(self._status))
        if not self._nodes:
            raise exception.EUnInited("nodes list length is 0")
        self.status = self.Status.INITED
        self._current_node = self._nodes[0].name
Esempio n. 4
0
    def start(self):
        """
        启动状态机

        :return: None
        :raises EStatusMismatch: 状态不匹配
        :raises Exception: 通用异常
        """
        self.prepare()
        if self._status == self.Status.INITED \
                or self._status == self.Status.PAUSED:
            self._status = self.Status.RUNNING
        else:
            raise exception.EStatusMismatch(
                "Only in inited or paused status can call "
                "this method.current status:{}".format(self._status))
        while self._status == self.Status.RUNNING:
            try:
                self.run_next()
            except Exception as e:
                self._status = self.Status.FAILED
                log.r(e, "start fail in run_next")