1   
   2   
   3   
   4   
   5   
   6   
   7   
   8   
   9   
  10   
  11   
  12   
  13   
  14   
  15   
  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   
  58   
  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   
  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   
  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      'maintenanceMode'             : ROAttr(), 
  97      'maintenanceOwners'           : ROAttr(), 
  98    } 
  99   
 100 -  def __init__(self, resource_root, name=None, type=None): 
  102   
 104      return "<ApiService>: %s (cluster: %s)" % ( 
 105          self.name, self._get_cluster_name()) 
  106   
 108      if hasattr(self, 'clusterRef') and self.clusterRef: 
 109        return self.clusterRef.clusterName 
 110      return None 
  111   
 113      """ 
 114      Return the API path for this service. 
 115   
 116      This method assumes that lack of a cluster reference means that the 
 117      object refers to the Cloudera Management Services instance. 
 118      """ 
 119      if self._get_cluster_name(): 
 120        return SERVICE_PATH % (self._get_cluster_name(), self.name) 
 121      else: 
 122        return '/cm/service' 
  123   
 124 -  def _role_cmd(self, cmd, roles, api_version=1): 
  127   
 129      """ 
 130      Parse a json-decoded ApiServiceConfig dictionary into a 2-tuple. 
 131   
 132      @param json_dic: The json dictionary with the config data. 
 133      @param view: View to materialize. 
 134      @return: 2-tuple (service config dictionary, role type configurations) 
 135      """ 
 136      svc_config = json_to_config(json_dic, view == 'full') 
 137      rt_configs = { } 
 138      if json_dic.has_key(ROLETYPES_CFG_KEY): 
 139        for rt_config in json_dic[ROLETYPES_CFG_KEY]: 
 140          rt_configs[rt_config['roleType']] = \ 
 141              json_to_config(rt_config, view == 'full') 
 142   
 143      return (svc_config, rt_configs) 
  144   
 146      """ 
 147      Retrieve a list of running commands for this service. 
 148   
 149      @param view: View to materialize ('full' or 'summary') 
 150      @return: A list of running commands. 
 151      """ 
 152      return self._get("commands", ApiCommand, True, 
 153          params = view and dict(view=view) or None) 
  154   
 157   
 159      return self._get("activities", ApiActivity, True, 
 160          params=query_str and dict(query=query_str) or dict()) 
  161   
 164   
 165 -  def get_impala_queries(self, start_time, end_time, filter_str="", limit=100, 
 166       offset=0): 
  167      """ 
 168      Returns a list of queries that satisfy the filter 
 169   
 170      @type start_time: datetime.datetime. Note that the datetime must either be 
 171                        time zone aware or specified in the server time zone. See 
 172                        the python datetime documentation for more details about 
 173                        python's time zone handling. 
 174      @param start_time: Queries must have ended after this time 
 175      @type end_time: datetime.datetime. Note that the datetime must either be 
 176                      time zone aware or specified in the server time zone. See 
 177                      the python datetime documentation for more details about 
 178                      python's time zone handling. 
 179      @param end_time: Queries must have started before this time 
 180      @param filter_str: A filter to apply to the queries. For example: 
 181                         'user = root and queryDuration > 5s' 
 182      @param limit: The maximum number of results to return 
 183      @param offset: The offset into the return list 
 184      @since: API v4 
 185      """ 
 186      params = { 
 187        'from':   start_time.isoformat(), 
 188        'to':     end_time.isoformat(), 
 189        'filter': filter_str, 
 190        'limit':  limit, 
 191        'offset': offset, 
 192      } 
 193      return self._get("impalaQueries", ApiImpalaQueryResponse, 
 194          params=params, api_version=4) 
  195   
 197      """ 
 198      Cancel the query. 
 199   
 200      @param query_id: The query ID 
 201      @return: The warning message, if any. 
 202      @since: API v4 
 203      """ 
 204      return self._post("impalaQueries/%s/cancel" % query_id, 
 205          ApiImpalaCancelResponse, api_version=4) 
  206   
 208      """ 
 209      Get the query details 
 210   
 211      @param query_id: The query ID 
 212      @param format: The format of the response ('text' or 'thrift_encoded') 
 213      @return: The details text 
 214      @since: API v4 
 215      """ 
 216      return self._get("impalaQueries/" + query_id, ApiImpalaQueryDetailsResponse, 
 217          params=dict(format=format), api_version=4) 
  218   
 220      """ 
 221      Returns the list of all attributes that the Service Monitor can associate 
 222      with Impala queries. 
 223   
 224      Examples of attributes include the user who issued the query and the 
 225      number of HDFS bytes read by the query. 
 226   
 227      These attributes can be used to search for specific Impala queries through 
 228      the get_impala_queries API. For example the 'user' attribute could be used 
 229      in the search 'user = root'. If the attribute is numeric it can also be used 
 230      as a metric in a tsquery (ie, 'select hdfs_bytes_read from IMPALA_QUERIES'). 
 231   
 232      Note that this response is identical for all Impala services. 
 233   
 234      @return: A list of the Impala query attributes 
 235      @since API v6 
 236      """ 
 237      return self._get("impalaQueries/attributes", ApiImpalaQueryAttribute, 
 238          api_version=6) 
  239   
 241      """ 
 242      Create the Impala Catalog Database. Only works with embedded postgresql 
 243      database. This command should usually be followed by a call to 
 244      create_impala_catalog_database_tables. 
 245   
 246      @return: Reference to the submitted command. 
 247      @since: API v6 
 248      """ 
 249      return self._cmd('impalaCreateCatalogDatabase', api_version=6) 
  250   
 252      """ 
 253      Creates the Impala Catalog Database tables in the configured database. 
 254      Will do nothing if tables already exist. Will not perform an upgrade. 
 255   
 256      @return: Reference to the submitted command. 
 257      @since: API v6 
 258      """ 
 259      return self._cmd('impalaCreateCatalogDatabaseTables', api_version=6) 
  260   
 262      """ 
 263      Create the Impala user directory 
 264   
 265      @return: Reference to submitted command. 
 266      @since: API v6 
 267      """ 
 268      return self._cmd('impalaCreateUserDir', api_version=6) 
  269   
 272      """ 
 273      Returns a list of YARN applications that satisfy the filter 
 274      @type start_time: datetime.datetime. Note that the datetime must either be 
 275                        time zone aware or specified in the server time zone. See 
 276                        the python datetime documentation for more details about 
 277                        python's time zone handling. 
 278      @param start_time: Applications must have ended after this time 
 279      @type end_time: datetime.datetime. Note that the datetime must either be 
 280                      time zone aware or specified in the server time zone. See 
 281                      the python datetime documentation for more details about 
 282                      python's time zone handling. 
 283      @param filter_str: A filter to apply to the applications. For example: 
 284                         'user = root and applicationDuration > 5s' 
 285      @param limit: The maximum number of results to return 
 286      @param offset: The offset into the return list 
 287      @since: API v6 
 288      """ 
 289      params = { 
 290        'from':   start_time.isoformat(), 
 291        'to':     end_time.isoformat(), 
 292        'filter': filter_str, 
 293        'limit':  limit, 
 294        'offset': offset 
 295      } 
 296      return self._get("yarnApplications", ApiYarnApplicationResponse, 
 297          params=params, api_version=6) 
  298   
 300      """ 
 301      Kills the application. 
 302   
 303      @return: The warning message, if any. 
 304      @since: API v6 
 305      """ 
 306      return self._post("yarnApplications/%s/kill" % (application_id, ), 
 307          ApiYarnKillResponse, api_version=6) 
  308   
 310      """ 
 311      Returns the list of all attributes that the Service Monitor can associate 
 312      with YARN applications. 
 313   
 314      Examples of attributes include the user who ran the application and the 
 315      number of maps completed by the application. 
 316   
 317      These attributes can be used to search for specific YARN applications through 
 318      the get_yarn_applications API. For example the 'user' attribute could be used 
 319      in the search 'user = root'. If the attribute is numeric it can also be used 
 320      as a metric in a tsquery (ie, 'select maps_completed from YARN_APPLICATIONS'). 
 321   
 322      Note that this response is identical for all YARN services. 
 323   
 324      @return: A list of the YARN application attributes 
 325      @since API v6 
 326      """ 
 327      return self._get("yarnApplications/attributes", ApiYarnApplicationAttribute, 
 328          api_version=6) 
  329   
 331      """ 
 332      Create the Yarn job history directory. 
 333   
 334      @return: Reference to submitted command. 
 335      @since: API v6 
 336      """ 
 337      return self._cmd('yarnCreateJobHistoryDirCommand', api_version=6) 
  338   
 340      """ 
 341      Create the Yarn NodeManager remote application log directory. 
 342   
 343      @return: Reference to submitted command. 
 344      @since: API v6 
 345      """ 
 346      return self._cmd('yarnNodeManagerRemoteAppLogDirCommand', api_version=6) 
  347   
 349      """ 
 350      Retrieve the service's configuration. 
 351   
 352      Retrieves both the service configuration and role type configuration 
 353      for each of the service's supported role types. The role type 
 354      configurations are returned as a dictionary, whose keys are the 
 355      role type name, and values are the respective configuration dictionaries. 
 356   
 357      The 'summary' view contains strings as the dictionary values. The full 
 358      view contains ApiConfig instances as the values. 
 359   
 360      @param view: View to materialize ('full' or 'summary') 
 361      @return: 2-tuple (service config dictionary, role type configurations) 
 362      """ 
 363      path = self._path() + '/config' 
 364      resp = self._get_resource_root().get(path, 
 365          params = view and dict(view=view) or None) 
 366      return self._parse_svc_config(resp, view) 
  367   
 369      """ 
 370      Update the service's configuration. 
 371   
 372      @param svc_config: Dictionary with service configuration to update. 
 373      @param rt_configs: Dict of role type configurations to update. 
 374      @return: 2-tuple (service config dictionary, role type configurations) 
 375      """ 
 376      path = self._path() + '/config' 
 377   
 378      if svc_config: 
 379        data = config_to_api_list(svc_config) 
 380      else: 
 381        data = { } 
 382      if rt_configs: 
 383        rt_list = [ ] 
 384        for rt, cfg in rt_configs.iteritems(): 
 385          rt_data = config_to_api_list(cfg) 
 386          rt_data['roleType'] = rt 
 387          rt_list.append(rt_data) 
 388        data[ROLETYPES_CFG_KEY] = rt_list 
 389   
 390      resp = self._get_resource_root().put(path, data = json.dumps(data)) 
 391      return self._parse_svc_config(resp) 
  392   
 394      """ 
 395      Create a role. 
 396   
 397      @param role_name: Role name 
 398      @param role_type: Role type 
 399      @param host_id: ID of the host to assign the role to 
 400      @return: An ApiRole object 
 401      """ 
 402      return roles.create_role(self._get_resource_root(), self.name, role_type, 
 403          role_name, host_id, self._get_cluster_name()) 
  404   
 414   
 424   
 434   
 436      """ 
 437      Get all roles of a certain type in a service. 
 438   
 439      @param role_type: Role type 
 440      @param view: View to materialize ('full' or 'summary') 
 441      @return: A list of ApiRole objects. 
 442      """ 
 443      return roles.get_roles_by_type(self._get_resource_root(), self.name, 
 444          role_type, self._get_cluster_name(), view) 
  445   
 447      """ 
 448      Get a list of role types in a service. 
 449   
 450      @return: A list of role types (strings) 
 451      """ 
 452      resp = self._get_resource_root().get(self._path() + '/roleTypes') 
 453      return resp[ApiList.LIST_KEY] 
  454   
 464   
 475   
 477      """ 
 478      Create a role config group. 
 479   
 480      @param name: The name of the new group. 
 481      @param display_name: The display name of the new group. 
 482      @param role_type: The role type of the new group. 
 483      @return: New ApiRoleConfigGroup object. 
 484      @since: API v3 
 485      """ 
 486      return role_config_groups.create_role_config_group( 
 487          self._get_resource_root(), self.name, name, display_name, role_type, 
 488          self._get_cluster_name()) 
  489   
 502   
 513   
 514 -  def get_metrics(self, from_time=None, to_time=None, metrics=None, view=None): 
  515      """ 
 516      This endpoint is not supported as of v6. Use the timeseries API 
 517      instead. To get all metrics for a service with the timeseries API use 
 518      the query: 
 519   
 520      'select * where serviceName = $SERVICE_NAME'. 
 521   
 522      To get specific metrics for a service use a comma-separated list of 
 523      the metric names as follows: 
 524   
 525      'select $METRIC_NAME1, $METRIC_NAME2 where serviceName = $SERVICE_NAME'. 
 526   
 527      For more information see http://tiny.cloudera.com/tsquery_doc 
 528   
 529      Retrieve metric readings for the service. 
 530      @param from_time: A datetime; start of the period to query (optional). 
 531      @param to_time: A datetime; end of the period to query (default = now). 
 532      @param metrics: List of metrics to query (default = all). 
 533      @param view: View to materialize ('full' or 'summary') 
 534      @return: List of metrics and their readings. 
 535      """ 
 536      return self._get_resource_root().get_metrics(self._path() + '/metrics', 
 537          from_time, to_time, metrics, view) 
  538   
 540      """ 
 541      Start a service. 
 542   
 543      @return: Reference to the submitted command. 
 544      """ 
 545      return self._cmd('start') 
  546   
 548      """ 
 549      Stop a service. 
 550   
 551      @return: Reference to the submitted command. 
 552      """ 
 553      return self._cmd('stop') 
  554   
 556      """ 
 557      Restart a service. 
 558   
 559      @return: Reference to the submitted command. 
 560      """ 
 561      return self._cmd('restart') 
  562   
 564      """ 
 565      Start a list of roles. 
 566   
 567      @param role_names: names of the roles to start. 
 568      @return: List of submitted commands. 
 569      """ 
 570      return self._role_cmd('start', role_names) 
  571   
 573      """ 
 574      Stop a list of roles. 
 575   
 576      @param role_names: names of the roles to stop. 
 577      @return: List of submitted commands. 
 578      """ 
 579      return self._role_cmd('stop', role_names) 
  580   
 582      """ 
 583      Restart a list of roles. 
 584   
 585      @param role_names: names of the roles to restart. 
 586      @return: List of submitted commands. 
 587      """ 
 588      return self._role_cmd('restart', role_names) 
  589   
 591      """ 
 592      Bootstrap HDFS stand-by NameNodes. 
 593   
 594      Initialize their state by syncing it with the respective HA partner. 
 595   
 596      @param role_names: NameNodes to bootstrap. 
 597      @return: List of submitted commands. 
 598      """ 
 599      return self._role_cmd('hdfsBootstrapStandBy', role_names) 
  600   
 602      """ 
 603      DEPRECATED: use create_hive_warehouse on the Hive service. Deprecated since v3. 
 604   
 605      Create the Beeswax role's warehouse for a Hue service. 
 606   
 607      @return: Reference to the submitted command. 
 608      """ 
 609      return self._cmd('hueCreateHiveWarehouse') 
  610   
 612      """ 
 613      Create the root directory of an HBase service. 
 614   
 615      @return: Reference to the submitted command. 
 616      """ 
 617      return self._cmd('hbaseCreateRoot') 
  618   
 620      """ 
 621      Create the /tmp directory in HDFS with appropriate ownership and permissions. 
 622   
 623      @return: Reference to the submitted command 
 624      @since: API v2 
 625      """ 
 626      return self._cmd('hdfsCreateTmpDir') 
  627   
 629      """ 
 630      Execute the "refresh" command on a set of roles. 
 631   
 632      @param role_names: Names of the roles to refresh. 
 633      @return: Reference to the submitted command. 
 634      """ 
 635      return self._role_cmd('refresh', role_names) 
  636   
 638      """ 
 639      Decommission roles in a service. 
 640   
 641      @param role_names: Names of the roles to decommission. 
 642      @return: Reference to the submitted command. 
 643      """ 
 644      return self._cmd('decommission', data=role_names) 
  645   
 647      """ 
 648      Recommission roles in a service. 
 649   
 650      @param role_names: Names of the roles to recommission. 
 651      @return: Reference to the submitted command. 
 652      @since: API v2 
 653      """ 
 654      return self._cmd('recommission', data=role_names) 
  655   
 657      """ 
 658      Deploys client configuration to the hosts where roles are running. 
 659   
 660      @param role_names: Names of the roles to decommission. 
 661      @return: Reference to the submitted command. 
 662      """ 
 663      return self._cmd('deployClientConfig', data=role_names) 
  664   
 666      """ 
 667      Disable auto-failover for a highly available HDFS nameservice. 
 668      This command is no longer supported with API v6 onwards. Use disable_nn_ha instead. 
 669   
 670      @param nameservice: Affected nameservice. 
 671      @return: Reference to the submitted command. 
 672      """ 
 673      return self._cmd('hdfsDisableAutoFailover', data=nameservice) 
  674   
 675 -  def disable_hdfs_ha(self, active_name, secondary_name, 
 676        start_dependent_services=True, deploy_client_configs=True, 
 677                        disable_quorum_storage=False): 
  678      """ 
 679      Disable high availability for an HDFS NameNode. 
 680      This command is no longer supported with API v6 onwards. Use disable_nn_ha instead. 
 681   
 682      @param active_name: Name of the NameNode to keep. 
 683      @param secondary_name: Name of (existing) SecondaryNameNode to link to 
 684                             remaining NameNode. 
 685      @param start_dependent_services: whether to re-start dependent services. 
 686      @param deploy_client_configs: whether to re-deploy client configurations. 
 687      @param disable_quorum_storage: whether to disable Quorum-based Storage. Available since API v2. 
 688                                     Quorum-based Storage will be disabled for all 
 689                                     nameservices that have Quorum-based Storage 
 690                                     enabled. 
 691      @return: Reference to the submitted command. 
 692      """ 
 693      args = dict( 
 694        activeName = active_name, 
 695        secondaryName = secondary_name, 
 696        startDependentServices = start_dependent_services, 
 697        deployClientConfigs = deploy_client_configs, 
 698      ) 
 699   
 700      version = self._get_resource_root().version 
 701      if version < 2: 
 702        if disable_quorum_storage: 
 703          raise AttributeError("Quorum-based Storage requires at least API version 2 available in Cloudera Manager 4.1.") 
 704      else: 
 705        args['disableQuorumStorage'] = disable_quorum_storage 
 706   
 707      return self._cmd('hdfsDisableHa', data=args) 
  708   
 711      """ 
 712      Enable auto-failover for an HDFS nameservice. 
 713      This command is no longer supported with API v6 onwards. Use enable_nn_ha instead. 
 714   
 715      @param nameservice: Nameservice for which to enable auto-failover. 
 716      @param active_fc_name: Name of failover controller to create for active node. 
 717      @param standby_fc_name: Name of failover controller to create for stand-by node. 
 718      @param zk_service: ZooKeeper service to use. 
 719      @return: Reference to the submitted command. 
 720      """ 
 721      version = self._get_resource_root().version 
 722   
 723      args = dict( 
 724        nameservice = nameservice, 
 725        activeFCName = active_fc_name, 
 726        standByFCName = standby_fc_name, 
 727        zooKeeperService = dict( 
 728          clusterName = zk_service.clusterRef.clusterName, 
 729          serviceName = zk_service.name, 
 730          ), 
 731        ) 
 732      return self._cmd('hdfsEnableAutoFailover', data=args) 
  733   
 734 -  def enable_hdfs_ha(self, active_name, active_shared_path, standby_name, 
 735        standby_shared_path, nameservice, start_dependent_services=True, 
 736        deploy_client_configs=True, enable_quorum_storage=False): 
  737      """ 
 738      Enable high availability for an HDFS NameNode. 
 739      This command is no longer supported with API v6 onwards. Use enable_nn_ha instead. 
 740   
 741      @param active_name: name of active NameNode. 
 742      @param active_shared_path: shared edits path for active NameNode. 
 743                                 Ignored if Quorum-based Storage is being enabled. 
 744      @param standby_name: name of stand-by NameNode. 
 745      @param standby_shared_path: shared edits path for stand-by NameNode. 
 746                                  Ignored if Quourm Journal is being enabled. 
 747      @param nameservice: nameservice for the HA pair. 
 748      @param start_dependent_services: whether to re-start dependent services. 
 749      @param deploy_client_configs: whether to re-deploy client configurations. 
 750      @param enable_quorum_storage: whether to enable Quorum-based Storage. Available since API v2. 
 751                                    Quorum-based Storage will be enabled for all 
 752                                    nameservices except those configured with NFS High 
 753                                    Availability. 
 754      @return: Reference to the submitted command. 
 755      """ 
 756      version = self._get_resource_root().version 
 757   
 758      args = dict( 
 759        activeName = active_name, 
 760        standByName = standby_name, 
 761        nameservice = nameservice, 
 762        startDependentServices = start_dependent_services, 
 763        deployClientConfigs = deploy_client_configs, 
 764      ) 
 765   
 766      if enable_quorum_storage: 
 767        if version < 2: 
 768          raise AttributeError("Quorum-based Storage is not supported prior to Cloudera Manager 4.1.") 
 769        else: 
 770          args['enableQuorumStorage'] = enable_quorum_storage 
 771      else: 
 772        if active_shared_path is None or standby_shared_path is None: 
 773          raise AttributeError("Active and standby shared paths must be specified if not enabling Quorum-based Storage") 
 774        args['activeSharedEditsPath'] = active_shared_path 
 775        args['standBySharedEditsPath'] = standby_shared_path 
 776   
 777      return self._cmd('hdfsEnableHa', data=args) 
  778   
 779 -  def enable_nn_ha(self, active_name, standby_host_id, nameservice, jns, 
 780        standby_name_dir_list=None, qj_name=None, standby_name=None, 
 781        active_fc_name=None, standby_fc_name=None, zk_service_name=None, 
 782        force_init_znode=True, clear_existing_standby_name_dirs=True, clear_existing_jn_edits_dir=True): 
  783      """ 
 784      Enable High Availability (HA) with Auto-Failover for an HDFS NameNode. 
 785      @param active_name: Name of Active NameNode. 
 786      @param standby_host_id: ID of host where Standby NameNode will be created. 
 787      @param nameservice: Nameservice to be used while enabling HA. 
 788                          Optional if Active NameNode already has this config set. 
 789      @param jns: List of Journal Nodes to be created during the command. 
 790                  Each element of the list must be a dict containing the following keys: 
 791                    - B{jnHostId}: ID of the host where the new JournalNode will be created. 
 792                    - B{jnName}: Name of the JournalNode role (optional) 
 793                    - B{jnEditsDir}: Edits dir of the JournalNode. Can be omitted if the config 
 794                      is already set at RCG level. 
 795      @param standby_name_dir_list: List of directories for the new Standby NameNode. 
 796                                    If not provided then it will use same dirs as Active NameNode. 
 797      @param qj_name: Name of the journal located on each JournalNodes' filesystem. 
 798                      This can be optionally provided if the config hasn't been already set for the Active NameNode. 
 799                      If this isn't provided and Active NameNode doesn't also have the config, 
 800                      then nameservice is used by default. 
 801      @param standby_name: Name of the Standby NameNode role to be created (Optional). 
 802      @param active_fc_name: Name of the Active Failover Controller role to be created (Optional). 
 803      @param standby_fc_name: Name of the Standby Failover Controller role to be created (Optional). 
 804      @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 
 805                              If HDFS service already depends on a ZooKeeper service then that ZooKeeper 
 806                              service will be used for auto-failover and in that case this parameter 
 807                              can either be omitted or should be the same ZooKeeper service. 
 808      @param force_init_znode: Indicates if the ZNode should be force initialized if it is 
 809                               already present. Useful while re-enabling High Availability. (Default: TRUE) 
 810      @param clear_existing_standby_name_dirs: Indicates if the existing name directories for Standby NameNode 
 811                                               should be cleared during the workflow. 
 812                                               Useful while re-enabling High Availability. (Default: TRUE) 
 813      @param clear_existing_jn_edits_dir: Indicates if the existing edits directories for the JournalNodes 
 814                                          for the specified nameservice should be cleared during the workflow. 
 815                                          Useful while re-enabling High Availability. (Default: TRUE) 
 816      @return: Reference to the submitted command. 
 817      @since: API v6 
 818      """ 
 819      args = dict ( 
 820        activeNnName = active_name, 
 821        standbyNnName = standby_name, 
 822        standbyNnHostId = standby_host_id, 
 823        standbyNameDirList = standby_name_dir_list, 
 824        nameservice = nameservice, 
 825        qjName = qj_name, 
 826        activeFcName = active_fc_name, 
 827        standbyFcName = standby_fc_name, 
 828        zkServiceName = zk_service_name, 
 829        forceInitZNode = force_init_znode, 
 830        clearExistingStandbyNameDirs = clear_existing_standby_name_dirs, 
 831        clearExistingJnEditsDir = clear_existing_jn_edits_dir, 
 832        jns = jns 
 833      ) 
 834      return self._cmd('hdfsEnableNnHa', data=args, api_version=6) 
  835   
 836 -  def disable_nn_ha(self, active_name, snn_host_id, snn_check_point_dir_list, 
 837        snn_name=None): 
  838      """ 
 839      Disable high availability with automatic failover for an HDFS NameNode. 
 840   
 841      @param active_name: Name of the NamdeNode role that is going to be active after 
 842                          High Availability is disabled. 
 843      @param snn_host_id: Id of the host where the new SecondaryNameNode will be created. 
 844      @param snn_check_point_dir_list : List of directories used for checkpointing 
 845                                        by the new SecondaryNameNode. 
 846      @param snn_name: Name of the new SecondaryNameNode role (Optional). 
 847      @return: Reference to the submitted command. 
 848      @since: API v6 
 849      """ 
 850      args = dict( 
 851        activeNnName = active_name, 
 852        snnHostId = snn_host_id, 
 853        snnCheckpointDirList = snn_check_point_dir_list, 
 854        snnName = snn_name 
 855      ) 
 856      return self._cmd('hdfsDisableNnHa', data=args, api_version=6) 
  857   
 858 -  def enable_jt_ha(self, new_jt_host_id, force_init_znode=True, zk_service_name=None, 
 859        new_jt_name=None, fc1_name=None, fc2_name=None): 
  860      """ 
 861      Enable high availability for a MR JobTracker. 
 862   
 863      @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 
 864             If MapReduce service depends on a ZooKeeper service then that ZooKeeper 
 865             service will be used for auto-failover and in that case this parameter 
 866             can be omitted. 
 867      @param new_jt_host_id: id of the host where the second JobTracker 
 868                          will be added. 
 869      @param force_init_znode: Initialize the ZNode used for auto-failover even if 
 870                               it already exists. This can happen if JobTracker HA 
 871                               was enabled before and then disabled. Disable operation 
 872                               doesn't delete this ZNode. Defaults to true. 
 873      @param new_jt_name: Name of the second JobTracker role to be created. 
 874      @param fc1_name: Name of the Failover Controller role that is co-located with 
 875                       the existing JobTracker. 
 876      @param fc2_name: Name of the Failover Controller role that is co-located with 
 877                       the new JobTracker. 
 878      @return: Reference to the submitted command. 
 879      @since: API v5 
 880      """ 
 881      args = dict( 
 882        newJtHostId = new_jt_host_id, 
 883        forceInitZNode = force_init_znode, 
 884        zkServiceName = zk_service_name, 
 885        newJtRoleName = new_jt_name, 
 886        fc1RoleName = fc1_name, 
 887        fc2RoleName = fc2_name 
 888      ) 
 889      return self._cmd('enableJtHa', data=args) 
  890   
 892      """ 
 893      Disable high availability for a MR JobTracker active-standby pair. 
 894   
 895      @param active_name: name of the JobTracker that will be active after 
 896                          the disable operation. The other JobTracker and 
 897                          Failover Controllers will be removed. 
 898      @return: Reference to the submitted command. 
 899      """ 
 900      args = dict( 
 901        activeName = active_name, 
 902      ) 
 903      return self._cmd('disableJtHa', data=args) 
  904   
 905 -  def enable_rm_ha(self, new_rm_host_id, zk_service_name=None): 
  906      """ 
 907      Enable high availability for a YARN ResourceManager. 
 908   
 909      @param new_rm_host_id: id of the host where the second ResourceManager 
 910                             will be added. 
 911      @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 
 912             If YARN service depends on a ZooKeeper service then that ZooKeeper 
 913             service will be used for auto-failover and in that case this parameter 
 914             can be omitted. 
 915      @return: Reference to the submitted command. 
 916      @since: API v6 
 917      """ 
 918      args = dict( 
 919        newRmHostId = new_rm_host_id, 
 920        zkServiceName = zk_service_name 
 921      ) 
 922      return self._cmd('enableRmHa', data=args) 
  923   
 925      """ 
 926      Disable high availability for a YARN ResourceManager active-standby pair. 
 927   
 928      @param active_name: name of the ResourceManager that will be active after 
 929                          the disable operation. The other ResourceManager 
 930                          will be removed. 
 931      @return: Reference to the submitted command. 
 932      @since: API v6 
 933      """ 
 934      args = dict( 
 935        activeName = active_name 
 936      ) 
 937      return self._cmd('disableRmHa', data=args) 
  938   
 939 -  def enable_oozie_ha(self, new_oozie_server_host_ids, new_oozie_server_role_names=None, 
 940      zk_service_name=None, load_balancer_host_port=None): 
  941      """ 
 942      Enable high availability for Oozie. 
 943   
 944      @param new_oozie_server_host_ids: List of IDs of the hosts on which new Oozie Servers 
 945                                        will be added. 
 946      @param new_oozie_server_role_names: List of names of the new Oozie Servers. This is an 
 947                                          optional argument, but if provided, it should 
 948                                          match the length of host IDs provided. 
 949      @param zk_service_name: Name of the ZooKeeper service that will be used for Oozie HA. 
 950                              This is an optional parameter if the Oozie to ZooKeeper 
 951                              dependency is already set. 
 952      @param load_balancer_host_port: Address and port of the load balancer used for Oozie HA. 
 953                                      This is an optional parameter if this config is already set. 
 954      @return: Reference to the submitted command. 
 955      @since: API v6 
 956      """ 
 957      args = dict( 
 958        newOozieServerHostIds = new_oozie_server_host_ids, 
 959        newOozieServerRoleNames = new_oozie_server_role_names, 
 960        zkServiceName = zk_service_name, 
 961        loadBalancerHostPort = load_balancer_host_port 
 962      ) 
 963      return self._cmd('oozieEnableHa', data=args, api_version=6) 
  964   
 966      """ 
 967      Disable high availability for Oozie 
 968   
 969      @param active_name: Name of the Oozie Server that will be active after 
 970                          High Availability is disabled. 
 971      @return: Reference to the submitted command. 
 972      @since: API v6 
 973      """ 
 974      args = dict( 
 975        activeName = active_name 
 976      ) 
 977      return self._cmd('oozieDisableHa', data=args, api_version=6) 
  978   
 979 -  def failover_hdfs(self, active_name, standby_name, force=False): 
  980      """ 
 981      Initiate a failover of an HDFS NameNode HA pair. 
 982   
 983      This will make the given stand-by NameNode active, and vice-versa. 
 984   
 985      @param active_name: name of currently active NameNode. 
 986      @param standby_name: name of NameNode currently in stand-by. 
 987      @param force: whether to force failover. 
 988      @return: Reference to the submitted command. 
 989      """ 
 990      params = { "force" : "true" and force or "false" } 
 991      args = { ApiList.LIST_KEY : [ active_name, standby_name ] } 
 992      return self._cmd('hdfsFailover', data=[ active_name, standby_name ], 
 993          params = { "force" : "true" and force or "false" }) 
  994   
1003   
1005      """ 
1006      Initialize HDFS failover controller metadata. 
1007   
1008      Only one controller per nameservice needs to be initialized. 
1009   
1010      @param controllers: Name of failover controller instances to initialize. 
1011      @return: List of submitted commands. 
1012      """ 
1013      return self._role_cmd('hdfsInitializeAutoFailover', controllers) 
 1014   
1016      """ 
1017      Initialize a NameNode's shared edits directory. 
1018   
1019      @param namenodes: Name of NameNode instances. 
1020      @return: List of submitted commands. 
1021      """ 
1022      return self._role_cmd('hdfsInitializeSharedDir', namenodes) 
 1023   
1025      """ 
1026      Roll the edits of an HDFS NameNode or Nameservice. 
1027   
1028      @param nameservice: Nameservice whose edits should be rolled. 
1029                          Required only with a federated HDFS. 
1030      @return: Reference to the submitted command. 
1031      @since: API v3 
1032      """ 
1033      args = dict() 
1034      if nameservice: 
1035        args['nameservice'] = nameservice 
1036   
1037      return self._cmd('hdfsRollEdits', data=args) 
 1038   
1047   
1049      """ 
1050      Upgrade HBase data in HDFS and ZooKeeper as part of upgrade from CDH4 to CDH5. 
1051   
1052      @return: Reference to the submitted command. 
1053      @since: API v6 
1054      """ 
1055      return self._cmd('hbaseUpgrade', api_version=6) 
 1056   
1058      """ 
1059      Upgrade Sqoop Database schema as part of a major version upgrade. 
1060   
1061      @return: Reference to the submitted command. 
1062      @since: API v6 
1063      """ 
1064      return self._cmd('sqoopUpgradeDb', api_version=6) 
 1065   
1074   
1076      """ 
1077      Cleanup a ZooKeeper service or roles. 
1078   
1079      If no server role names are provided, the command applies to the whole 
1080      service, and cleans up all the server roles that are currently running. 
1081   
1082      @param servers: ZK server role names (optional). 
1083      @return: Command reference (for service command) or list of command 
1084               references (for role commands). 
1085      """ 
1086      if servers: 
1087        return self._role_cmd('zooKeeperCleanup', servers) 
1088      else: 
1089        return self._cmd('zooKeeperCleanup') 
 1090   
1092      """ 
1093      Initialize a ZooKeeper service or roles. 
1094   
1095      If no server role names are provided, the command applies to the whole 
1096      service, and initializes all the configured server roles. 
1097   
1098      @param servers: ZK server role names (optional). 
1099      @return: Command reference (for service command) or list of command 
1100               references (for role commands). 
1101      """ 
1102      if servers: 
1103        return self._role_cmd('zooKeeperInit', servers) 
1104      else: 
1105        return self._cmd('zooKeeperInit') 
 1106   
1108      """ 
1109      Synchronize the Hue server's database. 
1110   
1111      @param servers: Name of Hue Server roles to synchronize. 
1112      @return: List of submitted commands. 
1113      """ 
1114      return self._role_cmd('hueSyncDb', servers) 
 1115   
1117      """ 
1118      Put the service in maintenance mode. 
1119   
1120      @return: Reference to the completed command. 
1121      @since: API v2 
1122      """ 
1123      cmd = self._cmd('enterMaintenanceMode') 
1124      if cmd.success: 
1125        self._update(_get_service(self._get_resource_root(), self._path())) 
1126      return cmd 
 1127   
1129      """ 
1130      Take the service out of maintenance mode. 
1131   
1132      @return: Reference to the completed command. 
1133      @since: API v2 
1134      """ 
1135      cmd = self._cmd('exitMaintenanceMode') 
1136      if cmd.success: 
1137        self._update(_get_service(self._get_resource_root(), self._path())) 
1138      return cmd 
 1139   
1140 -  def rolling_restart(self, slave_batch_size=None, 
1141                        slave_fail_count_threshold=None, 
1142                        sleep_seconds=None, 
1143                        stale_configs_only=None, 
1144                        unupgraded_only=None, 
1145                        restart_role_types=None, 
1146                        restart_role_names=None): 
 1147      """ 
1148      Rolling restart the roles of a service. The sequence is: 
1149        1. Restart all the non-slave roles 
1150        2. If slaves are present restart them in batches of size specified 
1151        3. Perform any post-command needed after rolling restart 
1152   
1153      @param slave_batch_size: Number of slave roles to restart at a time 
1154             Must be greater than 0. Default is 1. 
1155             For HDFS, this number should be less than the replication factor (default 3) 
1156             to ensure data availability during rolling restart. 
1157      @param slave_fail_count_threshold: The threshold for number of slave batches that 
1158             are allowed to fail to restart before the entire command is considered failed. 
1159             Must be >= 0. Default is 0. 
1160      @param sleep_seconds: Number of seconds to sleep between restarts of slave role batches. 
1161              Must be >=0. Default is 0. 
1162      @param stale_configs_only: Restart roles with stale configs only. Default is false. 
1163      @param unupgraded_only: Restart roles that haven't been upgraded yet. Default is false. 
1164      @param restart_role_types: Role types to restart. If not specified, all startable roles are restarted. 
1165      @param restart_role_names: List of specific roles to restart. 
1166              If none are specified, then all roles of specified role types are restarted. 
1167      @return: Reference to the submitted command. 
1168      @since: API v3 
1169      """ 
1170      args = dict() 
1171      if slave_batch_size: 
1172        args['slaveBatchSize'] = slave_batch_size 
1173      if slave_fail_count_threshold: 
1174        args['slaveFailCountThreshold'] = slave_fail_count_threshold 
1175      if sleep_seconds: 
1176        args['sleepSeconds'] = sleep_seconds 
1177      if stale_configs_only: 
1178        args['staleConfigsOnly'] = stale_configs_only 
1179      if unupgraded_only: 
1180        args['unUpgradedOnly'] = unupgraded_only 
1181      if restart_role_types: 
1182        args['restartRoleTypes'] = restart_role_types 
1183      if restart_role_names: 
1184        args['restartRoleNames'] = restart_role_names 
1185   
1186      return self._cmd('rollingRestart', data=args) 
 1187   
1188 -  def create_replication_schedule(self, 
1189        start_time, end_time, interval_unit, interval, paused, arguments, 
1190        alert_on_start=False, alert_on_success=False, alert_on_fail=False, 
1191        alert_on_abort=False): 
 1192      """ 
1193      Create a new replication schedule for this service. 
1194   
1195      The replication argument type varies per service type. The following types 
1196      are recognized: 
1197        - HDFS: ApiHdfsReplicationArguments 
1198        - Hive: ApiHiveReplicationArguments 
1199   
1200      @type  start_time: datetime.datetime 
1201      @param start_time: The time at which the schedule becomes active and first executes. 
1202      @type  end_time: datetime.datetime 
1203      @param end_time: The time at which the schedule will expire. 
1204      @type  interval_unit: str 
1205      @param interval_unit: The unit of time the `interval` represents. Ex. MINUTE, HOUR, 
1206                            DAY. See the server documentation for a full list of values. 
1207      @type  interval: int 
1208      @param interval: The number of time units to wait until triggering the next replication. 
1209      @type  paused: bool 
1210      @param paused: Should the schedule be paused? Useful for on-demand replication. 
1211      @param arguments: service type-specific arguments for the replication job. 
1212      @param alert_on_start: whether to generate alerts when the job is started. 
1213      @param alert_on_success: whether to generate alerts when the job succeeds. 
1214      @param alert_on_fail: whether to generate alerts when the job fails. 
1215      @param alert_on_abort: whether to generate alerts when the job is aborted. 
1216      @return: The newly created schedule. 
1217      @since: API v3 
1218      """ 
1219      schedule = ApiReplicationSchedule(self._get_resource_root(), 
1220        startTime=start_time, endTime=end_time, intervalUnit=interval_unit, interval=interval, 
1221        paused=paused, alertOnStart=alert_on_start, alertOnSuccess=alert_on_success, 
1222        alertOnFail=alert_on_fail, alertOnAbort=alert_on_abort) 
1223   
1224      if self.type == 'HDFS': 
1225        if not isinstance(arguments, ApiHdfsReplicationArguments): 
1226          raise TypeError, 'Unexpected type for HDFS replication argument.' 
1227        schedule.hdfsArguments = arguments 
1228      elif self.type == 'HIVE': 
1229        if not isinstance(arguments, ApiHiveReplicationArguments): 
1230          raise TypeError, 'Unexpected type for Hive replication argument.' 
1231        schedule.hiveArguments = arguments 
1232      else: 
1233        raise TypeError, 'Replication is not supported for service type ' + self.type 
1234   
1235      return self._post("replications", ApiReplicationSchedule, True, [schedule], 
1236          api_version=3)[0] 
 1237   
1239      """ 
1240      Retrieve a list of replication schedules. 
1241   
1242      @return: A list of replication schedules. 
1243      @since: API v3 
1244      """ 
1245      return self._get("replications", ApiReplicationSchedule, True, 
1246          api_version=3) 
 1247   
1249      """ 
1250      Retrieve a single replication schedule. 
1251   
1252      @param schedule_id: The id of the schedule to retrieve. 
1253      @return: The requested schedule. 
1254      @since: API v3 
1255      """ 
1256      return self._get("replications/%d" % schedule_id, ApiReplicationSchedule, 
1257          api_version=3) 
 1258   
1260      """ 
1261      Delete a replication schedule. 
1262   
1263      @param schedule_id: The id of the schedule to delete. 
1264      @return: The deleted replication schedule. 
1265      @since: API v3 
1266      """ 
1267      return self._delete("replications/%s" % schedule_id, ApiReplicationSchedule, 
1268          api_version=3) 
 1269   
1271      """ 
1272      Update a replication schedule. 
1273   
1274      @param schedule_id: The id of the schedule to update. 
1275      @param schedule: The modified schedule. 
1276      @return: The updated replication schedule. 
1277      @since: API v3 
1278      """ 
1279      return self._put("replications/%s" % schedule_id, ApiReplicationSchedule, 
1280          data=schedule, api_version=3) 
 1281   
1282 -  def get_replication_command_history(self, schedule_id, limit=20, offset=0, 
1283                                        view=None): 
 1284      """ 
1285      Retrieve a list of commands for a replication schedule. 
1286   
1287      @param schedule_id: The id of the replication schedule. 
1288      @param limit: Maximum number of commands to retrieve. 
1289      @param offset: Index of first command to retrieve. 
1290      @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 
1291      @return: List of commands executed for a replication schedule. 
1292      @since: API v4 
1293      """ 
1294      params = { 
1295        'limit':  limit, 
1296        'offset': offset, 
1297      } 
1298      if view: 
1299        params['view'] = view 
1300   
1301      return self._get("replications/%s/history" % schedule_id, 
1302                       ApiReplicationCommand, True, params=params, api_version=4) 
 1303   
1305      """ 
1306      Trigger replication immediately. Start and end dates on the schedule will be 
1307      ignored. 
1308   
1309      @param schedule_id: The id of the schedule to trigger. 
1310      @param dry_run: Whether to execute a dry run. 
1311      @return: The command corresponding to the replication job. 
1312      @since: API v3 
1313      """ 
1314      return self._post("replications/%s/run" % schedule_id, ApiCommand, 
1315          params=dict(dryRun=dry_run), 
1316          api_version=3) 
 1317   
1319      """ 
1320      Create a new snapshot policy for this service. 
1321      @param policy: The snapshot policy to create 
1322      @return: The newly created policy. 
1323      @since: API v6 
1324      """ 
1325      return self._post("snapshots/policies", ApiSnapshotPolicy, True, [policy], 
1326          api_version=6)[0] 
 1327   
1329      """ 
1330      Retrieve a list of snapshot policies. 
1331   
1332      @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 
1333      @return: A list of snapshot policies. 
1334      @since: API v6 
1335      """ 
1336      return self._get("snapshots/policies", ApiSnapshotPolicy, True, 
1337          params=view and dict(view=view) or None, api_version=6) 
 1338   
1340      """ 
1341      Retrieve a single snapshot policy. 
1342   
1343      @param name: The name of the snapshot policy to retrieve. 
1344      @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 
1345      @return: The requested snapshot policy. 
1346      @since: API v6 
1347      """ 
1348      return self._get("snapshots/policies/%s" % name, ApiSnapshotPolicy, 
1349          params=view and dict(view=view) or None, api_version=6) 
 1350   
1352      """ 
1353      Delete a snapshot policy. 
1354   
1355      @param name: The name of the snapshot policy to delete. 
1356      @return: The deleted snapshot policy. 
1357      @since: API v6 
1358      """ 
1359      return self._delete("snapshots/policies/%s" % name, ApiSnapshotPolicy, api_version=6) 
 1360   
1362      """ 
1363      Update a snapshot policy. 
1364   
1365      @param name: The name of the snapshot policy to update. 
1366      @param policy: The modified snapshot policy. 
1367      @return: The updated snapshot policy. 
1368      @since: API v6 
1369      """ 
1370      return self._put("snapshots/policies/%s" % name, ApiSnapshotPolicy, data=policy, 
1371          api_version=6) 
 1372   
1373 -  def get_snapshot_command_history(self, name, limit=20, offset=0, view=None): 
 1374      """ 
1375      Retrieve a list of commands triggered by a snapshot policy. 
1376   
1377      @param name: The name of the snapshot policy. 
1378      @param limit: Maximum number of commands to retrieve. 
1379      @param offset: Index of first command to retrieve. 
1380      @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 
1381      @return: List of commands triggered by a snapshot policy. 
1382      @since: API v6 
1383      """ 
1384      params = { 
1385        'limit':  limit, 
1386        'offset': offset, 
1387      } 
1388      if view: 
1389        params['view'] = view 
1390   
1391      return self._get("snapshots/policies/%s/history" % name, ApiSnapshotCommand, True, 
1392          params=params, api_version=6) 
 1393   
1394   
1396      """ 
1397      Installs the Oozie ShareLib. Oozie must be stopped before running this 
1398      command. 
1399   
1400      @return: Reference to the submitted command. 
1401      @since: API v3 
1402      """ 
1403      return self._cmd('installOozieShareLib', api_version=3) 
 1404   
1406      """ 
1407      Creates the Oozie Database Schema in the configured database. 
1408   
1409      @return: Reference to the submitted command. 
1410      @since: API v2 
1411      """ 
1412      return self._cmd('createOozieDb', api_version=2) 
 1413   
1415      """ 
1416      Upgrade Oozie Database schema as part of a major version upgrade. 
1417   
1418      @return: Reference to the submitted command. 
1419      @since: API v6 
1420      """ 
1421      return self._cmd('oozieUpgradeDb', api_version=6) 
 1422   
1432   
1434      """ 
1435      Creates the Hive warehouse directory in HDFS. 
1436   
1437      @return: Reference to the submitted command. 
1438      @since: API v3 
1439      """ 
1440      return self._cmd('hiveCreateHiveWarehouse') 
 1441   
1443      """ 
1444      Creates the Hive user directory in HDFS. 
1445   
1446      @return: Reference to the submitted command. 
1447      @since: API v4 
1448      """ 
1449      return self._cmd('hiveCreateHiveUserDir') 
 1450   
1461   
1474   
1476      """ 
1477      Import MapReduce configuration into Yarn, overwriting Yarn configuration. 
1478   
1479      You will lose existing Yarn configuration. Read all MapReduce 
1480      configuration, role assignments, and role configuration groups and update 
1481      Yarn with corresponding values. MR1 configuration will be converted into 
1482      the equivalent MR2 configuration. 
1483   
1484      Before running this command, Yarn must be stopped and MapReduce must exist 
1485      with valid configuration. 
1486   
1487      @return: Reference to the submitted command. 
1488      @since: API v6 
1489      """ 
1490      return self._cmd('importMrConfigsIntoYarn', api_version=6) 
 1491   
1493      """ 
1494      Change the cluster to use MR2 instead of MR1. Services will be restarted. 
1495   
1496      Will perform the following steps: 
1497      * Update all services that depend on MapReduce to instead depend on Yarn. 
1498      * Stop MapReduce 
1499      * Start Yarn (includes MR2) 
1500      * Deploy Yarn (MR2) Client Configuration 
1501   
1502      Available since API v6. 
1503   
1504      @return: Reference to the submitted command. 
1505      @since: API v6 
1506      """ 
1507      return self._cmd('switchToMr2', api_version=6) 
 1508   
1510      """ 
1511      Executes a role command by name on the specified 
1512      roles 
1513   
1514      @param command_name: The name of the command. 
1515      @param role_names: The role names to execute this command on. 
1516      @return: Reference to the submitted command. 
1517      @since: API v6 
1518      """ 
1519      return self._role_cmd(command_name, role_names, api_version=6) 
 1520   
1522      """ 
1523      Executes a command on the service specified 
1524      by name. 
1525   
1526      @param command_name: The name of the command. 
1527      @return: Reference to the submitted command. 
1528      @since: API v6 
1529      """ 
1530      return self._cmd(command_name, api_version=6) 
 1531   
1533      """ 
1534      Lists all the commands that can be executed by name 
1535      on the provided service. 
1536   
1537      @return: A list of command metadata objects 
1538      @since: API v6 
1539      """ 
1540      return self._get("commandsByName", ApiCommandMetadata, True, 
1541          api_version=6) 
  1542   
1544    _ATTRIBUTES = { 
1545      'name'    : None, 
1546      'type'    : None, 
1547      'config'  : Attr(ApiConfig), 
1548      'roles'   : Attr(roles.ApiRole), 
1549    } 
1550   
1551 -  def __init__(self, name=None, type=None, 
1552                 config=None, roles=None): 
 1553       
1554      resource_root = None 
1555       
1556       
1557      BaseApiObject.init(self, None, locals()) 
 1558   
1560      """ 
1561      Set the service configuration. 
1562   
1563      @param config: A dictionary of config key/value 
1564      """ 
1565      if self.config is None: 
1566        self.config = { } 
1567      self.config.update(config_to_api_list(config)) 
 1568   
1570      """ 
1571      Add a role type setup info. 
1572   
1573      @param role_type: Role type 
1574      @param config: A dictionary of role type configuration 
1575      """ 
1576      rt_config = config_to_api_list(config) 
1577      rt_config['roleType'] = role_type 
1578   
1579      if self.config is None: 
1580        self.config = { } 
1581      if not self.config.has_key(ROLETYPES_CFG_KEY): 
1582        self.config[ROLETYPES_CFG_KEY] = [ ] 
1583      self.config[ROLETYPES_CFG_KEY].append(rt_config) 
 1584   
1585 -  def add_role_info(self, role_name, role_type, host_id, config=None): 
 1586      """ 
1587      Add a role info. The role will be created along with the service setup. 
1588   
1589      @param role_name: Role name 
1590      @param role_type: Role type 
1591      @param host_id: The host where the role should run 
1592      @param config: (Optional) A dictionary of role config values 
1593      """ 
1594      if self.roles is None: 
1595        self.roles = [ ] 
1596      api_config_list = config is not None and config_to_api_list(config) or None 
1597      self.roles.append({ 
1598          'name' : role_name, 
1599          'type' : role_type, 
1600          'hostRef' : { 'hostId' : host_id }, 
1601          'config' : api_config_list }) 
  1602