Search in sources :

Example 6 with GetContainerStatusesResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse in project hadoop by apache.

the class TestContainerManager method testContainerManagerInitialization.

@Test
public void testContainerManagerInitialization() throws IOException {
    containerManager.start();
    InetAddress localAddr = InetAddress.getLocalHost();
    String fqdn = localAddr.getCanonicalHostName();
    if (!localAddr.getHostAddress().equals(fqdn)) {
        // only check if fqdn is not same as ip
        // api returns ip in case of resolution failure
        Assert.assertEquals(fqdn, context.getNodeId().getHost());
    }
    // Just do a query for a non-existing container.
    boolean throwsException = false;
    try {
        List<ContainerId> containerIds = new ArrayList<>();
        ContainerId id = createContainerId(0);
        containerIds.add(id);
        GetContainerStatusesRequest request = GetContainerStatusesRequest.newInstance(containerIds);
        GetContainerStatusesResponse response = containerManager.getContainerStatuses(request);
        if (response.getFailedRequests().containsKey(id)) {
            throw response.getFailedRequests().get(id).deSerialize();
        }
    } catch (Throwable e) {
        throwsException = true;
    }
    Assert.assertTrue(throwsException);
}
Also used : GetContainerStatusesResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) GetContainerStatusesRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 7 with GetContainerStatusesResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse in project hadoop by apache.

the class TestContainerManager method testMultipleContainersStopAndGetStatus.

@Test
public void testMultipleContainersStopAndGetStatus() throws Exception {
    containerManager.start();
    List<StartContainerRequest> startRequest = new ArrayList<>();
    ContainerLaunchContext containerLaunchContext = recordFactory.newRecordInstance(ContainerLaunchContext.class);
    List<ContainerId> containerIds = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        ContainerId cId;
        if ((i & 1) == 0) {
            // Containers with even id belong to an unauthorized app
            cId = createContainerId(i, 1);
        } else {
            cId = createContainerId(i, 0);
        }
        Token containerToken = createContainerToken(cId, DUMMY_RM_IDENTIFIER, context.getNodeId(), user, context.getContainerTokenSecretManager());
        StartContainerRequest request = StartContainerRequest.newInstance(containerLaunchContext, containerToken);
        startRequest.add(request);
        containerIds.add(cId);
    }
    // start containers
    StartContainersRequest requestList = StartContainersRequest.newInstance(startRequest);
    containerManager.startContainers(requestList);
    Thread.sleep(5000);
    // Get container statuses
    GetContainerStatusesRequest statusRequest = GetContainerStatusesRequest.newInstance(containerIds);
    GetContainerStatusesResponse statusResponse = containerManager.getContainerStatuses(statusRequest);
    Assert.assertEquals(5, statusResponse.getContainerStatuses().size());
    for (ContainerStatus status : statusResponse.getContainerStatuses()) {
        // Containers with odd id should succeed
        Assert.assertEquals(1, status.getContainerId().getContainerId() & 1);
    }
    Assert.assertEquals(5, statusResponse.getFailedRequests().size());
    for (Map.Entry<ContainerId, SerializedException> entry : statusResponse.getFailedRequests().entrySet()) {
        // Containers with even id should fail.
        Assert.assertEquals(0, entry.getKey().getContainerId() & 1);
        Assert.assertTrue(entry.getValue().getMessage().contains("attempted to get status for non-application container"));
    }
    // stop containers
    StopContainersRequest stopRequest = StopContainersRequest.newInstance(containerIds);
    StopContainersResponse stopResponse = containerManager.stopContainers(stopRequest);
    Assert.assertEquals(5, stopResponse.getSuccessfullyStoppedContainers().size());
    for (ContainerId id : stopResponse.getSuccessfullyStoppedContainers()) {
        // Containers with odd id should succeed.
        Assert.assertEquals(1, id.getContainerId() & 1);
    }
    Assert.assertEquals(5, stopResponse.getFailedRequests().size());
    for (Map.Entry<ContainerId, SerializedException> entry : stopResponse.getFailedRequests().entrySet()) {
        // Containers with even id should fail.
        Assert.assertEquals(0, entry.getKey().getContainerId() & 1);
        Assert.assertTrue(entry.getValue().getMessage().contains("attempted to stop non-application container"));
    }
}
Also used : StartContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest) GetContainerStatusesRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest) SerializedException(org.apache.hadoop.yarn.api.records.SerializedException) ArrayList(java.util.ArrayList) Token(org.apache.hadoop.yarn.api.records.Token) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) StartContainerRequest(org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest) GetContainerStatusesResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Map(java.util.Map) HashMap(java.util.HashMap) StopContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest) StopContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.StopContainersResponse) Test(org.junit.Test)

Aggregations

GetContainerStatusesResponse (org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse)7 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)7 ArrayList (java.util.ArrayList)6 GetContainerStatusesRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest)5 ContainerManagementProtocol (org.apache.hadoop.yarn.api.ContainerManagementProtocol)3 StartContainerRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest)3 StartContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest)3 StopContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest)3 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)3 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)3 Token (org.apache.hadoop.yarn.api.records.Token)3 ContainerTokenIdentifier (org.apache.hadoop.yarn.security.ContainerTokenIdentifier)3 Test (org.junit.Test)3 StopContainersResponse (org.apache.hadoop.yarn.api.protocolrecords.StopContainersResponse)2 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 NodeId (org.apache.hadoop.yarn.api.records.NodeId)2 Resource (org.apache.hadoop.yarn.api.records.Resource)2 YarnRPC (org.apache.hadoop.yarn.ipc.YarnRPC)2 IOException (java.io.IOException)1