Authored by fanzelei

Merge branch 'master' of http://git.yoho.cn/ops/monitor-ui

... ... @@ -45,6 +45,32 @@ public class HttpRestClient {
}
}
public <T> T get(String url, Class<T> responseType,Map<String, ?> map) {
try {
StringBuilder uri = new StringBuilder(url);
if(map != null){
uri.append("?");
for (Map.Entry<String, ?> entry : map.entrySet()) {
uri.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
}
return restTemplate.getForObject(uri.toString().substring(0, uri.length()-1), responseType);
}
return restTemplate.getForObject(url, responseType);
} catch (Exception e) {
logger.error("getForObject failed!url: "+url, e);
return null;
}
}
public <T> T post(String url, Object request, Class<T> responseType) {
try {
return restTemplate.postForObject(url, request,responseType);
} catch (Exception e) {
logger.error("postForObject failed!url:"+url, e);
return null;
}
}
public <T> T defaultGet(String uri, Class<T> responseType) {
try {
return restTemplate.getForObject(systemConfig.getServiceUrl() + uri, responseType);
... ...
package com.ui.model.req;
import java.io.Serializable;
@SuppressWarnings("serial")
public class BuildRequest implements Serializable {
private String project;
private String environment;
private String operate;
private String rollbackfile;
private String messageid;
private String tag;
private String branch;
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getProject() {
return project;
}
public void setProject(String project) {
this.project = project;
}
public String getEnvironment() {
return environment;
}
public void setEnvironment(String environment) {
this.environment = environment;
}
public String getOperate() {
return operate;
}
public void setOperate(String operate) {
this.operate = operate;
}
public String getRollbackfile() {
return rollbackfile;
}
public void setRollbackfile(String rollbackfile) {
this.rollbackfile = rollbackfile;
}
public String getMessageid() {
return messageid;
}
public void setMessageid(String messageid) {
this.messageid = messageid;
}
public String getBranch() {
return branch;
}
public void setBranch(String branch) {
this.branch = branch;
}
}
... ...
package com.ui.project;
/**
* Created by zhengyouwei on 2016/6/29.
*/
public class Project {
private String order;//顺序
private String name;
private String projectid;
private String group;
public Project(){
}
public Project(String order, String name, String projectid, String group){
this.order = order;
this.name = name;
this.projectid = projectid;
this.group = group;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getProjectid() {
return projectid;
}
public void setProjectid(String projectid) {
this.projectid = projectid;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
}
... ...
package com.ui.project;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class ProjectEnvironment {
private static Map<String,String> map = new HashMap<>();
static{
map.put("aws", "");
map.put("qcloud","");
map.put("qcloud_gray","");
map.put("test","http://192.168.102.220:8080/web/");
//map.put("dev");
}
public static Set<String> getEnviroments(){
return map.keySet();
}
public static String getUrl(String envi){
return map.get(envi);
}
}
... ...
package com.ui.project;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ProjectOnline {
private static List<Project> list = new ArrayList<Project>();
private static Map<String,Project> map = new HashMap<String,Project>();
static{
list.add(new Project("1","yoho-gateway","126","yoho30"));
list.add(new Project("1","yoho-users","134","yoho30"));
list.add(new Project("1","yoho-message","123","yoho30"));
list.add(new Project("1","yoho-sns","125","yoho30"));
list.add(new Project("1","yoho-push","137","yoho30"));
list.add(new Project("1","yohobuy-resources","122","yoho30"));
list.add(new Project("1","yohobuy-order","124","yoho30"));
list.add(new Project("1","yohobuy-promotion","140","yoho30"));
list.add(new Project("1","yohobuy-product","143","yoho30"));
list.add(new Project("1","yohobuy-union","133","yoho30"));
list.add(new Project("1","yohobuy-activity","129","yoho30"));
list.add(new Project("1","yohobuy-task","138","yoho30"));
list.add(new Project("1","yohobuy-wechat","248","yoho30"));
list.add(new Project("1","yohobuy-brower","131","yoho30"));
list.add(new Project("2","yoho-search-service","12","yoho-search"));
list.add(new Project("2","yoho-search-consumer","8","yoho-search"));
list.add(new Project("2","yoho-search-producer","7","yoho-search"));
list.add(new Project("3","yohobuy-platform","110","platform"));
list.add(new Project("3","yohobuy-bigdata","113","platform"));
for(Project project :list){
map.put(project.getName(),project);
}
}
public static List<Project> getProjectList() {
return list;
}
public static Project getProject(String name){
return map.get(name);
}
}
... ...
package com.ui.ctrl;
import com.alibaba.fastjson.JSONArray;
import com.ui.http.HttpRestClient;
import com.ui.model.req.BuildRequest;
import com.ui.project.ProjectEnvironment;
import com.ui.project.ProjectOnline;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("/project")
public class ProjectBuildCtrl {
@Autowired
private HttpRestClient httpRestClient;
@RequestMapping(value = "projectbuild")
public ModelAndView projectbuild(Model model) {
model.addAttribute("environments", ProjectEnvironment.getEnviroments());
return new ModelAndView("jsp/project/project");
}
/**
* 获取所有项目
*
* @return
*/
@RequestMapping(value = "getProjects", method = RequestMethod.POST)
@ResponseBody
public String getProjects() {
try {
return JSONArray.toJSON(ProjectOnline.getProjectList()).toString();
} catch (Exception ex) {
return "failed";
}
}
/**
* 校验tag
*
* @return
*/
@RequestMapping(value = "checkTag", method = RequestMethod.POST)
@ResponseBody
public String checkTag(String projects, String tag, String enviromment) {
Map<String, String> map = new HashMap<>();
map.put("projects", projects);
map.put("tag", tag);
return httpRestClient.get(ProjectEnvironment.getUrl(enviromment) + "checkTag", String.class, map);
}
/**
* 校验branch
*
* @return
*/
@RequestMapping(value = "checkBranch")
@ResponseBody
public String checkBranch(String projects, String branch, String environment) {
if (!("master".equals(branch) || "test".equals(branch) || "dev".equals(branch))) {
Map<String, String> map = new HashMap<>();
map.put("projects", projects);
map.put("branch", branch);
return httpRestClient.get(ProjectEnvironment.getUrl(environment) + "checkBranch", String.class, map);
}
return "1";
}
/**
* 执行任务
*
* @param request
* @return
*/
@RequestMapping(value = "build", method = RequestMethod.POST)
@ResponseBody
public String build(@RequestBody BuildRequest request) {
try {
return httpRestClient.post(ProjectEnvironment.getUrl(request.getEnvironment()) + "build", request, String.class);
} catch (Exception ex) {
return "failed";
}
}
/**
* 获取执行结果
*
* @param messageid
* @return
*/
@RequestMapping(value = "getbuildmsg", method = RequestMethod.POST)
@ResponseBody
public String getbuildmsg(String messageid, String project) {
try {
Map<String, String> map = new HashMap<>();
map.put("messageid", messageid);
map.put("project", project);
return httpRestClient.get(ProjectEnvironment.getUrl(messageid.split("_")[0]) + "getbuildmsg", String.class, map);
} catch (Exception ex) {
return "failed";
}
}
@RequestMapping(value = "cancelBuild")
@ResponseBody
public String cancelBuild(String id) {
try {
Map<String, String> map = new HashMap<>();
map.put("id", id);
return httpRestClient.get(ProjectEnvironment.getUrl(id.split("_")[0]) + "cancelBuild", String.class, map);
} catch (Exception ex) {
return "failed";
}
}
@RequestMapping(value = "rollbackList", method = RequestMethod.POST)
@ResponseBody
public String rollbackList(String project, String environment) {
try {
Map<String, String> map = new HashMap<>();
map.put("project", project);
map.put("environment", environment);
return httpRestClient.get(ProjectEnvironment.getUrl(environment) + "rollbackList", String.class, map);
} catch (Exception ex) {
return "failed";
}
}
}
... ...
... ... @@ -27,23 +27,8 @@
</div>
</div>
</div>
<div id="testDiv"></div>
<script type="text/javascript">
$.ajax({
url: contextPath + "/redisInfo/getRedisInfo",
type: 'post',
async: false,
dataType: "json",
success: function (data) {
if(data.data!=null&&data.data!=''){
console.log(data.data);
var chart = new FusionCharts("<%=basePath %>/js/charts/DragNode.swf", "ChartId", "1650", "650", "0");
chart.setXMLData(data.data);
chart.render("chartdiv");
}else{
alert("数据加载失败!");
}
}
});
var chart = new FusionCharts("<%=basePath %>/js/charts/DragNode.swf", "ChartId", "1650", "650", "0");
chart.setXMLData(dataString );
chart.render("chartdiv");
</script>
\ No newline at end of file
... ...