Skip to content

Commit 94b7a4d

Browse files
committed
fix: usr: Support different qubole version for cluster methods. Pull Request #147.
When creating clusters with the v1.3 of the API we still use the v1.2 endpoint during cluster creation. The _parse_create_update method accepts the api-version only to distinguish the request parameters. But the create, update and clone methods still use the default configuration of Qubole.agent(..) which is set to v1.2 unless all the actions in the session are configure(..)`ed with the v1.3 of the API. If you want to perform some of the unsupported actions with v1.3 of the cluster API but fall back to v1.2 for commands APIs we explicitly switch the version in the create(..)/update(..)/clone(..) calls which thereby alter the version for that API call alone and leave the cached_agent as is for the v1.2 APIs. Squashed commit of the following: commit 4eacc8f commit 7df4fbe
1 parent b1b7e63 commit 94b7a4d

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

qds_sdk/cluster.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Cluster(Resource):
2424
"""
2525

2626
rest_entity_path = "clusters"
27+
api_version = "v1.2"
2728

2829
@classmethod
2930
def _parse_list(cls, args):
@@ -408,29 +409,38 @@ def _parse_create_update(cls, args, action, api_version):
408409
return arguments
409410

410411
@classmethod
411-
def create(cls, cluster_info):
412+
def create(cls, cluster_info, version=None):
412413
"""
413414
Create a new cluster using information provided in `cluster_info`.
415+
416+
Optionally provide the version (eg: v1.3) to use the new version of the
417+
API. If None we default to v1.2
414418
"""
415-
conn = Qubole.agent()
419+
conn = Qubole.agent(version=version)
416420
return conn.post(cls.rest_entity_path, data=cluster_info)
417421

418422
@classmethod
419-
def update(cls, cluster_id_label, cluster_info):
423+
def update(cls, cluster_id_label, cluster_info, version=None):
420424
"""
421425
Update the cluster with id/label `cluster_id_label` using information provided in
422426
`cluster_info`.
427+
428+
Optionally provide the version (eg: v1.3) to use the new version of the
429+
API. If None we default to v1.2
423430
"""
424-
conn = Qubole.agent()
431+
conn = Qubole.agent(version=version)
425432
return conn.put(cls.element_path(cluster_id_label), data=cluster_info)
426433

427434
@classmethod
428-
def clone(cls, cluster_id_label, cluster_info):
435+
def clone(cls, cluster_id_label, cluster_info, version=None):
429436
"""
430437
Update the cluster with id/label `cluster_id_label` using information provided in
431438
`cluster_info`.
439+
440+
Optionally provide the version (eg: v1.3) to use the new version of the
441+
API. If None we default to v1.2
432442
"""
433-
conn = Qubole.agent()
443+
conn = Qubole.agent(version=version)
434444
return conn.post(cls.element_path(cluster_id_label) + '/clone', data=cluster_info)
435445

436446
@classmethod

qds_sdk/connection.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def init_poolmanager(self, connections, maxsize,
3131

3232
class Connection:
3333

34-
def __init__(self, auth, base_url, skip_ssl_cert_check, reuse=True):
34+
def __init__(self, auth, rest_url, skip_ssl_cert_check, reuse=True):
3535
self.auth = auth
36-
self.base_url = base_url
36+
self.rest_url = rest_url
3737
self.skip_ssl_cert_check = skip_ssl_cert_check
3838
self._headers = {'User-Agent': 'qds-sdk-py-%s' % pkg_resources.get_distribution("qds-sdk").version,
3939
'Content-Type': 'application/json'}
@@ -61,7 +61,7 @@ def delete(self, path, data=None):
6161
return self._api_call("DELETE", path, data)
6262

6363
def _api_call_raw(self, req_type, path, data=None, params=None):
64-
url = self.base_url.rstrip('/') + '/' + path
64+
url = self.rest_url.rstrip('/') + '/' + path
6565

6666
if self.reuse:
6767
x = self.session

qds_sdk/qubole.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class Qubole:
2525

2626
_auth = None
2727
api_token = None
28-
base_url = None
28+
baseurl = None
29+
version = None
2930
poll_interval = None
3031
skip_ssl_cert_check = None
3132

@@ -41,13 +42,14 @@ def configure(cls, api_token,
4142
4243
`api_url`: the base URL for QDS API. configurable for testing only
4344
44-
`version`: QDS REST api version
45+
`version`: QDS REST api version. Will be used throughout unless overridden in Qubole.agent(..)
4546
4647
`poll_interval`: interval in secs when polling QDS for events
4748
"""
4849
cls._auth = QuboleAuth(api_token)
4950
cls.api_token = api_token
50-
cls.base_url = api_url.rstrip('/') + '/' + version
51+
cls.version = version
52+
cls.baseurl = api_url
5153
if poll_interval < Qubole.MIN_POLL_INTERVAL:
5254
log.warn("Poll interval cannot be less than %s seconds. Setting it to %s seconds.\n" % (Qubole.MIN_POLL_INTERVAL, Qubole.MIN_POLL_INTERVAL))
5355
cls.poll_interval = Qubole.MIN_POLL_INTERVAL
@@ -58,15 +60,30 @@ def configure(cls, api_token,
5860
cached_agent = None
5961

6062
@classmethod
61-
def agent(cls):
63+
def agent(cls, version=None):
6264
"""
6365
Returns:
6466
a connection object to make REST calls to QDS
67+
68+
optionally override the `version` of the REST endpoint for advanced
69+
features available only in the newer version of the API available
70+
for certain resource end points eg: /v1.3/cluster. When version is
71+
None we default to v1.2
6572
"""
73+
reuse_cached_agent = True
74+
if version:
75+
log.debug("api version changed to %s" % version)
76+
cls.rest_url = '/'.join([cls.baseurl.rstrip('/'), version])
77+
reuse_cached_agent = False
78+
else:
79+
cls.rest_url = '/'.join([cls.baseurl.rstrip('/'), cls.version])
6680
if cls.api_token is None:
6781
raise ConfigError("No API Token specified - please supply one via Qubole.configure()")
6882

83+
if not reuse_cached_agent:
84+
uncached_agent = Connection(cls._auth, cls.rest_url, cls.skip_ssl_cert_check)
85+
return uncached_agent
6986
if cls.cached_agent is None:
70-
cls.cached_agent = Connection(cls._auth, cls.base_url, cls.skip_ssl_cert_check)
87+
cls.cached_agent = Connection(cls._auth, cls.rest_url, cls.skip_ssl_cert_check)
7188

7289
return cls.cached_agent

0 commit comments

Comments
 (0)