示例#1
0
文件: task.py 项目: bronhaim/vdsm
 def resourceAcquired(self, namespace, resource, locktype):
     # Callback from resourceManager.Owner. May be called by another thread.
     self._incref()
     try:
         self.callbackLock.acquire()
         try:
             self.log.debug("_resourcesAcquired: %s.%s (%s)", namespace,
                            resource, locktype)
             if self.state == State.preparing:
                 return
             if self.state == State.acquiring:
                 self._updateState(State.acquiring)
             elif self.state == State.racquiring:
                 self._updateState(State.racquiring)
             elif self.state == State.blocked:
                 self._updateState(State.preparing)
             elif (self.state == State.aborting
                   or self.state == State.raborting):
                 self.log.debug("resource %s.%s acquired while in state %s",
                                namespace, resource, self.state)
             else:
                 raise se.TaskStateError("acquire is not allowed in state"
                                         " %s" % self.state)
         finally:
             self.callbackLock.release()
     finally:
         self._decref()
示例#2
0
文件: task.py 项目: bronhaim/vdsm
 def persist(self):
     if self.persistPolicy == TaskPersistType.none:
         return
     if not self.store:
         raise se.TaskPersistError("no store defined")
     if self.state == State.init:
         raise se.TaskStateError("can't persist in state %s" % self.state)
     self._save(self.store)
示例#3
0
文件: task.py 项目: ZhangNatural/vdsm
 def _runJobs(self):
     result = ""
     code = 100
     message = "Unknown Error"
     i = 0
     j = None
     try:
         if self.aborting():
             raise se.TaskAborted("shutting down")
         if not self.state == State.running:
             raise se.TaskStateError("%s: can't run Jobs in state %s" %
                                     (self, self.state))
         # for now: result is the last job result, jobs are run sequentially
         for j in self.jobs:
             if self.aborting():
                 raise se.TaskAborted("shutting down")
             self.log.debug("Task.run: running job %s: %s" % (i, j))
             self._updateResult(
                 0, 'running job {0} of {1}'.format(i + 1, len(self.jobs)),
                 '')
             result = self._run(j.run)
             if self.aborting():
                 raise se.TaskAborted("shutting down")
             if result is None:
                 result = ""
             i += 1
         j = None
         self._updateResult(0, "%s jobs completed successfully" % i, result)
         self._updateState(State.finished)
         self.log.debug('Task.run: exit - success: result %s' % result)
         return result
     except se.TaskAborted as e:
         self.log.debug("aborting: %s", e)
         message = e.value
         code = e.abortedcode
         if not self.aborting():
             self.log.error("Aborted exception but not in aborting state")
             raise
     self._updateResult(code, message, "")
示例#4
0
文件: task.py 项目: ZhangNatural/vdsm
 def _recover(self):
     self.log.debug("_recover")
     if not self.state == State.recovering:
         raise se.TaskStateError("%s: _recover in state %s" %
                                 (self, self.state))
     try:
         while self.state == State.recovering:
             rec = self.popRecovery()
             self.log.debug("running recovery %s", rec)
             if not rec:
                 break
             self._run(rec.run)
     except Exception as e:
         self.log.warning("task %s: recovery failed: %s",
                          self, e, exc_info=True)
         # protect agains races with stop/abort
         try:
             if self.state == State.recovering:
                 self._updateState(State.raborting)
         except se.TaskStateTransitionError:
             pass
     self._recoverDone()
示例#5
0
文件: task.py 项目: bronhaim/vdsm
 def clean(self):
     if not self.store:
         return
     if not self.isDone():
         raise se.TaskStateError("can't clean in state %s" % self.state)
     self._clean(self.store)