def set_presto_node_state(cluster_ip, node_ip, state): cmd = ("sudo sed -i 's/http-server.threads.max=.*/http-server.threads.max=%s/g' " + "/etc/presto/conf/config.properties") % INVALID_CONFIG_VALUE out = run_ssh(cmd, cluster_ip, user='******', via_hosts=[node_ip], cache_duration_secs=QUERY_CACHE_TIMEOUT) cmd = ("curl -s --connect-timeout %s -X PUT -H 'Content-Type:application/json' " + "-d '\\\"%s\\\"' http://%s:8889/v1/info/state") % (CURL_CONNECT_TIMEOUT, state, node_ip) LOG.info(cmd) out = run_ssh(cmd, cluster_ip, user='******', cache_duration_secs=QUERY_CACHE_TIMEOUT) out = re.sub(r'\s*"(.+)"\s*', r'\1', out) return out
def set_presto_node_state(cluster_ip, node_ip, state): cmd = ("sudo sed -i 's/http-server.threads.max=.*/http-server.threads.max=%s/g' " + "/etc/presto/conf/config.properties") % INVALID_CONFIG_VALUE if not is_ip_address(cluster_ip): cluster_ip = hostname_to_ip(cluster_ip) out = run_ssh(cmd, cluster_ip, user='******', via_hosts=[node_ip], cache_duration_secs=QUERY_CACHE_TIMEOUT) cmd = ("curl -s --connect-timeout %s -X PUT -H 'Content-Type:application/json' " + "-d '\\\"%s\\\"' http://%s:8889/v1/info/state") % (CURL_CONNECT_TIMEOUT, state, node_ip) LOG.info(cmd) out = run_ssh(cmd, cluster_ip, user='******', cache_duration_secs=QUERY_CACHE_TIMEOUT) out = re.sub(r'\s*"(.+)"\s*', r'\1', out) return out
def get_node_queries(cluster_ip): cmd = ('presto-cli --execute \\"SELECT n.http_uri,count(q.node_id) from system.runtime.nodes n ' + 'left join (select * from system.runtime.queries where state = \'RUNNING\' ) as q ' + 'on q.node_id = n.node_id group by n.http_uri\\"') result = {} if cluster_ip == 'localhost': # for testing purposes return result # run ssh command out = run_ssh(cmd, cluster_ip, user='******', cache_duration_secs=QUERY_CACHE_TIMEOUT) # remove SSH log output line out = remove_lines_from_string(out, r'.*Permanently added.*') for line in out.splitlines(): ip = re.sub(r'.*http://([0-9\.]+):.*', r'\1', line) if ip: queries = re.sub(r'.*"([0-9\.]+)"$', r'\1', line) host = aws_common.ip_to_hostname(ip) try: result[host] = int(queries) except Exception, e: result[host] = 0
def get_node_queries(cluster): cmd = ('presto-cli --execute \\"SELECT n.http_uri,count(q.node_id) from system.runtime.nodes n ' + 'left join (select * from system.runtime.queries where state = \'RUNNING\' ) as q ' + 'on q.node_id = n.node_id group by n.http_uri\\"') result = {} if cluster.ip == 'localhost': # for testing purposes return result # run ssh command out = run_ssh(cmd, cluster.ip, user='******', cache_duration_secs=QUERY_CACHE_TIMEOUT) # remove SSH log output line out = remove_lines_from_string(out, r'.*Permanently added.*') # read config for domain custom_dn = config.get_value(constants.KEY_CUSTOM_DOMAIN_NAME, section=SECTION_EMR, resource=cluster.id) # assume input is actually domain name (not ip) dn = custom_dn if custom_dn else re.match(r'ip-[^\.]+\.(.+)', cluster.ip).group(1) for line in out.splitlines(): ip = re.sub(r'.*http://([0-9\.]+):.*', r'\1', line) if ip: queries = re.sub(r'.*"([0-9\.]+)"$', r'\1', line) host = aws_common.ip_to_hostname(ip, dn) try: result[host] = int(queries) except Exception, e: result[host] = 0
def get_presto_node_state(cluster_ip, node_ip): cmd = ('curl -s --connect-timeout %s --max-time %s http://%s:8889/v1/info/state' % (CURL_CONNECT_TIMEOUT, CURL_CONNECT_TIMEOUT, node_ip)) out = run_ssh(cmd, cluster_ip, user='******', cache_duration_secs=QUERY_CACHE_TIMEOUT) out = remove_lines_from_string(out, r'.*Permanently added.*') out = re.sub(r'\s*"(.+)"\s*', r'\1', out) return out
def terminate_inactive_nodes(cluster_ip, nodes): for key, node in nodes.iteritems(): if (node['state'] == INSTANCE_STATE_RUNNING and node['presto_state'] not in [PRESTO_STATE_SHUTTING_DOWN, PRESTO_STATE_ACTIVE]): try: cmd = "cat /etc/presto/conf/config.properties | grep http-server.threads" out = run_ssh(cmd, cluster_ip, user='******', via_hosts=[node['host']], cache_duration_secs=QUERY_CACHE_TIMEOUT) if INVALID_CONFIG_VALUE in out: LOG.info("Terminating instance of idle node %s in instance group %s" % (node['iid'], node['gid'])) terminate_task_node(node['gid'], node['iid']) except Exception, e: LOG.info("Unable to read Presto config from node %s: %s" % (node, e))
def terminate_inactive_nodes(cluster, cluster_state, role=None): if not is_presto_cluster(cluster): return nodes = cluster_state['nodes'] for key, node in nodes.iteritems(): if (node['state'] == INSTANCE_STATE_RUNNING and node['presto_state'] not in [PRESTO_STATE_SHUTTING_DOWN, PRESTO_STATE_ACTIVE]): try: cmd = "cat /etc/presto/conf/config.properties | grep http-server.threads" out = run_ssh(cmd, cluster.ip, user='******', via_hosts=[node['host']], cache_duration_secs=QUERY_CACHE_TIMEOUT) if INVALID_CONFIG_VALUE in out: LOG.info("Terminating instance of idle node %s in instance group %s" % (node['iid'], node['gid'])) terminate_task_node(instance_group_id=node['gid'], instance_id=node['iid'], role=role) except Exception, e: LOG.info("Unable to read Presto config from node %s: %s" % (node, e))