Skip to content

Commit 768ee22

Browse files
YARN-10035. Add ability to filter the Cluster Applications API request by name. Contributed by Adam Antal
1 parent 4a76ab7 commit 768ee22

File tree

21 files changed

+95
-20
lines changed

21 files changed

+95
-20
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
@@ -206,6 +206,7 @@ message GetApplicationsRequestProto {
206206
optional int64 finish_end = 9;
207207
repeated string applicationTags = 10;
208208
optional ApplicationsRequestScopeProto scope = 11 [default = ALL];
209+
optional string name = 12;
209210
}
210211

211212
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
Range<Long> 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 synchronized void setFinishRange(long begin, long end) {
370374
this.finish = Range.between(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
@@ -107,7 +107,8 @@ public TimelineAbout about(
107107
public AppsInfo get(@Context HttpServletRequest req,
108108
@Context HttpServletResponse res) {
109109
return getApps(req, res, null, Collections.<String> emptySet(), null, null,
110-
null, null, null, null, null, null, Collections.<String> emptySet());
110+
null, null, null, null, null, null, null,
111+
Collections.<String> emptySet());
111112
}
112113

113114
@GET
@@ -126,12 +127,13 @@ public AppsInfo getApps(@Context HttpServletRequest req,
126127
@QueryParam("startedTimeEnd") String startedEnd,
127128
@QueryParam("finishedTimeBegin") String finishBegin,
128129
@QueryParam("finishedTimeEnd") String finishEnd,
130+
@QueryParam("name") String name,
129131
@QueryParam("applicationTypes") Set<String> applicationTypes) {
130132
initForReadableEndpoints(res);
131133
validateStates(stateQuery, statesQuery);
132134
return super.getApps(req, res, stateQuery, statesQuery, finalStatusQuery,
133135
userQuery, queueQuery, count, startedBegin, startedEnd, finishBegin,
134-
finishEnd, applicationTypes);
136+
finishEnd, name, applicationTypes);
135137
}
136138

137139
@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
@@ -865,6 +865,7 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
865865
Range<Long> start = request.getStartRange();
866866
Range<Long> finish = request.getFinishRange();
867867
ApplicationsRequestScope scope = request.getScope();
868+
String name = request.getName();
868869

869870
final Map<ApplicationId, RMApp> apps = rmContext.getRMApps();
870871
Iterator<RMApp> appsIter = apps.values().iterator();
@@ -943,6 +944,10 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
943944
continue;
944945
}
945946

947+
if (name != null && !name.equals(application.getName())) {
948+
continue;
949+
}
950+
946951
reports.add(application.createAndGetApplicationReport(
947952
callerUGI.getUserName(), allowAccess));
948953
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class ApplicationsRequestBuilder {
4444
private long finishTimeEnd = Long.MAX_VALUE;
4545
private Set<String> appTypes = Sets.newHashSet();
4646
private Set<String> appTags = Sets.newHashSet();
47+
private String name = null;
4748
private ResourceManager rm;
4849

4950
private ApplicationsRequestBuilder() {
@@ -137,6 +138,11 @@ public ApplicationsRequestBuilder withApplicationTags(
137138
return this;
138139
}
139140

141+
public ApplicationsRequestBuilder withName(String applicationName) {
142+
name = applicationName;
143+
return this;
144+
}
145+
140146
private void validate() {
141147
queues.forEach(q -> validateQueueExists(rm, q));
142148
validateLimit();
@@ -225,6 +231,9 @@ public GetApplicationsRequest build() {
225231
if (!appTags.isEmpty()) {
226232
request.setApplicationTags(appTags);
227233
}
234+
if (name != null) {
235+
request.setName(name);
236+
}
228237

229238
return request;
230239
}

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
@@ -245,6 +245,7 @@ public final class RMWSConsts {
245245
public static final String COMMAND = "command";
246246
public static final String ACTIONS = "actions";
247247
public static final String SUMMARIZE = "summarize";
248+
public static final String NAME = "name";
248249

249250
private RMWSConsts() {
250251
// 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
@@ -186,6 +186,7 @@ ResourceInfo updateNodeResource(HttpServletRequest hsr, String nodeId,
186186
* @param finishEnd filter the result by finish end time. It is a QueryParam.
187187
* @param applicationTypes filter the result by types. It is a QueryParam.
188188
* @param applicationTags filter the result by tags. It is a QueryParam.
189+
* @param name filter the name of the application. It is a QueryParam.
189190
* @param unselectedFields De-selected params to avoid from report. It is a
190191
* QueryParam.
191192
* @return all apps in the cluster
@@ -195,7 +196,7 @@ AppsInfo getApps(HttpServletRequest hsr, String stateQuery,
195196
Set<String> statesQuery, String finalStatusQuery, String userQuery,
196197
String queueQuery, String count, String startedBegin, String startedEnd,
197198
String finishBegin, String finishEnd, Set<String> applicationTypes,
198-
Set<String> applicationTags, Set<String> unselectedFields);
199+
Set<String> applicationTags, String name, Set<String> unselectedFields);
199200

200201
/**
201202
* 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ public AppsInfo getApps(@Context HttpServletRequest hsr,
610610
@QueryParam(RMWSConsts.FINISHED_TIME_END) String finishEnd,
611611
@QueryParam(RMWSConsts.APPLICATION_TYPES) Set<String> applicationTypes,
612612
@QueryParam(RMWSConsts.APPLICATION_TAGS) Set<String> applicationTags,
613+
@QueryParam(RMWSConsts.NAME) String name,
613614
@QueryParam(RMWSConsts.DESELECTS) Set<String> unselectedFields) {
614615

615616
initForReadableEndpoints();
@@ -627,6 +628,7 @@ public AppsInfo getApps(@Context HttpServletRequest hsr,
627628
.withFinishTimeEnd(finishEnd)
628629
.withApplicationTypes(applicationTypes)
629630
.withApplicationTags(applicationTags)
631+
.withName(name)
630632
.build();
631633

632634
List<ApplicationReport> appReports;

0 commit comments

Comments
 (0)