Search in sources :

Example 6 with DynamicForm

use of play.data.DynamicForm in project dr-elephant by linkedin.

the class Application method restCompare.

/**
 * The Rest API for Compare Feature
 * E.g., localhost:8080/rest/compare?flow-exec-id1=abc&flow-exec-id2=xyz
 */
public static Result restCompare() {
    DynamicForm form = Form.form().bindFromRequest(request());
    String flowExecId1 = form.get(COMPARE_FLOW_ID1);
    flowExecId1 = (flowExecId1 != null) ? flowExecId1.trim() : null;
    String flowExecId2 = form.get(COMPARE_FLOW_ID2);
    flowExecId2 = (flowExecId2 != null) ? flowExecId2.trim() : null;
    List<AppResult> results1 = null;
    List<AppResult> results2 = null;
    if (flowExecId1 != null && !flowExecId1.isEmpty() && flowExecId2 != null && !flowExecId2.isEmpty()) {
        results1 = AppResult.find.select("*").where().eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecId1).setMaxRows(100).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, "*").fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "." + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS, "*").findList();
        results2 = AppResult.find.select("*").where().eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecId2).setMaxRows(100).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, "*").fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "." + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS, "*").findList();
    }
    Map<IdUrlPair, Map<IdUrlPair, List<AppResult>>> compareResults = compareFlows(results1, results2);
    Map<String, Map<String, List<AppResult>>> resMap = new HashMap<String, Map<String, List<AppResult>>>();
    for (Map.Entry<IdUrlPair, Map<IdUrlPair, List<AppResult>>> entry : compareResults.entrySet()) {
        IdUrlPair jobExecPair = entry.getKey();
        Map<IdUrlPair, List<AppResult>> value = entry.getValue();
        for (Map.Entry<IdUrlPair, List<AppResult>> innerEntry : value.entrySet()) {
            IdUrlPair flowExecPair = innerEntry.getKey();
            List<AppResult> results = innerEntry.getValue();
            Map<String, List<AppResult>> resultMap = new HashMap<String, List<AppResult>>();
            resultMap.put(flowExecPair.getId(), results);
            resMap.put(jobExecPair.getId(), resultMap);
        }
    }
    return ok(Json.toJson(resMap));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AppResult(models.AppResult) List(java.util.List) ExpressionList(com.avaje.ebean.ExpressionList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DynamicForm(play.data.DynamicForm) Map(java.util.Map) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with DynamicForm

use of play.data.DynamicForm in project dr-elephant by linkedin.

the class Application method restSearch.

/**
 * The Rest API for Search Feature
 *
 * http://localhost:8080/rest/search?username=abc&job-type=HadoopJava
 */
public static Result restSearch() {
    DynamicForm form = Form.form().bindFromRequest(request());
    String appId = form.get(APP_ID);
    appId = appId != null ? appId.trim() : "";
    if (appId.contains("job")) {
        appId = appId.replaceAll("job", "application");
    }
    String flowExecId = form.get(FLOW_EXEC_ID);
    flowExecId = (flowExecId != null) ? flowExecId.trim() : null;
    if (!appId.isEmpty()) {
        AppResult result = AppResult.find.select("*").fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, "*").fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "." + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS, "*").where().idEq(appId).findUnique();
        if (result != null) {
            return ok(Json.toJson(result));
        } else {
            return notFound("Unable to find record on id: " + appId);
        }
    } else if (flowExecId != null && !flowExecId.isEmpty()) {
        List<AppResult> results = AppResult.find.select("*").fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, "*").fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "." + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS, "*").where().eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecId).findList();
        if (results.size() == 0) {
            return notFound("Unable to find record on flow execution: " + flowExecId);
        } else {
            return ok(Json.toJson(results));
        }
    }
    int page = 1;
    if (request().queryString().containsKey(PAGE)) {
        page = Integer.parseInt(request().queryString().get(PAGE)[0]);
        if (page <= 0) {
            page = 1;
        }
    }
    Query<AppResult> query = generateSearchQuery("*", getSearchParams());
    List<AppResult> results = query.setFirstRow((page - 1) * REST_PAGE_LENGTH).setMaxRows(REST_PAGE_LENGTH).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, "*").fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "." + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS, "*").findList();
    if (results.size() == 0) {
        return notFound("No records");
    } else {
        return ok(Json.toJson(results));
    }
}
Also used : List(java.util.List) ExpressionList(com.avaje.ebean.ExpressionList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DynamicForm(play.data.DynamicForm) AppResult(models.AppResult)

Example 8 with DynamicForm

use of play.data.DynamicForm in project dr-elephant by linkedin.

the class Application method search.

/**
 * Controls the Search Feature
 */
public static Result search() {
    DynamicForm form = Form.form().bindFromRequest(request());
    String appId = form.get(APP_ID);
    appId = appId != null ? appId.trim() : "";
    if (appId.contains("job")) {
        appId = appId.replaceAll("job", "application");
    }
    String partialFlowExecId = form.get(FLOW_EXEC_ID);
    partialFlowExecId = (partialFlowExecId != null) ? partialFlowExecId.trim() : null;
    String jobDefId = form.get(JOB_DEF_ID);
    jobDefId = jobDefId != null ? jobDefId.trim() : "";
    // Search and display job details when job id or flow execution url is provided.
    if (!appId.isEmpty()) {
        AppResult result = AppResult.find.select("*").fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, "*").fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "." + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS, "*").where().idEq(appId).findUnique();
        return ok(searchPage.render(null, jobDetails.render(result)));
    } else if (Utils.isSet(partialFlowExecId)) {
        IdUrlPair flowExecPair = bestSchedulerInfoMatchGivenPartialId(partialFlowExecId, AppResult.TABLE.FLOW_EXEC_ID);
        List<AppResult> results = AppResult.find.select(AppResult.getSearchFields() + "," + AppResult.TABLE.JOB_EXEC_ID).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields()).where().eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecPair.getId()).findList();
        Map<IdUrlPair, List<AppResult>> map = ControllerUtil.groupJobs(results, ControllerUtil.GroupBy.JOB_EXECUTION_ID);
        return ok(searchPage.render(null, flowDetails.render(flowExecPair, map)));
    } else if (!jobDefId.isEmpty()) {
        List<AppResult> results = AppResult.find.select(AppResult.getSearchFields() + "," + AppResult.TABLE.JOB_DEF_ID).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields()).where().eq(AppResult.TABLE.JOB_DEF_ID, jobDefId).findList();
        Map<IdUrlPair, List<AppResult>> map = ControllerUtil.groupJobs(results, ControllerUtil.GroupBy.FLOW_EXECUTION_ID);
        // all results should have the same flow id
        String flowDefId = (results.isEmpty()) ? "" : results.get(0).flowDefId;
        IdUrlPair flowDefIdPair = new IdUrlPair(flowDefId, AppResult.TABLE.FLOW_DEF_URL);
        return ok(searchPage.render(null, flowDefinitionIdDetails.render(flowDefIdPair, map)));
    }
    // Prepare pagination of results
    PaginationStats paginationStats = new PaginationStats(PAGE_LENGTH, PAGE_BAR_LENGTH);
    int pageLength = paginationStats.getPageLength();
    paginationStats.setCurrentPage(1);
    final Map<String, String[]> searchString = request().queryString();
    if (searchString.containsKey(PAGE)) {
        try {
            paginationStats.setCurrentPage(Integer.parseInt(searchString.get(PAGE)[0]));
        } catch (NumberFormatException ex) {
            logger.error("Error parsing page number. Setting current page to 1.");
            paginationStats.setCurrentPage(1);
        }
    }
    int currentPage = paginationStats.getCurrentPage();
    int paginationBarStartIndex = paginationStats.getPaginationBarStartIndex();
    // Filter jobs by search parameters
    Query<AppResult> query = generateSearchQuery(AppResult.getSearchFields(), getSearchParams());
    List<AppResult> results = query.setFirstRow((paginationBarStartIndex - 1) * pageLength).setMaxRows((paginationStats.getPageBarLength() - 1) * pageLength + 1).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields()).findList();
    paginationStats.setQueryString(getQueryString());
    if (results.isEmpty() || currentPage > paginationStats.computePaginationBarEndIndex(results.size())) {
        return ok(searchPage.render(null, jobDetails.render(null)));
    } else {
        List<AppResult> resultsToDisplay = results.subList((currentPage - paginationBarStartIndex) * pageLength, Math.min(results.size(), (currentPage - paginationBarStartIndex + 1) * pageLength));
        return ok(searchPage.render(paginationStats, searchResults.render(String.format("Results: Showing %,d of %,d", resultsToDisplay.size(), query.findRowCount()), resultsToDisplay)));
    }
}
Also used : AppResult(models.AppResult) List(java.util.List) ExpressionList(com.avaje.ebean.ExpressionList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DynamicForm(play.data.DynamicForm) Map(java.util.Map) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with DynamicForm

use of play.data.DynamicForm in project dr-elephant by linkedin.

the class Application method compare.

/**
 *   Controls the Compare Feature
 */
public static Result compare() {
    DynamicForm form = Form.form().bindFromRequest(request());
    String partialFlowExecId1 = form.get(COMPARE_FLOW_ID1);
    partialFlowExecId1 = (partialFlowExecId1 != null) ? partialFlowExecId1.trim() : null;
    String partialFlowExecId2 = form.get(COMPARE_FLOW_ID2);
    partialFlowExecId2 = (partialFlowExecId2 != null) ? partialFlowExecId2.trim() : null;
    List<AppResult> results1 = null;
    List<AppResult> results2 = null;
    if (partialFlowExecId1 != null && !partialFlowExecId1.isEmpty() && partialFlowExecId2 != null && !partialFlowExecId2.isEmpty()) {
        IdUrlPair flowExecIdPair1 = bestSchedulerInfoMatchGivenPartialId(partialFlowExecId1, AppResult.TABLE.FLOW_EXEC_ID);
        IdUrlPair flowExecIdPair2 = bestSchedulerInfoMatchGivenPartialId(partialFlowExecId2, AppResult.TABLE.FLOW_EXEC_ID);
        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, flowExecIdPair1.getId()).setMaxRows(100).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields()).findList();
        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).where().eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecIdPair2.getId()).setMaxRows(100).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields()).findList();
    }
    return ok(comparePage.render(compareResults.render(compareFlows(results1, results2))));
}
Also used : DynamicForm(play.data.DynamicForm) AppResult(models.AppResult)

Example 10 with DynamicForm

use of play.data.DynamicForm in project dr-elephant by linkedin.

the class Web method getFilterParamsForUserSummary.

/**
 * Returns the filter parameters for the user summary
 * @return The filter parameters for the user summary
 */
public static Map<String, String> getFilterParamsForUserSummary() {
    DynamicForm form = Form.form().bindFromRequest(request());
    Map<String, String> filterParams = new HashMap<String, String>();
    filterParams.put(Application.FINISHED_TIME_BEGIN, form.get(Application.FINISHED_TIME_BEGIN));
    filterParams.put(Application.FINISHED_TIME_END, form.get(Application.FINISHED_TIME_END));
    filterParams.put(Application.STARTED_TIME_BEGIN, form.get(Application.STARTED_TIME_BEGIN));
    filterParams.put(Application.STARTED_TIME_END, form.get(Application.STARTED_TIME_END));
    return filterParams;
}
Also used : HashMap(java.util.HashMap) DynamicForm(play.data.DynamicForm)

Aggregations

DynamicForm (play.data.DynamicForm)12 AppResult (models.AppResult)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ExpressionList (com.avaje.ebean.ExpressionList)5 LinkedHashMap (java.util.LinkedHashMap)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 Map (java.util.Map)4 ListOrderedMap (org.apache.commons.collections.map.ListOrderedMap)4 Gson (com.google.gson.Gson)3 JsonArray (com.google.gson.JsonArray)3 JsonObject (com.google.gson.JsonObject)3 AppHeuristicResult (models.AppHeuristicResult)2 SqlQuery (com.avaje.ebean.SqlQuery)1 SqlRow (com.avaje.ebean.SqlRow)1 ExceptionFinder (com.linkedin.drelephant.exceptions.ExceptionFinder)1 HadoopException (com.linkedin.drelephant.exceptions.HadoopException)1 HadoopSecurity (com.linkedin.drelephant.security.HadoopSecurity)1 IOException (java.io.IOException)1