blob: b07e66355833e58347695fb26805f4fa1c25e637 [file] [log] [blame]
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +04001# Copyright (c) 2013 Mirantis Inc.
2#
Yaroslav Lobankov18544b02014-04-24 20:17:49 +04003# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +04006#
Yaroslav Lobankov18544b02014-04-24 20:17:49 +04007# http://www.apache.org/licenses/LICENSE-2.0
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +04008#
Yaroslav Lobankov18544b02014-04-24 20:17:49 +04009# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040014
15import json
16
17from tempest.common import rest_client
Matthew Treinish684d8992014-01-30 16:27:40 +000018from tempest import config
19
20CONF = config.CONF
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040021
22
23class DataProcessingClient(rest_client.RestClient):
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000024 def __init__(self, auth_provider):
25 super(DataProcessingClient, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000026 self.service = CONF.data_processing.catalog_type
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040027
28 @classmethod
29 def _request_and_parse(cls, req_fun, uri, res_name, *args, **kwargs):
30 """Make a request using specified req_fun and parse response.
31
32 It returns pair: resp and parsed resource(s) body.
33 """
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040034 resp, body = req_fun(uri, headers={
35 'Content-Type': 'application/json'
36 }, *args, **kwargs)
37 body = json.loads(body)
38 return resp, body[res_name]
39
40 def list_node_group_templates(self):
41 """List all node group templates for a user."""
42
43 uri = 'node-group-templates'
44 return self._request_and_parse(self.get, uri, 'node_group_templates')
45
46 def get_node_group_template(self, tmpl_id):
47 """Returns the details of a single node group template."""
48
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040049 uri = 'node-group-templates/%s' % tmpl_id
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040050 return self._request_and_parse(self.get, uri, 'node_group_template')
51
52 def create_node_group_template(self, name, plugin_name, hadoop_version,
53 node_processes, flavor_id,
54 node_configs=None, **kwargs):
55 """Creates node group template with specified params.
56
57 It supports passing additional params using kwargs and returns created
58 object.
59 """
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040060 uri = 'node-group-templates'
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040061 body = kwargs.copy()
62 body.update({
63 'name': name,
64 'plugin_name': plugin_name,
65 'hadoop_version': hadoop_version,
66 'node_processes': node_processes,
67 'flavor_id': flavor_id,
68 'node_configs': node_configs or dict(),
69 })
70 return self._request_and_parse(self.post, uri, 'node_group_template',
71 body=json.dumps(body))
72
73 def delete_node_group_template(self, tmpl_id):
74 """Deletes the specified node group template by id."""
75
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040076 uri = 'node-group-templates/%s' % tmpl_id
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040077 return self.delete(uri)
Sergey Lukjanovdad26cc2014-02-06 19:58:31 +040078
79 def list_plugins(self):
80 """List all enabled plugins."""
81
82 uri = 'plugins'
83 return self._request_and_parse(self.get, uri, 'plugins')
84
85 def get_plugin(self, plugin_name, plugin_version=None):
86 """Returns the details of a single plugin."""
87
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040088 uri = 'plugins/%s' % plugin_name
Sergey Lukjanovdad26cc2014-02-06 19:58:31 +040089 if plugin_version:
90 uri += '/%s' % plugin_version
91 return self._request_and_parse(self.get, uri, 'plugin')
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040092
93 def list_cluster_templates(self):
94 """List all cluster templates for a user."""
95
96 uri = 'cluster-templates'
97 return self._request_and_parse(self.get, uri, 'cluster_templates')
98
99 def get_cluster_template(self, tmpl_id):
100 """Returns the details of a single cluster template."""
101
102 uri = 'cluster-templates/%s' % tmpl_id
103 return self._request_and_parse(self.get, uri, 'cluster_template')
104
105 def create_cluster_template(self, name, plugin_name, hadoop_version,
106 node_groups, cluster_configs=None,
107 **kwargs):
108 """Creates cluster template with specified params.
109
110 It supports passing additional params using kwargs and returns created
111 object.
112 """
113 uri = 'cluster-templates'
114 body = kwargs.copy()
115 body.update({
116 'name': name,
117 'plugin_name': plugin_name,
118 'hadoop_version': hadoop_version,
119 'node_groups': node_groups,
120 'cluster_configs': cluster_configs or dict(),
121 })
122 return self._request_and_parse(self.post, uri, 'cluster_template',
123 body=json.dumps(body))
124
125 def delete_cluster_template(self, tmpl_id):
126 """Deletes the specified cluster template by id."""
127
128 uri = 'cluster-templates/%s' % tmpl_id
129 return self.delete(uri)
Yaroslav Lobankov4267bcc2014-04-25 13:25:03 +0400130
131 def list_data_sources(self):
132 """List all data sources for a user."""
133
134 uri = 'data-sources'
135 return self._request_and_parse(self.get, uri, 'data_sources')
136
137 def get_data_source(self, source_id):
138 """Returns the details of a single data source."""
139
140 uri = 'data-sources/%s' % source_id
141 return self._request_and_parse(self.get, uri, 'data_source')
142
143 def create_data_source(self, name, data_source_type, url, **kwargs):
144 """Creates data source with specified params.
145
146 It supports passing additional params using kwargs and returns created
147 object.
148 """
149 uri = 'data-sources'
150 body = kwargs.copy()
151 body.update({
152 'name': name,
153 'type': data_source_type,
154 'url': url
155 })
156 return self._request_and_parse(self.post, uri, 'data_source',
157 body=json.dumps(body))
158
159 def delete_data_source(self, source_id):
160 """Deletes the specified data source by id."""
161
162 uri = 'data-sources/%s' % source_id
163 return self.delete(uri)