getApplicationList(String applicationType)
+ throws YarnException, IOException;
/**
*
diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/YarnClientImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/YarnClientImpl.java
index 48be1a3..2b75998 100644
--- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/YarnClientImpl.java
+++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/YarnClientImpl.java
@@ -191,11 +191,12 @@ public ApplicationReport getApplicationReport(ApplicationId appId)
}
@Override
- public List getApplicationList()
+ public List getApplicationList(String applicationType)
throws YarnException, IOException {
GetAllApplicationsRequest request =
Records.newRecord(GetAllApplicationsRequest.class);
- GetAllApplicationsResponse response = rmClient.getAllApplications(request);
+ GetAllApplicationsResponse response =
+ rmClient.getAllApplications(request, applicationType);
return response.getApplicationList();
}
diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java
index 6bcd804..5efa281 100644
--- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java
+++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java
@@ -52,7 +52,7 @@ public int run(String[] args) throws Exception {
Options opts = new Options();
opts.addOption(STATUS_CMD, true, "Prints the status of the application.");
- opts.addOption(LIST_CMD, false, "Lists all the Applications from RM.");
+ opts.addOption(LIST_CMD, true, "Lists all the Applications from RM.");
opts.addOption(KILL_CMD, true, "Kills the application.");
CommandLine cliParser = new GnuParser().parse(opts, args);
@@ -64,7 +64,11 @@ public int run(String[] args) throws Exception {
}
printApplicationReport(cliParser.getOptionValue(STATUS_CMD));
} else if (cliParser.hasOption(LIST_CMD)) {
- listAllApplications();
+ if(args.length != 2) {
+ printUsage(opts);
+ return exitCode;
+ }
+ listAllApplications(cliParser.getOptionValue(LIST_CMD));
} else if (cliParser.hasOption(KILL_CMD)) {
if (args.length != 2) {
printUsage(opts);
@@ -93,9 +97,11 @@ private void printUsage(Options opts) {
* @throws YarnException
* @throws IOException
*/
- private void listAllApplications() throws YarnException, IOException {
+ private void listAllApplications(String applicationType)
+ throws YarnException, IOException {
PrintWriter writer = new PrintWriter(sysout);
- List appsReport = client.getApplicationList();
+ List appsReport =
+ client.getApplicationList(applicationType);
writer.println("Total Applications:" + appsReport.size());
writer.printf(APPLICATIONS_PATTERN, "Application-Id",
diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java
index 49d7867..2fe0f15 100644
--- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java
+++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java
@@ -47,6 +47,7 @@
import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import org.apache.hadoop.yarn.client.YarnClient;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.util.Records;
import org.junit.Before;
import org.junit.Test;
@@ -115,10 +116,10 @@ public void testGetAllApplications() throws Exception {
FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN");
List applicationReports = new ArrayList();
applicationReports.add(newApplicationReport);
- when(client.getApplicationList()).thenReturn(applicationReports);
- int result = cli.run(new String[] { "-list" });
+ when(client.getApplicationList("YARN")).thenReturn(applicationReports);
+ int result = cli.run(new String[] { "-list", "YARN" });
assertEquals(0, result);
- verify(client).getApplicationList();
+ verify(client).getApplicationList("YARN");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(baos);
@@ -137,6 +138,43 @@ public void testGetAllApplications() throws Exception {
String appsReportStr = baos.toString("UTF-8");
Assert.assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(1)).write(any(byte[].class), anyInt(), anyInt());
+
+ sysOutStream.reset();
+ ApplicationId applicationId2 = ApplicationId.newInstance(1234, 6);
+ ApplicationReport newApplicationReport2 = ApplicationReport.newInstance(
+ applicationId2, ApplicationAttemptId.newInstance(applicationId2, 2),
+ "user2", "queue2", "appname2", "host2", 125, null,
+ YarnApplicationState.FINISHED, "diagnostics2", "url2", 2, 2,
+ FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.63789f, "NON-YARN");
+ applicationReports.add(newApplicationReport2);
+ when(client.getApplicationList(YarnConfiguration.ALL_APPLICATION_TYPE))
+ .thenReturn(applicationReports);
+ result = cli.run(new String[] { "-list", "ALL" });
+ assertEquals(0, result);
+ verify(client).getApplicationList(YarnConfiguration.ALL_APPLICATION_TYPE);
+ System.out.println(sysOutStream.toString());
+ baos = new ByteArrayOutputStream();
+ pw = new PrintWriter(baos);
+ pw.println("Total Applications:2");
+ pw.print(" Application-Id\t Application-Name");
+ pw.print("\t Application-Type");
+ pw.print("\t User\t Queue\t State\t ");
+ pw.print("Final-State\t Progress");
+ pw.println("\t Tracking-URL");
+ pw.print(" application_1234_0005\t ");
+ pw.print("appname\t YARN\t user\t ");
+ pw.print("queue\t FINISHED\t ");
+ pw.print("SUCCEEDED\t 53.79%");
+ pw.println("\t N/A");
+ pw.print(" application_1234_0006\t ");
+ pw.print("appname2\t NON-YARN\t user2\t ");
+ pw.print("queue2\t FINISHED\t ");
+ pw.print("SUCCEEDED\t 63.79%");
+ pw.println("\t N/A");
+ pw.close();
+ appsReportStr = baos.toString("UTF-8");
+ Assert.assertEquals(appsReportStr, sysOutStream.toString());
+ verify(sysOut, times(2)).write(any(byte[].class), anyInt(), anyInt());
}
@Test
diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ClientRMProtocolPBClientImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ClientRMProtocolPBClientImpl.java
index 8394324..56ee8d2 100644
--- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ClientRMProtocolPBClientImpl.java
+++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ClientRMProtocolPBClientImpl.java
@@ -80,6 +80,7 @@
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SubmitApplicationResponsePBImpl;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.ipc.RPCUtil;
+import org.apache.hadoop.yarn.proto.ClientRMProtocol.AllApplicationsRequestProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllApplicationsRequestProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationReportRequestProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetClusterMetricsRequestProto;
@@ -187,13 +188,17 @@ public SubmitApplicationResponse submitApplication(
@Override
public GetAllApplicationsResponse getAllApplications(
- GetAllApplicationsRequest request) throws YarnException,
- IOException {
+ GetAllApplicationsRequest request, String applicationType)
+ throws YarnException, IOException {
GetAllApplicationsRequestProto requestProto =
((GetAllApplicationsRequestPBImpl) request).getProto();
+ AllApplicationsRequestProto allApplicationsRequestProto =
+ AllApplicationsRequestProto.newBuilder()
+ .setAllApplicationsRequest(requestProto)
+ .setApplicationType(applicationType).build();
try {
return new GetAllApplicationsResponsePBImpl(proxy.getAllApplications(
- null, requestProto));
+ null, allApplicationsRequestProto));
} catch (ServiceException e) {
RPCUtil.unwrapAndThrowException(e);
return null;
diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/service/ClientRMProtocolPBServiceImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/service/ClientRMProtocolPBServiceImpl.java
index caad876..c3075f8 100644
--- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/service/ClientRMProtocolPBServiceImpl.java
+++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/service/ClientRMProtocolPBServiceImpl.java
@@ -65,6 +65,7 @@
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SubmitApplicationRequestPBImpl;
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SubmitApplicationResponsePBImpl;
import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.proto.ClientRMProtocol.AllApplicationsRequestProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllApplicationsRequestProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllApplicationsResponseProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationReportRequestProto;
@@ -169,12 +170,13 @@ public SubmitApplicationResponseProto submitApplication(RpcController arg0,
@Override
public GetAllApplicationsResponseProto getAllApplications(
- RpcController controller, GetAllApplicationsRequestProto proto)
+ RpcController controller, AllApplicationsRequestProto proto)
throws ServiceException {
GetAllApplicationsRequestPBImpl request =
- new GetAllApplicationsRequestPBImpl(proto);
+ new GetAllApplicationsRequestPBImpl(proto.getAllApplicationsRequest());
try {
- GetAllApplicationsResponse response = real.getAllApplications(request);
+ GetAllApplicationsResponse response =
+ real.getAllApplications(request, proto.getApplicationType());
return ((GetAllApplicationsResponsePBImpl)response).getProto();
} catch (YarnException e) {
throw new ServiceException(e);
diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ClientRMService.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ClientRMService.java
index 88bc68b..ec6552f 100644
--- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ClientRMService.java
+++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ClientRMService.java
@@ -393,7 +393,7 @@ public GetClusterMetricsResponse getClusterMetrics(
@Override
public GetAllApplicationsResponse getAllApplications(
- GetAllApplicationsRequest request) throws YarnException {
+ GetAllApplicationsRequest request, String applicationType) throws YarnException {
UserGroupInformation callerUGI;
try {
@@ -407,7 +407,12 @@ public GetAllApplicationsResponse getAllApplications(
for (RMApp application : this.rmContext.getRMApps().values()) {
boolean allowAccess = checkAccess(callerUGI, application.getUser(),
ApplicationAccessType.VIEW_APP, application.getApplicationId());
- reports.add(application.createAndGetApplicationReport(allowAccess));
+ ApplicationReport applicationReport =
+ application.createAndGetApplicationReport(allowAccess);
+ if (YarnConfiguration.ALL_APPLICATION_TYPE.equals(applicationType)
+ || applicationReport.getApplicationType().equals(applicationType)) {
+ reports.add(application.createAndGetApplicationReport(allowAccess));
+ }
}
GetAllApplicationsResponse response =
diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java
index ef36858..b05b809 100644
--- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java
+++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java
@@ -214,7 +214,8 @@ private void verifyOwnerAccess() throws Exception {
// List apps as owner
Assert.assertEquals("App view by owner should list the apps!!", 1,
rmClient.getAllApplications(
- recordFactory.newRecordInstance(GetAllApplicationsRequest.class))
+ recordFactory.newRecordInstance(GetAllApplicationsRequest.class),
+ YarnConfiguration.DEFAULT_APPLICATION_TYPE)
.getApplicationList().size());
// Kill app as owner
@@ -245,7 +246,8 @@ private void verifySuperUserAccess() throws Exception {
// List apps as superUser
Assert.assertEquals("App view by super-user should list the apps!!", 2,
superUserClient.getAllApplications(
- recordFactory.newRecordInstance(GetAllApplicationsRequest.class))
+ recordFactory.newRecordInstance(GetAllApplicationsRequest.class),
+ YarnConfiguration.DEFAULT_APPLICATION_TYPE)
.getApplicationList().size());
// Kill app as the superUser
@@ -276,7 +278,8 @@ private void verifyFriendAccess() throws Exception {
// List apps as friend
Assert.assertEquals("App view by a friend should list the apps!!", 3,
friendClient.getAllApplications(
- recordFactory.newRecordInstance(GetAllApplicationsRequest.class))
+ recordFactory.newRecordInstance(GetAllApplicationsRequest.class),
+ YarnConfiguration.DEFAULT_APPLICATION_TYPE)
.getApplicationList().size());
// Kill app as the friend
@@ -309,7 +312,8 @@ private void verifyEnemyAccess() throws Exception {
// List apps as enemy
List appReports = enemyRmClient
.getAllApplications(recordFactory
- .newRecordInstance(GetAllApplicationsRequest.class))
+ .newRecordInstance(GetAllApplicationsRequest.class),
+ YarnConfiguration.DEFAULT_APPLICATION_TYPE)
.getApplicationList();
Assert.assertEquals("App view by enemy should list the apps!!", 4,
appReports.size());