1
2
3
4
5 from __future__ import print_function
6 from __future__ import absolute_import
7 from future import standard_library
8 standard_library.install_aliases()
9 from builtins import object
10 import bz2
11 import fcntl
12 import hashlib
13 import http.client
14 import httplib2
15 import json
16 import logging
17 import os
18 import pprint
19 import re
20 import string
21 import sys
22 import time
23 import types
24 import zlib
25
26 if sys.version_info >= (3, 0):
27 from collections import UserDict
28 else:
29 from UserDict import UserDict
30
31 from .api import api, api_from_config, http_cache
32 from .collection import CollectionReader, CollectionWriter, ResumableCollectionWriter
33 from arvados.keep import *
34 from arvados.stream import *
35 from .arvfile import StreamFileReader
36 from .retry import RetryLoop
37 import arvados.errors as errors
38 import arvados.util as util
39
40
41
42 log_format = '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s'
43 log_date_format = '%Y-%m-%d %H:%M:%S'
44 log_handler = logging.StreamHandler()
45 log_handler.setFormatter(logging.Formatter(log_format, log_date_format))
46 logger = logging.getLogger('arvados')
47 logger.addHandler(log_handler)
48 logger.setLevel(logging.DEBUG if config.get('ARVADOS_DEBUG')
49 else logging.WARNING)
52 for tries_left in RetryLoop(num_retries=num_retries, backoff_start=0):
53 try:
54 return api('v1').job_tasks().update(
55 uuid=self['uuid'],
56 body={
57 'output':s,
58 'success':True,
59 'progress':1.0
60 }).execute()
61 except errors.ApiError as error:
62 if retry.check_http_response_success(error.resp.status) is None and tries_left > 0:
63 logger.debug("task_set_output: job_tasks().update() raised {}, retrying with {} tries left".format(repr(error),tries_left))
64 else:
65 raise
66
67 _current_task = None
69 global _current_task
70 if _current_task:
71 return _current_task
72
73 for tries_left in RetryLoop(num_retries=num_retries, backoff_start=2):
74 try:
75 task = api('v1').job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
76 task = UserDict(task)
77 task.set_output = types.MethodType(task_set_output, task)
78 task.tmpdir = os.environ['TASK_WORK']
79 _current_task = task
80 return task
81 except errors.ApiError as error:
82 if retry.check_http_response_success(error.resp.status) is None and tries_left > 0:
83 logger.debug("current_task: job_tasks().get() raised {}, retrying with {} tries left".format(repr(error),tries_left))
84 else:
85 raise
86
87 _current_job = None
89 global _current_job
90 if _current_job:
91 return _current_job
92
93 for tries_left in RetryLoop(num_retries=num_retries, backoff_start=2):
94 try:
95 job = api('v1').jobs().get(uuid=os.environ['JOB_UUID']).execute()
96 job = UserDict(job)
97 job.tmpdir = os.environ['JOB_WORK']
98 _current_job = job
99 return job
100 except errors.ApiError as error:
101 if retry.check_http_response_success(error.resp.status) is None and tries_left > 0:
102 logger.debug("current_job: jobs().get() raised {}, retrying with {} tries left".format(repr(error),tries_left))
103 else:
104 raise
105
108
110 return os.path.join(os.environ['TASK_KEEPMOUNT'], current_job()['script_parameters'].get(*args))
111
114
116 - def __init__(self, parameters=dict(), runtime_constraints=dict()):
117 print("init jobtask %s %s" % (parameters, runtime_constraints))
118
120 @staticmethod
151
152 @staticmethod
174