Ejemplo n.º 1
0
  public void create(Project project) {
    Assert.isNull(
        projectService.findProject(project.getName()),
        "project  [" + project.getName() + "] has exist");
    MongoTemplate template = project.fetchMongoTemplate();
    Assert.notNull(template, "mongo uri is not access");
    Assert.notNull(template.getDb(), "mongo uri is not access");
    Assert.isTrue(
        project.fetchMongoTemplate().collectionExists(project.getLogCollection()),
        " [" + project.getLogCollection() + "] 日志表不存在");
    try {
      List<Task> taskList = Lists.newArrayList();
      logger.debug("init task count:{}", project.getTasks().size());
      for (Task _task : project.getTasks()) {

        Task task = getTemplateTask(_task);
        Task tempTask = renderTemplateTask(task, project);
        if (tempTask != null) taskList.add(tempTask);
      }
      project.setTasks(taskList);
    } catch (Exception e) {
      logger.error("", e);
      throw new IllegalArgumentException("自动添加监控脚本错误:" + e.getMessage());
    }
    projectService.saveProject(project);
  }
Ejemplo n.º 2
0
  @RequestMapping(value = "/projects/{projectName}/timeRange", method = RequestMethod.POST)
  public String update(ModelMap map, @PathVariable String projectName, TimeRange timeRange) {
    logger.debug("update  time range to {} of project {} ", timeRange, projectName);
    Project project = projectService.findProject(projectName);

    projectService.saveProject(project);
    return "redirect:/projects/" + projectName;
  }
Ejemplo n.º 3
0
  @RequestMapping(value = "/projects/{name}/members", method = RequestMethod.POST)
  public String update(ModelMap map, @PathVariable String name, String admins) throws IOException {
    Project dbProject = projectService.findProject(name);
    dbProject.setAdmins(Lists.newArrayList(admins.split(",")));

    projectService.saveProject(dbProject);

    return "redirect:/projects/" + name + "/settings/members";
  }
Ejemplo n.º 4
0
  /**
   * 更新指定项目
   *
   * @param map
   * @param name
   * @return
   */
  @RequestMapping(value = "/projects/{name}/info", method = RequestMethod.POST)
  public String update(ModelMap map, @PathVariable String name, Project project)
      throws IOException {
    Project dbProject = projectService.findProject(name);
    dbProject.setMailList(project.getMailList());
    dbProject.setLogCollection(project.getLogCollection());
    dbProject.setMongoUri(project.getMongoUri());
    dbProject.setAlias(project.getAlias());
    dbProject.setMetricCollection(project.getMetricCollection());
    projectService.saveProject(dbProject);

    return "redirect:/projects/" + name + "/settings/info";
  }
Ejemplo n.º 5
0
  @RequestMapping(value = "/projects/{name}/ext", method = RequestMethod.POST)
  public @ResponseBody WebResult updateNotify(
      @PathVariable String name, HttpServletRequest request, HttpEntity<Map> httpEntity)
      throws IOException {

    Map map = httpEntity.getBody();
    Project dbProject = projectService.findProject(name);
    dbProject.getProperties().putAll(map);
    logger.debug("update project ext properties {}", map);

    projectService.saveProject(dbProject);

    return new WebResult();
  }
Ejemplo n.º 6
0
  /**
   * 更新指定项目
   *
   * @param name
   * @return
   */
  @RequestMapping(value = "/projects/{name}/basic", method = RequestMethod.POST)
  public @ResponseBody WebResult updateBasic(@PathVariable String name, HttpEntity<Project> entity)
      throws IOException {
    Project project = entity.getBody();
    Project dbProject = projectService.findProject(name);
    dbProject.setMailList(project.getMailList());
    dbProject.setLogCollection(project.getLogCollection());
    dbProject.setMongoUri(project.getMongoUri());
    dbProject.setAlias(project.getAlias());
    dbProject.setMetricCollection(project.getMetricCollection());
    dbProject.setAdmins(project.getAdmins());
    projectService.saveProject(dbProject);

    return new WebResult();
  }
Ejemplo n.º 7
0
 /**
  * 进入设置项目页面
  *
  * @param map
  * @param name
  * @return
  * @throws IOException
  */
 @RequestMapping(value = "/projects/{name}/settings/{module}", method = RequestMethod.GET)
 public String settings(ModelMap map, @PathVariable String name, @PathVariable String module)
     throws IOException {
   Project project = projectService.findProject(name);
   map.put("project", project);
   map.put("module", module);
   return "project/settings";
 }
Ejemplo n.º 8
0
 @RequestMapping(value = "/project/list", method = RequestMethod.GET)
 public @ResponseBody ModelMap list(ModelMap map, HttpServletResponse response)
     throws IOException {
   List<Project> projects = projectService.findProjects();
   map.put("projects", projects);
   List<View> views = viewService.findAll();
   map.put("views", views);
   return map;
 }
Ejemplo n.º 9
0
  @RequestMapping(value = "/project/{name}", method = RequestMethod.GET)
  public @ResponseBody ModelMap showProject(ModelMap map, @PathVariable String name)
      throws IOException {
    Project project = projectService.findProject(name);
    map.put("project", project);
    map.put("metricNames", project.findMetricNames());

    return map;
  }
Ejemplo n.º 10
0
 /**
  * 查看项目
  *
  * @param map
  * @param name
  * @return
  * @throws IOException
  */
 @RequestMapping(value = "/projects/{name}", method = RequestMethod.GET)
 public String show(ModelMap map, @PathVariable String name) throws IOException {
   Project project = projectService.findProject(name);
   map.put("project", project);
   map.put("metricNames", project.findMetricNames());
   Map views = project.getViews();
   if (views.isEmpty()) {
     for (String metricName : project.findMetricNames()) views.put(metricName, metricName);
   }
   map.put("views", project.getViews());
   return "project/show";
 }
Ejemplo n.º 11
0
  public void createSelf() {
    Project project = new Project();
    project.setAlias("闪电狗");
    project.setName("flash_dog");
    setMongoInfoByLog4j(project);

    if (projectService.findProject(project.getName()) == null) {
      logger.debug("try create a monitor project for flash-dog {}", project);
      project.setTasks(initTasks);
      create(project);

    } else {
      logger.debug("projectName={} has exist ,skip create ", project.getName());
    }
  }
Ejemplo n.º 12
0
  /**
   * 创建项目
   *
   * @return
   * @throws IOException
   */
  @RequestMapping(value = "/projects/add", method = RequestMethod.POST)
  public @ResponseBody WebResult add(HttpEntity<Project> entity) throws IOException {
    Project project = entity.getBody();
    String userName = simpleAuthz.getPrincipal();
    project.setAdmins(Lists.newArrayList(userName));
    WebResult result = new WebResult();
    project.setMetricCollection(project.getMetricCollection());
    try {
      projectService.create(project);

    } catch (IllegalArgumentException e) {
      result.setSuccess(false);
      result.setMessage(e.getMessage());
    }
    return result;
  }
Ejemplo n.º 13
0
  /**
   * 创建项目
   *
   * @param map
   * @param response
   * @return
   * @throws IOException
   */
  @RequestMapping(value = "/projects", method = RequestMethod.POST)
  public String save(
      ModelMap map, HttpServletResponse response, Project project, BindingResult bindingResult)
      throws IOException {

    String userName = simpleAuthz.getPrincipal();
    project.setAdmins(Lists.newArrayList(userName));

    project.setMetricCollection(project.getMetricCollection());
    try {
      projectService.create(project);
      return "redirect:/projects/" + project.getName();
    } catch (IllegalArgumentException e) {
      map.put("project", project);
      map.put("flashMsg", e.getMessage());
      return "project/new";
    }
  }
Ejemplo n.º 14
0
  @RequestMapping(value = "/projects/{projectName}/destroy")
  public @ResponseBody WebResult delete(@PathVariable String projectName) throws IOException {
    projectService.remove(projectName);

    return new WebResult();
  }
Ejemplo n.º 15
0
 /**
  * 进入设置项目页面
  *
  * @param map
  * @param name
  * @return
  * @throws IOException
  */
 @RequestMapping("/projects/{name}/settings")
 public String edit(ModelMap map, @PathVariable String name) throws IOException {
   Project project = projectService.findProject(name);
   map.put("project", project);
   return "project/settings";
 }