Showing
4 changed files
with
149 additions
and
56 deletions
@@ -96,6 +96,7 @@ public class HttpUriContants { | @@ -96,6 +96,7 @@ public class HttpUriContants { | ||
96 | * nginxswitch | 96 | * nginxswitch |
97 | */ | 97 | */ |
98 | public static final String VIEW_NGINX_CONF= "/nginxswitch/viewNginxConf"; | 98 | public static final String VIEW_NGINX_CONF= "/nginxswitch/viewNginxConf"; |
99 | + public static final String VIEW_TOCHANGE_NGINX_CONF= "/nginxswitch/viewToChangeNginxConf"; | ||
99 | public static final String SWITCH_NGINX= "/nginxswitch/switchNginxConf"; | 100 | public static final String SWITCH_NGINX= "/nginxswitch/switchNginxConf"; |
100 | 101 | ||
101 | /** | 102 | /** |
@@ -35,9 +35,9 @@ public class NginxSwitchCtrl { | @@ -35,9 +35,9 @@ public class NginxSwitchCtrl { | ||
35 | */ | 35 | */ |
36 | @RequestMapping(value = "toNginxSwitch") | 36 | @RequestMapping(value = "toNginxSwitch") |
37 | public ModelAndView viewNginxConf() { | 37 | public ModelAndView viewNginxConf() { |
38 | - BaseResponse<Map<String,List<Map<String, Object>>>> response = httpRestClient.exchangeForget(HttpUriContants.VIEW_NGINX_CONF, new ParameterizedTypeReference<BaseResponse<Map<String,List<Map<String, Object>>>>>() { | 38 | + BaseResponse<Map<String, List<Map<String, Object>>>> response = httpRestClient.exchangeForget(HttpUriContants.VIEW_NGINX_CONF, new ParameterizedTypeReference<BaseResponse<Map<String, List<Map<String, Object>>>>>() { |
39 | }, null); | 39 | }, null); |
40 | - Map<String,List<Map<String, Object>>> map = response.getData(); | 40 | + Map<String, List<Map<String, Object>>> map = response.getData(); |
41 | ModelAndView mdv = new ModelAndView("switch/nginxSwitch"); | 41 | ModelAndView mdv = new ModelAndView("switch/nginxSwitch"); |
42 | mdv.addObject("awsList", map.get("awsList")); | 42 | mdv.addObject("awsList", map.get("awsList")); |
43 | mdv.addObject("qcloudList", map.get("qcloudList")); | 43 | mdv.addObject("qcloudList", map.get("qcloudList")); |
@@ -51,11 +51,25 @@ public class NginxSwitchCtrl { | @@ -51,11 +51,25 @@ public class NginxSwitchCtrl { | ||
51 | */ | 51 | */ |
52 | @RequestMapping(value = "switchNginxConf") | 52 | @RequestMapping(value = "switchNginxConf") |
53 | @ResponseBody | 53 | @ResponseBody |
54 | - public BaseResponse switchNginxConf(String cloudName, String target) { | ||
55 | - Map map = new HashMap<>(); | ||
56 | - map.put("cloudName",cloudName); | ||
57 | - map.put("target",target); | 54 | + public BaseResponse switchNginxConf() { |
55 | + Map<String, String> map = new HashMap<>(); | ||
58 | return httpRestClient.defaultGet(HttpUriContants.SWITCH_NGINX, BaseResponse.class, map); | 56 | return httpRestClient.defaultGet(HttpUriContants.SWITCH_NGINX, BaseResponse.class, map); |
59 | } | 57 | } |
60 | 58 | ||
59 | + /** | ||
60 | + * 修改配置 | ||
61 | + * | ||
62 | + * @return 2016年5月12日下午1:49:48 | ||
63 | + */ | ||
64 | + @RequestMapping(value = "viewToChangeNginxConf") | ||
65 | + @ResponseBody | ||
66 | + public BaseResponse viewToChangeNginxConf(String cloudName, String target, String onlineOrGray, String noChangeIps) { | ||
67 | + Map<String, String> map = new HashMap<>(); | ||
68 | + map.put("cloudName", cloudName); | ||
69 | + map.put("target", target); | ||
70 | + map.put("onlineOrGray", onlineOrGray); | ||
71 | + map.put("ips", noChangeIps); | ||
72 | + return httpRestClient.defaultGet(HttpUriContants.VIEW_TOCHANGE_NGINX_CONF, BaseResponse.class, map); | ||
73 | + } | ||
74 | + | ||
61 | } | 75 | } |
@@ -124,27 +124,27 @@ | @@ -124,27 +124,27 @@ | ||
124 | <button class="btn btn-sm "> | 124 | <button class="btn btn-sm "> |
125 | 线上切换 | 125 | 线上切换 |
126 | </button> | 126 | </button> |
127 | - <button class="btn btn-sm btn-success" onclick="initSwitch('aws','qcloud')"> | 127 | + <button class="btn btn-sm btn-success" onclick="initSwitch('aws','qcloud','online','${awsList}')"> |
128 | <i class="icon-cogs bigger-110"></i> | 128 | <i class="icon-cogs bigger-110"></i> |
129 | 切向qcloud | 129 | 切向qcloud |
130 | </button> | 130 | </button> |
131 | - <button class="btn btn-sm btn-success" onclick="initSwitch('aws','aws')"> | 131 | + <button class="btn btn-sm btn-success" onclick="initSwitch('aws','aws','online','${awsList}')"> |
132 | <i class="icon-cogs bigger-110"></i> | 132 | <i class="icon-cogs bigger-110"></i> |
133 | 切向aws | 133 | 切向aws |
134 | </button><br><br> | 134 | </button><br><br> |
135 | <button class="btn btn-sm "> | 135 | <button class="btn btn-sm "> |
136 | 灰度切换 | 136 | 灰度切换 |
137 | </button> | 137 | </button> |
138 | - <button class="btn btn-sm btn-success" onclick="initSwitch('gray','qcloud')"> | 138 | + <button class="btn btn-sm btn-success" onclick="initSwitch('aws','qcloud','gray','${awsList}')"> |
139 | <i class="icon-cogs bigger-110"></i> | 139 | <i class="icon-cogs bigger-110"></i> |
140 | 切向qcloud | 140 | 切向qcloud |
141 | </button> | 141 | </button> |
142 | </button> | 142 | </button> |
143 | - <button class="btn btn-sm btn-success" onclick="initSwitch('gray','aws')"> | 143 | + <button class="btn btn-sm btn-success" onclick="initSwitch('aws','aws','gray','${awsList}')"> |
144 | <i class="icon-cogs bigger-110"></i> | 144 | <i class="icon-cogs bigger-110"></i> |
145 | 切向aws | 145 | 切向aws |
146 | </button> | 146 | </button> |
147 | - <button class="btn btn-sm btn-success" onclick="initSwitch('gray','gray')"> | 147 | + <button class="btn btn-sm btn-success" onclick="initSwitch('aws','gray','gray','${awsList}')"> |
148 | <i class="icon-cogs bigger-110"></i> | 148 | <i class="icon-cogs bigger-110"></i> |
149 | 切向gray | 149 | 切向gray |
150 | </button> | 150 | </button> |
@@ -180,11 +180,11 @@ | @@ -180,11 +180,11 @@ | ||
180 | <button class="btn btn-sm "> | 180 | <button class="btn btn-sm "> |
181 | 线上切换 | 181 | 线上切换 |
182 | </button> | 182 | </button> |
183 | - <button class="btn btn-sm btn-success" onclick="initSwitch('qcloud','qcloud')"> | 183 | + <button class="btn btn-sm btn-success" onclick="initSwitch('qcloud','qcloud','online','${qcloudList}')"> |
184 | <i class="icon-cogs bigger-110"></i> | 184 | <i class="icon-cogs bigger-110"></i> |
185 | 切向qcloud | 185 | 切向qcloud |
186 | </button> | 186 | </button> |
187 | - <button class="btn btn-sm btn-success" onclick="initSwitch('qcloud','aws')"> | 187 | + <button class="btn btn-sm btn-success" onclick="initSwitch('qcloud','aws','online','${qcloudList}')"> |
188 | <i class="icon-cogs bigger-110"></i> | 188 | <i class="icon-cogs bigger-110"></i> |
189 | 切向aws | 189 | 切向aws |
190 | </button> | 190 | </button> |
@@ -192,15 +192,15 @@ | @@ -192,15 +192,15 @@ | ||
192 | <button class="btn btn-sm "> | 192 | <button class="btn btn-sm "> |
193 | 灰度切换 | 193 | 灰度切换 |
194 | </button> | 194 | </button> |
195 | - <button class="btn btn-sm btn-success" onclick="initSwitch('gray','qcloud')"> | 195 | + <button class="btn btn-sm btn-success" onclick="initSwitch('qcloud','qcloud','gray','${qcloudList}')"> |
196 | <i class="icon-cogs bigger-110"></i> | 196 | <i class="icon-cogs bigger-110"></i> |
197 | 切向qcloud | 197 | 切向qcloud |
198 | </button> | 198 | </button> |
199 | - <button class="btn btn-sm btn-success" onclick="initSwitch('gray','aws')"> | 199 | + <button class="btn btn-sm btn-success" onclick="initSwitch('qcloud','aws','gray','${qcloudList}')"> |
200 | <i class="icon-cogs bigger-110"></i> | 200 | <i class="icon-cogs bigger-110"></i> |
201 | 切向aws | 201 | 切向aws |
202 | </button> | 202 | </button> |
203 | - <button class="btn btn-sm btn-success" onclick="initSwitch('gray','gray')"> | 203 | + <button class="btn btn-sm btn-success" onclick="initSwitch('qcloud','gray','gray','${qcloudList}')"> |
204 | <i class="icon-cogs bigger-110"></i> | 204 | <i class="icon-cogs bigger-110"></i> |
205 | 切向gray | 205 | 切向gray |
206 | </button> | 206 | </button> |
@@ -229,9 +229,5 @@ | @@ -229,9 +229,5 @@ | ||
229 | </div> | 229 | </div> |
230 | 230 | ||
231 | <script src="<%=basePath %>script/common/genarate_left_panel.js"></script> | 231 | <script src="<%=basePath %>script/common/genarate_left_panel.js"></script> |
232 | -<script> | ||
233 | - $("#li_switch").addClass("active open"); | ||
234 | - $("#li_nginxswitch").addClass("active"); | ||
235 | -</script> | ||
236 | </body> | 232 | </body> |
237 | </html> | 233 | </html> |
1 | +var dialog1; | ||
2 | +var dialog2; | ||
3 | +var dialog3; | ||
4 | + | ||
1 | $(function () { | 5 | $(function () { |
2 | - $("#validateTokenRltInfo").hide(); | 6 | + dialog1 = $("<div>").appendTo($("body")); |
7 | + dialog2 = $("<div>").appendTo($("body")); | ||
8 | + dialog3 = $("<div>").appendTo($("body")); | ||
3 | }); | 9 | }); |
4 | 10 | ||
5 | -function initSwitch(cloudName, target) { | ||
6 | - var dialog = $("<div>").appendTo($("body")); | ||
7 | - dialog.dialog({ | 11 | +function initSwitch(cloudName, target, onlineOrGray, list) { |
12 | + var arr = getNoChangeIpArr(onlineOrGray, list); | ||
13 | + if (undefined === arr || null === arr || 0 === arr.length) { | ||
14 | + prompt("提示", "无可切换的gateway!"); | ||
15 | + return; | ||
16 | + } | ||
17 | + | ||
18 | + dialog2.dialog({ | ||
8 | title: "你确定切换吗", | 19 | title: "你确定切换吗", |
9 | backdrop: "static", | 20 | backdrop: "static", |
10 | - content: "你确定要将" + cloudName + "上的流量切向" + target + "吗?", | 21 | + content: "你确定要将" + cloudName + "上的" + onlineOrGray + "流量切向" + target + "吗?", |
11 | buttons: [{ | 22 | buttons: [{ |
12 | text: "否", | 23 | text: "否", |
13 | className: "btn-danger", | 24 | className: "btn-danger", |
14 | onclick: function () { | 25 | onclick: function () { |
15 | - $(dialog).dialog("hide"); | 26 | + $(dialog2).dialog("hide"); |
16 | } | 27 | } |
17 | }, { | 28 | }, { |
18 | text: "是", | 29 | text: "是", |
@@ -20,38 +31,109 @@ function initSwitch(cloudName, target) { | @@ -20,38 +31,109 @@ function initSwitch(cloudName, target) { | ||
20 | onclick: function () { | 31 | onclick: function () { |
21 | var param = { | 32 | var param = { |
22 | cloudName: cloudName, | 33 | cloudName: cloudName, |
23 | - target: target | ||
24 | - } | ||
25 | - $.ajax({ | ||
26 | - type: 'post', | ||
27 | - url: 'switchNginxConf', | ||
28 | - data: param, | ||
29 | - dataType: 'text', | ||
30 | - success: function (resp) { | ||
31 | - $(dialog).dialog("hide"); | ||
32 | - var data = JSON.parse(resp); | ||
33 | - | ||
34 | - var dialog2 = $("<div>").appendTo($("body")); | ||
35 | - dialog2.dialog({ | ||
36 | - title: "切换结果", | ||
37 | - backdrop: "static", | ||
38 | - content: data.data, | ||
39 | - buttons: [{ | ||
40 | - text: "确定", | ||
41 | - className: "btn-danger", | ||
42 | - onclick: function () { | ||
43 | - window.location.href = getUrlBasePath() + "/nginxswitch/toNginxSwitch"; | ||
44 | - } | ||
45 | - }] | ||
46 | - }); | ||
47 | - | ||
48 | - }, | ||
49 | - error: function (data) { | ||
50 | - layer.msg("Token异常", {icon: 2}); | ||
51 | - } | ||
52 | - }); | 34 | + target: target, |
35 | + onlineOrGray: onlineOrGray, | ||
36 | + noChangeIps: JSON.stringify(arr) | ||
37 | + }; | ||
38 | + sendAjax("post", "viewToChangeNginxConf", param, "text", viewToChangeSuccess, errorFunc); | ||
53 | } | 39 | } |
54 | }] | 40 | }] |
55 | }); | 41 | }); |
42 | +} | ||
43 | + | ||
44 | +function viewToChangeSuccess(resp) { | ||
45 | + $(dialog2).dialog("hide"); | ||
46 | + | ||
47 | + var data = JSON.parse(resp); | ||
48 | + dialog3.dialog({ | ||
49 | + title: "切换结果", | ||
50 | + backdrop: "static", | ||
51 | + content: data.data, | ||
52 | + buttons: [{ | ||
53 | + text: "否", | ||
54 | + className: "btn-danger", | ||
55 | + onclick: function () { | ||
56 | + $(dialog3).dialog("hide"); | ||
57 | + } | ||
58 | + }, { | ||
59 | + text: "确定", | ||
60 | + className: "btn-danger", | ||
61 | + onclick: function () { | ||
62 | + sendAjax("post", "switchNginxConf", {}, "text", switchSuccess, errorFunc); | ||
63 | + } | ||
64 | + }] | ||
65 | + }); | ||
66 | +} | ||
67 | + | ||
68 | +function switchSuccess() { | ||
69 | + window.location.href = getUrlBasePath() + "/nginxswitch/toNginxSwitch"; | ||
70 | +} | ||
71 | + | ||
72 | +/** | ||
73 | + * 获取不切换的服务器ip(由于线上和灰度同在nginx.conf配置中,模板须设计两个占位符,所以切换某一处时,须将不切换的ip提交到后台) | ||
74 | + * @param onlineOrGray 切换线上/灰度 | ||
75 | + * @param list 线上和灰度的upstream配置列表 | ||
76 | + * @returns {Array} 不切换服务器的ip列表 | ||
77 | + */ | ||
78 | +function getNoChangeIpArr(onlineOrGray, list) { | ||
79 | + if (undefined === list || null === list || 0 === list.length) { | ||
80 | + return []; | ||
81 | + } | ||
82 | + var arr = []; | ||
83 | + var p = ""; | ||
84 | + if ("online" === onlineOrGray) { | ||
85 | + p = "grayapigateway"; | ||
86 | + } else { | ||
87 | + p = "apigateway"; | ||
88 | + } | ||
89 | + for (var o in list) { | ||
90 | + if (undefined === o || null === o || undefined === o.name || null === o.name || p !== o.name) { | ||
91 | + continue; | ||
92 | + } | ||
93 | + if (undefined === o.server || null === o.server || 0 === o.server.length) { | ||
94 | + continue; | ||
95 | + } | ||
96 | + for (var ob in o.server) { | ||
97 | + if (undefined === ob || null === ob || '' === ob) { | ||
98 | + continue; | ||
99 | + } | ||
100 | + arr.push(ob.split(":")[0].replace(" ", "").replace("server", "")); | ||
101 | + } | ||
102 | + } | ||
103 | + return arr; | ||
104 | +} | ||
105 | + | ||
106 | +/** | ||
107 | + * 提示函数 | ||
108 | + * @param title | ||
109 | + * @param content | ||
110 | + */ | ||
111 | +function prompt(title, content) { | ||
112 | + dialog1.dialog({ | ||
113 | + title: title, | ||
114 | + backdrop: "static", | ||
115 | + content: content, | ||
116 | + buttons: [{ | ||
117 | + text: "确定", | ||
118 | + className: "btn-success", | ||
119 | + onclick: function () { | ||
120 | + $(dialog1).dialog("hide"); | ||
121 | + } | ||
122 | + }] | ||
123 | + }); | ||
124 | +} | ||
125 | + | ||
126 | +function sendAjax(type, url, data, dataType, success, error) { | ||
127 | + $.ajax({ | ||
128 | + type: type, | ||
129 | + url: url, | ||
130 | + data: data, | ||
131 | + dataType: dataType, | ||
132 | + success: success, | ||
133 | + error: error | ||
134 | + }); | ||
135 | +} | ||
56 | 136 | ||
137 | +function errorFunc() { | ||
138 | + layer.msg("Token异常", {icon: 2}); | ||
57 | } | 139 | } |
-
Please register or login to post a comment