Search in sources :

Example 21 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport in project hadoop by apache.

the class LogsCLI method fetchContainerLogs.

private int fetchContainerLogs(ContainerLogsRequest request, LogCLIHelpers logCliHelper, boolean useRegex) throws IOException, ClientHandlerException, UniformInterfaceException, JSONException {
    int resultCode = 0;
    String appIdStr = request.getAppId().toString();
    String containerIdStr = request.getContainerId();
    String nodeAddress = request.getNodeId();
    String appOwner = request.getAppOwner();
    boolean isAppFinished = request.isAppFinished();
    // we could directly get logs from HDFS.
    if (isAppFinished) {
        // to logCliHelper so that it fetches all the logs
        if (nodeAddress != null && !nodeAddress.isEmpty()) {
            return printContainerLogsForFinishedApplication(request, logCliHelper, useRegex);
        } else {
            return printContainerLogsForFinishedApplicationWithoutNodeId(request, logCliHelper, useRegex);
        }
    }
    String nodeHttpAddress = null;
    String nodeId = null;
    try {
        // If the nodeAddress is not provided, we will try to get
        // the ContainerReport. In the containerReport, we could get
        // nodeAddress and nodeHttpAddress
        ContainerReport report = getContainerReport(containerIdStr);
        nodeHttpAddress = report.getNodeHttpAddress();
        if (nodeHttpAddress != null && !nodeHttpAddress.isEmpty()) {
            nodeHttpAddress = nodeHttpAddress.replaceFirst(WebAppUtils.getHttpSchemePrefix(getConf()), "");
            request.setNodeHttpAddress(nodeHttpAddress);
        }
        nodeId = report.getAssignedNode().toString();
        request.setNodeId(nodeId);
        request.setContainerState(report.getContainerState());
    } catch (IOException | YarnException ex) {
        if (isAppFinished) {
            return printContainerLogsForFinishedApplicationWithoutNodeId(request, logCliHelper, useRegex);
        } else {
            nodeHttpAddress = getNodeHttpAddressFromRMWebString(request);
            if (nodeHttpAddress != null && !nodeHttpAddress.isEmpty()) {
                request.setNodeHttpAddress(nodeHttpAddress);
            } else {
                // for the case, we have already uploaded partial logs in HDFS
                int result = -1;
                if (nodeAddress != null && !nodeAddress.isEmpty()) {
                    result = printAggregatedContainerLogs(request, logCliHelper, useRegex);
                } else {
                    result = printAggregatedContainerLogsWithoutNodeId(request, logCliHelper, useRegex);
                }
                if (result == -1) {
                    System.err.println("Unable to get logs for this container:" + containerIdStr + " for the application:" + appIdStr + " with the appOwner: " + appOwner);
                    System.err.println("The application: " + appIdStr + " is still running, and we can not get Container report " + "for the container: " + containerIdStr + ". Please try later " + "or after the application finishes.");
                }
                return result;
            }
        }
    }
    // by calling NodeManager webservice.
    if (!isAppFinished) {
        resultCode = printContainerLogsFromRunningApplication(getConf(), request, logCliHelper, useRegex);
    } else {
        // If the application is in the final state, we will directly
        // get the container logs from HDFS.
        resultCode = printContainerLogsForFinishedApplication(request, logCliHelper, useRegex);
    }
    return resultCode;
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 22 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport in project hadoop by apache.

the class LogsCLI method showApplicationLogInfo.

private int showApplicationLogInfo(ContainerLogsRequest request, LogCLIHelpers logCliHelper) throws IOException, YarnException {
    String appState = "Application State: " + (request.isAppFinished() ? "Completed." : "Running.");
    if (!request.isAppFinished()) {
        List<ContainerReport> reports = getContainerReportsFromRunningApplication(request);
        List<ContainerReport> filterReports = filterContainersInfo(request, reports);
        if (filterReports.isEmpty()) {
            System.err.println("Can not find any containers for the application:" + request.getAppId() + ".");
            return -1;
        }
        outStream.println(appState);
        for (ContainerReport report : filterReports) {
            outStream.println(String.format(LogCLIHelpers.CONTAINER_ON_NODE_PATTERN, report.getContainerId(), report.getAssignedNode()));
        }
        return 0;
    } else {
        outStream.println(appState);
        logCliHelper.printContainersList(request, System.out, System.err);
        return 0;
    }
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport)

Example 23 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport in project hadoop by apache.

the class ApplicationCLI method printContainerReport.

/**
   * Prints the container report for an container id.
   * 
   * @param containerId
   * @return exitCode
   * @throws YarnException
   */
private int printContainerReport(String containerId) throws YarnException, IOException {
    ContainerReport containerReport = null;
    try {
        containerReport = client.getContainerReport(ContainerId.fromString(containerId));
    } catch (ApplicationNotFoundException e) {
        sysout.println("Application for Container with id '" + containerId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    } catch (ApplicationAttemptNotFoundException e) {
        sysout.println("Application Attempt for Container with id '" + containerId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    } catch (ContainerNotFoundException e) {
        sysout.println("Container with id '" + containerId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    }
    // Use PrintWriter.println, which uses correct platform line ending.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter containerReportStr = new PrintWriter(new OutputStreamWriter(baos, Charset.forName("UTF-8")));
    if (containerReport != null) {
        containerReportStr.println("Container Report : ");
        containerReportStr.print("\tContainer-Id : ");
        containerReportStr.println(containerReport.getContainerId());
        containerReportStr.print("\tStart-Time : ");
        containerReportStr.println(containerReport.getCreationTime());
        containerReportStr.print("\tFinish-Time : ");
        containerReportStr.println(containerReport.getFinishTime());
        containerReportStr.print("\tState : ");
        containerReportStr.println(containerReport.getContainerState());
        containerReportStr.print("\tLOG-URL : ");
        containerReportStr.println(containerReport.getLogUrl());
        containerReportStr.print("\tHost : ");
        containerReportStr.println(containerReport.getAssignedNode());
        containerReportStr.print("\tNodeHttpAddress : ");
        containerReportStr.println(containerReport.getNodeHttpAddress() == null ? "N/A" : containerReport.getNodeHttpAddress());
        containerReportStr.print("\tDiagnostics : ");
        containerReportStr.print(containerReport.getDiagnosticsInfo());
    } else {
        containerReportStr.print("Container with id '" + containerId + "' doesn't exist in Timeline Server.");
        containerReportStr.close();
        sysout.println(baos.toString("UTF-8"));
        return -1;
    }
    containerReportStr.close();
    sysout.println(baos.toString("UTF-8"));
    return 0;
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) PrintWriter(java.io.PrintWriter)

Example 24 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport in project hadoop by apache.

the class ApplicationCLI method listContainers.

/**
   * Lists the containers matching the given application attempts
   * 
   * @param appAttemptId
   * @throws YarnException
   * @throws IOException
   */
private void listContainers(String appAttemptId) throws YarnException, IOException {
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(sysout, Charset.forName("UTF-8")));
    List<ContainerReport> appsReport = client.getContainers(ApplicationAttemptId.fromString(appAttemptId));
    writer.println("Total number of containers " + ":" + appsReport.size());
    writer.printf(CONTAINER_PATTERN, "Container-Id", "Start Time", "Finish Time", "State", "Host", "Node Http Address", "LOG-URL");
    for (ContainerReport containerReport : appsReport) {
        writer.printf(CONTAINER_PATTERN, containerReport.getContainerId(), Times.format(containerReport.getCreationTime()), Times.format(containerReport.getFinishTime()), containerReport.getContainerState(), containerReport.getAssignedNode(), containerReport.getNodeHttpAddress() == null ? "N/A" : containerReport.getNodeHttpAddress(), containerReport.getLogUrl());
    }
    writer.flush();
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Example 25 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport in project hadoop by apache.

the class TestAHSClient method testGetContainers.

@Test(timeout = 10000)
public void testGetContainers() throws YarnException, IOException {
    Configuration conf = new Configuration();
    final AHSClient client = new MockAHSClient();
    client.init(conf);
    client.start();
    ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(applicationId, 1);
    List<ContainerReport> reports = client.getContainers(appAttemptId);
    Assert.assertNotNull(reports);
    Assert.assertEquals(reports.get(0).getContainerId(), (ContainerId.newContainerId(appAttemptId, 1)));
    Assert.assertEquals(reports.get(1).getContainerId(), (ContainerId.newContainerId(appAttemptId, 2)));
    client.stop();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) AHSClient(org.apache.hadoop.yarn.client.api.AHSClient) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Aggregations

ContainerReport (org.apache.hadoop.yarn.api.records.ContainerReport)36 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)16 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)16 Test (org.junit.Test)16 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)14 ArrayList (java.util.ArrayList)9 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)8 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)8 Configuration (org.apache.hadoop.conf.Configuration)7 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)5 ApplicationAttemptReport (org.apache.hadoop.yarn.api.records.ApplicationAttemptReport)5 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)5 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)5 ContainerInfo (org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo)5 PrintWriter (java.io.PrintWriter)4 GetContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest)4 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)4 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)4 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3