/** * 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); } } }
@Test public void testRemovalOfChildlessParentQueue() { AllocationConfiguration allocConf = scheduler.getAllocationConfiguration(); queueManager.updateAllocationConfiguration(allocConf); FSParentQueue q1 = queueManager.getParentQueue("root.test.childB", false); assertNotNull("Queue root.test.childB was not created", q1); assertEquals("createQueue() returned wrong queue", "root.test.childB", q1.getName()); assertFalse("root.test.childB is a dynamic queue", q1.isDynamic()); // static queues should not be deleted queueManager.removePendingIncompatibleQueues(); queueManager.removeEmptyDynamicQueues(); q1 = queueManager.getParentQueue("root.test.childB", false); assertNotNull("Queue root.test.childB was deleted", q1); // next we remove root.test.childB from the allocation config allocConf.configuredQueues.get(FSQueueType.PARENT) .remove("root.test.childB"); queueManager.updateAllocationConfiguration(allocConf); queueManager.setQueuesToDynamic(Collections.singleton("root.test.childB")); // the next removeEmptyDynamicQueues() call should clean // root.test.childB up queueManager.removePendingIncompatibleQueues(); queueManager.removeEmptyDynamicQueues(); q1 = queueManager.getParentQueue("root.leaf1", false); assertNull("Queue root.leaf1 was not deleted", q1); }