Search in sources :

Example 16 with ModelMap

use of org.springframework.ui.ModelMap in project jstorm by alibaba.

the class LogController method search.

@RequestMapping(value = "/logSearch", method = RequestMethod.GET)
public String search(@RequestParam(value = "cluster", required = true) String clusterName, @RequestParam(value = "host", required = true) String host, @RequestParam(value = "port", required = true) String logServerPort, @RequestParam(value = "dir", required = true) String dir, @RequestParam(value = "file", required = true) String logName, @RequestParam(value = "key", required = false) String keyword, @RequestParam(value = "workerPort", required = false) String workerPort, @RequestParam(value = "tid", required = false) String topologyId, @RequestParam(value = "pos", required = false) String pos, @RequestParam(value = "caseIgnore", required = false) String caseIgnore, ModelMap model) {
    clusterName = StringEscapeUtils.escapeHtml(clusterName);
    topologyId = StringEscapeUtils.escapeHtml(topologyId);
    if (StringUtils.isBlank(dir)) {
        dir = ".";
    }
    String fullFile = getFullFile(dir, logName);
    boolean _caseIgnore = !StringUtils.isBlank(caseIgnore);
    model.addAttribute("keyword", keyword);
    try {
        // encode space and url characters
        keyword = URLEncoder.encode(keyword, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        LOG.error(e.getMessage(), e);
        UIUtils.addErrorAttribute(model, e);
    }
    String url = String.format("http://%s:%s/logview?cmd=searchLog&file=%s&key=%s&offset=%s&case_ignore=%s", host, logServerPort, fullFile, keyword, JStormUtils.parseLong(pos, 0), _caseIgnore);
    if (filterKeyword(model, keyword)) {
        try {
            HttpResponse httpResponse = httpGet(url);
            String data = EntityUtils.toString(httpResponse.getEntity());
            Map result = (Map) JStormUtils.from_json(data);
            if (result == null) {
                model.addAttribute("tip", data);
            } else if (result.get("error") != null) {
                model.addAttribute("tip", result.get("msg"));
            } else {
                model.addAttribute("matchResults", result.get("match_results"));
                model.addAttribute("nextOffset", result.get("next_offset"));
                model.addAttribute("numMatch", result.get("num_match"));
            }
        } catch (IOException e) {
            e.printStackTrace();
            model.addAttribute("tip", "Internal Error, can't get response from logview");
        }
    }
    model.addAttribute("host", host);
    model.addAttribute("clusterName", clusterName);
    model.addAttribute("logServerPort", logServerPort);
    model.addAttribute("topologyId", topologyId);
    model.addAttribute("workerPort", workerPort);
    model.addAttribute("dir", dir);
    model.addAttribute("file", logName);
    model.addAttribute("caseIgnore", _caseIgnore);
    UIUtils.addTitleAttribute(model, "LogSearch");
    return "logSearch";
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with ModelMap

use of org.springframework.ui.ModelMap in project jstorm by alibaba.

the class LogController method deepSearch.

@RequestMapping(value = "/deepSearch", method = RequestMethod.GET)
public String deepSearch(@RequestParam(value = "cluster", required = true) String clusterName, @RequestParam(value = "tid", required = true) String topologyId, @RequestParam(value = "key", required = false) String keyword, @RequestParam(value = "caseIgnore", required = false) String caseIgnore, ModelMap model) {
    clusterName = StringEscapeUtils.escapeHtml(clusterName);
    topologyId = StringEscapeUtils.escapeHtml(topologyId);
    boolean _caseIgnore = !StringUtils.isBlank(caseIgnore);
    int port = UIUtils.getSupervisorPort(clusterName);
    model.addAttribute("keyword", keyword);
    List<Future<?>> futures = new ArrayList<>();
    ConcurrentLinkedQueue<Map> result = new ConcurrentLinkedQueue<>();
    if (filterKeyword(model, keyword)) {
        NimbusClient client = null;
        try {
            // encode space and url characters
            keyword = URLEncoder.encode(keyword, "UTF-8");
            client = NimbusClientManager.getNimbusClient(clusterName);
            TopologyInfo info = client.getClient().getTopologyInfo(topologyId);
            String topologyName = info.get_topology().get_name();
            List<UIWorkerMetric> workerData = UIMetricUtils.getWorkerMetrics(info.get_metrics().get_workerMetric(), topologyId, 60);
            String dir = "." + File.separator + topologyName;
            for (UIWorkerMetric metric : workerData) {
                String logFile = topologyName + "-worker-" + metric.getPort() + ".log";
                String url = String.format("http://%s:%s/logview?cmd=searchLog&file=%s&key=%s&offset=%s&case_ignore=%s", metric.getHost(), port, getFullFile(dir, logFile), keyword, 0, _caseIgnore);
                futures.add(_backround.submit(new SearchRequest(url, metric.getHost(), metric.getPort(), dir, logFile, result)));
            }
            JStormServerUtils.checkFutures(futures);
            model.addAttribute("result", result);
        } catch (NotAliveException nae) {
            model.addAttribute("tip", String.format("The topology: %s is dead.", topologyId));
        } catch (Exception e) {
            NimbusClientManager.removeClient(clusterName);
            LOG.error(e.getMessage(), e);
            UIUtils.addErrorAttribute(model, e);
        }
    }
    model.addAttribute("clusterName", clusterName);
    model.addAttribute("topologyId", topologyId);
    model.addAttribute("logServerPort", port);
    model.addAttribute("caseIgnore", _caseIgnore);
    UIUtils.addTitleAttribute(model, "DeepSearch");
    return "deepSearch";
}
Also used : UIWorkerMetric(com.alibaba.jstorm.ui.model.UIWorkerMetric) NimbusClient(backtype.storm.utils.NimbusClient) NotAliveException(backtype.storm.generated.NotAliveException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotAliveException(backtype.storm.generated.NotAliveException) ModelMap(org.springframework.ui.ModelMap) TopologyInfo(backtype.storm.generated.TopologyInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with ModelMap

use of org.springframework.ui.ModelMap in project jstorm by alibaba.

the class LogController method show.

@RequestMapping(value = "/log", method = RequestMethod.GET)
public String show(@RequestParam(value = "cluster", required = true) String clusterName, @RequestParam(value = "host", required = true) String host, @RequestParam(value = "port", required = false) String logServerPort, @RequestParam(value = "dir", required = false) String dir, @RequestParam(value = "wport", required = false) String workerPort, @RequestParam(value = "file", required = false) String logName, @RequestParam(value = "tid", required = false) String topologyId, @RequestParam(value = "pos", required = false) String pos, ModelMap model) {
    clusterName = StringEscapeUtils.escapeHtml(clusterName);
    topologyId = StringEscapeUtils.escapeHtml(topologyId);
    if (StringUtils.isBlank(dir)) {
        dir = ".";
    }
    Map conf = UIUtils.getNimbusConf(clusterName);
    Event event = new Event(clusterName, host, logServerPort, logName, topologyId, workerPort, pos, dir, conf);
    try {
        requestLog(event, model);
    } catch (IOException e) {
        e.printStackTrace();
    }
    model.addAttribute("logName", event.logName);
    model.addAttribute("host", host);
    model.addAttribute("dir", event.dir);
    model.addAttribute("clusterName", clusterName);
    model.addAttribute("logServerPort", logServerPort);
    model.addAttribute("topologyId", topologyId);
    model.addAttribute("fullFile", getFullFile(event.dir, event.logName));
    model.addAttribute("workerPort", workerPort);
    return "log";
}
Also used : IOException(java.io.IOException) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with ModelMap

use of org.springframework.ui.ModelMap in project jstorm by alibaba.

the class NettyController method show.

@RequestMapping(value = "/netty", method = RequestMethod.GET)
public String show(@RequestParam(value = "cluster", required = true) String clusterName, @RequestParam(value = "topology", required = true) String topology_id, @RequestParam(value = "host", required = true) String host, @RequestParam(value = "page", required = false) String page, @RequestParam(value = "win", required = false) String win, ModelMap model) {
    clusterName = StringEscapeUtils.escapeHtml(clusterName);
    long start = System.currentTimeMillis();
    host = NetWorkUtils.host2Ip(host);
    int window = UIUtils.parseWindow(win);
    UIUtils.addWindowAttribute(model, window);
    int _page = JStormUtils.parseInt(page, 1);
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(clusterName);
        //get netty metrics, page is from 1
        MetricInfo nettyMetric = client.getClient().getPagingNettyMetrics(topology_id, host, _page);
        //            System.out.println("nettyMetric:"+nettyMetric);
        List<UINettyMetric> nettyData = getNettyData(nettyMetric, host, window);
        model.addAttribute("nettyMetrics", nettyData);
        model.addAttribute("nettyHead", UIMetricUtils.sortHead(nettyData, UINettyMetric.HEAD));
        int size = client.getClient().getNettyMetricSizeByHost(topology_id, host);
        //            System.out.println("netty size:"+size);
        int pageSize = (size + PAGE_SIZE - 1) / PAGE_SIZE;
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("curPage", _page);
        if (size == 0) {
            //check whether netty metric is turn off
            Map conf = UIUtils.getTopologyConf(clusterName, topology_id);
            boolean enable = MetricUtils.isEnableNettyMetrics(conf);
            if (!enable) {
                model.addAttribute("flush", "the netty metrics is not enabled");
            }
        }
    } catch (Exception e) {
        NimbusClientManager.removeClient(clusterName);
        LOG.error(e.getMessage(), e);
        UIUtils.addErrorAttribute(model, e);
    }
    // page information
    model.addAttribute("clusterName", clusterName);
    model.addAttribute("host", host);
    model.addAttribute("page", "netty");
    model.addAttribute("topologyId", topology_id);
    model.addAttribute("supervisorPort", UIUtils.getSupervisorPort(clusterName));
    UIUtils.addTitleAttribute(model, "Netty Summary");
    LOG.info("netty page show cost:{}ms", System.currentTimeMillis() - start);
    return "netty";
}
Also used : MetricInfo(backtype.storm.generated.MetricInfo) UINettyMetric(com.alibaba.jstorm.ui.model.UINettyMetric) NimbusClient(backtype.storm.utils.NimbusClient) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with ModelMap

use of org.springframework.ui.ModelMap in project gocd by gocd.

the class MyGoInterceptorTest method shouldPutSecurityIsEnabledIntoModelAndView.

@Test
public void shouldPutSecurityIsEnabledIntoModelAndView() throws Exception {
    securityIs(true);
    smtpIs(true);
    myGoInterceptor.postHandle(request, response, null, modelAndView);
    ModelMap modelMap = modelAndView.getModelMap();
    assertThat(modelMap.get(SECURITY_IS_ENABLED), is(true));
    assertThat(modelMap.get(SMTP_IS_ENABLED), is(true));
}
Also used : ModelMap(org.springframework.ui.ModelMap) Test(org.junit.Test)

Aggregations

ModelMap (org.springframework.ui.ModelMap)48 Test (org.junit.Test)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 ModelAndView (org.springframework.web.servlet.ModelAndView)11 RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)5 Map (java.util.Map)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IOException (java.io.IOException)3 Date (java.util.Date)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 HttpSessionRequiredException (org.springframework.web.HttpSessionRequiredException)3 RedirectAttributes (org.springframework.web.servlet.mvc.support.RedirectAttributes)3 NimbusClient (backtype.storm.utils.NimbusClient)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2