diff --git hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/main/java/org/apache/hadoop/mapred/ResourceMgrDelegate.java hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/main/java/org/apache/hadoop/mapred/ResourceMgrDelegate.java index f4c89f6..119658b 100644 --- hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/main/java/org/apache/hadoop/mapred/ResourceMgrDelegate.java +++ hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/main/java/org/apache/hadoop/mapred/ResourceMgrDelegate.java @@ -20,7 +20,9 @@ import java.io.IOException; import java.net.InetSocketAddress; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -129,7 +131,8 @@ protected void serviceStop() throws Exception { public JobStatus[] getAllJobs() throws IOException, InterruptedException { try { - return TypeConverter.fromYarnApps(client.getApplicationList(), this.conf); + return TypeConverter.fromYarnApps( + client.getApplicationList(new HashSet()), this.conf); } catch (YarnException e) { throw new IOException(e); } @@ -297,9 +300,9 @@ public ApplicationReport getApplicationReport(ApplicationId appId) } @Override - public List getApplicationList() throws YarnException, - IOException { - return client.getApplicationList(); + public List getApplicationList( + Set applicationTypes) throws YarnException, IOException { + return client.getApplicationList(applicationTypes); } @Override diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllApplicationsRequest.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllApplicationsRequest.java index 8890238..0088572 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllApplicationsRequest.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllApplicationsRequest.java @@ -18,8 +18,12 @@ package org.apache.hadoop.yarn.api.protocolrecords; +import java.util.Set; + +import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.classification.InterfaceAudience.Public; import org.apache.hadoop.classification.InterfaceStability.Stable; +import org.apache.hadoop.classification.InterfaceStability.Unstable; import org.apache.hadoop.yarn.api.ApplicationClientProtocol; import org.apache.hadoop.yarn.util.Records; @@ -36,9 +40,32 @@ public abstract class GetAllApplicationsRequest { @Public @Stable - public static GetAllApplicationsRequest newInstance() { + public static GetAllApplicationsRequest newInstance( + Set applicationTypes) { GetAllApplicationsRequest request = Records.newRecord(GetAllApplicationsRequest.class); + request.setApplicationTypes(applicationTypes); return request; } + + /** + * Get the application types to filter applications on + * + * @return Set of Application Types to filter on + */ + @Public + @Stable + public abstract Set getApplicationTypes(); + + /** + * Set the application types to filter applications on + * + * @param applicationTypes + * A Set of Application Types to filter on. + * If not defined, match all applications + */ + @Private + @Unstable + public abstract void + setApplicationTypes(Set applicationTypes); } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_service_protos.proto hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_service_protos.proto index 791239d..29edbd6 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_service_protos.proto +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_service_protos.proto @@ -118,6 +118,7 @@ message GetClusterMetricsResponseProto { } message GetAllApplicationsRequestProto { + repeated string applicationType = 1; } message GetAllApplicationsResponseProto { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/YarnClient.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/YarnClient.java index 869a52b..fc8c68f 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/YarnClient.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/YarnClient.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.util.List; +import java.util.Set; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience.Private; @@ -173,8 +174,8 @@ public abstract ApplicationReport getApplicationReport(ApplicationId appId) * @throws YarnException * @throws IOException */ - public abstract List getApplicationList() throws YarnException, - IOException; + public abstract List getApplicationList( + Set applicationTypes) throws YarnException, IOException; /** *

diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/YarnClientImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/YarnClientImpl.java index cbe8120..277b94d 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/YarnClientImpl.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/YarnClientImpl.java @@ -22,6 +22,7 @@ import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.List; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -204,10 +205,10 @@ public ApplicationReport getApplicationReport(ApplicationId appId) } @Override - public List getApplicationList() - throws YarnException, IOException { + public List getApplicationList( + Set applicationTypes) throws YarnException, IOException { GetAllApplicationsRequest request = - Records.newRecord(GetAllApplicationsRequest.class); + GetAllApplicationsRequest.newInstance(applicationTypes); GetAllApplicationsResponse response = rmClient.getAllApplications(request); 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 312aab2..506dff1 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 @@ -21,11 +21,14 @@ import java.io.IOException; import java.io.PrintWriter; import java.text.DecimalFormat; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.classification.InterfaceStability.Unstable; @@ -56,8 +59,14 @@ 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(KILL_CMD, true, "Kills the application."); + opts.addOption(HELP_CMD, false, "Displays help for all commands"); + Option list_opt = new Option(LIST_CMD, true, "Lists all the applications" + + " or ones matching optionally provided application types from RM. " + + "For multiple application types, " + + "use -list --appTypes=,"); + list_opt.setOptionalArg(true); + opts.addOption(list_opt); CommandLine cliParser = new GnuParser().parse(opts, args); int exitCode = -1; @@ -68,13 +77,27 @@ public int run(String[] args) throws Exception { } printApplicationReport(cliParser.getOptionValue(STATUS_CMD)); } else if (cliParser.hasOption(LIST_CMD)) { - listAllApplications(); + String env = cliParser.getOptionValue(LIST_CMD); + Set appTypes = new HashSet(); + if (env != null) { + int index = env.indexOf("="); + if (index != -1 && index < (env.length() - 1)) { + String[] types = env.substring(index + 1).split(","); + for (String type : types) { + appTypes.add(type.trim()); + } + } + } + listAllApplications(appTypes); } else if (cliParser.hasOption(KILL_CMD)) { if (args.length != 2) { printUsage(opts); return exitCode; } killApplication(cliParser.getOptionValue(KILL_CMD)); + } else if (cliParser.hasOption(HELP_CMD)) { + printUsage(opts); + return 0; } else { syserr.println("Invalid Command Usage : "); printUsage(opts); @@ -97,9 +120,11 @@ private void printUsage(Options opts) { * @throws YarnException * @throws IOException */ - private void listAllApplications() throws YarnException, IOException { + private void listAllApplications(Set appTypes) + throws YarnException, IOException { PrintWriter writer = new PrintWriter(sysout); - List appsReport = client.getApplicationList(); + List appsReport = + client.getApplicationList(appTypes); writer.println("Total Applications:" + appsReport.size()); writer.printf(APPLICATIONS_PATTERN, "Application-Id", diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/YarnCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/YarnCLI.java index 5f86033..921c135 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/YarnCLI.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/YarnCLI.java @@ -33,6 +33,7 @@ public static final String STATUS_CMD = "status"; public static final String LIST_CMD = "list"; public static final String KILL_CMD = "kill"; + public static final String HELP_CMD = "help"; protected PrintStream sysout; protected PrintStream syserr; protected YarnClient client; 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 365bc8e..d15e3f8 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 @@ -32,7 +32,9 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import junit.framework.Assert; @@ -115,10 +117,31 @@ 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" }); + + 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); + + ApplicationId applicationId3 = ApplicationId.newInstance(1234, 7); + ApplicationReport newApplicationReport3 = ApplicationReport.newInstance( + applicationId3, ApplicationAttemptId.newInstance(applicationId3, 3), + "user3", "queue3", "appname3", "host3", 126, null, + YarnApplicationState.FINISHED, "diagnostics3", "url3", 3, 3, + FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.73789f, "MAPREDUCE"); + applicationReports.add(newApplicationReport3); + + Set appType1 = new HashSet(); + appType1.add("YARN"); + + when(client.getApplicationList(appType1)).thenReturn( + getApplicationReports(applicationReports, appType1)); + int result = cli.run(new String[] { "-list", "--appTypes = YARN" }); assertEquals(0, result); - verify(client).getApplicationList(); + verify(client).getApplicationList(appType1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); @@ -137,8 +160,93 @@ 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(); + Set appType2 = new HashSet(); + appType2.add("YARN"); + appType2.add("NON-YARN"); + when(client.getApplicationList(appType2)).thenReturn( + getApplicationReports(applicationReports, appType2)); + + result = cli.run(new String[] { "-list", "--appTypes = YARN, NON-YARN" }); + assertEquals(0, result); + verify(client).getApplicationList(appType2); + 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()); + + sysOutStream.reset(); + Set appType3 = new HashSet(); + when(client.getApplicationList(appType3)).thenReturn( + getApplicationReports(applicationReports, appType3)); + result = cli.run(new String[] { "-list" }); + assertEquals(0, result); + verify(client).getApplicationList(appType3); + + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("Total Applications:3"); + 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.print(" application_1234_0007\t "); + pw.print("appname3\t MAPREDUCE\t user3\t "); + pw.print("queue3\t FINISHED\t "); + pw.print("SUCCEEDED\t 73.79%"); + pw.println("\t N/A"); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(3)).write(any(byte[].class), anyInt(), anyInt()); } + private List getApplicationReports( + List applicationReports, + Set appTypes) { + + List appReports = new ArrayList(); + boolean bypassFilter = appTypes.isEmpty(); + + for (ApplicationReport appReport : applicationReports) { + if (!(bypassFilter || appTypes.contains( + appReport.getApplicationType()))) { + continue; + } + appReports.add(appReport); + } + return appReports; + } @Test public void testKillApplication() throws Exception { ApplicationCLI cli = createAndGetAppCLI(); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/GetAllApplicationsRequestPBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/GetAllApplicationsRequestPBImpl.java index 24b16d0..3915fed 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/GetAllApplicationsRequestPBImpl.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/GetAllApplicationsRequestPBImpl.java @@ -18,10 +18,15 @@ package org.apache.hadoop.yarn.api.protocolrecords.impl.pb; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.classification.InterfaceStability.Unstable; import org.apache.hadoop.yarn.api.protocolrecords.GetAllApplicationsRequest; import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllApplicationsRequestProto; +import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllApplicationsRequestProtoOrBuilder; @Private @Unstable @@ -30,6 +35,8 @@ GetAllApplicationsRequestProto.Builder builder = null; boolean viaProto = false; + Set applicationTypes = null; + public GetAllApplicationsRequestPBImpl() { builder = GetAllApplicationsRequestProto.newBuilder(); } @@ -40,11 +47,67 @@ public GetAllApplicationsRequestPBImpl(GetAllApplicationsRequestProto proto) { } public GetAllApplicationsRequestProto getProto() { + mergeLocalToProto(); proto = viaProto ? proto : builder.build(); viaProto = true; return proto; } + private void mergeLocalToProto() { + if (viaProto) + maybeInitBuilder(); + mergeLocalToBuilder(); + proto = builder.build(); + viaProto = true; + } + + private void mergeLocalToBuilder() { + if (this.applicationTypes != null) { + addApplicationTypesToProto(); + } + } + + private void addApplicationTypesToProto() { + maybeInitBuilder(); + builder.clearApplicationType(); + if (this.applicationTypes == null) + return; + builder.addAllApplicationType(applicationTypes); + } + + private void maybeInitBuilder() { + if (viaProto || builder == null) { + builder = GetAllApplicationsRequestProto.newBuilder(proto); + } + viaProto = false; + } + + private void initApplicationTypes() { + if (this.applicationTypes != null) { + return; + } + GetAllApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder; + List appTypeList = p.getApplicationTypeList(); + this.applicationTypes = new HashSet(); + this.applicationTypes.addAll(appTypeList); + } + + @Override + public Set getApplicationTypes() { + initApplicationTypes(); + return this.applicationTypes; + } + + @Override + public void setApplicationTypes(Set applicationType) { + if (applicationType == null) { + return; + } + initApplicationTypes(); + this.applicationTypes.clear(); + this.applicationTypes.addAll(applicationType); + } + @Override public int hashCode() { return getProto().hashCode(); 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 512ba83..a1bd02c 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 @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.EnumSet; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; @@ -401,8 +402,14 @@ public GetAllApplicationsResponse getAllApplications( throw RPCUtil.getRemoteException(ie); } + Set applicationTypes = request.getApplicationTypes(); + boolean bypassFilter = applicationTypes.isEmpty(); List reports = new ArrayList(); for (RMApp application : this.rmContext.getRMApps().values()) { + if (!(bypassFilter || applicationTypes.contains(application + .getApplicationType()))) { + continue; + } boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application.getApplicationId()); reports.add(application.createAndGetApplicationReport(allowAccess)); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java index 1c185ac..83c8270 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java @@ -26,7 +26,9 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.security.PrivilegedExceptionAction; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CyclicBarrier; @@ -41,6 +43,8 @@ import org.apache.hadoop.security.token.Token; import org.apache.hadoop.yarn.MockApps; import org.apache.hadoop.yarn.api.ApplicationClientProtocol; +import org.apache.hadoop.yarn.api.protocolrecords.GetAllApplicationsRequest; +import org.apache.hadoop.yarn.api.protocolrecords.GetAllApplicationsResponse; import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest; import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse; import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodesRequest; @@ -48,6 +52,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.GetQueueInfoResponse; import org.apache.hadoop.yarn.api.protocolrecords.RenewDelegationTokenRequest; import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest; +import org.apache.hadoop.yarn.api.records.ApplicationAccessType; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationReport; import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; @@ -87,6 +92,8 @@ private RecordFactory recordFactory = RecordFactoryProvider .getRecordFactory(null); + private String appType = "MockApp"; + private static RMDelegationTokenSecretManager dtsm; @BeforeClass @@ -271,11 +278,18 @@ public void testAppSubmit() throws Exception { new EventHandler() { public void handle(Event event) {} }); + ApplicationId appId1 = getApplicationId(100); + + ApplicationACLsManager mockAclsManager = mock(ApplicationACLsManager.class); + when( + mockAclsManager.checkAccess(UserGroupInformation.getCurrentUser(), + ApplicationAccessType.VIEW_APP, null, appId1)).thenReturn(true); ClientRMService rmService = - new ClientRMService(rmContext, yarnScheduler, appManager, null, null); + new ClientRMService(rmContext, yarnScheduler, appManager, + mockAclsManager, null); // without name and queue - ApplicationId appId1 = getApplicationId(100); + SubmitApplicationRequest submitRequest1 = mockSubmitAppRequest( appId1, null, null); try { @@ -296,6 +310,8 @@ public void handle(Event event) {} ApplicationId appId2 = getApplicationId(101); SubmitApplicationRequest submitRequest2 = mockSubmitAppRequest( appId2, name, queue); + submitRequest2.getApplicationSubmissionContext().setApplicationType( + "matchType"); try { rmService.submitApplication(submitRequest2); } catch (YarnException e) { @@ -314,6 +330,25 @@ public void handle(Event event) {} Assert.assertTrue("The thrown exception is not expected.", e.getMessage().contains("Cannot add a duplicate!")); } + + GetAllApplicationsRequest getAllAppsRequest = + GetAllApplicationsRequest.newInstance(new HashSet()); + GetAllApplicationsResponse getAllApplicationsResponse = + rmService.getAllApplications(getAllAppsRequest); + Assert.assertEquals(5, + getAllApplicationsResponse.getApplicationList().size()); + + Set appTypes = new HashSet(); + appTypes.add("matchType"); + + getAllAppsRequest = GetAllApplicationsRequest.newInstance(appTypes); + getAllApplicationsResponse = + rmService.getAllApplications(getAllAppsRequest); + Assert.assertEquals(1, + getAllApplicationsResponse.getApplicationList().size()); + Assert.assertEquals(appId2, + getAllApplicationsResponse.getApplicationList() + .get(0).getApplicationId()); } @Test(timeout=4000) @@ -395,6 +430,7 @@ private SubmitApplicationRequest mockSubmitAppRequest(ApplicationId appId, submissionContext.setQueue(queue); submissionContext.setApplicationId(appId); submissionContext.setResource(resource); + submissionContext.setApplicationType(appType); SubmitApplicationRequest submitRequest = recordFactory.newRecordInstance(SubmitApplicationRequest.class);