5037: Remove connection pool. Now, api(cache=False) refers only to the discovery...
authorTom Clegg <tom@curoverse.com>
Fri, 30 Jan 2015 18:20:50 +0000 (13:20 -0500)
committerTom Clegg <tom@curoverse.com>
Fri, 30 Jan 2015 18:20:50 +0000 (13:20 -0500)
sdk/python/arvados/api.py
sdk/python/arvados/commands/ws.py
sdk/python/arvados/events.py
sdk/python/tests/test_api.py
sdk/python/tests/test_arv_put.py
sdk/python/tests/test_pipeline_template.py
sdk/python/tests/test_websockets.py

index c618fc3c6623ef18e8663609340b55bcce219f78..87e428ddf63cc95b141d80f11ad4f24f91b13210 100644 (file)
@@ -13,7 +13,6 @@ import errors
 import util
 
 _logger = logging.getLogger('arvados.api')
-conncache = {}
 
 class CredentialsFromToken(object):
     def __init__(self, api_token):
@@ -80,11 +79,8 @@ def api(version=None, cache=True, host=None, token=None, insecure=False, **kwarg
     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.
@@ -132,12 +128,6 @@ def api(version=None, cache=True, host=None, token=None, insecure=False, **kwarg
         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.
@@ -156,6 +146,4 @@ def api(version=None, cache=True, host=None, token=None, insecure=False, **kwarg
     svc = apiclient_discovery.build('arvados', version, **kwargs)
     svc.api_token = token
     kwargs['http'].cache = None
-    if cache:
-        conncache[connprofile] = svc
     return svc
index 04e3f6414b338f47ee88a228d84eca1ea5389344..9bce9971076372394fdf2e5c1f9523eda9d115ec 100644 (file)
@@ -46,7 +46,7 @@ def main(arguments=None):
             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] ]
@@ -85,7 +85,7 @@ def main(arguments=None):
             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()
index 7e8cdc3282113ad7984c9e9d93cdb187a0c77b4f..fc86cb46d4eecfbdd821f0e6f34da5df2061d437 100644 (file)
@@ -107,9 +107,9 @@ class PollClient(threading.Thread):
 
 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
index 0d81fdf738caf3d3120725479c8b110d27204c66..97d3e2c7b6e8c520efce9cc278c6024a53128e31 100644 (file)
@@ -42,7 +42,7 @@ class ArvadosApiClientTest(unittest.TestCase):
                     {'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,
index 001add3d7cd9fb99c7bd6d83d6838b9c5c2e7ceb..88cd3a0dafd24ba77c3c433677a04ca1c78fe0aa 100644 (file)
@@ -433,7 +433,7 @@ class ArvPutIntegrationTest(run_test_server.TestCaseWithServers,
                   "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()
@@ -523,7 +523,7 @@ class ArvPutIntegrationTest(run_test_server.TestCaseWithServers,
             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]
index 54539b02b39a9260fc40acab06839b4e6da10c58..bc82271f9c4f0019e6565086f2405e20ee8d3bcc 100644 (file)
@@ -13,7 +13,7 @@ class PipelineTemplateTest(unittest.TestCase):
 
     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,
@@ -27,7 +27,7 @@ class PipelineTemplateTest(unittest.TestCase):
             '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()
@@ -39,20 +39,20 @@ class PipelineTemplateTest(unittest.TestCase):
         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()
 
index 032ac51f0d445a5b03e751cf569f5c835307c367..b62acb2b9d6c609543d495bacfbe5f5d219879af 100644 (file)
@@ -24,11 +24,10 @@ class EventTestBase(object):
         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)