Authored by zhengyouwei

java restart

... ... @@ -150,5 +150,7 @@ public class HttpUriContants {
//java服务重启
public static final String JAVA_RESTART_GET = "/javaRestart/query";
public static final String JAVA_RESTART_STATAUS = "/javaRestart/getProjectStatus";
public static final String JAVA_STOP_RESTART = "/javaRestart/stopOrRestart";
public static final String JAVA_GET_MESSAGE = "/javaRestart/getMessage";
}
... ...
package com.ui.model.domain;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/10/19.
*/
@Data
public class RestartModel {
//restart,stop
private String exe;
//aws qcloud mix,single
private String cloud;
private String project;
private String ip;
private Integer id;
}
... ...
... ... @@ -3,11 +3,14 @@ package com.ui.ctrl;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.domain.RestartModel;
import com.ui.model.req.PageRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
... ... @@ -29,6 +32,15 @@ public class JavaRestartCtrl {
return new ModelAndView("/switch/java_restart");
}
@RequestMapping("/toStopOrRestart")
public ModelAndView toStopOrRestart(String project,String cloud, String exe,String ip,Model model) {
model.addAttribute("project",project);
model.addAttribute("cloud",cloud);
model.addAttribute("exe",exe);
model.addAttribute("ip",ip);
return new ModelAndView("/switch/java_restart_process");
}
@RequestMapping("/query")
@ResponseBody
public BaseResponse query(PageRequest req) {
... ... @@ -38,9 +50,25 @@ public class JavaRestartCtrl {
@RequestMapping("/getProjectStatus")
@ResponseBody
public BaseResponse getStatusInfos(String project) {
public BaseResponse getProjectStatus(String project) {
BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_RESTART_STATAUS + "?project=" + project, null, BaseResponse.class);
return rep;
}
@RequestMapping("/stopOrRestart")
@ResponseBody
public BaseResponse stopOrRestart( RestartModel restartModel) {
if(StringUtils.isBlank(restartModel.getExe()) || StringUtils.isBlank(restartModel.getCloud()) || StringUtils.isBlank(restartModel.getProject())){
return null;
}
BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_STOP_RESTART, restartModel, BaseResponse.class);
return rep;
}
@RequestMapping("/getMessage")
@ResponseBody
public BaseResponse getMessage(Integer id) {
BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_GET_MESSAGE+ "?id=" + id, null, BaseResponse.class);
return rep;
}
}
... ...
... ... @@ -58,7 +58,6 @@
<script src="<%=basePath %>js/jquery.toaster.js"></script>
<script>
var contextPath = '<%=basePath %>';
var api_type = "<%=api_type %>";
</script>
<title>YOHO!运维</title>
</head>
... ... @@ -86,17 +85,17 @@
<div>
<button id="awsRestart" class="btn btn-primary" style="margin-top: 12px;margin-left: 100px;"
onclick="restart('all','aws')">
onclick="restart('all','aws','')">
aws重启
</button>
&nbsp;
<button id="qcloudRestart" class="btn btn-primary" style="margin-top: 12px;margin-left: 100px;"
onclick="restart('all','qcloud')">
onclick="restart('all','qcloud','')">
qq重启
</button>
&nbsp;
<button id="allRestart" class="btn btn-primary" style="margin-top: 12px;margin-left: 100px;"
onclick="restart('all','mix')">
onclick="restart('all','mix','')">
所有重启
</button>
</div>
... ... @@ -108,6 +107,7 @@
</div>
</div>
</div>
</body>
<script src="<%=basePath %>script/common/genarate_left_panel.js"></script>
<script>
... ... @@ -158,11 +158,16 @@
field: "op",
formatter: function (value, rowData, rowIndex) {
var div = $("<div>");
$("<button onclick=\"restart(\'" + rowData.name + "\',\'aws\')\">").addClass("btn btn-xs btn-primary").html("aws重启").appendTo(div);
$("<button onclick=\"restart(\'" + rowData.name + "\',\'aws\',\'\')\">").addClass("btn btn-xs btn-primary").html("aws重启").appendTo(div);
div.append("&nbsp;");
$("<button onclick=\"restart(\'" + rowData.name + "\',\'qcloud\',\'\')\">").addClass("btn btn-xs btn-primary").html("qq重启").appendTo(div);
div.append("&nbsp;");
$("<button onclick=\"restart(\'" + rowData.name + "\',\'qcloud\')\">").addClass("btn btn-xs btn-primary").html("qq重启").appendTo(div);
$("<button onclick=\"restart(\'" + rowData.name + "\',\'mix\',\'\')\">").addClass("btn btn-xs btn-primary").html("全部重启").appendTo(div);
div.append("</br>");
div.append("</br>");
$("<button onclick=\"stop(\'" + rowData.name + "\',\'aws\',\'\')\">").addClass("btn btn-xs btn-primary").html("aws停止").appendTo(div);
div.append("&nbsp;");
$("<button onclick=\"restart(\'" + rowData.name + "\',\'mix\')\">").addClass("btn btn-xs btn-primary").html("全部重启").appendTo(div);
$("<button onclick=\"stop(\'" + rowData.name + "\',\'qcloud\',\'\')\">").addClass("btn btn-xs btn-primary").html("qq停止").appendTo(div);
return div;
},
width: "20%"
... ... @@ -200,21 +205,27 @@
span.attr("data-toggle", "popover");
span.attr("data-placement", "bottom");
span.attr("data-html", "true");
span.attr("data-content", val.lastStart);
if(val.status == "1"){
span.attr("title", val.lastStart);
span.attr("data-content", "<button class='btn btn-primary btn-xs' onclick=\"restart(\'" + name + "\',\'single\',\'"+val.ip+"\')\">重启</button>&nbsp;&nbsp;<button class='btn btn-primary btn-xs' onclick=\"stop(\'" + name + "\',\'single\',\'"+val.ip+"\')\">停止</button>");
// span.attr("data-content", "unkown");
span.popover({
//delay: {"show": 500, "hide": 100}
// container: 'tip_well'
});
// span.attr("onclick","singleOp('"+val.ip+"','"+name+"')");
if (val.status == "1") {
span.addClass('btn-success');
}else{
} else {
span.addClass('btn-danger');
}
if(val.cloud == "aws"){
if (val.cloud == "aws") {
aws_div.append(span);
}else{
} else {
qcloud_div.append(span);
}
span.popover({
delay: {"show": 500, "hide": 100}
// container: 'tip_well'
});
});
$("#aws_" + name).html("");
... ... @@ -229,9 +240,60 @@
});
}
function restart(project, cloud,ip) {
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title: "重启确定",
backdrop: "static",
content: "服务:"+project+",云:"+cloud+",ip:"+ip+"",
buttons: [{
text: "否",
className: "btn-danger",
onclick: function () {
$(dialog).dialog("hide");
}
}, {
text: "是",
className: "btn-success",
onclick: function () {
function restart(project, cloud) {
var iWidth = 1200;
var iHeight = 900;
var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
window.open(contextPath + "javaRestart/toStopOrRestart?project=" + project + "&cloud=" + cloud + "&exe=restart"+ "&ip=" + ip, "_blank", "height=" + iHeight + ", width=" + iWidth + ", top=" + iTop + ", left=" + iLeft);
$(dialog).dialog("hide");
}
}]
});
}
function stop(project, cloud,ip) {
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title: "停机确定",
backdrop: "static",
content: "服务:"+project+",云:"+cloud+",ip:"+ip+"",
buttons: [{
text: "否",
className: "btn-danger",
onclick: function () {
$(dialog).dialog("hide");
}
}, {
text: "是",
className: "btn-success",
onclick: function () {
var iWidth = 1200;
var iHeight = 900;
var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
window.open(contextPath + "javaRestart/toStopOrRestart?project=" + project + "&cloud=" + cloud + "&exe=stop"+ "&ip=" + ip, "_blank", "height=" + iHeight + ", width=" + iWidth + ", top=" + iTop + ", left=" + iLeft);
$(dialog).dialog("hide");
}
}]
});
}
</script>
 
\ No newline at end of file
... ...
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap-responsive.min.css"/>
<link rel="stylesheet" href="<%=basePath %>css/jquery.gritter.css"/>
<link rel="stylesheet" href="<%=basePath %>css/jquery-ui.css"/>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css" class="skin-color"/>
<script src="<%=basePath %>js/excanvas.min.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jquery-1.12.0.min.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jquery-ui.custom.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>/js/bootstrap.min.js"></script>
<script src="<%=basePath %>/js/unicorn.js"></script>
<script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/moment-with-locales.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/global.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.pagination.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.table.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.dialog.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.panel.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.alerts.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.accordion.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.breadcrumb.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.validate.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/layer/layer.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.select.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jstree/jstree.min.js"></script>
<script src="<%=basePath %>js/jquery.toaster.js"></script>
<script src="<%=basePath %>js/jquery.gritter.min.js"></script>
<script>
var contextPath = '<%=basePath %>';
</script>
<title>YOHO!运维</title>
</head>
<body>
<!-- 右侧具体内容 -->
<input type="hidden" id="hidden_ip" value="${ip}">
<input type="hidden" id="hidden_project" value="${project}">
<input type="hidden" id="hidden_exe" value="${exe}">
<input type="hidden" id="hidden_cloud" value="${cloud}">
<div id="infoTable">
</div>
</body>
<script>
var myArray = new Array();
var removeArray = new Array();
$(function () {
var ip = $("#hidden_ip").val();
var cloud = $("#hidden_cloud").val();
var exe = $("#hidden_exe").val();
var project = $("#hidden_project").val();
var tableParam = {
columnAutoWidth: false,
url: contextPath + "/javaRestart/stopOrRestart",
striped: true,
title: "java服务操作进程",
dataType: "json",
loadFilter: function (data) {
return defaultLoadFilter(data);
},
onLoadSuccess: function (data) {
$.each(data, function (idx, val) {
myArray[idx] = val.id;
});
setStatus();
},
columns: [{
title: "项目名称",
field: "project",
width: "10%"
}, {
title: "操作",
field: "exe",
width: "10%"
}, {
title: "云",
field: "cloud",
width: "10%"
}, {
title: "已执行IP",
field: "id",
formatter: function (value, rowData, rowIndex) {
var div = $("<div >").attr('id', 'done_' + value);
return div;
},
width: "25%"
}, {
title: "待执行IP",
field: "id",
formatter: function (value, rowData, rowIndex) {
var div = $("<div >").attr('id', 'todo_' + value);
return div;
},
width: "25%"
}, {
title: "进度",
field: "id",
formatter: function (value, rowData, rowIndex) {
var div = $("<div id=\"process_" + value + "\">");
return div;
},
width: "20%"
}]
};
//加载表格
$("#infoTable").table(tableParam);
$("#infoTable").table("load", {
'ip': ip,
'cloud': cloud,
'exe': exe,
'project': project
});
var interval = setInterval(function () {//查后台,展示数据
setStatus();
}, 3000);
});
function setStatus() {
if (myArray.length == 0)
return;
$.each(myArray, function (idx, val) {
if(jQuery.inArray(val, removeArray) != -1){
return;
}
$.ajax({
type: 'post',
url: contextPath + "/javaRestart/getMessage?id=" + val,
dataType: 'json',
success: function (resp) {
if (resp == null || resp.code == 300) {
removeArray[removeArray.length+1] = val;
return;
}
$("#done_" + val).html("");
$("#done_" + val).html(resp.data.doneList);
$("#todo_" + val).html("");
$("#todo_" + val).html(resp.data.toDoList);
$("#process_" + val).html("");
$("#process_" + val).html(resp.data.donePersent);
},
error: function (resp) {
}
});
});
}
</script>
\ No newline at end of file
... ...