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 recommission(self, *role_names):
843 """ 844 Recommission roles in a service. 845 846 @param role_names: Names of the roles to recommission. 847 @return: Reference to the submitted command. 848 @since: API v2 849 """ 850 return self._cmd('recommission', data=role_names)
851
852 - def deploy_client_config(self, *role_names):
853 """ 854 Deploys client configuration to the hosts where roles are running. 855 856 @param role_names: Names of the roles to decommission. 857 @return: Reference to the submitted command. 858 """ 859 return self._cmd('deployClientConfig', data=role_names)
860
861 - def disable_hdfs_auto_failover(self, nameservice):
862 """ 863 Disable auto-failover for a highly available HDFS nameservice. 864 This command is no longer supported with API v6 onwards. Use disable_nn_ha instead. 865 866 @param nameservice: Affected nameservice. 867 @return: Reference to the submitted command. 868 """ 869 return self._cmd('hdfsDisableAutoFailover', data=nameservice)
870
871 - def disable_hdfs_ha(self, active_name, secondary_name, 872 start_dependent_services=True, deploy_client_configs=True, 873 disable_quorum_storage=False):
874 """ 875 Disable high availability for an HDFS NameNode. 876 This command is no longer supported with API v6 onwards. Use disable_nn_ha instead. 877 878 @param active_name: Name of the NameNode to keep. 879 @param secondary_name: Name of (existing) SecondaryNameNode to link to 880 remaining NameNode. 881 @param start_dependent_services: whether to re-start dependent services. 882 @param deploy_client_configs: whether to re-deploy client configurations. 883 @param disable_quorum_storage: whether to disable Quorum-based Storage. Available since API v2. 884 Quorum-based Storage will be disabled for all 885 nameservices that have Quorum-based Storage 886 enabled. 887 @return: Reference to the submitted command. 888 """ 889 args = dict( 890 activeName = active_name, 891 secondaryName = secondary_name, 892 startDependentServices = start_dependent_services, 893 deployClientConfigs = deploy_client_configs, 894 ) 895 896 version = self._get_resource_root().version 897 if version < 2: 898 if disable_quorum_storage: 899 raise AttributeError("Quorum-based Storage requires at least API version 2 available in Cloudera Manager 4.1.") 900 else: 901 args['disableQuorumStorage'] = disable_quorum_storage 902 903 return self._cmd('hdfsDisableHa', data=args)
904
905 - def enable_hdfs_auto_failover(self, nameservice, active_fc_name, 906 standby_fc_name, zk_service):
907 """ 908 Enable auto-failover for an HDFS nameservice. 909 This command is no longer supported with API v6 onwards. Use enable_nn_ha instead. 910 911 @param nameservice: Nameservice for which to enable auto-failover. 912 @param active_fc_name: Name of failover controller to create for active node. 913 @param standby_fc_name: Name of failover controller to create for stand-by node. 914 @param zk_service: ZooKeeper service to use. 915 @return: Reference to the submitted command. 916 """ 917 version = self._get_resource_root().version 918 919 args = dict( 920 nameservice = nameservice, 921 activeFCName = active_fc_name, 922 standByFCName = standby_fc_name, 923 zooKeeperService = dict( 924 clusterName = zk_service.clusterRef.clusterName, 925 serviceName = zk_service.name, 926 ), 927 ) 928 return self._cmd('hdfsEnableAutoFailover', data=args)
929
930 - def enable_hdfs_ha(self, active_name, active_shared_path, standby_name, 931 standby_shared_path, nameservice, start_dependent_services=True, 932 deploy_client_configs=True, enable_quorum_storage=False):
933 """ 934 Enable high availability for an HDFS NameNode. 935 This command is no longer supported with API v6 onwards. Use enable_nn_ha instead. 936 937 @param active_name: name of active NameNode. 938 @param active_shared_path: shared edits path for active NameNode. 939 Ignored if Quorum-based Storage is being enabled. 940 @param standby_name: name of stand-by NameNode. 941 @param standby_shared_path: shared edits path for stand-by NameNode. 942 Ignored if Quourm Journal is being enabled. 943 @param nameservice: nameservice for the HA pair. 944 @param start_dependent_services: whether to re-start dependent services. 945 @param deploy_client_configs: whether to re-deploy client configurations. 946 @param enable_quorum_storage: whether to enable Quorum-based Storage. Available since API v2. 947 Quorum-based Storage will be enabled for all 948 nameservices except those configured with NFS High 949 Availability. 950 @return: Reference to the submitted command. 951 """ 952 version = self._get_resource_root().version 953 954 args = dict( 955 activeName = active_name, 956 standByName = standby_name, 957 nameservice = nameservice, 958 startDependentServices = start_dependent_services, 959 deployClientConfigs = deploy_client_configs, 960 ) 961 962 if enable_quorum_storage: 963 if version < 2: 964 raise AttributeError("Quorum-based Storage is not supported prior to Cloudera Manager 4.1.") 965 else: 966 args['enableQuorumStorage'] = enable_quorum_storage 967 else: 968 if active_shared_path is None or standby_shared_path is None: 969 raise AttributeError("Active and standby shared paths must be specified if not enabling Quorum-based Storage") 970 args['activeSharedEditsPath'] = active_shared_path 971 args['standBySharedEditsPath'] = standby_shared_path 972 973 return self._cmd('hdfsEnableHa', data=args)
974
975 - def enable_nn_ha(self, active_name, standby_host_id, nameservice, jns, 976 standby_name_dir_list=None, qj_name=None, standby_name=None, 977 active_fc_name=None, standby_fc_name=None, zk_service_name=None, 978 force_init_znode=True, clear_existing_standby_name_dirs=True, clear_existing_jn_edits_dir=True):
979 """ 980 Enable High Availability (HA) with Auto-Failover for an HDFS NameNode. 981 @param active_name: Name of Active NameNode. 982 @param standby_host_id: ID of host where Standby NameNode will be created. 983 @param nameservice: Nameservice to be used while enabling HA. 984 Optional if Active NameNode already has this config set. 985 @param jns: List of Journal Nodes to be created during the command. 986 Each element of the list must be a dict containing the following keys: 987 - B{jnHostId}: ID of the host where the new JournalNode will be created. 988 - B{jnName}: Name of the JournalNode role (optional) 989 - B{jnEditsDir}: Edits dir of the JournalNode. Can be omitted if the config 990 is already set at RCG level. 991 @param standby_name_dir_list: List of directories for the new Standby NameNode. 992 If not provided then it will use same dirs as Active NameNode. 993 @param qj_name: Name of the journal located on each JournalNodes' filesystem. 994 This can be optionally provided if the config hasn't been already set for the Active NameNode. 995 If this isn't provided and Active NameNode doesn't also have the config, 996 then nameservice is used by default. 997 @param standby_name: Name of the Standby NameNode role to be created (Optional). 998 @param active_fc_name: Name of the Active Failover Controller role to be created (Optional). 999 @param standby_fc_name: Name of the Standby Failover Controller role to be created (Optional). 1000 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 1001 If HDFS service already depends on a ZooKeeper service then that ZooKeeper 1002 service will be used for auto-failover and in that case this parameter 1003 can either be omitted or should be the same ZooKeeper service. 1004 @param force_init_znode: Indicates if the ZNode should be force initialized if it is 1005 already present. Useful while re-enabling High Availability. (Default: TRUE) 1006 @param clear_existing_standby_name_dirs: Indicates if the existing name directories for Standby NameNode 1007 should be cleared during the workflow. 1008 Useful while re-enabling High Availability. (Default: TRUE) 1009 @param clear_existing_jn_edits_dir: Indicates if the existing edits directories for the JournalNodes 1010 for the specified nameservice should be cleared during the workflow. 1011 Useful while re-enabling High Availability. (Default: TRUE) 1012 @return: Reference to the submitted command. 1013 @since: API v6 1014 """ 1015 args = dict ( 1016 activeNnName = active_name, 1017 standbyNnName = standby_name, 1018 standbyNnHostId = standby_host_id, 1019 standbyNameDirList = standby_name_dir_list, 1020 nameservice = nameservice, 1021 qjName = qj_name, 1022 activeFcName = active_fc_name, 1023 standbyFcName = standby_fc_name, 1024 zkServiceName = zk_service_name, 1025 forceInitZNode = force_init_znode, 1026 clearExistingStandbyNameDirs = clear_existing_standby_name_dirs, 1027 clearExistingJnEditsDir = clear_existing_jn_edits_dir, 1028 jns = jns 1029 ) 1030 return self._cmd('hdfsEnableNnHa', data=args, api_version=6)
1031
1032 - def disable_nn_ha(self, active_name, snn_host_id, snn_check_point_dir_list, 1033 snn_name=None):
1034 """ 1035 Disable high availability with automatic failover for an HDFS NameNode. 1036 1037 @param active_name: Name of the NamdeNode role that is going to be active after 1038 High Availability is disabled. 1039 @param snn_host_id: Id of the host where the new SecondaryNameNode will be created. 1040 @param snn_check_point_dir_list : List of directories used for checkpointing 1041 by the new SecondaryNameNode. 1042 @param snn_name: Name of the new SecondaryNameNode role (Optional). 1043 @return: Reference to the submitted command. 1044 @since: API v6 1045 """ 1046 args = dict( 1047 activeNnName = active_name, 1048 snnHostId = snn_host_id, 1049 snnCheckpointDirList = snn_check_point_dir_list, 1050 snnName = snn_name 1051 ) 1052 return self._cmd('hdfsDisableNnHa', data=args, api_version=6)
1053
1054 - def enable_jt_ha(self, new_jt_host_id, force_init_znode=True, zk_service_name=None, 1055 new_jt_name=None, fc1_name=None, fc2_name=None):
1056 """ 1057 Enable high availability for a MR JobTracker. 1058 1059 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 1060 If MapReduce service depends on a ZooKeeper service then that ZooKeeper 1061 service will be used for auto-failover and in that case this parameter 1062 can be omitted. 1063 @param new_jt_host_id: id of the host where the second JobTracker 1064 will be added. 1065 @param force_init_znode: Initialize the ZNode used for auto-failover even if 1066 it already exists. This can happen if JobTracker HA 1067 was enabled before and then disabled. Disable operation 1068 doesn't delete this ZNode. Defaults to true. 1069 @param new_jt_name: Name of the second JobTracker role to be created. 1070 @param fc1_name: Name of the Failover Controller role that is co-located with 1071 the existing JobTracker. 1072 @param fc2_name: Name of the Failover Controller role that is co-located with 1073 the new JobTracker. 1074 @return: Reference to the submitted command. 1075 @since: API v5 1076 """ 1077 args = dict( 1078 newJtHostId = new_jt_host_id, 1079 forceInitZNode = force_init_znode, 1080 zkServiceName = zk_service_name, 1081 newJtRoleName = new_jt_name, 1082 fc1RoleName = fc1_name, 1083 fc2RoleName = fc2_name 1084 ) 1085 return self._cmd('enableJtHa', data=args)
1086
1087 - def disable_jt_ha(self, active_name):
1088 """ 1089 Disable high availability for a MR JobTracker active-standby pair. 1090 1091 @param active_name: name of the JobTracker that will be active after 1092 the disable operation. The other JobTracker and 1093 Failover Controllers will be removed. 1094 @return: Reference to the submitted command. 1095 """ 1096 args = dict( 1097 activeName = active_name, 1098 ) 1099 return self._cmd('disableJtHa', data=args)
1100
1101 - def enable_rm_ha(self, new_rm_host_id, zk_service_name=None):
1102 """ 1103 Enable high availability for a YARN ResourceManager. 1104 1105 @param new_rm_host_id: id of the host where the second ResourceManager 1106 will be added. 1107 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 1108 If YARN service depends on a ZooKeeper service then that ZooKeeper 1109 service will be used for auto-failover and in that case this parameter 1110 can be omitted. 1111 @return: Reference to the submitted command. 1112 @since: API v6 1113 """ 1114 args = dict( 1115 newRmHostId = new_rm_host_id, 1116 zkServiceName = zk_service_name 1117 ) 1118 return self._cmd('enableRmHa', data=args)
1119
1120 - def disable_rm_ha(self, active_name):
1121 """ 1122 Disable high availability for a YARN ResourceManager active-standby pair. 1123 1124 @param active_name: name of the ResourceManager that will be active after 1125 the disable operation. The other ResourceManager 1126 will be removed. 1127 @return: Reference to the submitted command. 1128 @since: API v6 1129 """ 1130 args = dict( 1131 activeName = active_name 1132 ) 1133 return self._cmd('disableRmHa', data=args)
1134
1135 - def enable_oozie_ha(self, new_oozie_server_host_ids, new_oozie_server_role_names=None, 1136 zk_service_name=None, load_balancer_host_port=None):
1137 """ 1138 Enable high availability for Oozie. 1139 1140 @param new_oozie_server_host_ids: List of IDs of the hosts on which new Oozie Servers 1141 will be added. 1142 @param new_oozie_server_role_names: List of names of the new Oozie Servers. This is an 1143 optional argument, but if provided, it should 1144 match the length of host IDs provided. 1145 @param zk_service_name: Name of the ZooKeeper service that will be used for Oozie HA. 1146 This is an optional parameter if the Oozie to ZooKeeper 1147 dependency is already set. 1148 @param load_balancer_host_port: Address and port of the load balancer used for Oozie HA. 1149 This is an optional parameter if this config is already set. 1150 @return: Reference to the submitted command. 1151 @since: API v6 1152 """ 1153 args = dict( 1154 newOozieServerHostIds = new_oozie_server_host_ids, 1155 newOozieServerRoleNames = new_oozie_server_role_names, 1156 zkServiceName = zk_service_name, 1157 loadBalancerHostPort = load_balancer_host_port 1158 ) 1159 return self._cmd('oozieEnableHa', data=args, api_version=6)
1160
1161 - def disable_oozie_ha(self, active_name):
1162 """ 1163 Disable high availability for Oozie 1164 1165 @param active_name: Name of the Oozie Server that will be active after 1166 High Availability is disabled. 1167 @return: Reference to the submitted command. 1168 @since: API v6 1169 """ 1170 args = dict( 1171 activeName = active_name 1172 ) 1173 return self._cmd('oozieDisableHa', data=args, api_version=6)
1174
1175 - def failover_hdfs(self, active_name, standby_name, force=False):
1176 """ 1177 Initiate a failover of an HDFS NameNode HA pair. 1178 1179 This will make the given stand-by NameNode active, and vice-versa. 1180 1181 @param active_name: name of currently active NameNode. 1182 @param standby_name: name of NameNode currently in stand-by. 1183 @param force: whether to force failover. 1184 @return: Reference to the submitted command. 1185 """ 1186 params = { "force" : "true" and force or "false" } 1187 args = { ApiList.LIST_KEY : [ active_name, standby_name ] } 1188 return self._cmd('hdfsFailover', data=[ active_name, standby_name ], 1189 params = { "force" : "true" and force or "false" })
1190
1191 - def format_hdfs(self, *namenodes):
1192 """ 1193 Format NameNode instances of an HDFS service. 1194 1195 @param namenodes: Name of NameNode instances to format. 1196 @return: List of submitted commands. 1197 """ 1198 return self._role_cmd('hdfsFormat', namenodes)
1199
1200 - def init_hdfs_auto_failover(self, *controllers):
1201 """ 1202 Initialize HDFS failover controller metadata. 1203 1204 Only one controller per nameservice needs to be initialized. 1205 1206 @param controllers: Name of failover controller instances to initialize. 1207 @return: List of submitted commands. 1208 """ 1209 return self._role_cmd('hdfsInitializeAutoFailover', controllers)
1210
1211 - def init_hdfs_shared_dir(self, *namenodes):
1212 """ 1213 Initialize a NameNode's shared edits directory. 1214 1215 @param namenodes: Name of NameNode instances. 1216 @return: List of submitted commands. 1217 """ 1218 return self._role_cmd('hdfsInitializeSharedDir', namenodes)
1219
1220 - def roll_edits_hdfs(self, nameservice=None):
1221 """ 1222 Roll the edits of an HDFS NameNode or Nameservice. 1223 1224 @param nameservice: Nameservice whose edits should be rolled. 1225 Required only with a federated HDFS. 1226 @return: Reference to the submitted command. 1227 @since: API v3 1228 """ 1229 args = dict() 1230 if nameservice: 1231 args['nameservice'] = nameservice 1232 1233 return self._cmd('hdfsRollEdits', data=args)
1234
1235 - def upgrade_hdfs_metadata(self):
1236 """ 1237 Upgrade HDFS Metadata as part of a major version upgrade. 1238 1239 @return: Reference to the submitted command. 1240 @since: API v6 1241 """ 1242 return self._cmd('hdfsUpgradeMetadata', api_version=6)
1243
1244 - def upgrade_hbase(self):
1245 """ 1246 Upgrade HBase data in HDFS and ZooKeeper as part of upgrade from CDH4 to CDH5. 1247 1248 @return: Reference to the submitted command. 1249 @since: API v6 1250 """ 1251 return self._cmd('hbaseUpgrade', api_version=6)
1252
1253 - def create_sqoop_user_dir(self):
1254 """ 1255 Creates the user directory of a Sqoop service in HDFS. 1256 1257 @return: Reference to the submitted command. 1258 @since: API v4 1259 """ 1260 return self._cmd('createSqoopUserDir', api_version=4)
1261
1263 """ 1264 Creates the Sqoop2 Server database tables in the configured database. 1265 Will do nothing if tables already exist. Will not perform an upgrade. 1266 1267 @return: Reference to the submitted command. 1268 @since: API v10 1269 """ 1270 return self._cmd('sqoopCreateDatabaseTables', api_version=10)
1271
1272 - def upgrade_sqoop_db(self):
1273 """ 1274 Upgrade Sqoop Database schema as part of a major version upgrade. 1275 1276 @return: Reference to the submitted command. 1277 @since: API v6 1278 """ 1279 return self._cmd('sqoopUpgradeDb', api_version=6)
1280
1281 - def upgrade_hive_metastore(self):
1282 """ 1283 Upgrade Hive Metastore as part of a major version upgrade. 1284 1285 @return: Reference to the submitted command. 1286 @since: API v6 1287 """ 1288 return self._cmd('hiveUpgradeMetastore', api_version=6)
1289
1290 - def cleanup_zookeeper(self, *servers):
1291 """ 1292 Cleanup a ZooKeeper service or roles. 1293 1294 If no server role names are provided, the command applies to the whole 1295 service, and cleans up all the server roles that are currently running. 1296 1297 @param servers: ZK server role names (optional). 1298 @return: Command reference (for service command) or list of command 1299 references (for role commands). 1300 """ 1301 if servers: 1302 return self._role_cmd('zooKeeperCleanup', servers) 1303 else: 1304 return self._cmd('zooKeeperCleanup')
1305
1306 - def init_zookeeper(self, *servers):
1307 """ 1308 Initialize a ZooKeeper service or roles. 1309 1310 If no server role names are provided, the command applies to the whole 1311 service, and initializes all the configured server roles. 1312 1313 @param servers: ZK server role names (optional). 1314 @return: Command reference (for service command) or list of command 1315 references (for role commands). 1316 """ 1317 if servers: 1318 return self._role_cmd('zooKeeperInit', servers) 1319 else: 1320 return self._cmd('zooKeeperInit')
1321
1322 - def sync_hue_db(self, *servers):
1323 """ 1324 Synchronize the Hue server's database. 1325 1326 @param servers: Name of Hue Server roles to synchronize. Not required starting with API v10. 1327 @return: List of submitted commands. 1328 """ 1329 1330 actual_version = self._get_resource_root().version 1331 if actual_version < 10: 1332 return self._role_cmd('hueSyncDb', servers) 1333 1334 return self._cmd('hueSyncDb', api_version=10)
1335 1336
1337 - def dump_hue_db(self):
1338 """ 1339 Dump the Hue server's database; it can be loaded later. 1340 1341 @return: List of submitted commands. 1342 """ 1343 return self._cmd('hueDumpDb', api_version=10)
1344
1345 - def load_hue_db(self):
1346 """ 1347 Load data into Hue server's database from a previous data dump. 1348 1349 @return: List of submitted commands. 1350 """ 1351 return self._cmd('hueLoadDb', api_version=10)
1352
1353 - def lsof(self, *rolenames):
1354 """ 1355 Run the lsof diagnostic command. This command runs the lsof utility to list 1356 a role's open files. 1357 1358 @param rolenames: Name of the role instances 1359 @return: List of submitted commands. 1360 @since: API v8 1361 """ 1362 return self._role_cmd('lsof', rolenames)
1363
1364 - def jstack(self, *rolenames):
1365 """ 1366 Run the jstack diagnostic command. The command runs the jstack utility to 1367 capture a role's java thread stacks. 1368 1369 @param rolenames: Name of the role instances 1370 @return: List of submitted commands. 1371 @since: API v8 1372 """ 1373 return self._role_cmd('jstack', rolenames)
1374
1375 - def jmap_histo(self, *rolenames):
1376 """ 1377 Run the jmapHisto diagnostic command. The command runs the jmap utility to 1378 capture a histogram of the objects on the role's java heap. 1379 1380 @param rolenames: Name of the role instances 1381 @return: List of submitted commands. 1382 @since: API v8 1383 """ 1384 return self._role_cmd('jmapHisto', rolenames)
1385
1386 - def jmap_dump(self, *rolenames):
1387 """ 1388 Run the jmapDump diagnostic command. The command runs the jmap utility to 1389 capture a dump of the role's java heap. 1390 1391 @param rolenames: Name of the role instances 1392 @return: List of submitted commands. 1393 @since: API v8 1394 """ 1395 return self._role_cmd('jmapDump', rolenames)
1396
1397 - def enter_maintenance_mode(self):
1398 """ 1399 Put the service in maintenance mode. 1400 1401 @return: Reference to the completed command. 1402 @since: API v2 1403 """ 1404 cmd = self._cmd('enterMaintenanceMode') 1405 if cmd.success: 1406 self._update(_get_service(self._get_resource_root(), self._path())) 1407 return cmd
1408
1409 - def exit_maintenance_mode(self):
1410 """ 1411 Take the service out of maintenance mode. 1412 1413 @return: Reference to the completed command. 1414 @since: API v2 1415 """ 1416 cmd = self._cmd('exitMaintenanceMode') 1417 if cmd.success: 1418 self._update(_get_service(self._get_resource_root(), self._path())) 1419 return cmd
1420
1421 - def rolling_restart(self, slave_batch_size=None, 1422 slave_fail_count_threshold=None, 1423 sleep_seconds=None, 1424 stale_configs_only=None, 1425 unupgraded_only=None, 1426 restart_role_types=None, 1427 restart_role_names=None):
1428 """ 1429 Rolling restart the roles of a service. The sequence is: 1430 1. Restart all the non-slave roles 1431 2. If slaves are present restart them in batches of size specified 1432 3. Perform any post-command needed after rolling restart 1433 1434 @param slave_batch_size: Number of slave roles to restart at a time 1435 Must be greater than 0. Default is 1. 1436 For HDFS, this number should be less than the replication factor (default 3) 1437 to ensure data availability during rolling restart. 1438 @param slave_fail_count_threshold: The threshold for number of slave batches that 1439 are allowed to fail to restart before the entire command is considered failed. 1440 Must be >= 0. Default is 0. 1441 @param sleep_seconds: Number of seconds to sleep between restarts of slave role batches. 1442 Must be >=0. Default is 0. 1443 @param stale_configs_only: Restart roles with stale configs only. Default is false. 1444 @param unupgraded_only: Restart roles that haven't been upgraded yet. Default is false. 1445 @param restart_role_types: Role types to restart. If not specified, all startable roles are restarted. 1446 @param restart_role_names: List of specific roles to restart. 1447 If none are specified, then all roles of specified role types are restarted. 1448 @return: Reference to the submitted command. 1449 @since: API v3 1450 """ 1451 args = dict() 1452 if slave_batch_size: 1453 args['slaveBatchSize'] = slave_batch_size 1454 if slave_fail_count_threshold: 1455 args['slaveFailCountThreshold'] = slave_fail_count_threshold 1456 if sleep_seconds: 1457 args['sleepSeconds'] = sleep_seconds 1458 if stale_configs_only: 1459 args['staleConfigsOnly'] = stale_configs_only 1460 if unupgraded_only: 1461 args['unUpgradedOnly'] = unupgraded_only 1462 if restart_role_types: 1463 args['restartRoleTypes'] = restart_role_types 1464 if restart_role_names: 1465 args['restartRoleNames'] = restart_role_names 1466 1467 return self._cmd('rollingRestart', data=args)
1468
1469 - def create_replication_schedule(self, 1470 start_time, end_time, interval_unit, interval, paused, arguments, 1471 alert_on_start=False, alert_on_success=False, alert_on_fail=False, 1472 alert_on_abort=False):
1473 """ 1474 Create a new replication schedule for this service. 1475 1476 The replication argument type varies per service type. The following types 1477 are recognized: 1478 - HDFS: ApiHdfsReplicationArguments 1479 - Hive: ApiHiveReplicationArguments 1480 1481 @type start_time: datetime.datetime 1482 @param start_time: The time at which the schedule becomes active and first executes. 1483 @type end_time: datetime.datetime 1484 @param end_time: The time at which the schedule will expire. 1485 @type interval_unit: str 1486 @param interval_unit: The unit of time the `interval` represents. Ex. MINUTE, HOUR, 1487 DAY. See the server documentation for a full list of values. 1488 @type interval: int 1489 @param interval: The number of time units to wait until triggering the next replication. 1490 @type paused: bool 1491 @param paused: Should the schedule be paused? Useful for on-demand replication. 1492 @param arguments: service type-specific arguments for the replication job. 1493 @param alert_on_start: whether to generate alerts when the job is started. 1494 @param alert_on_success: whether to generate alerts when the job succeeds. 1495 @param alert_on_fail: whether to generate alerts when the job fails. 1496 @param alert_on_abort: whether to generate alerts when the job is aborted. 1497 @return: The newly created schedule. 1498 @since: API v3 1499 """ 1500 schedule = ApiReplicationSchedule(self._get_resource_root(), 1501 startTime=start_time, endTime=end_time, intervalUnit=interval_unit, interval=interval, 1502 paused=paused, alertOnStart=alert_on_start, alertOnSuccess=alert_on_success, 1503 alertOnFail=alert_on_fail, alertOnAbort=alert_on_abort) 1504 1505 if self.type == 'HDFS': 1506 if isinstance(arguments, ApiHdfsCloudReplicationArguments): 1507 schedule.hdfsCloudArguments = arguments 1508 elif isinstance(arguments, ApiHdfsReplicationArguments): 1509 schedule.hdfsArguments = arguments 1510 else: 1511 raise TypeError, 'Unexpected type for HDFS replication argument.' 1512 elif self.type == 'HIVE': 1513 if not isinstance(arguments, ApiHiveReplicationArguments): 1514 raise TypeError, 'Unexpected type for Hive replication argument.' 1515 schedule.hiveArguments = arguments 1516 else: 1517 raise TypeError, 'Replication is not supported for service type ' + self.type 1518 1519 return self._post("replications", ApiReplicationSchedule, True, [schedule], 1520 api_version=3)[0]
1521
1522 - def get_replication_schedules(self):
1523 """ 1524 Retrieve a list of replication schedules. 1525 1526 @return: A list of replication schedules. 1527 @since: API v3 1528 """ 1529 return self._get("replications", ApiReplicationSchedule, True, 1530 api_version=3)
1531
1532 - def get_replication_schedule(self, schedule_id):
1533 """ 1534 Retrieve a single replication schedule. 1535 1536 @param schedule_id: The id of the schedule to retrieve. 1537 @return: The requested schedule. 1538 @since: API v3 1539 """ 1540 return self._get("replications/%d" % schedule_id, ApiReplicationSchedule, 1541 api_version=3)
1542
1543 - def delete_replication_schedule(self, schedule_id):
1544 """ 1545 Delete a replication schedule. 1546 1547 @param schedule_id: The id of the schedule to delete. 1548 @return: The deleted replication schedule. 1549 @since: API v3 1550 """ 1551 return self._delete("replications/%s" % schedule_id, ApiReplicationSchedule, 1552 api_version=3)
1553
1554 - def update_replication_schedule(self, schedule_id, schedule):
1555 """ 1556 Update a replication schedule. 1557 1558 @param schedule_id: The id of the schedule to update. 1559 @param schedule: The modified schedule. 1560 @return: The updated replication schedule. 1561 @since: API v3 1562 """ 1563 return self._put("replications/%s" % schedule_id, ApiReplicationSchedule, 1564 data=schedule, api_version=3)
1565
1566 - def get_replication_command_history(self, schedule_id, limit=20, offset=0, 1567 view=None):
1568 """ 1569 Retrieve a list of commands for a replication schedule. 1570 1571 @param schedule_id: The id of the replication schedule. 1572 @param limit: Maximum number of commands to retrieve. 1573 @param offset: Index of first command to retrieve. 1574 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1575 @return: List of commands executed for a replication schedule. 1576 @since: API v4 1577 """ 1578 params = { 1579 'limit': limit, 1580 'offset': offset, 1581 } 1582 if view: 1583 params['view'] = view 1584 1585 return self._get("replications/%s/history" % schedule_id, 1586 ApiReplicationCommand, True, params=params, api_version=4)
1587
1588 - def trigger_replication_schedule(self, schedule_id, dry_run=False):
1589 """ 1590 Trigger replication immediately. Start and end dates on the schedule will be 1591 ignored. 1592 1593 @param schedule_id: The id of the schedule to trigger. 1594 @param dry_run: Whether to execute a dry run. 1595 @return: The command corresponding to the replication job. 1596 @since: API v3 1597 """ 1598 return self._post("replications/%s/run" % schedule_id, ApiCommand, 1599 params=dict(dryRun=dry_run), 1600 api_version=3)
1601
1602 - def create_snapshot_policy(self, policy):
1603 """ 1604 Create a new snapshot policy for this service. 1605 @param policy: The snapshot policy to create 1606 @return: The newly created policy. 1607 @since: API v6 1608 """ 1609 return self._post("snapshots/policies", ApiSnapshotPolicy, True, [policy], 1610 api_version=6)[0]
1611
1612 - def get_snapshot_policies(self, view=None):
1613 """ 1614 Retrieve a list of snapshot policies. 1615 1616 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1617 @return: A list of snapshot policies. 1618 @since: API v6 1619 """ 1620 return self._get("snapshots/policies", ApiSnapshotPolicy, True, 1621 params=view and dict(view=view) or None, api_version=6)
1622
1623 - def get_snapshot_policy(self, name, view=None):
1624 """ 1625 Retrieve a single snapshot policy. 1626 1627 @param name: The name of the snapshot policy to retrieve. 1628 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1629 @return: The requested snapshot policy. 1630 @since: API v6 1631 """ 1632 return self._get("snapshots/policies/%s" % name, ApiSnapshotPolicy, 1633 params=view and dict(view=view) or None, api_version=6)
1634
1635 - def delete_snapshot_policy(self, name):
1636 """ 1637 Delete a snapshot policy. 1638 1639 @param name: The name of the snapshot policy to delete. 1640 @return: The deleted snapshot policy. 1641 @since: API v6 1642 """ 1643 return self._delete("snapshots/policies/%s" % name, ApiSnapshotPolicy, api_version=6)
1644
1645 - def update_snapshot_policy(self, name, policy):
1646 """ 1647 Update a snapshot policy. 1648 1649 @param name: The name of the snapshot policy to update. 1650 @param policy: The modified snapshot policy. 1651 @return: The updated snapshot policy. 1652 @since: API v6 1653 """ 1654 return self._put("snapshots/policies/%s" % name, ApiSnapshotPolicy, data=policy, 1655 api_version=6)
1656
1657 - def get_snapshot_command_history(self, name, limit=20, offset=0, view=None):
1658 """ 1659 Retrieve a list of commands triggered by a snapshot policy. 1660 1661 @param name: The name of the snapshot policy. 1662 @param limit: Maximum number of commands to retrieve. 1663 @param offset: Index of first command to retrieve. 1664 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1665 @return: List of commands triggered by a snapshot policy. 1666 @since: API v6 1667 """ 1668 params = { 1669 'limit': limit, 1670 'offset': offset, 1671 } 1672 if view: 1673 params['view'] = view 1674 1675 return self._get("snapshots/policies/%s/history" % name, ApiSnapshotCommand, True, 1676 params=params, api_version=6)
1677 1678
1679 - def install_oozie_sharelib(self):
1680 """ 1681 Installs the Oozie ShareLib. Oozie must be stopped before running this 1682 command. 1683 1684 @return: Reference to the submitted command. 1685 @since: API v3 1686 """ 1687 return self._cmd('installOozieShareLib', api_version=3)
1688
1690 """ 1691 Create the Oozie Server Database. Only works with embedded postgresql 1692 database. This command should usually be followed by a call to 1693 create_oozie_db. 1694 1695 @return: Reference to the submitted command. 1696 @since: API v10 1697 """ 1698 return self._cmd('oozieCreateEmbeddedDatabase', api_version=10)
1699
1700 - def create_oozie_db(self):
1701 """ 1702 Creates the Oozie Database Schema in the configured database. 1703 This command does not create database. This command creates only tables 1704 required by Oozie. To create database, please refer to create_oozie_embedded_database. 1705 1706 @return: Reference to the submitted command. 1707 @since: API v2 1708 """ 1709 return self._cmd('createOozieDb', api_version=2)
1710
1711 - def upgrade_oozie_db(self):
1712 """ 1713 Upgrade Oozie Database schema as part of a major version upgrade. 1714 1715 @return: Reference to the submitted command. 1716 @since: API v6 1717 """ 1718 return self._cmd('oozieUpgradeDb', api_version=6)
1719
1720 - def init_solr(self):
1721 """ 1722 Initializes the Solr service in Zookeeper. 1723 1724 @return: Reference to the submitted command. 1725 @since: API v4 1726 """ 1727 return self._cmd('initSolr', api_version=4)
1728
1729 - def create_solr_hdfs_home_dir(self):
1730 """ 1731 Creates the home directory of a Solr service in HDFS. 1732 1733 @return: Reference to the submitted command. 1734 @since: API v4 1735 """ 1736 return self._cmd('createSolrHdfsHomeDir', api_version=4)
1737
1739 """ 1740 Creates the Hive metastore tables in the configured database. 1741 Will do nothing if tables already exist. Will not perform an upgrade. 1742 1743 @return: Reference to the submitted command. 1744 @since: API v3 1745 """ 1746 return self._cmd('hiveCreateMetastoreDatabaseTables', api_version=3)
1747
1748 - def create_hive_warehouse(self):
1749 """ 1750 Creates the Hive warehouse directory in HDFS. 1751 1752 @return: Reference to the submitted command. 1753 @since: API v3 1754 """ 1755 return self._cmd('hiveCreateHiveWarehouse')
1756
1757 - def create_hive_userdir(self):
1758 """ 1759 Creates the Hive user directory in HDFS. 1760 1761 @return: Reference to the submitted command. 1762 @since: API v4 1763 """ 1764 return self._cmd('hiveCreateHiveUserDir')
1765
1767 """ 1768 Create the Hive Metastore Database. Only works with embedded postgresql 1769 database. This command should usually be followed by a call to 1770 create_hive_metastore_tables. 1771 1772 @return: Reference to the submitted command. 1773 @since: API v4 1774 """ 1775 return self._cmd('hiveCreateMetastoreDatabase', api_version=4)
1776
1777 - def create_sentry_database(self):
1778 """ 1779 Create the Sentry Server Database. Only works with embedded postgresql 1780 database. This command should usually be followed by a call to 1781 create_sentry_database_tables. 1782 1783 @return: Reference to the submitted command. 1784 @since: API v7 1785 """ 1786 return self._cmd('sentryCreateDatabase', api_version=7)
1787
1789 """ 1790 Creates the Sentry Server database tables in the configured database. 1791 Will do nothing if tables already exist. Will not perform an upgrade. 1792 1793 @return: Reference to the submitted command. 1794 @since: API v7 1795 """ 1796 return self._cmd('sentryCreateDatabaseTables', api_version=7)
1797
1799 """ 1800 Upgrades the Sentry Server database tables in the configured database. 1801 1802 @return: Reference to the submitted command. 1803 @since: API v8 1804 """ 1805 return self._cmd('sentryUpgradeDatabaseTables', api_version=8)
1806
1807 - def update_metastore_namenodes(self):
1808 """ 1809 Update Hive Metastore to point to a NameNode's Nameservice name instead of 1810 hostname. Only available when all Hive Metastore Servers are stopped and 1811 HDFS has High Availability. 1812 1813 Back up the Hive Metastore Database before running this command. 1814 1815 @return: Reference to the submitted command. 1816 @since: API v4 1817 """ 1818 return self._cmd('hiveUpdateMetastoreNamenodes', api_version=4)
1819
1821 """ 1822 Import MapReduce configuration into Yarn, overwriting Yarn configuration. 1823 1824 You will lose existing Yarn configuration. Read all MapReduce 1825 configuration, role assignments, and role configuration groups and update 1826 Yarn with corresponding values. MR1 configuration will be converted into 1827 the equivalent MR2 configuration. 1828 1829 Before running this command, Yarn must be stopped and MapReduce must exist 1830 with valid configuration. 1831 1832 @return: Reference to the submitted command. 1833 @since: API v6 1834 """ 1835 return self._cmd('importMrConfigsIntoYarn', api_version=6)
1836
1837 - def switch_to_mr2(self):
1838 """ 1839 Change the cluster to use MR2 instead of MR1. Services will be restarted. 1840 1841 Will perform the following steps: 1842 * Update all services that depend on MapReduce to instead depend on Yarn. 1843 * Stop MapReduce 1844 * Start Yarn (includes MR2) 1845 * Deploy Yarn (MR2) Client Configuration 1846 1847 Available since API v6. 1848 1849 @return: Reference to the submitted command. 1850 @since: API v6 1851 """ 1852 return self._cmd('switchToMr2', api_version=6)
1853
1854 - def finalize_rolling_upgrade(self):
1855 """ 1856 Finalizes the rolling upgrade for HDFS by updating the NameNode 1857 metadata permanently to the next version. Should be done after 1858 doing a rolling upgrade to a CDH version >= 5.2.0. 1859 1860 @return: Reference to the submitted command. 1861 @since: API v8 1862 """ 1863 return self._cmd('hdfsFinalizeRollingUpgrade', api_version=8)
1864
1865 - def role_command_by_name(self, command_name, *role_names):
1866 """ 1867 Executes a role command by name on the specified 1868 roles 1869 1870 @param command_name: The name of the command. 1871 @param role_names: The role names to execute this command on. 1872 @return: Reference to the submitted command. 1873 @since: API v6 1874 """ 1875 return self._role_cmd(command_name, role_names, api_version=6)
1876
1877 - def service_command_by_name(self, command_name):
1878 """ 1879 Executes a command on the service specified 1880 by name. 1881 1882 @param command_name: The name of the command. 1883 @return: Reference to the submitted command. 1884 @since: API v6 1885 """ 1886 return self._cmd(command_name, api_version=6)
1887
1888 - def list_commands_by_name(self):
1889 """ 1890 Lists all the commands that can be executed by name 1891 on the provided service. 1892 1893 @return: A list of command metadata objects 1894 @since: API v6 1895 """ 1896 return self._get("commandsByName", ApiCommandMetadata, True, 1897 api_version=6)
1898
1900 """ 1901 Creates the HDFS directory where YARN container usage metrics are 1902 stored by NodeManagers for CM to read and aggregate into app usage metrics. 1903 1904 @return: Reference to submitted command. 1905 @since: API v13 1906 """ 1907 return self._cmd('yarnCreateCmContainerUsageInputDirCommand', api_version=13)
1908
1909 -class ApiServiceSetupInfo(ApiService):
1910 _ATTRIBUTES = { 1911 'name' : None, 1912 'type' : None, 1913 'config' : Attr(ApiConfig), 1914 'roles' : Attr(roles.ApiRole), 1915 } 1916
1917 - def __init__(self, name=None, type=None, 1918 config=None, roles=None):
1919 # The BaseApiObject expects a resource_root, which we don't care about 1920 resource_root = None 1921 # Unfortunately, the json key is called "type". So our input arg 1922 # needs to be called "type" as well, despite it being a python keyword. 1923 BaseApiObject.init(self, None, locals())
1924
1925 - def set_config(self, config):
1926 """ 1927 Set the service configuration. 1928 1929 @param config: A dictionary of config key/value 1930 """ 1931 if self.config is None: 1932 self.config = { } 1933 self.config.update(config_to_api_list(config))
1934
1935 - def add_role_type_info(self, role_type, config):
1936 """ 1937 Add a role type setup info. 1938 1939 @param role_type: Role type 1940 @param config: A dictionary of role type configuration 1941 """ 1942 rt_config = config_to_api_list(config) 1943 rt_config['roleType'] = role_type 1944 1945 if self.config is None: 1946 self.config = { } 1947 if not self.config.has_key(ROLETYPES_CFG_KEY): 1948 self.config[ROLETYPES_CFG_KEY] = [ ] 1949 self.config[ROLETYPES_CFG_KEY].append(rt_config)
1950
1951 - def add_role_info(self, role_name, role_type, host_id, config=None):
1952 """ 1953 Add a role info. The role will be created along with the service setup. 1954 1955 @param role_name: Role name 1956 @param role_type: Role type 1957 @param host_id: The host where the role should run 1958 @param config: (Optional) A dictionary of role config values 1959 """ 1960 if self.roles is None: 1961 self.roles = [ ] 1962 api_config_list = config is not None and config_to_api_list(config) or None 1963 self.roles.append({ 1964 'name' : role_name, 1965 'type' : role_type, 1966 'hostRef' : { 'hostId' : host_id }, 1967 'config' : api_config_list })
1968
1969 - def first_run(self):
1970 """ 1971 Prepare and start this service. 1972 Perform all the steps needed to prepare and start this service. 1973 1974 @return: Reference to the submitted command. 1975 @since: API v7 1976 """ 1977 return self._cmd('firstRun', None, api_version=7)
1978