private FSAppAttempt MockAppAttempt(long startTime) { FSAppAttempt schedApp = Org.Mockito.Mockito.Mock <FSAppAttempt>(); Org.Mockito.Mockito.When(schedApp.GetStartTime()).ThenReturn(startTime); return(schedApp); }
protected internal virtual void VerifyHeadroom(FSAppAttempt schedulerApp, int expectedMemory , int expectedCPU) { Org.Apache.Hadoop.Yarn.Api.Records.Resource headroom = schedulerApp.GetHeadroom(); NUnit.Framework.Assert.AreEqual(expectedMemory, headroom.GetMemory()); NUnit.Framework.Assert.AreEqual(expectedCPU, headroom.GetVirtualCores()); }
/// <exception cref="System.Exception"/> public virtual void TestSchedulingDelay() { // Add one node string host = "127.0.0.1"; RMNode node1 = MockNodes.NewNodeInfo(1, Resources.CreateResource(4096, 4), 1, host ); NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1); scheduler.Handle(nodeEvent1); NodeUpdateSchedulerEvent nodeUpdateEvent = new NodeUpdateSchedulerEvent(node1); scheduler.Handle(nodeUpdateEvent); // Create one application and submit one each of node-local, rack-local // and ANY requests ApplicationAttemptId appAttemptId = CreateAppAttemptId(this.AppId++, this.AttemptId ++); CreateMockRMApp(appAttemptId); scheduler.AddApplication(appAttemptId.GetApplicationId(), "queue11", "user11", false ); scheduler.AddApplicationAttempt(appAttemptId, false, false); IList <ResourceRequest> ask = new AList <ResourceRequest>(); ask.AddItem(CreateResourceRequest(1024, 1, ResourceRequest.Any, 1, 1, true)); scheduler.Allocate(appAttemptId, ask, new AList <ContainerId>(), null, null); FSAppAttempt app = scheduler.GetSchedulerApp(appAttemptId); // Advance time and let continuous scheduling kick in mockClock.Tick(1); while (1024 != app.GetCurrentConsumption().GetMemory()) { Sharpen.Thread.Sleep(100); } NUnit.Framework.Assert.AreEqual(1024, app.GetCurrentConsumption().GetMemory()); }
/// <summary>Removes the given app from this queue.</summary> /// <returns>whether or not the app was runnable</returns> public virtual bool RemoveApp(FSAppAttempt app) { bool runnable = false; // Remove app from runnable/nonRunnable list while holding the write lock writeLock.Lock(); try { runnable = runnableApps.Remove(app); if (!runnable) { // removeNonRunnableApp acquires the write lock again, which is fine if (!RemoveNonRunnableApp(app)) { throw new InvalidOperationException("Given app to remove " + app + " does not exist in queue " + this); } } } finally { writeLock.Unlock(); } // Update AM resource usage if needed if (runnable && app.IsAmRunning() && app.GetAMResource() != null) { Resources.SubtractFrom(amResourceUsage, app.GetAMResource()); } return(runnable); }
public virtual void TestHeadroom() { FairScheduler mockScheduler = Org.Mockito.Mockito.Mock <FairScheduler>(); Org.Mockito.Mockito.When(mockScheduler.GetClock()).ThenReturn(scheduler.GetClock( )); FSLeafQueue mockQueue = Org.Mockito.Mockito.Mock <FSLeafQueue>(); Resource queueMaxResources = Resource.NewInstance(5 * 1024, 3); Org.Apache.Hadoop.Yarn.Api.Records.Resource queueFairShare = Resources.CreateResource (4096, 2); Org.Apache.Hadoop.Yarn.Api.Records.Resource queueUsage = Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(2048, 2); Org.Apache.Hadoop.Yarn.Api.Records.Resource queueStarvation = Resources.Subtract( queueFairShare, queueUsage); Org.Apache.Hadoop.Yarn.Api.Records.Resource queueMaxResourcesAvailable = Resources .Subtract(queueMaxResources, queueUsage); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (8192, 8); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterUsage = Resources.CreateResource (2048, 2); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterAvailable = Resources.Subtract (clusterResource, clusterUsage); QueueMetrics fakeRootQueueMetrics = Org.Mockito.Mockito.Mock <QueueMetrics>(); Org.Mockito.Mockito.When(mockQueue.GetMaxShare()).ThenReturn(queueMaxResources); Org.Mockito.Mockito.When(mockQueue.GetFairShare()).ThenReturn(queueFairShare); Org.Mockito.Mockito.When(mockQueue.GetResourceUsage()).ThenReturn(queueUsage); Org.Mockito.Mockito.When(mockScheduler.GetClusterResource()).ThenReturn(clusterResource ); Org.Mockito.Mockito.When(fakeRootQueueMetrics.GetAllocatedResources()).ThenReturn (clusterUsage); Org.Mockito.Mockito.When(mockScheduler.GetRootQueueMetrics()).ThenReturn(fakeRootQueueMetrics ); ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1); RMContext rmContext = resourceManager.GetRMContext(); FSAppAttempt schedulerApp = new FSAppAttempt(mockScheduler, applicationAttemptId, "user1", mockQueue, null, rmContext); // Min of Memory and CPU across cluster and queue is used in // DominantResourceFairnessPolicy Org.Mockito.Mockito.When(mockQueue.GetPolicy()).ThenReturn(SchedulingPolicy.GetInstance (typeof(DominantResourceFairnessPolicy))); VerifyHeadroom(schedulerApp, Min(queueStarvation.GetMemory(), clusterAvailable.GetMemory (), queueMaxResourcesAvailable.GetMemory()), Min(queueStarvation.GetVirtualCores (), clusterAvailable.GetVirtualCores(), queueMaxResourcesAvailable.GetVirtualCores ())); // Fair and Fifo ignore CPU of queue, so use cluster available CPU Org.Mockito.Mockito.When(mockQueue.GetPolicy()).ThenReturn(SchedulingPolicy.GetInstance (typeof(FairSharePolicy))); VerifyHeadroom(schedulerApp, Min(queueStarvation.GetMemory(), clusterAvailable.GetMemory (), queueMaxResourcesAvailable.GetMemory()), Math.Min(clusterAvailable.GetVirtualCores (), queueMaxResourcesAvailable.GetVirtualCores())); Org.Mockito.Mockito.When(mockQueue.GetPolicy()).ThenReturn(SchedulingPolicy.GetInstance (typeof(FifoPolicy))); VerifyHeadroom(schedulerApp, Min(queueStarvation.GetMemory(), clusterAvailable.GetMemory (), queueMaxResourcesAvailable.GetMemory()), Math.Min(clusterAvailable.GetVirtualCores (), queueMaxResourcesAvailable.GetVirtualCores())); }
public virtual void TestConcurrentAccess() { conf.Set(FairSchedulerConfiguration.AssignMultiple, "false"); resourceManager = new MockRM(conf); resourceManager.Start(); scheduler = (FairScheduler)resourceManager.GetResourceScheduler(); string queueName = "root.queue1"; FSLeafQueue schedulable = scheduler.GetQueueManager().GetLeafQueue(queueName, true ); ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1); RMContext rmContext = resourceManager.GetRMContext(); FSAppAttempt app = new FSAppAttempt(scheduler, applicationAttemptId, "user1", schedulable , null, rmContext); // this needs to be in sync with the number of runnables declared below int testThreads = 2; IList <Runnable> runnables = new AList <Runnable>(); // add applications to modify the list runnables.AddItem(new _Runnable_257(schedulable, app)); // iterate over the list a couple of times in a different thread runnables.AddItem(new _Runnable_267(schedulable)); IList <Exception> exceptions = Sharpen.Collections.SynchronizedList(new AList <Exception >()); ExecutorService threadPool = Executors.NewFixedThreadPool(testThreads); try { CountDownLatch allExecutorThreadsReady = new CountDownLatch(testThreads); CountDownLatch startBlocker = new CountDownLatch(1); CountDownLatch allDone = new CountDownLatch(testThreads); foreach (Runnable submittedTestRunnable in runnables) { threadPool.Submit(new _Runnable_287(allExecutorThreadsReady, startBlocker, submittedTestRunnable , exceptions, allDone)); } // wait until all threads are ready allExecutorThreadsReady.Await(); // start all test runners startBlocker.CountDown(); int testTimeout = 2; NUnit.Framework.Assert.IsTrue("Timeout waiting for more than " + testTimeout + " seconds" , allDone.Await(testTimeout, TimeUnit.Seconds)); } catch (Exception ie) { exceptions.AddItem(ie); } finally { threadPool.ShutdownNow(); } NUnit.Framework.Assert.IsTrue("Test failed with exception(s)" + exceptions, exceptions .IsEmpty()); }
/// <summary> /// Checks to see whether any other applications runnable now that the given /// application has been removed from the given queue. /// </summary> /// <remarks> /// Checks to see whether any other applications runnable now that the given /// application has been removed from the given queue. And makes them so. /// Runs in O(n log(n)) where n is the number of queues that are under the /// highest queue that went from having no slack to having slack. /// </remarks> public virtual void UpdateRunnabilityOnAppRemoval(FSAppAttempt app, FSLeafQueue queue ) { AllocationConfiguration allocConf = scheduler.GetAllocationConfiguration(); // childqueueX might have no pending apps itself, but if a queue higher up // in the hierarchy parentqueueY has a maxRunningApps set, an app completion // in childqueueX could allow an app in some other distant child of // parentqueueY to become runnable. // An app removal will only possibly allow another app to become runnable if // the queue was already at its max before the removal. // Thus we find the ancestor queue highest in the tree for which the app // that was at its maxRunningApps before the removal. FSQueue highestQueueWithAppsNowRunnable = (queue.GetNumRunnableApps() == allocConf .GetQueueMaxApps(queue.GetName()) - 1) ? queue : null; FSParentQueue parent = queue.GetParent(); while (parent != null) { if (parent.GetNumRunnableApps() == allocConf.GetQueueMaxApps(parent.GetName()) - 1) { highestQueueWithAppsNowRunnable = parent; } parent = parent.GetParent(); } IList <IList <FSAppAttempt> > appsNowMaybeRunnable = new AList <IList <FSAppAttempt> >( ); // Compile lists of apps which may now be runnable // We gather lists instead of building a set of all non-runnable apps so // that this whole operation can be O(number of queues) instead of // O(number of apps) if (highestQueueWithAppsNowRunnable != null) { GatherPossiblyRunnableAppLists(highestQueueWithAppsNowRunnable, appsNowMaybeRunnable ); } string user = app.GetUser(); int userNumRunning = usersNumRunnableApps[user]; if (userNumRunning == null) { userNumRunning = 0; } if (userNumRunning == allocConf.GetUserMaxApps(user) - 1) { IList <FSAppAttempt> userWaitingApps = usersNonRunnableApps.Get(user); if (userWaitingApps != null) { appsNowMaybeRunnable.AddItem(userWaitingApps); } } UpdateAppsRunnability(appsNowMaybeRunnable, appsNowMaybeRunnable.Count); }
public virtual bool IsNonRunnableApp(FSAppAttempt attempt) { readLock.Lock(); try { return(nonRunnableApps.Contains(attempt)); } finally { readLock.Unlock(); } }
// for testing internal virtual void AddAppSchedulable(FSAppAttempt appSched) { writeLock.Lock(); try { runnableApps.AddItem(appSched); } finally { writeLock.Unlock(); } }
/// <summary>Removes the given app if it is non-runnable and belongs to this queue</summary> /// <returns>true if the app is removed, false otherwise</returns> public virtual bool RemoveNonRunnableApp(FSAppAttempt app) { writeLock.Lock(); try { return(nonRunnableApps.Remove(app)); } finally { writeLock.Unlock(); } }
public virtual void TestDelayScheduling() { FSLeafQueue queue = Org.Mockito.Mockito.Mock <FSLeafQueue>(); Priority prio = Org.Mockito.Mockito.Mock <Priority>(); Org.Mockito.Mockito.When(prio.GetPriority()).ThenReturn(1); double nodeLocalityThreshold = .5; double rackLocalityThreshold = .6; ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1); RMContext rmContext = resourceManager.GetRMContext(); FSAppAttempt schedulerApp = new FSAppAttempt(scheduler, applicationAttemptId, "user1" , queue, null, rmContext); // Default level should be node-local NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); // First five scheduling opportunities should remain node local for (int i = 0; i < 5; i++) { schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); } // After five it should switch to rack local schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); // Manually set back to node local schedulerApp.ResetAllowedLocalityLevel(prio, NodeType.NodeLocal); schedulerApp.ResetSchedulingOpportunities(prio); NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); // Now escalate again to rack-local, then to off-switch for (int i_1 = 0; i_1 < 5; i_1++) { schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); } schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); for (int i_2 = 0; i_2 < 6; i_2++) { schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); } schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.OffSwitch, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); }
private void UpdateDemandForApp(FSAppAttempt sched, Org.Apache.Hadoop.Yarn.Api.Records.Resource maxRes) { sched.UpdateDemand(); Org.Apache.Hadoop.Yarn.Api.Records.Resource toAdd = sched.GetDemand(); if (Log.IsDebugEnabled()) { Log.Debug("Counting resource from " + sched.GetName() + " " + toAdd + "; Total resource consumption for " + GetName() + " now " + demand); } demand = Resources.Add(demand, toAdd); demand = Resources.ComponentwiseMin(demand, maxRes); }
public virtual void TestLocalityLevelWithoutDelays() { FSLeafQueue queue = Org.Mockito.Mockito.Mock <FSLeafQueue>(); Priority prio = Org.Mockito.Mockito.Mock <Priority>(); Org.Mockito.Mockito.When(prio.GetPriority()).ThenReturn(1); RMContext rmContext = resourceManager.GetRMContext(); ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1); FSAppAttempt schedulerApp = new FSAppAttempt(scheduler, applicationAttemptId, "user1" , queue, null, rmContext); NUnit.Framework.Assert.AreEqual(NodeType.OffSwitch, schedulerApp.GetAllowedLocalityLevel (prio, 10, -1.0, -1.0)); }
public virtual double AdjustWeight(FSAppAttempt app, double curWeight) { long start = app.GetStartTime(); long now = Runtime.CurrentTimeMillis(); if (now - start < duration) { return(curWeight * factor); } else { return(curWeight); } }
/// <summary> /// Tracks the given new runnable app for purposes of maintaining max running /// app limits. /// </summary> public virtual void TrackRunnableApp(FSAppAttempt app) { string user = app.GetUser(); FSLeafQueue queue = ((FSLeafQueue)app.GetQueue()); // Increment running counts for all parent queues FSParentQueue parent = queue.GetParent(); while (parent != null) { parent.IncrementRunnableApps(); parent = parent.GetParent(); } int userNumRunnable = usersNumRunnableApps[user]; usersNumRunnableApps[user] = (userNumRunnable == null ? 0 : userNumRunnable) + 1; }
public override void UnreserveResource(SchedulerApplicationAttempt application) { lock (this) { // Cannot unreserve for wrong application... ApplicationAttemptId reservedApplication = GetReservedContainer().GetContainer(). GetId().GetApplicationAttemptId(); if (!reservedApplication.Equals(application.GetApplicationAttemptId())) { throw new InvalidOperationException("Trying to unreserve " + " for application " + application.GetApplicationId() + " when currently reserved " + " for application " + reservedApplication.GetApplicationId() + " on node " + this); } SetReservedContainer(null); this.reservedAppSchedulable = null; } }
/// <summary> /// Checks to see whether applications are runnable now by iterating /// through each one of them and check if the queue and user have slack /// if we know how many apps can be runnable, there is no need to iterate /// through all apps, maxRunnableApps is used to break out of the iteration /// </summary> private void UpdateAppsRunnability(IList <IList <FSAppAttempt> > appsNowMaybeRunnable , int maxRunnableApps) { // Scan through and check whether this means that any apps are now runnable IEnumerator <FSAppAttempt> iter = new MaxRunningAppsEnforcer.MultiListStartTimeIterator (appsNowMaybeRunnable); FSAppAttempt prev = null; IList <FSAppAttempt> noLongerPendingApps = new AList <FSAppAttempt>(); while (iter.HasNext()) { FSAppAttempt next = iter.Next(); if (next == prev) { continue; } if (CanAppBeRunnable(((FSLeafQueue)next.GetQueue()), next.GetUser())) { TrackRunnableApp(next); FSAppAttempt appSched = next; ((FSLeafQueue)next.GetQueue()).AddApp(appSched, true); noLongerPendingApps.AddItem(appSched); if (noLongerPendingApps.Count >= maxRunnableApps) { break; } } prev = next; } // We remove the apps from their pending lists afterwards so that we don't // pull them out from under the iterator. If they are not in these lists // in the first place, there is a bug. foreach (FSAppAttempt appSched_1 in noLongerPendingApps) { if (!((FSLeafQueue)appSched_1.GetQueue()).RemoveNonRunnableApp(appSched_1)) { Log.Error("Can't make app runnable that does not already exist in queue" + " as non-runnable: " + appSched_1 + ". This should never happen."); } if (!usersNonRunnableApps.Remove(appSched_1.GetUser(), appSched_1)) { Log.Error("Waiting app " + appSched_1 + " expected to be in " + "usersNonRunnableApps, but was not. This should never happen." ); } } }
private FSAppAttempt AddApp(FSLeafQueue queue, string user) { ApplicationId appId = ApplicationId.NewInstance(0l, appNum++); ApplicationAttemptId attId = ApplicationAttemptId.NewInstance(appId, 0); bool runnable = maxAppsEnforcer.CanAppBeRunnable(queue, user); FSAppAttempt app = new FSAppAttempt(scheduler, attId, user, queue, null, rmContext ); queue.AddApp(app, runnable); if (runnable) { maxAppsEnforcer.TrackRunnableApp(app); } else { maxAppsEnforcer.TrackNonRunnableApp(app); } return(app); }
public virtual void AddApp(FSAppAttempt app, bool runnable) { writeLock.Lock(); try { if (runnable) { runnableApps.AddItem(app); } else { nonRunnableApps.AddItem(app); } } finally { writeLock.Unlock(); } }
public virtual void TestRemoveDoesNotEnableAnyApp() { FSLeafQueue leaf1 = queueManager.GetLeafQueue("root.queue1", true); FSLeafQueue leaf2 = queueManager.GetLeafQueue("root.queue2", true); queueMaxApps["root"] = 2; queueMaxApps["root.queue1"] = 1; queueMaxApps["root.queue2"] = 1; FSAppAttempt app1 = AddApp(leaf1, "user"); AddApp(leaf2, "user"); AddApp(leaf2, "user"); NUnit.Framework.Assert.AreEqual(1, leaf1.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumNonRunnableApps()); RemoveApp(app1); NUnit.Framework.Assert.AreEqual(0, leaf1.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumNonRunnableApps()); }
public virtual void TestRemoveEnablesAppOnCousinQueue() { FSLeafQueue leaf1 = queueManager.GetLeafQueue("root.queue1.subqueue1.leaf1", true ); FSLeafQueue leaf2 = queueManager.GetLeafQueue("root.queue1.subqueue2.leaf2", true ); queueMaxApps["root.queue1"] = 2; FSAppAttempt app1 = AddApp(leaf1, "user"); AddApp(leaf2, "user"); AddApp(leaf2, "user"); NUnit.Framework.Assert.AreEqual(1, leaf1.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumNonRunnableApps()); RemoveApp(app1); NUnit.Framework.Assert.AreEqual(0, leaf1.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(2, leaf2.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(0, leaf2.GetNumNonRunnableApps()); }
public virtual void TestDelaySchedulingForContinuousScheduling() { FSLeafQueue queue = scheduler.GetQueueManager().GetLeafQueue("queue", true); Priority prio = Org.Mockito.Mockito.Mock <Priority>(); Org.Mockito.Mockito.When(prio.GetPriority()).ThenReturn(1); TestFSAppAttempt.MockClock clock = new TestFSAppAttempt.MockClock(this); scheduler.SetClock(clock); long nodeLocalityDelayMs = 5 * 1000L; // 5 seconds long rackLocalityDelayMs = 6 * 1000L; // 6 seconds RMContext rmContext = resourceManager.GetRMContext(); ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1); FSAppAttempt schedulerApp = new FSAppAttempt(scheduler, applicationAttemptId, "user1" , queue, null, rmContext); // Default level should be node-local NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevelByTime (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime())); // after 4 seconds should remain node local clock.Tick(4); NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevelByTime (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime())); // after 6 seconds should switch to rack local clock.Tick(2); NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevelByTime (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime())); // manually set back to node local schedulerApp.ResetAllowedLocalityLevel(prio, NodeType.NodeLocal); schedulerApp.ResetSchedulingOpportunities(prio, clock.GetTime()); NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevelByTime (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime())); // Now escalate again to rack-local, then to off-switch clock.Tick(6); NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevelByTime (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime())); clock.Tick(7); NUnit.Framework.Assert.AreEqual(NodeType.OffSwitch, schedulerApp.GetAllowedLocalityLevelByTime (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime())); }
public virtual void TestRemoveEnablesOneByQueueOneByUser() { FSLeafQueue leaf1 = queueManager.GetLeafQueue("root.queue1.leaf1", true); FSLeafQueue leaf2 = queueManager.GetLeafQueue("root.queue1.leaf2", true); queueMaxApps["root.queue1.leaf1"] = 2; userMaxApps["user1"] = 1; FSAppAttempt app1 = AddApp(leaf1, "user1"); AddApp(leaf1, "user2"); AddApp(leaf1, "user3"); AddApp(leaf2, "user1"); NUnit.Framework.Assert.AreEqual(2, leaf1.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(1, leaf1.GetNumNonRunnableApps()); NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumNonRunnableApps()); RemoveApp(app1); NUnit.Framework.Assert.AreEqual(2, leaf1.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumRunnableApps()); NUnit.Framework.Assert.AreEqual(0, leaf1.GetNumNonRunnableApps()); NUnit.Framework.Assert.AreEqual(0, leaf2.GetNumNonRunnableApps()); }
public override RMContainer PreemptContainer() { RMContainer toBePreempted = null; // If this queue is not over its fair share, reject if (!PreemptContainerPreCheck()) { return(toBePreempted); } if (Log.IsDebugEnabled()) { Log.Debug("Queue " + GetName() + " is going to preempt a container " + "from its applications." ); } // Choose the app that is most over fair share IComparer <Schedulable> comparator = policy.GetComparator(); FSAppAttempt candidateSched = null; readLock.Lock(); try { foreach (FSAppAttempt sched in runnableApps) { if (candidateSched == null || comparator.Compare(sched, candidateSched) > 0) { candidateSched = sched; } } } finally { readLock.Unlock(); } // Preempt from the selected app if (candidateSched != null) { toBePreempted = candidateSched.PreemptContainer(); } return(toBePreempted); }
public virtual void TestUpdateDemand() { conf.Set(FairSchedulerConfiguration.AssignMultiple, "false"); resourceManager = new MockRM(conf); resourceManager.Start(); scheduler = (FairScheduler)resourceManager.GetResourceScheduler(); scheduler.allocConf = Org.Mockito.Mockito.Mock <AllocationConfiguration>(); string queueName = "root.queue1"; Org.Mockito.Mockito.When(scheduler.allocConf.GetMaxResources(queueName)).ThenReturn (maxResource); Org.Mockito.Mockito.When(scheduler.allocConf.GetMinResources(queueName)).ThenReturn (Resources.None()); FSLeafQueue schedulable = new FSLeafQueue(queueName, scheduler, null); FSAppAttempt app = Org.Mockito.Mockito.Mock <FSAppAttempt>(); Org.Mockito.Mockito.When(app.GetDemand()).ThenReturn(maxResource); schedulable.AddAppSchedulable(app); schedulable.AddAppSchedulable(app); schedulable.UpdateDemand(); NUnit.Framework.Assert.IsTrue("Demand is greater than max allowed ", Resources.Equals (schedulable.GetDemand(), maxResource)); }
public override void ReserveResource(SchedulerApplicationAttempt application, Priority priority, RMContainer container) { lock (this) { // Check if it's already reserved RMContainer reservedContainer = GetReservedContainer(); if (reservedContainer != null) { // Sanity check if (!container.GetContainer().GetNodeId().Equals(GetNodeID())) { throw new InvalidOperationException("Trying to reserve" + " container " + container + " on node " + container.GetReservedNode() + " when currently" + " reserved resource " + reservedContainer + " on node " + reservedContainer.GetReservedNode()); } // Cannot reserve more than one application on a given node! if (!reservedContainer.GetContainer().GetId().GetApplicationAttemptId().Equals(container .GetContainer().GetId().GetApplicationAttemptId())) { throw new InvalidOperationException("Trying to reserve" + " container " + container + " for application " + application.GetApplicationId() + " when currently" + " reserved container " + reservedContainer + " on node " + this); } Log.Info("Updated reserved container " + container.GetContainer().GetId() + " on node " + this + " for application " + application); } else { Log.Info("Reserved container " + container.GetContainer().GetId() + " on node " + this + " for application " + application); } SetReservedContainer(container); this.reservedAppSchedulable = (FSAppAttempt)application; } }
/// <summary> /// Updates the relevant tracking variables after a runnable app with the given /// queue and user has been removed. /// </summary> public virtual void UntrackRunnableApp(FSAppAttempt app) { // Update usersRunnableApps string user = app.GetUser(); int newUserNumRunning = usersNumRunnableApps[user] - 1; if (newUserNumRunning == 0) { Sharpen.Collections.Remove(usersNumRunnableApps, user); } else { usersNumRunnableApps[user] = newUserNumRunning; } // Update runnable app bookkeeping for queues FSLeafQueue queue = ((FSLeafQueue)app.GetQueue()); FSParentQueue parent = queue.GetParent(); while (parent != null) { parent.DecrementRunnableApps(); parent = parent.GetParent(); } }
/// <summary> /// Tracks the given new non runnable app so that it can be made runnable when /// it would not violate max running app limits. /// </summary> public virtual void TrackNonRunnableApp(FSAppAttempt app) { string user = app.GetUser(); usersNonRunnableApps.Put(user, app); }
public _Runnable_257(FSLeafQueue schedulable, FSAppAttempt app) { this.schedulable = schedulable; this.app = app; }
/// <summary>Stops tracking the given non-runnable app</summary> public virtual void UntrackNonRunnableApp(FSAppAttempt app) { usersNonRunnableApps.Remove(app.GetUser(), app); }