Skip to content

Commit 0d7a99f

Browse files
committed
YARN-1387. RMWebServices should use ClientRMService for filtering applications (Karthik Kambatla via Sandy Ryza)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1540851 13f79535-47bb-0310-9956-ffa450edef68
1 parent b6b2010 commit 0d7a99f

File tree

7 files changed

+446
-51
lines changed

7 files changed

+446
-51
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ Release 2.3.0 - UNRELEASED
9191
YARN-1121. Changed ResourceManager's state-store to drain all events on
9292
shut-down. (Jian He via vinodkv)
9393

94+
YARN-1387. RMWebServices should use ClientRMService for filtering
95+
applications (Karthik Kambatla via Sandy Ryza)
96+
9497
OPTIMIZATIONS
9598

9699
BUG FIXES

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.EnumSet;
2222
import java.util.Set;
2323

24+
import org.apache.commons.collections.buffer.UnboundedFifoBuffer;
25+
import org.apache.commons.lang.math.LongRange;
2426
import org.apache.hadoop.classification.InterfaceAudience.Private;
2527
import org.apache.hadoop.classification.InterfaceAudience.Public;
2628
import org.apache.hadoop.classification.InterfaceStability.Stable;
@@ -150,4 +152,109 @@ public static GetApplicationsRequest newInstance(
150152
@Unstable
151153
public abstract void
152154
setApplicationStates(EnumSet<YarnApplicationState> applicationStates);
155+
156+
/**
157+
* Set the application states to filter applications on
158+
*
159+
* @param applicationStates all lower-case string representation of the
160+
* application states to filter on
161+
*/
162+
@Private
163+
@Unstable
164+
public abstract void setApplicationStates(Set<String> applicationStates);
165+
166+
/**
167+
* Get the users to filter applications on
168+
*
169+
* @return set of users to filter applications on
170+
*/
171+
@Private
172+
@Unstable
173+
public abstract Set<String> getUsers();
174+
175+
/**
176+
* Set the users to filter applications on
177+
*
178+
* @param users set of users to filter applications on
179+
*/
180+
@Private
181+
@Unstable
182+
public abstract void setUsers(Set<String> users);
183+
184+
/**
185+
* Get the queues to filter applications on
186+
*
187+
* @return set of queues to filter applications on
188+
*/
189+
@Private
190+
@Unstable
191+
public abstract Set<String> getQueues();
192+
193+
/**
194+
* Set the queue to filter applications on
195+
*
196+
* @param queue user to filter applications on
197+
*/
198+
@Private
199+
@Unstable
200+
public abstract void setQueues(Set<String> queue);
201+
202+
/**
203+
* Get the limit on the number applications to return
204+
*
205+
* @return number of applications to limit to
206+
*/
207+
@Private
208+
@Unstable
209+
public abstract long getLimit();
210+
211+
/**
212+
* Limit the number applications to return
213+
*
214+
* @param limit number of applications to limit to
215+
*/
216+
@Private
217+
@Unstable
218+
public abstract void setLimit(long limit);
219+
220+
/**
221+
* Get the range of start times to filter applications on
222+
*
223+
* @return {@link LongRange} of start times to filter applications on
224+
*/
225+
@Private
226+
@Unstable
227+
public abstract LongRange getStartRange();
228+
229+
/**
230+
* Set the range of start times to filter applications on
231+
*
232+
* @param begin beginning of the range
233+
* @param end end of the range
234+
* @throws IllegalArgumentException
235+
*/
236+
@Private
237+
@Unstable
238+
public abstract void setStartRange(long begin, long end)
239+
throws IllegalArgumentException;
240+
241+
/**
242+
* Get the range of finish times to filter applications on
243+
*
244+
* @return {@link LongRange} of finish times to filter applications on
245+
*/
246+
@Private
247+
@Unstable
248+
public abstract LongRange getFinishRange();
249+
250+
/**
251+
* Set the range of finish times to filter applications on
252+
*
253+
* @param begin beginning of the range
254+
* @param end end of the range
255+
* @throws IllegalArgumentException
256+
*/
257+
@Private
258+
@Unstable
259+
public abstract void setFinishRange(long begin, long end);
153260
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ message GetClusterMetricsResponseProto {
125125
message GetApplicationsRequestProto {
126126
repeated string application_types = 1;
127127
repeated YarnApplicationStateProto application_states = 2;
128+
repeated string users = 3;
129+
repeated string queues = 4;
130+
optional int64 limit = 5;
131+
optional int64 start_begin = 6;
132+
optional int64 start_end = 7;
133+
optional int64 finish_begin = 8;
134+
optional int64 finish_end = 9;
128135
}
129136

130137
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: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Set;
2626

27+
import org.apache.commons.lang.math.LongRange;
2728
import org.apache.hadoop.classification.InterfaceAudience.Private;
2829
import org.apache.hadoop.classification.InterfaceStability.Unstable;
2930
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest;
@@ -44,6 +45,10 @@ public class GetApplicationsRequestPBImpl extends GetApplicationsRequest {
4445

4546
Set<String> applicationTypes = null;
4647
EnumSet<YarnApplicationState> applicationStates = null;
48+
Set<String> users = null;
49+
Set<String> queues = null;
50+
long limit = Long.MAX_VALUE;
51+
LongRange start = null, finish = null;
4752

4853
public GetApplicationsRequestPBImpl() {
4954
builder = GetApplicationsRequestProto.newBuilder();
@@ -148,6 +153,26 @@ private void initApplicationStates() {
148153
}
149154
}
150155

156+
private void initUsers() {
157+
if (this.users != null) {
158+
return;
159+
}
160+
GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
161+
List<String> usersList = p.getUsersList();
162+
this.users = new HashSet<String>();
163+
this.users.addAll(usersList);
164+
}
165+
166+
private void initQueues() {
167+
if (this.queues != null) {
168+
return;
169+
}
170+
GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
171+
List<String> queuesList = p.getQueuesList();
172+
this.queues = new HashSet<String>();
173+
this.queues.addAll(queuesList);
174+
}
175+
151176
@Override
152177
public Set<String> getApplicationTypes() {
153178
initApplicationTypes();
@@ -177,6 +202,111 @@ public void setApplicationStates(EnumSet<YarnApplicationState> applicationStates
177202
this.applicationStates = applicationStates;
178203
}
179204

205+
@Override
206+
public void setApplicationStates(Set<String> applicationStates) {
207+
EnumSet<YarnApplicationState> appStates = null;
208+
for (YarnApplicationState state : YarnApplicationState.values()) {
209+
if (applicationStates.contains(state.name().toLowerCase())) {
210+
if (appStates == null) {
211+
appStates = EnumSet.of(state);
212+
} else {
213+
appStates.add(state);
214+
}
215+
}
216+
}
217+
setApplicationStates(appStates);
218+
}
219+
220+
@Override
221+
public Set<String> getUsers() {
222+
initUsers();
223+
return this.users;
224+
}
225+
226+
@Override
227+
public void setUsers(Set<String> users) {
228+
maybeInitBuilder();
229+
if (users == null) {
230+
builder.clearUsers();
231+
}
232+
this.users = users;
233+
}
234+
235+
@Override
236+
public Set<String> getQueues() {
237+
initQueues();
238+
return this.queues;
239+
}
240+
241+
@Override
242+
public void setQueues(Set<String> queues) {
243+
maybeInitBuilder();
244+
if (queues == null) {
245+
builder.clearQueues();
246+
}
247+
this.queues = queues;
248+
}
249+
250+
@Override
251+
public long getLimit() {
252+
if (this.limit == Long.MAX_VALUE) {
253+
GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
254+
this.limit = p.hasLimit() ? p.getLimit() : Long.MAX_VALUE;
255+
}
256+
return this.limit;
257+
}
258+
259+
@Override
260+
public void setLimit(long limit) {
261+
maybeInitBuilder();
262+
this.limit = limit;
263+
}
264+
265+
@Override
266+
public LongRange getStartRange() {
267+
if (this.start == null) {
268+
GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder;
269+
if (p.hasStartBegin() || p.hasFinishBegin()) {
270+
long begin = p.hasStartBegin() ? p.getStartBegin() : 0L;
271+
long end = p.hasStartEnd() ? p.getStartEnd() : Long.MAX_VALUE;
272+
this.start = new LongRange(begin, end);
273+
}
274+
}
275+
return this.start;
276+
}
277+
278+
@Override
279+
public void setStartRange(long begin, long end)
280+
throws IllegalArgumentException {
281+
if (begin > end) {
282+
throw new IllegalArgumentException("begin > end in range (begin, " +
283+
"end): (" + begin + ", " + end + ")");
284+
}
285+
this.start = new LongRange(begin, end);
286+
}
287+
288+
@Override
289+
public LongRange getFinishRange() {
290+
if (this.finish == null) {
291+
GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder;
292+
if (p.hasFinishBegin() || p.hasFinishEnd()) {
293+
long begin = p.hasFinishBegin() ? p.getFinishBegin() : 0L;
294+
long end = p.hasFinishEnd() ? p.getFinishEnd() : Long.MAX_VALUE;
295+
this.finish = new LongRange(begin, end);
296+
}
297+
}
298+
return this.finish;
299+
}
300+
301+
@Override
302+
public void setFinishRange(long begin, long end) {
303+
if (begin > end) {
304+
throw new IllegalArgumentException("begin > end in range (begin, " +
305+
"end): (" + begin + ", " + end + ")");
306+
}
307+
this.finish = new LongRange(begin, end);
308+
}
309+
180310
@Override
181311
public int hashCode() {
182312
return getProto().hashCode();

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: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Set;
2929
import java.util.concurrent.atomic.AtomicInteger;
3030

31+
import org.apache.commons.lang.math.LongRange;
3132
import org.apache.commons.logging.Log;
3233
import org.apache.commons.logging.LogFactory;
3334
import org.apache.hadoop.classification.InterfaceAudience.Private;
@@ -401,6 +402,18 @@ public GetClusterMetricsResponse getClusterMetrics(
401402
@Override
402403
public GetApplicationsResponse getApplications(
403404
GetApplicationsRequest request) throws YarnException {
405+
return getApplications(request, true);
406+
}
407+
408+
/**
409+
* Get applications matching the {@link GetApplicationsRequest}. If
410+
* caseSensitive is set to false, applicationTypes in
411+
* GetApplicationRequest are expected to be in all-lowercase
412+
*/
413+
@Private
414+
public GetApplicationsResponse getApplications(
415+
GetApplicationsRequest request, boolean caseSensitive)
416+
throws YarnException {
404417
UserGroupInformation callerUGI;
405418
try {
406419
callerUGI = UserGroupInformation.getCurrentUser();
@@ -412,11 +425,23 @@ public GetApplicationsResponse getApplications(
412425
Set<String> applicationTypes = request.getApplicationTypes();
413426
EnumSet<YarnApplicationState> applicationStates =
414427
request.getApplicationStates();
428+
Set<String> users = request.getUsers();
429+
Set<String> queues = request.getQueues();
430+
long limit = request.getLimit();
431+
LongRange start = request.getStartRange();
432+
LongRange finish = request.getFinishRange();
415433

416434
List<ApplicationReport> reports = new ArrayList<ApplicationReport>();
435+
long count = 0;
417436
for (RMApp application : this.rmContext.getRMApps().values()) {
437+
if (++count > limit) {
438+
break;
439+
}
418440
if (applicationTypes != null && !applicationTypes.isEmpty()) {
419-
if (!applicationTypes.contains(application.getApplicationType())) {
441+
String appTypeToMatch = caseSensitive
442+
? application.getApplicationType()
443+
: application.getApplicationType().toLowerCase();
444+
if (!applicationTypes.contains(appTypeToMatch)) {
420445
continue;
421446
}
422447
}
@@ -427,6 +452,25 @@ public GetApplicationsResponse getApplications(
427452
continue;
428453
}
429454
}
455+
456+
if (users != null && !users.isEmpty() &&
457+
!users.contains(application.getUser())) {
458+
continue;
459+
}
460+
461+
if (queues != null && !queues.isEmpty() &&
462+
!queues.contains(application.getQueue())) {
463+
continue;
464+
}
465+
466+
if (start != null && !start.containsLong(application.getStartTime())) {
467+
continue;
468+
}
469+
470+
if (finish != null && !finish.containsLong(application.getFinishTime())) {
471+
continue;
472+
}
473+
430474
boolean allowAccess = checkAccess(callerUGI, application.getUser(),
431475
ApplicationAccessType.VIEW_APP, application);
432476
reports.add(application.createAndGetApplicationReport(

0 commit comments

Comments
 (0)