def from_state(cls, state_data, action_graph, output_path, context, run_node): """Restore a JobRun from a serialized state.""" node_pools = node.NodePoolStore.get_instance() if state_data.get('node_name'): run_node = node_pools.get(state_data['node_name']) # TODO: remove in 0.6 if 'job_name' not in state_data: # This is only to support old state files. job_name = state_data['id'].split('.')[0] else: job_name = state_data['job_name'] job_run = cls( job_name, state_data['run_num'], state_data['run_time'], run_node, action_graph=action_graph, manual=state_data.get('manual', False), output_path=output_path, base_context=context ) action_runs = ActionRunFactory.action_run_collection_from_state( job_run, state_data['runs'], state_data['cleanup_run']) job_run.action_runs = action_runs return job_run
def test_action_run_from_state(self): state_data = self.action_state_data action_run = ActionRunFactory.action_run_from_state( self.job_run, state_data) assert_equal(action_run.job_run_id, state_data['job_run_id']) assert not action_run.is_cleanup
def test_build_action_run_collection(self): collection = ActionRunFactory.build_action_run_collection(self.job_run) assert_equal(collection.action_graph, self.action_graph) assert_in('act1', collection.run_map) assert_in('act2', collection.run_map) assert_length(collection.run_map, 2) assert_equal(collection.run_map['act1'].action_name, 'act1')
def from_state( cls, state_data, action_graph, output_path, context, run_node, ): """Restore a JobRun from a serialized state.""" pool_repo = node.NodePoolRepository.get_instance() run_node = pool_repo.get_node(state_data.get('node_name'), run_node) job_name = state_data['job_name'] job_run = cls( job_name, state_data['run_num'], state_data['run_time'], run_node, action_graph=action_graph, manual=state_data.get('manual', False), output_path=output_path, base_context=context, ) action_runs = ActionRunFactory.action_run_collection_from_state( job_run, state_data['runs'], state_data['cleanup_run'], ) job_run.action_runs = action_runs return job_run
def for_job(cls, job, run_num, run_time, node, manual): """Create a JobRun for a job.""" run = cls(job.name, run_num, run_time, node, job.output_path.clone(), job.context, action_graph=job.action_graph, manual=manual) action_runs = ActionRunFactory.build_action_run_collection(run) run.action_runs = action_runs return run
def test_build_run_for_action_with_node(self): action = Turtle(name='theaction', is_cleanup=True, command="doit") action_run = ActionRunFactory.build_run_for_action(self.job_run, action) assert_equal(action_run.job_run_id, self.job_run.id) assert_equal(action_run.node, action.node_pool.next.returns[0]) assert action_run.is_cleanup assert_equal(action_run.action_name, action.name) assert_equal(action_run.command, action.command)
def test_build_run_for_action(self): action = Turtle( name='theaction', node_pool=None, is_cleanup=False, command="doit") action_run = ActionRunFactory.build_run_for_action(self.job_run, action) assert_equal(action_run.job_run_id, self.job_run.id) assert_equal(action_run.node, self.job_run.node) assert_equal(action_run.action_name, action.name) assert not action_run.is_cleanup assert_equal(action_run.command, action.command)
def test_action_run_collection_from_state(self): state_data = [self.action_state_data] cleanup_action_state_data = { 'job_run_id': 'job_run_id', 'action_name': 'cleanup', 'state': 'succeeded', 'run_time': self.run_time, 'start_time': None, 'end_time': None, 'command': 'do cleanup', 'node_name': 'anode' } collection = ActionRunFactory.action_run_collection_from_state( self.job_run, state_data, cleanup_action_state_data) assert_equal(collection.action_graph, self.action_graph) assert_length(collection.run_map, 2) assert_equal(collection.run_map['act1'].action_name, 'act1') assert_equal(collection.run_map['cleanup'].action_name, 'cleanup')