示例#1
0
 /// <summary>Heart of the scheduler...</summary>
 /// <param name="node">node on which resources are available to be allocated</param>
 private void AssignContainers(FiCaSchedulerNode node)
 {
     Log.Debug("assignContainers:" + " node=" + node.GetRMNode().GetNodeAddress() + " #applications="
               + applications.Count);
     // Try to assign containers to applications in fifo order
     foreach (KeyValuePair <ApplicationId, SchedulerApplication <FiCaSchedulerApp> > e in
              applications)
     {
         FiCaSchedulerApp application = e.Value.GetCurrentAppAttempt();
         if (application == null)
         {
             continue;
         }
         Log.Debug("pre-assignContainers");
         application.ShowRequests();
         lock (application)
         {
             // Check if this resource is on the blacklist
             if (SchedulerAppUtils.IsBlacklisted(application, node, Log))
             {
                 continue;
             }
             foreach (Priority priority in application.GetPriorities())
             {
                 int maxContainers = GetMaxAllocatableContainers(application, priority, node, NodeType
                                                                 .OffSwitch);
                 // Ensure the application needs containers of this priority
                 if (maxContainers > 0)
                 {
                     int assignedContainers = AssignContainersOnNode(node, application, priority);
                     // Do not assign out of order w.r.t priorities
                     if (assignedContainers == 0)
                     {
                         break;
                     }
                 }
             }
         }
         Log.Debug("post-assignContainers");
         application.ShowRequests();
         // Done
         if (Resources.LessThan(resourceCalculator, clusterResource, node.GetAvailableResource
                                    (), minimumAllocation))
         {
             break;
         }
     }
     // Update the applications' headroom to correctly take into
     // account the containers assigned in this update.
     foreach (SchedulerApplication <FiCaSchedulerApp> application_1 in applications.Values)
     {
         FiCaSchedulerApp attempt = (FiCaSchedulerApp)application_1.GetCurrentAppAttempt();
         if (attempt == null)
         {
             continue;
         }
         UpdateAppHeadRoom(attempt);
     }
 }
示例#2
0
        public override Org.Apache.Hadoop.Yarn.Api.Records.Resource AssignContainer(FSSchedulerNode
                                                                                    node)
        {
            Org.Apache.Hadoop.Yarn.Api.Records.Resource assigned = Resources.None();
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Node " + node.GetNodeName() + " offered to queue: " + GetName());
            }
            if (!AssignContainerPreCheck(node))
            {
                return(assigned);
            }
            IComparer <Schedulable> comparator = policy.GetComparator();

            writeLock.Lock();
            try
            {
                runnableApps.Sort(comparator);
            }
            finally
            {
                writeLock.Unlock();
            }
            // Release write lock here for better performance and avoiding deadlocks.
            // runnableApps can be in unsorted state because of this section,
            // but we can accept it in practice since the probability is low.
            readLock.Lock();
            try
            {
                foreach (FSAppAttempt sched in runnableApps)
                {
                    if (SchedulerAppUtils.IsBlacklisted(sched, node, Log))
                    {
                        continue;
                    }
                    assigned = sched.AssignContainer(node);
                    if (!assigned.Equals(Resources.None()))
                    {
                        break;
                    }
                }
            }
            finally
            {
                readLock.Unlock();
            }
            return(assigned);
        }