YARN-5384. Expose priority in ReservationSystem submission APIs. (Sean Po via Subru).

This commit is contained in:
Subru Krishnan 2016-09-30 19:41:43 -07:00
parent 89bd6d29a6
commit 3a3697deab
6 changed files with 91 additions and 9 deletions

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.yarn.api.records;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.util.Records;
@ -38,7 +37,7 @@ public abstract class ReservationDefinition {
@Unstable
public static ReservationDefinition newInstance(long arrival, long deadline,
ReservationRequests reservationRequests, String name,
String recurrenceExpression) {
String recurrenceExpression, Priority priority) {
ReservationDefinition rDefinition =
Records.newRecord(ReservationDefinition.class);
rDefinition.setArrival(arrival);
@ -46,6 +45,7 @@ public abstract class ReservationDefinition {
rDefinition.setReservationRequests(reservationRequests);
rDefinition.setReservationName(name);
rDefinition.setRecurrenceExpression(recurrenceExpression);
rDefinition.setPriority(priority);
return rDefinition;
}
@ -53,8 +53,8 @@ public abstract class ReservationDefinition {
@Unstable
public static ReservationDefinition newInstance(long arrival, long deadline,
ReservationRequests reservationRequests, String name) {
ReservationDefinition rDefinition =
newInstance(arrival, deadline, reservationRequests, name, "0");
ReservationDefinition rDefinition = newInstance(arrival, deadline,
reservationRequests, name, "0", Priority.UNDEFINED);
return rDefinition;
}
@ -130,7 +130,7 @@ public abstract class ReservationDefinition {
* allocation in the scheduler
*/
@Public
@Evolving
@Unstable
public abstract String getReservationName();
/**
@ -142,7 +142,7 @@ public abstract class ReservationDefinition {
* allocation in the scheduler
*/
@Public
@Evolving
@Unstable
public abstract void setReservationName(String name);
/**
@ -160,7 +160,7 @@ public abstract class ReservationDefinition {
* @return recurrence of this reservation
*/
@Public
@Evolving
@Unstable
public abstract String getRecurrenceExpression();
/**
@ -178,7 +178,35 @@ public abstract class ReservationDefinition {
* @param recurrenceExpression recurrence interval of this reservation
*/
@Public
@Evolving
@Unstable
public abstract void setRecurrenceExpression(String recurrenceExpression);
/**
* Get the priority for this reservation. A lower number for priority
* indicates a higher priority reservation. Recurring reservations are
* always higher priority than non-recurring reservations. Priority for
* non-recurring reservations are only compared with non-recurring
* reservations. Likewise for recurring reservations.
*
* @return int representing the priority of the reserved resource
* allocation in the scheduler
*/
@Public
@Unstable
public abstract Priority getPriority();
/**
* Set the priority for this reservation. A lower number for priority
* indicates a higher priority reservation. Recurring reservations are
* always higher priority than non-recurring reservations. Priority for
* non-recurring reservations are only compared with non-recurring
* reservations. Likewise for recurring reservations.
*
* @param priority representing the priority of the reserved resource
* allocation in the scheduler
*/
@Public
@Unstable
public abstract void setPriority(Priority priority);
}

View File

@ -489,6 +489,7 @@ message ReservationDefinitionProto {
optional int64 deadline = 3;
optional string reservation_name = 4;
optional string recurrence_expression = 5 [default = "0"];
optional PriorityProto priority = 6;
}
message ResourceAllocationRequestProto {

View File

@ -18,8 +18,10 @@
package org.apache.hadoop.yarn.api.records.impl.pb;
import org.apache.hadoop.yarn.api.records.Priority;
import org.apache.hadoop.yarn.api.records.ReservationDefinition;
import org.apache.hadoop.yarn.api.records.ReservationRequests;
import org.apache.hadoop.yarn.proto.YarnProtos;
import org.apache.hadoop.yarn.proto.YarnProtos.ReservationDefinitionProto;
import org.apache.hadoop.yarn.proto.YarnProtos.ReservationDefinitionProtoOrBuilder;
import org.apache.hadoop.yarn.proto.YarnProtos.ReservationRequestsProto;
@ -32,6 +34,7 @@ public class ReservationDefinitionPBImpl extends ReservationDefinition {
boolean viaProto = false;
private ReservationRequests reservationReqs;
private Priority priority = null;
public ReservationDefinitionPBImpl() {
builder = ReservationDefinitionProto.newBuilder();
@ -150,6 +153,33 @@ public class ReservationDefinitionPBImpl extends ReservationDefinition {
builder.setReservationName(name);
}
@Override
public Priority getPriority() {
ReservationDefinitionProtoOrBuilder p = viaProto ? proto : builder;
if (this.priority != null) {
return this.priority;
}
if (!p.hasPriority()) {
return Priority.UNDEFINED;
}
this.priority = convertFromProtoFormat(p.getPriority());
return this.priority;
}
@Override
public void setPriority(Priority priority) {
maybeInitBuilder();
if (priority == null) {
this.priority = Priority.UNDEFINED;
}
this.priority = priority;
}
private PriorityPBImpl convertFromProtoFormat(
YarnProtos.PriorityProto p) {
return new PriorityPBImpl(p);
}
private ReservationRequestsPBImpl convertFromProtoFormat(
ReservationRequestsProto p) {
return new ReservationRequestsPBImpl(p);
@ -164,6 +194,7 @@ public class ReservationDefinitionPBImpl extends ReservationDefinition {
return "{Arrival: " + getArrival() + ", Deadline: " + getDeadline()
+ ", Reservation Name: " + getReservationName()
+ ", Recurrence expression: " + getRecurrenceExpression()
+ ", Priority: " + getPriority().toString()
+ ", Resources: " + getReservationRequests() + "}";
}

View File

@ -44,6 +44,9 @@ public class ReservationDefinitionInfo {
@XmlElement(name = "reservation-name")
private String reservationName;
@XmlElement(name = "priority")
private int priority;
public ReservationDefinitionInfo() {
}
@ -89,4 +92,12 @@ public class ReservationDefinitionInfo {
this.reservationName = reservationName;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
}

View File

@ -31,6 +31,7 @@ import java.util.TreeMap;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest;
import org.apache.hadoop.yarn.api.records.Priority;
import org.apache.hadoop.yarn.api.records.ReservationDefinition;
import org.apache.hadoop.yarn.api.records.ReservationId;
import org.apache.hadoop.yarn.api.records.ReservationRequest;
@ -199,6 +200,13 @@ public class ReservationSystemTestUtil {
public static ReservationSubmissionRequest createSimpleReservationRequest(
ReservationId reservationId, int numContainers, long arrival,
long deadline, long duration) {
return createSimpleReservationRequest(reservationId, numContainers,
arrival, deadline, duration, Priority.UNDEFINED);
}
public static ReservationSubmissionRequest createSimpleReservationRequest(
ReservationId reservationId, int numContainers, long arrival,
long deadline, long duration, Priority priority) {
// create a request with a single atomic ask
ReservationRequest r =
ReservationRequest.newInstance(Resource.newInstance(1024, 1),
@ -208,7 +216,7 @@ public class ReservationSystemTestUtil {
ReservationRequestInterpreter.R_ALL);
ReservationDefinition rDef =
ReservationDefinition.newInstance(arrival, deadline, reqs,
"testClientRMService#reservation");
"testClientRMService#reservation", "0", priority);
ReservationSubmissionRequest request =
ReservationSubmissionRequest.newInstance(rDef,
reservationQ, reservationId);

View File

@ -3237,6 +3237,7 @@ The Cluster Reservation API can be used to list reservations. When listing reser
| deadline | long | The UTC time representation of the latest time within which this reservation can be allocated. |
| reservation-name | string | A mnemonic name of the reservation (not a valid identifier). |
| reservation-requests | object | A list of "stages" or phases of this reservation, each describing resource requirements and duration |
| priority | int | An integer representing the priority of the reservation. A lower number for priority indicates a higher priority reservation. Recurring reservations are always higher priority than non-recurring reservations. Priority for non-recurring reservations are only compared with non-recurring reservations. Likewise with recurring reservations. |
### Elements of the *reservation-requests* object
@ -3500,6 +3501,7 @@ Elements of the *reservation-definition* object
| deadline | long | The UTC time representation of the latest time within which this reservation can be allocated. |
| reservation-name | string | A mnemonic name of the reservation (not a valid identifier). |
| reservation-requests | object | A list of "stages" or phases of this reservation, each describing resource requirements and duration |
| priority | int | An integer representing the priority of the reservation. A lower number for priority indicates a higher priority reservation. Recurring reservations are always higher priority than non-recurring reservations. Priority for non-recurring reservations are only compared with non-recurring reservations. Likewise with recurring reservations. |
Elements of the *reservation-requests* object
@ -3675,6 +3677,7 @@ Elements of the *reservation-definition* object
| deadline | long | The UTC time representation of the latest time within which this reservation can be allocated. |
| reservation-name | string | A mnemonic name of the reservation (not a valid identifier). |
| reservation-requests | object | A list of "stages" or phases of this reservation, each describing resource requirements and duration |
| priority | int | An integer representing the priority of the reservation. A lower number for priority indicates a higher priority reservation. Recurring reservations are always higher priority than non-recurring reservations. Priority for non-recurring reservations are only compared with non-recurring reservations. Likewise with recurring reservations. |
Elements of the *reservation-requests* object