Search in sources :

Example 1 with ContainerReport

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

the class GetContainersResponsePBImpl method initLocalContainerList.

// Once this is called. containerList will never be null - until a getProto
// is called.
private void initLocalContainerList() {
    if (this.containerList != null) {
        return;
    }
    GetContainersResponseProtoOrBuilder p = viaProto ? proto : builder;
    List<ContainerReportProto> list = p.getContainersList();
    containerList = new ArrayList<ContainerReport>();
    for (ContainerReportProto c : list) {
        containerList.add(convertFromProtoFormat(c));
    }
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ContainerReportProto(org.apache.hadoop.yarn.proto.YarnProtos.ContainerReportProto) GetContainersResponseProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnServiceProtos.GetContainersResponseProtoOrBuilder)

Example 2 with ContainerReport

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

the class TestApplicationHistoryClientService method testContainers.

@Test
public void testContainers() throws IOException, YarnException {
    ApplicationId appId = ApplicationId.newInstance(0, 1);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1);
    ContainerId containerId1 = ContainerId.newContainerId(appAttemptId, 2);
    GetContainersRequest request = GetContainersRequest.newInstance(appAttemptId);
    GetContainersResponse response = clientService.getContainers(request);
    List<ContainerReport> containers = response.getContainerList();
    Assert.assertNotNull(containers);
    Assert.assertEquals(containerId, containers.get(0).getContainerId());
    Assert.assertEquals(containerId1, containers.get(1).getContainerId());
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) GetContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest) Test(org.junit.Test)

Example 3 with ContainerReport

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

the class TestApplicationHistoryClientService method testContainerReport.

@Test
public void testContainerReport() throws IOException, YarnException {
    ApplicationId appId = ApplicationId.newInstance(0, 1);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1);
    GetContainerReportRequest request = GetContainerReportRequest.newInstance(containerId);
    GetContainerReportResponse response = clientService.getContainerReport(request);
    ContainerReport container = response.getContainerReport();
    Assert.assertNotNull(container);
    Assert.assertEquals(containerId, container.getContainerId());
    Assert.assertEquals("http://0.0.0.0:8188/applicationhistory/logs/" + "test host:100/container_0_0001_01_000001/" + "container_0_0001_01_000001/user1", container.getLogUrl());
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) GetContainerReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetContainerReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest) Test(org.junit.Test)

Example 4 with ContainerReport

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

the class TestApplicationHistoryManagerOnTimelineStore method testGetContainers.

@Test
public void testGetContainers() throws Exception {
    final ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1);
    Collection<ContainerReport> containers;
    if (callerUGI == null) {
        containers = historyManager.getContainers(appAttemptId).values();
    } else {
        try {
            containers = callerUGI.doAs(new PrivilegedExceptionAction<Collection<ContainerReport>>() {

                @Override
                public Collection<ContainerReport> run() throws Exception {
                    return historyManager.getContainers(appAttemptId).values();
                }
            });
            if (callerUGI != null && callerUGI.getShortUserName().equals("user3")) {
                // The exception is expected
                Assert.fail();
            }
        } catch (AuthorizationException e) {
            if (callerUGI != null && callerUGI.getShortUserName().equals("user3")) {
                // The exception is expected
                return;
            }
            throw e;
        }
    }
    Assert.assertNotNull(containers);
    Assert.assertEquals(SCALE, containers.size());
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Test(org.junit.Test)

Example 5 with ContainerReport

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

the class LogsCLI method printContainerInfoFromRunningApplication.

private int printContainerInfoFromRunningApplication(ContainerLogsRequest options, LogCLIHelpers logCliHelper) throws YarnException, IOException, ClientHandlerException, UniformInterfaceException, JSONException {
    String containerIdStr = options.getContainerId();
    String nodeIdStr = options.getNodeId();
    List<ContainerReport> reports = getContainerReportsFromRunningApplication(options);
    List<ContainerReport> filteredReports = filterContainersInfo(options, reports);
    if (filteredReports.isEmpty()) {
        // if we specify the containerId as well as NodeAddress
        String nodeHttpAddress = null;
        if (options.getContainerId() != null && !options.getContainerId().isEmpty()) {
            nodeHttpAddress = getNodeHttpAddressFromRMWebString(options);
        }
        if (nodeHttpAddress != null) {
            outputContainerLogMeta(options.getContainerId(), options.getNodeId(), nodeHttpAddress);
            return 0;
        } else {
            int result = logCliHelper.printAContainerLogMetadata(options, System.out, System.err);
            if (result == -1) {
                StringBuilder sb = new StringBuilder();
                if (containerIdStr != null && !containerIdStr.isEmpty()) {
                    sb.append("Trying to get container with ContainerId: " + containerIdStr + "\n");
                }
                if (nodeIdStr != null && !nodeIdStr.isEmpty()) {
                    sb.append("Trying to get container from NodeManager: " + nodeIdStr + "\n");
                }
                sb.append("Can not find any matched containers for the application: " + options.getAppId());
                System.err.println(sb.toString());
            }
            return result;
        }
    }
    for (ContainerReport report : filteredReports) {
        String nodeId = report.getAssignedNode().toString();
        String nodeHttpAddress = report.getNodeHttpAddress().replaceFirst(WebAppUtils.getHttpSchemePrefix(getConf()), "");
        String containerId = report.getContainerId().toString();
        outputContainerLogMeta(containerId, nodeId, nodeHttpAddress);
    }
    return 0;
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport)

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