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); }
@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; }
@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"; }
/** * 更新指定项目 * * @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"; }
@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(); }
/** * 更新指定项目 * * @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(); }
/** * 进入设置项目页面 * * @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"; }
@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; }
@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; }
/** * 查看项目 * * @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"; }
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()); } }
/** * 创建项目 * * @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; }
/** * 创建项目 * * @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"; } }
@RequestMapping(value = "/projects/{projectName}/destroy") public @ResponseBody WebResult delete(@PathVariable String projectName) throws IOException { projectService.remove(projectName); return new WebResult(); }
/** * 进入设置项目页面 * * @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"; }