YARN-5703. ReservationAgents are not correctly configured. Contributed by Manikandan R.

This commit is contained in:
Naganarasimha 2017-02-27 20:38:29 +05:30
parent 4d33683882
commit 5f5b031d1f
8 changed files with 42 additions and 25 deletions

View File

@ -451,12 +451,16 @@ public abstract class AbstractReservationSystem extends AbstractService
try { try {
Class<?> agentClazz = conf.getClassByName(agentClassName); Class<?> agentClazz = conf.getClassByName(agentClassName);
if (ReservationAgent.class.isAssignableFrom(agentClazz)) { if (ReservationAgent.class.isAssignableFrom(agentClazz)) {
return (ReservationAgent) ReflectionUtils.newInstance(agentClazz, conf); ReservationAgent resevertionAgent =
(ReservationAgent) agentClazz.newInstance();
resevertionAgent.init(conf);
return resevertionAgent;
} else { } else {
throw new YarnRuntimeException("Class: " + agentClassName throw new YarnRuntimeException("Class: " + agentClassName
+ " not instance of " + ReservationAgent.class.getCanonicalName()); + " not instance of " + ReservationAgent.class.getCanonicalName());
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException | InstantiationException
| IllegalAccessException e) {
throw new YarnRuntimeException("Could not instantiate Agent: " throw new YarnRuntimeException("Could not instantiate Agent: "
+ agentClassName + " for queue: " + queueName, e); + agentClassName + " for queue: " + queueName, e);
} }

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation.planning;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.records.ReservationDefinition; import org.apache.hadoop.yarn.api.records.ReservationDefinition;
import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.api.records.ReservationId;
import org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan; import org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan;
@ -35,22 +36,25 @@ import org.slf4j.LoggerFactory;
public class AlignedPlannerWithGreedy implements ReservationAgent { public class AlignedPlannerWithGreedy implements ReservationAgent {
// Default smoothness factor // Default smoothness factor
private static final int DEFAULT_SMOOTHNESS_FACTOR = 10; public static final int DEFAULT_SMOOTHNESS_FACTOR = 10;
public static final String SMOOTHNESS_FACTOR =
"yarn.resourcemanager.reservation-system.smoothness-factor";
// Log // Log
private static final Logger LOG = LoggerFactory private static final Logger LOG = LoggerFactory
.getLogger(AlignedPlannerWithGreedy.class); .getLogger(AlignedPlannerWithGreedy.class);
// Smoothness factor // Smoothness factor
private final ReservationAgent planner; private ReservationAgent planner;
// Constructor // Constructor
public AlignedPlannerWithGreedy() { public AlignedPlannerWithGreedy() {
this(DEFAULT_SMOOTHNESS_FACTOR);
} }
// Constructor @Override
public AlignedPlannerWithGreedy(int smoothnessFactor) { public void init(Configuration conf) {
int smoothnessFactor =
conf.getInt(SMOOTHNESS_FACTOR, DEFAULT_SMOOTHNESS_FACTOR);
// List of algorithms // List of algorithms
List<ReservationAgent> listAlg = new LinkedList<ReservationAgent>(); List<ReservationAgent> listAlg = new LinkedList<ReservationAgent>();
@ -71,7 +75,6 @@ public class AlignedPlannerWithGreedy implements ReservationAgent {
// 1. Attempt to execute algAligned // 1. Attempt to execute algAligned
// 2. If failed, fall back to algGreedy // 2. If failed, fall back to algGreedy
planner = new TryManyReservationAgents(listAlg); planner = new TryManyReservationAgents(listAlg);
} }
@Override @Override
@ -119,5 +122,4 @@ public class AlignedPlannerWithGreedy implements ReservationAgent {
return planner.deleteReservation(reservationId, user, plan); return planner.deleteReservation(reservationId, user, plan);
} }
} }

View File

@ -46,25 +46,19 @@ public class GreedyReservationAgent implements ReservationAgent {
.getLogger(GreedyReservationAgent.class); .getLogger(GreedyReservationAgent.class);
// Greedy planner // Greedy planner
private final ReservationAgent planner; private ReservationAgent planner;
public final static String GREEDY_FAVOR_EARLY_ALLOCATION = public final static String GREEDY_FAVOR_EARLY_ALLOCATION =
"yarn.resourcemanager.reservation-system.favor-early-allocation"; "yarn.resourcemanager.reservation-system.favor-early-allocation";
public final static boolean DEFAULT_GREEDY_FAVOR_EARLY_ALLOCATION = true; public final static boolean DEFAULT_GREEDY_FAVOR_EARLY_ALLOCATION = true;
private boolean allocateLeft;
private final boolean allocateLeft;
public GreedyReservationAgent() { public GreedyReservationAgent() {
this(new Configuration());
} }
public GreedyReservationAgent(Configuration yarnConfiguration) { @Override
public void init(Configuration conf) {
allocateLeft = allocateLeft = conf.getBoolean(GREEDY_FAVOR_EARLY_ALLOCATION,
yarnConfiguration.getBoolean(GREEDY_FAVOR_EARLY_ALLOCATION, DEFAULT_GREEDY_FAVOR_EARLY_ALLOCATION);
DEFAULT_GREEDY_FAVOR_EARLY_ALLOCATION);
if (allocateLeft) { if (allocateLeft) {
LOG.info("Initializing the GreedyReservationAgent to favor \"early\"" LOG.info("Initializing the GreedyReservationAgent to favor \"early\""
+ " (left) allocations (controlled by parameter: " + " (left) allocations (controlled by parameter: "
@ -78,7 +72,6 @@ public class GreedyReservationAgent implements ReservationAgent {
planner = planner =
new IterativePlanner(new StageEarliestStartByJobArrival(), new IterativePlanner(new StageEarliestStartByJobArrival(),
new StageAllocatorGreedyRLE(allocateLeft), allocateLeft); new StageAllocatorGreedyRLE(allocateLeft), allocateLeft);
} }
public boolean isAllocateLeft(){ public boolean isAllocateLeft(){

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation.planning;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.records.ReservationDefinition; import org.apache.hadoop.yarn.api.records.ReservationDefinition;
import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.api.records.ReservationId;
import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.Resource;
@ -206,4 +207,7 @@ public abstract class PlanningAlgorithm implements ReservationAgent {
} }
@Override
public void init(Configuration conf) {
}
} }

View File

@ -17,6 +17,7 @@
*******************************************************************************/ *******************************************************************************/
package org.apache.hadoop.yarn.server.resourcemanager.reservation.planning; package org.apache.hadoop.yarn.server.resourcemanager.reservation.planning;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.records.ReservationDefinition; import org.apache.hadoop.yarn.api.records.ReservationDefinition;
import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.api.records.ReservationId;
import org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan; import org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan;
@ -70,4 +71,11 @@ public interface ReservationAgent {
public boolean deleteReservation(ReservationId reservationId, String user, public boolean deleteReservation(ReservationId reservationId, String user,
Plan plan) throws PlanningException; Plan plan) throws PlanningException;
/**
* Init configuration.
*
* @param conf Configuration
*/
void init(Configuration conf);
} }

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation.planning;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.records.ReservationDefinition; import org.apache.hadoop.yarn.api.records.ReservationDefinition;
import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.api.records.ReservationId;
import org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan; import org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan;
@ -110,5 +111,7 @@ public class TryManyReservationAgents implements ReservationAgent {
return plan.deleteReservation(reservationId); return plan.deleteReservation(reservationId);
} }
@Override
public void init(Configuration conf) {
}
} }

View File

@ -726,8 +726,11 @@ public class TestAlignedPlanner {
QueueMetrics queueMetrics = mock(QueueMetrics.class); QueueMetrics queueMetrics = mock(QueueMetrics.class);
RMContext context = ReservationSystemTestUtil.createMockRMContext(); RMContext context = ReservationSystemTestUtil.createMockRMContext();
conf.setInt(AlignedPlannerWithGreedy.SMOOTHNESS_FACTOR,
AlignedPlannerWithGreedy.DEFAULT_SMOOTHNESS_FACTOR);
// Set planning agent // Set planning agent
agent = new AlignedPlannerWithGreedy(); agent = new AlignedPlannerWithGreedy();
agent.init(conf);
// Create Plan // Create Plan
plan = plan =

View File

@ -110,8 +110,8 @@ public class TestGreedyReservationAgent {
// setting conf to // setting conf to
conf.setBoolean(GreedyReservationAgent.GREEDY_FAVOR_EARLY_ALLOCATION, conf.setBoolean(GreedyReservationAgent.GREEDY_FAVOR_EARLY_ALLOCATION,
allocateLeft); allocateLeft);
agent = new GreedyReservationAgent();
agent = new GreedyReservationAgent(conf); agent.init(conf);
QueueMetrics queueMetrics = mock(QueueMetrics.class); QueueMetrics queueMetrics = mock(QueueMetrics.class);
RMContext context = ReservationSystemTestUtil.createMockRMContext(); RMContext context = ReservationSystemTestUtil.createMockRMContext();