def update_executed_workflow_state(self, operation): """ Used for updating the state of an executed workflow. Only if the operation with the specified id has resulted after the execution of an ExecutedWorkflowStep than the state of the ExecutedWorkflow to which belongs the step will be updated. """ executed_step, _ = self._get_data(operation.id) if executed_step is not None: if operation.status == model.STATUS_ERROR: all_executed_steps = dao.get_workflow_steps( executed_step.fk_workflow) for step in all_executed_steps: if step.step_index > executed_step.step_index: self.logger.debug( "Marking unreached operation %s with error." % step.fk_operation) unreached_operation = dao.get_operation_by_id( step.fk_operation) self.persist_operation_state( unreached_operation, model.STATUS_ERROR, "Blocked by failure in step %s with message: \n\n%s." % (executed_step.step_index, operation.additional_info)) workflow = dao.get_workflow_by_id(executed_step.fk_workflow) burst = dao.get_burst_by_id(workflow.fk_burst) self.mark_burst_finished(burst, error_message=operation.additional_info) dao.store_entity(burst)
def prepare_next_step(self, last_executed_op_id): """ If the operation with id 'last_executed_op_id' resulted after the execution of a workflow step then this method will launch the operation corresponding to the next step from the workflow. """ try: current_step, next_workflow_step = self._get_data(last_executed_op_id) if next_workflow_step is not None: operation = dao.get_operation_by_id(next_workflow_step.fk_operation) dynamic_param_names = next_workflow_step.dynamic_workflow_param_names if len(dynamic_param_names) > 0: op_params = json.loads(operation.parameters) for param_name in dynamic_param_names: dynamic_param = op_params[param_name] former_step = dao.get_workflow_step_by_step_index(next_workflow_step.fk_workflow, dynamic_param[wf_cfg.STEP_INDEX_KEY]) if type(dynamic_param[wf_cfg.DATATYPE_INDEX_KEY]) is IntType: datatypes = dao.get_results_for_operation(former_step.fk_operation) op_params[param_name] = datatypes[dynamic_param[wf_cfg.DATATYPE_INDEX_KEY]].gid else: previous_operation = dao.get_operation_by_id(former_step.fk_operation) op_params[param_name] = json.loads(previous_operation.parameters)[ dynamic_param[wf_cfg.DATATYPE_INDEX_KEY]] operation.parameters = json.dumps(op_params) operation = dao.store_entity(operation) return operation.id else: if current_step is not None: current_workflow = dao.get_workflow_by_id(current_step.fk_workflow) current_workflow.status = current_workflow.STATUS_FINISHED dao.store_entity(current_workflow) burst_entity = dao.get_burst_by_id(current_workflow.fk_burst) parallel_workflows = dao.get_workflows_for_burst(burst_entity.id) all_finished = True for workflow in parallel_workflows: if workflow.status == workflow.STATUS_STARTED: all_finished = False if all_finished: self.mark_burst_finished(burst_entity, success=True) disk_size = dao.get_burst_disk_size(burst_entity.id) # Transform from kB to MB if disk_size > 0: user = dao.get_project_by_id(burst_entity.fk_project).administrator user.used_disk_space = user.used_disk_space + disk_size dao.store_entity(user) else: operation = dao.get_operation_by_id(last_executed_op_id) disk_size = dao.get_disk_size_for_operation(operation.id) # Transform from kB to MB if disk_size > 0: user = dao.get_user_by_id(operation.fk_launched_by) user.used_disk_space = user.used_disk_space + disk_size dao.store_entity(user) return None except Exception, excep: self.logger.error(excep) self.logger.exception(excep) raise WorkflowInterStepsException(excep)
def prepare_next_step(self, last_executed_op_id): """ If the operation with id 'last_executed_op_id' resulted after the execution of a workflow step then this method will launch the operation corresponding to the next step from the workflow. """ try: current_step, next_workflow_step = self._get_data( last_executed_op_id) if next_workflow_step is not None: operation = dao.get_operation_by_id( next_workflow_step.fk_operation) dynamic_param_names = next_workflow_step.dynamic_workflow_param_names if len(dynamic_param_names) > 0: op_params = json.loads(operation.parameters) for param_name in dynamic_param_names: dynamic_param = op_params[param_name] former_step = dao.get_workflow_step_by_step_index( next_workflow_step.fk_workflow, dynamic_param[ WorkflowStepConfiguration.STEP_INDEX_KEY]) if type(dynamic_param[WorkflowStepConfiguration. DATATYPE_INDEX_KEY]) is IntType: datatypes = dao.get_results_for_operation( former_step.fk_operation) op_params[param_name] = datatypes[ dynamic_param[WorkflowStepConfiguration. DATATYPE_INDEX_KEY]].gid else: previous_operation = dao.get_operation_by_id( former_step.fk_operation) op_params[param_name] = json.loads( previous_operation.parameters)[ dynamic_param[WorkflowStepConfiguration. DATATYPE_INDEX_KEY]] operation.parameters = json.dumps(op_params) operation = dao.store_entity(operation) return operation.id elif current_step is not None: current_workflow = dao.get_workflow_by_id( current_step.fk_workflow) current_workflow.status = current_workflow.STATUS_FINISHED dao.store_entity(current_workflow) burst_entity = dao.get_burst_by_id(current_workflow.fk_burst) parallel_workflows = dao.get_workflows_for_burst( burst_entity.id) all_finished = True for workflow in parallel_workflows: if workflow.status == workflow.STATUS_STARTED: all_finished = False if all_finished: self.mark_burst_finished(burst_entity) return None except Exception, excep: self.logger.error(excep) self.logger.exception(excep) raise WorkflowInterStepsException(excep)
def update_executed_workflow_state(self, operation): """ Used for updating the state of an executed workflow. Only if the operation with the specified id has resulted after the execution of an ExecutedWorkflowStep than the state of the ExecutedWorkflow to which belongs the step will be updated. """ executed_step, _ = self._get_data(operation.id) if executed_step is not None: if operation.status == model.STATUS_ERROR: all_executed_steps = dao.get_workflow_steps(executed_step.fk_workflow) for step in all_executed_steps: if step.step_index > executed_step.step_index: self.logger.debug("Marking unreached operation %s with error." % step.fk_operation) unreached_operation = dao.get_operation_by_id(step.fk_operation) self.persist_operation_state(unreached_operation, model.STATUS_ERROR, "Blocked by failure in step %s with message: \n\n%s." % ( executed_step.step_index, operation.additional_info)) workflow = dao.get_workflow_by_id(executed_step.fk_workflow) burst = dao.get_burst_by_id(workflow.fk_burst) self.mark_burst_finished(burst, error_message=operation.additional_info) dao.store_entity(burst)