/** * Remove a queue and all its descendents. */ private void removeQueue(FSQueue queue) { if (queue instanceof FSLeafQueue) { leafQueues.remove(queue); } else { List<FSQueue> childQueues = queue.getChildQueues(); while (!childQueues.isEmpty()) { removeQueue(childQueues.get(0)); } } queues.remove(queue.getName()); queue.getParent().getChildQueues().remove(queue); }
/** * Remove a queue and all its descendents. */ private void removeQueue(FSQueue queue) { if (queue instanceof FSLeafQueue) { leafQueues.remove(queue); } else { List<FSQueue> childQueues = queue.getChildQueues(); while (!childQueues.isEmpty()) { removeQueue(childQueues.get(0)); } } queues.remove(queue.getName()); queue.getParent().getChildQueues().remove(queue); }
/** * Removes all empty dynamic queues (including empty dynamic parent queues). */ public void removeEmptyDynamicQueues() { synchronized (queues) { Set<FSParentQueue> parentQueuesToCheck = new HashSet<>(); for (FSQueue queue : getQueues()) { if (queue.isDynamic() && queue.getChildQueues().isEmpty()) { boolean removed = removeQueueIfEmpty(queue); if (removed && queue.getParent().isDynamic()) { parentQueuesToCheck.add(queue.getParent()); } } } while (!parentQueuesToCheck.isEmpty()) { FSParentQueue queue = parentQueuesToCheck.iterator().next(); if (queue.getChildQueues().isEmpty()) { removeQueue(queue); if (queue.getParent().isDynamic()) { parentQueuesToCheck.add(queue.getParent()); } } parentQueuesToCheck.remove(queue); } } }
@Override protected void dumpStateInternal(StringBuilder sb) { sb.append("{Name: " + getName() + ", Weight: " + weights + ", Policy: " + policy.getName() + ", FairShare: " + getFairShare() + ", SteadyFairShare: " + getSteadyFairShare() + ", MaxShare: " + getMaxShare() + ", MinShare: " + minShare + ", ResourceUsage: " + getResourceUsage() + ", Demand: " + getDemand() + ", MaxAMShare: " + maxAMShare + ", Runnable: " + getNumRunnableApps() + "}"); for(FSQueue child : getChildQueues()) { sb.append(", "); child.dumpStateInternal(sb); } } }
@Test public void testConcurrentChangeToGetChildQueue() { queueManager.getLeafQueue("parent.child", true); queueManager.getLeafQueue("parent.child2", true); FSParentQueue test = queueManager.getParentQueue("parent", false); assertEquals(2, test.getChildQueues().size()); boolean first = true; int childQueuesFound = 0; for (FSQueue childQueue:test.getChildQueues()) { if (first) { first = false; queueManager.getLeafQueue("parent.child3", true); } childQueuesFound++; } assertEquals(2, childQueuesFound); assertEquals(3, test.getChildQueues().size()); } }
@Test public void testReloadTurnsLeafToParentWithNoLeaf() { AllocationConfiguration allocConf = new AllocationConfiguration(conf); // Create a leaf queue1 allocConf.configuredQueues.get(FSQueueType.LEAF).add("root.queue1"); queueManager.updateAllocationConfiguration(allocConf); assertNotNull(queueManager.getLeafQueue("root.queue1", false)); // Lets say later on admin makes queue1 a parent queue by // specifying "type=parent" in the alloc xml and lets say apps running in // queue1 notEmptyQueues.add(queueManager.getLeafQueue("root.queue1", false)); allocConf = new AllocationConfiguration(conf); allocConf.configuredQueues.get(FSQueueType.PARENT) .add("root.queue1"); // When allocs are reloaded queue1 shouldn't be converter to parent queueManager.updateAllocationConfiguration(allocConf); assertNotNull(queueManager.getLeafQueue("root.queue1", false)); assertNull(queueManager.getParentQueue("root.queue1", false)); // Now lets assume apps completed and there are no apps in queue1 notEmptyQueues.clear(); // We should see queue1 transform from leaf queue to parent queue. queueManager.updateAllocationConfiguration(allocConf); assertNull(queueManager.getLeafQueue("root.queue1", false)); assertNotNull(queueManager.getParentQueue("root.queue1", false)); // this parent should not have any children assertTrue(queueManager.getParentQueue("root.queue1", false) .getChildQueues().isEmpty()); }
@Test public void testReloadTurnsLeafToParentWithNoLeaf() { AllocationConfiguration allocConf = new AllocationConfiguration(conf); // Create a leaf queue1 allocConf.configuredQueues.get(FSQueueType.LEAF).add("root.queue1"); queueManager.updateAllocationConfiguration(allocConf); assertNotNull(queueManager.getLeafQueue("root.queue1", false)); // Lets say later on admin makes queue1 a parent queue by // specifying "type=parent" in the alloc xml and lets say apps running in // queue1 notEmptyQueues.add(queueManager.getLeafQueue("root.queue1", false)); allocConf = new AllocationConfiguration(conf); allocConf.configuredQueues.get(FSQueueType.PARENT) .add("root.queue1"); // When allocs are reloaded queue1 shouldn't be converter to parent queueManager.updateAllocationConfiguration(allocConf); assertNotNull(queueManager.getLeafQueue("root.queue1", false)); assertNull(queueManager.getParentQueue("root.queue1", false)); // Now lets assume apps completed and there are no apps in queue1 notEmptyQueues.clear(); // We should see queue1 transform from leaf queue to parent queue. queueManager.updateAllocationConfiguration(allocConf); assertNull(queueManager.getLeafQueue("root.queue1", false)); assertNotNull(queueManager.getParentQueue("root.queue1", false)); // this parent should not have any children assertTrue(queueManager.getParentQueue("root.queue1", false) .getChildQueues().isEmpty()); }