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)
90 for s in cr.all_streams():
91 for f in s.all_files():
93 task_input = os.path.join(job_input, s.name(), f.name())
95 task_input = f.as_manifest()
97 'job_uuid': current_job()['uuid'],
98 'created_by_job_task_uuid': current_task()['uuid'],
99 'sequence': if_sequence + 1,
104 api('v1').job_tasks().create(body=new_task_attrs).execute()
106 api('v1').job_tasks().update(uuid=current_task()['uuid'],
107 body={'success':True}
112 def one_task_per_input_stream(if_sequence=0, and_end_task=True):
113 if if_sequence != current_task()['sequence']:
115 job_input = current_job()['script_parameters']['input']
116 cr = CollectionReader(job_input)
117 for s in cr.all_streams():
118 task_input = s.tokens()
120 'job_uuid': current_job()['uuid'],
121 'created_by_job_task_uuid': current_task()['uuid'],
122 'sequence': if_sequence + 1,
127 api('v1').job_tasks().create(body=new_task_attrs).execute()
129 api('v1').job_tasks().update(uuid=current_task()['uuid'],
130 body={'success':True}