def finalize_execution(cls, actor_id, execution_id, status, stats, final_state, exit_code): """ Update an execution status and stats after the execution is complete or killed. `actor_id` should be the dbid of the actor. `execution_id` should be the id of the execution returned from a prior call to add_execution. `status` should be the final status of the execution. `stats` parameter should be a dictionary with io, cpu, and runtime. `final_state` parameter should be the `State` object returned from the docker inspect command. `exit_code` parameter should be the exit code of the container. """ params_str = "actor: {}. ex: {}. status: {}. final_state: {}. exit_code: {}. stats: {}".format( actor_id, execution_id, status, final_state, exit_code, stats) logger.debug("top of finalize_execution. Params: {}".format(params_str)) if not 'io' in stats: logger.error("Could not finalize execution. io missing. Params: {}".format(params_str)) raise errors.ExecutionException("'io' parameter required to finalize execution.") if not 'cpu' in stats: logger.error("Could not finalize execution. cpu missing. Params: {}".format(params_str)) raise errors.ExecutionException("'cpu' parameter required to finalize execution.") if not 'runtime' in stats: logger.error("Could not finalize execution. runtime missing. Params: {}".format(params_str)) raise errors.ExecutionException("'runtime' parameter required to finalize execution.") try: executions_store.update_subfield(actor_id, execution_id, 'status', status) executions_store.update_subfield(actor_id, execution_id, 'io', stats['io']) executions_store.update_subfield(actor_id, execution_id, 'cpu', stats['cpu']) executions_store.update_subfield(actor_id, execution_id, 'runtime', stats['runtime']) executions_store.update_subfield(actor_id, execution_id, 'final_state', final_state) executions_store.update_subfield(actor_id, execution_id, 'exit_code', exit_code) except KeyError: logger.error("Could not finalize execution. execution not found. Params: {}".format(params_str)) raise errors.ExecutionException("Execution {} not found.".format(execution_id))
def add_worker_id(cls, actor_id, execution_id, worker_id): """ :param actor_id: the id of the actor :param execution_id: the id of the execution :param worker_id: the id of the worker that executed this actor. :return: """ try: executions_store.update_subfield(actor_id, execution_id, 'worker_id', worker_id) except KeyError: raise errors.ExecutionException( "Execution {} not found.".format(execution_id))
def get_derived_value(self, name, d): """Compute a derived value for the attribute `name` from the dictionary d of attributes provided.""" # first, see if the attribute is already in the object: try: if d[name]: return d[name] except KeyError: pass # if not, compute and store all values, returning the one requested: try: dbid = d['db_id'] except KeyError: raise errors.ExecutionException('db_id is required.') tot = self.compute_summary_stats(dbid) d.update(tot) return tot[name]
def add_worker_id(cls, actor_id, execution_id, worker_id): """ :param actor_id: the id of the actor :param execution_id: the id of the execution :param worker_id: the id of the worker that executed this actor. :return: """ logger.debug("top of add_worker_id() for actor: {} execution: {} worker: {}".format( actor_id, execution_id, worker_id)) try: executions_store.update_subfield(actor_id, execution_id, 'worker_id', worker_id) logger.debug("worker added to execution: {} actor: {} worker: {}".format( execution_id, actor_id, worker_id)) except KeyError as e: logger.error("Could not add an execution. KeyError: {}. actor: {}. ex: {}. worker: {}".format( e, actor_id, execution_id, worker_id)) raise errors.ExecutionException("Execution {} not found.".format(execution_id))