Authored by xuhui

nginx切换之dns切换

... ... @@ -117,6 +117,14 @@ public class HttpUriContants {
public static final String VIEW_CURRENT_CONF = "/luaswitch/viewCurrentConf";
/**
* nginx切换
* 之
* dnsswitch
*/
public static final String NGINX_VIEW_DNS_CONF = "/luaswitch/dnsViewConf";
public static final String NGINX_SWITCH_DNS = "/luaswitch/dnsSwitchConf";
/**
* lbswitch
*/
public static final String VIEW_LB_CONF = "/lbswitch/viewConf";
... ...
... ... @@ -83,4 +83,37 @@ public class LuaSwitchCtrl {
return null;
}
}
/**
* 查看当前流量入口配置
*
* @return BaseResponse
*/
@RequestMapping(value = "dnsViewCurrentConf")
@ResponseBody
public BaseResponse dnsViewCurrentConf(){
try{
return httpRestClient.defaultGet(HttpUriContants.NGINX_VIEW_DNS_CONF, BaseResponse.class, null);
}catch (Exception e){
logger.error(" - LuaSwitchCtrl - viewCurrentConf - err ",e);
}
return null;
}
/**
* 当前流量入口切换
*
* @param cloudName toAws toQcloud
* @return BaseResponse
*/
@RequestMapping(value = "dnsSwitchConf")
@ResponseBody
public BaseResponse dnsSwitchConf(String cloudName){
try{
return httpRestClient.defaultGet(HttpUriContants.NGINX_SWITCH_DNS+"?cloudName="+cloudName, BaseResponse.class, null);
}catch (Exception e){
logger.error(" - LuaSwitchCtrl - viewCurrentConf - err ",e);
}
return null;
}
}
\ No newline at end of file
... ...
... ... @@ -78,6 +78,21 @@
<div class="tree_container" style="height: 540px;color: black;overflow:auto;">
<div class="panel panel-default">
<div class="widget-title" style="height: 50px;">
<h5 style="display: inline">DNS切换</h5>
</div>
<div class="panel-body">
<button class="btn btn-sm btn-primary"
onclick="dnsViewConf()">
<em class="icon-cogs bigger-110"></em>
查看当前DNS配置
</button>
<h3 class="header smaller red"></h3>
<div id="dns-div" class="btn-group">
</div>
</div>
<div class="widget-title" style="height: 50px;">
<h5 style="display: inline">直连切换</h5>
</div>
<div class="panel-body">
... ...
... ... @@ -116,6 +116,8 @@ function drawData(resp) {
//创建lua切换按钮
createLuaSwitchButton(data.luaType);
//创建入口切换按钮
createDnsSwitchButton(data.luaType);
}
/**
... ... @@ -165,6 +167,7 @@ function luaInitSwitch(cloudName) {
};
sendAjax("post", getUrlBasePath() + "/luaswitch/viewToChangeLuaConf", param, "text", luaViewToChangeSuccess, errorFunc);
dialog.dialog("hide");
toWait();
}
}]
});
... ... @@ -204,6 +207,84 @@ function luaViewToChangeSuccess(resp) {
}
/**
* 创建Dns切换按钮
* @param luaType
*/
function createDnsSwitchButton(luaType){
if(luaType == ""){
return;
}
var awsButton = "<button class=\"btn btn-sm btn-success\" onclick=\"dnsSwitch(\'toAws\')\"> <em class=\"icon-cogs bigger-110\"></em>切向aws</button>";
var qqButton = "<button class=\"btn btn-sm btn-success\" onclick=\"dnsSwitch(\'toQcloud\')\"> <em class=\"icon-cogs bigger-110\"></em>切向qcloud</button>";
var mixButton = "<button class=\"btn btn-sm btn-success\" onclick=\"dnsSwitch(\'mix\')\"> <em class=\"icon-cogs bigger-110\"></em>切向双云</button>";
if(luaType == 'aws'){
$("#dns-div").html(qqButton + mixButton);
}else if (luaType == 'qq'){
$("#dns-div").html(awsButton + mixButton);
}else{
$("#dns-div").html(awsButton + qqButton);
}
}
/**
* 直接切换,由于调用的是api
* @param cloud
*/
function dnsSwitch(cloud){
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title: "你确定切换吗",
backdrop: "static",
content: "由于切换dns是调用的dnspod提供的api,因此当点击确定就直接切换!!!!!!",
buttons: [{
text: "否",
className: "btn-danger",
onclick: function () {
dialog.dialog("hide");
}
}, {
text: "是",
className: "btn-success",
onclick: function () {
sendAjax("post", getUrlBasePath() + "/luaswitch/dnsSwitchConf?cloudName="+cloud, {}, "text", switchSuccess, errorFunc);
dialog.dialog("hide");
}
}]
});
}
/**
* 查看当前入口配置
*/
function dnsViewConf(){
sendAjax("post", getUrlBasePath() + "/luaswitch/dnsViewCurrentConf", {}, "text", dnsViewCurrentConf, errorFunc);
}
/**
* 打开对话框,查看当前dns配置
* @param resp 当前响应数据
*/
function dnsViewCurrentConf(resp) {
var data = JSON.parse(resp);
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title: "当前配置",
backdrop: "static",
content: "<pre>" + data.data + "</pre>",
buttons: [{
text: "确定",
className: "btn-danger",
onclick: function () {
dialog.dialog("hide");
}
}]
}).find(".modal-body").css({
height: "650px"
});
}
/**
* 查看当前lua配置
*/
function luaViewConf(){
... ... @@ -401,33 +482,6 @@ function toWait() {
});
}
// 节点
function newNode(scene,x, y, w, h, text) {
var node = new JTopo.Node(text);
... ...