21 from .api import api, http_cache
22 from collection import CollectionReader, CollectionWriter, ResumableCollectionWriter
25 from arvfile import StreamFileReader
29 # Set up Arvados logging based on the user's configuration.
30 # All Arvados code should log under the arvados hierarchy.
31 log_handler = logging.StreamHandler()
32 log_handler.setFormatter(logging.Formatter(
33 '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s',
35 logger = logging.getLogger('arvados')
36 logger.addHandler(log_handler)
37 logger.setLevel(logging.DEBUG if config.get('ARVADOS_DEBUG')
40 def task_set_output(self,s):
41 api('v1').job_tasks().update(uuid=self['uuid'],
53 t = api('v1').job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
54 t = UserDict.UserDict(t)
55 t.set_output = types.MethodType(task_set_output, t)
56 t.tmpdir = os.environ['TASK_WORK']
65 t = api('v1').jobs().get(uuid=os.environ['JOB_UUID']).execute()
66 t = UserDict.UserDict(t)
67 t.tmpdir = os.environ['JOB_WORK']
71 def getjobparam(*args):
72 return current_job()['script_parameters'].get(*args)
74 def get_job_param_mount(*args):
75 return os.path.join(os.environ['TASK_KEEPMOUNT'], current_job()['script_parameters'].get(*args))
77 def get_task_param_mount(*args):
78 return os.path.join(os.environ['TASK_KEEPMOUNT'], current_task()['parameters'].get(*args))
80 class JobTask(object):
81 def __init__(self, parameters=dict(), runtime_constraints=dict()):
82 print "init jobtask %s %s" % (parameters, runtime_constraints)
86 def one_task_per_input_file(if_sequence=0, and_end_task=True, input_as_path=False, api_client=None):
87 if if_sequence != current_task()['sequence']:
91 api_client = api('v1')
93 job_input = current_job()['script_parameters']['input']
94 cr = CollectionReader(job_input, api_client=api_client)
96 for s in cr.all_streams():
97 for f in s.all_files():
99 task_input = os.path.join(job_input, s.name(), f.name())
101 task_input = f.as_manifest()
103 'job_uuid': current_job()['uuid'],
104 'created_by_job_task_uuid': current_task()['uuid'],
105 'sequence': if_sequence + 1,
110 api_client.job_tasks().create(body=new_task_attrs).execute()
112 api_client.job_tasks().update(uuid=current_task()['uuid'],
113 body={'success':True}
118 def one_task_per_input_stream(if_sequence=0, and_end_task=True):
119 if if_sequence != current_task()['sequence']:
121 job_input = current_job()['script_parameters']['input']
122 cr = CollectionReader(job_input)
123 for s in cr.all_streams():
124 task_input = s.tokens()
126 'job_uuid': current_job()['uuid'],
127 'created_by_job_task_uuid': current_task()['uuid'],
128 'sequence': if_sequence + 1,
133 api('v1').job_tasks().create(body=new_task_attrs).execute()
135 api('v1').job_tasks().update(uuid=current_task()['uuid'],
136 body={'success':True}