Search in sources :

Example 1 with Html

use of play.api.templates.Html in project dr-elephant by linkedin.

the class Application method getHelp.

/**
 * Returns the help based on the version
 *
 * @param version The version for which help page has to be returned
 * @return The help page based on the version
 */
private static Result getHelp(Version version) {
    DynamicForm form = Form.form().bindFromRequest(request());
    String topic = form.get("topic");
    Html page = null;
    String title = "Help";
    if (topic != null && !topic.isEmpty()) {
        // check if it is a heuristic help
        page = ElephantContext.instance().getHeuristicToView().get(topic);
        // check if it is a metrics help
        if (page == null) {
            page = getMetricsNameView().get(topic);
        }
        if (page != null) {
            title = topic;
        }
    }
    if (version.equals(Version.NEW)) {
        return ok(helpPage.render(title, page));
    }
    return ok(oldHelpPage.render(title, page));
}
Also used : Html(play.api.templates.Html) DynamicForm(play.data.DynamicForm)

Example 2 with Html

use of play.api.templates.Html in project dr-elephant by linkedin.

the class ElephantContext method loadHeuristics.

/**
 * Load all the heuristics and their views configured in HeuristicConf.xml
 */
private void loadHeuristics() {
    Document document = Utils.loadXMLDoc(HEURISTICS_CONF);
    _heuristicsConfData = new HeuristicConfiguration(document.getDocumentElement()).getHeuristicsConfigurationData();
    for (HeuristicConfigurationData data : _heuristicsConfData) {
        // Load all the heuristic classes
        try {
            Class<?> heuristicClass = Class.forName(data.getClassName());
            Object instance = heuristicClass.getConstructor(HeuristicConfigurationData.class).newInstance(data);
            if (!(instance instanceof Heuristic)) {
                throw new IllegalArgumentException("Class " + heuristicClass.getName() + " is not an implementation of " + Heuristic.class.getName());
            }
            ApplicationType type = data.getAppType();
            List<Heuristic> heuristics = _typeToHeuristics.get(type);
            if (heuristics == null) {
                heuristics = new ArrayList<Heuristic>();
                _typeToHeuristics.put(type, heuristics);
            }
            heuristics.add((Heuristic) instance);
            logger.info("Load Heuristic : " + data.getClassName());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Could not find class " + data.getClassName(), e);
        } catch (InstantiationException e) {
            throw new RuntimeException("Could not instantiate class " + data.getClassName(), e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Could not access constructor for class" + data.getClassName(), e);
        } catch (RuntimeException e) {
            // More descriptive on other runtime exception such as ClassCastException
            throw new RuntimeException(data.getClassName() + " is not a valid Heuristic class.", e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException("Could not invoke class " + data.getClassName(), e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("Could not find constructor for class " + data.getClassName(), e);
        }
        // Load all the heuristic views
        try {
            Class<?> viewClass = Class.forName(data.getViewName());
            Method render = viewClass.getDeclaredMethod("render");
            Html page = (Html) render.invoke(null);
            _heuristicToView.put(data.getHeuristicName(), page);
            logger.info("Load View : " + data.getViewName());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Could not find view " + data.getViewName(), e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Could not access render on view" + data.getViewName(), e);
        } catch (RuntimeException e) {
            // More descriptive on other runtime exception such as ClassCastException
            throw new RuntimeException(data.getViewName() + " is not a valid view class.", e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException("Could not invoke view " + data.getViewName(), e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("Could not find method render for view " + data.getViewName(), e);
        }
    }
    // Bind No_DATA heuristic to its helper pages, no need to add any real configurations
    _heuristicsConfData.add(new HeuristicConfigurationData(HeuristicResult.NO_DATA.getHeuristicName(), HeuristicResult.NO_DATA.getHeuristicClassName(), "views.html.help.helpNoData", null, null));
}
Also used : HeuristicConfigurationData(com.linkedin.drelephant.configurations.heuristic.HeuristicConfigurationData) Html(play.api.templates.Html) Method(java.lang.reflect.Method) Document(org.w3c.dom.Document) InvocationTargetException(java.lang.reflect.InvocationTargetException) ApplicationType(com.linkedin.drelephant.analysis.ApplicationType) HeuristicConfiguration(com.linkedin.drelephant.configurations.heuristic.HeuristicConfiguration) Heuristic(com.linkedin.drelephant.analysis.Heuristic)

Aggregations

Html (play.api.templates.Html)2 ApplicationType (com.linkedin.drelephant.analysis.ApplicationType)1 Heuristic (com.linkedin.drelephant.analysis.Heuristic)1 HeuristicConfiguration (com.linkedin.drelephant.configurations.heuristic.HeuristicConfiguration)1 HeuristicConfigurationData (com.linkedin.drelephant.configurations.heuristic.HeuristicConfigurationData)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Document (org.w3c.dom.Document)1 DynamicForm (play.data.DynamicForm)1