class ApiServiceSetupInfo(ApiService): _ATTRIBUTES = { 'name': None, 'type': None, 'config': types.Attr(types.ApiConfig), 'roles': types.Attr(roles.ApiRole), } def __init__(self, name=None, type=None, config=None, roles=None): # The BaseApiObject expects a resource_root, which we don't care about resource_root = None # Unfortunately, the json key is called "type". So our input arg # needs to be called "type" as well, despite it being a python keyword. types.BaseApiObject.init(self, None, locals()) def set_config(self, config): """Set the service configuration :param config: A dictionary of config key/value """ if self.config is None: self.config = {} self.config.update(types.config_to_api_list(config)) def add_role_info(self, role_name, role_type, host_id, config=None): """Add a role info The role will be created along with the service setup. :param role_name: Role name :param role_type: Role type :param host_id: The host where the role should run :param config: (Optional) A dictionary of role config values """ if self.roles is None: self.roles = [] api_config_list = (config is not None and types.config_to_api_list(config) or None) self.roles.append({ 'name': role_name, 'type': role_type, 'hostRef': { 'hostId': host_id }, 'config': api_config_list })
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 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 ApiServiceSetupInfo(ApiService): _ATTRIBUTES = { 'name': None, 'type': None, 'config': types.Attr(types.ApiConfig), 'roles': types.Attr(roles.ApiRole), } def __init__(self, name=None, type=None, config=None, roles=None): # The BaseApiObject expects a resource_root, which we don't care about resource_root = None # Unfortunately, the json key is called "type". So our input arg # needs to be called "type" as well, despite it being a python keyword. types.BaseApiObject.init(self, None, locals()) def set_config(self, config): """Set the service configuration :param config: A dictionary of config key/value """ if self.config is None: self.config = {} self.config.update(types.config_to_api_list(config)) def add_role_info(self, role_name, role_type, host_id, config=None): """Add a role info The role will be created along with the service setup. :param role_name: Role name :param role_type: Role type :param host_id: The host where the role should run :param config: (Optional) A dictionary of role config values """ if self.roles is None: self.roles = [] api_config_list = (config is not None and types.config_to_api_list(config) or None) self.roles.append({ 'name': role_name, 'type': role_type, 'hostRef': { 'hostId': host_id }, 'config': api_config_list }) 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)