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

Source Code for Module cm_api.endpoints.services

   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 import roles, role_config_groups 
  24   
  25  __docformat__ = "epytext" 
  26   
  27  SERVICES_PATH = "/clusters/%s/services" 
  28  SERVICE_PATH = "/clusters/%s/services/%s" 
  29  ROLETYPES_CFG_KEY = 'roleTypeConfigs' 
  30   
31 -def create_service(resource_root, name, service_type, 32 cluster_name="default"):
33 """ 34 Create a service 35 @param resource_root: The root Resource object. 36 @param name: Service name 37 @param service_type: Service type 38 @param cluster_name: Cluster name 39 @return: An ApiService object 40 """ 41 apiservice = ApiService(resource_root, name, service_type) 42 return call(resource_root.post, 43 SERVICES_PATH % (cluster_name,), 44 ApiService, True, data=[apiservice])[0]
45
46 -def get_service(resource_root, name, cluster_name="default"):
47 """ 48 Lookup a service by name 49 @param resource_root: The root Resource object. 50 @param name: Service name 51 @param cluster_name: Cluster name 52 @return: An ApiService object 53 """ 54 return _get_service(resource_root, "%s/%s" % (SERVICES_PATH % (cluster_name,), name))
55
56 -def _get_service(resource_root, path):
57 return call(resource_root.get, path, ApiService)
58
59 -def get_all_services(resource_root, cluster_name="default", view=None):
60 """ 61 Get all services 62 @param resource_root: The root Resource object. 63 @param cluster_name: Cluster name 64 @return: A list of ApiService objects. 65 """ 66 return call(resource_root.get, 67 SERVICES_PATH % (cluster_name,), 68 ApiService, True, params=view and dict(view=view) or None)
69
70 -def delete_service(resource_root, name, cluster_name="default"):
71 """ 72 Delete a service by name 73 @param resource_root: The root Resource object. 74 @param name: Service name 75 @param cluster_name: Cluster name 76 @return: The deleted ApiService object 77 """ 78 return call(resource_root.delete, 79 "%s/%s" % (SERVICES_PATH % (cluster_name,), name), 80 ApiService)
81 82
83 -class ApiService(BaseApiResource):
84 _ATTRIBUTES = { 85 'name' : None, 86 'type' : None, 87 'displayName' : None, 88 'serviceState' : ROAttr(), 89 'healthSummary' : ROAttr(), 90 'healthChecks' : ROAttr(), 91 'clusterRef' : ROAttr(ApiClusterRef), 92 'configStale' : ROAttr(), 93 'configStalenessStatus' : ROAttr(), 94 'clientConfigStalenessStatus' : ROAttr(), 95 'serviceUrl' : ROAttr(), 96 'roleInstancesUrl' : ROAttr(), 97 'maintenanceMode' : ROAttr(), 98 'maintenanceOwners' : ROAttr(), 99 'entityStatus' : ROAttr(), 100 } 101
102 - def __init__(self, resource_root, name=None, type=None):
103 BaseApiObject.init(self, resource_root, locals())
104
105 - def __str__(self):
106 return "<ApiService>: %s (cluster: %s)" % ( 107 self.name, self._get_cluster_name())
108
109 - def _get_cluster_name(self):
110 if hasattr(self, 'clusterRef') and self.clusterRef: 111 return self.clusterRef.clusterName 112 return None
113
114 - def _path(self):
115 """ 116 Return the API path for this service. 117 118 This method assumes that lack of a cluster reference means that the 119 object refers to the Cloudera Management Services instance. 120 """ 121 if self._get_cluster_name(): 122 return SERVICE_PATH % (self._get_cluster_name(), self.name) 123 else: 124 return '/cm/service'
125
126 - def _role_cmd(self, cmd, roles, api_version=1):
127 return self._post("roleCommands/" + cmd, ApiBulkCommandList, 128 data=roles, api_version=api_version)
129
130 - def _parse_svc_config(self, json_dic, view = None):
131 """ 132 Parse a json-decoded ApiServiceConfig dictionary into a 2-tuple. 133 134 @param json_dic: The json dictionary with the config data. 135 @param view: View to materialize. 136 @return: 2-tuple (service config dictionary, role type configurations) 137 """ 138 svc_config = json_to_config(json_dic, view == 'full') 139 rt_configs = { } 140 if json_dic.has_key(ROLETYPES_CFG_KEY): 141 for rt_config in json_dic[ROLETYPES_CFG_KEY]: 142 rt_configs[rt_config['roleType']] = \ 143 json_to_config(rt_config, view == 'full') 144 145 return (svc_config, rt_configs)
146
147 - def get_commands(self, view=None):
148 """ 149 Retrieve a list of running commands for this service. 150 151 @param view: View to materialize ('full' or 'summary') 152 @return: A list of running commands. 153 """ 154 return self._get("commands", ApiCommand, True, 155 params = view and dict(view=view) or None)
156
157 - def get_running_activities(self):
158 return self.query_activities()
159
160 - def query_activities(self, query_str=None):
161 return self._get("activities", ApiActivity, True, 162 params=query_str and dict(query=query_str) or dict())
163
164 - def get_activity(self, job_id):
165 return self._get("activities/" + job_id, ApiActivity)
166
167 - def list_watched_directories(self):
168 """ 169 Returns a list of directories being watched by the Reports Manager. 170 171 @return: A list of directories being watched 172 @since: API v14 173 """ 174 return self._get("watcheddir", ApiWatchedDir, ret_is_list=True, api_version=14)
175
176 - def add_watched_directory(self, dir_path):
177 """ 178 Adds a directory to the watching list. 179 180 @param dir_path: The path of the directory to be added to the watching list 181 @return: The added directory, or null if failed 182 @since: API v14 183 """ 184 req = ApiWatchedDir(self._get_resource_root(), path=dir_path) 185 return self._post("watcheddir", ApiWatchedDir, data=req, api_version=14)
186
187 - def remove_watched_directory(self, dir_path):
188 """ 189 Removes a directory from the watching list. 190 191 @param dir_path: The path of the directory to be removed from the watching list 192 @return: The removed directory, or null if failed 193 @since: API v14 194 """ 195 return self._delete("watcheddir/%s" % dir_path, ApiWatchedDir, api_version=14)
196
197 - def get_impala_queries(self, start_time, end_time, filter_str="", limit=100, 198 offset=0):
199 """ 200 Returns a list of queries that satisfy the filter 201 202 @type start_time: datetime.datetime. Note that the datetime must either be 203 time zone aware or specified in the server time zone. See 204 the python datetime documentation for more details about 205 python's time zone handling. 206 @param start_time: Queries must have ended after this time 207 @type end_time: datetime.datetime. Note that the datetime must either be 208 time zone aware or specified in the server time zone. See 209 the python datetime documentation for more details about 210 python's time zone handling. 211 @param end_time: Queries must have started before this time 212 @param filter_str: A filter to apply to the queries. For example: 213 'user = root and queryDuration > 5s' 214 @param limit: The maximum number of results to return 215 @param offset: The offset into the return list 216 @since: API v4 217 """ 218 params = { 219 'from': start_time.isoformat(), 220 'to': end_time.isoformat(), 221 'filter': filter_str, 222 'limit': limit, 223 'offset': offset, 224 } 225 return self._get("impalaQueries", ApiImpalaQueryResponse, 226 params=params, api_version=4)
227
228 - def cancel_impala_query(self, query_id):
229 """ 230 Cancel the query. 231 232 @param query_id: The query ID 233 @return: The warning message, if any. 234 @since: API v4 235 """ 236 return self._post("impalaQueries/%s/cancel" % query_id, 237 ApiImpalaCancelResponse, api_version=4)
238
239 - def get_query_details(self, query_id, format='text'):
240 """ 241 Get the query details 242 243 @param query_id: The query ID 244 @param format: The format of the response ('text' or 'thrift_encoded') 245 @return: The details text 246 @since: API v4 247 """ 248 return self._get("impalaQueries/" + query_id, ApiImpalaQueryDetailsResponse, 249 params=dict(format=format), api_version=4)
250
252 """ 253 Returns the list of all attributes that the Service Monitor can associate 254 with Impala queries. 255 256 Examples of attributes include the user who issued the query and the 257 number of HDFS bytes read by the query. 258 259 These attributes can be used to search for specific Impala queries through 260 the get_impala_queries API. For example the 'user' attribute could be used 261 in the search 'user = root'. If the attribute is numeric it can also be used 262 as a metric in a tsquery (ie, 'select hdfs_bytes_read from IMPALA_QUERIES'). 263 264 Note that this response is identical for all Impala services. 265 266 @return: A list of the Impala query attributes 267 @since API v6 268 """ 269 return self._get("impalaQueries/attributes", ApiImpalaQueryAttribute, 270 ret_is_list=True, api_version=6)
271
273 """ 274 Create the Impala Catalog Database. Only works with embedded postgresql 275 database. This command should usually be followed by a call to 276 create_impala_catalog_database_tables. 277 278 @return: Reference to the submitted command. 279 @since: API v6 280 """ 281 return self._cmd('impalaCreateCatalogDatabase', api_version=6)
282
284 """ 285 Creates the Impala Catalog Database tables in the configured database. 286 Will do nothing if tables already exist. Will not perform an upgrade. 287 288 @return: Reference to the submitted command. 289 @since: API v6 290 """ 291 return self._cmd('impalaCreateCatalogDatabaseTables', api_version=6)
292
293 - def create_impala_user_dir(self):
294 """ 295 Create the Impala user directory 296 297 @return: Reference to submitted command. 298 @since: API v6 299 """ 300 return self._cmd('impalaCreateUserDir', api_version=6)
301
302 - def enable_llama_rm(self, llama1_host_id, llama1_role_name=None, 303 llama2_host_id=None, llama2_role_name=None, 304 zk_service_name=None, skip_restart=False):
305 """ 306 Enable Llama-based resource management for Impala. 307 308 This command only applies to CDH 5.1+ Impala services. 309 310 This command configures YARN and Impala for Llama resource management, 311 and then creates one or two Llama roles, as specified by the parameters. 312 When two Llama roles are created, they are configured as an active-standby 313 pair. Auto-failover from active to standby Llama will be enabled using 314 ZooKeeper. 315 316 If optional role name(s) are specified, the new Llama role(s) will be 317 named accordingly; otherwise, role name(s) will be automatically generated. 318 319 By default, YARN, Impala, and any dependent services will be restarted, 320 and client configuration will be re-deployed across the cluster. These 321 default actions may be suppressed. 322 323 In order to enable Llama resource management, a YARN service must be 324 present in the cluster, and Cgroup-based resource management must be 325 enabled for all hosts with NodeManager roles. If these preconditions 326 are not met, the command will fail. 327 328 @param llama1_host_id: id of the host where the first Llama role will 329 be created. 330 @param llama1_role_name: Name of the first Llama role. If omitted, a 331 name will be generated automatically. 332 @param llama2_host_id: id of the host where the second Llama role will 333 be created. If omitted, only one Llama role will 334 be created (i.e., high availability will not be 335 enabled). 336 @param llama2_role_name: Name of the second Llama role. If omitted, a 337 name will be generated automatically. 338 @param zk_service_name: Name of the ZooKeeper service to use for 339 auto-failover. Only relevant when enabling 340 Llama RM in HA mode (i.e., when creating two 341 Llama roles). If Impala's ZooKeeper dependency 342 is already set, then that ZooKeeper service will 343 be used for auto-failover, and this parameter 344 may be omitted. 345 @param skip_restart: true to skip the restart of Yarn, Impala, and 346 their dependent services, and to skip deployment 347 of client configuration. Default is False (i.e., 348 by default dependent services are restarted and 349 client configuration is deployed). 350 @return: Reference to the submitted command. 351 @since: API v8 352 """ 353 args = dict( 354 llama1HostId = llama1_host_id, 355 llama1RoleName = llama1_role_name, 356 llama2HostId = llama2_host_id, 357 llama2RoleName = llama2_role_name, 358 zkServiceName = zk_service_name, 359 skipRestart = skip_restart 360 ) 361 return self._cmd('impalaEnableLlamaRm', data=args, api_version=8)
362
363 - def disable_llama_rm(self):
364 """ 365 Disable Llama-based resource management for Impala. 366 367 This command only applies to CDH 5.1+ Impala services. 368 369 This command disables resource management for Impala by removing all 370 Llama roles present in the Impala service. Any services that depend 371 on the Impala service being modified are restarted by the command, 372 and client configuration is deployed for all services of the cluster. 373 374 @return: Reference to the submitted command. 375 @since: API v8 376 """ 377 return self._cmd('impalaDisableLlamaRm', api_version=8)
378
379 - def enable_llama_ha(self, new_llama_host_id, zk_service_name=None, 380 new_llama_role_name=None):
381 """ 382 Enable high availability for an Impala Llama ApplicationMaster. 383 384 This command only applies to CDH 5.1+ Impala services. 385 386 @param new_llama_host_id: id of the host where the second Llama role 387 will be added. 388 @param zk_service_name: Name of the ZooKeeper service to use for 389 auto-failover. If Impala's ZooKeeper dependency 390 is already set, then that ZooKeeper service will 391 be used for auto-failover, and this parameter 392 may be omitted. 393 @param new_llama_role_name: Name of the new Llama role. If omitted, a 394 name will be generated automatically. 395 @return: Reference to the submitted command. 396 @since: API v8 397 """ 398 args = dict( 399 newLlamaHostId = new_llama_host_id, 400 zkServiceName = zk_service_name, 401 newLlamaRoleName = new_llama_role_name 402 ) 403 return self._cmd('impalaEnableLlamaHa', data=args, api_version=8)
404
405 - def disable_llama_ha(self, active_name):
406 """ 407 Disable high availability for an Impala Llama active-standby pair. 408 409 This command only applies to CDH 5.1+ Impala services. 410 411 @param active_name: name of the Llama role that will be active after 412 the disable operation. The other Llama role will 413 be removed. 414 415 @return: Reference to the submitted command. 416 @since: API v8 417 """ 418 args = dict( 419 activeName = active_name 420 ) 421 return self._cmd('impalaDisableLlamaHa', data=args, api_version=8)
422
423 - def get_yarn_applications(self, start_time, end_time, filter_str="", limit=100, 424 offset=0):
425 """ 426 Returns a list of YARN applications that satisfy the filter 427 @type start_time: datetime.datetime. Note that the datetime must either be 428 time zone aware or specified in the server time zone. See 429 the python datetime documentation for more details about 430 python's time zone handling. 431 @param start_time: Applications must have ended after this time 432 @type end_time: datetime.datetime. Note that the datetime must either be 433 time zone aware or specified in the server time zone. See 434 the python datetime documentation for more details about 435 python's time zone handling. 436 @param filter_str: A filter to apply to the applications. For example: 437 'user = root and applicationDuration > 5s' 438 @param limit: The maximum number of results to return 439 @param offset: The offset into the return list 440 @since: API v6 441 """ 442 params = { 443 'from': start_time.isoformat(), 444 'to': end_time.isoformat(), 445 'filter': filter_str, 446 'limit': limit, 447 'offset': offset 448 } 449 return self._get("yarnApplications", ApiYarnApplicationResponse, 450 params=params, api_version=6)
451
452 - def kill_yarn_application(self, application_id):
453 """ 454 Kills the application. 455 456 @return: The warning message, if any. 457 @since: API v6 458 """ 459 return self._post("yarnApplications/%s/kill" % (application_id, ), 460 ApiYarnKillResponse, api_version=6)
461
463 """ 464 Returns the list of all attributes that the Service Monitor can associate 465 with YARN applications. 466 467 Examples of attributes include the user who ran the application and the 468 number of maps completed by the application. 469 470 These attributes can be used to search for specific YARN applications through 471 the get_yarn_applications API. For example the 'user' attribute could be used 472 in the search 'user = root'. If the attribute is numeric it can also be used 473 as a metric in a tsquery (ie, 'select maps_completed from YARN_APPLICATIONS'). 474 475 Note that this response is identical for all YARN services. 476 477 @return: A list of the YARN application attributes 478 @since API v6 479 """ 480 return self._get("yarnApplications/attributes", ApiYarnApplicationAttribute, 481 ret_is_list=True, api_version=6)
482
484 """ 485 Create the Yarn job history directory. 486 487 @return: Reference to submitted command. 488 @since: API v6 489 """ 490 return self._cmd('yarnCreateJobHistoryDirCommand', api_version=6)
491
493 """ 494 Create the Yarn NodeManager remote application log directory. 495 496 @return: Reference to submitted command. 497 @since: API v6 498 """ 499 return self._cmd('yarnNodeManagerRemoteAppLogDirCommand', api_version=6)
500
501 - def collect_yarn_application_diagnostics(self, *application_ids):
502 """ 503 DEPRECATED: use create_yarn_application_diagnostics_bundle on the Yarn service. Deprecated since v10. 504 505 Collects the Diagnostics data for Yarn applications. 506 507 @param application_ids: An array of strings containing the ids of the 508 yarn applications. 509 @return: Reference to the submitted command. 510 @since: API v8 511 """ 512 args = dict(applicationIds = application_ids) 513 return self._cmd('yarnApplicationDiagnosticsCollection', api_version=8, data=args)
514
515 - def create_yarn_application_diagnostics_bundle(self, application_ids, ticket_number=None, comments=None):
516 """ 517 Collects the Diagnostics data for Yarn applications. 518 519 @param application_ids: An array of strings containing the ids of the 520 yarn applications. 521 @param ticket_number: If applicable, the support ticket number of the issue 522 being experienced on the cluster. 523 @param comments: Additional comments 524 @return: Reference to the submitted command. 525 @since: API v10 526 """ 527 args = dict(applicationIds = application_ids, 528 ticketNumber = ticket_number, 529 comments = comments) 530 531 return self._cmd('yarnApplicationDiagnosticsCollection', api_version=10, data=args)
532
533 - def get_config(self, view = None):
534 """ 535 Retrieve the service's configuration. 536 537 Retrieves both the service configuration and role type configuration 538 for each of the service's supported role types. The role type 539 configurations are returned as a dictionary, whose keys are the 540 role type name, and values are the respective configuration dictionaries. 541 542 The 'summary' view contains strings as the dictionary values. The full 543 view contains ApiConfig instances as the values. 544 545 @param view: View to materialize ('full' or 'summary') 546 @return: 2-tuple (service config dictionary, role type configurations) 547 """ 548 path = self._path() + '/config' 549 resp = self._get_resource_root().get(path, 550 params = view and dict(view=view) or None) 551 return self._parse_svc_config(resp, view)
552
553 - def update_config(self, svc_config, **rt_configs):
554 """ 555 Update the service's configuration. 556 557 @param svc_config: Dictionary with service configuration to update. 558 @param rt_configs: Dict of role type configurations to update. 559 @return: 2-tuple (service config dictionary, role type configurations) 560 """ 561 path = self._path() + '/config' 562 563 if svc_config: 564 data = config_to_api_list(svc_config) 565 else: 566 data = { } 567 if rt_configs: 568 rt_list = [ ] 569 for rt, cfg in rt_configs.iteritems(): 570 rt_data = config_to_api_list(cfg) 571 rt_data['roleType'] = rt 572 rt_list.append(rt_data) 573 data[ROLETYPES_CFG_KEY] = rt_list 574 575 resp = self._get_resource_root().put(path, data = json.dumps(data)) 576 return self._parse_svc_config(resp)
577
578 - def create_role(self, role_name, role_type, host_id):
579 """ 580 Create a role. 581 582 @param role_name: Role name 583 @param role_type: Role type 584 @param host_id: ID of the host to assign the role to 585 @return: An ApiRole object 586 """ 587 return roles.create_role(self._get_resource_root(), self.name, role_type, 588 role_name, host_id, self._get_cluster_name())
589
590 - def delete_role(self, name):
591 """ 592 Delete a role by name. 593 594 @param name: Role name 595 @return: The deleted ApiRole object 596 """ 597 return roles.delete_role(self._get_resource_root(), self.name, name, 598 self._get_cluster_name())
599
600 - def get_role(self, name):
601 """ 602 Lookup a role by name. 603 604 @param name: Role name 605 @return: An ApiRole object 606 """ 607 return roles.get_role(self._get_resource_root(), self.name, name, 608 self._get_cluster_name())
609
610 - def get_all_roles(self, view = None):
611 """ 612 Get all roles in the service. 613 614 @param view: View to materialize ('full' or 'summary') 615 @return: A list of ApiRole objects. 616 """ 617 return roles.get_all_roles(self._get_resource_root(), self.name, 618 self._get_cluster_name(), view)
619
620 - def get_roles_by_type(self, role_type, view = None):
621 """ 622 Get all roles of a certain type in a service. 623 624 @param role_type: Role type 625 @param view: View to materialize ('full' or 'summary') 626 @return: A list of ApiRole objects. 627 """ 628 return roles.get_roles_by_type(self._get_resource_root(), self.name, 629 role_type, self._get_cluster_name(), view)
630
631 - def get_role_types(self):
632 """ 633 Get a list of role types in a service. 634 635 @return: A list of role types (strings) 636 """ 637 resp = self._get_resource_root().get(self._path() + '/roleTypes') 638 return resp[ApiList.LIST_KEY]
639
640 - def get_all_role_config_groups(self):
641 """ 642 Get a list of role configuration groups in the service. 643 644 @return: A list of ApiRoleConfigGroup objects. 645 @since: API v3 646 """ 647 return role_config_groups.get_all_role_config_groups( 648 self._get_resource_root(), self.name, self._get_cluster_name())
649
650 - def get_role_config_group(self, name):
651 """ 652 Get a role configuration group in the service by name. 653 654 @param name: The name of the role config group. 655 @return: An ApiRoleConfigGroup object. 656 @since: API v3 657 """ 658 return role_config_groups.get_role_config_group( 659 self._get_resource_root(), self.name, name, self._get_cluster_name())
660
661 - def create_role_config_group(self, name, display_name, role_type):
662 """ 663 Create a role config group. 664 665 @param name: The name of the new group. 666 @param display_name: The display name of the new group. 667 @param role_type: The role type of the new group. 668 @return: New ApiRoleConfigGroup object. 669 @since: API v3 670 """ 671 return role_config_groups.create_role_config_group( 672 self._get_resource_root(), self.name, name, display_name, role_type, 673 self._get_cluster_name())
674
675 - def update_role_config_group(self, name, apigroup):
676 """ 677 Update a role config group. 678 679 @param name: Role config group name. 680 @param apigroup: The updated role config group. 681 @return: The updated ApiRoleConfigGroup object. 682 @since: API v3 683 """ 684 return role_config_groups.update_role_config_group( 685 self._get_resource_root(), self.name, name, apigroup, 686 self._get_cluster_name())
687
688 - def delete_role_config_group(self, name):
689 """ 690 Delete a role config group by name. 691 692 @param name: Role config group name. 693 @return: The deleted ApiRoleConfigGroup object. 694 @since: API v3 695 """ 696 return role_config_groups.delete_role_config_group( 697 self._get_resource_root(), self.name, name, self._get_cluster_name())
698
699 - def get_metrics(self, from_time=None, to_time=None, metrics=None, view=None):
700 """ 701 This endpoint is not supported as of v6. Use the timeseries API 702 instead. To get all metrics for a service with the timeseries API use 703 the query: 704 705 'select * where serviceName = $SERVICE_NAME'. 706 707 To get specific metrics for a service use a comma-separated list of 708 the metric names as follows: 709 710 'select $METRIC_NAME1, $METRIC_NAME2 where serviceName = $SERVICE_NAME'. 711 712 For more information see http://tiny.cloudera.com/tsquery_doc 713 714 Retrieve metric readings for the service. 715 @param from_time: A datetime; start of the period to query (optional). 716 @param to_time: A datetime; end of the period to query (default = now). 717 @param metrics: List of metrics to query (default = all). 718 @param view: View to materialize ('full' or 'summary') 719 @return: List of metrics and their readings. 720 """ 721 return self._get_resource_root().get_metrics(self._path() + '/metrics', 722 from_time, to_time, metrics, view)
723
724 - def start(self):
725 """ 726 Start a service. 727 728 @return: Reference to the submitted command. 729 """ 730 return self._cmd('start')
731
732 - def stop(self):
733 """ 734 Stop a service. 735 736 @return: Reference to the submitted command. 737 """ 738 return self._cmd('stop')
739
740 - def restart(self):
741 """ 742 Restart a service. 743 744 @return: Reference to the submitted command. 745 """ 746 return self._cmd('restart')
747
748 - def start_roles(self, *role_names):
749 """ 750 Start a list of roles. 751 752 @param role_names: names of the roles to start. 753 @return: List of submitted commands. 754 """ 755 return self._role_cmd('start', role_names)
756
757 - def stop_roles(self, *role_names):
758 """ 759 Stop a list of roles. 760 761 @param role_names: names of the roles to stop. 762 @return: List of submitted commands. 763 """ 764 return self._role_cmd('stop', role_names)
765
766 - def restart_roles(self, *role_names):
767 """ 768 Restart a list of roles. 769 770 @param role_names: names of the roles to restart. 771 @return: List of submitted commands. 772 """ 773 return self._role_cmd('restart', role_names)
774
775 - def bootstrap_hdfs_stand_by(self, *role_names):
776 """ 777 Bootstrap HDFS stand-by NameNodes. 778 779 Initialize their state by syncing it with the respective HA partner. 780 781 @param role_names: NameNodes to bootstrap. 782 @return: List of submitted commands. 783 """ 784 return self._role_cmd('hdfsBootstrapStandBy', role_names)
785
786 - def finalize_metadata_upgrade(self, *role_names):
787 """ 788 Finalize HDFS NameNode metadata upgrade. Should be done after doing 789 HDFS upgrade with full downtime (and not with rolling upgrade). 790 791 @param role_names: NameNodes for which to finalize the upgrade. 792 @return: List of submitted commands. 793 @since: API v3 794 """ 795 return self._role_cmd('hdfsFinalizeMetadataUpgrade', role_names, api_version=3)
796
797 - def create_beeswax_warehouse(self):
798 """ 799 DEPRECATED: use create_hive_warehouse on the Hive service. Deprecated since v3. 800 801 Create the Beeswax role's warehouse for a Hue service. 802 803 @return: Reference to the submitted command. 804 """ 805 return self._cmd('hueCreateHiveWarehouse')
806
807 - def create_hbase_root(self):
808 """ 809 Create the root directory of an HBase service. 810 811 @return: Reference to the submitted command. 812 """ 813 return self._cmd('hbaseCreateRoot')
814
815 - def create_hdfs_tmp(self):
816 """ 817 Create the /tmp directory in HDFS with appropriate ownership and permissions. 818 819 @return: Reference to the submitted command 820 @since: API v2 821 """ 822 return self._cmd('hdfsCreateTmpDir')
823
824 - def refresh(self, *role_names):
825 """ 826 Execute the "refresh" command on a set of roles. 827 828 @param role_names: Names of the roles to refresh. 829 @return: Reference to the submitted command. 830 """ 831 return self._role_cmd('refresh', role_names)
832
833 - def decommission(self, *role_names):
834 """ 835 Decommission roles in a service. 836 837 @param role_names: Names of the roles to decommission. 838 @return: Reference to the submitted command. 839 """ 840 return self._cmd('decommission', data=role_names)
841
842 - def offline(self, *role_names, **options):
843 """ 844 Offline roles in a service. 845 846 @param role_names: List of names of the roles to offline. 847 @param options: Dictionary of options. The following are recognized: 848 timeout - Offline timeout in seconds. 849 Specify to override the default offline timeout of 4 hours. 850 @return: Reference to the submitted command. 851 @since: API v17 852 """ 853 timeout = options.pop("timeout", None) 854 return self._cmd('offline', data=role_names, 855 params=timeout and dict(timeout=timeout) or dict(), 856 api_version=17)
857
858 - def recommission(self, *role_names):
859 """ 860 Recommission roles in a service. 861 862 @param role_names: Names of the roles to recommission. 863 @return: Reference to the submitted command. 864 @since: API v2 865 """ 866 return self._cmd('recommission', data=role_names)
867
868 - def recommission_with_start(self, *role_names):
869 """ 870 Recommission roles in a service. Roles are started before recommissioning. 871 872 Warning: Evolving. This method may change in the future and does not offer 873 standard compatibility guarantees. 874 Only support by HDFS. 875 Do not use without guidance from Cloudera. 876 877 @param role_names: Names of the roles to recommission. 878 @return: Reference to the submitted command. 879 @since: API v15 880 """ 881 return self._cmd('recommissionWithStart', data=role_names, api_version=15)
882
883 - def deploy_client_config(self, *role_names):
884 """ 885 Deploys client configuration to the hosts where roles are running. 886 887 @param role_names: Names of the roles to decommission. 888 @return: Reference to the submitted command. 889 """ 890 return self._cmd('deployClientConfig', data=role_names)
891
892 - def disable_hdfs_auto_failover(self, nameservice):
893 """ 894 Disable auto-failover for a highly available HDFS nameservice. 895 This command is no longer supported with API v6 onwards. Use disable_nn_ha instead. 896 897 @param nameservice: Affected nameservice. 898 @return: Reference to the submitted command. 899 """ 900 return self._cmd('hdfsDisableAutoFailover', data=nameservice)
901
902 - def disable_hdfs_ha(self, active_name, secondary_name, 903 start_dependent_services=True, deploy_client_configs=True, 904 disable_quorum_storage=False):
905 """ 906 Disable high availability for an HDFS NameNode. 907 This command is no longer supported with API v6 onwards. Use disable_nn_ha instead. 908 909 @param active_name: Name of the NameNode to keep. 910 @param secondary_name: Name of (existing) SecondaryNameNode to link to 911 remaining NameNode. 912 @param start_dependent_services: whether to re-start dependent services. 913 @param deploy_client_configs: whether to re-deploy client configurations. 914 @param disable_quorum_storage: whether to disable Quorum-based Storage. Available since API v2. 915 Quorum-based Storage will be disabled for all 916 nameservices that have Quorum-based Storage 917 enabled. 918 @return: Reference to the submitted command. 919 """ 920 args = dict( 921 activeName = active_name, 922 secondaryName = secondary_name, 923 startDependentServices = start_dependent_services, 924 deployClientConfigs = deploy_client_configs, 925 ) 926 927 version = self._get_resource_root().version 928 if version < 2: 929 if disable_quorum_storage: 930 raise AttributeError("Quorum-based Storage requires at least API version 2 available in Cloudera Manager 4.1.") 931 else: 932 args['disableQuorumStorage'] = disable_quorum_storage 933 934 return self._cmd('hdfsDisableHa', data=args)
935
936 - def enable_hdfs_auto_failover(self, nameservice, active_fc_name, 937 standby_fc_name, zk_service):
938 """ 939 Enable auto-failover for an HDFS nameservice. 940 This command is no longer supported with API v6 onwards. Use enable_nn_ha instead. 941 942 @param nameservice: Nameservice for which to enable auto-failover. 943 @param active_fc_name: Name of failover controller to create for active node. 944 @param standby_fc_name: Name of failover controller to create for stand-by node. 945 @param zk_service: ZooKeeper service to use. 946 @return: Reference to the submitted command. 947 """ 948 version = self._get_resource_root().version 949 950 args = dict( 951 nameservice = nameservice, 952 activeFCName = active_fc_name, 953 standByFCName = standby_fc_name, 954 zooKeeperService = dict( 955 clusterName = zk_service.clusterRef.clusterName, 956 serviceName = zk_service.name, 957 ), 958 ) 959 return self._cmd('hdfsEnableAutoFailover', data=args)
960
961 - def enable_hdfs_ha(self, active_name, active_shared_path, standby_name, 962 standby_shared_path, nameservice, start_dependent_services=True, 963 deploy_client_configs=True, enable_quorum_storage=False):
964 """ 965 Enable high availability for an HDFS NameNode. 966 This command is no longer supported with API v6 onwards. Use enable_nn_ha instead. 967 968 @param active_name: name of active NameNode. 969 @param active_shared_path: shared edits path for active NameNode. 970 Ignored if Quorum-based Storage is being enabled. 971 @param standby_name: name of stand-by NameNode. 972 @param standby_shared_path: shared edits path for stand-by NameNode. 973 Ignored if Quourm Journal is being enabled. 974 @param nameservice: nameservice for the HA pair. 975 @param start_dependent_services: whether to re-start dependent services. 976 @param deploy_client_configs: whether to re-deploy client configurations. 977 @param enable_quorum_storage: whether to enable Quorum-based Storage. Available since API v2. 978 Quorum-based Storage will be enabled for all 979 nameservices except those configured with NFS High 980 Availability. 981 @return: Reference to the submitted command. 982 """ 983 version = self._get_resource_root().version 984 985 args = dict( 986 activeName = active_name, 987 standByName = standby_name, 988 nameservice = nameservice, 989 startDependentServices = start_dependent_services, 990 deployClientConfigs = deploy_client_configs, 991 ) 992 993 if enable_quorum_storage: 994 if version < 2: 995 raise AttributeError("Quorum-based Storage is not supported prior to Cloudera Manager 4.1.") 996 else: 997 args['enableQuorumStorage'] = enable_quorum_storage 998 else: 999 if active_shared_path is None or standby_shared_path is None: 1000 raise AttributeError("Active and standby shared paths must be specified if not enabling Quorum-based Storage") 1001 args['activeSharedEditsPath'] = active_shared_path 1002 args['standBySharedEditsPath'] = standby_shared_path 1003 1004 return self._cmd('hdfsEnableHa', data=args)
1005
1006 - def enable_nn_ha(self, active_name, standby_host_id, nameservice, jns, 1007 standby_name_dir_list=None, qj_name=None, standby_name=None, 1008 active_fc_name=None, standby_fc_name=None, zk_service_name=None, 1009 force_init_znode=True, clear_existing_standby_name_dirs=True, clear_existing_jn_edits_dir=True):
1010 """ 1011 Enable High Availability (HA) with Auto-Failover for an HDFS NameNode. 1012 @param active_name: Name of Active NameNode. 1013 @param standby_host_id: ID of host where Standby NameNode will be created. 1014 @param nameservice: Nameservice to be used while enabling HA. 1015 Optional if Active NameNode already has this config set. 1016 @param jns: List of Journal Nodes to be created during the command. 1017 Each element of the list must be a dict containing the following keys: 1018 - B{jnHostId}: ID of the host where the new JournalNode will be created. 1019 - B{jnName}: Name of the JournalNode role (optional) 1020 - B{jnEditsDir}: Edits dir of the JournalNode. Can be omitted if the config 1021 is already set at RCG level. 1022 @param standby_name_dir_list: List of directories for the new Standby NameNode. 1023 If not provided then it will use same dirs as Active NameNode. 1024 @param qj_name: Name of the journal located on each JournalNodes' filesystem. 1025 This can be optionally provided if the config hasn't been already set for the Active NameNode. 1026 If this isn't provided and Active NameNode doesn't also have the config, 1027 then nameservice is used by default. 1028 @param standby_name: Name of the Standby NameNode role to be created (Optional). 1029 @param active_fc_name: Name of the Active Failover Controller role to be created (Optional). 1030 @param standby_fc_name: Name of the Standby Failover Controller role to be created (Optional). 1031 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 1032 If HDFS service already depends on a ZooKeeper service then that ZooKeeper 1033 service will be used for auto-failover and in that case this parameter 1034 can either be omitted or should be the same ZooKeeper service. 1035 @param force_init_znode: Indicates if the ZNode should be force initialized if it is 1036 already present. Useful while re-enabling High Availability. (Default: TRUE) 1037 @param clear_existing_standby_name_dirs: Indicates if the existing name directories for Standby NameNode 1038 should be cleared during the workflow. 1039 Useful while re-enabling High Availability. (Default: TRUE) 1040 @param clear_existing_jn_edits_dir: Indicates if the existing edits directories for the JournalNodes 1041 for the specified nameservice should be cleared during the workflow. 1042 Useful while re-enabling High Availability. (Default: TRUE) 1043 @return: Reference to the submitted command. 1044 @since: API v6 1045 """ 1046 args = dict ( 1047 activeNnName = active_name, 1048 standbyNnName = standby_name, 1049 standbyNnHostId = standby_host_id, 1050 standbyNameDirList = standby_name_dir_list, 1051 nameservice = nameservice, 1052 qjName = qj_name, 1053 activeFcName = active_fc_name, 1054 standbyFcName = standby_fc_name, 1055 zkServiceName = zk_service_name, 1056 forceInitZNode = force_init_znode, 1057 clearExistingStandbyNameDirs = clear_existing_standby_name_dirs, 1058 clearExistingJnEditsDir = clear_existing_jn_edits_dir, 1059 jns = jns 1060 ) 1061 return self._cmd('hdfsEnableNnHa', data=args, api_version=6)
1062
1063 - def disable_nn_ha(self, active_name, snn_host_id, snn_check_point_dir_list, 1064 snn_name=None):
1065 """ 1066 Disable high availability with automatic failover for an HDFS NameNode. 1067 1068 @param active_name: Name of the NamdeNode role that is going to be active after 1069 High Availability is disabled. 1070 @param snn_host_id: Id of the host where the new SecondaryNameNode will be created. 1071 @param snn_check_point_dir_list : List of directories used for checkpointing 1072 by the new SecondaryNameNode. 1073 @param snn_name: Name of the new SecondaryNameNode role (Optional). 1074 @return: Reference to the submitted command. 1075 @since: API v6 1076 """ 1077 args = dict( 1078 activeNnName = active_name, 1079 snnHostId = snn_host_id, 1080 snnCheckpointDirList = snn_check_point_dir_list, 1081 snnName = snn_name 1082 ) 1083 return self._cmd('hdfsDisableNnHa', data=args, api_version=6)
1084
1085 - def enable_jt_ha(self, new_jt_host_id, force_init_znode=True, zk_service_name=None, 1086 new_jt_name=None, fc1_name=None, fc2_name=None):
1087 """ 1088 Enable high availability for a MR JobTracker. 1089 1090 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 1091 If MapReduce service depends on a ZooKeeper service then that ZooKeeper 1092 service will be used for auto-failover and in that case this parameter 1093 can be omitted. 1094 @param new_jt_host_id: id of the host where the second JobTracker 1095 will be added. 1096 @param force_init_znode: Initialize the ZNode used for auto-failover even if 1097 it already exists. This can happen if JobTracker HA 1098 was enabled before and then disabled. Disable operation 1099 doesn't delete this ZNode. Defaults to true. 1100 @param new_jt_name: Name of the second JobTracker role to be created. 1101 @param fc1_name: Name of the Failover Controller role that is co-located with 1102 the existing JobTracker. 1103 @param fc2_name: Name of the Failover Controller role that is co-located with 1104 the new JobTracker. 1105 @return: Reference to the submitted command. 1106 @since: API v5 1107 """ 1108 args = dict( 1109 newJtHostId = new_jt_host_id, 1110 forceInitZNode = force_init_znode, 1111 zkServiceName = zk_service_name, 1112 newJtRoleName = new_jt_name, 1113 fc1RoleName = fc1_name, 1114 fc2RoleName = fc2_name 1115 ) 1116 return self._cmd('enableJtHa', data=args)
1117
1118 - def disable_jt_ha(self, active_name):
1119 """ 1120 Disable high availability for a MR JobTracker active-standby pair. 1121 1122 @param active_name: name of the JobTracker that will be active after 1123 the disable operation. The other JobTracker and 1124 Failover Controllers will be removed. 1125 @return: Reference to the submitted command. 1126 """ 1127 args = dict( 1128 activeName = active_name, 1129 ) 1130 return self._cmd('disableJtHa', data=args)
1131
1132 - def enable_rm_ha(self, new_rm_host_id, zk_service_name=None):
1133 """ 1134 Enable high availability for a YARN ResourceManager. 1135 1136 @param new_rm_host_id: id of the host where the second ResourceManager 1137 will be added. 1138 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 1139 If YARN service depends on a ZooKeeper service then that ZooKeeper 1140 service will be used for auto-failover and in that case this parameter 1141 can be omitted. 1142 @return: Reference to the submitted command. 1143 @since: API v6 1144 """ 1145 args = dict( 1146 newRmHostId = new_rm_host_id, 1147 zkServiceName = zk_service_name 1148 ) 1149 return self._cmd('enableRmHa', data=args)
1150
1151 - def disable_rm_ha(self, active_name):
1152 """ 1153 Disable high availability for a YARN ResourceManager active-standby pair. 1154 1155 @param active_name: name of the ResourceManager that will be active after 1156 the disable operation. The other ResourceManager 1157 will be removed. 1158 @return: Reference to the submitted command. 1159 @since: API v6 1160 """ 1161 args = dict( 1162 activeName = active_name 1163 ) 1164 return self._cmd('disableRmHa', data=args)
1165
1166 - def enable_oozie_ha(self, new_oozie_server_host_ids, new_oozie_server_role_names=None, 1167 zk_service_name=None, load_balancer_host_port=None):
1168 """ 1169 Enable high availability for Oozie. 1170 1171 @param new_oozie_server_host_ids: List of IDs of the hosts on which new Oozie Servers 1172 will be added. 1173 @param new_oozie_server_role_names: List of names of the new Oozie Servers. This is an 1174 optional argument, but if provided, it should 1175 match the length of host IDs provided. 1176 @param zk_service_name: Name of the ZooKeeper service that will be used for Oozie HA. 1177 This is an optional parameter if the Oozie to ZooKeeper 1178 dependency is already set. 1179 @param load_balancer_host_port: Address and port of the load balancer used for Oozie HA. 1180 This is an optional parameter if this config is already set. 1181 @return: Reference to the submitted command. 1182 @since: API v6 1183 """ 1184 args = dict( 1185 newOozieServerHostIds = new_oozie_server_host_ids, 1186 newOozieServerRoleNames = new_oozie_server_role_names, 1187 zkServiceName = zk_service_name, 1188 loadBalancerHostPort = load_balancer_host_port 1189 ) 1190 return self._cmd('oozieEnableHa', data=args, api_version=6)
1191
1192 - def disable_oozie_ha(self, active_name):
1193 """ 1194 Disable high availability for Oozie 1195 1196 @param active_name: Name of the Oozie Server that will be active after 1197 High Availability is disabled. 1198 @return: Reference to the submitted command. 1199 @since: API v6 1200 """ 1201 args = dict( 1202 activeName = active_name 1203 ) 1204 return self._cmd('oozieDisableHa', data=args, api_version=6)
1205
1206 - def failover_hdfs(self, active_name, standby_name, force=False):
1207 """ 1208 Initiate a failover of an HDFS NameNode HA pair. 1209 1210 This will make the given stand-by NameNode active, and vice-versa. 1211 1212 @param active_name: name of currently active NameNode. 1213 @param standby_name: name of NameNode currently in stand-by. 1214 @param force: whether to force failover. 1215 @return: Reference to the submitted command. 1216 """ 1217 params = { "force" : "true" and force or "false" } 1218 args = { ApiList.LIST_KEY : [ active_name, standby_name ] } 1219 return self._cmd('hdfsFailover', data=[ active_name, standby_name ], 1220 params = { "force" : "true" and force or "false" })
1221
1222 - def format_hdfs(self, *namenodes):
1223 """ 1224 Format NameNode instances of an HDFS service. 1225 1226 @param namenodes: Name of NameNode instances to format. 1227 @return: List of submitted commands. 1228 """ 1229 return self._role_cmd('hdfsFormat', namenodes)
1230
1231 - def init_hdfs_auto_failover(self, *controllers):
1232 """ 1233 Initialize HDFS failover controller metadata. 1234 1235 Only one controller per nameservice needs to be initialized. 1236 1237 @param controllers: Name of failover controller instances to initialize. 1238 @return: List of submitted commands. 1239 """ 1240 return self._role_cmd('hdfsInitializeAutoFailover', controllers)
1241
1242 - def init_hdfs_shared_dir(self, *namenodes):
1243 """ 1244 Initialize a NameNode's shared edits directory. 1245 1246 @param namenodes: Name of NameNode instances. 1247 @return: List of submitted commands. 1248 """ 1249 return self._role_cmd('hdfsInitializeSharedDir', namenodes)
1250
1251 - def roll_edits_hdfs(self, nameservice=None):
1252 """ 1253 Roll the edits of an HDFS NameNode or Nameservice. 1254 1255 @param nameservice: Nameservice whose edits should be rolled. 1256 Required only with a federated HDFS. 1257 @return: Reference to the submitted command. 1258 @since: API v3 1259 """ 1260 args = dict() 1261 if nameservice: 1262 args['nameservice'] = nameservice 1263 1264 return self._cmd('hdfsRollEdits', data=args)
1265
1266 - def upgrade_hdfs_metadata(self):
1267 """ 1268 Upgrade HDFS Metadata as part of a major version upgrade. 1269 1270 @return: Reference to the submitted command. 1271 @since: API v6 1272 """ 1273 return self._cmd('hdfsUpgradeMetadata', api_version=6)
1274
1275 - def upgrade_hbase(self):
1276 """ 1277 Upgrade HBase data in HDFS and ZooKeeper as part of upgrade from CDH4 to CDH5. 1278 1279 @return: Reference to the submitted command. 1280 @since: API v6 1281 """ 1282 return self._cmd('hbaseUpgrade', api_version=6)
1283
1284 - def create_sqoop_user_dir(self):
1285 """ 1286 Creates the user directory of a Sqoop service in HDFS. 1287 1288 @return: Reference to the submitted command. 1289 @since: API v4 1290 """ 1291 return self._cmd('createSqoopUserDir', api_version=4)
1292
1294 """ 1295 Creates the Sqoop2 Server database tables in the configured database. 1296 Will do nothing if tables already exist. Will not perform an upgrade. 1297 1298 @return: Reference to the submitted command. 1299 @since: API v10 1300 """ 1301 return self._cmd('sqoopCreateDatabaseTables', api_version=10)
1302
1303 - def upgrade_sqoop_db(self):
1304 """ 1305 Upgrade Sqoop Database schema as part of a major version upgrade. 1306 1307 @return: Reference to the submitted command. 1308 @since: API v6 1309 """ 1310 return self._cmd('sqoopUpgradeDb', api_version=6)
1311
1312 - def upgrade_hive_metastore(self):
1313 """ 1314 Upgrade Hive Metastore as part of a major version upgrade. 1315 1316 @return: Reference to the submitted command. 1317 @since: API v6 1318 """ 1319 return self._cmd('hiveUpgradeMetastore', api_version=6)
1320
1321 - def cleanup_zookeeper(self, *servers):
1322 """ 1323 Cleanup a ZooKeeper service or roles. 1324 1325 If no server role names are provided, the command applies to the whole 1326 service, and cleans up all the server roles that are currently running. 1327 1328 @param servers: ZK server role names (optional). 1329 @return: Command reference (for service command) or list of command 1330 references (for role commands). 1331 """ 1332 if servers: 1333 return self._role_cmd('zooKeeperCleanup', servers) 1334 else: 1335 return self._cmd('zooKeeperCleanup')
1336
1337 - def init_zookeeper(self, *servers):
1338 """ 1339 Initialize a ZooKeeper service or roles. 1340 1341 If no server role names are provided, the command applies to the whole 1342 service, and initializes all the configured server roles. 1343 1344 @param servers: ZK server role names (optional). 1345 @return: Command reference (for service command) or list of command 1346 references (for role commands). 1347 """ 1348 if servers: 1349 return self._role_cmd('zooKeeperInit', servers) 1350 else: 1351 return self._cmd('zooKeeperInit')
1352
1353 - def sync_hue_db(self, *servers):
1354 """ 1355 Synchronize the Hue server's database. 1356 1357 @param servers: Name of Hue Server roles to synchronize. Not required starting with API v10. 1358 @return: List of submitted commands. 1359 """ 1360 1361 actual_version = self._get_resource_root().version 1362 if actual_version < 10: 1363 return self._role_cmd('hueSyncDb', servers) 1364 1365 return self._cmd('hueSyncDb', api_version=10)
1366 1367
1368 - def dump_hue_db(self):
1369 """ 1370 Dump the Hue server's database; it can be loaded later. 1371 1372 @return: List of submitted commands. 1373 """ 1374 return self._cmd('hueDumpDb', api_version=10)
1375
1376 - def load_hue_db(self):
1377 """ 1378 Load data into Hue server's database from a previous data dump. 1379 1380 @return: List of submitted commands. 1381 """ 1382 return self._cmd('hueLoadDb', api_version=10)
1383
1384 - def lsof(self, *rolenames):
1385 """ 1386 Run the lsof diagnostic command. This command runs the lsof utility to list 1387 a role's open files. 1388 1389 @param rolenames: Name of the role instances 1390 @return: List of submitted commands. 1391 @since: API v8 1392 """ 1393 return self._role_cmd('lsof', rolenames)
1394
1395 - def jstack(self, *rolenames):
1396 """ 1397 Run the jstack diagnostic command. The command runs the jstack utility to 1398 capture a role's java thread stacks. 1399 1400 @param rolenames: Name of the role instances 1401 @return: List of submitted commands. 1402 @since: API v8 1403 """ 1404 return self._role_cmd('jstack', rolenames)
1405
1406 - def jmap_histo(self, *rolenames):
1407 """ 1408 Run the jmapHisto diagnostic command. The command runs the jmap utility to 1409 capture a histogram of the objects on the role's java heap. 1410 1411 @param rolenames: Name of the role instances 1412 @return: List of submitted commands. 1413 @since: API v8 1414 """ 1415 return self._role_cmd('jmapHisto', rolenames)
1416
1417 - def jmap_dump(self, *rolenames):
1418 """ 1419 Run the jmapDump diagnostic command. The command runs the jmap utility to 1420 capture a dump of the role's java heap. 1421 1422 @param rolenames: Name of the role instances 1423 @return: List of submitted commands. 1424 @since: API v8 1425 """ 1426 return self._role_cmd('jmapDump', rolenames)
1427
1428 - def enter_maintenance_mode(self):
1429 """ 1430 Put the service in maintenance mode. 1431 1432 @return: Reference to the completed command. 1433 @since: API v2 1434 """ 1435 cmd = self._cmd('enterMaintenanceMode') 1436 if cmd.success: 1437 self._update(_get_service(self._get_resource_root(), self._path())) 1438 return cmd
1439
1440 - def exit_maintenance_mode(self):
1441 """ 1442 Take the service out of maintenance mode. 1443 1444 @return: Reference to the completed command. 1445 @since: API v2 1446 """ 1447 cmd = self._cmd('exitMaintenanceMode') 1448 if cmd.success: 1449 self._update(_get_service(self._get_resource_root(), self._path())) 1450 return cmd
1451
1452 - def rolling_restart(self, slave_batch_size=None, 1453 slave_fail_count_threshold=None, 1454 sleep_seconds=None, 1455 stale_configs_only=None, 1456 unupgraded_only=None, 1457 restart_role_types=None, 1458 restart_role_names=None):
1459 """ 1460 Rolling restart the roles of a service. The sequence is: 1461 1. Restart all the non-slave roles 1462 2. If slaves are present restart them in batches of size specified 1463 3. Perform any post-command needed after rolling restart 1464 1465 @param slave_batch_size: Number of slave roles to restart at a time 1466 Must be greater than 0. Default is 1. 1467 For HDFS, this number should be less than the replication factor (default 3) 1468 to ensure data availability during rolling restart. 1469 @param slave_fail_count_threshold: The threshold for number of slave batches that 1470 are allowed to fail to restart before the entire command is considered failed. 1471 Must be >= 0. Default is 0. 1472 @param sleep_seconds: Number of seconds to sleep between restarts of slave role batches. 1473 Must be >=0. Default is 0. 1474 @param stale_configs_only: Restart roles with stale configs only. Default is false. 1475 @param unupgraded_only: Restart roles that haven't been upgraded yet. Default is false. 1476 @param restart_role_types: Role types to restart. If not specified, all startable roles are restarted. 1477 @param restart_role_names: List of specific roles to restart. 1478 If none are specified, then all roles of specified role types are restarted. 1479 @return: Reference to the submitted command. 1480 @since: API v3 1481 """ 1482 args = dict() 1483 if slave_batch_size: 1484 args['slaveBatchSize'] = slave_batch_size 1485 if slave_fail_count_threshold: 1486 args['slaveFailCountThreshold'] = slave_fail_count_threshold 1487 if sleep_seconds: 1488 args['sleepSeconds'] = sleep_seconds 1489 if stale_configs_only: 1490 args['staleConfigsOnly'] = stale_configs_only 1491 if unupgraded_only: 1492 args['unUpgradedOnly'] = unupgraded_only 1493 if restart_role_types: 1494 args['restartRoleTypes'] = restart_role_types 1495 if restart_role_names: 1496 args['restartRoleNames'] = restart_role_names 1497 1498 return self._cmd('rollingRestart', data=args)
1499
1500 - def create_replication_schedule(self, 1501 start_time, end_time, interval_unit, interval, paused, arguments, 1502 alert_on_start=False, alert_on_success=False, alert_on_fail=False, 1503 alert_on_abort=False):
1504 """ 1505 Create a new replication schedule for this service. 1506 1507 The replication argument type varies per service type. The following types 1508 are recognized: 1509 - HDFS: ApiHdfsReplicationArguments 1510 - Hive: ApiHiveReplicationArguments 1511 1512 @type start_time: datetime.datetime 1513 @param start_time: The time at which the schedule becomes active and first executes. 1514 @type end_time: datetime.datetime 1515 @param end_time: The time at which the schedule will expire. 1516 @type interval_unit: str 1517 @param interval_unit: The unit of time the `interval` represents. Ex. MINUTE, HOUR, 1518 DAY. See the server documentation for a full list of values. 1519 @type interval: int 1520 @param interval: The number of time units to wait until triggering the next replication. 1521 @type paused: bool 1522 @param paused: Should the schedule be paused? Useful for on-demand replication. 1523 @param arguments: service type-specific arguments for the replication job. 1524 @param alert_on_start: whether to generate alerts when the job is started. 1525 @param alert_on_success: whether to generate alerts when the job succeeds. 1526 @param alert_on_fail: whether to generate alerts when the job fails. 1527 @param alert_on_abort: whether to generate alerts when the job is aborted. 1528 @return: The newly created schedule. 1529 @since: API v3 1530 """ 1531 schedule = ApiReplicationSchedule(self._get_resource_root(), 1532 startTime=start_time, endTime=end_time, intervalUnit=interval_unit, interval=interval, 1533 paused=paused, alertOnStart=alert_on_start, alertOnSuccess=alert_on_success, 1534 alertOnFail=alert_on_fail, alertOnAbort=alert_on_abort) 1535 1536 if self.type == 'HDFS': 1537 if isinstance(arguments, ApiHdfsCloudReplicationArguments): 1538 schedule.hdfsCloudArguments = arguments 1539 elif isinstance(arguments, ApiHdfsReplicationArguments): 1540 schedule.hdfsArguments = arguments 1541 else: 1542 raise TypeError, 'Unexpected type for HDFS replication argument.' 1543 elif self.type == 'HIVE': 1544 if not isinstance(arguments, ApiHiveReplicationArguments): 1545 raise TypeError, 'Unexpected type for Hive replication argument.' 1546 schedule.hiveArguments = arguments 1547 else: 1548 raise TypeError, 'Replication is not supported for service type ' + self.type 1549 1550 return self._post("replications", ApiReplicationSchedule, True, [schedule], 1551 api_version=3)[0]
1552
1553 - def get_replication_schedules(self):
1554 """ 1555 Retrieve a list of replication schedules. 1556 1557 @return: A list of replication schedules. 1558 @since: API v3 1559 """ 1560 return self._get("replications", ApiReplicationSchedule, True, 1561 api_version=3)
1562
1563 - def get_replication_schedule(self, schedule_id):
1564 """ 1565 Retrieve a single replication schedule. 1566 1567 @param schedule_id: The id of the schedule to retrieve. 1568 @return: The requested schedule. 1569 @since: API v3 1570 """ 1571 return self._get("replications/%d" % schedule_id, ApiReplicationSchedule, 1572 api_version=3)
1573
1574 - def delete_replication_schedule(self, schedule_id):
1575 """ 1576 Delete a replication schedule. 1577 1578 @param schedule_id: The id of the schedule to delete. 1579 @return: The deleted replication schedule. 1580 @since: API v3 1581 """ 1582 return self._delete("replications/%s" % schedule_id, ApiReplicationSchedule, 1583 api_version=3)
1584
1585 - def update_replication_schedule(self, schedule_id, schedule):
1586 """ 1587 Update a replication schedule. 1588 1589 @param schedule_id: The id of the schedule to update. 1590 @param schedule: The modified schedule. 1591 @return: The updated replication schedule. 1592 @since: API v3 1593 """ 1594 return self._put("replications/%s" % schedule_id, ApiReplicationSchedule, 1595 data=schedule, api_version=3)
1596
1597 - def get_replication_command_history(self, schedule_id, limit=20, offset=0, 1598 view=None):
1599 """ 1600 Retrieve a list of commands for a replication schedule. 1601 1602 @param schedule_id: The id of the replication schedule. 1603 @param limit: Maximum number of commands to retrieve. 1604 @param offset: Index of first command to retrieve. 1605 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1606 @return: List of commands executed for a replication schedule. 1607 @since: API v4 1608 """ 1609 params = { 1610 'limit': limit, 1611 'offset': offset, 1612 } 1613 if view: 1614 params['view'] = view 1615 1616 return self._get("replications/%s/history" % schedule_id, 1617 ApiReplicationCommand, True, params=params, api_version=4)
1618
1619 - def trigger_replication_schedule(self, schedule_id, dry_run=False):
1620 """ 1621 Trigger replication immediately. Start and end dates on the schedule will be 1622 ignored. 1623 1624 @param schedule_id: The id of the schedule to trigger. 1625 @param dry_run: Whether to execute a dry run. 1626 @return: The command corresponding to the replication job. 1627 @since: API v3 1628 """ 1629 return self._post("replications/%s/run" % schedule_id, ApiCommand, 1630 params=dict(dryRun=dry_run), 1631 api_version=3)
1632
1633 - def create_snapshot_policy(self, policy):
1634 """ 1635 Create a new snapshot policy for this service. 1636 @param policy: The snapshot policy to create 1637 @return: The newly created policy. 1638 @since: API v6 1639 """ 1640 return self._post("snapshots/policies", ApiSnapshotPolicy, True, [policy], 1641 api_version=6)[0]
1642
1643 - def get_snapshot_policies(self, view=None):
1644 """ 1645 Retrieve a list of snapshot policies. 1646 1647 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1648 @return: A list of snapshot policies. 1649 @since: API v6 1650 """ 1651 return self._get("snapshots/policies", ApiSnapshotPolicy, True, 1652 params=view and dict(view=view) or None, api_version=6)
1653
1654 - def get_snapshot_policy(self, name, view=None):
1655 """ 1656 Retrieve a single snapshot policy. 1657 1658 @param name: The name of the snapshot policy to retrieve. 1659 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1660 @return: The requested snapshot policy. 1661 @since: API v6 1662 """ 1663 return self._get("snapshots/policies/%s" % name, ApiSnapshotPolicy, 1664 params=view and dict(view=view) or None, api_version=6)
1665
1666 - def delete_snapshot_policy(self, name):
1667 """ 1668 Delete a snapshot policy. 1669 1670 @param name: The name of the snapshot policy to delete. 1671 @return: The deleted snapshot policy. 1672 @since: API v6 1673 """ 1674 return self._delete("snapshots/policies/%s" % name, ApiSnapshotPolicy, api_version=6)
1675
1676 - def update_snapshot_policy(self, name, policy):
1677 """ 1678 Update a snapshot policy. 1679 1680 @param name: The name of the snapshot policy to update. 1681 @param policy: The modified snapshot policy. 1682 @return: The updated snapshot policy. 1683 @since: API v6 1684 """ 1685 return self._put("snapshots/policies/%s" % name, ApiSnapshotPolicy, data=policy, 1686 api_version=6)
1687
1688 - def get_snapshot_command_history(self, name, limit=20, offset=0, view=None):
1689 """ 1690 Retrieve a list of commands triggered by a snapshot policy. 1691 1692 @param name: The name of the snapshot policy. 1693 @param limit: Maximum number of commands to retrieve. 1694 @param offset: Index of first command to retrieve. 1695 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1696 @return: List of commands triggered by a snapshot policy. 1697 @since: API v6 1698 """ 1699 params = { 1700 'limit': limit, 1701 'offset': offset, 1702 } 1703 if view: 1704 params['view'] = view 1705 1706 return self._get("snapshots/policies/%s/history" % name, ApiSnapshotCommand, True, 1707 params=params, api_version=6)
1708 1709
1710 - def install_oozie_sharelib(self):
1711 """ 1712 Installs the Oozie ShareLib. Oozie must be stopped before running this 1713 command. 1714 1715 @return: Reference to the submitted command. 1716 @since: API v3 1717 """ 1718 return self._cmd('installOozieShareLib', api_version=3)
1719
1721 """ 1722 Create the Oozie Server Database. Only works with embedded postgresql 1723 database. This command should usually be followed by a call to 1724 create_oozie_db. 1725 1726 @return: Reference to the submitted command. 1727 @since: API v10 1728 """ 1729 return self._cmd('oozieCreateEmbeddedDatabase', api_version=10)
1730
1731 - def create_oozie_db(self):
1732 """ 1733 Creates the Oozie Database Schema in the configured database. 1734 This command does not create database. This command creates only tables 1735 required by Oozie. To create database, please refer to create_oozie_embedded_database. 1736 1737 @return: Reference to the submitted command. 1738 @since: API v2 1739 """ 1740 return self._cmd('createOozieDb', api_version=2)
1741
1742 - def upgrade_oozie_db(self):
1743 """ 1744 Upgrade Oozie Database schema as part of a major version upgrade. 1745 1746 @return: Reference to the submitted command. 1747 @since: API v6 1748 """ 1749 return self._cmd('oozieUpgradeDb', api_version=6)
1750
1751 - def init_solr(self):
1752 """ 1753 Initializes the Solr service in Zookeeper. 1754 1755 @return: Reference to the submitted command. 1756 @since: API v4 1757 """ 1758 return self._cmd('initSolr', api_version=4)
1759
1760 - def create_solr_hdfs_home_dir(self):
1761 """ 1762 Creates the home directory of a Solr service in HDFS. 1763 1764 @return: Reference to the submitted command. 1765 @since: API v4 1766 """ 1767 return self._cmd('createSolrHdfsHomeDir', api_version=4)
1768
1770 """ 1771 Creates the Hive metastore tables in the configured database. 1772 Will do nothing if tables already exist. Will not perform an upgrade. 1773 1774 @return: Reference to the submitted command. 1775 @since: API v3 1776 """ 1777 return self._cmd('hiveCreateMetastoreDatabaseTables', api_version=3)
1778
1779 - def create_hive_warehouse(self):
1780 """ 1781 Creates the Hive warehouse directory in HDFS. 1782 1783 @return: Reference to the submitted command. 1784 @since: API v3 1785 """ 1786 return self._cmd('hiveCreateHiveWarehouse')
1787
1788 - def create_hive_userdir(self):
1789 """ 1790 Creates the Hive user directory in HDFS. 1791 1792 @return: Reference to the submitted command. 1793 @since: API v4 1794 """ 1795 return self._cmd('hiveCreateHiveUserDir')
1796
1798 """ 1799 Create the Hive Metastore Database. Only works with embedded postgresql 1800 database. This command should usually be followed by a call to 1801 create_hive_metastore_tables. 1802 1803 @return: Reference to the submitted command. 1804 @since: API v4 1805 """ 1806 return self._cmd('hiveCreateMetastoreDatabase', api_version=4)
1807
1808 - def create_sentry_database(self):
1809 """ 1810 Create the Sentry Server Database. Only works with embedded postgresql 1811 database. This command should usually be followed by a call to 1812 create_sentry_database_tables. 1813 1814 @return: Reference to the submitted command. 1815 @since: API v7 1816 """ 1817 return self._cmd('sentryCreateDatabase', api_version=7)
1818
1820 """ 1821 Creates the Sentry Server database tables in the configured database. 1822 Will do nothing if tables already exist. Will not perform an upgrade. 1823 1824 @return: Reference to the submitted command. 1825 @since: API v7 1826 """ 1827 return self._cmd('sentryCreateDatabaseTables', api_version=7)
1828
1830 """ 1831 Upgrades the Sentry Server database tables in the configured database. 1832 1833 @return: Reference to the submitted command. 1834 @since: API v8 1835 """ 1836 return self._cmd('sentryUpgradeDatabaseTables', api_version=8)
1837
1838 - def update_metastore_namenodes(self):
1839 """ 1840 Update Hive Metastore to point to a NameNode's Nameservice name instead of 1841 hostname. Only available when all Hive Metastore Servers are stopped and 1842 HDFS has High Availability. 1843 1844 Back up the Hive Metastore Database before running this command. 1845 1846 @return: Reference to the submitted command. 1847 @since: API v4 1848 """ 1849 return self._cmd('hiveUpdateMetastoreNamenodes', api_version=4)
1850
1852 """ 1853 Import MapReduce configuration into Yarn, overwriting Yarn configuration. 1854 1855 You will lose existing Yarn configuration. Read all MapReduce 1856 configuration, role assignments, and role configuration groups and update 1857 Yarn with corresponding values. MR1 configuration will be converted into 1858 the equivalent MR2 configuration. 1859 1860 Before running this command, Yarn must be stopped and MapReduce must exist 1861 with valid configuration. 1862 1863 @return: Reference to the submitted command. 1864 @since: API v6 1865 """ 1866 return self._cmd('importMrConfigsIntoYarn', api_version=6)
1867
1868 - def switch_to_mr2(self):
1869 """ 1870 Change the cluster to use MR2 instead of MR1. Services will be restarted. 1871 1872 Will perform the following steps: 1873 * Update all services that depend on MapReduce to instead depend on Yarn. 1874 * Stop MapReduce 1875 * Start Yarn (includes MR2) 1876 * Deploy Yarn (MR2) Client Configuration 1877 1878 Available since API v6. 1879 1880 @return: Reference to the submitted command. 1881 @since: API v6 1882 """ 1883 return self._cmd('switchToMr2', api_version=6)
1884
1885 - def finalize_rolling_upgrade(self):
1886 """ 1887 Finalizes the rolling upgrade for HDFS by updating the NameNode 1888 metadata permanently to the next version. Should be done after 1889 doing a rolling upgrade to a CDH version >= 5.2.0. 1890 1891 @return: Reference to the submitted command. 1892 @since: API v8 1893 """ 1894 return self._cmd('hdfsFinalizeRollingUpgrade', api_version=8)
1895
1896 - def role_command_by_name(self, command_name, *role_names):
1897 """ 1898 Executes a role command by name on the specified 1899 roles 1900 1901 @param command_name: The name of the command. 1902 @param role_names: The role names to execute this command on. 1903 @return: Reference to the submitted command. 1904 @since: API v6 1905 """ 1906 return self._role_cmd(command_name, role_names, api_version=6)
1907
1908 - def service_command_by_name(self, command_name):
1909 """ 1910 Executes a command on the service specified 1911 by name. 1912 1913 @param command_name: The name of the command. 1914 @return: Reference to the submitted command. 1915 @since: API v6 1916 """ 1917 return self._cmd(command_name, api_version=6)
1918
1919 - def list_commands_by_name(self):
1920 """ 1921 Lists all the commands that can be executed by name 1922 on the provided service. 1923 1924 @return: A list of command metadata objects 1925 @since: API v6 1926 """ 1927 return self._get("commandsByName", ApiCommandMetadata, True, 1928 api_version=6)
1929
1931 """ 1932 Creates the HDFS directory where YARN container usage metrics are 1933 stored by NodeManagers for CM to read and aggregate into app usage metrics. 1934 1935 @return: Reference to submitted command. 1936 @since: API v13 1937 """ 1938 return self._cmd('yarnCreateCmContainerUsageInputDirCommand', api_version=13)
1939
1941 """ 1942 Validates the Hive metastore database schema. 1943 1944 @return: Reference to the submitted command. 1945 @since: API v7 1946 """ 1947 return self._cmd('hiveValidateMetastoreSchema', api_version=17)
1948
1949 -class ApiServiceSetupInfo(ApiService):
1950 _ATTRIBUTES = { 1951 'name' : None, 1952 'type' : None, 1953 'config' : Attr(ApiConfig), 1954 'roles' : Attr(roles.ApiRole), 1955 } 1956
1957 - def __init__(self, name=None, type=None, 1958 config=None, roles=None):
1959 # The BaseApiObject expects a resource_root, which we don't care about 1960 resource_root = None 1961 # Unfortunately, the json key is called "type". So our input arg 1962 # needs to be called "type" as well, despite it being a python keyword. 1963 BaseApiObject.init(self, None, locals())
1964
1965 - def set_config(self, config):
1966 """ 1967 Set the service configuration. 1968 1969 @param config: A dictionary of config key/value 1970 """ 1971 if self.config is None: 1972 self.config = { } 1973 self.config.update(config_to_api_list(config))
1974
1975 - def add_role_type_info(self, role_type, config):
1976 """ 1977 Add a role type setup info. 1978 1979 @param role_type: Role type 1980 @param config: A dictionary of role type configuration 1981 """ 1982 rt_config = config_to_api_list(config) 1983 rt_config['roleType'] = role_type 1984 1985 if self.config is None: 1986 self.config = { } 1987 if not self.config.has_key(ROLETYPES_CFG_KEY): 1988 self.config[ROLETYPES_CFG_KEY] = [ ] 1989 self.config[ROLETYPES_CFG_KEY].append(rt_config)
1990
1991 - def add_role_info(self, role_name, role_type, host_id, config=None):
1992 """ 1993 Add a role info. The role will be created along with the service setup. 1994 1995 @param role_name: Role name 1996 @param role_type: Role type 1997 @param host_id: The host where the role should run 1998 @param config: (Optional) A dictionary of role config values 1999 """ 2000 if self.roles is None: 2001 self.roles = [ ] 2002 api_config_list = config is not None and config_to_api_list(config) or None 2003 self.roles.append({ 2004 'name' : role_name, 2005 'type' : role_type, 2006 'hostRef' : { 'hostId' : host_id }, 2007 'config' : api_config_list })
2008
2009 - def first_run(self):
2010 """ 2011 Prepare and start this service. 2012 Perform all the steps needed to prepare and start this service. 2013 2014 @return: Reference to the submitted command. 2015 @since: API v7 2016 """ 2017 return self._cmd('firstRun', None, api_version=7)
2018