private boolean reservationExceedsThreshold(FSSchedulerNode node, NodeType type) { // Only if not node-local if (type != NodeType.NODE_LOCAL) { int existingReservations = getNumReservations(node.getRackName(), type == NodeType.OFF_SWITCH); int totalAvailNodes = (type == NodeType.OFF_SWITCH) ? scheduler.getNumClusterNodes() : scheduler.getNumNodesInRack(node.getRackName()); int numAllowedReservations = (int)Math.ceil( totalAvailNodes * scheduler.getReservableNodesRatio()); if (existingReservations >= numAllowedReservations) { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); if (LOG.isDebugEnabled()) { LOG.debug("Reservation Exceeds Allowed number of nodes:" + " app_id=" + getApplicationId() + " existingReservations=" + existingReservations + " totalAvailableNodes=" + totalAvailNodes + " reservableNodesRatio=" + df.format( scheduler.getReservableNodesRatio()) + " numAllowedReservations=" + numAllowedReservations); } return true; } } return false; }
} else { allowedLocality = getAllowedLocalityLevel(schedulerKey, scheduler.getNumClusterNodes(), scheduler.getNodeLocalityThreshold(), scheduler.getRackLocalityThreshold());
@Test public void testContinuousSchedulingInterruptedException() throws Exception { scheduler.init(conf); scheduler.start(); FairScheduler spyScheduler = spy(scheduler); Assert.assertTrue("Continuous scheduling should be disabled.", !spyScheduler.isContinuousSchedulingEnabled()); // Add one nodes RMNode node1 = MockNodes.newNodeInfo(1, Resources.createResource(8 * 1024, 8), 1, "127.0.0.1"); NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1); spyScheduler.handle(nodeEvent1); Assert.assertEquals("We should have one alive node.", 1, spyScheduler.getNumClusterNodes()); InterruptedException ie = new InterruptedException(); doThrow(new YarnRuntimeException(ie)).when(spyScheduler). attemptScheduling(isA(FSSchedulerNode.class)); // Invoke the continuous scheduling once try { spyScheduler.continuousSchedulingAttempt(); fail("Expected InterruptedException to stop schedulingThread"); } catch (InterruptedException e) { Assert.assertEquals(ie, e); } }
} else { allowedLocality = getAllowedLocalityLevel(priority, scheduler.getNumClusterNodes(), scheduler.getNodeLocalityThreshold(), scheduler.getRackLocalityThreshold());
scheduler.handle(nodeEvent2); Assert.assertEquals("We should have two alive nodes.", 2, scheduler.getNumClusterNodes()); scheduler.handle(removeNode1); Assert.assertEquals("We should only have one alive node.", 1, scheduler.getNumClusterNodes());
} else { allowedLocality = getAllowedLocalityLevel(priority, scheduler.getNumClusterNodes(), scheduler.getNodeLocalityThreshold(), scheduler.getRackLocalityThreshold());
spyScheduler.handle(nodeEvent1); Assert.assertEquals("We should have one alive node.", 1, spyScheduler.getNumClusterNodes()); InterruptedException ie = new InterruptedException(); doThrow(new YarnRuntimeException(ie)).when(spyScheduler).
scheduler.handle(nodeEvent2); assertEquals("We should have two alive nodes.", 2, scheduler.getNumClusterNodes()); Resource clusterResource = scheduler.getClusterResource(); Resource clusterUsage = scheduler.getRootQueueMetrics()
scheduler.handle(nodeEvent2); Assert.assertEquals("We should have two alive nodes.", 2, scheduler.getNumClusterNodes()); scheduler.handle(removeNode1); Assert.assertEquals("We should only have one alive node.", 1, scheduler.getNumClusterNodes());