Search in sources :

Example 11 with SerializedException

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

the class TestContainerManager method testMultipleContainersLaunch.

@Test
public void testMultipleContainersLaunch() throws Exception {
    containerManager.start();
    List<StartContainerRequest> list = new ArrayList<>();
    ContainerLaunchContext containerLaunchContext = recordFactory.newRecordInstance(ContainerLaunchContext.class);
    for (int i = 0; i < 10; i++) {
        ContainerId cId = createContainerId(i);
        long identifier = 0;
        if ((i & 1) == 0)
            // container with even id fail
            identifier = ResourceManagerConstants.RM_INVALID_IDENTIFIER;
        else
            identifier = DUMMY_RM_IDENTIFIER;
        Token containerToken = createContainerToken(cId, identifier, context.getNodeId(), user, context.getContainerTokenSecretManager());
        StartContainerRequest request = StartContainerRequest.newInstance(containerLaunchContext, containerToken);
        list.add(request);
    }
    StartContainersRequest requestList = StartContainersRequest.newInstance(list);
    StartContainersResponse response = containerManager.startContainers(requestList);
    Thread.sleep(5000);
    Assert.assertEquals(5, response.getSuccessfullyStartedContainers().size());
    for (ContainerId id : response.getSuccessfullyStartedContainers()) {
        // Containers with odd id should succeed.
        Assert.assertEquals(1, id.getContainerId() & 1);
    }
    Assert.assertEquals(5, response.getFailedRequests().size());
    for (Map.Entry<ContainerId, SerializedException> entry : response.getFailedRequests().entrySet()) {
        // Containers with even id should fail.
        Assert.assertEquals(0, entry.getKey().getContainerId() & 1);
        Assert.assertTrue(entry.getValue().getMessage().contains("Container " + entry.getKey() + " rejected as it is allocated by a previous RM"));
    }
}
Also used : StartContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest) StartContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse) 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) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 12 with SerializedException

use of org.apache.hadoop.yarn.api.records.SerializedException 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)

Example 13 with SerializedException

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

the class GetContainerStatusesResponsePBImpl method initFailedRequests.

private void initFailedRequests() {
    if (this.failedRequests != null) {
        return;
    }
    GetContainerStatusesResponseProtoOrBuilder p = viaProto ? proto : builder;
    List<ContainerExceptionMapProto> protoList = p.getFailedRequestsList();
    this.failedRequests = new HashMap<ContainerId, SerializedException>();
    for (ContainerExceptionMapProto ce : protoList) {
        this.failedRequests.put(convertFromProtoFormat(ce.getContainerId()), convertFromProtoFormat(ce.getException()));
    }
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) GetContainerStatusesResponseProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnServiceProtos.GetContainerStatusesResponseProtoOrBuilder) ContainerExceptionMapProto(org.apache.hadoop.yarn.proto.YarnServiceProtos.ContainerExceptionMapProto) SerializedException(org.apache.hadoop.yarn.api.records.SerializedException)

Example 14 with SerializedException

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

the class StartContainersResponsePBImpl method initFailedContainers.

private void initFailedContainers() {
    if (this.failedContainers != null) {
        return;
    }
    StartContainersResponseProtoOrBuilder p = viaProto ? proto : builder;
    List<ContainerExceptionMapProto> protoList = p.getFailedRequestsList();
    this.failedContainers = new HashMap<ContainerId, SerializedException>();
    for (ContainerExceptionMapProto ce : protoList) {
        this.failedContainers.put(convertFromProtoFormat(ce.getContainerId()), convertFromProtoFormat(ce.getException()));
    }
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) StartContainersResponseProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnServiceProtos.StartContainersResponseProtoOrBuilder) ContainerExceptionMapProto(org.apache.hadoop.yarn.proto.YarnServiceProtos.ContainerExceptionMapProto) SerializedException(org.apache.hadoop.yarn.api.records.SerializedException)

Example 15 with SerializedException

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

the class IncreaseContainersResourceResponsePBImpl method initFailedRequests.

private void initFailedRequests() {
    if (this.failedRequests != null) {
        return;
    }
    IncreaseContainersResourceResponseProtoOrBuilder p = viaProto ? proto : builder;
    List<ContainerExceptionMapProto> protoList = p.getFailedRequestsList();
    this.failedRequests = new HashMap<ContainerId, SerializedException>();
    for (ContainerExceptionMapProto ce : protoList) {
        this.failedRequests.put(convertFromProtoFormat(ce.getContainerId()), convertFromProtoFormat(ce.getException()));
    }
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) IncreaseContainersResourceResponseProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnServiceProtos.IncreaseContainersResourceResponseProtoOrBuilder) ContainerExceptionMapProto(org.apache.hadoop.yarn.proto.YarnServiceProtos.ContainerExceptionMapProto) SerializedException(org.apache.hadoop.yarn.api.records.SerializedException)

Aggregations

SerializedException (org.apache.hadoop.yarn.api.records.SerializedException)15 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)7 StartContainerRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest)6 StartContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest)5 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 Map (java.util.Map)4 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)4 Token (org.apache.hadoop.yarn.api.records.Token)4 ContainerExceptionMapProto (org.apache.hadoop.yarn.proto.YarnServiceProtos.ContainerExceptionMapProto)4 NMTokenIdentifier (org.apache.hadoop.yarn.security.NMTokenIdentifier)4 StartContainersResponse (org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse)3 InvalidToken (org.apache.hadoop.security.token.SecretManager.InvalidToken)2 IncreaseContainersResourceRequest (org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceRequest)2 IncreaseContainersResourceResponse (org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceResponse)2 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)2