summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Freudberg <jeremyfreudberg@gmail.com>2018-07-09 11:48:30 -0400
committerJeremy Freudberg <jeremyfreudberg@gmail.com>2018-07-09 12:00:43 -0400
commitcb0e5ad7ca192fdbea93902517a608bccfa427f4 (patch)
tree929521153b7b11b77c392eb5b87b5601a1c33a61
parentb23abe2f96b591db5f6d8fe1c1f08bbd22c7666d (diff)
Final fixup to APIv2 responses
Some inconsistencies still remained. Change-Id: Ic54af5433f6498488f457d8e49dae74e684e2bd2 Story: 1745294 Task: 8392
Notes
Notes (review): Code-Review+2: Telles Mota Vidal Nóbrega <tenobreg@redhat.com> Code-Review+2: Luigi Toscano <ltoscano@redhat.com> Workflow+1: Luigi Toscano <ltoscano@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 11 Jul 2018 11:12:08 +0000 Reviewed-on: https://review.openstack.org/581072 Project: openstack/sahara Branch: refs/heads/master
-rw-r--r--releasenotes/notes/apiv2-payload-tweaks-b73c20a35263d958.yaml9
-rw-r--r--sahara/api/v2/cluster_templates.py16
-rw-r--r--sahara/api/v2/clusters.py26
-rw-r--r--sahara/api/v2/job_templates.py8
-rw-r--r--sahara/api/v2/jobs.py22
-rw-r--r--sahara/api/v2/node_group_templates.py15
-rw-r--r--sahara/utils/api.py5
7 files changed, 74 insertions, 27 deletions
diff --git a/releasenotes/notes/apiv2-payload-tweaks-b73c20a35263d958.yaml b/releasenotes/notes/apiv2-payload-tweaks-b73c20a35263d958.yaml
new file mode 100644
index 0000000..3bbeadc
--- /dev/null
+++ b/releasenotes/notes/apiv2-payload-tweaks-b73c20a35263d958.yaml
@@ -0,0 +1,9 @@
1---
2other:
3 - A few responses in the experimental (but nearly-stable) APIv2 have been
4 tweaked. To be specific, the key `hadoop_version` has been replaced with
5 `plugin_version`, the key `job` has been replaced with `job_template`, the
6 key `job_execution` has been replaced with `job`, and the key
7 `oozie_job_id` has been replaced with `engine_job_id`. In fact, these
8 changes were all previously partially implemented, and are now completely
9 implemented.
diff --git a/sahara/api/v2/cluster_templates.py b/sahara/api/v2/cluster_templates.py
index f013e49..fd9f7d4 100644
--- a/sahara/api/v2/cluster_templates.py
+++ b/sahara/api/v2/cluster_templates.py
@@ -31,6 +31,8 @@ rest = u.RestV2('cluster-templates', __name__)
31 v.validate_sorting_cluster_templates) 31 v.validate_sorting_cluster_templates)
32def cluster_templates_list(): 32def cluster_templates_list():
33 result = api.get_cluster_templates(**u.get_request_args().to_dict()) 33 result = api.get_cluster_templates(**u.get_request_args().to_dict())
34 for ct in result:
35 u._replace_hadoop_version_plugin_version(ct)
34 return u.render(res=result, name='cluster_templates') 36 return u.render(res=result, name='cluster_templates')
35 37
36 38
@@ -43,14 +45,19 @@ def cluster_templates_create(data):
43 # this can be removed once APIv1 is deprecated 45 # this can be removed once APIv1 is deprecated
44 data['hadoop_version'] = data['plugin_version'] 46 data['hadoop_version'] = data['plugin_version']
45 del data['plugin_version'] 47 del data['plugin_version']
46 return u.render(api.create_cluster_template(data).to_wrapped_dict()) 48 result = api.create_cluster_template(data).to_wrapped_dict()
49 u._replace_hadoop_version_plugin_version(result['cluster_template'])
50 return u.render(result)
47 51
48 52
49@rest.get('/cluster-templates/<cluster_template_id>') 53@rest.get('/cluster-templates/<cluster_template_id>')
50@acl.enforce("data-processing:cluster-templates:get") 54@acl.enforce("data-processing:cluster-templates:get")
51@v.check_exists(api.get_cluster_template, 'cluster_template_id') 55@v.check_exists(api.get_cluster_template, 'cluster_template_id')
52def cluster_templates_get(cluster_template_id): 56def cluster_templates_get(cluster_template_id):
53 return u.to_wrapped_dict(api.get_cluster_template, cluster_template_id) 57 result = u.to_wrapped_dict_no_render(
58 api.get_cluster_template, cluster_template_id)
59 u._replace_hadoop_version_plugin_version(result['cluster_template'])
60 return u.render(result)
54 61
55 62
56@rest.patch('/cluster-templates/<cluster_template_id>') 63@rest.patch('/cluster-templates/<cluster_template_id>')
@@ -62,8 +69,10 @@ def cluster_templates_update(cluster_template_id, data):
62 if data.get('plugin_version', None): 69 if data.get('plugin_version', None):
63 data['hadoop_version'] = data['plugin_version'] 70 data['hadoop_version'] = data['plugin_version']
64 del data['plugin_version'] 71 del data['plugin_version']
65 return u.to_wrapped_dict( 72 result = u.to_wrapped_dict_no_render(
66 api.update_cluster_template, cluster_template_id, data) 73 api.update_cluster_template, cluster_template_id, data)
74 u._replace_hadoop_version_plugin_version(result['cluster_template'])
75 return u.render(result)
67 76
68 77
69@rest.delete('/cluster-templates/<cluster_template_id>') 78@rest.delete('/cluster-templates/<cluster_template_id>')
@@ -91,6 +100,7 @@ def _cluster_template_export_helper(template):
91def cluster_template_export(cluster_template_id): 100def cluster_template_export(cluster_template_id):
92 content = u.to_wrapped_dict_no_render( 101 content = u.to_wrapped_dict_no_render(
93 api.export_cluster_template, cluster_template_id) 102 api.export_cluster_template, cluster_template_id)
103 u._replace_hadoop_version_plugin_version(content['cluster_template'])
94 _cluster_template_export_helper(content['cluster_template']) 104 _cluster_template_export_helper(content['cluster_template'])
95 res = u.render(content) 105 res = u.render(content)
96 res.headers.add('Content-Disposition', 'attachment', 106 res.headers.add('Content-Disposition', 'attachment',
diff --git a/sahara/api/v2/clusters.py b/sahara/api/v2/clusters.py
index b2ae322..72f3855 100644
--- a/sahara/api/v2/clusters.py
+++ b/sahara/api/v2/clusters.py
@@ -33,6 +33,8 @@ rest = u.RestV2('clusters', __name__)
33@v.validate(None, v.validate_pagination_limit) 33@v.validate(None, v.validate_pagination_limit)
34def clusters_list(): 34def clusters_list():
35 result = api.get_clusters(**u.get_request_args().to_dict()) 35 result = api.get_clusters(**u.get_request_args().to_dict())
36 for c in result:
37 u._replace_hadoop_version_plugin_version(c)
36 return u.render(res=result, name='clusters') 38 return u.render(res=result, name='clusters')
37 39
38 40
@@ -46,9 +48,14 @@ def clusters_create(data):
46 data['hadoop_version'] = data['plugin_version'] 48 data['hadoop_version'] = data['plugin_version']
47 del data['plugin_version'] 49 del data['plugin_version']
48 if data.get('count', None) is not None: 50 if data.get('count', None) is not None:
49 return u.render(api.create_multiple_clusters(data)) 51 result = api.create_multiple_clusters(data)
52 for c in result:
53 u._replace_hadoop_version_plugin_version(c['cluster'])
54 return u.render(result)
50 else: 55 else:
51 return u.render(api.create_cluster(data).to_wrapped_dict()) 56 result = api.create_cluster(data).to_wrapped_dict()
57 u._replace_hadoop_version_plugin_version(c['cluster'])
58 return u.render(result)
52 59
53 60
54@rest.put('/clusters/<cluster_id>') 61@rest.put('/clusters/<cluster_id>')
@@ -56,7 +63,10 @@ def clusters_create(data):
56@v.check_exists(api.get_cluster, 'cluster_id') 63@v.check_exists(api.get_cluster, 'cluster_id')
57@v.validate(v_c_schema.CLUSTER_SCALING_SCHEMA_V2, v_c_s.check_cluster_scaling) 64@v.validate(v_c_schema.CLUSTER_SCALING_SCHEMA_V2, v_c_s.check_cluster_scaling)
58def clusters_scale(cluster_id, data): 65def clusters_scale(cluster_id, data):
59 return u.to_wrapped_dict(api.scale_cluster, cluster_id, data) 66 result = u.to_wrapped_dict_no_render(
67 api.scale_cluster, cluster_id, data)
68 u._replace_hadoop_version_plugin_version(result['cluster'])
69 return u.render(result)
60 70
61 71
62@rest.get('/clusters/<cluster_id>') 72@rest.get('/clusters/<cluster_id>')
@@ -66,7 +76,10 @@ def clusters_get(cluster_id):
66 data = u.get_request_args() 76 data = u.get_request_args()
67 show_events = six.text_type( 77 show_events = six.text_type(
68 data.get('show_progress', 'false')).lower() == 'true' 78 data.get('show_progress', 'false')).lower() == 'true'
69 return u.to_wrapped_dict(api.get_cluster, cluster_id, show_events) 79 result = u.to_wrapped_dict_no_render(
80 api.get_cluster, cluster_id, show_events)
81 u._replace_hadoop_version_plugin_version(result['cluster'])
82 return u.render(result)
70 83
71 84
72@rest.patch('/clusters/<cluster_id>') 85@rest.patch('/clusters/<cluster_id>')
@@ -74,7 +87,10 @@ def clusters_get(cluster_id):
74@v.check_exists(api.get_cluster, 'cluster_id') 87@v.check_exists(api.get_cluster, 'cluster_id')
75@v.validate(v_c_schema.CLUSTER_UPDATE_SCHEMA, v_c.check_cluster_update) 88@v.validate(v_c_schema.CLUSTER_UPDATE_SCHEMA, v_c.check_cluster_update)
76def clusters_update(cluster_id, data): 89def clusters_update(cluster_id, data):
77 return u.to_wrapped_dict(api.update_cluster, cluster_id, data) 90 result = u.to_wrapped_dict_no_render(
91 api.update_cluster, cluster_id, data)
92 u._replace_hadoop_version_plugin_version(result['cluster'])
93 return u.render(result)
78 94
79 95
80@rest.delete('/clusters/<cluster_id>') 96@rest.delete('/clusters/<cluster_id>')
diff --git a/sahara/api/v2/job_templates.py b/sahara/api/v2/job_templates.py
index 01e86c0..c1e268e 100644
--- a/sahara/api/v2/job_templates.py
+++ b/sahara/api/v2/job_templates.py
@@ -38,14 +38,15 @@ def job_templates_list():
38@acl.enforce("data-processing:job-templates:create") 38@acl.enforce("data-processing:job-templates:create")
39@v.validate(v_j_schema.JOB_SCHEMA, v_j.check_mains_libs, v_j.check_interface) 39@v.validate(v_j_schema.JOB_SCHEMA, v_j.check_mains_libs, v_j.check_interface)
40def job_templates_create(data): 40def job_templates_create(data):
41 return u.render(api.create_job_template(data).to_wrapped_dict()) 41 return u.render({'job_template': api.create_job_template(data).to_dict()})
42 42
43 43
44@rest.get('/job-templates/<job_templates_id>') 44@rest.get('/job-templates/<job_templates_id>')
45@acl.enforce("data-processing:job-templates:get") 45@acl.enforce("data-processing:job-templates:get")
46@v.check_exists(api.get_job_templates, id='job_templates_id') 46@v.check_exists(api.get_job_templates, id='job_templates_id')
47def job_templates_get(job_templates_id): 47def job_templates_get(job_templates_id):
48 return u.to_wrapped_dict(api.get_job_template, job_templates_id) 48 return u.render({'job_template': api.get_job_template(
49 job_templates_id).to_dict()})
49 50
50 51
51@rest.patch('/job-templates/<job_templates_id>') 52@rest.patch('/job-templates/<job_templates_id>')
@@ -53,7 +54,8 @@ def job_templates_get(job_templates_id):
53@v.check_exists(api.get_job_templates, id='job_templates_id') 54@v.check_exists(api.get_job_templates, id='job_templates_id')
54@v.validate(v_j_schema.JOB_UPDATE_SCHEMA) 55@v.validate(v_j_schema.JOB_UPDATE_SCHEMA)
55def job_templates_update(job_templates_id, data): 56def job_templates_update(job_templates_id, data):
56 return u.to_wrapped_dict(api.update_job_template, job_templates_id, data) 57 return u.render({'job_template': api.update_job_template(
58 job_templates_id, data).to_dict()})
57 59
58 60
59@rest.delete('/job-templates/<job_templates_id>') 61@rest.delete('/job-templates/<job_templates_id>')
diff --git a/sahara/api/v2/jobs.py b/sahara/api/v2/jobs.py
index 1ef9a96..3c4dcfc 100644
--- a/sahara/api/v2/jobs.py
+++ b/sahara/api/v2/jobs.py
@@ -45,7 +45,11 @@ def jobs_list():
45@acl.enforce("data-processing:jobs:execute") 45@acl.enforce("data-processing:jobs:execute")
46@v.validate(v_j_e_schema.JOB_EXEC_SCHEMA_V2, v_j_e.check_job_execution) 46@v.validate(v_j_e_schema.JOB_EXEC_SCHEMA_V2, v_j_e.check_job_execution)
47def jobs_execute(data): 47def jobs_execute(data):
48 return u.render(api.execute_job(data).to_wrapped_dict()) 48 result = {'job': api.execute_job(data)}
49 dict.update(result['job'],
50 {'engine_job_id': result['job']['oozie_job_id']})
51 dict.pop(result['job'], 'oozie_job_id')
52 return u.render(result)
49 53
50 54
51@rest.get('/jobs/<job_id>') 55@rest.get('/jobs/<job_id>')
@@ -55,12 +59,8 @@ def jobs_get(job_id):
55 data = u.get_request_args() 59 data = u.get_request_args()
56 refresh_status = six.text_type( 60 refresh_status = six.text_type(
57 data.get('refresh_status', 'false')).lower() == 'true' 61 data.get('refresh_status', 'false')).lower() == 'true'
58 result = u.to_wrapped_dict_no_render( 62 result = {'job': api.get_job_execution(job_id, refresh_status)}
59 api.get_job_execution, job_id, refresh_status) 63 result['job'].pop('oozie_job_id', force=True)
60 result['job_execution']['engine_job_id'] = (
61 result['job_execution']['oozie_job_id']
62 )
63 del result['job_execution']['oozie_job_id']
64 return u.render(result) 64 return u.render(result)
65 65
66 66
@@ -70,12 +70,8 @@ def jobs_get(job_id):
70@v.validate( 70@v.validate(
71 v_j_e_schema.JOB_EXEC_UPDATE_SCHEMA, v_j_e.check_job_execution_update) 71 v_j_e_schema.JOB_EXEC_UPDATE_SCHEMA, v_j_e.check_job_execution_update)
72def jobs_update(job_id, data): 72def jobs_update(job_id, data):
73 result = u.to_wrapped_dict_no_render( 73 result = {'job': api.update_job_execution(job_id, data)}
74 api.update_job_execution, job_id, data) 74 result['job'].pop('oozie_job_id', force=True)
75 result['job_execution']['engine_job_id'] = (
76 result['job_execution']['oozie_job_id']
77 )
78 del result['job_execution']['oozie_job_id']
79 return u.render(result) 75 return u.render(result)
80 76
81 77
diff --git a/sahara/api/v2/node_group_templates.py b/sahara/api/v2/node_group_templates.py
index d756635..c0b20d0 100644
--- a/sahara/api/v2/node_group_templates.py
+++ b/sahara/api/v2/node_group_templates.py
@@ -32,6 +32,8 @@ rest = u.RestV2('node-group-templates', __name__)
32 v.validate_sorting_node_group_templates) 32 v.validate_sorting_node_group_templates)
33def node_group_templates_list(): 33def node_group_templates_list():
34 result = api.get_node_group_templates(**u.get_request_args().to_dict()) 34 result = api.get_node_group_templates(**u.get_request_args().to_dict())
35 for ngt in result:
36 u._replace_hadoop_version_plugin_version(ngt)
35 return u.render(res=result, name="node_group_templates") 37 return u.render(res=result, name="node_group_templates")
36 38
37 39
@@ -44,15 +46,19 @@ def node_group_templates_create(data):
44 # this can be removed once APIv1 is deprecated 46 # this can be removed once APIv1 is deprecated
45 data['hadoop_version'] = data['plugin_version'] 47 data['hadoop_version'] = data['plugin_version']
46 del data['plugin_version'] 48 del data['plugin_version']
47 return u.render(api.create_node_group_template(data).to_wrapped_dict()) 49 result = api.create_node_group_template(data).to_wrapped_dict()
50 u._replace_hadoop_version_plugin_version(result['node_group_template'])
51 return u.render(result)
48 52
49 53
50@rest.get('/node-group-templates/<node_group_template_id>') 54@rest.get('/node-group-templates/<node_group_template_id>')
51@acl.enforce("data-processing:node-group-templates:get") 55@acl.enforce("data-processing:node-group-templates:get")
52@v.check_exists(api.get_node_group_template, 'node_group_template_id') 56@v.check_exists(api.get_node_group_template, 'node_group_template_id')
53def node_group_templates_get(node_group_template_id): 57def node_group_templates_get(node_group_template_id):
54 return u.to_wrapped_dict( 58 result = u.to_wrapped_dict_no_render(
55 api.get_node_group_template, node_group_template_id) 59 api.get_node_group_template, node_group_template_id)
60 u._replace_hadoop_version_plugin_version(result['node_group_template'])
61 return u.render(result)
56 62
57 63
58@rest.patch('/node-group-templates/<node_group_template_id>') 64@rest.patch('/node-group-templates/<node_group_template_id>')
@@ -64,8 +70,10 @@ def node_group_templates_update(node_group_template_id, data):
64 if data.get('plugin_version', None): 70 if data.get('plugin_version', None):
65 data['hadoop_version'] = data['plugin_version'] 71 data['hadoop_version'] = data['plugin_version']
66 del data['plugin_version'] 72 del data['plugin_version']
67 return u.to_wrapped_dict( 73 result = u.to_wrapped_dict_no_render(
68 api.update_node_group_template, node_group_template_id, data) 74 api.update_node_group_template, node_group_template_id, data)
75 u._replace_hadoop_version_plugin_version(result['node_group_template'])
76 return u.render(result)
69 77
70 78
71@rest.delete('/node-group-templates/<node_group_template_id>') 79@rest.delete('/node-group-templates/<node_group_template_id>')
@@ -95,6 +103,7 @@ def _node_group_template_export_helper(template):
95def node_group_template_export(node_group_template_id): 103def node_group_template_export(node_group_template_id):
96 content = u.to_wrapped_dict_no_render( 104 content = u.to_wrapped_dict_no_render(
97 api.export_node_group_template, node_group_template_id) 105 api.export_node_group_template, node_group_template_id)
106 u._replace_hadoop_version_plugin_version(content['node_group_template'])
98 _node_group_template_export_helper(content['node_group_template']) 107 _node_group_template_export_helper(content['node_group_template'])
99 res = u.render(content) 108 res = u.render(content)
100 res.headers.add('Content-Disposition', 'attachment', 109 res.headers.add('Content-Disposition', 'attachment',
diff --git a/sahara/utils/api.py b/sahara/utils/api.py
index da24ee9..847264f 100644
--- a/sahara/utils/api.py
+++ b/sahara/utils/api.py
@@ -349,3 +349,8 @@ def to_wrapped_dict_no_render(func, id, *args, **kwargs):
349 349
350 return not_found(e) 350 return not_found(e)
351 return obj.to_wrapped_dict() 351 return obj.to_wrapped_dict()
352
353
354def _replace_hadoop_version_plugin_version(obj):
355 dict.update(obj, {'plugin_version': obj['hadoop_version']})
356 dict.pop(obj, 'hadoop_version')