22 from collection import *
28 # Set up Arvados logging based on the user's configuration.
29 # All Arvados code should log under the arvados hierarchy.
30 log_handler = logging.StreamHandler()
31 log_handler.setFormatter(logging.Formatter(
32 '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s',
34 logger = logging.getLogger('arvados')
35 logger.addHandler(log_handler)
36 logger.setLevel(logging.DEBUG if config.get('ARVADOS_DEBUG')
39 def task_set_output(self,s):
40 api('v1').job_tasks().update(uuid=self['uuid'],
52 t = api('v1').job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
53 t = UserDict.UserDict(t)
54 t.set_output = types.MethodType(task_set_output, t)
55 t.tmpdir = os.environ['TASK_WORK']
64 t = api('v1').jobs().get(uuid=os.environ['JOB_UUID']).execute()
65 t = UserDict.UserDict(t)
66 t.tmpdir = os.environ['JOB_WORK']
70 def getjobparam(*args):
71 return current_job()['script_parameters'].get(*args)
73 def get_job_param_mount(*args):
74 return os.path.join(os.environ['TASK_KEEPMOUNT'], current_job()['script_parameters'].get(*args))
76 def get_task_param_mount(*args):
77 return os.path.join(os.environ['TASK_KEEPMOUNT'], current_task()['parameters'].get(*args))
79 class JobTask(object):
80 def __init__(self, parameters=dict(), runtime_constraints=dict()):
81 print "init jobtask %s %s" % (parameters, runtime_constraints)
85 def one_task_per_input_file(if_sequence=0, and_end_task=True, input_as_path=False):
86 if if_sequence != current_task()['sequence']:
88 job_input = current_job()['script_parameters']['input']
89 cr = CollectionReader(job_input)
91 for s in cr.all_streams():
92 for f in s.all_files():
94 task_input = os.path.join(job_input, s.name(), f.name())
96 task_input = f.as_manifest()
98 'job_uuid': current_job()['uuid'],
99 'created_by_job_task_uuid': current_task()['uuid'],
100 'sequence': if_sequence + 1,
105 api('v1').job_tasks().create(body=new_task_attrs).execute()
107 api('v1').job_tasks().update(uuid=current_task()['uuid'],
108 body={'success':True}
113 def one_task_per_input_stream(if_sequence=0, and_end_task=True):
114 if if_sequence != current_task()['sequence']:
116 job_input = current_job()['script_parameters']['input']
117 cr = CollectionReader(job_input)
118 for s in cr.all_streams():
119 task_input = s.tokens()
121 'job_uuid': current_job()['uuid'],
122 'created_by_job_task_uuid': current_task()['uuid'],
123 'sequence': if_sequence + 1,
128 api('v1').job_tasks().create(body=new_task_attrs).execute()
130 api('v1').job_tasks().update(uuid=current_task()['uuid'],
131 body={'success':True}