예제 #1
0
    def build_task_descriptor(cls,
                              task_descriptor,
                              parent_task_record,
                              args,
                              n_outputs,
                              is_tail_spawn=False,
                              handler_name=None):

        # This is needed to work around the fact that stdinout has its own implementation of build_task_descriptor, so
        # we can't rely using cls.handler_name to find the actual executor.
        if handler_name is None:
            handler_name = cls.handler_name

        if is_tail_spawn and len(
                task_descriptor["expected_outputs"]) != n_outputs:
            raise BlameUserException(
                "SimpleExecutor being built with delegated outputs %s but n_outputs=%d"
                % (task_descriptor["expected_outputs"], n_outputs))

        # Throw early if the args are bad
        cls.check_args_valid(args, n_outputs)

        # Discover required ref IDs for this executor
        reqd_refs = cls.get_required_refs(args)
        task_descriptor["dependencies"].extend(reqd_refs)

        sha = hashlib.sha1()
        hash_update_with_structure(sha, [args, n_outputs])
        name_prefix = "%s:%s:" % (handler_name, sha.hexdigest())

        # Name our outputs
        if not is_tail_spawn:
            task_descriptor["expected_outputs"] = [
                "%s%d" % (name_prefix, i) for i in range(n_outputs)
            ]

        # Add the args dict
        args_name = "%ssimple_exec_args" % name_prefix
        args_ref = ref_from_object(args, "pickle", args_name)
        parent_task_record.publish_ref(args_ref)
        task_descriptor["dependencies"].append(args_ref)
        task_descriptor["task_private"]["simple_exec_args"] = args_ref

        BaseExecutor.build_task_descriptor(task_descriptor, parent_task_record)

        if is_tail_spawn:
            return None
        else:
            return [
                SW2_FutureReference(x)
                for x in task_descriptor["expected_outputs"]
            ]
예제 #2
0
    def run(self):
        ciel.engine.publish("worker_event", "Start execution " + repr(self.task_descriptor['task_id']) + " with handler " + self.task_descriptor['handler'])
        ciel.log.error("Starting task %s with handler %s" % (str(self.task_descriptor['task_id']), self.task_descriptor['handler']), 'TASK', logging.DEBUG, False)
        try:
            self.start_time = datetime.datetime.now()
            
            # Need to do this to bring task_private into the execution context.
            BaseExecutor.prepare_task_descriptor_for_execute(self.task_descriptor, self, self.block_store)
        
            if "package_ref" in self.task_descriptor["task_private"]:
                self.package_ref = self.task_descriptor["task_private"]["package_ref"]
            else:
                self.package_ref = None
            
            with self._executor_lock:
                if self.aborted:
                    raise AbortedException()
                else:
                    self.executor = self.execution_features.get_executor(self.task_descriptor["handler"], self.worker)

            self.executor.run(self.task_descriptor, self)
            self.finish_time = datetime.datetime.now()
            
            self.success = not self.failed
            
            ciel.engine.publish("worker_event", "Completed execution " + repr(self.task_descriptor['task_id']))
            ciel.log.error("Completed task %s with handler %s" % (str(self.task_descriptor['task_id']), self.task_descriptor['handler']), 'TASK', logging.DEBUG, False)
        except MissingInputException as mie:
            ciel.log.error('Missing input in task %s with handler %s' % (str(self.task_descriptor['task_id']), self.task_descriptor['handler']), 'TASKEXEC', logging.ERROR, True)
            self.failure_bindings = mie.bindings
            self.failure_details = ""
            self.failure_reason = "MISSING_INPUT"
            self.finish_time = datetime.datetime.now()
            self.success = False
            raise
        except AbortedException:
            self.finish_time = datetime.datetime.now()
            self.success = False
            raise
        except Exception, e:
            ciel.log.error("Error in task %s with handler %s" % (str(self.task_descriptor['task_id']), self.task_descriptor['handler']), 'TASK', logging.ERROR, True)
            self.failure_bindings = dict()
            self.failure_details = getattr(e, "message", '')
            self.failure_reason = "RUNTIME_EXCEPTION"
            self.finish_time = datetime.datetime.now()
            self.success = False
            raise
예제 #3
0
파일: simple.py 프로젝트: ZubairNabi/ciel
    def build_task_descriptor(cls, task_descriptor, parent_task_record, args, n_outputs, is_tail_spawn=False, handler_name=None):

        # This is needed to work around the fact that stdinout has its own implementation of build_task_descriptor, so
        # we can't rely using cls.handler_name to find the actual executor.
        if handler_name is None:
            handler_name = cls.handler_name

        if is_tail_spawn and len(task_descriptor["expected_outputs"]) != n_outputs:
            raise BlameUserException("SimpleExecutor being built with delegated outputs %s but n_outputs=%d" % (task_descriptor["expected_outputs"], n_outputs))

        # Throw early if the args are bad
        cls.check_args_valid(args, n_outputs)

        # Discover required ref IDs for this executor
        reqd_refs = cls.get_required_refs(args)
        task_descriptor["dependencies"].extend(reqd_refs)

        sha = hashlib.sha1()
        hash_update_with_structure(sha, [args, n_outputs])
        name_prefix = "%s:%s:" % (handler_name, sha.hexdigest())

        # Name our outputs
        if not is_tail_spawn:
            task_descriptor["expected_outputs"] = ["%s%d" % (name_prefix, i) for i in range(n_outputs)]

        # Add the args dict
        args_name = "%ssimple_exec_args" % name_prefix
        args_ref = ref_from_object(args, "pickle", args_name)
        parent_task_record.publish_ref(args_ref)
        task_descriptor["dependencies"].append(args_ref)
        task_descriptor["task_private"]["simple_exec_args"] = args_ref
        
        BaseExecutor.build_task_descriptor(task_descriptor, parent_task_record)

        if is_tail_spawn:
            return None
        else:
            return [SW2_FutureReference(x) for x in task_descriptor["expected_outputs"]]
예제 #4
0
 def __init__(self, worker):
     BaseExecutor.__init__(self, worker)
예제 #5
0
파일: proc.py 프로젝트: jepst/ciel
 def __init__(self, worker):
     BaseExecutor.__init__(self, worker)
     self.process_pool = worker.process_pool
     self.ongoing_fetches = []
     self.ongoing_outputs = dict()
     self.transmit_lock = threading.Lock()
예제 #6
0
파일: simple.py 프로젝트: ZubairNabi/ciel
 def __init__(self, worker):
     BaseExecutor.__init__(self, worker)
예제 #7
0
 def __init__(self, worker):
     BaseExecutor.__init__(self, worker)
     self.process_pool = worker.process_pool
     self.ongoing_fetches = []
     self.ongoing_outputs = dict()
     self.transmit_lock = threading.Lock()
예제 #8
0
    def run(self):
        ciel.engine.publish(
            "worker_event",
            "Start execution " + repr(self.task_descriptor['task_id']) +
            " with handler " + self.task_descriptor['handler'])
        ciel.log.error(
            "Starting task %s with handler %s" %
            (str(self.task_descriptor['task_id']),
             self.task_descriptor['handler']), 'TASK', logging.DEBUG, False)
        try:
            self.start_time = datetime.datetime.now()

            # Need to do this to bring task_private into the execution context.
            BaseExecutor.prepare_task_descriptor_for_execute(
                self.task_descriptor, self, self.block_store)

            if "package_ref" in self.task_descriptor["task_private"]:
                self.package_ref = self.task_descriptor["task_private"][
                    "package_ref"]
            else:
                self.package_ref = None

            with self._executor_lock:
                if self.aborted:
                    raise AbortedException()
                else:
                    self.executor = self.execution_features.get_executor(
                        self.task_descriptor["handler"], self.worker)

            self.executor.run(self.task_descriptor, self)
            self.finish_time = datetime.datetime.now()

            self.success = not self.failed

            ciel.engine.publish(
                "worker_event",
                "Completed execution " + repr(self.task_descriptor['task_id']))
            ciel.log.error(
                "Completed task %s with handler %s" %
                (str(self.task_descriptor['task_id']),
                 self.task_descriptor['handler']), 'TASK', logging.DEBUG,
                False)
        except MissingInputException as mie:
            ciel.log.error(
                'Missing input in task %s with handler %s' %
                (str(self.task_descriptor['task_id']),
                 self.task_descriptor['handler']), 'TASKEXEC', logging.ERROR,
                True)
            self.failure_bindings = mie.bindings
            self.failure_details = ""
            self.failure_reason = "MISSING_INPUT"
            self.finish_time = datetime.datetime.now()
            self.success = False
            raise
        except AbortedException:
            self.finish_time = datetime.datetime.now()
            self.success = False
            raise
        except Exception, e:
            ciel.log.error(
                "Error in task %s with handler %s" %
                (str(self.task_descriptor['task_id']),
                 self.task_descriptor['handler']), 'TASK', logging.ERROR, True)
            self.failure_bindings = dict()
            self.failure_details = getattr(e, "message", '')
            self.failure_reason = "RUNTIME_EXCEPTION"
            self.finish_time = datetime.datetime.now()
            self.success = False
            raise