Authored by zhengyouwei

dns

  1 +package com.ui.ctrl;
  2 +
  3 +import com.ui.http.HttpRestClient;
  4 +import com.ui.model.domain.BuildMessage;
  5 +import com.ui.model.req.BuildRequest;
  6 +import com.ui.model.req.User;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.ui.Model;
  11 +import org.springframework.web.bind.annotation.RequestMapping;
  12 +import org.springframework.web.bind.annotation.RequestMethod;
  13 +import org.springframework.web.bind.annotation.ResponseBody;
  14 +import org.springframework.web.bind.annotation.RestController;
  15 +import org.springframework.web.servlet.ModelAndView;
  16 +
  17 +import javax.servlet.http.HttpSession;
  18 +import java.util.ArrayList;
  19 +import java.util.HashMap;
  20 +import java.util.List;
  21 +import java.util.Map;
  22 +
  23 +
  24 +@RestController
  25 +@RequestMapping("dnsBuild")
  26 +public class DnsBuildCtrl {
  27 + Logger log = LoggerFactory.getLogger(DnsBuildCtrl.class);
  28 +
  29 + @Autowired
  30 + private HttpRestClient httpRestClient;
  31 +
  32 + private String URL = "http://172.31.16.167:8883/dns/";
  33 +
  34 + @RequestMapping("/toProject")
  35 + public ModelAndView toProject(Model model) {
  36 + return new ModelAndView("project/dns_project");
  37 + }
  38 +
  39 + /**
  40 + * 获取所有项目
  41 + *
  42 + * @return
  43 + */
  44 + @RequestMapping(value = "getProjects", method = RequestMethod.POST)
  45 + @ResponseBody
  46 + public String getProjects() {
  47 + try {
  48 + return httpRestClient.get(URL + "getProjects", String.class, null);
  49 + } catch (Exception ex) {
  50 + return "failed";
  51 + }
  52 + }
  53 +
  54 + /**
  55 + * 获取所有项目
  56 + *
  57 + * @return
  58 + */
  59 + @RequestMapping(value = "getProject", method = RequestMethod.POST)
  60 + @ResponseBody
  61 + public String getProjects(String name) {
  62 + try {
  63 + return httpRestClient.get(URL + "getProject?name="+name , String.class, null);
  64 + } catch (Exception ex) {
  65 + return "failed";
  66 + }
  67 + }
  68 +
  69 +
  70 + /**
  71 + * 执行任务
  72 + *
  73 + * @return
  74 + */
  75 + @RequestMapping(value = "build", method = RequestMethod.POST)
  76 + public ModelAndView build(String project_name, String environment_name, String operate_name, String branch_name, String rollbackfile_name,String hosts_name, Model model, HttpSession session) {
  77 + try {
  78 + User user = (User) session.getAttribute("user");
  79 + List<BuildMessage> list = new ArrayList<>();
  80 + BuildRequest buildRequest = new BuildRequest();
  81 + buildRequest.setBranch(branch_name);
  82 + buildRequest.setUser(user.getName());
  83 + buildRequest.setEnvironment(environment_name);
  84 + buildRequest.setRollbackfile(rollbackfile_name);
  85 + buildRequest.setOperate(operate_name);
  86 + buildRequest.setHost(hosts_name);
  87 +
  88 + String messageids = "";
  89 + if ("Deploy".equals(operate_name)) {
  90 + String[] array = project_name.split(",");
  91 + if (array.length > 4) {
  92 + String[] newArray = new String[]{"", "", "", ""};
  93 + for (int i = 0; i < array.length; i++) {
  94 + newArray[i % 4] = newArray[i % 4] + array[i] + ",";
  95 + }
  96 + for (String project : newArray) {
  97 + buildRequest.setProject(project.substring(0, project.length() - 1));
  98 + BuildMessage buildMessage = httpRestClient.post(URL + "build", buildRequest, BuildMessage.class);
  99 + if (buildMessage != null) {
  100 + list.add(buildMessage);
  101 + messageids = messageids + buildMessage.getId() + ",";
  102 + }
  103 + }
  104 +
  105 + } else {
  106 + for (String project : array) {
  107 + buildRequest.setProject(project);
  108 + BuildMessage buildMessage = httpRestClient.post(URL + "build", buildRequest, BuildMessage.class);
  109 + if (buildMessage != null) {
  110 + list.add(buildMessage);
  111 + messageids = messageids + buildMessage.getId() + ",";
  112 + }
  113 + }
  114 + }
  115 +
  116 +
  117 + } else {
  118 + buildRequest.setProject(project_name);
  119 + BuildMessage buildMessage = httpRestClient.post(URL + "build", buildRequest, BuildMessage.class);
  120 + if (buildMessage != null) {
  121 + list.add(buildMessage);
  122 + messageids = messageids + buildMessage.getId() + ",";
  123 + }
  124 + }
  125 + model.addAttribute("environment_name", environment_name);
  126 + model.addAttribute("operate_name", operate_name);
  127 + model.addAttribute("branch_name", branch_name);
  128 + model.addAttribute("rollbackfile_name", rollbackfile_name);
  129 + model.addAttribute("messageids", messageids);
  130 + model.addAttribute("messageList", list);
  131 + model.addAttribute("hosts_name", hosts_name);
  132 +
  133 + } catch (Exception ex) {
  134 + }
  135 + return new ModelAndView("project/dns_project_build");
  136 + }
  137 +
  138 + /**
  139 + * 获取执行结果
  140 + *
  141 + * @param messageid
  142 + * @return
  143 + */
  144 + @RequestMapping(value = "getbuildmsg", method = RequestMethod.POST)
  145 + @ResponseBody
  146 + public String getbuildmsg(String messageid, String project) {
  147 + try {
  148 + Map<String, String> map = new HashMap<>();
  149 + map.put("messageid", messageid);
  150 + map.put("project", project);
  151 +
  152 + return httpRestClient.get(URL + "getbuildmsg", String.class, map);
  153 +
  154 + } catch (Exception ex) {
  155 + return "failed";
  156 + }
  157 + }
  158 +
  159 + @RequestMapping(value = "cancelBuild")
  160 + @ResponseBody
  161 + public String cancelBuild(String id) {
  162 + try {
  163 + Map<String, String> map = new HashMap<>();
  164 + map.put("id", id);
  165 + return httpRestClient.get(URL + "cancelBuild", String.class, map);
  166 + } catch (Exception ex) {
  167 + return "failed";
  168 + }
  169 + }
  170 +
  171 + @RequestMapping(value = "rollbackList", method = RequestMethod.POST)
  172 + @ResponseBody
  173 + public String rollbackList(String project, String environment) {
  174 + try {
  175 + Map<String, String> map = new HashMap<>();
  176 + map.put("project", project);
  177 + map.put("environment", environment);
  178 + return httpRestClient.get(URL + "rollbackList", String.class, map);
  179 + } catch (Exception ex) {
  180 + return "failed";
  181 + }
  182 + }
  183 +
  184 + @RequestMapping(value = "refreshGit", method = RequestMethod.POST)
  185 + @ResponseBody
  186 + public String refreshGit() {
  187 + try {
  188 + return httpRestClient.get(URL + "refreshGit", String.class, null);
  189 + } catch (Exception ex) {
  190 + return "failed";
  191 + }
  192 + }
  193 +
  194 +
  195 +}
  1 +<%@page language="java" contentType="text/html;charset=utf-8" %>
  2 +<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3 +
  4 +<%
  5 + String path = request.getContextPath();
  6 + String basePath = request.getScheme() + "://"
  7 + + request.getServerName() + ":" + request.getServerPort()
  8 + + path + "/";
  9 +%>
  10 +
  11 +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  12 +<html lang="en">
  13 +<head>
  14 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  15 +
  16 + <title>项目发布</title>
  17 + <link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
  18 + <link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css"/>
  19 + <link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
  20 + <link href="<%=basePath%>css/style.default.css" rel="stylesheet">
  21 + <link href="<%=basePath%>css/morris.css" rel="stylesheet">
  22 + <link href="<%=basePath%>css/select2.css" rel="stylesheet"/>
  23 +
  24 +</head>
  25 +
  26 +<body style="background-color: #444444;font-size: 14px">
  27 +
  28 +<!-- 头部 -->
  29 +<div id="head">
  30 +</div>
  31 +<div id="content">
  32 + <div id="breadcrumb">
  33 + <a href="#" title="Go to Home" class="tip-bottom"><i
  34 + class="icon-home"></i> Home</a> <a href="#" class="current">项目发布</a>
  35 + </div>
  36 + <div>
  37 + <!-- query panel -->
  38 + <form class="form-bordered">
  39 + <div class="form-group">
  40 + <label class="col-sm-1 control-label">操作选择</label>
  41 +
  42 + <div class="col-sm-8" style="display: inline">
  43 + <div class="rdio rdio-default">
  44 + <input type="radio" name="operate" id="operatedeploy" value="Deploy" checked="checked"
  45 + onclick="operateChange()"/>
  46 + <label for="operatedeploy">发布
  47 + </label>
  48 +
  49 + </div>
  50 +
  51 + <div class="rdio rdio-default" >
  52 + <input type="radio" name="operate" value="Rollback" id="operateback" onclick="operateChange()"/>
  53 + <label for="operateback">回滚</label>
  54 + </div>
  55 + </div>
  56 + <div id="autotest-div">
  57 + <input type="button" class="btn btn-primary" id="autotest-button" onclick="refresh()" value="刷新列表"> </input>
  58 + </div>
  59 + </div>
  60 +
  61 + <div class="form-group">
  62 + <label class="col-sm-1 control-label">项目选择</label>
  63 +
  64 + <div class="col-sm-8" id="project-div">
  65 + </div>
  66 + </div>
  67 +
  68 + <div class="form-group">
  69 + <label class="col-sm-1 control-label">发布环境</label>
  70 +
  71 + <div class="col-sm-8" id="select-environment-div">
  72 +
  73 + </div>
  74 + </div>
  75 + <div class="form-group" id="branch-div">
  76 + <label class="col-sm-1 control-label">Branch输入</label>
  77 + <div class="col-sm-8">
  78 + <input name="branch" type="text" class="form-control"
  79 + style="width: 300px"/>
  80 + </div>
  81 + </div>
  82 +
  83 + <div class="form-group" id="rollback-div" style="display: none">
  84 + <label class="col-sm-1 control-label">回滚版本选择</label>
  85 +
  86 + <div class="col-sm-8" id="select-rollbackList-div">
  87 +
  88 + </div>
  89 + </div>
  90 + <div class="form-group">
  91 + <label class="col-sm-1 control-label">确认操作</label>
  92 +
  93 + <div class="col-sm-8">
  94 + <button type="button" id="submit-btn" onclick="comfirmSubmit()" class="btn btn-primary">提交</button>
  95 + </div>
  96 + </div>
  97 +
  98 + </form>
  99 + </div>
  100 +</div>
  101 +
  102 +<!-- 初始化确认页面 -->
  103 +<div class="modal fade" id="confirmSubmitDivId" tabindex="-1" role="dialog" aria-labelledby="confirmSubmitLabel"
  104 + aria-hidden="true" style="padding-top: 10%">
  105 + <div class="modal-dialog">
  106 + <div class="modal-content">
  107 + <div class="modal-header">
  108 + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  109 + <h2 class="modal-title" id="confirmSubmitLabel">
  110 + <span style="font-weight: bold;"> 确认提交</span>
  111 + </h2>
  112 + </div>
  113 + <div class="modal-body">
  114 + <form class="bs-example bs-example-form" action="<%=basePath %>dnsBuild/build" role="form"
  115 + id="GitBranchCreateForm" method="post">
  116 + <div class="input-group">
  117 + <span class="input-group-addon">操作类型</span>
  118 + <input type="text" name="operate_name" class="form-control" readonly="readonly">
  119 + </div>
  120 + <br>
  121 +
  122 + <div class="input-group">
  123 + <span class="input-group-addon">发布环境</span>
  124 + <input type="text" name="environment_name" class="form-control" readonly="readonly">
  125 + </div>
  126 + <br>
  127 +
  128 + <div class="input-group">
  129 + <span class="input-group-addon">工程名称</span>
  130 + <input type="text" name="project_name" class="form-control" readonly="readonly">
  131 + </div>
  132 + <br>
  133 + <div class="input-group">
  134 + <span class="input-group-addon">主机地址</span>
  135 + <input type="text" name="hosts_name" class="form-control" readonly="readonly">
  136 + </div>
  137 + <br>
  138 +
  139 + <div class="input-group">
  140 + <span class="input-group-addon">分支名称</span>
  141 + <input type="text" name="branch_name" class="form-control" readonly="readonly">
  142 + </div>
  143 + <br>
  144 +
  145 + <div class="input-group">
  146 + <span class="input-group-addon">回滚文件</span>
  147 + <input type="text" name="rollbackfile_name" class="form-control" readonly="readonly">
  148 + </div>
  149 + <div class="modal-footer">
  150 + <button type="submit" class="btn btn-primary">确认</button>
  151 + <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
  152 + </div>
  153 + </form>
  154 + </div>
  155 +
  156 + </div>
  157 + </div>
  158 +</div>
  159 +</body>
  160 +<script src="<%=basePath%>js/jquery-2.1.4.min.js"></script>
  161 +<script src="<%=basePath%>js/bootstrap.min.js"></script>
  162 +<script src="<%=basePath%>js/select2.min.js"></script>
  163 +<script src="<%=basePath%>js/custom.js"></script>
  164 +<script src="<%=basePath%>script/build/dns_project.js"></script>
  165 +<script src="<%=basePath %>/js/unicorn.js"></script>
  166 +<script src="<%=basePath %>script/common/genarate_left_panel.js"></script>
  167 +<script type="text/javascript">
  168 + $("#li_project").addClass("active open");
  169 + $("#li_dnsRelease").addClass("active");
  170 +</script>
  171 +
  172 +</html>
  1 +<%@page language="java" contentType="text/html;charset=utf-8" %>
  2 +<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3 +
  4 +<%
  5 + String path = request.getContextPath();
  6 + String basePath = request.getScheme() + "://"
  7 + + request.getServerName() + ":" + request.getServerPort()
  8 + + path + "/";
  9 +%>
  10 +
  11 +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  12 +<html>
  13 +<head>
  14 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  15 + <link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
  16 + <link rel="stylesheet" href="<%=basePath %>css/bootstrap-datetimepicker.css"/>
  17 + <link href="<%=basePath %>js/bootstrap-plugin/css/bootstrap.table.css" rel="stylesheet" media="screen"/>
  18 + <link rel="stylesheet" href="<%=basePath %>css/bootstrap-responsive.min.css"/>
  19 + <link rel="stylesheet" href="<%=basePath %>css/fullcalendar.css"/>
  20 + <link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
  21 + <link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css"/>
  22 + <link rel="stylesheet" href="<%=basePath %>css/jquery-ui.css"/>
  23 + <link rel="stylesheet" href="<%=basePath %>css/uniform.css"/>
  24 + <link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
  25 + <link rel="stylesheet" href="<%=basePath %>js/jstree/themes/proton/style.css"/>
  26 + <link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
  27 + <link rel="stylesheet" href="<%=basePath %>css/yoho.css"/>
  28 + <script src="<%=basePath %>js/excanvas.min.js" charset="UTF-8" type="text/javascript"></script>
  29 + <script src="<%=basePath %>js/jquery-1.12.0.min.js" charset="UTF-8" type="text/javascript"></script>
  30 + <script src="<%=basePath %>js/jquery-ui.custom.js" charset="UTF-8" type="text/javascript"></script>
  31 + <script src="<%=basePath %>/js/bootstrap.min.js"></script>
  32 + <script src="<%=basePath %>/js/unicorn.js"></script>
  33 + <script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/moment-with-locales.js" charset="UTF-8"
  34 + type="text/javascript"></script>
  35 + <script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"
  36 + type="text/javascript"></script>
  37 + <script src="<%=basePath %>js/global.js" charset="UTF-8" type="text/javascript"></script>
  38 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.pagination.js" charset="UTF-8"
  39 + type="text/javascript"></script>
  40 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.table.js" charset="UTF-8" type="text/javascript"></script>
  41 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.dialog.js" charset="UTF-8" type="text/javascript"></script>
  42 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
  43 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.panel.js" charset="UTF-8" type="text/javascript"></script>
  44 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.alerts.js" charset="UTF-8" type="text/javascript"></script>
  45 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.accordion.js" charset="UTF-8"
  46 + type="text/javascript"></script>
  47 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.breadcrumb.js" charset="UTF-8"
  48 + type="text/javascript"></script>
  49 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.validate.js" charset="UTF-8"
  50 + type="text/javascript"></script>
  51 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
  52 + <script src="<%=basePath %>js/layer/layer.js" charset="UTF-8" type="text/javascript"></script>
  53 + <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.select.js" charset="UTF-8" type="text/javascript"></script>
  54 + <script src="<%=basePath %>js/jstree/jstree.min.js"></script>
  55 + <script src="<%=basePath %>js/jquery.toaster.js"></script>
  56 + <script>
  57 + var contextPath = '<%=basePath %>';
  58 + </script>
  59 + <title>YOHO!运维</title>
  60 +</head>
  61 +<body>
  62 +
  63 +<!-- 头部 -->
  64 +<div id="head">
  65 +</div>
  66 +<!-- 右侧具体内容 -->
  67 +<div id="content">
  68 +
  69 + <div id="breadcrumb">
  70 + <a href="#" title="Go to Home" class="tip-bottom"><i
  71 + class="icon-home"></i> Home</a> <a href="#" class="current">发布进程</a>
  72 + </div>
  73 +
  74 + <div class="container-fluid">
  75 +
  76 +
  77 + <div class="widget-box">
  78 + <div class="widget-title">
  79 + <h5>发布进程信息</h5>
  80 + </div>
  81 + <div class="widget-content nopadding">
  82 + <div class="widget-title" style="height: 53px;">
  83 + <div>
  84 + <div class="form-inline" role="form" id="inBoxQueryDiv"
  85 + style=" margin-top: 12px;margin-left: 25px;float: left;">
  86 + <div class="input-group" style="float: left;">
  87 + <span class="input-group-addon">操作:</span>
  88 + <input type="text" id="operate_name" name="operate_name" class="form-control"
  89 + readonly="readonly" value="${operate_name}"/>
  90 + </div>
  91 + <div class="input-group" style="float: left;">
  92 + <span class="input-group-addon">环境:</span>
  93 + <input type="text" id="environment_name" name="environment_name" class="form-control"
  94 + readonly="readonly" value="${environment_name}"/>
  95 + </div>
  96 + <div class="input-group" style="float: left;">
  97 + <span class="input-group-addon">分支:</span>
  98 + <input type="text" id="branch_name" name="branch_name" class="form-control"
  99 + readonly="readonly" value="${branch_name}"/>
  100 + </div>
  101 + <div class="input-group" style="float: left;">
  102 + <span class="input-group-addon">主机:</span>
  103 + <input type="text" id="hosts_name" name="hosts_name" class="form-control"
  104 + readonly="readonly" value="${hosts_name}"/>
  105 + </div>
  106 + <div class="input-group" style="float: left;">
  107 + <span class="input-group-addon">回滚:</span>
  108 + <input type="text" id="rollbackfile_name" name="rollbackfile_name" class="form-control"
  109 + readonly="readonly" value="${rollbackfile_name}"/>
  110 + </div>
  111 + </div>
  112 + </div>
  113 + </div>
  114 + <c:forEach items="${messageList }" var="message">
  115 + <div style="float: left;height: 600px;">
  116 + <hr>
  117 + <div>执行顺序:<strong>${message.projectOrder}</strong>
  118 + </div>
  119 + <div>当前项目:<input type="text" id="currentProject_${message.id}" value="${message.currentProject}" readonly="readonly">
  120 + <button type="button" id="cancel-btn_${message.id}" onclick="cancelBuild('${message.id}')"
  121 + class="btn btn-xs btn-danger">取消
  122 + </button>
  123 + </div>
  124 + <div style="height: 50px" class="alert alert-warning" id="task-info-div_${message.id}">
  125 + </div>
  126 + <textarea id="resultArea_${message.id}" rows="25" cols="100"
  127 + style="background-color: black; color: white" readonly="readonly"></textarea>
  128 + </div>
  129 + </c:forEach>
  130 +
  131 +
  132 + </div>
  133 + </div>
  134 + </div>
  135 +
  136 +</div>
  137 +<input type="hidden" id="messageListHidden" value="${messageids}">
  138 +</body>
  139 +<script src="<%=basePath %>script/common/genarate_left_panel.js"></script>
  140 +<script>
  141 + $("#li_project").addClass("active open");
  142 + $("#li_dnsRelease").addClass("active");
  143 +</script>
  144 +<script>
  145 +
  146 + var myArray;
  147 + var removeArray = new Array();
  148 + $(function () {
  149 + var messageListHidden = $("#messageListHidden").val();
  150 + myArray = messageListHidden.split(",");
  151 +
  152 + var interval = setInterval(function () {//查后台,展示数据
  153 + $.each(myArray, function (idx, val) {
  154 + if(jQuery.inArray(val, removeArray) != -1){
  155 + return;
  156 + }
  157 + if(val == ""){
  158 + return;
  159 + }
  160 + var cproject = $("#currentProject_"+val).val();
  161 + $.ajax({
  162 + url: contextPath + 'dnsBuild/getbuildmsg?messageid=' + val+"&project="+cproject,
  163 + type: 'POST',
  164 + dataType: 'json',
  165 + success: function (data3) {
  166 + var obj2 = eval("(" + data3 + ")");
  167 + var messagedata = obj2.data;
  168 +
  169 + var currproject = messagedata.currentProject;
  170 + if (currproject != cproject) {
  171 + $("#currentProject_"+val).val(currproject);//更换当前的项目
  172 + $("#resultArea_" + val).val("")
  173 + }
  174 +
  175 + if (messagedata.message != "") {
  176 + var d = $("#resultArea_" + val).val();
  177 + $("#resultArea_"+ val).val(d + messagedata.message);
  178 + var scrollTop = $("#resultArea_" + val)[0].scrollHeight;
  179 + $("#resultArea_" + val).scrollTop(scrollTop);
  180 + }
  181 +
  182 + //code为2 ,则结束
  183 + var code = obj2.code;
  184 + var message = obj2.message;
  185 + if (code == 2) {
  186 + document.getElementById("task-info-div_" + val).innerHTML = "<strong>'" + message + "'</strong>";
  187 + removeArray.push(val);
  188 + $("#cancel-btn_"+val).hide();
  189 + }
  190 +
  191 + },
  192 + error: function (e) {
  193 + }
  194 + });
  195 + });
  196 + }, 3000);
  197 + });
  198 +
  199 + /**
  200 + * 取消
  201 + */
  202 + function cancelBuild(messageid) {
  203 +
  204 + var jsondata = {"id": messageid};
  205 + $.ajax({
  206 + url: contextPath + 'dnsBuild/cancelBuild',
  207 + type: 'POST',
  208 + dataType: 'json',
  209 + data: jsondata,
  210 + success: function (data) {
  211 + },
  212 + error: function (e) {
  213 + }
  214 + });
  215 + }
  216 +
  217 +</script>
  218 +
  219 +<script>
  220 + document.onkeydown = function()
  221 + {
  222 + if(event.keyCode==116 || event.keyCode==8 || (event.ctrlKey && event.keyCode==82) || event.keyCode == 13) {
  223 + event.keyCode=0;
  224 + event.returnValue = false;
  225 + }
  226 + }
  227 + document.oncontextmenu = function() {event.returnValue = false;}
  228 +
  229 +</script>
  1 +var ENV;
  2 +
  3 +jQuery(document).ready(function () {
  4 + getProjects();
  5 +});
  6 +
  7 +/**
  8 + * 操作变更
  9 + */
  10 +function operateChange() {
  11 + var operate = $("input[name='operate']:checked").val();
  12 + if ("Rollback" == operate) {
  13 + //隐藏Branch输入框
  14 + document.getElementById("branch-div").style.display = "none";
  15 + //展示 回滚选择框
  16 + document.getElementById("rollback-div").style.display = "";
  17 + //隐藏自动执行测试用例
  18 + document.getElementById("autotest-div").style.display = "none";
  19 + getRollbackList();
  20 + } else {
  21 + //展示Branch输入框
  22 + document.getElementById("branch-div").style.display = "";
  23 + //隐藏 回滚选择框
  24 + document.getElementById("rollback-div").style.display = "none";
  25 + //展示自动执行测试用例
  26 + document.getElementById("autotest-div").style.display = "";
  27 + branchdefault();
  28 + }
  29 +}
  30 +
  31 +/**
  32 + * 根据操作获取当前的项目列表
  33 + */
  34 +function getProjects() {
  35 + var operate = $("input[name='operate']:checked").val();
  36 +
  37 + $.ajax({
  38 + url: 'getProjects',
  39 + type: 'POST',
  40 + dataType: 'json',
  41 + contentType: "application/json",
  42 + success: function (data) {
  43 + var obj = eval("(" + data + ")");
  44 + var order1HTML = "";
  45 + var order2HTML = "";
  46 +
  47 + var order1num = 1;
  48 + var order2num = 1;
  49 +
  50 + for (var i = 0; i < obj.length; i++) {
  51 + var order = obj[i].order;
  52 + var name = obj[i].name;
  53 + if ("1" == order) {
  54 + order1HTML += "<div class='rdio rdio-primary' style='display: inline'>";
  55 + order1HTML += " <input name='project' type='radio' id='" + name + "' value='" + name + "' onclick='changeProject()'/>";
  56 + order1HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
  57 + if (order1num % 4 == 0) {
  58 + order1HTML += "</br>";
  59 + }
  60 + order1num += 1;
  61 + }
  62 + if ("2" == order) {
  63 + order2HTML += "<div class='rdio rdio-warning' style='display: inline'>";
  64 + order2HTML += " <input name='project' type='radio' id='" + name + "' value='" + name + "' onclick='changeProject()'/>";
  65 + order2HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
  66 + if (order2num % 4 == 0) {
  67 + order2HTML += "</br>";
  68 + }
  69 + order2num += 1;
  70 +
  71 + }
  72 + document.getElementById("project-div").innerHTML = order1HTML + "<hr>" + order2HTML + "<hr>";
  73 + }
  74 + },
  75 + error: function (e) {
  76 + alert("从后台获取数据出错");
  77 + }
  78 + });
  79 +}
  80 +
  81 +//确认提交
  82 +function comfirmSubmit() {
  83 + var operate = $("input[name='operate']:checked").val();
  84 + var environment = $("input[name='environments']:checked").val();
  85 + var project = $("input[name='project']:checked").val();
  86 + if (!project) {
  87 + alert("请选择项目");
  88 + return;
  89 + }
  90 + var hosts = new Array();
  91 + $("input[name=\""+environment+"-checkbox\"]:checked").each(function () {
  92 + hosts.push($(this).val());//向数组中添加元素
  93 + });
  94 +
  95 +
  96 + $("input[name='operate_name']").val(operate);
  97 + $("input[name='project_name']").val(project);
  98 + $("input[name='environment_name']").val(environment);
  99 + $("input[name='hosts_name']").val(hosts);
  100 +
  101 + if ("Deploy" == operate) {//发布
  102 + var branch = $("input[name='branch']").val();
  103 + if (branch == "") {
  104 + alert("请填写分支名称");
  105 + return;
  106 + }
  107 + $("input[name='branch_name']").val(branch);
  108 + $('#confirmSubmitDivId').modal('show');
  109 + } else {//回滚
  110 + var rollbackfile = $("#rollbackList option:selected").val();
  111 + if (typeof(rollbackfile) == "undefined" || rollbackfile == "") {
  112 + alert("请选择回滚版本");
  113 + return;
  114 + }
  115 + $("input[name='rollbackfile_name']").val(rollbackfile);
  116 + $('#confirmSubmitDivId').modal('show');
  117 + }
  118 +}
  119 +
  120 +function getRollbackList() {
  121 + var project = $("input[name='project']:checked").val();
  122 + var environment = $("input[name='environments']:checked").val();
  123 + if(!environment){
  124 + return;
  125 + }
  126 + $.ajax({
  127 + url: 'rollbackList?project=' + project + "&environment=" + environment,
  128 + type: 'POST',
  129 + dataType: 'json',
  130 + success: function (data) {
  131 + if ("failed" == data) {
  132 + document.getElementById("select-rollbackList-div").innerHTML = "";
  133 + return;
  134 + }
  135 +
  136 + var list = eval("(" + data + ")");
  137 + //动态生成rollbackList的select组件
  138 + var innerHTMLContext = "<select id='rollbackList' data-placeholder='Choose One' style='width:350px;'>";
  139 + for (var i = 0; i < list.length; i++) {
  140 + innerHTMLContext += "<option value='" + list[i] + "'>" + list[i] + "</option>";
  141 + }
  142 + innerHTMLContext += "</select>";
  143 + document.getElementById("select-rollbackList-div").innerHTML = innerHTMLContext;
  144 +
  145 + jQuery('#rollbackList').select2({
  146 + minimumResultsForSearch: -1
  147 + });
  148 + },
  149 + error: function (e) {
  150 + alert("该项目暂无备份,无法回滚");
  151 + }
  152 + });
  153 +}
  154 +
  155 +function changeProject(){
  156 + var operate = $("input[name='operate']:checked").val();
  157 + var project = $("input[name='project']:checked").val();
  158 +
  159 + $.ajax({
  160 + url: 'getProject?name=' + project,
  161 + type: 'POST',
  162 + dataType: 'json',
  163 + success: function (data) {
  164 + $("#select-environment-div").empty();
  165 + if ("failed" == data) {
  166 + return;
  167 + }
  168 +
  169 + var pythonProject = eval("(" + data + ")");
  170 + //动态生成环境的组件
  171 + var list = pythonProject.envs;
  172 + ENV = list;
  173 + for(var i = 0; i < list.length; i++){
  174 + var env = list[i];
  175 + var div = $("<div>").addClass("rdio rdio-default");
  176 + var redio = $("<input>");
  177 + redio.attr("type","radio");
  178 + redio.attr("name","environments");
  179 + redio.attr("id",env.name);
  180 + redio.attr("value",env.name);
  181 + redio.attr("onclick","changeservers()");
  182 + redio.attr("checked","checked");
  183 +
  184 + var label = $("<label for=\""+env.name+"\">"+env.name+"</label>");
  185 +
  186 + var checkBoxDiv = $("<div>").attr("id",env.name+"-div").attr("display","display");
  187 +
  188 + var hosts = env.host_ips;
  189 + for(var j = 0; j < hosts.length; j++){
  190 + var host = hosts[j];
  191 + checkBoxDiv.append("<input type=\"checkbox\" value=\""+host+"\" name=\""+env.name +"-checkbox\" checked=\"checked\">"+host+"");
  192 + }
  193 + div.append(redio).append(label).append(checkBoxDiv);
  194 + $("#select-environment-div").append(div);
  195 + }
  196 + changeservers();
  197 + },
  198 + error: function (e) {
  199 + alert("获取项目环境失败");
  200 + }
  201 + });
  202 +}
  203 +
  204 +function changeservers() {
  205 + var environment = $("input[name='environments']:checked").val();
  206 + for(var i = 0; i < ENV.length; i++){
  207 + $("#"+ENV[i].name+"-div").hide();
  208 + }
  209 + $("#"+environment+"-div").show();
  210 +
  211 + var operate = $("input[name='operate']:checked").val();
  212 + if (operate == "Rollback") {
  213 + getRollbackList();
  214 + }
  215 + if (operate == "Deploy") {
  216 + branchdefault();
  217 + }
  218 +
  219 +}
  220 +
  221 +function branchdefault() {
  222 + var operate = $("input[name='operate']:checked").val();
  223 + if (operate == "Deploy") {
  224 + $("input[name='branch']").val("master");
  225 + }
  226 +}
  227 +
  228 +function refresh(){
  229 + $.ajax({
  230 + url: 'refreshGit',
  231 + type: 'POST',
  232 + dataType: 'json',
  233 + success: function (data) {
  234 + alert("刷新成功");
  235 + },
  236 + error: function (e) {
  237 + alert("刷新失败");
  238 + }
  239 + });
  240 +
  241 +}
  242 +
  243 +
  244 +
  245 +
  246 +
@@ -23,6 +23,7 @@ innerHTML += "<li id='li_newRedisMonitor'><a id='li_memcachedMonitor_a' href=''> @@ -23,6 +23,7 @@ innerHTML += "<li id='li_newRedisMonitor'><a id='li_memcachedMonitor_a' href=''>
23 /*innerHTML += "<li id='li_nginxview'><a id='li_nginxview_a' href=''><i class='icon icon-th'></i> <span>Nginx监控</span></a></li>";*/ 23 /*innerHTML += "<li id='li_nginxview'><a id='li_nginxview_a' href=''><i class='icon icon-th'></i> <span>Nginx监控</span></a></li>";*/
24 innerHTML += "<li id='li_dns_monitor'><a id='li_dns_monitor_a' href=''><i class='icon icon-th'></i> <span>DNS反劫持监控</span></a></li>"; 24 innerHTML += "<li id='li_dns_monitor'><a id='li_dns_monitor_a' href=''><i class='icon icon-th'></i> <span>DNS反劫持监控</span></a></li>";
25 innerHTML += "<li id='li_monit'><a id='li_monit_a' href=''><i class='icon icon-th'></i> <span>Monit监控</span></a></li>"; 25 innerHTML += "<li id='li_monit'><a id='li_monit_a' href=''><i class='icon icon-th'></i> <span>Monit监控</span></a></li>";
  26 +innerHTML += "<li id='li_nodeMonitor'><a id='li_nodeMonitor_a' href=''><i class='icon icon-th'></i> <span>node监控</span></a></li>";
26 innerHTML += "</ul></li>"; 27 innerHTML += "</ul></li>";
27 28
28 29
@@ -69,7 +70,7 @@ innerHTML += "<li class='submenu' id='li_project'><a id='li_project_a' href='#'> @@ -69,7 +70,7 @@ innerHTML += "<li class='submenu' id='li_project'><a id='li_project_a' href='#'>
69 innerHTML += "<li id='li_projectRelease'><a id='li_projectRelease_a' href=''><i class='icon icon-th'></i> <span>JAVA发布</span></a></li>"; 70 innerHTML += "<li id='li_projectRelease'><a id='li_projectRelease_a' href=''><i class='icon icon-th'></i> <span>JAVA发布</span></a></li>";
70 innerHTML += "<li id='li_phpRelease'><a id='li_phpRelease_a' href=''><i class='icon icon-th'></i> <span>PHP发布</span></a></li>"; 71 innerHTML += "<li id='li_phpRelease'><a id='li_phpRelease_a' href=''><i class='icon icon-th'></i> <span>PHP发布</span></a></li>";
71 innerHTML += "<li id='li_nodeRelease'><a id='li_nodeRelease_a' href=''><i class='icon icon-th'></i> <span>NODE发布</span></a></li>"; 72 innerHTML += "<li id='li_nodeRelease'><a id='li_nodeRelease_a' href=''><i class='icon icon-th'></i> <span>NODE发布</span></a></li>";
72 -innerHTML += "<li id='li_om'><a id='li_om_a' href=''><i class='icon icon-th'></i> <span>OM发布</span></a></li>"; 73 +innerHTML += "<li id='li_dnsRelease'><a id='li_dnsRelease_a' href=''><i class='icon icon-th'></i> <span>DNS发布</span></a></li>";
73 innerHTML += "<li id='li_node'><a id='li_node_a' href=''><i class='icon icon-th'></i> <span>NODE发布</span></a></li>"; 74 innerHTML += "<li id='li_node'><a id='li_node_a' href=''><i class='icon icon-th'></i> <span>NODE发布</span></a></li>";
74 innerHTML += "<li id='li_projectHistory'><a id='li_projectHistory_a' href=''><i class='icon icon-th'></i> <span>历史记录</span></a></li>"; 75 innerHTML += "<li id='li_projectHistory'><a id='li_projectHistory_a' href=''><i class='icon icon-th'></i> <span>历史记录</span></a></li>";
75 innerHTML += "</ul></li>"; 76 innerHTML += "</ul></li>";
@@ -112,6 +113,7 @@ document.getElementById("li_rabbitview_a").setAttribute("href", path + "/rabbitm @@ -112,6 +113,7 @@ document.getElementById("li_rabbitview_a").setAttribute("href", path + "/rabbitm
112 document.getElementById("li_projectRelease_a").setAttribute("href", path + "/project/toProject"); 113 document.getElementById("li_projectRelease_a").setAttribute("href", path + "/project/toProject");
113 document.getElementById("li_phpRelease_a").setAttribute("href", path + "/phpBuild/toProject"); 114 document.getElementById("li_phpRelease_a").setAttribute("href", path + "/phpBuild/toProject");
114 document.getElementById("li_nodeRelease_a").setAttribute("href", path + "/nodeBuild/toProject"); 115 document.getElementById("li_nodeRelease_a").setAttribute("href", path + "/nodeBuild/toProject");
  116 +document.getElementById("li_dnsRelease_a").setAttribute("href", path + "/dnsBuild/toProject");
115 document.getElementById("logout_a").setAttribute("href", path + "/user/logout"); 117 document.getElementById("logout_a").setAttribute("href", path + "/user/logout");
116 document.getElementById("changepwd_a").setAttribute("href", path + "/user/toupdatePwd"); 118 document.getElementById("changepwd_a").setAttribute("href", path + "/user/toupdatePwd");
117 document.getElementById("li_sms_a").setAttribute("href", path + "/sms/toSmsLog"); 119 document.getElementById("li_sms_a").setAttribute("href", path + "/sms/toSmsLog");
@@ -126,7 +128,6 @@ document.getElementById("a_hystrix_aws").setAttribute("href", path + "/hystrix/a @@ -126,7 +128,6 @@ document.getElementById("a_hystrix_aws").setAttribute("href", path + "/hystrix/a
126 document.getElementById("a_hystrix_qcloud").setAttribute("href", path + "/hystrix/qcloud"); 128 document.getElementById("a_hystrix_qcloud").setAttribute("href", path + "/hystrix/qcloud");
127 document.getElementById("li_dns_monitor_a").setAttribute("href", path + "/dns_monitor/"); 129 document.getElementById("li_dns_monitor_a").setAttribute("href", path + "/dns_monitor/");
128 document.getElementById("li_nginxSync_a").setAttribute("href", path + "/nginxSync/toNginxSync"); 130 document.getElementById("li_nginxSync_a").setAttribute("href", path + "/nginxSync/toNginxSync");
129 -document.getElementById("li_om_a").setAttribute("href", path + "/project/toOm");  
130 document.getElementById("li_node_a").setAttribute("href", path + "/project/toNode"); 131 document.getElementById("li_node_a").setAttribute("href", path + "/project/toNode");
131 document.getElementById("li_degrade_info_a").setAttribute("href", path + "/degrade/info"); 132 document.getElementById("li_degrade_info_a").setAttribute("href", path + "/degrade/info");
132 document.getElementById("li_hystrix_info_a").setAttribute("href", path + "/hystrixInfo/info"); 133 document.getElementById("li_hystrix_info_a").setAttribute("href", path + "/hystrixInfo/info");
@@ -146,7 +147,7 @@ document.getElementById("li_lbswitch_a").setAttribute("href", path + "/lbSwitch/ @@ -146,7 +147,7 @@ document.getElementById("li_lbswitch_a").setAttribute("href", path + "/lbSwitch/
146 document.getElementById("li_monit_a").setAttribute("href",path+"/monit/toMonit"); 147 document.getElementById("li_monit_a").setAttribute("href",path+"/monit/toMonit");
147 document.getElementById("li_ABTestConfig_a").setAttribute("href",path+"/abtestConfig/toABTestConfig"); 148 document.getElementById("li_ABTestConfig_a").setAttribute("href",path+"/abtestConfig/toABTestConfig");
148 document.getElementById("li_ABTestTotal_a").setAttribute("href",path+"/abtestTotal/toABTestTotal"); 149 document.getElementById("li_ABTestTotal_a").setAttribute("href",path+"/abtestTotal/toABTestTotal");
149 - 150 +document.getElementById("li_nodeMonitor_a").setAttribute("href",path+"/nodeMonitor/toNodeMonitor");
150 151
151 function getUrlBasePath() { 152 function getUrlBasePath() {
152 var location = ( window.location + '').split('/'); 153 var location = ( window.location + '').split('/');