In a Hadoop cluster besides Active nodes you may also have Unhealthy, Lost and Decommissioned nodes. Unhealthy nodes are running but just excluded from scheduling the tasks because they, for example, do not have enough disk space. Lost nodes are nodes that are not reachable anymore. The decommissioned nodes are nodes that successfully terminated and left the cluster.
But all these nodes are known to the Hadoop YARN cluster and you can see their details such as IP addresses, last health updates and so on.
At the same time there can be also Ghost nodes i.e. nodes that are running by Amazon EMR services but Hadoop itself does not know anything about their existence. Let’s see how you can find them.
In one Hadoop cluster I noticed that it is configured to run 110 nodes, while Hadoop YARN ResourceManager shows only 103 nodes, so 7 modes are missing.
You can use the following Python code to get a list of Amazon EMR nodes in your cluster:
import sys import subprocess import json cluster_id = 'set your cluster ID here' emr_nodes_list = [] emr_nodes = subprocess.check_output("aws emr list-instances --cluster-id=" + cluster_id, shell = True) for i in json.loads(emr_nodes)["Instances"]: emr_node = { "State" : i["Status"]["State"], "Ec2InstanceId": i["Ec2InstanceId"], "PrivateDnsName": i["PrivateDnsName"] } emr_nodes_list.append(emr_node)
Sample content:
[{'PrivateDnsName': 'ip-10-93-17-215.ec2.internal', 'State': u'RUNNING', 'Ec2InstanceId': 'i-0518'}, {'PrivateDnsName': 'ip-10-93-18-101.ec2.internal', 'State': u'RUNNING', 'Ec2InstanceId': 'i-0866'}, ... {'PrivateDnsName': 'ip-10-93-20-69.ec2.internal', 'State': u'RUNNING', 'Ec2InstanceId': 'i-03b6'}]
Then you can get a list of Hadoop YARN nodes:
import requests cluster_ip = 'set your cluster IP here' yarn_nodes = {} for i in requests.get('http://' + cluster_ip + ':8088/ws/v1/cluster/nodes').json()["nodes"]["node"]: yarn_nodes[i["nodeHostName"]] = i["state"]
Sample content:
{'ip-10-93-17-215.ec2.internal': 'RUNNING', 'ip-10-93-18-101.ec2.internal': 'RUNNING', ... 'ip-10-93-20-69.ec2.internal': 'RUNNING'}
And finally you can intersect these 2 structures to get a list of nodes that are in Amazon EMR but not in Hadoop YARN:
for i in emr_nodes_list: if i["PrivateDnsName"] not in yarn_nodes: print i
If there are no ghost nodes in your cluster, the last script should output only the master node IP and its state.
If you find ghost nodes, you should try to bring them back to the cluster.
First, take their IPs and try to connect to them using SSH. Most likely they are not reachable so you have to reboot them using Ec2InstanceId
. You can do that from the AWS Management Console or command line.
Then, in many cases after a reboot nodes become Active in Hadoop YARN. If it does not happen try to connect to them, check disk space, and the status of EMR and Hadoop services.