Package cm_api :: Package endpoints :: Module cms
[hide private]
[frames] | no frames]

Source Code for Module cm_api.endpoints.cms

  1  # Licensed to Cloudera, Inc. under one 
  2  # or more contributor license agreements.  See the NOTICE file 
  3  # distributed with this work for additional information 
  4  # regarding copyright ownership.  Cloudera, Inc. licenses this file 
  5  # to you under the Apache License, Version 2.0 (the 
  6  # "License"); you may not use this file except in compliance 
  7  # with the License.  You may obtain a copy of the License at 
  8  # 
  9  #     http://www.apache.org/licenses/LICENSE-2.0 
 10  # 
 11  # Unless required by applicable law or agreed to in writing, software 
 12  # distributed under the License is distributed on an "AS IS" BASIS, 
 13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 14  # See the License for the specific language governing permissions and 
 15  # limitations under the License. 
 16   
 17  try: 
 18    import json 
 19  except ImportError: 
 20    import simplejson as json 
 21   
 22  from cm_api.endpoints.types import * 
 23  from cm_api.endpoints.services import ApiService 
 24   
25 -class ApiLicense(BaseApiObject):
26 """Model for a CM license.""" 27 _ATTRIBUTES = { 28 'owner' : ROAttr(), 29 'uuid' : ROAttr(), 30 'expiration' : ROAttr(), 31 } 32
33 - def __init__(self, resource_root):
34 BaseApiObject.init(self, resource_root)
35
36 -class ClouderaManager(BaseApiObject):
37 """ 38 The Cloudera Manager instance. 39 40 Provides access to CM configuration and services. 41 """ 42
43 - def __init__(self, resource_root):
44 BaseApiObject.init(self, resource_root)
45
46 - def _cmd(self, command, data = None):
47 """ 48 Invokes a global command. 49 50 @param command: Command name. 51 @param data: Optional data to send to the command. 52 @return Information about the submitted command. 53 """ 54 resp = self._get_resource_root().post("/cm/commands/" + command, data=data) 55 return ApiCommand.from_json_dict(resp, self._get_resource_root())
56
57 - def get_commands(self, view=None):
58 """ 59 Retrieve a list of running global commands. 60 61 @param view: View to materialize ('full' or 'summary') 62 @return: A list of running commands. 63 """ 64 resp = self._get_resource_root().get( 65 "/cm/commands", 66 params = view and dict(view=view) or None) 67 return ApiList.from_json_dict(ApiCommand, resp, self._get_resource_root())
68
69 - def create_mgmt_service(self, service_setup_info):
70 """ 71 Setup the Cloudera Management Service. 72 73 @param service_setup_info: ApiServiceSetupInfo object. 74 @return: The management service instance. 75 """ 76 body = json.dumps(service_setup_info.to_json_dict()) 77 resp = self._get_resource_root().put('/cm/service', data=body) 78 return ApiService.from_json_dict(resp, self._get_resource_root())
79
80 - def get_service(self):
81 """ 82 Return the Cloudera Management Services instance. 83 84 @return: An ApiService instance. 85 """ 86 resp = self._get_resource_root().get('/cm/service') 87 return ApiService.from_json_dict(resp, self._get_resource_root())
88
89 - def get_license(self):
90 """ 91 Return information about the currently installed license. 92 93 @return: License information. 94 """ 95 resp = self._get_resource_root().get('/cm/license') 96 return ApiLicense.from_json_dict(resp, self._get_resource_root())
97
98 - def update_license(self, license_text):
99 """ 100 Install or update the Cloudera Manager license. 101 102 @param license_text: the license in text form 103 """ 104 content = ( 105 '--MULTI_BOUNDARY', 106 'Content-Disposition: form-data; name="license"', 107 '', 108 license_text, 109 '--MULTI_BOUNDARY--', 110 '') 111 resp = self._get_resource_root().post('cm/license', 112 data="\r\n".join(content), 113 contenttype='multipart/form-data; boundary=MULTI_BOUNDARY') 114 return ApiLicense.from_json_dict(resp, self._get_resource_root())
115
116 - def get_config(self, view = None):
117 """ 118 Retrieve the Cloudera Manager configuration. 119 120 The 'summary' view contains strings as the dictionary values. The full 121 view contains ApiConfig instances as the values. 122 123 @param view: View to materialize ('full' or 'summary') 124 @return: Dictionary with configuration data. 125 """ 126 resp = self._get_resource_root().get('/cm/config', 127 params = view and dict(view=view) or None) 128 return json_to_config(resp, view == 'full')
129
130 - def update_config(self, config):
131 """ 132 Update the CM configuration. 133 134 @param: config Dictionary with configuration to update. 135 @return: Dictionary with updated configuration. 136 """ 137 resp = self._get_resource_root().put('/cm/config', 138 data = config_to_json(config)) 139 return json_to_config(resp, False)
140
141 - def generate_credentials(self):
142 """ 143 Generate credentials for services configured with Kerberos. 144 145 @return: Information about the submitted command. 146 """ 147 return self._cmd('generateCredentials')
148
149 - def inspect_hosts(self):
150 """ 151 Runs the host inspector on the configured hosts. 152 153 @return: Information about the submitted command. 154 """ 155 return self._cmd('inspectHosts')
156
157 - def collect_diagnostic_data(self, start_datetime, end_datetime, includeInfoLog=False):
158 """ 159 This method is deprecated as of CM 4.5. 160 You should use collect_diagnostic_data_45. 161 Issue the command to collect diagnostic data. 162 163 @param start_datetime: The start of the collection period. Type datetime. 164 @param end_datetime: The end of the collection period. Type datetime. 165 @param includeInfoLog: Whether to include INFO level log messages. 166 """ 167 args = { 168 'startTime': start_datetime.isoformat(), 169 'endTime': end_datetime.isoformat(), 170 'includeInfoLog': includeInfoLog, 171 } 172 return self._cmd('collectDiagnosticData', data=json.dumps(args))
173
174 - def collect_diagnostic_data_45(self, end_datetime, bundle_size_bytes):
175 """ 176 Issue the command to collect diagnostic data. 177 178 @param end_datetime: The end of the collection period. Type datetime. 179 @param bundle_size_bytes: The target size for the support bundle in bytes 180 """ 181 args = { 182 'endTime': end_datetime.isoformat(), 183 'bundleSizeBytes': bundle_size_bytes 184 } 185 return self._cmd('collectDiagnosticData', data=json.dumps(args))
186
187 - def hosts_decommission(self, host_names):
188 """ 189 Decommission the specified hosts by decommissioning the slave roles 190 and stopping the remaining ones. 191 192 @param host_names: List of names of hosts to be decommissioned. 193 @return: Information about the submitted command. 194 @since: API v2 195 """ 196 return self._cmd('hostsDecommission', data=json.dumps({ApiList.LIST_KEY : host_names}))
197
198 - def hosts_recommission(self, host_names):
199 """ 200 Recommission the specified hosts by recommissioning the slave roles. 201 This command doesn't start the roles. Use hosts_start_roles for that. 202 203 @param host_names: List of names of hosts to be recommissioned. 204 @return: Information about the submitted command. 205 @since: API v2 206 """ 207 return self._cmd('hostsRecommission', data=json.dumps({ApiList.LIST_KEY : host_names}))
208
209 - def hosts_start_roles(self, host_names):
210 """ 211 Start all the roles on the specified hosts. 212 213 @param host_names: List of names of hosts on which to start all roles. 214 @return: Information about the submitted command. 215 @since: API v2 216 """ 217 return self._cmd('hostsStartRoles', data=json.dumps({ApiList.LIST_KEY : host_names}))
218
219 - def create_peer(self, name, url, username, password):
220 """ 221 Create a new peer for replication. 222 223 @param name: The name of the peer. 224 @param url: The url of the peer. 225 @param username: The admin username to use to setup the remote side of the peer connection. 226 @param password: The password of the admin user. 227 @return: The newly created peer. 228 @since: API v3 229 """ 230 self._require_min_api_version(3) 231 body = json.dumps( 232 ApiCmPeer(self._get_resource_root(), 233 name=name, 234 url=url, 235 username=username, 236 password=password).to_json_dict()) 237 resp = self._get_resource_root().post('/cm/peers', data=body) 238 return ApiCmPeer.from_json_dict(resp, self._get_resource_root())
239
240 - def delete_peer(self, name):
241 """ 242 Delete a replication peer. 243 244 @param name: The name of the peer. 245 @return: The deleted peer. 246 @since: API v3 247 """ 248 self._require_min_api_version(3) 249 resp = self._get_resource_root()\ 250 .delete("/cm/peers/%s" % ( name, )) 251 return ApiCmPeer.from_json_dict(resp, self._get_resource_root())
252
253 - def update_peer(self, 254 current_name, 255 new_name, new_url, username, password):
256 """ 257 Update a replication peer. 258 259 @param current_name: The name of the peer to updated. 260 @param new_name: The new name for the peer. 261 @param new_url: The new url for the peer. 262 @param username: The admin username to use to setup the remote side of the peer connection. 263 @param password: The password of the admin user. 264 @return: The updated peer. 265 @since: API v3 266 """ 267 self._require_min_api_version(3) 268 body = json.dumps( 269 ApiCmPeer(self._get_resource_root(), 270 name=new_name, 271 url=new_url, 272 username=username, 273 password=password).to_json_dict()) 274 resp = self._get_resource_root().put('/cm/peers/%s' % (current_name, ), data=body) 275 return ApiCmPeer.from_json_dict(resp, self._get_resource_root())
276
277 - def get_peers(self):
278 """ 279 Retrieve a list of replication peers. 280 281 @return: A list of replication peers. 282 @since: API v3 283 """ 284 self._require_min_api_version(3) 285 resp = self._get_resource_root().get("/cm/peers") 286 return ApiList.from_json_dict(ApiCmPeer, resp, self._get_resource_root())
287
288 - def get_peer(self, name):
289 """ 290 Retrieve a replication peer by name. 291 292 @param name: The name of the peer. 293 @return: The peer. 294 @since: API v3 295 """ 296 self._require_min_api_version(3) 297 resp = self._get_resource_root().get("/cm/peers/%s" % (name, )) 298 return ApiCmPeer.from_json_dict(resp, self._get_resource_root())
299
300 - def test_peer_connectivity(self, name):
301 """ 302 Test connectivity for a replication peer. 303 304 @param name: The name of the peer to test. 305 @return: The command representing the test. 306 @since: API v3 307 """ 308 self._require_min_api_version(3) 309 resp = self._get_resource_root().post('/cm/peers/%s/commands/test' % (name, )) 310 return ApiCommand.from_json_dict(resp, self._get_resource_root())
311
312 - def get_all_hosts_config(self, view=None):
313 """ 314 Retrieve the default configuration for all hosts. 315 316 @param view: View to materialize. 317 @param view: View to materialize ('full' or 'summary') 318 @return: Dictionary with configuration data. 319 """ 320 params = view and dict(view=view) or None 321 resp = self._get_resource_root().get('/cm/allHosts/config', params=params) 322 return json_to_config(resp, view == 'full')
323
324 - def update_all_hosts_config(self, config):
325 """ 326 Update the default configuration for all hosts. 327 328 @param: config Dictionary with configuration to update. 329 @return: Dictionary with updated configuration. 330 """ 331 resp = self._get_resource_root().put('/cm/allHosts/config', 332 data=config_to_json(config)) 333 return json_to_config(resp, False)
334