import util
_logger = logging.getLogger('arvados.api')
-conncache = {}
class CredentialsFromToken(object):
def __init__(self, api_token):
Arguments:
* version: A string naming the version of the Arvados API to use (for
example, 'v1').
- * cache: If True (default), return an existing Resources object if
- one already exists with the same endpoint and credentials. If
- False, create a new one, and do not keep it in the cache (i.e.,
- do not return it from subsequent api(cache=True) calls with
- matching endpoint and credentials).
+ * cache: Use (if available and recent) or create/update a cached copy
+ of the discovery document.
* host: The Arvados API server host (and optional :port) to connect to.
* token: The authentication token to send with each API call.
* insecure: If True, ignore SSL certificate validation errors.
kwargs['discoveryServiceUrl'] = (
'https://%s/discovery/v1/apis/{api}/{apiVersion}/rest' % (host,))
- if cache:
- connprofile = (version, host, token, insecure)
- svc = conncache.get(connprofile)
- if svc:
- return svc
-
if 'http' not in kwargs:
http_kwargs = {}
# Prefer system's CA certificates (if available) over httplib2's.
svc = apiclient_discovery.build('arvados', version, **kwargs)
svc.api_token = token
kwargs['http'].cache = None
- if cache:
- conncache[connprofile] = svc
return svc
ws.subscribe([['object_uuid', 'in', [args.pipeline] + list(pipeline_jobs)]])
known_component_jobs = pipeline_jobs
- api = arvados.api('v1', cache=False)
+ api = arvados.api('v1')
if args.uuid:
filters += [ ['object_uuid', '=', args.uuid] ]
print json.dumps(ev)
try:
- ws = subscribe(arvados.api('v1', cache=False), filters, on_message, poll_fallback=args.poll_interval)
+ ws = subscribe(arvados.api('v1'), filters, on_message, poll_fallback=args.poll_interval)
if ws:
if args.pipeline:
c = api.pipeline_instances().get(uuid=args.pipeline).execute()
def subscribe(api, filters, on_event, poll_fallback=15):
'''
- api: Must be a newly created from arvados.api(cache=False), not shared with the caller, as it may be used by a background thread.
+ api: a client object retrieved from arvados.api(). The caller should not use this client object for anything else after calling subscribe().
filters: Initial subscription filters.
- on_event: The callback when a message is received
+ on_event: The callback when a message is received.
poll_fallback: If websockets are not available, fall back to polling every N seconds. If poll_fallback=False, this will return None if websockets are not available.
'''
ws = None
{'items_available': 0, 'items': []})),
}
req_builder = apiclient_http.RequestMockBuilder(mock_responses)
- cls.api = arvados.api('v1', cache=False,
+ cls.api = arvados.api('v1',
host=os.environ['ARVADOS_API_HOST'],
token='discovery-doc-only-no-token-needed',
insecure=True,
"ARVADOS_API_HOST_INSECURE",
"ARVADOS_API_TOKEN"]:
self.ENVIRON[v] = arvados.config.settings()[v]
- arv_put.api_client = arvados.api('v1', cache=False)
+ arv_put.api_client = arvados.api('v1')
def current_user(self):
return arv_put.api_client.users().current().execute()
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=self.ENVIRON)
stdout, stderr = pipe.communicate(text)
- collection_list = arvados.api('v1', cache=False).collections().list(
+ collection_list = arvados.api('v1').collections().list(
filters=[['portable_data_hash', '=', stdout.strip()]]).execute().get('items', [])
self.assertEqual(1, len(collection_list))
return collection_list[0]
def runTest(self):
run_test_server.authorize_with("admin")
- pt_uuid = arvados.api('v1', cache=False).pipeline_templates().create(
+ pt_uuid = arvados.api('v1').pipeline_templates().create(
body={'name':__file__}
).execute()['uuid']
self.assertEqual(len(pt_uuid), 27,
'spass_box': False,
'spass-box': [True, 'Maybe', False]
}
- update_response = arvados.api('v1', cache=False).pipeline_templates().update(
+ update_response = arvados.api('v1').pipeline_templates().update(
uuid=pt_uuid,
body={'components':components}
).execute()
self.assertEqual(update_response['name'], __file__,
'update() response has a different name (%s, not %s)'
% (update_response['name'], __file__))
- get_response = arvados.api('v1', cache=False).pipeline_templates().get(
+ get_response = arvados.api('v1').pipeline_templates().get(
uuid=pt_uuid
).execute()
self.assertEqual(get_response['components'], components,
'components got munged by server (%s -> %s)'
% (components, update_response['components']))
- delete_response = arvados.api('v1', cache=False).pipeline_templates().delete(
+ delete_response = arvados.api('v1').pipeline_templates().delete(
uuid=pt_uuid
).execute()
self.assertEqual(delete_response['uuid'], pt_uuid,
'delete() response has wrong uuid (%s, not %s)'
% (delete_response['uuid'], pt_uuid))
with self.assertRaises(apiclient.errors.HttpError):
- geterror_response = arvados.api('v1', cache=False).pipeline_templates().get(
+ geterror_response = arvados.api('v1').pipeline_templates().get(
uuid=pt_uuid
).execute()
self.done = threading.Event()
run_test_server.authorize_with("admin")
- api = arvados.api('v1', cache=False)
- self.ws = arvados.events.subscribe(arvados.api('v1', cache=False), [['object_uuid', 'is_a', 'arvados#human']], self.on_event, poll_fallback=2)
+ self.ws = arvados.events.subscribe(arvados.api('v1'), [['object_uuid', 'is_a', 'arvados#human']], self.on_event, poll_fallback=2)
self.assertIsInstance(self.ws, self.WS_TYPE)
self.subscribed.wait(10)
- self.h = api.humans().create(body={}).execute()
+ self.h = arvados.api('v1').humans().create(body={}).execute()
self.done.wait(10)
self.assertEqual(3, self.state)