slfan1989 commented on code in PR #4711:
URL: https://github.com/apache/hadoop/pull/4711#discussion_r939616561


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java:
##########
@@ -400,6 +406,40 @@ public Configuration getConf() {
     return this.conf;
   }
 
+
+
+  /**
+   * Adds the home {@link SubClusterId} for the specified {@link 
ReservationId}.
+   *
+   * @param appHomeSubCluster the mapping of the reservation to it's home
+   *          sub-cluster
+   * @return the stored Subcluster from StateStore
+   * @throws YarnException if the call to the state store is unsuccessful
+   */
+  public SubClusterId addReservationHomeSubCluster(
+      ReservationHomeSubCluster appHomeSubCluster) throws YarnException {
+    AddReservationHomeSubClusterResponse response =
+        stateStore.addReservationHomeSubCluster(
+        AddReservationHomeSubClusterRequest.newInstance(appHomeSubCluster));
+    return response.getHomeSubCluster();
+  }
+
+  /**
+   * Returns the home {@link SubClusterId} for the specified
+   * {@link ReservationId}.
+   *
+   * @param reservationId the identifier of the reservation
+   * @return the home sub cluster identifier
+   * @throws YarnException if the call to the state store is unsuccessful
+   */
+  public SubClusterId getReservationHomeSubCluster(ReservationId reservationId)
+      throws YarnException {
+    GetReservationHomeSubClusterResponse response =
+        stateStore.getReservationHomeSubCluster(

Review Comment:
   I will fix it.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/policies/router/BaseRouterPoliciesTest.java:
##########
@@ -126,4 +134,55 @@ public void testNullReservationContext() throws Exception {
         () -> policy.getReservationHomeSubcluster(null));
   }
 
+  @Test
+  public void testUnknownReservation() throws Exception {
+    ReservationSubmissionRequest resReq = getReservationSubmissionRequest();
+    ReservationId reservationId = 
ReservationId.newInstance(System.currentTimeMillis(), 1);
+    when(resReq.getQueue()).thenReturn("queue1");
+    when(resReq.getReservationId()).thenReturn(reservationId);
+
+    // route an application that uses this app
+    ApplicationSubmissionContext applicationSubmissionContext =
+        ApplicationSubmissionContext.newInstance(
+            ApplicationId.newInstance(System.currentTimeMillis(), 1), "app1",
+            "queue1", Priority.newInstance(1), null, false, false, 1, null, 
null, false);
+
+    applicationSubmissionContext.setReservationID(resReq.getReservationId());
+    FederationRouterPolicy policy = (FederationRouterPolicy) getPolicy();
+
+    LambdaTestUtils.intercept(YarnException.class,
+        "Reservation " + reservationId + " does not exist",
+        () -> policy.getHomeSubcluster(applicationSubmissionContext, new 
ArrayList<>()));
+  }
+
+  @Test
+  public void testFollowReservation() throws YarnException {
+    ReservationSubmissionRequest resReq = getReservationSubmissionRequest();
+    when(resReq.getQueue()).thenReturn("queue1");
+    when(resReq.getReservationId())
+        .thenReturn(ReservationId.newInstance(System.currentTimeMillis(), 1));
+
+    // first we invoke a reservation placement
+    SubClusterId chosen = ((FederationRouterPolicy) getPolicy())
+        .getReservationHomeSubcluster(resReq);
+
+    // add this to the store
+    this.getFederationPolicyContext().getFederationStateStoreFacade()
+        .addReservationHomeSubCluster(ReservationHomeSubCluster.newInstance(
+             resReq.getReservationId(), chosen));
+
+    // route an application that uses this app
+    ApplicationSubmissionContext applicationSubmissionContext =
+        ApplicationSubmissionContext.newInstance(
+            ApplicationId.newInstance(System.currentTimeMillis(), 1), "app1",

Review Comment:
   I will fix it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to