New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
YARN-11226. [Federation] Add createNewReservation, submitReservation, updateReservation, deleteReservation REST APIs for Router. #4892
Changes from 9 commits
e54c767
4a3dc94
6e8af50
d7209e6
7a73686
bb738ae
12d5811
001a2fe
7617b48
27d310c
f569b26
f324c59
b9d33b4
a0fc7bb
ad614d5
c1dbec5
1e96bfb
07a3133
7f7426d
bbaeebc
60ee8a3
2352c50
21bc868
6ad7d6a
8ed08bb
43bb877
8d8492e
f32ed12
b89b320
e64f06d
be63f62
bb39541
5abeb24
0dfeb5c
5d535b5
a73a258
b62ec21
61f9165
a23e080
c0f381d
5011e12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,20 @@ | |
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.util.ReflectionUtils; | ||
import org.apache.hadoop.util.StringUtils; | ||
import org.apache.hadoop.yarn.api.records.ReservationRequest; | ||
import org.apache.hadoop.yarn.api.records.Priority; | ||
import org.apache.hadoop.yarn.api.records.ReservationId; | ||
import org.apache.hadoop.yarn.api.records.ReservationRequestInterpreter; | ||
import org.apache.hadoop.yarn.api.records.Resource; | ||
import org.apache.hadoop.yarn.api.records.ReservationRequests; | ||
import org.apache.hadoop.yarn.api.records.ReservationDefinition; | ||
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; | ||
import org.apache.hadoop.yarn.server.federation.store.records.ReservationHomeSubCluster; | ||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationRequestsInfo; | ||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDefinitionInfo; | ||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationRequestInfo; | ||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo; | ||
import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade; | ||
import org.apache.hadoop.yarn.exceptions.YarnException; | ||
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; | ||
import org.slf4j.Logger; | ||
|
@@ -222,4 +236,115 @@ public static void logAndThrowRunTimeException(Throwable t, String errMsgFormat, | |
throw new RuntimeException(msg); | ||
} | ||
} | ||
|
||
/** | ||
* Save Reservation And HomeSubCluster Mapping. | ||
* | ||
* @param federationFacade federation facade | ||
* @param reservationId reservationId | ||
* @param homeSubCluster homeSubCluster | ||
* @throws YarnException on failure | ||
*/ | ||
public static void addReservationHomeSubCluster(FederationStateStoreFacade federationFacade, | ||
ReservationId reservationId, ReservationHomeSubCluster homeSubCluster) throws YarnException { | ||
try { | ||
// persist the mapping of reservationId and the subClusterId which has | ||
// been selected as its home | ||
federationFacade.addReservationHomeSubCluster(homeSubCluster); | ||
} catch (YarnException e) { | ||
RouterServerUtil.logAndThrowException(e, | ||
"Unable to insert the ReservationId %s into the FederationStateStore.", reservationId); | ||
} | ||
} | ||
|
||
/** | ||
* Update Reservation And HomeSubCluster Mapping. | ||
* | ||
* @param federationFacade federation facade | ||
* @param subClusterId subClusterId | ||
* @param reservationId reservationId | ||
* @param homeSubCluster homeSubCluster | ||
* @throws YarnException on failure | ||
*/ | ||
public static void updateReservationHomeSubCluster(FederationStateStoreFacade federationFacade, | ||
SubClusterId subClusterId, ReservationId reservationId, | ||
ReservationHomeSubCluster homeSubCluster) throws YarnException { | ||
try { | ||
// update the mapping of reservationId and the home subClusterId to | ||
// the new subClusterId we have selected | ||
federationFacade.updateReservationHomeSubCluster(homeSubCluster); | ||
} catch (YarnException e) { | ||
SubClusterId subClusterIdInStateStore = | ||
federationFacade.getReservationHomeSubCluster(reservationId); | ||
if (subClusterId == subClusterIdInStateStore) { | ||
LOG.info("Reservation {} already submitted on SubCluster {}.", reservationId, subClusterId); | ||
} else { | ||
RouterServerUtil.logAndThrowException(e, | ||
"Unable to update the ReservationId %s into the FederationStateStore.", reservationId); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Exists ReservationHomeSubCluster Mapping. | ||
* | ||
* @param federationFacade federation facade | ||
* @param reservationId reservationId | ||
* @return true - exist, false - not exist | ||
*/ | ||
public static Boolean existsReservationHomeSubCluster(FederationStateStoreFacade federationFacade, | ||
ReservationId reservationId) { | ||
try { | ||
SubClusterId subClusterId = federationFacade.getReservationHomeSubCluster(reservationId); | ||
if (subClusterId != null) { | ||
return true; | ||
} | ||
} catch (YarnException e) { | ||
LOG.warn("get homeSubCluster by reservationId = {} error.", reservationId, e); | ||
} | ||
return false; | ||
} | ||
|
||
public static ReservationDefinition convertReservationDefinition( | ||
goiri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ReservationDefinitionInfo definitionInfo) { | ||
|
||
// basic variable | ||
long arrival = definitionInfo.getArrival(); | ||
long deadline = definitionInfo.getDeadline(); | ||
|
||
// ReservationRequests reservationRequests | ||
String name = definitionInfo.getReservationName(); | ||
String recurrenceExpression = definitionInfo.getRecurrenceExpression(); | ||
Priority priority = Priority.newInstance(definitionInfo.getPriority()); | ||
|
||
// reservation requests info | ||
List<ReservationRequest> reservationRequestList = new ArrayList<>(); | ||
|
||
ReservationRequestsInfo reservationRequestsInfo = definitionInfo.getReservationRequests(); | ||
|
||
List<ReservationRequestInfo> reservationRequestInfos = | ||
reservationRequestsInfo.getReservationRequest(); | ||
|
||
for (ReservationRequestInfo resRequestInfo : reservationRequestInfos) { | ||
ResourceInfo resourceInfo = resRequestInfo.getCapability(); | ||
Resource capability = | ||
Resource.newInstance(resourceInfo.getMemorySize(), resourceInfo.getvCores()); | ||
ReservationRequest reservationRequest = ReservationRequest.newInstance(capability, | ||
resRequestInfo.getNumContainers(), resRequestInfo.getMinConcurrency(), | ||
resRequestInfo.getDuration()); | ||
reservationRequestList.add(reservationRequest); | ||
} | ||
|
||
ReservationRequestInterpreter[] values = ReservationRequestInterpreter.values(); | ||
ReservationRequestInterpreter reservationRequestInterpreter = | ||
values[reservationRequestsInfo.getReservationRequestsInterpreter()]; | ||
ReservationRequests reservationRequests = | ||
ReservationRequests.newInstance(reservationRequestList, reservationRequestInterpreter); | ||
|
||
ReservationDefinition definition = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First two lines into one line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This? |
||
ReservationDefinition.newInstance( | ||
arrival, deadline, reservationRequests, name, recurrenceExpression, priority); | ||
|
||
return definition; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be the native
boolean
type?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your help reviewing the code, I will modify the code.