Search in sources :

Example 1 with Allocation

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation in project hadoop by apache.

the class Application method getResources.

public synchronized List<Container> getResources() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("getResources begin:" + " application=" + applicationId + " #ask=" + ask.size());
        for (ResourceRequest request : ask) {
            LOG.debug("getResources:" + " application=" + applicationId + " ask-request=" + request);
        }
    }
    // Get resources from the ResourceManager
    Allocation allocation = resourceManager.getResourceScheduler().allocate(applicationAttemptId, new ArrayList<ResourceRequest>(ask), new ArrayList<ContainerId>(), null, null, new ContainerUpdates());
    if (LOG.isInfoEnabled()) {
        LOG.info("-=======" + applicationAttemptId + System.lineSeparator() + "----------" + resourceManager.getRMContext().getRMApps().get(applicationId).getRMAppAttempt(applicationAttemptId));
    }
    List<Container> containers = allocation.getContainers();
    // Clear state for next interaction with ResourceManager
    ask.clear();
    if (LOG.isDebugEnabled()) {
        LOG.debug("getResources() for " + applicationId + ":" + " ask=" + ask.size() + " recieved=" + containers.size());
    }
    return containers;
}
Also used : Container(org.apache.hadoop.yarn.api.records.Container) Allocation(org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerUpdates(org.apache.hadoop.yarn.server.resourcemanager.scheduler.ContainerUpdates) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest)

Example 2 with Allocation

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation in project hadoop by apache.

the class SLSCapacityScheduler method allocate.

@Override
public Allocation allocate(ApplicationAttemptId attemptId, List<ResourceRequest> resourceRequests, List<ContainerId> containerIds, List<String> strings, List<String> strings2, ContainerUpdates updateRequests) {
    if (metricsON) {
        final Timer.Context context = schedulerAllocateTimer.time();
        Allocation allocation = null;
        try {
            allocation = super.allocate(attemptId, resourceRequests, containerIds, strings, strings2, updateRequests);
            return allocation;
        } finally {
            context.stop();
            schedulerAllocateCounter.inc();
            try {
                updateQueueWithAllocateRequest(allocation, attemptId, resourceRequests, containerIds);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } else {
        return super.allocate(attemptId, resourceRequests, containerIds, strings, strings2, updateRequests);
    }
}
Also used : Timer(com.codahale.metrics.Timer) Allocation(org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation) IOException(java.io.IOException)

Example 3 with Allocation

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation in project hadoop by apache.

the class ResourceSchedulerWrapper method allocate.

@Override
public Allocation allocate(ApplicationAttemptId attemptId, List<ResourceRequest> resourceRequests, List<ContainerId> containerIds, List<String> strings, List<String> strings2, ContainerUpdates updateRequests) {
    if (metricsON) {
        final Timer.Context context = schedulerAllocateTimer.time();
        Allocation allocation = null;
        try {
            allocation = scheduler.allocate(attemptId, resourceRequests, containerIds, strings, strings2, updateRequests);
            return allocation;
        } finally {
            context.stop();
            schedulerAllocateCounter.inc();
            try {
                updateQueueWithAllocateRequest(allocation, attemptId, resourceRequests, containerIds);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } else {
        return scheduler.allocate(attemptId, resourceRequests, containerIds, strings, strings2, updateRequests);
    }
}
Also used : Timer(com.codahale.metrics.Timer) Allocation(org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation) IOException(java.io.IOException)

Example 4 with Allocation

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation in project hadoop by apache.

the class CapacityScheduler method allocate.

@Override
@Lock(Lock.NoLock.class)
public Allocation allocate(ApplicationAttemptId applicationAttemptId, List<ResourceRequest> ask, List<ContainerId> release, List<String> blacklistAdditions, List<String> blacklistRemovals, ContainerUpdates updateRequests) {
    FiCaSchedulerApp application = getApplicationAttempt(applicationAttemptId);
    if (application == null) {
        return EMPTY_ALLOCATION;
    }
    // Handle all container updates
    handleContainerUpdates(application, updateRequests);
    // Release containers
    releaseContainers(release, application);
    LeafQueue updateDemandForQueue = null;
    // Sanity check for new allocation requests
    normalizeRequests(ask);
    Allocation allocation;
    // when the allocate comes in
    try {
        application.getWriteLock().lock();
        if (application.isStopped()) {
            return EMPTY_ALLOCATION;
        }
        // Process resource requests
        if (!ask.isEmpty()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("allocate: pre-update " + applicationAttemptId + " ask size =" + ask.size());
                application.showRequests();
            }
            // Update application requests
            if (application.updateResourceRequests(ask)) {
                updateDemandForQueue = (LeafQueue) application.getQueue();
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("allocate: post-update");
                application.showRequests();
            }
        }
        application.updateBlacklist(blacklistAdditions, blacklistRemovals);
        allocation = application.getAllocation(getResourceCalculator(), getClusterResource(), getMinimumResourceCapability());
    } finally {
        application.getWriteLock().unlock();
    }
    if (updateDemandForQueue != null && !application.isWaitingForAMContainer()) {
        updateDemandForQueue.getOrderingPolicy().demandUpdated(application);
    }
    return allocation;
}
Also used : Allocation(org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation) FiCaSchedulerApp(org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp) Lock(org.apache.hadoop.yarn.server.utils.Lock)

Example 5 with Allocation

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation in project hadoop by apache.

the class FiCaSchedulerApp method getAllocation.

/**
   * This method produces an Allocation that includes the current view
   * of the resources that will be allocated to and preempted from this
   * application.
   *
   * @param resourceCalculator resourceCalculator
   * @param clusterResource clusterResource
   * @param minimumAllocation minimumAllocation
   * @return an allocation
   */
public Allocation getAllocation(ResourceCalculator resourceCalculator, Resource clusterResource, Resource minimumAllocation) {
    try {
        writeLock.lock();
        Set<ContainerId> currentContPreemption = Collections.unmodifiableSet(new HashSet<ContainerId>(containersToPreempt));
        containersToPreempt.clear();
        Resource tot = Resource.newInstance(0, 0);
        for (ContainerId c : currentContPreemption) {
            Resources.addTo(tot, liveContainers.get(c).getContainer().getResource());
        }
        int numCont = (int) Math.ceil(Resources.divide(rc, clusterResource, tot, minimumAllocation));
        ResourceRequest rr = ResourceRequest.newBuilder().priority(Priority.UNDEFINED).resourceName(ResourceRequest.ANY).capability(minimumAllocation).numContainers(numCont).build();
        List<Container> newlyAllocatedContainers = pullNewlyAllocatedContainers();
        List<Container> newlyIncreasedContainers = pullNewlyIncreasedContainers();
        List<Container> newlyDecreasedContainers = pullNewlyDecreasedContainers();
        List<Container> newlyPromotedContainers = pullNewlyPromotedContainers();
        List<Container> newlyDemotedContainers = pullNewlyDemotedContainers();
        List<NMToken> updatedNMTokens = pullUpdatedNMTokens();
        Resource headroom = getHeadroom();
        setApplicationHeadroomForMetrics(headroom);
        return new Allocation(newlyAllocatedContainers, headroom, null, currentContPreemption, Collections.singletonList(rr), updatedNMTokens, newlyIncreasedContainers, newlyDecreasedContainers, newlyPromotedContainers, newlyDemotedContainers);
    } finally {
        writeLock.unlock();
    }
}
Also used : SchedulerContainer(org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.SchedulerContainer) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) Container(org.apache.hadoop.yarn.api.records.Container) NMToken(org.apache.hadoop.yarn.api.records.NMToken) Allocation(org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Resource(org.apache.hadoop.yarn.api.records.Resource) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest)

Aggregations

Allocation (org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation)15 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)8 Resource (org.apache.hadoop.yarn.api.records.Resource)8 ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)8 Container (org.apache.hadoop.yarn.api.records.Container)7 ArrayList (java.util.ArrayList)6 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)6 Configuration (org.apache.hadoop.conf.Configuration)5 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)5 RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)5 ContainerUpdates (org.apache.hadoop.yarn.server.resourcemanager.scheduler.ContainerUpdates)5 Test (org.junit.Test)5 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)4 RMNode (org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode)4 List (java.util.List)3 UpdateNodeResourceRequest (org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceRequest)3 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)3 AppAddedSchedulerEvent (org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppAddedSchedulerEvent)3 AppAttemptAddedSchedulerEvent (org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppAttemptAddedSchedulerEvent)3 NodeAddedSchedulerEvent (org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeAddedSchedulerEvent)3