Remove cyclic dependency
The cyclical dependency from client to manager then back on client has caused problems in other projects as the client doesn't always get properly destroyed which can lead to it holding open network connections. Remove this dependency and instead simply pass the constructed HTTPClient to the managers. Change-Id: Id112ab366ad19bc6ae239cfcadb5eb98f6cb8abf
This commit is contained in:
@@ -77,7 +77,7 @@ class ResourceManager(object):
|
||||
def _create(self, url, data, response_key=None, dump_json=True):
|
||||
if dump_json:
|
||||
data = json.dumps(data)
|
||||
resp = self.api.client.post(url, data, json=dump_json)
|
||||
resp = self.api.post(url, data, json=dump_json)
|
||||
|
||||
if resp.status_code != 202:
|
||||
self._raise_api_exception(resp)
|
||||
@@ -91,7 +91,7 @@ class ResourceManager(object):
|
||||
def _update(self, url, data, response_key=None, dump_json=True):
|
||||
if dump_json:
|
||||
data = json.dumps(data)
|
||||
resp = self.api.client.put(url, data, json=dump_json)
|
||||
resp = self.api.put(url, data, json=dump_json)
|
||||
|
||||
if resp.status_code != 202:
|
||||
self._raise_api_exception(resp)
|
||||
@@ -102,7 +102,7 @@ class ResourceManager(object):
|
||||
return self.resource_class(self, data)
|
||||
|
||||
def _list(self, url, response_key):
|
||||
resp = self.api.client.get(url)
|
||||
resp = self.api.get(url)
|
||||
if resp.status_code == 200:
|
||||
data = get_json(resp)[response_key]
|
||||
|
||||
@@ -112,7 +112,7 @@ class ResourceManager(object):
|
||||
self._raise_api_exception(resp)
|
||||
|
||||
def _get(self, url, response_key=None):
|
||||
resp = self.api.client.get(url)
|
||||
resp = self.api.get(url)
|
||||
|
||||
if resp.status_code == 200:
|
||||
if response_key is not None:
|
||||
@@ -124,7 +124,7 @@ class ResourceManager(object):
|
||||
self._raise_api_exception(resp)
|
||||
|
||||
def _delete(self, url):
|
||||
resp = self.api.client.delete(url)
|
||||
resp = self.api.delete(url)
|
||||
|
||||
if resp.status_code != 204:
|
||||
self._raise_api_exception(resp)
|
||||
|
||||
@@ -78,22 +78,24 @@ class Client(object):
|
||||
if not sahara_catalog_url:
|
||||
raise RuntimeError("Could not find Sahara endpoint in catalog")
|
||||
|
||||
self.client = httpclient.HTTPClient(sahara_catalog_url,
|
||||
input_auth_token)
|
||||
client = httpclient.HTTPClient(sahara_catalog_url, input_auth_token)
|
||||
|
||||
self.clusters = clusters.ClusterManager(self)
|
||||
self.cluster_templates = cluster_templates.ClusterTemplateManager(self)
|
||||
self.node_group_templates = (node_group_templates.
|
||||
NodeGroupTemplateManager(self))
|
||||
self.plugins = plugins.PluginManager(self)
|
||||
self.images = images.ImageManager(self)
|
||||
self.clusters = clusters.ClusterManager(client)
|
||||
self.cluster_templates = (
|
||||
cluster_templates.ClusterTemplateManager(client)
|
||||
)
|
||||
self.node_group_templates = (
|
||||
node_group_templates.NodeGroupTemplateManager(client)
|
||||
)
|
||||
self.plugins = plugins.PluginManager(client)
|
||||
self.images = images.ImageManager(client)
|
||||
|
||||
self.data_sources = data_sources.DataSourceManager(self)
|
||||
self.jobs = jobs.JobsManager(self)
|
||||
self.job_executions = job_executions.JobExecutionsManager(self)
|
||||
self.job_binaries = job_binaries.JobBinariesManager(self)
|
||||
self.data_sources = data_sources.DataSourceManager(client)
|
||||
self.jobs = jobs.JobsManager(client)
|
||||
self.job_executions = job_executions.JobExecutionsManager(client)
|
||||
self.job_binaries = job_binaries.JobBinariesManager(client)
|
||||
self.job_binary_internals = (
|
||||
job_binary_internals.JobBinaryInternalsManager(self)
|
||||
job_binary_internals.JobBinaryInternalsManager(client)
|
||||
)
|
||||
|
||||
def get_keystone_client(self, username=None, api_key=None, auth_url=None,
|
||||
|
||||
@@ -40,7 +40,7 @@ class ImageManager(base.ResourceManager):
|
||||
body = {"username": user_name,
|
||||
"description": desc}
|
||||
|
||||
resp = self.api.client.post('/images/%s' % image_id, json.dumps(body))
|
||||
resp = self.api.post('/images/%s' % image_id, json.dumps(body))
|
||||
if resp.status_code != 202:
|
||||
raise RuntimeError('Failed to register image %s' % image_id)
|
||||
|
||||
@@ -54,15 +54,15 @@ class ImageManager(base.ResourceManager):
|
||||
to_remove = list(old_tags - new_tags)
|
||||
|
||||
if len(to_add) != 0:
|
||||
resp = self.api.client.post('/images/%s/tag' % image_id,
|
||||
json.dumps({'tags': to_add}))
|
||||
resp = self.api.post('/images/%s/tag' % image_id,
|
||||
json.dumps({'tags': to_add}))
|
||||
|
||||
if resp.status_code != 202:
|
||||
raise RuntimeError('Failed to add tags to image %s' % image_id)
|
||||
|
||||
if len(to_remove) != 0:
|
||||
resp = self.api.client.post('/images/%s/untag' % image_id,
|
||||
json.dumps({'tags': to_remove}))
|
||||
resp = self.api.post('/images/%s/untag' % image_id,
|
||||
json.dumps({'tags': to_remove}))
|
||||
|
||||
if resp.status_code != 202:
|
||||
raise RuntimeError('Failed to remove tags from image %s' %
|
||||
|
||||
@@ -44,7 +44,7 @@ class JobBinariesManager(base.ResourceManager):
|
||||
self._delete('/job-binaries/%s' % job_binary_id)
|
||||
|
||||
def get_file(self, job_binary_id):
|
||||
resp = self.api.client.get('/job-binaries/%s/data' % job_binary_id)
|
||||
resp = self.api.get('/job-binaries/%s/data' % job_binary_id)
|
||||
|
||||
if resp.status_code != 200:
|
||||
self._raise_api_exception(resp)
|
||||
|
||||
@@ -44,11 +44,11 @@ class PluginManager(base.ResourceManager):
|
||||
|
||||
def convert_to_cluster_template(self, plugin_name, hadoop_version,
|
||||
template_name, filecontent):
|
||||
resp = self.api.client.post('/plugins/%s/%s/convert-config/%s' %
|
||||
(plugin_name,
|
||||
hadoop_version,
|
||||
urlparse.quote(template_name)),
|
||||
filecontent)
|
||||
resp = self.api.post('/plugins/%s/%s/convert-config/%s' %
|
||||
(plugin_name,
|
||||
hadoop_version,
|
||||
urlparse.quote(template_name)),
|
||||
filecontent)
|
||||
if resp.status_code != 202:
|
||||
raise RuntimeError('Failed to upload template file for plugin "%s"'
|
||||
' and version "%s"' %
|
||||
|
||||
Reference in New Issue
Block a user