class ApiRoleConfigGroup(types.BaseApiResource): _ATTRIBUTES = { 'name': None, 'displayName': None, 'roleType': None, 'config': types.Attr(types.ApiConfig), 'base': types.ROAttr(), 'serviceRef': types.ROAttr(types.ApiServiceRef), } def __init__(self, resource_root, name=None, displayName=None, roleType=None, config=None): types.BaseApiObject.init(self, resource_root, locals()) def __str__(self): return ("<ApiRoleConfigGroup>: %s (cluster: %s; service: %s)" % (self.name, self.serviceRef.clusterName, self.serviceRef.serviceName)) def _api_version(self): return 3 def _path(self): return _get_role_config_group_path(self.serviceRef.clusterName, self.serviceRef.serviceName, self.name) def get_config(self, view=None): """Retrieve the group's configuration The 'summary' view contains strings as the dictionary values. The full view contains types.ApiConfig instances as the values. :param view: View to materialize ('full' or 'summary'). :return: Dictionary with configuration data. """ path = self._path() + '/config' resp = self._get_resource_root().get( path, params=(dict(view=view) if view else None)) return types.json_to_config(resp, view == 'full') def update_config(self, config): """Update the group's configuration :param config: Dictionary with configuration to update. :return: Dictionary with updated configuration. """ path = self._path() + '/config' resp = self._get_resource_root().put(path, data=types.config_to_json(config)) return types.json_to_config(resp)
class ApiCluster(types.BaseApiResource): _ATTRIBUTES = { 'name': None, 'displayName': None, 'version': None, 'fullVersion': None, 'maintenanceMode': types.ROAttr(), 'maintenanceOwners': types.ROAttr(), } def __init__(self, resource_root, name=None, version=None, fullVersion=None): types.BaseApiObject.init(self, resource_root, locals()) def _path(self): return "%s/%s" % (CLUSTERS_PATH, self.name) def get_service_types(self): """Get all service types supported by this cluster :return: A list of service types (strings) """ resp = self._get_resource_root().get(self._path() + '/serviceTypes') return resp[types.ApiList.LIST_KEY] def get_commands(self, view=None): """Retrieve a list of running commands for this cluster :param view: View to materialize ('full' or 'summary') :return: A list of running commands. """ return self._get("commands", types.ApiCommand, True, params=(dict(view=view) if view else None)) def create_service(self, name, service_type): """Create a service :param name: Service name :param service_type: Service type :return: An ApiService object """ return services.create_service(self._get_resource_root(), name, service_type, self.name) def get_service(self, name): """Lookup a service by name :param name: Service name :return: An ApiService object """ return services.get_service(self._get_resource_root(), name, self.name) def start(self): """Start all services in a cluster, respecting dependencies :return: Reference to the submitted command. """ return self._cmd('start') def deploy_client_config(self): """Deploys Service client configuration to the hosts on the cluster :return: Reference to the submitted command. :since: API v2 """ return self._cmd('deployClientConfig') def first_run(self): """Prepare and start services in a cluster Perform all the steps needed to prepare each service in a cluster and start the services in order. :return: Reference to the submitted command. :since: API v7 """ return self._cmd('firstRun', None, api_version=7) def remove_host(self, hostId): """Removes the association of the host with the cluster :return: A ApiHostRef of the host that was removed. :since: API v3 """ return self._delete("hosts/" + hostId, types.ApiHostRef, api_version=3)
class ApiHost(types.BaseApiResource): _ATTRIBUTES = { 'hostId': None, 'hostname': None, 'ipAddress': None, 'rackId': None, 'status': types.ROAttr(), 'lastHeartbeat': types.ROAttr(datetime.datetime), 'roleRefs': types.ROAttr(types.ApiRoleRef), 'healthSummary': types.ROAttr(), 'healthChecks': types.ROAttr(), 'hostUrl': types.ROAttr(), 'commissionState': types.ROAttr(), 'maintenanceMode': types.ROAttr(), 'maintenanceOwners': types.ROAttr(), 'numCores': types.ROAttr(), 'totalPhysMemBytes': types.ROAttr(), } def __init__(self, resource_root, hostId=None, hostname=None, ipAddress=None, rackId=None): types.BaseApiObject.init(self, resource_root, locals()) def __str__(self): return "<ApiHost>: %s (%s)" % (self.hostId, self.ipAddress) def _path(self): return HOSTS_PATH + '/' + self.hostId def _put_host(self): """Update this resource :return: The updated object. """ return self._put('', ApiHost, data=self)
class ApiService(types.BaseApiResource): _ATTRIBUTES = { 'name': None, 'type': None, 'displayName': None, 'serviceState': types.ROAttr(), 'healthSummary': types.ROAttr(), 'healthChecks': types.ROAttr(), 'clusterRef': types.ROAttr(types.ApiClusterRef), 'configStale': types.ROAttr(), 'configStalenessStatus': types.ROAttr(), 'clientConfigStalenessStatus': types.ROAttr(), 'serviceUrl': types.ROAttr(), 'maintenanceMode': types.ROAttr(), 'maintenanceOwners': types.ROAttr(), } def __init__(self, resource_root, name=None, type=None): types.BaseApiObject.init(self, resource_root, locals()) def __str__(self): return ("<ApiService>: %s (cluster: %s)" % (self.name, self._get_cluster_name())) def _get_cluster_name(self): if hasattr(self, 'clusterRef') and self.clusterRef: return self.clusterRef.clusterName return None def _path(self): """Return the API path for this service This method assumes that lack of a cluster reference means that the object refers to the Cloudera Management Services instance. """ if self._get_cluster_name(): return SERVICE_PATH % (self._get_cluster_name(), self.name) else: return '/cm/service' def _role_cmd(self, cmd, roles, api_version=1): return self._post("roleCommands/" + cmd, types.ApiBulkCommandList, data=roles, api_version=api_version) def _parse_svc_config(self, json_dic, view=None): """Parse a json-decoded ApiServiceConfig dictionary into a 2-tuple :param json_dic: The json dictionary with the config data. :param view: View to materialize. :return: 2-tuple (service config dictionary, role type configurations) """ svc_config = types.json_to_config(json_dic, view == 'full') rt_configs = {} if ROLETYPES_CFG_KEY in json_dic: for rt_config in json_dic[ROLETYPES_CFG_KEY]: rt_configs[rt_config['roleType']] = types.json_to_config( rt_config, view == 'full') return (svc_config, rt_configs) def create_yarn_job_history_dir(self): """Create the Yarn job history directory :return: Reference to submitted command. :since: API v6 """ return self._cmd('yarnCreateJobHistoryDirCommand', api_version=6) def get_config(self, view=None): """Retrieve the service's configuration Retrieves both the service configuration and role type configuration for each of the service's supported role types. The role type configurations are returned as a dictionary, whose keys are the role type name, and values are the respective configuration dictionaries. The 'summary' view contains strings as the dictionary values. The full view contains types.ApiConfig instances as the values. :param view: View to materialize ('full' or 'summary') :return: 2-tuple (service config dictionary, role type configurations) """ path = self._path() + '/config' resp = self._get_resource_root().get( path, params=(dict(view=view) if view else None)) return self._parse_svc_config(resp, view) def update_config(self, svc_config, **rt_configs): """Update the service's configuration :param svc_config: Dictionary with service configuration to update. :param rt_configs: Dict of role type configurations to update. :return: 2-tuple (service config dictionary, role type configurations) """ path = self._path() + '/config' if svc_config: data = types.config_to_api_list(svc_config) else: data = {} if rt_configs: rt_list = [] for rt, cfg in six.iteritems(rt_configs): rt_data = types.config_to_api_list(cfg) rt_data['roleType'] = rt rt_list.append(rt_data) data[ROLETYPES_CFG_KEY] = rt_list resp = self._get_resource_root().put(path, data=json.dumps(data)) return self._parse_svc_config(resp) def create_role(self, role_name, role_type, host_id): """Create a role :param role_name: Role name :param role_type: Role type :param host_id: ID of the host to assign the role to :return: An ApiRole object """ return roles.create_role(self._get_resource_root(), self.name, role_type, role_name, host_id, self._get_cluster_name()) def delete_role(self, name): """Delete a role by name :param name: Role name :return: The deleted ApiRole object """ return roles.delete_role(self._get_resource_root(), self.name, name, self._get_cluster_name()) def get_roles_by_type(self, role_type, view=None): """Get all roles of a certain type in a service :param role_type: Role type :param view: View to materialize ('full' or 'summary') :return: A list of ApiRole objects. """ return roles.get_roles_by_type(self._get_resource_root(), self.name, role_type, self._get_cluster_name(), view) def get_all_role_config_groups(self): """Get a list of role configuration groups in the service :return: A list of ApiRoleConfigGroup objects. :since: API v3 """ return role_config_groups.get_all_role_config_groups( self._get_resource_root(), self.name, self._get_cluster_name()) def start(self): """Start a service :return: Reference to the submitted command. """ return self._cmd('start') def stop(self): """Stop a service :return: Reference to the submitted command. """ return self._cmd('stop') def restart(self): """Restart a service :return: Reference to the submitted command. """ return self._cmd('restart') def get_health_summary(self): return getattr(self, 'healthSummary', None) def get_health_checks_status(self): return getattr(self, 'healthChecks', None) def start_roles(self, *role_names): """Start a list of roles :param role_names: names of the roles to start. :return: List of submitted commands. """ return self._role_cmd('start', role_names) def create_hbase_root(self): """Create the root directory of an HBase service :return: Reference to the submitted command. """ return self._cmd('hbaseCreateRoot') def create_hdfs_tmp(self): """Create /tmp directory in HDFS Create the /tmp directory in HDFS with appropriate ownership and permissions. :return: Reference to the submitted command :since: API v2 """ return self._cmd('hdfsCreateTmpDir') def refresh(self, *role_names): """Execute the "refresh" command on a set of roles :param role_names: Names of the roles to refresh. :return: Reference to the submitted command. """ return self._role_cmd('refresh', role_names) def decommission(self, *role_names): """Decommission roles in a service :param role_names: Names of the roles to decommission. :return: Reference to the submitted command. """ return self._cmd('decommission', data=role_names) def deploy_client_config(self, *role_names): """Deploys client configuration to the hosts where roles are running :param role_names: Names of the roles to decommission. :return: Reference to the submitted command. """ return self._cmd('deployClientConfig', data=role_names) def format_hdfs(self, *namenodes): """Format NameNode instances of an HDFS service :param namenodes: Name of NameNode instances to format. :return: List of submitted commands. """ return self._role_cmd('hdfsFormat', namenodes) def install_oozie_sharelib(self): """Installs the Oozie ShareLib Oozie must be stopped before running this command. :return: Reference to the submitted command. :since: API v3 """ return self._cmd('installOozieShareLib', api_version=3) def create_oozie_db(self): """Creates the Oozie Database Schema in the configured database :return: Reference to the submitted command. :since: API v2 """ return self._cmd('createOozieDb', api_version=2) def upgrade_oozie_db(self): """Upgrade Oozie Database schema as part of a major version upgrade :return: Reference to the submitted command. :since: API v6 """ return self._cmd('oozieUpgradeDb', api_version=6) def create_hive_metastore_tables(self): """Creates the Hive metastore tables in the configured database Will do nothing if tables already exist. Will not perform an upgrade. :return: Reference to the submitted command. :since: API v3 """ return self._cmd('hiveCreateMetastoreDatabaseTables', api_version=3) def create_hive_warehouse(self): """Creates the Hive warehouse directory in HDFS :return: Reference to the submitted command. :since: API v3 """ return self._cmd('hiveCreateHiveWarehouse') def create_hive_userdir(self): """Creates the Hive user directory in HDFS :return: Reference to the submitted command. :since: API v4 """ return self._cmd('hiveCreateHiveUserDir') def enable_nn_ha(self, active_name, standby_host_id, nameservice, jns, standby_name_dir_list=None, qj_name=None, standby_name=None, active_fc_name=None, standby_fc_name=None, zk_service_name=None, force_init_znode=True, clear_existing_standby_name_dirs=True, clear_existing_jn_edits_dir=True): """Enable High Availability (HA) with Auto-Failover for HDFS NameNode @param active_name: Name of Active NameNode. @param standby_host_id: ID of host where Standby NameNode will be created. @param nameservice: Nameservice to be used while enabling HA. Optional if Active NameNode already has this config set. @param jns: List of Journal Nodes to be created during the command. Each element of the list must be a dict containing the following items: - jns['jnHostId']: ID of the host where the new JournalNode will be created. - jns['jnName']: Name of the JournalNode role (optional) - jns['jnEditsDir']: Edits dir of the JournalNode. Can be omitted if the config is already set at RCG level. @param standby_name_dir_list: List of directories for the new Standby NameNode. If not provided then it will use same dirs as Active NameNode. @param qj_name: Name of the journal located on each JournalNodes' filesystem. This can be optionally provided if the config hasn't been already set for the Active NameNode. If this isn't provided and Active NameNode doesn't also have the config, then nameservice is used by default. @param standby_name: Name of the Standby NameNode role to be created (Optional). @param active_fc_name: Name of the Active Failover Controller role to be created (Optional). @param standby_fc_name: Name of the Standby Failover Controller role to be created (Optional). @param zk_service_name: Name of the ZooKeeper service to use for auto- failover. If HDFS service already depends on a ZooKeeper service then that ZooKeeper service will be used for auto-failover and in that case this parameter can either be omitted or should be the same ZooKeeper service. @param force_init_znode: Indicates if the ZNode should be force initialized if it is already present. Useful while re-enabling High Availability. (Default: TRUE) @param clear_existing_standby_name_dirs: Indicates if the existing name directories for Standby NameNode should be cleared during the workflow. Useful while re-enabling High Availability. (Default: TRUE) @param clear_existing_jn_edits_dir: Indicates if the existing edits directories for the JournalNodes for the specified nameservice should be cleared during the workflow. Useful while re-enabling High Availability. (Default: TRUE) @return: Reference to the submitted command. @since: API v6 """ args = dict( activeNnName=active_name, standbyNnName=standby_name, standbyNnHostId=standby_host_id, standbyNameDirList=standby_name_dir_list, nameservice=nameservice, qjName=qj_name, activeFcName=active_fc_name, standbyFcName=standby_fc_name, zkServiceName=zk_service_name, forceInitZNode=force_init_znode, clearExistingStandbyNameDirs=clear_existing_standby_name_dirs, clearExistingJnEditsDir=clear_existing_jn_edits_dir, jns=jns) return self._cmd('hdfsEnableNnHa', data=args, api_version=6) def enable_rm_ha(self, new_rm_host_id, zk_service_name=None): """Enable high availability for a YARN ResourceManager. @param new_rm_host_id: id of the host where the second ResourceManager will be added. @param zk_service_name: Name of the ZooKeeper service to use for auto- failover. If YARN service depends on a ZooKeeper service then that ZooKeeper service will be used for auto-failover and in that case this parameter can be omitted. @return: Reference to the submitted command. @since: API v6 """ args = dict(newRmHostId=new_rm_host_id, zkServiceName=zk_service_name) return self._cmd('enableRmHa', data=args)
class ApiHost(types.BaseApiResource): _ATTRIBUTES = { 'hostId': None, 'hostname': None, 'ipAddress': None, 'rackId': None, 'status': types.ROAttr(), 'lastHeartbeat': types.ROAttr(datetime.datetime), 'roleRefs': types.ROAttr(types.ApiRoleRef), 'healthSummary': types.ROAttr(), 'healthChecks': types.ROAttr(), 'hostUrl': types.ROAttr(), 'commissionState': types.ROAttr(), 'maintenanceMode': types.ROAttr(), 'maintenanceOwners': types.ROAttr(), 'numCores': types.ROAttr(), 'totalPhysMemBytes': types.ROAttr(), } def __init__(self, resource_root, hostId=None, hostname=None, ipAddress=None, rackId=None): types.BaseApiObject.init(self, resource_root, locals()) def __str__(self): return "<ApiHost>: %s (%s)" % (self.hostId, self.ipAddress) def _path(self): return HOSTS_PATH + '/' + self.hostId def put_host(self): """Update this resource note (mionkin):Currently, according to Cloudera docs, only updating the rackId is supported. All other fields of the host will be ignored. :return: The updated object. """ return self._put('', ApiHost, data=self)
class ApiService(types.BaseApiResource): _ATTRIBUTES = { 'name': None, 'type': None, 'displayName': None, 'serviceState': types.ROAttr(), 'healthSummary': types.ROAttr(), 'healthChecks': types.ROAttr(), 'clusterRef': types.ROAttr(types.ApiClusterRef), 'configStale': types.ROAttr(), 'configStalenessStatus': types.ROAttr(), 'clientConfigStalenessStatus': types.ROAttr(), 'serviceUrl': types.ROAttr(), 'maintenanceMode': types.ROAttr(), 'maintenanceOwners': types.ROAttr(), } def __init__(self, resource_root, name=None, type=None): types.BaseApiObject.init(self, resource_root, locals()) def __str__(self): return ("<ApiService>: %s (cluster: %s)" % (self.name, self._get_cluster_name())) def _get_cluster_name(self): if hasattr(self, 'clusterRef') and self.clusterRef: return self.clusterRef.clusterName return None def _path(self): """Return the API path for this service This method assumes that lack of a cluster reference means that the object refers to the Cloudera Management Services instance. """ if self._get_cluster_name(): return SERVICE_PATH % (self._get_cluster_name(), self.name) else: return '/cm/service' def _role_cmd(self, cmd, roles, api_version=1): return self._post("roleCommands/" + cmd, types.ApiBulkCommandList, data=roles, api_version=api_version) def _parse_svc_config(self, json_dic, view=None): """Parse a json-decoded ApiServiceConfig dictionary into a 2-tuple :param json_dic: The json dictionary with the config data. :param view: View to materialize. :return: 2-tuple (service config dictionary, role type configurations) """ svc_config = types.json_to_config(json_dic, view == 'full') rt_configs = {} if ROLETYPES_CFG_KEY in json_dic: for rt_config in json_dic[ROLETYPES_CFG_KEY]: rt_configs[rt_config['roleType']] = types.json_to_config( rt_config, view == 'full') return (svc_config, rt_configs) def create_yarn_job_history_dir(self): """Create the Yarn job history directory :return: Reference to submitted command. :since: API v6 """ return self._cmd('yarnCreateJobHistoryDirCommand', api_version=6) def get_config(self, view=None): """Retrieve the service's configuration Retrieves both the service configuration and role type configuration for each of the service's supported role types. The role type configurations are returned as a dictionary, whose keys are the role type name, and values are the respective configuration dictionaries. The 'summary' view contains strings as the dictionary values. The full view contains types.ApiConfig instances as the values. :param view: View to materialize ('full' or 'summary') :return: 2-tuple (service config dictionary, role type configurations) """ path = self._path() + '/config' resp = self._get_resource_root().get( path, params=(dict(view=view) if view else None)) return self._parse_svc_config(resp, view) def update_config(self, svc_config, **rt_configs): """Update the service's configuration :param svc_config: Dictionary with service configuration to update. :param rt_configs: Dict of role type configurations to update. :return: 2-tuple (service config dictionary, role type configurations) """ path = self._path() + '/config' if svc_config: data = types.config_to_api_list(svc_config) else: data = {} if rt_configs: rt_list = [] for rt, cfg in six.iteritems(rt_configs): rt_data = types.config_to_api_list(cfg) rt_data['roleType'] = rt rt_list.append(rt_data) data[ROLETYPES_CFG_KEY] = rt_list resp = self._get_resource_root().put(path, data=json.dumps(data)) return self._parse_svc_config(resp) def create_role(self, role_name, role_type, host_id): """Create a role :param role_name: Role name :param role_type: Role type :param host_id: ID of the host to assign the role to :return: An ApiRole object """ return roles.create_role(self._get_resource_root(), self.name, role_type, role_name, host_id, self._get_cluster_name()) def delete_role(self, name): """Delete a role by name :param name: Role name :return: The deleted ApiRole object """ return roles.delete_role(self._get_resource_root(), self.name, name, self._get_cluster_name()) def get_roles_by_type(self, role_type, view=None): """Get all roles of a certain type in a service :param role_type: Role type :param view: View to materialize ('full' or 'summary') :return: A list of ApiRole objects. """ return roles.get_roles_by_type(self._get_resource_root(), self.name, role_type, self._get_cluster_name(), view) def get_all_role_config_groups(self): """Get a list of role configuration groups in the service :return: A list of ApiRoleConfigGroup objects. :since: API v3 """ return role_config_groups.get_all_role_config_groups( self._get_resource_root(), self.name, self._get_cluster_name()) def start(self): """Start a service :return: Reference to the submitted command. """ return self._cmd('start') def stop(self): """Stop a service :return: Reference to the submitted command. """ return self._cmd('stop') def restart(self): """Restart a service :return: Reference to the submitted command. """ return self._cmd('restart') def start_roles(self, *role_names): """Start a list of roles :param role_names: names of the roles to start. :return: List of submitted commands. """ return self._role_cmd('start', role_names) def create_hbase_root(self): """Create the root directory of an HBase service :return: Reference to the submitted command. """ return self._cmd('hbaseCreateRoot') def create_hdfs_tmp(self): """Create /tmp directory in HDFS Create the /tmp directory in HDFS with appropriate ownership and permissions. :return: Reference to the submitted command :since: API v2 """ return self._cmd('hdfsCreateTmpDir') def refresh(self, *role_names): """Execute the "refresh" command on a set of roles :param role_names: Names of the roles to refresh. :return: Reference to the submitted command. """ return self._role_cmd('refresh', role_names) def decommission(self, *role_names): """Decommission roles in a service :param role_names: Names of the roles to decommission. :return: Reference to the submitted command. """ return self._cmd('decommission', data=role_names) def deploy_client_config(self, *role_names): """Deploys client configuration to the hosts where roles are running :param role_names: Names of the roles to decommission. :return: Reference to the submitted command. """ return self._cmd('deployClientConfig', data=role_names) def format_hdfs(self, *namenodes): """Format NameNode instances of an HDFS service :param namenodes: Name of NameNode instances to format. :return: List of submitted commands. """ return self._role_cmd('hdfsFormat', namenodes) def install_oozie_sharelib(self): """Installs the Oozie ShareLib Oozie must be stopped before running this command. :return: Reference to the submitted command. :since: API v3 """ return self._cmd('installOozieShareLib', api_version=3) def create_oozie_db(self): """Creates the Oozie Database Schema in the configured database :return: Reference to the submitted command. :since: API v2 """ return self._cmd('createOozieDb', api_version=2) def upgrade_oozie_db(self): """Upgrade Oozie Database schema as part of a major version upgrade :return: Reference to the submitted command. :since: API v6 """ return self._cmd('oozieUpgradeDb', api_version=6) def create_hive_metastore_tables(self): """Creates the Hive metastore tables in the configured database Will do nothing if tables already exist. Will not perform an upgrade. :return: Reference to the submitted command. :since: API v3 """ return self._cmd('hiveCreateMetastoreDatabaseTables', api_version=3) def create_hive_warehouse(self): """Creates the Hive warehouse directory in HDFS :return: Reference to the submitted command. :since: API v3 """ return self._cmd('hiveCreateHiveWarehouse') def create_hive_userdir(self): """Creates the Hive user directory in HDFS :return: Reference to the submitted command. :since: API v4 """ return self._cmd('hiveCreateHiveUserDir')
class ApiRole(types.BaseApiResource): _ATTRIBUTES = { 'name': None, 'type': None, 'hostRef': types.Attr(types.ApiHostRef), 'roleState': types.ROAttr(), 'healthSummary': types.ROAttr(), 'healthChecks': types.ROAttr(), 'serviceRef': types.ROAttr(types.ApiServiceRef), 'configStale': types.ROAttr(), 'configStalenessStatus': types.ROAttr(), 'haStatus': types.ROAttr(), 'roleUrl': types.ROAttr(), 'commissionState': types.ROAttr(), 'maintenanceMode': types.ROAttr(), 'maintenanceOwners': types.ROAttr(), 'roleConfigGroupRef': types.ROAttr(types.ApiRoleConfigGroupRef), 'zooKeeperServerMode': types.ROAttr(), } def __init__(self, resource_root, name=None, type=None, hostRef=None): types.BaseApiObject.init(self, resource_root, locals()) def __str__(self): return ("<ApiRole>: %s (cluster: %s; service: %s)" % (self.name, self.serviceRef.clusterName, self.serviceRef.serviceName)) def _path(self): return _get_role_path(self.serviceRef.clusterName, self.serviceRef.serviceName, self.name) def _get_log(self, log): path = "%s/logs/%s" % (self._path(), log) return self._get_resource_root().get(path) def get_commands(self, view=None): """Retrieve a list of running commands for this role :param view: View to materialize ('full' or 'summary') :return: A list of running commands. """ return self._get("commands", types.ApiCommand, True, params=(dict(view=view) if view else None)) def get_config(self, view=None): """Retrieve the role's configuration The 'summary' view contains strings as the dictionary values. The full view contains types.ApiConfig instances as the values. :param view: View to materialize ('full' or 'summary') :return: Dictionary with configuration data. """ return self._get_config("config", view) def update_config(self, config): """Update the role's configuration :param config: Dictionary with configuration to update. :return: Dictionary with updated configuration. """ return self._update_config("config", config)
class ApiCluster(types.BaseApiResource): _ATTRIBUTES = { 'name': None, 'clusterUrl': None, 'displayName': None, 'version': None, 'fullVersion': None, 'hostsUrl': types.ROAttr(), 'maintenanceMode': types.ROAttr(), 'maintenanceOwners': types.ROAttr(), 'entityStatus': types.ROAttr(), } def __init__(self, resource_root, name=None, version=None, fullVersion=None): types.BaseApiObject.init(self, resource_root, locals()) def _path(self): return "%s/%s" % (CLUSTERS_PATH, self.name) def get_service_types(self): """Get all service types supported by this cluster :return: A list of service types (strings) """ resp = self._get_resource_root().get(self._path() + '/serviceTypes') return resp[types.ApiList.LIST_KEY] def get_commands(self, view=None): """Retrieve a list of running commands for this cluster :param view: View to materialize ('full' or 'summary') :return: A list of running commands. """ return self._get("commands", types.ApiCommand, True, params=(dict(view=view) if view else None)) def create_service(self, name, service_type): """Create a service :param name: Service name :param service_type: Service type :return: An ApiService object """ return services.create_service(self._get_resource_root(), name, service_type, self.name) def get_service(self, name): """Lookup a service by name :param name: Service name :return: An ApiService object """ return services.get_service(self._get_resource_root(), name, self.name) def start(self): """Start all services in a cluster, respecting dependencies :return: Reference to the submitted command. """ return self._cmd('start') def restart(self, restart_only_stale_services=None, redeploy_client_configuration=None, restart_service_names=None): """Restart all services in the cluster. Services are restarted in the appropriate order given their dependencies. :param restart_only_stale_services: Only restart services that have stale configuration and their dependent services. Default is False. :param redeploy_client_configuration: Re-deploy client configuration for all services in the cluster. Default is False. :param restart_service_names: Only restart services that are specified and their dependent services. :return: Reference to the submitted command. """ if self._get_resource_root().version < 6: return self._cmd('restart') args = dict() args['restartOnlyStaleServices'] = restart_only_stale_services args['redeployClientConfiguration'] = redeploy_client_configuration if self._get_resource_root().version >= 11: args['restartServiceNames'] = restart_service_names return self._cmd('restart', data=args, api_version=6) def stop(self): """Stop all services in a cluster, respecting dependencies :return: Reference to the submitted command. """ return self._cmd('stop') def deploy_client_config(self): """Deploys Service client configuration to the hosts on the cluster :return: Reference to the submitted command. :since: API v2 """ return self._cmd('deployClientConfig') def first_run(self): """Prepare and start services in a cluster Perform all the steps needed to prepare each service in a cluster and start the services in order. :return: Reference to the submitted command. :since: API v7 """ return self._cmd('firstRun', None, api_version=7) def remove_host(self, hostId): """Removes the association of the host with the cluster :return: A ApiHostRef of the host that was removed. :since: API v3 """ return self._delete("hosts/" + hostId, types.ApiHostRef, api_version=3) def get_service_health_status(self): """Lookup a service health status by name :return: A dict with cluster health status """ health_dict = {} cl_services = services.get_all_services(self._get_resource_root(), cluster_name=self.name) for curr in cl_services: health_dict[curr.name] = { 'summary': curr.get_health_summary(), 'checks': curr.get_health_checks_status()} return health_dict def configure_for_kerberos(self, datanode_transceiver_port=None, datanode_web_port=None): """Command to configure the cluster to use Kerberos for authentication. This command will configure all relevant services on a cluster for Kerberos usage. This command will trigger a GenerateCredentials command to create Kerberos keytabs for all roles in the cluster. :param datanode_transceiver_port: The HDFS DataNode transceiver port to use. This will be applied to all DataNode role configuration groups. If not specified, this will default to 1004. :param datanode_web_port: The HDFS DataNode web port to use. This will be applied to all DataNode role configuration groups. If not specified, this will default to 1006. :return: Reference to the submitted command. :since: API v11 """ args = dict() if datanode_transceiver_port: args['datanodeTransceiverPort'] = datanode_transceiver_port if datanode_web_port: args['datanodeWebPort'] = datanode_web_port return self._cmd('configureForKerberos', data=args, api_version=11)