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 load_balancer_hostname=None, load_balancer_port=None, load_balancer_ssl_port=None):
1169 """ 1170 Enable high availability for Oozie. 1171 1172 @param new_oozie_server_host_ids: List of IDs of the hosts on which new Oozie Servers 1173 will be added. 1174 @param new_oozie_server_role_names: List of names of the new Oozie Servers. This is an 1175 optional argument, but if provided, it should 1176 match the length of host IDs provided. 1177 @param zk_service_name: Name of the ZooKeeper service that will be used for Oozie HA. 1178 This is an optional parameter if the Oozie to ZooKeeper 1179 dependency is already set. 1180 @param load_balancer_host_port: DEPRECATED Address and port of the load balancer used for Oozie HA. 1181 This is an optional parameter if this config is already set. 1182 @param load_balancer_hostname: (since v19) Address and port of the load balancer used for Oozie HA. 1183 This is an optional parameter if this config is already set. 1184 @param load_balancer_port: (since v19) HTTP port of the load balancer used for Oozie HA. 1185 This is an optional parameter if this config is already set. 1186 @param load_balancer_ssl_port: (since v19) HTTPS port of the load balancer used for Oozie HA. 1187 This is an optional parameter if this config is already set. 1188 @return: Reference to the submitted command. 1189 @since: API v6 1190 """ 1191 if load_balancer_hostname: 1192 args = dict( 1193 newOozieServerHostIds = new_oozie_server_host_ids, 1194 newOozieServerRoleNames = new_oozie_server_role_names, 1195 zkServiceName = zk_service_name, 1196 loadBalancerHostname = load_balancer_hostname, 1197 loadBalancerPort = load_balancer_port, 1198 loadBalancerSslPort = load_balancer_ssl_port 1199 ) 1200 apiVersion = 19 1201 else: 1202 args = dict( 1203 newOozieServerHostIds = new_oozie_server_host_ids, 1204 newOozieServerRoleNames = new_oozie_server_role_names, 1205 zkServiceName = zk_service_name, 1206 loadBalancerHostPort = load_balancer_host_port, 1207 ) 1208 apiVersion = 6 1209 return self._cmd('oozieEnableHa', data=args, api_version=apiVersion)
1210
1211 - def disable_oozie_ha(self, active_name):
1212 """ 1213 Disable high availability for Oozie 1214 1215 @param active_name: Name of the Oozie Server that will be active after 1216 High Availability is disabled. 1217 @return: Reference to the submitted command. 1218 @since: API v6 1219 """ 1220 args = dict( 1221 activeName = active_name 1222 ) 1223 return self._cmd('oozieDisableHa', data=args, api_version=6)
1224
1225 - def enable_sentry_ha(self, new_sentry_host_id, new_sentry_role_name=None, 1226 zk_service_name=None):
1227 """ 1228 Enable high availability for Sentry. 1229 1230 @param new_sentry_server_host_id: ID of the host on which new Sentry Server will be added 1231 @param new_sentry_server_rolename: Name of the new Sentry Server. This is an optional argument. 1232 A default name will be generated if not specified. 1233 @param zk_service_name: Name of the ZooKeeper service that will be used for Oozie HA. 1234 This is an optional parameter if the Oozie to ZooKeeper 1235 dependency is already set. 1236 @return: Reference to the submitted command. 1237 @since: API v18 1238 """ 1239 args = dict( 1240 newSentryHostId = new_sentry_host_id, 1241 newSentryRoleName = new_sentry_role_name, 1242 zkServiceName = zk_service_name 1243 ) 1244 return self._cmd('enableSentryHa', data=args, api_version=18)
1245
1246 - def disable_sentry_ha(self, active_name):
1247 """ 1248 Disable high availability for Sentry 1249 1250 @param active_name: Name of the Sentry Server that will be active after 1251 high availability is disabled. 1252 @return: Reference to the submitted command. 1253 @since: API v18 1254 """ 1255 args = dict( 1256 activeName = active_name 1257 ) 1258 return self._cmd('disableSentryHa', data=args, api_version=18)
1259
1260 - def failover_hdfs(self, active_name, standby_name, force=False):
1261 """ 1262 Initiate a failover of an HDFS NameNode HA pair. 1263 1264 This will make the given stand-by NameNode active, and vice-versa. 1265 1266 @param active_name: name of currently active NameNode. 1267 @param standby_name: name of NameNode currently in stand-by. 1268 @param force: whether to force failover. 1269 @return: Reference to the submitted command. 1270 """ 1271 params = { "force" : "true" and force or "false" } 1272 args = { ApiList.LIST_KEY : [ active_name, standby_name ] } 1273 return self._cmd('hdfsFailover', data=[ active_name, standby_name ], 1274 params = { "force" : "true" and force or "false" })
1275
1276 - def format_hdfs(self, *namenodes):
1277 """ 1278 Format NameNode instances of an HDFS service. 1279 1280 @param namenodes: Name of NameNode instances to format. 1281 @return: List of submitted commands. 1282 """ 1283 return self._role_cmd('hdfsFormat', namenodes)
1284
1285 - def init_hdfs_auto_failover(self, *controllers):
1286 """ 1287 Initialize HDFS failover controller metadata. 1288 1289 Only one controller per nameservice needs to be initialized. 1290 1291 @param controllers: Name of failover controller instances to initialize. 1292 @return: List of submitted commands. 1293 """ 1294 return self._role_cmd('hdfsInitializeAutoFailover', controllers)
1295
1296 - def init_hdfs_shared_dir(self, *namenodes):
1297 """ 1298 Initialize a NameNode's shared edits directory. 1299 1300 @param namenodes: Name of NameNode instances. 1301 @return: List of submitted commands. 1302 """ 1303 return self._role_cmd('hdfsInitializeSharedDir', namenodes)
1304
1305 - def roll_edits_hdfs(self, nameservice=None):
1306 """ 1307 Roll the edits of an HDFS NameNode or Nameservice. 1308 1309 @param nameservice: Nameservice whose edits should be rolled. 1310 Required only with a federated HDFS. 1311 @return: Reference to the submitted command. 1312 @since: API v3 1313 """ 1314 args = dict() 1315 if nameservice: 1316 args['nameservice'] = nameservice 1317 1318 return self._cmd('hdfsRollEdits', data=args)
1319
1320 - def upgrade_hdfs_metadata(self):
1321 """ 1322 Upgrade HDFS Metadata as part of a major version upgrade. 1323 1324 @return: Reference to the submitted command. 1325 @since: API v6 1326 """ 1327 return self._cmd('hdfsUpgradeMetadata', api_version=6)
1328
1329 - def upgrade_hbase(self):
1330 """ 1331 Upgrade HBase data in HDFS and ZooKeeper as part of upgrade from CDH4 to CDH5. 1332 1333 @return: Reference to the submitted command. 1334 @since: API v6 1335 """ 1336 return self._cmd('hbaseUpgrade', api_version=6)
1337
1338 - def create_sqoop_user_dir(self):
1339 """ 1340 Creates the user directory of a Sqoop service in HDFS. 1341 1342 @return: Reference to the submitted command. 1343 @since: API v4 1344 """ 1345 return self._cmd('createSqoopUserDir', api_version=4)
1346
1348 """ 1349 Creates the Sqoop2 Server database tables in the configured database. 1350 Will do nothing if tables already exist. Will not perform an upgrade. 1351 1352 @return: Reference to the submitted command. 1353 @since: API v10 1354 """ 1355 return self._cmd('sqoopCreateDatabaseTables', api_version=10)
1356
1357 - def upgrade_sqoop_db(self):
1358 """ 1359 Upgrade Sqoop Database schema as part of a major version upgrade. 1360 1361 @return: Reference to the submitted command. 1362 @since: API v6 1363 """ 1364 return self._cmd('sqoopUpgradeDb', api_version=6)
1365
1366 - def upgrade_hive_metastore(self):
1367 """ 1368 Upgrade Hive Metastore as part of a major version upgrade. 1369 1370 @return: Reference to the submitted command. 1371 @since: API v6 1372 """ 1373 return self._cmd('hiveUpgradeMetastore', api_version=6)
1374
1375 - def cleanup_zookeeper(self, *servers):
1376 """ 1377 Cleanup a ZooKeeper service or roles. 1378 1379 If no server role names are provided, the command applies to the whole 1380 service, and cleans up all the server roles that are currently running. 1381 1382 @param servers: ZK server role names (optional). 1383 @return: Command reference (for service command) or list of command 1384 references (for role commands). 1385 """ 1386 if servers: 1387 return self._role_cmd('zooKeeperCleanup', servers) 1388 else: 1389 return self._cmd('zooKeeperCleanup')
1390
1391 - def init_zookeeper(self, *servers):
1392 """ 1393 Initialize a ZooKeeper service or roles. 1394 1395 If no server role names are provided, the command applies to the whole 1396 service, and initializes all the configured server roles. 1397 1398 @param servers: ZK server role names (optional). 1399 @return: Command reference (for service command) or list of command 1400 references (for role commands). 1401 """ 1402 if servers: 1403 return self._role_cmd('zooKeeperInit', servers) 1404 else: 1405 return self._cmd('zooKeeperInit')
1406
1407 - def sync_hue_db(self, *servers):
1408 """ 1409 Synchronize the Hue server's database. 1410 1411 @param servers: Name of Hue Server roles to synchronize. Not required starting with API v10. 1412 @return: List of submitted commands. 1413 """ 1414 1415 actual_version = self._get_resource_root().version 1416 if actual_version < 10: 1417 return self._role_cmd('hueSyncDb', servers) 1418 1419 return self._cmd('hueSyncDb', api_version=10)
1420 1421
1422 - def dump_hue_db(self):
1423 """ 1424 Dump the Hue server's database; it can be loaded later. 1425 1426 @return: List of submitted commands. 1427 """ 1428 return self._cmd('hueDumpDb', api_version=10)
1429
1430 - def load_hue_db(self):
1431 """ 1432 Load data into Hue server's database from a previous data dump. 1433 1434 @return: List of submitted commands. 1435 """ 1436 return self._cmd('hueLoadDb', api_version=10)
1437
1438 - def lsof(self, *rolenames):
1439 """ 1440 Run the lsof diagnostic command. This command runs the lsof utility to list 1441 a role's open files. 1442 1443 @param rolenames: Name of the role instances 1444 @return: List of submitted commands. 1445 @since: API v8 1446 """ 1447 return self._role_cmd('lsof', rolenames)
1448
1449 - def jstack(self, *rolenames):
1450 """ 1451 Run the jstack diagnostic command. The command runs the jstack utility to 1452 capture a role's java thread stacks. 1453 1454 @param rolenames: Name of the role instances 1455 @return: List of submitted commands. 1456 @since: API v8 1457 """ 1458 return self._role_cmd('jstack', rolenames)
1459
1460 - def jmap_histo(self, *rolenames):
1461 """ 1462 Run the jmapHisto diagnostic command. The command runs the jmap utility to 1463 capture a histogram of the objects on the role's java heap. 1464 1465 @param rolenames: Name of the role instances 1466 @return: List of submitted commands. 1467 @since: API v8 1468 """ 1469 return self._role_cmd('jmapHisto', rolenames)
1470
1471 - def jmap_dump(self, *rolenames):
1472 """ 1473 Run the jmapDump diagnostic command. The command runs the jmap utility to 1474 capture a dump of the role's java heap. 1475 1476 @param rolenames: Name of the role instances 1477 @return: List of submitted commands. 1478 @since: API v8 1479 """ 1480 return self._role_cmd('jmapDump', rolenames)
1481
1482 - def enter_maintenance_mode(self):
1483 """ 1484 Put the service in maintenance mode. 1485 1486 @return: Reference to the completed command. 1487 @since: API v2 1488 """ 1489 cmd = self._cmd('enterMaintenanceMode') 1490 if cmd.success: 1491 self._update(_get_service(self._get_resource_root(), self._path())) 1492 return cmd
1493
1494 - def exit_maintenance_mode(self):
1495 """ 1496 Take the service out of maintenance mode. 1497 1498 @return: Reference to the completed command. 1499 @since: API v2 1500 """ 1501 cmd = self._cmd('exitMaintenanceMode') 1502 if cmd.success: 1503 self._update(_get_service(self._get_resource_root(), self._path())) 1504 return cmd
1505
1506 - def rolling_restart(self, slave_batch_size=None, 1507 slave_fail_count_threshold=None, 1508 sleep_seconds=None, 1509 stale_configs_only=None, 1510 unupgraded_only=None, 1511 restart_role_types=None, 1512 restart_role_names=None):
1513 """ 1514 Rolling restart the roles of a service. The sequence is: 1515 1. Restart all the non-slave roles 1516 2. If slaves are present restart them in batches of size specified 1517 3. Perform any post-command needed after rolling restart 1518 1519 @param slave_batch_size: Number of slave roles to restart at a time 1520 Must be greater than 0. Default is 1. 1521 For HDFS, this number should be less than the replication factor (default 3) 1522 to ensure data availability during rolling restart. 1523 @param slave_fail_count_threshold: The threshold for number of slave batches that 1524 are allowed to fail to restart before the entire command is considered failed. 1525 Must be >= 0. Default is 0. 1526 @param sleep_seconds: Number of seconds to sleep between restarts of slave role batches. 1527 Must be >=0. Default is 0. 1528 @param stale_configs_only: Restart roles with stale configs only. Default is false. 1529 @param unupgraded_only: Restart roles that haven't been upgraded yet. Default is false. 1530 @param restart_role_types: Role types to restart. If not specified, all startable roles are restarted. 1531 @param restart_role_names: List of specific roles to restart. 1532 If none are specified, then all roles of specified role types are restarted. 1533 @return: Reference to the submitted command. 1534 @since: API v3 1535 """ 1536 args = dict() 1537 if slave_batch_size: 1538 args['slaveBatchSize'] = slave_batch_size 1539 if slave_fail_count_threshold: 1540 args['slaveFailCountThreshold'] = slave_fail_count_threshold 1541 if sleep_seconds: 1542 args['sleepSeconds'] = sleep_seconds 1543 if stale_configs_only: 1544 args['staleConfigsOnly'] = stale_configs_only 1545 if unupgraded_only: 1546 args['unUpgradedOnly'] = unupgraded_only 1547 if restart_role_types: 1548 args['restartRoleTypes'] = restart_role_types 1549 if restart_role_names: 1550 args['restartRoleNames'] = restart_role_names 1551 1552 return self._cmd('rollingRestart', data=args)
1553
1554 - def create_replication_schedule(self, 1555 start_time, end_time, interval_unit, interval, paused, arguments, 1556 alert_on_start=False, alert_on_success=False, alert_on_fail=False, 1557 alert_on_abort=False, name=None, description=None):
1558 """ 1559 Create a new replication schedule for this service. 1560 1561 The replication argument type varies per service type. The following types 1562 are recognized: 1563 - HDFS: ApiHdfsReplicationArguments 1564 - Hive: ApiHiveReplicationArguments 1565 1566 @type start_time: datetime.datetime 1567 @param start_time: The time at which the schedule becomes active and first executes. 1568 @type end_time: datetime.datetime 1569 @param end_time: The time at which the schedule will expire. 1570 @type interval_unit: str 1571 @param interval_unit: The unit of time the `interval` represents. Ex. MINUTE, HOUR, 1572 DAY. See the server documentation for a full list of values. 1573 @type interval: int 1574 @param interval: The number of time units to wait until triggering the next replication. 1575 @type paused: bool 1576 @param paused: Should the schedule be paused? Useful for on-demand replication. 1577 @param arguments: service type-specific arguments for the replication job. 1578 @param alert_on_start: whether to generate alerts when the job is started. 1579 @param alert_on_success: whether to generate alerts when the job succeeds. 1580 @param alert_on_fail: whether to generate alerts when the job fails. 1581 @param alert_on_abort: whether to generate alerts when the job is aborted. 1582 @param name: Name of the replication schedule 1583 @param description: Description of the replication schedule 1584 @return: The newly created schedule. 1585 @since: API v3 1586 """ 1587 schedule = ApiReplicationSchedule(self._get_resource_root(), 1588 startTime=start_time, endTime=end_time, intervalUnit=interval_unit, interval=interval, 1589 paused=paused, alertOnStart=alert_on_start, alertOnSuccess=alert_on_success, 1590 alertOnFail=alert_on_fail, alertOnAbort=alert_on_abort, displayName=name, description=description) 1591 1592 if self.type == 'HDFS': 1593 if isinstance(arguments, ApiHdfsCloudReplicationArguments): 1594 schedule.hdfsCloudArguments = arguments 1595 elif isinstance(arguments, ApiHdfsReplicationArguments): 1596 schedule.hdfsArguments = arguments 1597 else: 1598 raise TypeError, 'Unexpected type for HDFS replication argument.' 1599 elif self.type == 'HIVE': 1600 if not isinstance(arguments, ApiHiveReplicationArguments): 1601 raise TypeError, 'Unexpected type for Hive replication argument.' 1602 schedule.hiveArguments = arguments 1603 else: 1604 raise TypeError, 'Replication is not supported for service type ' + self.type 1605 1606 return self._post("replications", ApiReplicationSchedule, True, [schedule], 1607 api_version=3)[0]
1608
1609 - def get_replication_schedules(self):
1610 """ 1611 Retrieve a list of replication schedules. 1612 1613 @return: A list of replication schedules. 1614 @since: API v3 1615 """ 1616 return self._get("replications", ApiReplicationSchedule, True, 1617 api_version=3)
1618
1619 - def get_replication_schedule(self, schedule_id):
1620 """ 1621 Retrieve a single replication schedule. 1622 1623 @param schedule_id: The id of the schedule to retrieve. 1624 @return: The requested schedule. 1625 @since: API v3 1626 """ 1627 return self._get("replications/%d" % schedule_id, ApiReplicationSchedule, 1628 api_version=3)
1629
1630 - def delete_replication_schedule(self, schedule_id):
1631 """ 1632 Delete a replication schedule. 1633 1634 @param schedule_id: The id of the schedule to delete. 1635 @return: The deleted replication schedule. 1636 @since: API v3 1637 """ 1638 return self._delete("replications/%s" % schedule_id, ApiReplicationSchedule, 1639 api_version=3)
1640
1641 - def update_replication_schedule(self, schedule_id, schedule):
1642 """ 1643 Update a replication schedule. 1644 1645 @param schedule_id: The id of the schedule to update. 1646 @param schedule: The modified schedule. 1647 @return: The updated replication schedule. 1648 @since: API v3 1649 """ 1650 return self._put("replications/%s" % schedule_id, ApiReplicationSchedule, 1651 data=schedule, api_version=3)
1652
1653 - def get_replication_command_history(self, schedule_id, limit=20, offset=0, 1654 view=None):
1655 """ 1656 Retrieve a list of commands for a replication schedule. 1657 1658 @param schedule_id: The id of the replication schedule. 1659 @param limit: Maximum number of commands to retrieve. 1660 @param offset: Index of first command to retrieve. 1661 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1662 @return: List of commands executed for a replication schedule. 1663 @since: API v4 1664 """ 1665 params = { 1666 'limit': limit, 1667 'offset': offset, 1668 } 1669 if view: 1670 params['view'] = view 1671 1672 return self._get("replications/%s/history" % schedule_id, 1673 ApiReplicationCommand, True, params=params, api_version=4)
1674
1675 - def trigger_replication_schedule(self, schedule_id, dry_run=False):
1676 """ 1677 Trigger replication immediately. Start and end dates on the schedule will be 1678 ignored. 1679 1680 @param schedule_id: The id of the schedule to trigger. 1681 @param dry_run: Whether to execute a dry run. 1682 @return: The command corresponding to the replication job. 1683 @since: API v3 1684 """ 1685 return self._post("replications/%s/run" % schedule_id, ApiCommand, 1686 params=dict(dryRun=dry_run), 1687 api_version=3)
1688
1689 - def collect_replication_diagnostic_data(self, schedule_id, diagnostic_args, view=None):
1690 """ 1691 Collect replication diagnostic data for the specified schedule id 1692 1693 @param schedule_id: The id of the schedule to collect diagnostic data. 1694 @param diagnostic_args: Arguments for collecting diagnostic data. 1695 @return: The command corresponding to the collect diagnostic data. 1696 @since: API v11 1697 """ 1698 return self._post("replications/%s/collectDiagnosticData" % schedule_id, ApiCommand, 1699 data=diagnostic_args, params=view and dict(view=view) or None, 1700 api_version=11)
1701
1702 - def create_snapshot_policy(self, policy):
1703 """ 1704 Create a new snapshot policy for this service. 1705 @param policy: The snapshot policy to create 1706 @return: The newly created policy. 1707 @since: API v6 1708 """ 1709 return self._post("snapshots/policies", ApiSnapshotPolicy, True, [policy], 1710 api_version=6)[0]
1711
1712 - def get_snapshot_policies(self, view=None):
1713 """ 1714 Retrieve a list of snapshot policies. 1715 1716 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1717 @return: A list of snapshot policies. 1718 @since: API v6 1719 """ 1720 return self._get("snapshots/policies", ApiSnapshotPolicy, True, 1721 params=view and dict(view=view) or None, api_version=6)
1722
1723 - def get_snapshot_policy(self, name, view=None):
1724 """ 1725 Retrieve a single snapshot policy. 1726 1727 @param name: The name of the snapshot policy to retrieve. 1728 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1729 @return: The requested snapshot policy. 1730 @since: API v6 1731 """ 1732 return self._get("snapshots/policies/%s" % name, ApiSnapshotPolicy, 1733 params=view and dict(view=view) or None, api_version=6)
1734
1735 - def delete_snapshot_policy(self, name):
1736 """ 1737 Delete a snapshot policy. 1738 1739 @param name: The name of the snapshot policy to delete. 1740 @return: The deleted snapshot policy. 1741 @since: API v6 1742 """ 1743 return self._delete("snapshots/policies/%s" % name, ApiSnapshotPolicy, api_version=6)
1744
1745 - def update_snapshot_policy(self, name, policy):
1746 """ 1747 Update a snapshot policy. 1748 1749 @param name: The name of the snapshot policy to update. 1750 @param policy: The modified snapshot policy. 1751 @return: The updated snapshot policy. 1752 @since: API v6 1753 """ 1754 return self._put("snapshots/policies/%s" % name, ApiSnapshotPolicy, data=policy, 1755 api_version=6)
1756
1757 - def get_snapshot_command_history(self, name, limit=20, offset=0, view=None):
1758 """ 1759 Retrieve a list of commands triggered by a snapshot policy. 1760 1761 @param name: The name of the snapshot policy. 1762 @param limit: Maximum number of commands to retrieve. 1763 @param offset: Index of first command to retrieve. 1764 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1765 @return: List of commands triggered by a snapshot policy. 1766 @since: API v6 1767 """ 1768 params = { 1769 'limit': limit, 1770 'offset': offset, 1771 } 1772 if view: 1773 params['view'] = view 1774 1775 return self._get("snapshots/policies/%s/history" % name, ApiSnapshotCommand, True, 1776 params=params, api_version=6)
1777 1778
1779 - def install_oozie_sharelib(self):
1780 """ 1781 Installs the Oozie ShareLib. Oozie must be stopped before running this 1782 command. 1783 1784 @return: Reference to the submitted command. 1785 @since: API v3 1786 """ 1787 return self._cmd('installOozieShareLib', api_version=3)
1788
1790 """ 1791 Create the Oozie Server Database. Only works with embedded postgresql 1792 database. This command should usually be followed by a call to 1793 create_oozie_db. 1794 1795 @return: Reference to the submitted command. 1796 @since: API v10 1797 """ 1798 return self._cmd('oozieCreateEmbeddedDatabase', api_version=10)
1799
1800 - def create_oozie_db(self):
1801 """ 1802 Creates the Oozie Database Schema in the configured database. 1803 This command does not create database. This command creates only tables 1804 required by Oozie. To create database, please refer to create_oozie_embedded_database. 1805 1806 @return: Reference to the submitted command. 1807 @since: API v2 1808 """ 1809 return self._cmd('createOozieDb', api_version=2)
1810
1811 - def upgrade_oozie_db(self):
1812 """ 1813 Upgrade Oozie Database schema as part of a major version upgrade. 1814 1815 @return: Reference to the submitted command. 1816 @since: API v6 1817 """ 1818 return self._cmd('oozieUpgradeDb', api_version=6)
1819
1820 - def init_solr(self):
1821 """ 1822 Initializes the Solr service in Zookeeper. 1823 1824 @return: Reference to the submitted command. 1825 @since: API v4 1826 """ 1827 return self._cmd('initSolr', api_version=4)
1828
1829 - def create_solr_hdfs_home_dir(self):
1830 """ 1831 Creates the home directory of a Solr service in HDFS. 1832 1833 @return: Reference to the submitted command. 1834 @since: API v4 1835 """ 1836 return self._cmd('createSolrHdfsHomeDir', api_version=4)
1837
1839 """ 1840 Creates the Hive metastore tables in the configured database. 1841 Will do nothing if tables already exist. Will not perform an upgrade. 1842 1843 @return: Reference to the submitted command. 1844 @since: API v3 1845 """ 1846 return self._cmd('hiveCreateMetastoreDatabaseTables', api_version=3)
1847
1848 - def create_hive_warehouse(self):
1849 """ 1850 Creates the Hive warehouse directory in HDFS. 1851 1852 @return: Reference to the submitted command. 1853 @since: API v3 1854 """ 1855 return self._cmd('hiveCreateHiveWarehouse')
1856
1857 - def create_hive_userdir(self):
1858 """ 1859 Creates the Hive user directory in HDFS. 1860 1861 @return: Reference to the submitted command. 1862 @since: API v4 1863 """ 1864 return self._cmd('hiveCreateHiveUserDir')
1865
1867 """ 1868 Create the Hive Metastore Database. Only works with embedded postgresql 1869 database. This command should usually be followed by a call to 1870 create_hive_metastore_tables. 1871 1872 @return: Reference to the submitted command. 1873 @since: API v4 1874 """ 1875 return self._cmd('hiveCreateMetastoreDatabase', api_version=4)
1876
1877 - def create_sentry_database(self):
1878 """ 1879 Create the Sentry Server Database. Only works with embedded postgresql 1880 database. This command should usually be followed by a call to 1881 create_sentry_database_tables. 1882 1883 @return: Reference to the submitted command. 1884 @since: API v7 1885 """ 1886 return self._cmd('sentryCreateDatabase', api_version=7)
1887
1889 """ 1890 Creates the Sentry Server database tables in the configured database. 1891 Will do nothing if tables already exist. Will not perform an upgrade. 1892 1893 @return: Reference to the submitted command. 1894 @since: API v7 1895 """ 1896 return self._cmd('sentryCreateDatabaseTables', api_version=7)
1897
1899 """ 1900 Upgrades the Sentry Server database tables in the configured database. 1901 1902 @return: Reference to the submitted command. 1903 @since: API v8 1904 """ 1905 return self._cmd('sentryUpgradeDatabaseTables', api_version=8)
1906
1907 - def update_metastore_namenodes(self):
1908 """ 1909 Update Hive Metastore to point to a NameNode's Nameservice name instead of 1910 hostname. Only available when all Hive Metastore Servers are stopped and 1911 HDFS has High Availability. 1912 1913 Back up the Hive Metastore Database before running this command. 1914 1915 @return: Reference to the submitted command. 1916 @since: API v4 1917 """ 1918 return self._cmd('hiveUpdateMetastoreNamenodes', api_version=4)
1919
1921 """ 1922 Import MapReduce configuration into Yarn, overwriting Yarn configuration. 1923 1924 You will lose existing Yarn configuration. Read all MapReduce 1925 configuration, role assignments, and role configuration groups and update 1926 Yarn with corresponding values. MR1 configuration will be converted into 1927 the equivalent MR2 configuration. 1928 1929 Before running this command, Yarn must be stopped and MapReduce must exist 1930 with valid configuration. 1931 1932 @return: Reference to the submitted command. 1933 @since: API v6 1934 """ 1935 return self._cmd('importMrConfigsIntoYarn', api_version=6)
1936
1937 - def switch_to_mr2(self):
1938 """ 1939 Change the cluster to use MR2 instead of MR1. Services will be restarted. 1940 1941 Will perform the following steps: 1942 * Update all services that depend on MapReduce to instead depend on Yarn. 1943 * Stop MapReduce 1944 * Start Yarn (includes MR2) 1945 * Deploy Yarn (MR2) Client Configuration 1946 1947 Available since API v6. 1948 1949 @return: Reference to the submitted command. 1950 @since: API v6 1951 """ 1952 return self._cmd('switchToMr2', api_version=6)
1953
1954 - def finalize_rolling_upgrade(self):
1955 """ 1956 Finalizes the rolling upgrade for HDFS by updating the NameNode 1957 metadata permanently to the next version. Should be done after 1958 doing a rolling upgrade to a CDH version >= 5.2.0. 1959 1960 @return: Reference to the submitted command. 1961 @since: API v8 1962 """ 1963 return self._cmd('hdfsFinalizeRollingUpgrade', api_version=8)
1964
1965 - def role_command_by_name(self, command_name, *role_names):
1966 """ 1967 Executes a role command by name on the specified 1968 roles 1969 1970 @param command_name: The name of the command. 1971 @param role_names: The role names to execute this command on. 1972 @return: Reference to the submitted command. 1973 @since: API v6 1974 """ 1975 return self._role_cmd(command_name, role_names, api_version=6)
1976
1977 - def service_command_by_name(self, command_name):
1978 """ 1979 Executes a command on the service specified 1980 by name. 1981 1982 @param command_name: The name of the command. 1983 @return: Reference to the submitted command. 1984 @since: API v6 1985 """ 1986 return self._cmd(command_name, api_version=6)
1987
1988 - def list_commands_by_name(self):
1989 """ 1990 Lists all the commands that can be executed by name 1991 on the provided service. 1992 1993 @return: A list of command metadata objects 1994 @since: API v6 1995 """ 1996 return self._get("commandsByName", ApiCommandMetadata, True, 1997 api_version=6)
1998
2000 """ 2001 Creates the HDFS directory where YARN container usage metrics are 2002 stored by NodeManagers for CM to read and aggregate into app usage metrics. 2003 2004 @return: Reference to submitted command. 2005 @since: API v13 2006 """ 2007 return self._cmd('yarnCreateCmContainerUsageInputDirCommand', api_version=13)
2008
2010 """ 2011 Validates the Hive metastore database schema. 2012 2013 @return: Reference to the submitted command. 2014 @since: API v7 2015 """ 2016 return self._cmd('hiveValidateMetastoreSchema', api_version=17)
2017
2018 -class ApiServiceSetupInfo(ApiService):
2019 _ATTRIBUTES = { 2020 'name' : None, 2021 'type' : None, 2022 'config' : Attr(ApiConfig), 2023 'roles' : Attr(roles.ApiRole), 2024 } 2025
2026 - def __init__(self, name=None, type=None, 2027 config=None, roles=None):
2028 # The BaseApiObject expects a resource_root, which we don't care about 2029 resource_root = None 2030 # Unfortunately, the json key is called "type". So our input arg 2031 # needs to be called "type" as well, despite it being a python keyword. 2032 BaseApiObject.init(self, None, locals())
2033
2034 - def set_config(self, config):
2035 """ 2036 Set the service configuration. 2037 2038 @param config: A dictionary of config key/value 2039 """ 2040 if self.config is None: 2041 self.config = { } 2042 self.config.update(config_to_api_list(config))
2043
2044 - def add_role_type_info(self, role_type, config):
2045 """ 2046 Add a role type setup info. 2047 2048 @param role_type: Role type 2049 @param config: A dictionary of role type configuration 2050 """ 2051 rt_config = config_to_api_list(config) 2052 rt_config['roleType'] = role_type 2053 2054 if self.config is None: 2055 self.config = { } 2056 if not self.config.has_key(ROLETYPES_CFG_KEY): 2057 self.config[ROLETYPES_CFG_KEY] = [ ] 2058 self.config[ROLETYPES_CFG_KEY].append(rt_config)
2059
2060 - def add_role_info(self, role_name, role_type, host_id, config=None):
2061 """ 2062 Add a role info. The role will be created along with the service setup. 2063 2064 @param role_name: Role name 2065 @param role_type: Role type 2066 @param host_id: The host where the role should run 2067 @param config: (Optional) A dictionary of role config values 2068 """ 2069 if self.roles is None: 2070 self.roles = [ ] 2071 api_config_list = config is not None and config_to_api_list(config) or None 2072 self.roles.append({ 2073 'name' : role_name, 2074 'type' : role_type, 2075 'hostRef' : { 'hostId' : host_id }, 2076 'config' : api_config_list })
2077
2078 - def first_run(self):
2079 """ 2080 Prepare and start this service. 2081 Perform all the steps needed to prepare and start this service. 2082 2083 @return: Reference to the submitted command. 2084 @since: API v7 2085 """ 2086 return self._cmd('firstRun', None, api_version=7)
2087