This helper function creates a config group for a service with a list of hosts. You must provide the service name, list of hosts, and config group name as input.
This helper function adds hosts to the config group in a service with a list of hosts. You must provide service name, list of hosts, and config group name as input.
This helper function removes hosts to the config group in a service with a list of hosts. You must provide service name, list of hosts, and config group name as input.
listConfigGroups(service_name)
This helper function displays all the config groups in a service. You must provide service name.
This helper function clones the configs from one config group to another config group in a service. You must provide from config group, to config group, and service name.
This helper function updates the config properties to the config_type file of config_group in a service. You must provide service name, config type, config properties, config group, and config meta.
Note : config_properties is a map of config key and value pairs.
config_meta is map of config key and config metadata. Possible type values in config meta are PASSWORD and TEXT with default value as TEXT.
For example: helper.updateConfig(config_group="test", service_name="HDFS", config_type="core-site", config_properties={"fs.trash.interval": "400", "test.password":"XXXX"}, config_meta={"test.password": {"type":"PASSWORD"}})
This helper function removes the config from the config type file of config group in a service. You must provide config group, config type, config name, and service name.
For example: helper.removeConfig(service_name="HDFS", config_type="core-site", config_name="fs.trash.interval")
This helper function displays the config property value of config name in the config type file of a config group in a service. You must provide config group, config type, config name, and service name.
restartStaleConfig()
This helper function restarts the services where configs are stale.
This helper function displays all the configs in config type file of config group in a service. You must provide config group, config type, and service name.
Shell execution
runShellCommandOnAllNodes(command)
This helper function executes shell command on all the cluster nodes. You must provide the command.
runShellCommandOnNode(command, host)
This helper function executes shell command on the requested host. You must provide the command and host.
Utility
getClusterName()
Displays cluster name.
getMasterNodesIps()
Displays master nodes lps.
getWorkerNodesIps()
Displays worker nodes lps.
getUtilityNodesIps()
Displays utility node lps.
getQueryServerNodesIps()
Displays query server nodes lps.
getComputeOnlyWorkerNodesIps()
Displays compute only worker node lps.
getEdgeNodesIps()
Displays Edge node lps.
getAllNodesIps()
Displays all nodes lps.
getEventType()
Displays the event type. Possible event type values are CreateBdsInstance, AddWorkerNodes, StartBdsInstance, ChangeShape, on-demand.
getLogger()
This helper function returns the logger instance which you can use to log info and error logs. For example, getLogger().info("log info msg")
get_last_added_host_names()
Returns Python list of hostnames added in last "Add Node" operation.
Returns None, if no new hosts are added to the cluster.
get_last_added_host_ips()
Returns Python list of private IPs added in last "Add Node" operations.
Returns None, if no new hosts are added to the cluster.
This helper function runs Ambari REST API based method type, path, and payload. You must provide method, path, payload(If Any), params(If Any) and headers.
Parameters:
method: Possible values: GET, POST, PUT, and DELETE.
This helper function enables or disables the remoteJMX metric.
service_names: Optional list of services to be enabled with remoteJMX , service names mentioned in <remote-jmx-section>. If no value is passed, the operation is applied to all services
service_to_components: Optional Service to components mapping. If no value is passed, the operation is applied to all components of the selected services.
enable: True for enabling remoteJMX, False for disabling remoteJMX.
getRemoteJmxInfo()
This helper function returns:
Map of service → component → remoteJMX info
This function only returns this mapping for services available in the Ambari UI.
Add components
add_component_to_host(request_dict)
This function takes a Python dictionary and adds components to the hosts mentioned in the dictionary. Supported components are Namenode(NN), ResourceM,anager(RM) and Zookeeper_Server.
Caution: Support for NN and RM are only for HA clusters and to the hosts having default config groups.
Remove components
remove_component_from_host(request_dict)
This function takes a Python dictionary and removes components from the hosts mentioned in the dictionary with timeouts. Supported components are Datanode and NodeManager.
#!/usr/bin/env python2.7
def execute(helper):
# custom logger
logger = helper.getLogger()
logger.info('Testing Config Helper functions')
# Update config_properties in the Default config group of config_type file core-site in service HDFS
helper.updateConfig(service_name="HDFS", config_type="core-site", config_properties={"fs.trash.interval": "400"})
# Remove config property from Default config group of config_type core-site
helper.removeConfig(service_name="HDFS", config_type="core-site", config_name="fs.trash.interval")
# Get config value from Default config group of config_type file core-site in service HDFS
config_value = helper.getConfig(service_name="HDFS", config_type="core-site", config_name="fs.trash.interval")
# Export configs from Default config group of config_type file core-site in service HDFS
helper.exportConfig(service_name="HDFS", config_type="core-site")
# Restart stale config
helper.restartStaleConfig()
#!/usr/bin/env python2.7
def execute(helper):
logger = helper.getLogger()
logger.info("Custom logger logs are available in '/var/logs/oracle/bds/bootstrap/' directory of mn0 node")
logger.info("Execute get utility nodes ips")
utility_node_ips = helper.getUtilityNodesIps()
logger.info("Execute shell command on utility node")
helper.runShellCommandOnNode(command='pwd', host=utility_node_ips[0])
logger.info("Execute shell command for on-demand event type")
event_type = helper.getEventType()
if event_type == "on-demand":
helper.runShellCommandOnNode(command='ls', host=utility_node_ips[0])
logger.info("Create config group test in service HDFS")
helper.createConfigGroup(config_group="test", service_name="HDFS", hosts=[])
logger.info("Add Worker nodes as hosts to above created config group test in service HDFS")
worker_node_ips = helper.getWorkerNodesIps()
helper.addHostsInConfigGroup(service_name="HDFS", hosts=worker_node_ips, config_group="test")
logger.info("Update config_properties in the config group test of config_type file core-site in service HDFS")
helper.updateConfig(config_group="test", service_name="HDFS", config_type="core-site",
config_properties={"fs.trash.interval": "400"})
logger.info("Restart stale configs")
helper.restartStaleConfig()