コード例 #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);
  }
コード例 #2
0
ファイル: TimeRangeAction.java プロジェクト: zogwei/flash-dog
  @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;
  }
コード例 #3
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
  @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";
  }
コード例 #4
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
  /**
   * 更新指定项目
   *
   * @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";
  }
コード例 #5
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
  @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();
  }
コード例 #6
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
  /**
   * 更新指定项目
   *
   * @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();
  }
コード例 #7
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
 /**
  * 进入设置项目页面
  *
  * @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";
 }
コード例 #8
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
 @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;
 }
コード例 #9
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
  @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;
  }
コード例 #10
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
 /**
  * 查看项目
  *
  * @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";
 }
コード例 #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());
    }
  }
コード例 #12
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
  /**
   * 创建项目
   *
   * @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;
  }
コード例 #13
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
  /**
   * 创建项目
   *
   * @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";
    }
  }
コード例 #14
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
  @RequestMapping(value = "/projects/{projectName}/destroy")
  public @ResponseBody WebResult delete(@PathVariable String projectName) throws IOException {
    projectService.remove(projectName);

    return new WebResult();
  }
コード例 #15
0
ファイル: ProjectAction.java プロジェクト: zogwei/flash-dog
 /**
  * 进入设置项目页面
  *
  * @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";
 }