Skip to content

Commit 462057b

Browse files
szilard-nemethAdam Antal
authored andcommitted
YARN-10035. Add ability to filter the Cluster Applications API request by name. Contributed by Adam Antal
Ref.: CDH-77912 (cherry picked from commit 768ee22) Conflicts: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/ApplicationsRequestBuilder.java - Due to missing YARN-8501 commit. The behaviour was added to RMWebServices hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWSConsts.java - Trivial conflict - some constants were missing (YARN-8028,YARN-9489,YARN-9497,YARN-9578) hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java - Moderate conflict due to missing YARN-8501. Added the logic from ApplicationsRequestBuilder hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java - Missing commit YARN-8028 contained extra testcases Change-Id: I06880caa9e95bb3ec2142f5a7818f70e7fabc3d6
1 parent d9da56f commit 462057b

File tree

20 files changed

+87
-19
lines changed

20 files changed

+87
-19
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetApplicationsRequest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,22 @@ public abstract void setStartRange(long begin, long end)
393393
@Private
394394
@Unstable
395395
public abstract void setScope(ApplicationsRequestScope scope);
396+
397+
/**
398+
* Set the name to filter applications.
399+
*
400+
* @return the name
401+
*/
402+
@Private
403+
@Unstable
404+
public abstract String getName();
405+
406+
/**
407+
* Get the name to filter applications.
408+
*
409+
* @param name of the application
410+
*/
411+
@Private
412+
@Unstable
413+
public abstract void setName(String name);
396414
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_service_protos.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ message GetApplicationsRequestProto {
199199
optional int64 finish_end = 9;
200200
repeated string applicationTags = 10;
201201
optional ApplicationsRequestScopeProto scope = 11 [default = ALL];
202+
optional string name = 12;
202203
}
203204

204205
message GetApplicationsResponseProto {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/GetApplicationsRequestPBImpl.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class GetApplicationsRequestPBImpl extends GetApplicationsRequest {
5555
LongRange finish = null;
5656
private Set<String> applicationTags;
5757
private ApplicationsRequestScope scope;
58+
private String name;
5859

5960
public GetApplicationsRequestPBImpl() {
6061
builder = GetApplicationsRequestProto.newBuilder();
@@ -121,6 +122,9 @@ public YarnApplicationStateProto apply(YarnApplicationState input) {
121122
builder.clearQueues();
122123
builder.addAllQueues(queues);
123124
}
125+
if (name != null) {
126+
builder.setName(name);
127+
}
124128
}
125129

126130
private void maybeInitBuilder() {
@@ -370,6 +374,27 @@ public void setFinishRange(long begin, long end) {
370374
this.finish = new LongRange(begin, end);
371375
}
372376

377+
@Override
378+
public synchronized String getName() {
379+
GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
380+
if (this.name != null) {
381+
return this.name;
382+
}
383+
if (p.hasName()) {
384+
this.name = p.getName();
385+
}
386+
return this.name;
387+
}
388+
389+
@Override
390+
public synchronized void setName(String name) {
391+
maybeInitBuilder();
392+
if (name == null) {
393+
builder.clearName();
394+
}
395+
this.name = name;
396+
}
397+
373398
@Override
374399
public int hashCode() {
375400
return getProto().hashCode();

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ public TimelineAbout about(
121121
public AppsInfo get(@Context HttpServletRequest req,
122122
@Context HttpServletResponse res) {
123123
return getApps(req, res, null, Collections.<String> emptySet(), null, null,
124-
null, null, null, null, null, null, Collections.<String> emptySet());
124+
null, null, null, null, null, null, null,
125+
Collections.<String> emptySet());
125126
}
126127

127128
@GET
@@ -140,12 +141,13 @@ public AppsInfo getApps(@Context HttpServletRequest req,
140141
@QueryParam("startedTimeEnd") String startedEnd,
141142
@QueryParam("finishedTimeBegin") String finishBegin,
142143
@QueryParam("finishedTimeEnd") String finishEnd,
144+
@QueryParam("name") String name,
143145
@QueryParam("applicationTypes") Set<String> applicationTypes) {
144146
init(res);
145147
validateStates(stateQuery, statesQuery);
146148
return super.getApps(req, res, stateQuery, statesQuery, finalStatusQuery,
147149
userQuery, queueQuery, count, startedBegin, startedEnd, finishBegin,
148-
finishEnd, applicationTypes);
150+
finishEnd, name, applicationTypes);
149151
}
150152

151153
@GET

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/webapp/WebServices.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public WebServices(ApplicationBaseProtocol appBaseProt) {
7575
public AppsInfo getApps(HttpServletRequest req, HttpServletResponse res,
7676
String stateQuery, Set<String> statesQuery, String finalStatusQuery,
7777
String userQuery, String queueQuery, String count, String startedBegin,
78-
String startedEnd, String finishBegin, String finishEnd,
78+
String startedEnd, String finishBegin, String finishEnd, String nameQuery,
7979
Set<String> applicationTypes) {
8080
UserGroupInformation callerUGI = getUser(req);
8181
boolean checkEnd = false;
@@ -207,6 +207,11 @@ public Collection<ApplicationReport> run() throws Exception {
207207
&& (appReport.getFinishTime() < fBegin || appReport.getFinishTime() > fEnd)) {
208208
continue;
209209
}
210+
211+
if (nameQuery != null && !nameQuery.equals(appReport.getName())) {
212+
continue;
213+
}
214+
210215
AppInfo app = new AppInfo(appReport);
211216

212217
allApps.add(app);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ClientRMService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
803803
LongRange start = request.getStartRange();
804804
LongRange finish = request.getFinishRange();
805805
ApplicationsRequestScope scope = request.getScope();
806+
String name = request.getName();
806807

807808
final Map<ApplicationId, RMApp> apps = rmContext.getRMApps();
808809
Iterator<RMApp> appsIter;
@@ -914,6 +915,10 @@ public void remove() {
914915
continue;
915916
}
916917

918+
if (name != null && !name.equals(application.getName())) {
919+
continue;
920+
}
921+
917922
reports.add(application.createAndGetApplicationReport(
918923
callerUGI.getUserName(), allowAccess));
919924
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWSConsts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public final class RMWSConsts {
209209
public static final String GET_LABELS = "get-labels";
210210
public static final String DESELECTS = "deSelects";
211211
public static final String CONTAINERS = "containers";
212+
public static final String NAME = "name";
212213

213214
private RMWSConsts() {
214215
// not called

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServiceProtocol.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ String dumpSchedulerLogs(String time, HttpServletRequest hsr)
160160
* @param finishEnd filter the result by finish end time. It is a QueryParam.
161161
* @param applicationTypes filter the result by types. It is a QueryParam.
162162
* @param applicationTags filter the result by tags. It is a QueryParam.
163+
* @param name filter the name of the application. It is a QueryParam.
163164
* @param unselectedFields De-selected params to avoid from report. It is a
164165
* QueryParam.
165166
* @return all apps in the cluster
@@ -169,7 +170,7 @@ AppsInfo getApps(HttpServletRequest hsr, String stateQuery,
169170
Set<String> statesQuery, String finalStatusQuery, String userQuery,
170171
String queueQuery, String count, String startedBegin, String startedEnd,
171172
String finishBegin, String finishEnd, Set<String> applicationTypes,
172-
Set<String> applicationTags, Set<String> unselectedFields);
173+
Set<String> applicationTags, String name, Set<String> unselectedFields);
173174

174175
/**
175176
* This method retrieve all the activities in a specific node, and it is

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ public AppsInfo getApps(@Context HttpServletRequest hsr,
449449
@QueryParam(RMWSConsts.FINISHED_TIME_END) String finishEnd,
450450
@QueryParam(RMWSConsts.APPLICATION_TYPES) Set<String> applicationTypes,
451451
@QueryParam(RMWSConsts.APPLICATION_TAGS) Set<String> applicationTags,
452+
@QueryParam(RMWSConsts.NAME) String name,
452453
@QueryParam(RMWSConsts.DESELECTS) Set<String> unselectedFields) {
453454
boolean checkCount = false;
454455
boolean checkStart = false;
@@ -579,6 +580,10 @@ public AppsInfo getApps(@Context HttpServletRequest hsr,
579580
request.setUsers(users);
580581
}
581582

583+
if (name != null) {
584+
request.setName(name);
585+
}
586+
582587
List<ApplicationReport> appReports = null;
583588
try {
584589
appReports = rm.getClientRMService().getApplications(request)

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,14 @@ public void testAppsRace() throws Exception {
666666
// verify we don't get any apps when querying
667667
HttpServletRequest mockHsr = mock(HttpServletRequest.class);
668668
AppsInfo appsInfo = webSvc.getApps(mockHsr, null, emptySet, null,
669-
null, null, null, null, null, null, null, emptySet, emptySet, null);
669+
null, null, null, null, null, null, null, emptySet, emptySet, null,
670+
null);
670671
assertTrue(appsInfo.getApps().isEmpty());
671672

672673
// verify we don't get an NPE when specifying a final status query
673674
appsInfo = webSvc.getApps(mockHsr, null, emptySet, "FAILED",
674-
null, null, null, null, null, null, null, emptySet, emptySet, null);
675+
null, null, null, null, null, null, null, emptySet, emptySet, null,
676+
null);
675677
assertTrue(appsInfo.getApps().isEmpty());
676678
}
677679

0 commit comments

Comments
 (0)