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