Skip to content

Commit

Permalink
Added support to search by queue-name (linkedin#40)
Browse files Browse the repository at this point in the history
Added support to search by queue-name
  • Loading branch information
chetnachaudhari authored and akshayrai committed Jun 9, 2016
1 parent 4ce5f18 commit cfb720a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
29 changes: 19 additions & 10 deletions app/controllers/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class Application extends Controller {
public static final String FLOW_EXEC_ID = "flow-exec-id";
public static final String JOB_DEF_ID = "job-def-id";
public static final String USERNAME = "username";
public static final String QUEUE_NAME = "queue-name";
public static final String SEVERITY = "severity";
public static final String JOB_TYPE = "job-type";
public static final String ANALYSIS = "analysis";
Expand Down Expand Up @@ -237,6 +238,9 @@ private static Map<String, String> getSearchParams() {
String username = form.get(USERNAME);
username = username != null ? username.trim().toLowerCase() : null;
searchParams.put(USERNAME, username);
String queuename = form.get(QUEUE_NAME);
queuename = queuename != null ? queuename.trim().toLowerCase() : null;
searchParams.put(QUEUE_NAME, queuename);
searchParams.put(SEVERITY, form.get(SEVERITY));
searchParams.put(JOB_TYPE, form.get(JOB_TYPE));
searchParams.put(ANALYSIS, form.get(ANALYSIS));
Expand Down Expand Up @@ -265,6 +269,11 @@ public static Query<AppResult> generateSearchQuery(String selectParams, Map<Stri
if (Utils.isSet(username)) {
query = query.eq(AppResult.TABLE.USERNAME, username);
}

String queuename = searchParams.get(QUEUE_NAME);
if (Utils.isSet(queuename)) {
query = query.eq(AppResult.TABLE.QUEUE_NAME, queuename);
}
String jobType = searchParams.get(JOB_TYPE);
if (Utils.isSet(jobType)) {
query = query.eq(AppResult.TABLE.JOB_TYPE, jobType);
Expand Down Expand Up @@ -332,13 +341,13 @@ public static Result compare() {
List<AppResult> results1 = null;
List<AppResult> results2 = null;
if (flowExecId1 != null && !flowExecId1.isEmpty() && flowExecId2 != null && !flowExecId2.isEmpty()) {
results1 = AppResult.find
results1 = AppResult.find
.select(AppResult.getSearchFields() + "," + AppResult.TABLE.JOB_DEF_ID + "," + AppResult.TABLE.JOB_DEF_URL
+ "," + AppResult.TABLE.FLOW_EXEC_ID + "," + AppResult.TABLE.FLOW_EXEC_URL)
.where().eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecId1).setMaxRows(100)
.fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields())
.findList();
results2 = AppResult.find
results2 = AppResult.find
.select(
AppResult.getSearchFields() + "," + AppResult.TABLE.JOB_DEF_ID + "," + AppResult.TABLE.JOB_DEF_URL + ","
+ AppResult.TABLE.FLOW_EXEC_ID + "," + AppResult.TABLE.FLOW_EXEC_URL)
Expand All @@ -358,7 +367,7 @@ public static Result compare() {
* @return A map of Job Urls to the list of jobs corresponding to the 2 flow execution urls
*/
private static Map<IdUrlPair, Map<IdUrlPair, List<AppResult>>> compareFlows(List<AppResult> results1,
List<AppResult> results2) {
List<AppResult> results2) {
Map<IdUrlPair, Map<IdUrlPair, List<AppResult>>> jobDefMap = new HashMap<IdUrlPair, Map<IdUrlPair, List<AppResult>>>();

if (results1 != null && !results1.isEmpty() && results2 != null && !results2.isEmpty()) {
Expand Down Expand Up @@ -411,8 +420,8 @@ public static Result flowHistory() {
// Fetch available flow executions with latest JOB_HISTORY_LIMIT mr jobs.
List<AppResult> results = AppResult.find
.select(
AppResult.getSearchFields() + "," + AppResult.TABLE.FLOW_EXEC_ID + "," + AppResult.TABLE.FLOW_EXEC_URL + ","
+ AppResult.TABLE.JOB_DEF_ID + "," + AppResult.TABLE.JOB_DEF_URL + "," + AppResult.TABLE.JOB_NAME)
AppResult.getSearchFields() + "," + AppResult.TABLE.FLOW_EXEC_ID + "," + AppResult.TABLE.FLOW_EXEC_URL + ","
+ AppResult.TABLE.JOB_DEF_ID + "," + AppResult.TABLE.JOB_DEF_URL + "," + AppResult.TABLE.JOB_NAME)
.where().eq(AppResult.TABLE.FLOW_DEF_ID, flowDefId)
.order().desc(AppResult.TABLE.FINISH_TIME)
.setMaxRows(JOB_HISTORY_LIMIT)
Expand Down Expand Up @@ -525,7 +534,7 @@ public static Result jobHistory() {
* @return A map after applying the limit.
*/
private static Map<IdUrlPair, List<AppResult>> limitHistoryResults(Map<IdUrlPair, List<AppResult>> map,
int size, int execLimit) {
int size, int execLimit) {
Map<IdUrlPair, List<AppResult>> resultMap = new LinkedHashMap<IdUrlPair, List<AppResult>>();

int limit;
Expand Down Expand Up @@ -895,10 +904,10 @@ public static Result restFlowGraphData(String flowDefId) {
.where().eq(AppResult.TABLE.FLOW_DEF_ID, flowDefId)
.order().desc(AppResult.TABLE.FINISH_TIME)
.setMaxRows(JOB_HISTORY_LIMIT)
// The 2nd and 3rd table are not required for plotting the graph
//.fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields())
//.fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "."
// + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS, "*")
// The 2nd and 3rd table are not required for plotting the graph
//.fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields())
//.fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "."
// + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS, "*")
.findList();
if (results.size() == 0) {
logger.info("No results for Job url");
Expand Down
3 changes: 2 additions & 1 deletion app/models/AppResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static class TABLE {
public static final String ID = "id";
public static final String NAME = "name";
public static final String USERNAME = "username";
public static final String QUEUE_NAME = "queueName";
public static final String START_TIME = "startTime";
public static final String FINISH_TIME = "finishTime";
public static final String TRACKING_URL = "trackingUrl";
Expand All @@ -78,7 +79,7 @@ public static class TABLE {
}

public static String getSearchFields() {
return Utils.commaSeparated(AppResult.TABLE.NAME, AppResult.TABLE.USERNAME, AppResult.TABLE.JOB_TYPE,
return Utils.commaSeparated(AppResult.TABLE.NAME, AppResult.TABLE.USERNAME, TABLE.QUEUE_NAME, AppResult.TABLE.JOB_TYPE,
AppResult.TABLE.SEVERITY, AppResult.TABLE.FINISH_TIME);
}

Expand Down
4 changes: 4 additions & 0 deletions app/views/page/searchPage.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<label for="form-username">User</label>
<input type="text" class="form-control" id="form-username" name="username" placeholder="User">
</div>
<div class="form-group">
<label for="form-queue-name">Queue</label>
<input type="text" class="form-control" id="form-queue-name" name="queue-name" placeholder="Queue">
</div>

<!--Job Type filter-->
<div class="checkbox">
Expand Down
9 changes: 9 additions & 0 deletions conf/evolutions/default/2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# --- Indexing on queue for seach by queue feature
# --- !Ups

create index yarn_app_result_i8 on yarn_app_result (queue_name);

# --- !Downs

drop index yarn_app_result_i8 on yarn_app_result;

4 changes: 4 additions & 0 deletions public/js/searchform.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ $(document).ready(function(){
var jobId = $("#form-job-id");
var flowExecId = $("#form-flow-exec-id");
var user = $("#form-username");
var queueName = $("#form-queue-name");
var jobtypeEnable = $("#form-job-type-enable");
var jobtype = $("#form-job-type");
var severityEnable = $("#form-severity-enable");
Expand All @@ -46,6 +47,7 @@ $(document).ready(function(){
if(jobId.val()) {
flowExecId.prop('disabled', true);
user.prop('disabled', true);
queueName.prop('disabled', true);
severity.prop('disabled', true);
analysis.prop('disabled', true);
jobtype.prop('disabled', true);
Expand All @@ -57,6 +59,7 @@ $(document).ready(function(){
} else if(flowExecId.val()) {
jobId.prop('disabled', true);
user.prop('disabled', true);
queueName.prop('disabled', true);
severity.prop('disabled', true);
analysis.prop('disabled', true);
jobtype.prop('disabled', true);
Expand All @@ -73,6 +76,7 @@ $(document).ready(function(){
severityEnable.prop('disabled', false);
datetimeEnable.prop('disabled', false);
user.prop('disabled', false);
queueName.prop('disabled', false);
if(jobtypeEnable.prop('checked')){
jobtype.prop('disabled', false);
}
Expand Down
12 changes: 11 additions & 1 deletion test/controllers/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,17 @@ public void testGenerateSearchQuery() {
assertTrue(sql2.contains("from yarn_app_result t0 where"));
assertTrue(sql2.contains("t0.username = ? order by t0.finish_time desc"));

// Query by jobtype
// Query by queuename
searchParams.put(Application.QUEUE_NAME, "queueName");
query2 = Application.generateSearchQuery("*", searchParams);
assertNotNull(query2.findList());
sql2 = query2.getGeneratedSql();
assertTrue(sql2.contains("select t0.id c0"));
assertTrue(sql2.contains("from yarn_app_result t0 where"));
assertTrue(sql2.contains("t0.queue_name = ? order by t0.finish_time desc"));


// Query by jobtype
searchParams.put(Application.JOB_TYPE, "Pig");
query2 = Application.generateSearchQuery("*", searchParams);
assertNotNull(query2.findList());
Expand Down

0 comments on commit cfb720a

Please sign in to comment.