Authored by xuhui

nginx切换之dns切换

@@ -117,6 +117,14 @@ public class HttpUriContants { @@ -117,6 +117,14 @@ public class HttpUriContants {
117 public static final String VIEW_CURRENT_CONF = "/luaswitch/viewCurrentConf"; 117 public static final String VIEW_CURRENT_CONF = "/luaswitch/viewCurrentConf";
118 118
119 /** 119 /**
  120 + * nginx切换
  121 + * 之
  122 + * dnsswitch
  123 + */
  124 + public static final String NGINX_VIEW_DNS_CONF = "/luaswitch/dnsViewConf";
  125 + public static final String NGINX_SWITCH_DNS = "/luaswitch/dnsSwitchConf";
  126 +
  127 + /**
120 * lbswitch 128 * lbswitch
121 */ 129 */
122 public static final String VIEW_LB_CONF = "/lbswitch/viewConf"; 130 public static final String VIEW_LB_CONF = "/lbswitch/viewConf";
@@ -83,4 +83,37 @@ public class LuaSwitchCtrl { @@ -83,4 +83,37 @@ public class LuaSwitchCtrl {
83 return null; 83 return null;
84 } 84 }
85 85
86 -} 86 +
  87 + /**
  88 + * 查看当前流量入口配置
  89 + *
  90 + * @return BaseResponse
  91 + */
  92 + @RequestMapping(value = "dnsViewCurrentConf")
  93 + @ResponseBody
  94 + public BaseResponse dnsViewCurrentConf(){
  95 + try{
  96 + return httpRestClient.defaultGet(HttpUriContants.NGINX_VIEW_DNS_CONF, BaseResponse.class, null);
  97 + }catch (Exception e){
  98 + logger.error(" - LuaSwitchCtrl - viewCurrentConf - err ",e);
  99 + }
  100 + return null;
  101 + }
  102 +
  103 + /**
  104 + * 当前流量入口切换
  105 + *
  106 + * @param cloudName toAws toQcloud
  107 + * @return BaseResponse
  108 + */
  109 + @RequestMapping(value = "dnsSwitchConf")
  110 + @ResponseBody
  111 + public BaseResponse dnsSwitchConf(String cloudName){
  112 + try{
  113 + return httpRestClient.defaultGet(HttpUriContants.NGINX_SWITCH_DNS+"?cloudName="+cloudName, BaseResponse.class, null);
  114 + }catch (Exception e){
  115 + logger.error(" - LuaSwitchCtrl - viewCurrentConf - err ",e);
  116 + }
  117 + return null;
  118 + }
  119 +}
@@ -78,6 +78,21 @@ @@ -78,6 +78,21 @@
78 <div class="tree_container" style="height: 540px;color: black;overflow:auto;"> 78 <div class="tree_container" style="height: 540px;color: black;overflow:auto;">
79 <div class="panel panel-default"> 79 <div class="panel panel-default">
80 <div class="widget-title" style="height: 50px;"> 80 <div class="widget-title" style="height: 50px;">
  81 + <h5 style="display: inline">DNS切换</h5>
  82 + </div>
  83 + <div class="panel-body">
  84 + <button class="btn btn-sm btn-primary"
  85 + onclick="dnsViewConf()">
  86 + <em class="icon-cogs bigger-110"></em>
  87 + 查看当前DNS配置
  88 + </button>
  89 + <h3 class="header smaller red"></h3>
  90 +
  91 + <div id="dns-div" class="btn-group">
  92 + </div>
  93 + </div>
  94 +
  95 + <div class="widget-title" style="height: 50px;">
81 <h5 style="display: inline">直连切换</h5> 96 <h5 style="display: inline">直连切换</h5>
82 </div> 97 </div>
83 <div class="panel-body"> 98 <div class="panel-body">
@@ -116,6 +116,8 @@ function drawData(resp) { @@ -116,6 +116,8 @@ function drawData(resp) {
116 //创建lua切换按钮 116 //创建lua切换按钮
117 createLuaSwitchButton(data.luaType); 117 createLuaSwitchButton(data.luaType);
118 118
  119 + //创建入口切换按钮
  120 + createDnsSwitchButton(data.luaType);
119 } 121 }
120 122
121 /** 123 /**
@@ -165,6 +167,7 @@ function luaInitSwitch(cloudName) { @@ -165,6 +167,7 @@ function luaInitSwitch(cloudName) {
165 }; 167 };
166 sendAjax("post", getUrlBasePath() + "/luaswitch/viewToChangeLuaConf", param, "text", luaViewToChangeSuccess, errorFunc); 168 sendAjax("post", getUrlBasePath() + "/luaswitch/viewToChangeLuaConf", param, "text", luaViewToChangeSuccess, errorFunc);
167 dialog.dialog("hide"); 169 dialog.dialog("hide");
  170 + toWait();
168 } 171 }
169 }] 172 }]
170 }); 173 });
@@ -204,6 +207,84 @@ function luaViewToChangeSuccess(resp) { @@ -204,6 +207,84 @@ function luaViewToChangeSuccess(resp) {
204 } 207 }
205 208
206 /** 209 /**
  210 + * 创建Dns切换按钮
  211 + * @param luaType
  212 + */
  213 +function createDnsSwitchButton(luaType){
  214 + if(luaType == ""){
  215 + return;
  216 + }
  217 + var awsButton = "<button class=\"btn btn-sm btn-success\" onclick=\"dnsSwitch(\'toAws\')\"> <em class=\"icon-cogs bigger-110\"></em>切向aws</button>";
  218 + var qqButton = "<button class=\"btn btn-sm btn-success\" onclick=\"dnsSwitch(\'toQcloud\')\"> <em class=\"icon-cogs bigger-110\"></em>切向qcloud</button>";
  219 + var mixButton = "<button class=\"btn btn-sm btn-success\" onclick=\"dnsSwitch(\'mix\')\"> <em class=\"icon-cogs bigger-110\"></em>切向双云</button>";
  220 +
  221 + if(luaType == 'aws'){
  222 + $("#dns-div").html(qqButton + mixButton);
  223 + }else if (luaType == 'qq'){
  224 + $("#dns-div").html(awsButton + mixButton);
  225 + }else{
  226 + $("#dns-div").html(awsButton + qqButton);
  227 + }
  228 +}
  229 +
  230 +/**
  231 + * 直接切换,由于调用的是api
  232 + * @param cloud
  233 + */
  234 +function dnsSwitch(cloud){
  235 + var dialog = $("<div>").appendTo($("body"));
  236 + dialog.dialog({
  237 + title: "你确定切换吗",
  238 + backdrop: "static",
  239 + content: "由于切换dns是调用的dnspod提供的api,因此当点击确定就直接切换!!!!!!",
  240 + buttons: [{
  241 + text: "否",
  242 + className: "btn-danger",
  243 + onclick: function () {
  244 + dialog.dialog("hide");
  245 + }
  246 + }, {
  247 + text: "是",
  248 + className: "btn-success",
  249 + onclick: function () {
  250 + sendAjax("post", getUrlBasePath() + "/luaswitch/dnsSwitchConf?cloudName="+cloud, {}, "text", switchSuccess, errorFunc);
  251 + dialog.dialog("hide");
  252 + }
  253 + }]
  254 + });
  255 +}
  256 +
  257 +/**
  258 + * 查看当前入口配置
  259 + */
  260 +function dnsViewConf(){
  261 + sendAjax("post", getUrlBasePath() + "/luaswitch/dnsViewCurrentConf", {}, "text", dnsViewCurrentConf, errorFunc);
  262 +}
  263 +
  264 +/**
  265 +* 打开对话框,查看当前dns配置
  266 +* @param resp 当前响应数据
  267 +*/
  268 +function dnsViewCurrentConf(resp) {
  269 + var data = JSON.parse(resp);
  270 + var dialog = $("<div>").appendTo($("body"));
  271 + dialog.dialog({
  272 + title: "当前配置",
  273 + backdrop: "static",
  274 + content: "<pre>" + data.data + "</pre>",
  275 + buttons: [{
  276 + text: "确定",
  277 + className: "btn-danger",
  278 + onclick: function () {
  279 + dialog.dialog("hide");
  280 + }
  281 + }]
  282 + }).find(".modal-body").css({
  283 + height: "650px"
  284 + });
  285 +}
  286 +
  287 +/**
207 * 查看当前lua配置 288 * 查看当前lua配置
208 */ 289 */
209 function luaViewConf(){ 290 function luaViewConf(){
@@ -401,33 +482,6 @@ function toWait() { @@ -401,33 +482,6 @@ function toWait() {
401 }); 482 });
402 } 483 }
403 484
404 -  
405 -  
406 -  
407 -  
408 -  
409 -  
410 -  
411 -  
412 -  
413 -  
414 -  
415 -  
416 -  
417 -  
418 -  
419 -  
420 -  
421 -  
422 -  
423 -  
424 -  
425 -  
426 -  
427 -  
428 -  
429 -  
430 -  
431 // 节点 485 // 节点
432 function newNode(scene,x, y, w, h, text) { 486 function newNode(scene,x, y, w, h, text) {
433 var node = new JTopo.Node(text); 487 var node = new JTopo.Node(text);