Skip to content

Commit ab88e4b

Browse files
authored
YARN-11223. [Federation] Add getAppPriority, updateApplicationPriority REST APIs for Router. (apache#4733)
1 parent d0fdb1d commit ab88e4b

File tree

3 files changed

+127
-2
lines changed

3 files changed

+127
-2
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,14 +1261,52 @@ public NodeLabelsInfo getLabelsOnNode(HttpServletRequest hsr, String nodeId)
12611261
@Override
12621262
public AppPriority getAppPriority(HttpServletRequest hsr, String appId)
12631263
throws AuthorizationException {
1264-
throw new NotImplementedException("Code is not implemented");
1264+
1265+
if (appId == null || appId.isEmpty()) {
1266+
throw new IllegalArgumentException("Parameter error, the appId is empty or null.");
1267+
}
1268+
1269+
try {
1270+
SubClusterInfo subClusterInfo = getHomeSubClusterInfoByAppId(appId);
1271+
DefaultRequestInterceptorREST interceptor = getOrCreateInterceptorForSubCluster(
1272+
subClusterInfo.getSubClusterId(), subClusterInfo.getRMWebServiceAddress());
1273+
return interceptor.getAppPriority(hsr, appId);
1274+
} catch (IllegalArgumentException e) {
1275+
RouterServerUtil.logAndThrowRunTimeException(e,
1276+
"Unable to get the getAppPriority appId: %s.", appId);
1277+
} catch (YarnException e) {
1278+
RouterServerUtil.logAndThrowRunTimeException("getAppPriority Failed.", e);
1279+
}
1280+
1281+
return null;
12651282
}
12661283

12671284
@Override
12681285
public Response updateApplicationPriority(AppPriority targetPriority,
12691286
HttpServletRequest hsr, String appId) throws AuthorizationException,
12701287
YarnException, InterruptedException, IOException {
1271-
throw new NotImplementedException("Code is not implemented");
1288+
1289+
if (appId == null || appId.isEmpty()) {
1290+
throw new IllegalArgumentException("Parameter error, the appId is empty or null.");
1291+
}
1292+
1293+
if (targetPriority == null) {
1294+
throw new IllegalArgumentException("Parameter error, the targetPriority is empty or null.");
1295+
}
1296+
1297+
try {
1298+
SubClusterInfo subClusterInfo = getHomeSubClusterInfoByAppId(appId);
1299+
DefaultRequestInterceptorREST interceptor = getOrCreateInterceptorForSubCluster(
1300+
subClusterInfo.getSubClusterId(), subClusterInfo.getRMWebServiceAddress());
1301+
return interceptor.updateApplicationPriority(targetPriority, hsr, appId);
1302+
} catch (IllegalArgumentException e) {
1303+
RouterServerUtil.logAndThrowRunTimeException(e,
1304+
"Unable to get the updateApplicationPriority appId: %s.", appId);
1305+
} catch (YarnException e) {
1306+
RouterServerUtil.logAndThrowRunTimeException("updateApplicationPriority Failed.", e);
1307+
}
1308+
1309+
return null;
12721310
}
12731311

12741312
@Override

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/MockDefaultRequestInterceptorREST.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppAttemptsInfo;
7777
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppTimeoutInfo;
7878
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppTimeoutsInfo;
79+
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority;
7980
import org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo;
8081
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
8182
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
@@ -579,4 +580,45 @@ public Response updateApplicationTimeout(AppTimeoutInfo appTimeout, HttpServletR
579580

580581
return Response.status(Status.OK).entity(result).build();
581582
}
583+
584+
@Override
585+
public Response updateApplicationPriority(AppPriority targetPriority, HttpServletRequest hsr,
586+
String appId) throws YarnException, InterruptedException, IOException {
587+
if (!isRunning) {
588+
throw new RuntimeException("RM is stopped");
589+
}
590+
591+
ApplicationId applicationId = ApplicationId.fromString(appId);
592+
if (targetPriority == null) {
593+
return Response.status(Status.BAD_REQUEST).build();
594+
}
595+
596+
if (!applicationMap.containsKey(applicationId)) {
597+
throw new NotFoundException("app with id: " + appId + " not found");
598+
}
599+
600+
ApplicationReport appReport = applicationMap.get(applicationId);
601+
Priority newPriority = Priority.newInstance(targetPriority.getPriority());
602+
appReport.setPriority(newPriority);
603+
604+
return Response.status(Status.OK).entity(targetPriority).build();
605+
}
606+
607+
@Override
608+
public AppPriority getAppPriority(HttpServletRequest hsr, String appId)
609+
throws AuthorizationException {
610+
if (!isRunning) {
611+
throw new RuntimeException("RM is stopped");
612+
}
613+
614+
ApplicationId applicationId = ApplicationId.fromString(appId);
615+
616+
if (!applicationMap.containsKey(applicationId)) {
617+
throw new NotFoundException("app with id: " + appId + " not found");
618+
}
619+
ApplicationReport appReport = applicationMap.get(applicationId);
620+
Priority priority = appReport.getPriority();
621+
622+
return new AppPriority(priority.getPriority());
623+
}
582624
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestFederationInterceptorREST.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppAttemptInfo;
6262
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppTimeoutInfo;
6363
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppTimeoutsInfo;
64+
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority;
6465
import org.apache.hadoop.yarn.server.resourcemanager.webapp.NodeIDsInfo;
6566
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
6667
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
@@ -855,4 +856,48 @@ public void testUpdateApplicationTimeout() throws IOException, InterruptedExcept
855856
Assert.assertEquals(paramAppTimeOut.getTimeoutType(), entity.getTimeoutType());
856857
Assert.assertEquals(paramAppTimeOut.getRemainingTimeInSec(), entity.getRemainingTimeInSec());
857858
}
859+
860+
@Test
861+
public void testUpdateApplicationPriority() throws IOException, InterruptedException,
862+
YarnException {
863+
864+
// Submit application to multiSubCluster
865+
ApplicationId appId = ApplicationId.newInstance(Time.now(), 1);
866+
ApplicationSubmissionContextInfo context = new ApplicationSubmissionContextInfo();
867+
context.setApplicationId(appId.toString());
868+
context.setPriority(20);
869+
870+
// Submit the application we are going to kill later
871+
Assert.assertNotNull(interceptor.submitApplication(context, null));
872+
873+
int iPriority = 10;
874+
// Set Priority for application
875+
Response response = interceptor.updateApplicationPriority(
876+
new AppPriority(iPriority), null, appId.toString());
877+
878+
Assert.assertNotNull(response);
879+
AppPriority entity = (AppPriority) response.getEntity();
880+
Assert.assertNotNull(entity);
881+
Assert.assertEquals(iPriority, entity.getPriority());
882+
}
883+
884+
@Test
885+
public void testGetAppPriority() throws IOException, InterruptedException,
886+
YarnException {
887+
888+
// Submit application to multiSubCluster
889+
ApplicationId appId = ApplicationId.newInstance(Time.now(), 1);
890+
int priority = 40;
891+
ApplicationSubmissionContextInfo context = new ApplicationSubmissionContextInfo();
892+
context.setApplicationId(appId.toString());
893+
context.setPriority(priority);
894+
895+
// Submit the application we are going to kill later
896+
Assert.assertNotNull(interceptor.submitApplication(context, null));
897+
898+
// Set Priority for application
899+
AppPriority appPriority = interceptor.getAppPriority(null, appId.toString());
900+
Assert.assertNotNull(appPriority);
901+
Assert.assertEquals(priority, appPriority.getPriority());
902+
}
858903
}

0 commit comments

Comments
 (0)