Search in sources :

Example 6 with UpdateContainerRequest

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

the class TestContainerResizing method testOrderOfIncreaseContainerRequestAllocation.

@Test
public void testOrderOfIncreaseContainerRequestAllocation() throws Exception {
    /**
     * There're multiple containers need to be increased, check container will
     * be increase sorted by priority, if priority is same, smaller containerId
     * container will get preferred
     */
    MockRM rm1 = new MockRM() {

        @Override
        public RMNodeLabelsManager createNodeLabelManager() {
            return mgr;
        }
    };
    rm1.start();
    MockNM nm1 = rm1.registerNode("h1:1234", 10 * GB);
    // app1 -> a1
    RMApp app1 = rm1.submitApp(1 * GB, "app", "user", null, "default");
    MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1);
    FiCaSchedulerApp app = TestUtils.getFiCaSchedulerApp(rm1, app1.getApplicationId());
    ApplicationAttemptId attemptId = am1.getApplicationAttemptId();
    // Container 2, 3 (priority=3)
    allocateAndLaunchContainers(am1, nm1, rm1, 2, 1 * GB, 3, 2);
    // Container 4, 5 (priority=2)
    allocateAndLaunchContainers(am1, nm1, rm1, 2, 1 * GB, 2, 4);
    // Container 6, 7 (priority=4)
    allocateAndLaunchContainers(am1, nm1, rm1, 2, 1 * GB, 4, 6);
    // am1 asks to change its container[2-7] from 1G to 2G
    List<UpdateContainerRequest> increaseRequests = new ArrayList<>();
    for (int cId = 2; cId <= 7; cId++) {
        ContainerId containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), cId);
        increaseRequests.add(UpdateContainerRequest.newInstance(0, containerId, ContainerUpdateType.INCREASE_RESOURCE, Resources.createResource(2 * GB), null));
    }
    am1.sendContainerResizingRequest(increaseRequests);
    checkPendingResource(rm1, "default", 6 * GB, null);
    Assert.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize());
    // Get rmNode1
    CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler();
    RMNode rmNode1 = rm1.getRMContext().getRMNodes().get(nm1.getNodeId());
    // assignContainer, container-4/5/2 increased (which has highest priority OR
    // earlier allocated)
    cs.handle(new NodeUpdateSchedulerEvent(rmNode1));
    AllocateResponse allocateResponse = am1.allocate(null, null);
    Assert.assertEquals(3, allocateResponse.getUpdatedContainers().size());
    verifyContainerIncreased(allocateResponse, ContainerId.newContainerId(attemptId, 4), 2 * GB);
    verifyContainerIncreased(allocateResponse, ContainerId.newContainerId(attemptId, 5), 2 * GB);
    verifyContainerIncreased(allocateResponse, ContainerId.newContainerId(attemptId, 2), 2 * GB);
    /* Check statuses after allocation */
    // There're still 3 pending increase requests
    checkPendingResource(rm1, "default", 3 * GB, null);
    Assert.assertEquals(3 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize());
    // Queue/user/application's usage will be updated
    checkUsedResource(rm1, "default", 10 * GB, null);
    Assert.assertEquals(10 * GB, ((LeafQueue) cs.getQueue("default")).getUser("user").getUsed().getMemorySize());
    Assert.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize());
    Assert.assertEquals(10 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize());
    rm1.close();
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) NodeUpdateSchedulerEvent(org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) ArrayList(java.util.ArrayList) MockRM(org.apache.hadoop.yarn.server.resourcemanager.MockRM) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) AllocateResponse(org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse) RMNode(org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) FiCaSchedulerApp(org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) UpdateContainerRequest(org.apache.hadoop.yarn.api.records.UpdateContainerRequest) Test(org.junit.Test)

Example 7 with UpdateContainerRequest

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

the class RMServerUtils method validateAndSplitUpdateResourceRequests.

/**
   * Check if we have:
   * - Request for same containerId and different target resource.
   * - If targetResources violates maximum/minimumAllocation.
   * @param rmContext RM context.
   * @param request Allocate Request.
   * @param maximumAllocation Maximum Allocation.
   * @param updateErrors Container update errors.
   * @return ContainerUpdateRequests.
   */
public static ContainerUpdates validateAndSplitUpdateResourceRequests(RMContext rmContext, AllocateRequest request, Resource maximumAllocation, List<UpdateContainerError> updateErrors) {
    ContainerUpdates updateRequests = new ContainerUpdates();
    Set<ContainerId> outstandingUpdate = new HashSet<>();
    for (UpdateContainerRequest updateReq : request.getUpdateRequests()) {
        RMContainer rmContainer = rmContext.getScheduler().getRMContainer(updateReq.getContainerId());
        String msg = validateContainerIdAndVersion(outstandingUpdate, updateReq, rmContainer);
        ContainerUpdateType updateType = updateReq.getContainerUpdateType();
        if (msg == null) {
            if ((updateType != ContainerUpdateType.PROMOTE_EXECUTION_TYPE) && (updateType != ContainerUpdateType.DEMOTE_EXECUTION_TYPE)) {
                if (validateIncreaseDecreaseRequest(rmContext, updateReq, maximumAllocation)) {
                    if (ContainerUpdateType.INCREASE_RESOURCE == updateType) {
                        updateRequests.getIncreaseRequests().add(updateReq);
                    } else {
                        updateRequests.getDecreaseRequests().add(updateReq);
                    }
                    outstandingUpdate.add(updateReq.getContainerId());
                } else {
                    msg = RESOURCE_OUTSIDE_ALLOWED_RANGE;
                }
            } else {
                ExecutionType original = rmContainer.getExecutionType();
                ExecutionType target = updateReq.getExecutionType();
                if (target != original) {
                    if (target == ExecutionType.GUARANTEED && original == ExecutionType.OPPORTUNISTIC) {
                        updateRequests.getPromotionRequests().add(updateReq);
                        outstandingUpdate.add(updateReq.getContainerId());
                    } else if (target == ExecutionType.OPPORTUNISTIC && original == ExecutionType.GUARANTEED) {
                        updateRequests.getDemotionRequests().add(updateReq);
                        outstandingUpdate.add(updateReq.getContainerId());
                    }
                }
            }
        }
        checkAndcreateUpdateError(updateErrors, updateReq, rmContainer, msg);
    }
    return updateRequests;
}
Also used : ContainerUpdates(org.apache.hadoop.yarn.server.resourcemanager.scheduler.ContainerUpdates) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerUpdateType(org.apache.hadoop.yarn.api.records.ContainerUpdateType) ExecutionType(org.apache.hadoop.yarn.api.records.ExecutionType) UpdateContainerRequest(org.apache.hadoop.yarn.api.records.UpdateContainerRequest) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) HashSet(java.util.HashSet)

Aggregations

UpdateContainerRequest (org.apache.hadoop.yarn.api.records.UpdateContainerRequest)7 ArrayList (java.util.ArrayList)5 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)5 AllocateResponse (org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse)3 RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)3 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Container (org.apache.hadoop.yarn.api.records.Container)2 ContainerUpdateType (org.apache.hadoop.yarn.api.records.ContainerUpdateType)2 ExecutionType (org.apache.hadoop.yarn.api.records.ExecutionType)2 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)2 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)2 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)2 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 AllocateRequest (org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest)1 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)1