示例#1
0
 def _do_enqueue_procedures(self, within_procedure, actions,
                            lockable_objects):
     """Schedule a set of procedures.
     """
     procedures = None
     executor = ExecutorThread.executor_object()
     if not executor:
         if within_procedure:
             raise _errors.ProgrammingError(
                 "One can only create a new job from a job."
             )
         procedures, jobs = self._create_jobs(actions, lockable_objects)
         assert(len(set(procedures)) == len(set(jobs)))
         # There is no need to catch exceptions at this point. They will
         # be automatically caught by the caller which is usually the
         # XML-RPC session thread.
         _checkpoint.register(jobs, False)
         self.__scheduler.enqueue_procedures(procedures)
     else:
         current_job = executor.current_job
         current_procedure = current_job.procedure
         if within_procedure:
             procedures, jobs = self._create_jobs(
                 actions, lockable_objects, current_procedure.uuid
             )
             assert(set([job.procedure for job in jobs]) ==
                    set(procedures) == set([current_procedure])
             )
             current_job.append_jobs(jobs)
         else:
             procedures, jobs = self._create_jobs(actions, lockable_objects)
             assert(len(set(procedures)) == len(set(jobs)))
             current_job.append_procedures(procedures)
     assert(procedures is not None)
     return procedures
示例#2
0
 def _do_enqueue_procedures(self, within_procedure, actions,
                            lockable_objects):
     """Schedule a set of procedures.
     """
     procedures = None
     executor = ExecutorThread.executor_object()
     if not executor:
         if within_procedure:
             raise _errors.ProgrammingError(
                 "One can only create a new job from a job.")
         procedures, jobs = self._create_jobs(actions, lockable_objects)
         assert (len(set(procedures)) == len(set(jobs)))
         # There is no need to catch exceptions at this point. They will
         # be automatically caught by the caller which is usually the
         # XML-RPC session thread.
         _checkpoint.register(jobs, False)
         self.__scheduler.enqueue_procedures(procedures)
     else:
         current_job = executor.current_job
         current_procedure = current_job.procedure
         if within_procedure:
             procedures, jobs = self._create_jobs(actions, lockable_objects,
                                                  current_procedure.uuid)
             assert (set([job.procedure for job in jobs]) == set(procedures)
                     == set([current_procedure]))
             current_job.append_jobs(jobs)
         else:
             procedures, jobs = self._create_jobs(actions, lockable_objects)
             assert (len(set(procedures)) == len(set(jobs)))
             current_job.append_procedures(procedures)
     assert (procedures is not None)
     return procedures
示例#3
0
    def _commit_context(self, persister, scheduler, queue):
        """Commit transactional context.
        """
        registered_jobs = False
        try:
            # Register information on jobs created within the context of the
            # current job.
            _checkpoint.register(self.__jobs, True)

            # Register information on procedures created within the context
            # of the current job.
            for procedure in self.__procedures:
                assert(len(procedure.get_executed_jobs()) == 0)
                _checkpoint.register(procedure.get_registered_jobs(), True)

            # Register that the job has finished the execution.
            if self.__is_recoverable:
                self.__checkpoint.finish()

            registered_jobs = True

        except _errors.DatabaseError as error:
            _LOGGER.error(
                "Error in %s registering new jobs/procedures.",
                self.__action.__name__, exc_info=error
            )

        if registered_jobs:
            committed = False

            try:
                # Commit the job transactional context.
                # Currently, if the commit fails, we are not sure whether the
                # changes have succeeded or not. This is something that needs
                # to be improved in the near future.
                persister.commit()

                # Schedule jobs and procedures created within the context
                # of the current job.
                queue.schedule(self.__jobs)
                scheduler.enqueue_procedures(self.__procedures)

                committed = True

            except _errors.DatabaseError as error:
                _LOGGER.error(
                    "Error in %s committing job's context.",
                    self.__action.__name__, exc_info=error
                )

            if committed:
                # Update the job status.
                message = \
                    "Executed action ({0}).".format(self.__action.__name__)
                self._add_status(Job.SUCCESS, Job.COMPLETE, message)

                # Finish context which means mark the job as finished
                # and update procedure's information.
                self._finish_context(True)

                return

        # It was not possible to commit the current job.
        self._rollback_context(persister)
示例#4
0
    def _commit_context(self, persister, scheduler, queue):
        """Commit transactional context.
        """
        registered_jobs = False
        try:
            # Register information on jobs created within the context of the
            # current job.
            _checkpoint.register(self.__jobs, True)

            # Register information on procedures created within the context
            # of the current job.
            for procedure in self.__procedures:
                assert (len(procedure.get_executed_jobs()) == 0)
                _checkpoint.register(procedure.get_registered_jobs(), True)

            # Register that the job has finished the execution.
            if self.__is_recoverable:
                self.__checkpoint.finish()

            registered_jobs = True

        except _errors.DatabaseError as error:
            _LOGGER.error("Error in %s registering new jobs/procedures.",
                          self.__action.__name__,
                          exc_info=error)

        if registered_jobs:
            committed = False

            try:
                # Commit the job transactional context.
                # Currently, if the commit fails, we are not sure whether the
                # changes have succeeded or not. This is something that needs
                # to be improved in the near future.
                persister.commit()

                # Schedule jobs and procedures created within the context
                # of the current job.
                queue.schedule(self.__jobs)
                scheduler.enqueue_procedures(self.__procedures)

                committed = True

            except _errors.DatabaseError as error:
                _LOGGER.error("Error in %s committing job's context.",
                              self.__action.__name__,
                              exc_info=error)

            if committed:
                # Update the job status.
                message = \
                    "Executed action ({0}).".format(self.__action.__name__)
                self._add_status(Job.SUCCESS, Job.COMPLETE, message)

                # Finish context which means mark the job as finished
                # and update procedure's information.
                self._finish_context(True)

                return

        # It was not possible to commit the current job.
        self._rollback_context(persister)