Search in sources :

Example 36 with RequestMapping

use of org.springframework.web.bind.annotation.RequestMapping in project jstorm by alibaba.

the class ClusterAPIController method metrics.

@RequestMapping("/metrics")
public Map metrics(@PathVariable String clusterName) {
    //we only get the 60s window
    int window = 60;
    Map ret;
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(clusterName);
        List<MetricInfo> infos = client.getClient().getMetrics(JStormMetrics.CLUSTER_METRIC_KEY, MetaType.TOPOLOGY.getT());
        List<ChartSeries> metrics = UIUtils.getChartSeries(infos, window);
        ret = new HashMap<>();
        ret.put("metrics", metrics);
    } catch (Exception e) {
        NimbusClientManager.removeClient(clusterName);
        ret = UIUtils.exceptionJson(e);
        LOG.error(e.getMessage(), e);
    }
    return ret;
}
Also used : NimbusClient(backtype.storm.utils.NimbusClient) ChartSeries(com.alibaba.jstorm.ui.model.graph.ChartSeries) HashMap(java.util.HashMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with RequestMapping

use of org.springframework.web.bind.annotation.RequestMapping in project jstorm by alibaba.

the class ClusterAPIController method zookeepers.

@RequestMapping("/zookeeper/summary")
public Map zookeepers(@PathVariable String clusterName) {
    Map ret = new HashMap<>();
    List<ZooKeeperEntity> zkServers = UIUtils.getZooKeeperEntities(clusterName);
    ret.put("zookeepers", zkServers);
    return ret;
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with RequestMapping

use of org.springframework.web.bind.annotation.RequestMapping in project jstorm by alibaba.

the class TopologyAPIController method graph.

@RequestMapping("/graph")
public Map graph(@PathVariable String clusterName, @PathVariable String topology) {
    Map<String, Object> result = new HashMap<>();
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(clusterName);
        StormTopology stormTopology = client.getClient().getTopology(topology);
        int size = componentSize(stormTopology);
        if (size < 100) {
            List<MetricInfo> componentMetrics = client.getClient().getMetrics(topology, MetaType.COMPONENT.getT());
            TopologyGraph graph = UIUtils.getTopologyGraph(stormTopology, componentMetrics);
            result.put("graph", graph);
        } else {
            result.put("error", "too many components, please check your topology first!");
        }
    } catch (Exception e) {
        NimbusClientManager.removeClient(clusterName);
        LOG.error(e.getMessage(), e);
        result = UIUtils.exceptionJson(e);
    }
    return result;
}
Also used : TopologyGraph(com.alibaba.jstorm.ui.model.graph.TopologyGraph) NimbusClient(backtype.storm.utils.NimbusClient) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with RequestMapping

use of org.springframework.web.bind.annotation.RequestMapping in project jstorm by alibaba.

the class ClusterController method show.

@RequestMapping(value = "/cluster", method = RequestMethod.GET)
public String show(@RequestParam(value = "name", required = true) String name, ModelMap model) {
    name = StringEscapeUtils.escapeHtml(name);
    long start = System.currentTimeMillis();
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(name);
        ClusterSummary clusterSummary = client.getClient().getClusterInfo();
        model.addAttribute("nimbus", UIUtils.getNimbusEntities(clusterSummary));
        model.addAttribute("topologies", UIUtils.getTopologyEntities(clusterSummary));
        model.addAttribute("supervisors", UIUtils.getSupervisorEntities(clusterSummary));
        model.addAttribute("zkServers", UIUtils.getZooKeeperEntities(name));
        List<MetricInfo> clusterMetrics = client.getClient().getMetrics(JStormMetrics.CLUSTER_METRIC_KEY, MetaType.TOPOLOGY.getT());
        UISummaryMetric clusterData = UIMetricUtils.getSummaryMetrics(clusterMetrics, AsmWindow.M1_WINDOW);
        model.addAttribute("clusterData", clusterData);
        model.addAttribute("clusterHead", UIMetricUtils.sortHead(clusterData, UISummaryMetric.HEAD));
        //update cluster cache
        ClusterEntity ce = UIUtils.getClusterEntity(clusterSummary, name);
        model.addAttribute("cluster", ce);
        UIUtils.clustersCache.put(name, ce);
    } catch (Exception e) {
        NimbusClientManager.removeClient(name);
        LOG.error(e.getMessage(), e);
        UIUtils.addErrorAttribute(model, e);
    }
    //set nimbus port and supervisor port , if necessary
    model.addAttribute("nimbusPort", UIUtils.getNimbusPort(name));
    model.addAttribute("supervisorPort", UIUtils.getSupervisorPort(name));
    model.addAttribute("clusterName", name);
    model.addAttribute("page", "cluster");
    UIUtils.addTitleAttribute(model, "Cluster Summary");
    LOG.info("cluster page show cost:{}ms", System.currentTimeMillis() - start);
    return "cluster";
}
Also used : NimbusClient(backtype.storm.utils.NimbusClient) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with RequestMapping

use of org.springframework.web.bind.annotation.RequestMapping 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)

Aggregations

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1964 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)459 ModelAndView (org.springframework.web.servlet.ModelAndView)413 ApiOperation (io.swagger.annotations.ApiOperation)305 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)234 ArrayList (java.util.ArrayList)197 HashMap (java.util.HashMap)155 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)124 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)124 IOException (java.io.IOException)97 ResponseEntity (org.springframework.http.ResponseEntity)92 Date (java.util.Date)83 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)80 DBObject (com.mongodb.DBObject)71 BasicDBObject (com.mongodb.BasicDBObject)67 InputStream (java.io.InputStream)66 Aggregation.newAggregation (org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation)64 HttpServletResponse (javax.servlet.http.HttpServletResponse)59 User (org.hisp.dhis.user.User)59 List (java.util.List)53