Search in sources :

Example 6 with UpdatedContainer

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

the class TestContainerResizing method verifyContainerIncreased.

private void verifyContainerIncreased(AllocateResponse response, ContainerId containerId, int mem) {
    List<UpdatedContainer> increasedContainers = response.getUpdatedContainers();
    boolean found = false;
    for (UpdatedContainer c : increasedContainers) {
        if (c.getContainer().getId().equals(containerId)) {
            found = true;
            Assert.assertEquals(ContainerUpdateType.INCREASE_RESOURCE, c.getUpdateType());
            Assert.assertEquals(mem, c.getContainer().getResource().getMemorySize());
        }
    }
    if (!found) {
        Assert.fail("Container not increased: containerId=" + containerId);
    }
}
Also used : UpdatedContainer(org.apache.hadoop.yarn.api.records.UpdatedContainer)

Example 7 with UpdatedContainer

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

the class TestContainerResizing method verifyContainerDecreased.

private void verifyContainerDecreased(AllocateResponse response, ContainerId containerId, int mem) {
    List<UpdatedContainer> decreasedContainers = response.getUpdatedContainers();
    boolean found = false;
    for (UpdatedContainer c : decreasedContainers) {
        if (c.getContainer().getId().equals(containerId)) {
            found = true;
            Assert.assertEquals(ContainerUpdateType.DECREASE_RESOURCE, c.getUpdateType());
            Assert.assertEquals(mem, c.getContainer().getResource().getMemorySize());
        }
    }
    if (!found) {
        Assert.fail("Container not decreased: containerId=" + containerId);
    }
}
Also used : UpdatedContainer(org.apache.hadoop.yarn.api.records.UpdatedContainer)

Example 8 with UpdatedContainer

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

the class TestAMRMClientAsync method createAllocateResponse.

private AllocateResponse createAllocateResponse(List<ContainerStatus> completed, List<Container> allocated, List<Container> increased, List<Container> decreased, List<NMToken> nmTokens) {
    List<UpdatedContainer> updatedContainers = new ArrayList<>();
    for (Container c : increased) {
        updatedContainers.add(UpdatedContainer.newInstance(ContainerUpdateType.INCREASE_RESOURCE, c));
    }
    for (Container c : decreased) {
        updatedContainers.add(UpdatedContainer.newInstance(ContainerUpdateType.DECREASE_RESOURCE, c));
    }
    AllocateResponse response = AllocateResponse.newInstance(0, completed, allocated, new ArrayList<NodeReport>(), null, null, 1, null, nmTokens, updatedContainers);
    return response;
}
Also used : AllocateResponse(org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse) UpdatedContainer(org.apache.hadoop.yarn.api.records.UpdatedContainer) Container(org.apache.hadoop.yarn.api.records.Container) UpdatedContainer(org.apache.hadoop.yarn.api.records.UpdatedContainer) ArrayList(java.util.ArrayList) NodeReport(org.apache.hadoop.yarn.api.records.NodeReport)

Example 9 with UpdatedContainer

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

the class TestOpportunisticContainerAllocation method testDemotionFromAcquired.

@Test(timeout = 60000)
public void testDemotionFromAcquired() throws YarnException, IOException {
    // setup container request
    assertEquals(0, amClient.ask.size());
    assertEquals(0, amClient.release.size());
    amClient.addContainerRequest(new AMRMClient.ContainerRequest(capability, null, null, priority3));
    int guarContainersRequestedAny = amClient.getTable(0).get(priority3, ResourceRequest.ANY, ExecutionType.GUARANTEED, capability).remoteRequest.getNumContainers();
    assertEquals(1, guarContainersRequestedAny);
    assertEquals(1, amClient.ask.size());
    assertEquals(0, amClient.release.size());
    // RM should allocate container within 2 calls to allocate()
    int allocatedContainerCount = 0;
    Map<ContainerId, Container> allocatedGuarContainers = new HashMap<>();
    int iterationsLeft = 50;
    amClient.getNMTokenCache().clearCache();
    Assert.assertEquals(0, amClient.getNMTokenCache().numberOfTokensInCache());
    HashMap<String, Token> receivedNMTokens = new HashMap<>();
    updateMetrics("Before Guar Allocation");
    while (allocatedContainerCount < guarContainersRequestedAny && iterationsLeft-- > 0) {
        AllocateResponse allocResponse = amClient.allocate(0.1f);
        assertEquals(0, amClient.ask.size());
        assertEquals(0, amClient.release.size());
        allocatedContainerCount += allocResponse.getAllocatedContainers().size();
        for (Container container : allocResponse.getAllocatedContainers()) {
            if (container.getExecutionType() == ExecutionType.GUARANTEED) {
                allocatedGuarContainers.put(container.getId(), container);
                removeCR(container);
            }
        }
        for (NMToken token : allocResponse.getNMTokens()) {
            String nodeID = token.getNodeId().toString();
            receivedNMTokens.put(nodeID, token.getToken());
        }
        if (allocatedContainerCount < guarContainersRequestedAny) {
            // sleep to let NM's heartbeat to RM and trigger allocations
            sleep(100);
        }
    }
    assertEquals(guarContainersRequestedAny, allocatedContainerCount);
    assertEquals(guarContainersRequestedAny, allocatedGuarContainers.size());
    updateMetrics("After Guar Allocation / Before Demotion");
    try {
        Container c = allocatedGuarContainers.values().iterator().next();
        amClient.requestContainerUpdate(c, UpdateContainerRequest.newInstance(c.getVersion(), c.getId(), ContainerUpdateType.DEMOTE_EXECUTION_TYPE, null, ExecutionType.GUARANTEED));
        Assert.fail("Should throw Exception..");
    } catch (IllegalArgumentException e) {
        System.out.println("## " + e.getMessage());
        Assert.assertTrue(e.getMessage().contains("target should be OPPORTUNISTIC and original should be GUARANTEED"));
    }
    Container c = allocatedGuarContainers.values().iterator().next();
    amClient.requestContainerUpdate(c, UpdateContainerRequest.newInstance(c.getVersion(), c.getId(), ContainerUpdateType.DEMOTE_EXECUTION_TYPE, null, ExecutionType.OPPORTUNISTIC));
    iterationsLeft = 120;
    Map<ContainerId, UpdatedContainer> updatedContainers = new HashMap<>();
    // do a few iterations to ensure RM is not going to send new containers
    while (iterationsLeft-- > 0 && updatedContainers.isEmpty()) {
        // inform RM of rejection
        AllocateResponse allocResponse = amClient.allocate(0.1f);
        // RM did not send new containers because AM does not need any
        if (allocResponse.getUpdatedContainers() != null) {
            for (UpdatedContainer updatedContainer : allocResponse.getUpdatedContainers()) {
                System.out.println("Got update..");
                updatedContainers.put(updatedContainer.getContainer().getId(), updatedContainer);
            }
        }
        if (iterationsLeft > 0) {
            // sleep to make sure NM's heartbeat
            sleep(100);
        }
    }
    updateMetrics("After Demotion");
    assertEquals(1, updatedContainers.size());
    for (ContainerId cId : allocatedGuarContainers.keySet()) {
        Container orig = allocatedGuarContainers.get(cId);
        UpdatedContainer updatedContainer = updatedContainers.get(cId);
        assertNotNull(updatedContainer);
        assertEquals(ExecutionType.OPPORTUNISTIC, updatedContainer.getContainer().getExecutionType());
        assertEquals(orig.getResource(), updatedContainer.getContainer().getResource());
        assertEquals(orig.getNodeId(), updatedContainer.getContainer().getNodeId());
        assertEquals(orig.getVersion() + 1, updatedContainer.getContainer().getVersion());
    }
    assertEquals(0, amClient.ask.size());
    assertEquals(0, amClient.release.size());
    amClient.ask.clear();
}
Also used : AMRMClient(org.apache.hadoop.yarn.client.api.AMRMClient) NMToken(org.apache.hadoop.yarn.api.records.NMToken) HashMap(java.util.HashMap) NMToken(org.apache.hadoop.yarn.api.records.NMToken) Token(org.apache.hadoop.yarn.api.records.Token) AllocateResponse(org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse) UpdatedContainer(org.apache.hadoop.yarn.api.records.UpdatedContainer) Container(org.apache.hadoop.yarn.api.records.Container) UpdatedContainer(org.apache.hadoop.yarn.api.records.UpdatedContainer) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Test(org.junit.Test)

Aggregations

UpdatedContainer (org.apache.hadoop.yarn.api.records.UpdatedContainer)9 Container (org.apache.hadoop.yarn.api.records.Container)6 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)5 ArrayList (java.util.ArrayList)4 AllocateResponse (org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse)4 HashMap (java.util.HashMap)3 NMToken (org.apache.hadoop.yarn.api.records.NMToken)3 Token (org.apache.hadoop.yarn.api.records.Token)3 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)2 NodeReport (org.apache.hadoop.yarn.api.records.NodeReport)2 ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)2 AMRMClient (org.apache.hadoop.yarn.client.api.AMRMClient)2 Test (org.junit.Test)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 AllocateRequest (org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest)1 NodeId (org.apache.hadoop.yarn.api.records.NodeId)1 PreemptionContainer (org.apache.hadoop.yarn.api.records.PreemptionContainer)1 ResourceBlacklistRequest (org.apache.hadoop.yarn.api.records.ResourceBlacklistRequest)1