YARN-6871. Add additional deSelects params in RMWebServices#getAppReport. (Tanuj Nayak via Subru).

This commit is contained in:
Subru Krishnan 2017-10-20 17:19:29 -07:00
parent 062d9c9bab
commit 9bd77a6d9d
3 changed files with 156 additions and 35 deletions

View File

@ -91,7 +91,16 @@ public enum DeSelectType {
* <code>RESOURCE_REQUESTS</code> is the first * <code>RESOURCE_REQUESTS</code> is the first
* supported type from YARN-6280. * supported type from YARN-6280.
*/ */
RESOURCE_REQUESTS("resourceRequests"); RESOURCE_REQUESTS("resourceRequests"),
/**
* <code>APP_TIMEOUTS, APP_NODE_LABEL_EXPRESSION, AM_NODE_LABEL_EXPRESSION,
* RESOURCE_INFO</code> are additionally supported parameters added in
* YARN-6871.
*/
TIMEOUTS("timeouts"),
APP_NODE_LABEL_EXPRESSION("appNodeLabelExpression"),
AM_NODE_LABEL_EXPRESSION("amNodeLabelExpression"),
RESOURCE_INFO("resourceInfo");
private final String literals; private final String literals;

View File

@ -121,7 +121,7 @@ public class AppInfo {
protected String amNodeLabelExpression; protected String amNodeLabelExpression;
protected ResourcesInfo resourceInfo = null; protected ResourcesInfo resourceInfo = null;
protected AppTimeoutsInfo timeouts = new AppTimeoutsInfo(); private AppTimeoutsInfo timeouts;
public AppInfo() { public AppInfo() {
} // JAXB needs this } // JAXB needs this
@ -241,44 +241,85 @@ public AppInfo(ResourceManager rm, RMApp app, Boolean hasAccess,
unmanagedApplication = appSubmissionContext.getUnmanagedAM(); unmanagedApplication = appSubmissionContext.getUnmanagedAM();
appNodeLabelExpression = appNodeLabelExpression =
app.getApplicationSubmissionContext().getNodeLabelExpression(); app.getApplicationSubmissionContext().getNodeLabelExpression();
amNodeLabelExpression = (unmanagedApplication) ? null /*
: app.getAMResourceRequests().get(0).getNodeLabelExpression(); * When the deSelects parameter contains "amNodeLabelExpression", objects
* pertaining to the amNodeLabelExpression are not returned. By default,
* this is not skipped. (YARN-6871)
*/
if(!deSelects.contains(DeSelectType.AM_NODE_LABEL_EXPRESSION)) {
amNodeLabelExpression = (unmanagedApplication) ?
null :
app.getAMResourceRequests().get(0).getNodeLabelExpression();
}
/*
* When the deSelects parameter contains "appNodeLabelExpression", objects
* pertaining to the appNodeLabelExpression are not returned. By default,
* this is not skipped. (YARN-6871)
*/
if (!deSelects.contains(DeSelectType.APP_NODE_LABEL_EXPRESSION)) {
appNodeLabelExpression =
app.getApplicationSubmissionContext().getNodeLabelExpression();
}
/*
* When the deSelects parameter contains "amNodeLabelExpression", objects
* pertaining to the amNodeLabelExpression are not returned. By default,
* this is not skipped. (YARN-6871)
*/
if (!deSelects.contains(DeSelectType.AM_NODE_LABEL_EXPRESSION)) {
amNodeLabelExpression = (unmanagedApplication) ?
null :
app.getAMResourceRequests().get(0).getNodeLabelExpression();
}
/*
* When the deSelects parameter contains "resourceInfo", ResourceInfo
* objects are not returned. Default behavior is no skipping. (YARN-6871)
*/
// Setting partition based resource usage of application // Setting partition based resource usage of application
ResourceScheduler scheduler = rm.getRMContext().getScheduler(); if (!deSelects.contains(DeSelectType.RESOURCE_INFO)) {
if (scheduler instanceof CapacityScheduler) { ResourceScheduler scheduler = rm.getRMContext().getScheduler();
RMAppAttempt attempt = app.getCurrentAppAttempt(); if (scheduler instanceof CapacityScheduler) {
if (null != attempt) { RMAppAttempt attempt = app.getCurrentAppAttempt();
FiCaSchedulerApp ficaAppAttempt = ((CapacityScheduler) scheduler) if (null != attempt) {
.getApplicationAttempt(attempt.getAppAttemptId()); FiCaSchedulerApp ficaAppAttempt = ((CapacityScheduler) scheduler)
resourceInfo = null != ficaAppAttempt .getApplicationAttempt(attempt.getAppAttemptId());
? new ResourcesInfo(ficaAppAttempt.getSchedulingResourceUsage()) resourceInfo = null != ficaAppAttempt ?
: null; new ResourcesInfo(ficaAppAttempt.getSchedulingResourceUsage()) :
null;
}
} }
} }
Map<ApplicationTimeoutType, Long> applicationTimeouts = /*
app.getApplicationTimeouts(); * When the deSelects parameter contains "appTimeouts", objects pertaining
if (applicationTimeouts.isEmpty()) { * to app timeouts are not returned. By default, this is not skipped.
// If application is not set timeout, lifetime should be sent as default * (YARN-6871)
// with expiryTime=UNLIMITED and remainingTime=-1 */
AppTimeoutInfo timeoutInfo = new AppTimeoutInfo(); if (!deSelects.contains(DeSelectType.TIMEOUTS)) {
timeoutInfo.setTimeoutType(ApplicationTimeoutType.LIFETIME); Map<ApplicationTimeoutType, Long> applicationTimeouts =
timeouts.add(timeoutInfo); app.getApplicationTimeouts();
} else { if (applicationTimeouts.isEmpty()) {
for (Map.Entry<ApplicationTimeoutType, Long> entry : app // If application is not set timeout, lifetime should be sent
.getApplicationTimeouts().entrySet()) { // as default with expiryTime=UNLIMITED and remainingTime=-1
AppTimeoutInfo timeout = new AppTimeoutInfo(); AppTimeoutInfo timeoutInfo = new AppTimeoutInfo();
timeout.setTimeoutType(entry.getKey()); timeoutInfo.setTimeoutType(ApplicationTimeoutType.LIFETIME);
long timeoutInMillis = entry.getValue().longValue(); timeouts = new AppTimeoutsInfo();
timeout.setExpiryTime(Times.formatISO8601(timeoutInMillis)); timeouts.add(timeoutInfo);
if (app.isAppInCompletedStates()) { } else {
timeout.setRemainingTime(0); for (Map.Entry<ApplicationTimeoutType, Long> entry : app
} else { .getApplicationTimeouts().entrySet()) {
timeout.setRemainingTime(Math AppTimeoutInfo timeout = new AppTimeoutInfo();
.max((timeoutInMillis - System.currentTimeMillis()) / 1000, 0)); timeout.setTimeoutType(entry.getKey());
long timeoutInMillis = entry.getValue().longValue();
timeout.setExpiryTime(Times.formatISO8601(timeoutInMillis));
if (app.isAppInCompletedStates()) {
timeout.setRemainingTime(0);
} else {
timeout.setRemainingTime(Math.max(
(timeoutInMillis - System.currentTimeMillis()) / 1000, 0));
}
timeouts.add(timeout);
} }
timeouts.add(timeout);
} }
} }

View File

@ -1072,8 +1072,79 @@ public void testAppsQueryWithDeselects()
JSONArray array = apps.getJSONArray("app"); JSONArray array = apps.getJSONArray("app");
assertEquals("incorrect number of elements", 1, array.length()); assertEquals("incorrect number of elements", 1, array.length());
JSONObject app = array.getJSONObject(0); JSONObject app = array.getJSONObject(0);
assertTrue("resource requests shouldn't exits", assertTrue("resource requests shouldn't exist",
!app.has("resourceRequests")); !app.has("resourceRequests"));
params.clear();
params.add("deSelects",
DeSelectFields.DeSelectType.AM_NODE_LABEL_EXPRESSION.toString());
response =
r.path("ws").path("v1").path("cluster").path("apps").queryParams(params)
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
apps = json.getJSONObject("apps");
assertEquals("incorrect number of elements", 1, apps.length());
array = apps.getJSONArray("app");
assertEquals("incorrect number of elements", 1, array.length());
app = array.getJSONObject(0);
assertTrue("AMNodeLabelExpression shouldn't exist",
!app.has("amNodeLabelExpression"));
params.clear();
params.add("deSelects", DeSelectFields.DeSelectType.TIMEOUTS.toString());
response =
r.path("ws").path("v1").path("cluster").path("apps").queryParams(params)
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
apps = json.getJSONObject("apps");
assertEquals("incorrect number of elements", 1, apps.length());
array = apps.getJSONArray("app");
assertEquals("incorrect number of elements", 1, array.length());
app = array.getJSONObject(0);
assertTrue("Timeouts shouldn't exist", !app.has("timeouts"));
rm.stop();
params.clear();
params.add("deSelects",
DeSelectFields.DeSelectType.APP_NODE_LABEL_EXPRESSION.toString());
response =
r.path("ws").path("v1").path("cluster").path("apps").queryParams(params)
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
apps = json.getJSONObject("apps");
assertEquals("incorrect number of elements", 1, apps.length());
array = apps.getJSONArray("app");
assertEquals("incorrect number of elements", 1, array.length());
app = array.getJSONObject(0);
assertTrue("AppNodeLabelExpression shouldn't exist",
!app.has("appNodeLabelExpression"));
rm.stop();
params.clear();
params
.add("deSelects", DeSelectFields.DeSelectType.RESOURCE_INFO.toString());
response =
r.path("ws").path("v1").path("cluster").path("apps").queryParams(params)
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
apps = json.getJSONObject("apps");
assertEquals("incorrect number of elements", 1, apps.length());
array = apps.getJSONArray("app");
assertEquals("incorrect number of elements", 1, array.length());
app = array.getJSONObject(0);
assertTrue("Resource info shouldn't exist", !app.has("resourceInfo"));
rm.stop(); rm.stop();
} }