Search in sources :

Example 86 with YarnClient

use of org.apache.hadoop.yarn.client.api.YarnClient in project cdap by caskdata.

the class YarnNodes method collect.

@Override
public synchronized void collect() throws Exception {
    reset();
    List<NodeReport> nodeReports;
    YarnClient yarnClient = createYARNClient();
    try {
        nodeReports = yarnClient.getNodeReports();
    } finally {
        yarnClient.stop();
    }
    for (NodeReport nodeReport : nodeReports) {
        switch(nodeReport.getNodeState()) {
            case RUNNING:
                healthyNodes++;
                healthyContainers += nodeReport.getNumContainers();
                break;
            case UNHEALTHY:
            case DECOMMISSIONED:
            case LOST:
                unusableNodes++;
                unusableContainers += nodeReport.getNumContainers();
                break;
            case NEW:
            case REBOOTED:
                newNodes++;
                newContainers += nodeReport.getNumContainers();
                break;
        }
    }
}
Also used : NodeReport(org.apache.hadoop.yarn.api.records.NodeReport) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient)

Example 87 with YarnClient

use of org.apache.hadoop.yarn.client.api.YarnClient in project cdap by caskdata.

the class YarnQueues method collect.

@Override
public synchronized void collect() throws Exception {
    reset();
    List<QueueInfo> queues;
    YarnClient yarnClient = createYARNClient();
    try {
        queues = yarnClient.getAllQueues();
    } finally {
        yarnClient.stop();
    }
    for (QueueInfo queue : queues) {
        switch(queue.getQueueState()) {
            case RUNNING:
                running++;
                break;
            case STOPPED:
                stopped++;
                break;
        }
    }
}
Also used : QueueInfo(org.apache.hadoop.yarn.api.records.QueueInfo) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient)

Example 88 with YarnClient

use of org.apache.hadoop.yarn.client.api.YarnClient in project cdap by caskdata.

the class YarnResources method collect.

@Override
public synchronized void collect() throws Exception {
    reset();
    List<NodeReport> nodeReports;
    YarnClient yarnClient = createYARNClient();
    try {
        nodeReports = yarnClient.getNodeReports();
    } finally {
        yarnClient.stop();
    }
    for (NodeReport nodeReport : nodeReports) {
        NodeId nodeId = nodeReport.getNodeId();
        LOG.debug("Got report for node {}", nodeId);
        if (!nodeReport.getNodeState().isUnusable()) {
            Resource nodeCapability = nodeReport.getCapability();
            Resource nodeUsed = nodeReport.getUsed();
            // some versions of hadoop return null, others do not
            if (nodeCapability != null) {
                LOG.debug("node {} resource capability: memory = {}, vcores = {}", nodeId, nodeCapability.getMemory(), nodeCapability.getVirtualCores());
                totalMemory += nodeCapability.getMemory();
                totalVCores += nodeCapability.getVirtualCores();
            }
            if (nodeUsed != null) {
                LOG.debug("node {} resources used: memory = {}, vcores = {}", nodeId, nodeUsed.getMemory(), nodeUsed.getVirtualCores());
                usedMemory += nodeUsed.getMemory();
                usedVCores += nodeUsed.getVirtualCores();
            }
        }
    }
}
Also used : NodeId(org.apache.hadoop.yarn.api.records.NodeId) Resource(org.apache.hadoop.yarn.api.records.Resource) NodeReport(org.apache.hadoop.yarn.api.records.NodeReport) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient)

Aggregations

YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)88 Test (org.junit.Test)51 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)49 Configuration (org.apache.hadoop.conf.Configuration)44 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)37 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)20 CapacitySchedulerConfiguration (org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration)18 IOException (java.io.IOException)17 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)15 MiniYARNCluster (org.apache.hadoop.yarn.server.MiniYARNCluster)15 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)13 Path (org.apache.hadoop.fs.Path)12 Matchers.anyString (org.mockito.Matchers.anyString)11 FileSystem (org.apache.hadoop.fs.FileSystem)10 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)9 NodeId (org.apache.hadoop.yarn.api.records.NodeId)9 ArrayList (java.util.ArrayList)8 LocalFileSystem (org.apache.hadoop.fs.LocalFileSystem)8 ReservationSubmissionRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)7