Search in sources :

Example 46 with YarnClient

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

the class YarnTokenUtils method obtainToken.

/**
   * Gets a Yarn delegation token and stores it in the given Credentials.
   *
   * @return the same Credentials instance as the one given in parameter.
   */
public static Credentials obtainToken(YarnConfiguration configuration, Credentials credentials) {
    if (!UserGroupInformation.isSecurityEnabled()) {
        return credentials;
    }
    try {
        YarnClient yarnClient = YarnClient.createYarnClient();
        yarnClient.init(configuration);
        yarnClient.start();
        try {
            Text renewer = new Text(UserGroupInformation.getCurrentUser().getShortUserName());
            org.apache.hadoop.yarn.api.records.Token rmDelegationToken = yarnClient.getRMDelegationToken(renewer);
            // TODO: The following logic should be replaced with call to ClientRMProxy.getRMDelegationTokenService after
            // CDAP-4825 is resolved
            List<String> services = new ArrayList<>();
            if (HAUtil.isHAEnabled(configuration)) {
                // If HA is enabled, we need to enumerate all RM hosts
                // and add the corresponding service name to the token service
                // Copy the yarn conf since we need to modify it to get the RM addresses
                YarnConfiguration yarnConf = new YarnConfiguration(configuration);
                for (String rmId : HAUtil.getRMHAIds(configuration)) {
                    yarnConf.set(YarnConfiguration.RM_HA_ID, rmId);
                    InetSocketAddress address = yarnConf.getSocketAddr(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS, YarnConfiguration.DEFAULT_RM_PORT);
                    services.add(SecurityUtil.buildTokenService(address).toString());
                }
            } else {
                services.add(SecurityUtil.buildTokenService(YarnUtils.getRMAddress(configuration)).toString());
            }
            Token<TokenIdentifier> token = ConverterUtils.convertFromYarn(rmDelegationToken, null);
            token.setService(new Text(Joiner.on(',').join(services)));
            credentials.addToken(new Text(token.getService()), token);
            // OK to log, it won't log the credential, only information about the token.
            LOG.debug("Added RM delegation token: {}", token);
        } finally {
            yarnClient.stop();
        }
        return credentials;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration)

Example 47 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 48 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 49 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)

Example 50 with YarnClient

use of org.apache.hadoop.yarn.client.api.YarnClient in project h2o-3 by h2oai.

the class H2OYarnDiagnostic method run.

private void run() throws IOException, YarnException {
    YarnClient yarnClient;
    yarnClient = YarnClient.createYarnClient();
    yarnClient.init(conf);
    yarnClient.start();
    List<NodeReport> clusterNodeReports = yarnClient.getNodeReports();
    List<QueueInfo> rootQueues = yarnClient.getRootQueueInfos();
    QueueInfo queueInfo = yarnClient.getQueueInfo(this.queueName);
    if (queueInfo == null) {
        printErrorDiagnosis("Queue not found (" + this.queueName + ")");
        return;
    }
    System.out.println("");
    printYarnClusterMetrics(yarnClient);
    System.out.println("");
    printClusterNodeReports(clusterNodeReports);
    System.out.println("");
    printQueueInfo(queueInfo);
    System.out.println("");
    printQueueCapacity(clusterNodeReports, queueInfo, rootQueues);
    System.out.println("");
    printDiagnosis(clusterNodeReports);
}
Also used : YarnClient(org.apache.hadoop.yarn.client.api.YarnClient)

Aggregations

YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)89 Test (org.junit.Test)51 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)50 Configuration (org.apache.hadoop.conf.Configuration)45 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)37 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)21 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 Path (org.apache.hadoop.fs.Path)13 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)13 FileSystem (org.apache.hadoop.fs.FileSystem)11 Matchers.anyString (org.mockito.Matchers.anyString)11 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