use of models.AppHeuristicResult in project dr-elephant by linkedin.
the class Application method restJobMetricsGraphData.
/**
* The data for plotting the job history graph using time and resource metrics. While plotting the job history
* graph an ajax call is made to this to fetch the graph data.
*
* Data Returned:
* <pre>
* [
* {
* "flowtime": 1461234105456,
* "runtime": 2312107,
* "waittime": 118879,
* "resourceused": 304934912,
* "resourcewasted": 172913,
* "jobmetrics": [
* {
* "stageid": "application_1458194917883_1587177",
* "runtime": 642986,
* "waittime": 14016,
* "resourceused": 277352448,
* "resourcewasted": 0
* }],
* },
* {
* "flowtime": 1461237538639,
* "runtime": 2155354,
* "waittime": 112187,
* "resourceused": 293096448,
* "resourcewasted": 400461,
* "jobmetrics": [
* {
* "stageid": "application_1458194917883_1589302",
* "runtime": 548924,
* "waittime": 16903,
* "resourceused": 266217472,
* "resourcewasted": 0
* }]
* }
* ]
*
* </pre>
*/
public static Result restJobMetricsGraphData(String jobDefId) {
JsonArray datasets = new JsonArray();
if (jobDefId == null || jobDefId.isEmpty()) {
return ok(new Gson().toJson(datasets));
}
List<AppResult> results = getRestJobAppResults(jobDefId);
if (results.size() == 0) {
logger.info("No results for Job url");
}
Map<IdUrlPair, List<AppResult>> flowExecIdToJobsMap = ControllerUtil.limitHistoryResults(ControllerUtil.groupJobs(results, ControllerUtil.GroupBy.FLOW_EXECUTION_ID), results.size(), MAX_HISTORY_LIMIT);
// Compute the graph data starting from the earliest available execution to latest
List<IdUrlPair> keyList = new ArrayList<IdUrlPair>(flowExecIdToJobsMap.keySet());
for (int i = keyList.size() - 1; i >= 0; i--) {
IdUrlPair flowExecPair = keyList.get(i);
int jobPerfScore = 0;
JsonArray stageMetrics = new JsonArray();
List<AppResult> mrJobsList = Lists.reverse(flowExecIdToJobsMap.get(flowExecPair));
long totalMemoryUsed = 0;
long totalMemoryWasted = 0;
long totalDelay = 0;
for (AppResult appResult : flowExecIdToJobsMap.get(flowExecPair)) {
// Each MR job triggered by jobDefId for flowExecId
int mrPerfScore = 0;
for (AppHeuristicResult appHeuristicResult : appResult.yarnAppHeuristicResults) {
mrPerfScore += appHeuristicResult.score;
}
// A particular mr stage
JsonObject stageMetric = new JsonObject();
stageMetric.addProperty("stageid", appResult.id);
stageMetric.addProperty("runtime", appResult.finishTime - appResult.startTime);
stageMetric.addProperty("waittime", appResult.totalDelay);
stageMetric.addProperty("resourceused", appResult.resourceUsed);
stageMetric.addProperty("resourcewasted", appResult.resourceWasted);
stageMetrics.add(stageMetric);
jobPerfScore += mrPerfScore;
totalMemoryUsed += appResult.resourceUsed;
totalMemoryWasted += appResult.resourceWasted;
}
// Execution record
JsonObject dataset = new JsonObject();
dataset.addProperty("flowtime", Utils.getFlowTime(mrJobsList.get(mrJobsList.size() - 1)));
dataset.addProperty("runtime", Utils.getTotalRuntime(mrJobsList));
dataset.addProperty("waittime", Utils.getTotalWaittime(mrJobsList));
dataset.addProperty("resourceused", totalMemoryUsed);
dataset.addProperty("resourcewasted", totalMemoryWasted);
dataset.add("jobmetrics", stageMetrics);
datasets.add(dataset);
}
JsonArray sortedDatasets = Utils.sortJsonArray(datasets);
return ok(new Gson().toJson(sortedDatasets));
}
use of models.AppHeuristicResult in project dr-elephant by linkedin.
the class Web method restApplicationSummariesForUser.
/**
* This method returns the json object for the application-summaries based on the username
* @param username The username for which application-summaries json must be returned
* @return The application-summaries json for the given username
* response object:
* <pre>
*{
* "application-summaries": [
* {
* "id": "sample_app_0000000001",
* "username": "user",
* "starttime": 1471910835628,
* "finishtime": 1471911099238,
* "runtime": 263610,
* "waittime": 46234,
* "resourceused": 101382144,
* "resourcewasted": 15993417,
* "severity": "Moderate",
* "heuristicsummary": [
* {
* "name": "Mapper Data Skew",
* "severity": "None"
* },
* {
* "name": "Mapper GC",
* "severity": "None"
* },
* {
* "name": "Mapper Time",
* "severity": "Moderate"
* },
* {
* "name": "Mapper Speed",
* "severity": "None"
* },
* {
* "name": "Mapper Spill",
* "severity": "None"
* },
* {
* "name": "Mapper Memory",
* "severity": "None"
* },
* {
* "name": "Reducer Data Skew",
* "severity": "None"
* },
* {
* "name": "Reducer GC",
* "severity": "None"
* },
* {
* "name": "Reducer Time",
* "severity": "None"
* },
* {
* "name": "Reducer Memory",
* "severity": "None"
* },
* {
* "name": "Shuffle & Sort",
* "severity": "Low"
* }
* ]
* }
* ]
*}
* </pre>
*/
public static Result restApplicationSummariesForUser(String username) {
JsonArray applicationSummaryArray = new JsonArray();
List<AppResult> results = null;
if (username == null || username.isEmpty()) {
results = getApplications(MAX_APPLICATIONS);
} else {
results = getApplications(username, MAX_APPLICATIONS);
}
for (AppResult application : results) {
JsonObject applicationObject = new JsonObject();
JsonArray heuristicsArray = new JsonArray();
List<AppHeuristicResult> appHeuristicResult = application.yarnAppHeuristicResults;
for (AppHeuristicResult heuristic : appHeuristicResult) {
JsonObject heuristicObject = new JsonObject();
heuristicObject.addProperty(JsonKeys.NAME, heuristic.heuristicName);
heuristicObject.addProperty(JsonKeys.SEVERITY, heuristic.severity.getText());
heuristicsArray.add(heuristicObject);
}
applicationObject.addProperty(JsonKeys.ID, application.id);
applicationObject.addProperty(JsonKeys.USERNAME, application.username);
applicationObject.addProperty(JsonKeys.JOB_NAME, application.jobName);
applicationObject.addProperty(JsonKeys.JOB_TYPE, application.jobType);
applicationObject.addProperty(JsonKeys.START_TIME, application.startTime);
applicationObject.addProperty(JsonKeys.FINISH_TIME, application.finishTime);
applicationObject.addProperty(JsonKeys.RUNTIME, application.finishTime - application.startTime);
applicationObject.addProperty(JsonKeys.WAITTIME, application.totalDelay);
applicationObject.addProperty(JsonKeys.RESOURCE_USED, application.resourceUsed);
applicationObject.addProperty(JsonKeys.RESOURCE_WASTED, application.resourceWasted);
applicationObject.addProperty(JsonKeys.QUEUE, application.queueName);
applicationObject.addProperty(JsonKeys.SEVERITY, application.severity.getText());
applicationObject.add(JsonKeys.HEURISTICS_SUMMARY, heuristicsArray);
applicationSummaryArray.add(applicationObject);
}
JsonArray sortedApplicationSummaryArray = getSortedJsonArrayByFinishTime(applicationSummaryArray);
JsonObject parent = new JsonObject();
parent.add(JsonKeys.APPLICATION_SUMMARIES, sortedApplicationSummaryArray);
return ok(new Gson().toJson(parent));
}
use of models.AppHeuristicResult in project dr-elephant by linkedin.
the class Web method restApplicationFromApplicationId.
/**
* @param applicationId
* @return
* <pre>
* {
* "applications": {
* "id": "application_id",
* "username": "username",
* "jobtype": "Pig",
* "mapreducejobname": "mapreducejobname",
* "starttime": 1471910835628,
* "finishtime": 1471911099238,
* "runtime": 263610,
* "waittime": 46234,
* "resourceused": 101382144,
* "resourcewasted": 15993417,
* "severity": "Moderate",
* "trackingurl": "jobtracker_address",
* "jobexecid": "jobexecutionid",
* "jobdefid": "jobdefinitionid",
* "flowexeid": "flowexecutionid",
* "flowdefid": "flowdefinitionid",
* "yarnappheuristicresults": [
* {
* "name": "Mapper Data Skew",
* "severity": "None",
* "details": [
* {
* "name": "Group A",
* "value": "236 tasks @ 506 MB avg"
* },
* {
* "name": "Group B",
* "value": "234 tasks @ 507 MB avg"
* },
* {
* "name": "Number of tasks",
* "value": "470"
* }
* ]
* },
* {
* "name": "Mapper GC",
* "severity": "None",
* "details": [
* {
* "name": "Avg task CPU time (ms)",
* "value": "111717"
* },
* {
* "name": "Avg task GC time (ms)",
* "value": "3197"
* },
* {
* "name": "Avg task runtime (ms)",
* "value": "105633"
* },
* {
* "name": "Number of tasks",
* "value": "470"
* },
* {
* "name": "Task GC\/CPU ratio",
* "value": "0.028616951762041588"
* }
* ]
* }..
* ]
* }
*}
* </pre>
*/
public static Result restApplicationFromApplicationId(String applicationid) {
if (applicationid == null || applicationid.isEmpty()) {
JsonObject parent = new JsonObject();
parent.add(JsonKeys.APPLICATIONS, new JsonObject());
return notFound(new Gson().toJson(parent));
}
if (applicationid.startsWith("job")) {
applicationid = applicationid.replaceAll("job", "application");
}
JsonObject applicationObject = new JsonObject();
JsonArray heuristicsArray = new JsonArray();
AppResult result = getAppResultFromApplicationId(applicationid);
if (result == null) {
JsonObject parent = new JsonObject();
parent.add(JsonKeys.APPLICATIONS, new JsonObject());
return notFound(new Gson().toJson(parent));
}
for (AppHeuristicResult appHeuristicResult : result.yarnAppHeuristicResults) {
JsonArray detailsArray = new JsonArray();
JsonObject heuristicResultObject = new JsonObject();
for (AppHeuristicResultDetails details : appHeuristicResult.yarnAppHeuristicResultDetails) {
JsonObject detailsObject = new JsonObject();
detailsObject.addProperty(JsonKeys.NAME, details.name);
detailsObject.addProperty(JsonKeys.VALUE, details.value);
detailsObject.addProperty(JsonKeys.DETAILS, details.details);
detailsArray.add(detailsObject);
}
heuristicResultObject.addProperty(JsonKeys.NAME, appHeuristicResult.heuristicName);
heuristicResultObject.addProperty(JsonKeys.SEVERITY, appHeuristicResult.severity.getText());
heuristicResultObject.add(JsonKeys.DETAILS, detailsArray);
heuristicsArray.add(heuristicResultObject);
}
applicationObject.addProperty(JsonKeys.ID, result.id);
applicationObject.addProperty(JsonKeys.USERNAME, result.username);
applicationObject.addProperty(JsonKeys.JOB_TYPE, result.jobType);
applicationObject.addProperty(JsonKeys.MAPREDUCE_JOB_NAME, result.jobName);
applicationObject.addProperty(JsonKeys.START_TIME, result.startTime);
applicationObject.addProperty(JsonKeys.FINISH_TIME, result.finishTime);
applicationObject.addProperty(JsonKeys.RUNTIME, result.finishTime - result.startTime);
applicationObject.addProperty(JsonKeys.WAITTIME, result.totalDelay);
applicationObject.addProperty(JsonKeys.RESOURCE_USED, result.resourceUsed);
applicationObject.addProperty(JsonKeys.RESOURCE_WASTED, result.resourceWasted);
applicationObject.addProperty(JsonKeys.SEVERITY, result.severity.getText());
applicationObject.addProperty(JsonKeys.TRACKING_URL, result.trackingUrl);
applicationObject.addProperty(JsonKeys.JOB_EXEC_ID, result.jobExecId);
applicationObject.addProperty(JsonKeys.JOB_DEF_ID, result.jobDefId);
applicationObject.addProperty(JsonKeys.FLOW_EXEC_ID, result.flowExecId);
applicationObject.addProperty(JsonKeys.FLOW_DEF_ID, result.flowDefId);
applicationObject.addProperty(JsonKeys.QUEUE, result.queueName);
applicationObject.add(JsonKeys.YARN_APP_HEURISTIC_RESULTS, heuristicsArray);
JsonObject parent = new JsonObject();
parent.add(JsonKeys.APPLICATIONS, applicationObject);
return ok(new Gson().toJson(parent));
}
use of models.AppHeuristicResult in project dr-elephant by linkedin.
the class Web method restJobFromJobId.
/**
* @param jobId
* @return
* <pre>
**{
* "jobs": {
* "id": "jobid",
* "username": "username",
* "jobname": "jobname",
* "jobtype": "Pig",
* "starttime": 1471910835628,
* "finishtime": 1471911099238,
* "runtime": 263610,
* "waittime": 46234,
* "resourceused": 101382144,
* "resourcewasted": 15993417,
* "severity": "Moderate",
* "jobexecid": "jobexecid",
* "jobdefid": "jobdefid",
* "flowexecid": "flowexecid",
* "flowdefid": "flowdefid",
* "taskssummaries": [
* {
* "id": "application_id",
* "username": "username",
* "starttime": 1471910835628,
* "finishtime": 1471911099238,
* "runtime": 263610,
* "waittime": 46234,
* "resourceused": 101382144,
* "resourcewasted": 15993417,
* "severity": "Moderate",
* "heuristicsummary": [
* {
* "name": "Mapper Data Skew",
* "severity": "None"
* },
* {
* "name": "Mapper GC",
* "severity": "None"
* },
* {
* "name": "Mapper Time",
* "severity": "Moderate"
* },
* {
* "name": "Mapper Speed",
* "severity": "None"
* },
* {
* "name": "Mapper Spill",
* "severity": "None"
* },
* {
* "name": "Mapper Memory",
* "severity": "None"
* },
* {
* "name": "Reducer Data Skew",
* "severity": "None"
* },
* {
* "name": "Reducer GC",
* "severity": "None"
* },
* {
* "name": "Reducer Time",
* "severity": "None"
* },
* {
* "name": "Reducer Memory",
* "severity": "None"
* },
* {
* "name": "Shuffle & Sort",
* "severity": "Low"
* }
* ]
* }
* ],
* "tasksseverity": [
* {
* "severity": "Moderate",
* "count": 1
* }
* ]
* }
*}
*
* </pre>
*/
public static Result restJobFromJobId(String jobid) {
if (jobid == null || jobid.isEmpty()) {
JsonObject parent = new JsonObject();
parent.add(JsonKeys.JOBS, new JsonObject());
return notFound(new Gson().toJson(parent));
}
JsonArray taskSummaryArray = new JsonArray();
String jobDefID = jobid;
long jobResourceUsed = 0;
long jobResourceWasted = 0;
long jobRuntime = 0;
long jobDelay = 0;
Severity jobSeverity = Severity.NONE;
long jobStartTime = Long.MAX_VALUE;
long jobEndTime = 0;
String username = "";
String jobtype = "";
String jobExecutionId = "";
String jobDefinitionId = "";
String flowExecutionId = "";
String flowDefinitionId = "";
String jobname = "";
String queueName = "";
String scheduler = "";
List<AppResult> results = getRestJobResultsFromJobExecutionId(jobid);
if (results.isEmpty()) {
JsonObject parent = new JsonObject();
parent.add(JsonKeys.JOBS, new JsonObject());
return notFound(new Gson().toJson(parent));
}
Map<Severity, Long> taskSeverityCount = new HashMap<Severity, Long>();
for (AppResult task : results) {
username = task.username;
jobtype = task.jobType;
jobname = task.jobName;
jobExecutionId = task.jobExecId;
jobDefinitionId = task.jobDefId;
flowExecutionId = task.flowExecId;
flowDefinitionId = task.flowDefId;
queueName = task.queueName;
scheduler = task.scheduler;
JsonObject taskObject = new JsonObject();
JsonArray heuristicsArray = new JsonArray();
List<AppHeuristicResult> appHeuristicResult = task.yarnAppHeuristicResults;
for (AppHeuristicResult heuristic : appHeuristicResult) {
JsonObject heuristicObject = new JsonObject();
heuristicObject.addProperty(JsonKeys.NAME, heuristic.heuristicName);
heuristicObject.addProperty(JsonKeys.SEVERITY, heuristic.severity.getText());
heuristicsArray.add(heuristicObject);
}
if (task.severity.getValue() > jobSeverity.getValue()) {
jobSeverity = task.severity;
}
if (taskSeverityCount.containsKey(task.severity)) {
taskSeverityCount.put(task.severity, taskSeverityCount.get(task.severity) + 1L);
} else {
taskSeverityCount.put(task.severity, 1L);
}
taskObject.addProperty(JsonKeys.ID, task.id);
taskObject.addProperty(JsonKeys.USERNAME, task.username);
taskObject.addProperty(JsonKeys.START_TIME, task.startTime);
taskObject.addProperty(JsonKeys.FINISH_TIME, task.finishTime);
taskObject.addProperty(JsonKeys.RUNTIME, task.finishTime - task.startTime);
taskObject.addProperty(JsonKeys.WAITTIME, task.totalDelay);
taskObject.addProperty(JsonKeys.RESOURCE_USED, task.resourceUsed);
taskObject.addProperty(JsonKeys.RESOURCE_WASTED, task.resourceWasted);
taskObject.addProperty(JsonKeys.SEVERITY, task.severity.getText());
taskObject.addProperty(JsonKeys.QUEUE, task.queueName);
taskObject.add(JsonKeys.HEURISTICS_SUMMARY, heuristicsArray);
taskSummaryArray.add(taskObject);
jobResourceUsed += task.resourceUsed;
jobResourceWasted += task.resourceWasted;
if (jobSeverity.getValue() < task.severity.getValue()) {
jobSeverity = task.severity;
}
if (jobStartTime > task.startTime) {
jobStartTime = task.startTime;
}
if (jobEndTime < task.finishTime) {
jobEndTime = task.finishTime;
}
}
JsonArray taskSeverity = new JsonArray();
List<Severity> keys = getSortedSeverityKeys(taskSeverityCount.keySet());
for (Severity key : keys) {
JsonObject severityObject = new JsonObject();
severityObject.addProperty(JsonKeys.SEVERITY, key.getText());
severityObject.addProperty(JsonKeys.COUNT, taskSeverityCount.get(key));
taskSeverity.add(severityObject);
}
jobRuntime = Utils.getTotalRuntime(results);
jobDelay = Utils.getTotalWaittime(results);
JsonObject data = new JsonObject();
data.addProperty(JsonKeys.ID, jobDefID);
data.addProperty(JsonKeys.USERNAME, username);
data.addProperty(JsonKeys.JOB_NAME, jobname);
data.addProperty(JsonKeys.JOB_TYPE, jobtype);
data.addProperty(JsonKeys.START_TIME, jobStartTime);
data.addProperty(JsonKeys.FINISH_TIME, jobEndTime);
data.addProperty(JsonKeys.RUNTIME, jobRuntime);
data.addProperty(JsonKeys.WAITTIME, jobDelay);
data.addProperty(JsonKeys.RESOURCE_USED, jobResourceUsed);
data.addProperty(JsonKeys.RESOURCE_WASTED, jobResourceWasted);
data.addProperty(JsonKeys.SEVERITY, jobSeverity.getText());
data.addProperty(JsonKeys.JOB_EXEC_ID, jobExecutionId);
data.addProperty(JsonKeys.JOB_DEF_ID, jobDefinitionId);
data.addProperty(JsonKeys.FLOW_EXEC_ID, flowExecutionId);
data.addProperty(JsonKeys.FLOW_DEF_ID, flowDefinitionId);
data.addProperty(JsonKeys.QUEUE, queueName);
data.addProperty(JsonKeys.SCHEDULER, scheduler);
data.add(JsonKeys.TASKS_SUMMARIES, taskSummaryArray);
data.add(JsonKeys.TASKS_SEVERITY, taskSeverity);
JsonObject parent = new JsonObject();
parent.add(JsonKeys.JOBS, data);
return ok(new Gson().toJson(parent));
}
use of models.AppHeuristicResult in project dr-elephant by linkedin.
the class Web method restGetUsersSummaryStats.
/**
* The rest interface to return the results for a particular user. When the date is not specified, it returns the result
* for the last seven days.
* @return The json object of the form:
* result:
* * {
* "user-details": {
* "id": "user",
* "totalapplications": 3,
* "totaljobs": 3,
* "totalworkflows": 3,
* "resourceused": 101394532,
* "resourcewasted": 15999828,
* "runtime": 312283,
* "waittime": 46234,
* "start": 0,
* "end": 3,
* "total": 3,
* "summaries": [
* {
* "id": "application_12432132131",
* "username": "user",
* "starttime": 1477389986871,
* "finishtime": 1477390004463,
* "runtime": 17592,
* "waittime": 0,
* "resourceused": 12288,
* "resourcewasted": 6360,
* "severity": "Critical",
* "queue": "spark_default",
* "heuristicsummary": [
* {
* "name": "Spark Configuration Best Practice",
* "severity": "None"
* },
* {
* "name": "Spark Memory Limit",
* "severity": "None"
* },
* {
* "name": "Spark Stage Runtime",
* "severity": "Low"
* },
* {
* "name": "Spark Job Runtime",
* "severity": "Low"
* },
* {
* "name": "Spark Executor Load Balance",
* "severity": "Critical"
* },
* {
* "name": "Spark Event Log Limit",
* "severity": "None"
* }
* ]
* }
* }
* }
*/
public static Result restGetUsersSummaryStats() {
DynamicForm form = Form.form().bindFromRequest(request());
int offset = SEARCH_DEFAULT_PAGE_OFFSET;
int limit = SEARCH_DEFAULT_PAGE_LIMIT;
int end = 0;
int total = 0;
if (form.get("offset") != null && form.get("offset") != "") {
offset = Integer.valueOf(form.get("offset"));
}
if (form.get("limit") != null && form.get("limit") != "") {
limit = Integer.valueOf(form.get("limit"));
}
if (offset < 0) {
offset = 0;
}
if (limit > SEARCH_APPLICATION_MAX_OFFSET) {
limit = SEARCH_APPLICATION_MAX_OFFSET;
} else if (limit <= 0) {
return ok(new Gson().toJson(new JsonObject()));
}
String sortBy = "severity";
boolean increasing = true;
String usernameString = form.get("usernames");
if (usernameString == null || usernameString.isEmpty()) {
JsonObject parent = new JsonObject();
parent.add(JsonKeys.USER_RESULTS, new JsonObject());
return notFound(new Gson().toJson(parent));
}
List<String> usernames = Arrays.asList(usernameString.split(","));
Map<String, String> filterParamsForUserSummary = getFilterParamsForUserSummary();
if (form.get("sortKey") != null) {
sortBy = form.get("sortKey");
}
if (form.get("increasing") != null) {
increasing = Boolean.valueOf(form.get("increasing"));
}
JsonObject userResult = new JsonObject();
List<String> usernameQueryList = new ArrayList<String>();
for (int i = 0; i < usernames.size(); i++) {
usernameQueryList.add("username=:user" + i);
}
String usernameQueryString = StringUtils.join(usernameQueryList, " or ");
// by default, fetch data from last week
// week of data if not specified
String finishedTimeBegin = String.valueOf(System.currentTimeMillis() - DAY * 7);
String finishedTimeEnd = String.valueOf(System.currentTimeMillis());
if (Utils.isSet(filterParamsForUserSummary.get(Application.FINISHED_TIME_BEGIN))) {
finishedTimeBegin = filterParamsForUserSummary.get(Application.FINISHED_TIME_BEGIN);
}
if (Utils.isSet(filterParamsForUserSummary.get(Application.FINISHED_TIME_END))) {
finishedTimeEnd = filterParamsForUserSummary.get(Application.FINISHED_TIME_END);
}
StringBuilder timeFilterStringBuilder = new StringBuilder();
if (finishedTimeBegin != null) {
timeFilterStringBuilder.append("finish_time");
timeFilterStringBuilder.append(">=");
timeFilterStringBuilder.append(parseTime(String.valueOf(finishedTimeBegin)));
if (finishedTimeEnd != null) {
timeFilterStringBuilder.append(" and ");
}
}
if (finishedTimeEnd != null) {
timeFilterStringBuilder.append("finish_time");
timeFilterStringBuilder.append("<=");
timeFilterStringBuilder.append(parseTime(String.valueOf(finishedTimeEnd)));
}
String timeFilterString = timeFilterStringBuilder.toString();
String sql;
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("select count(id) as num_of_applications, count(distinct(job_exec_id)) as num_of_jobs, count(distinct(flow_exec_id)) as num_of_flows, sum(resource_used) as total_resource_used, sum(resource_wasted) as total_resource_wasted, sum(finish_time) - sum(start_time) as execution_time, sum(total_delay) as total_delay from yarn_app_result where");
if (timeFilterString != null && !timeFilterString.isEmpty()) {
sqlBuilder.append(" ( ");
sqlBuilder.append(usernameQueryString);
sqlBuilder.append(" ) and ");
sqlBuilder.append(timeFilterString);
} else {
sqlBuilder.append(" ");
sqlBuilder.append(usernameQueryString);
}
sql = sqlBuilder.toString();
SqlQuery query = Ebean.createSqlQuery(sql);
int iUserIndex = 0;
for (String username : usernames) {
query.setParameter("user" + iUserIndex, username);
iUserIndex++;
}
SqlRow resultRow = query.findUnique();
userResult.addProperty(JsonKeys.ID, usernameString);
userResult.addProperty(JsonKeys.TOTAL_APPLICATIONS, resultRow.getLong("num_of_applications"));
userResult.addProperty(JsonKeys.TOTAL_JOBS, resultRow.getLong("num_of_jobs"));
userResult.addProperty(JsonKeys.TOTAL_WORKFLOWS, resultRow.getLong("num_of_flows"));
userResult.addProperty(JsonKeys.RESOURCE_USED, resultRow.getLong("total_resource_used"));
userResult.addProperty(JsonKeys.RESOURCE_WASTED, resultRow.getLong("total_resource_wasted"));
userResult.addProperty(JsonKeys.RUNTIME, resultRow.getLong("execution_time"));
userResult.addProperty(JsonKeys.WAITTIME, resultRow.getLong("total_delay"));
Query<AppResult> userSummaryQuery = generateUserApplicationSummaryQuery(usernames, filterParamsForUserSummary, sortBy, increasing);
total = userSummaryQuery.findRowCount();
List<AppResult> results = userSummaryQuery.setFirstRow(offset).setMaxRows(limit).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields()).findList();
end = offset + results.size();
JsonArray applicationSummaryArray = new JsonArray();
for (AppResult application : results) {
JsonObject applicationObject = new JsonObject();
JsonArray heuristicsArray = new JsonArray();
List<AppHeuristicResult> appHeuristicResult = application.yarnAppHeuristicResults;
for (AppHeuristicResult heuristic : appHeuristicResult) {
JsonObject heuristicObject = new JsonObject();
heuristicObject.addProperty(JsonKeys.NAME, heuristic.heuristicName);
heuristicObject.addProperty(JsonKeys.SEVERITY, heuristic.severity.getText());
heuristicsArray.add(heuristicObject);
}
applicationObject.addProperty(JsonKeys.ID, application.id);
applicationObject.addProperty(JsonKeys.USERNAME, application.username);
applicationObject.addProperty(JsonKeys.START_TIME, application.startTime);
applicationObject.addProperty(JsonKeys.FINISH_TIME, application.finishTime);
applicationObject.addProperty(JsonKeys.RUNTIME, application.finishTime - application.startTime);
applicationObject.addProperty(JsonKeys.WAITTIME, application.totalDelay);
applicationObject.addProperty(JsonKeys.RESOURCE_USED, application.resourceUsed);
applicationObject.addProperty(JsonKeys.RESOURCE_WASTED, application.resourceWasted);
applicationObject.addProperty(JsonKeys.SEVERITY, application.severity.getText());
applicationObject.addProperty(JsonKeys.QUEUE, application.queueName);
applicationObject.add(JsonKeys.HEURISTICS_SUMMARY, heuristicsArray);
applicationSummaryArray.add(applicationObject);
}
userResult.addProperty(JsonKeys.START, offset);
userResult.addProperty(JsonKeys.END, end);
userResult.addProperty(JsonKeys.TOTAL, total);
userResult.add(JsonKeys.SUMMARIES, applicationSummaryArray);
JsonObject parent = new JsonObject();
parent.add(JsonKeys.USER_DETAILS, userResult);
return ok(new Gson().toJson(parent));
}
Aggregations