switch.js
27.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
$(document).ready(function () {
$("input.slider").slider();
sendAjax("post", "getNgixnStatus", null, "json", drawData, errorFunc);
});
/**
* 展示画布 和 数据
* @param resp
*/
function drawData(resp) {
if(resp==null){
alert("获取数据异常");
return;
}
if(200!=resp.code){
console.log(resp);
alert("获取数据错误,"+resp.message);
return ;
}
var data = resp.data;
var canvas = document.getElementById('canvas');
var stage = new JTopo.Stage(canvas);
//显示工具栏
//showJTopoToobar(stage);
var scene = new JTopo.Scene();
stage.add(scene);
scene.background = contextPath + "img/bg.jpg";
var appNodeX = 10;
var appNodeY = -80;
var appNodeW = 30;
var appNodeH = 26;
//定义container for qq
var container_az1 = new JTopo.Container();
scene.add(container_az1);
container_az1.add(newNode(scene,appNodeX,appNodeY+120,1,1));
container_az1.add(newNode(scene,appNodeX,appNodeY+520,1,1));
container_az1.add(newNode(scene,appNodeX+320,appNodeY+120,1,1));
var container_az2 = new JTopo.Container();
scene.add(container_az2);
container_az2.add(newNode(scene,appNodeX+340,appNodeY+120,1,1));
container_az2.add(newNode(scene,appNodeX+340,appNodeY+520,1,1));
container_az2.add(newNode(scene,appNodeX+650,appNodeY+120,1,1));
var container_az3 = new JTopo.Container();
//container_az3.fillColor = '10,10,100';
scene.add(container_az3);
container_az3.add(newNode(scene,appNodeX+340+340,appNodeY+120,1,1));
container_az3.add(newNode(scene,appNodeX+340+340,appNodeY+520,1,1));
container_az3.add(newNode(scene,appNodeX+650+340,appNodeY+120,1,1));
/*
var appNode = newNode(scene,appNodeX+200,appNodeY+20,appNodeW,appNodeH,'APP');
var askServer = newNode(scene,appNodeX-20,appNodeY+150,appNodeW,appNodeH,'问询服务器');
container_az1.add(askServer);
var link = newFoldLink(scene,appNode, askServer, '问询');
link.arrowsRadius = 10;
*/
var elbMap={};
var elb_az1_outer = newNode(scene,appNodeX+80,appNodeY+150,appNodeW,appNodeH,'elb_az1_outer');
resetLbNodeIp(elb_az1_outer,data);
elbMap.az1_outer=elb_az1_outer;
var elb_az1_inner = newNode(scene,appNodeX+80+120,appNodeY+150,appNodeW,appNodeH,'elb_az1_inner');
resetLbNodeIp(elb_az1_inner,data);
elbMap.az1_inner=elb_az1_inner;
container_az1.add(elb_az1_outer);
container_az1.add(elb_az1_inner);
var elb_az2_outer = newNode(scene,appNodeX+400,appNodeY+150,appNodeW,appNodeH,'elb_az2_outer');
resetLbNodeIp(elb_az2_outer,data);
elbMap.az2_outer=elb_az2_outer;
var elb_az2_inner = newNode(scene,appNodeX+400+120,appNodeY+150,appNodeW,appNodeH,'elb_az2_inner');
resetLbNodeIp(elb_az2_inner,data);
elbMap.az2_inner=elb_az2_inner;
container_az2.add(elb_az2_outer);
container_az2.add(elb_az2_inner);
var elb_az3_outer = newNode(scene,appNodeX+720,appNodeY+150,appNodeW,appNodeH,'elb_az3_outer');
resetLbNodeIp(elb_az3_outer,data);
elbMap.az3_outer=elb_az3_outer;
var elb_az3_inner = newNode(scene,appNodeX+720+120,appNodeY+150,appNodeW,appNodeH,'elb_az3_inner');
resetLbNodeIp(elb_az3_inner,data);
elbMap.az3_inner=elb_az3_inner;
container_az3.add(elb_az3_outer);
container_az3.add(elb_az3_inner);
var az1Nginx = newNode(scene,appNodeX+105,appNodeY+250,appNodeW,appNodeH,'az1Nginx');
container_az1.add(az1Nginx);
for(var i=0;i<data.az1NginxIps.length;i++){
var tmp=newNodeForIp(scene,appNodeX+105+75,appNodeY+250+i*10,1,1,data.az1NginxIps[i]);
tmp.textPosition = 'Middle_Right';
container_az1.add(tmp);
}
var az2Nginx = newNode(scene,appNodeX+425,appNodeY+250,appNodeW,appNodeH,'az2Nginx');
container_az2.add(az2Nginx);
for(var i=0;i<data.az2NginxIps.length;i++){
var tmp=newNodeForIp(scene,appNodeX+425+75,appNodeY+250+i*10,1,1,data.az2NginxIps[i]);
tmp.textPosition = 'Middle_Right';
container_az2.add(tmp);
}
var az3Nginx = newNode(scene,appNodeX+425+340,appNodeY+250,appNodeW,appNodeH,'az3Nginx');
container_az3.add(az3Nginx);
for(var i=0;i<data.az3NginxIps.length;i++){
var tmp=newNodeForIp(scene,appNodeX+425+75+340,appNodeY+250+i*10,1,1,data.az3NginxIps[i]);
tmp.textPosition = 'Middle_Right';
container_az3.add(tmp);
}
for(var key in data.lb_forward_nginx){
var valueCloudAndWeightStr=data.lb_forward_nginx[key];
var tmpElbObj=elbMap[key];
var tmpCloud=key.substr(0,3);
var linkStrokeColor = '255,0,255';
if(tmpCloud=="az2"){
linkStrokeColor = '220,0,0';
}else if(tmpCloud=="az3"){
linkStrokeColor = '255,255,0';
}
console.log(valueCloudAndWeightStr);
if(valueCloudAndWeightStr!=null&&valueCloudAndWeightStr.length>0){
var cloudAndWeightArray=valueCloudAndWeightStr.split(",");
for(var i=0;i<cloudAndWeightArray.length;i++){
var cloud=cloudAndWeightArray[i].split(":")[0];
var weight=cloudAndWeightArray[i].split(":")[1];
if(cloud.indexOf("az1")>=0){
var link = newLink(scene,tmpElbObj, az1Nginx,weight);
link.arrowsRadius = 10;
link.strokeColor=linkStrokeColor;
//$("#"+tmpCloud+"_target_operate_nginx_az1").prop("checked",true);
$("#"+tmpCloud+"_input_slider_az1").slider("setValue",weight);
}
if(cloud.indexOf("az2")>=0){
var link = newLink(scene,tmpElbObj, az2Nginx,weight);
link.arrowsRadius = 10;
link.strokeColor=linkStrokeColor;
//$("#"+tmpCloud+"_target_operate_nginx_az2").prop("checked",true);
$("#"+tmpCloud+"_input_slider_az2").slider("setValue",weight);
}
if(cloud.indexOf("az3")>=0){
var link = newLink(scene,tmpElbObj, az3Nginx,weight);
link.arrowsRadius = 10;
link.strokeColor=linkStrokeColor;
//$("#"+tmpCloud+"_target_operate_nginx_az3").prop("checked",true);
$("#"+tmpCloud+"_input_slider_az3").slider("setValue",weight);
}
}
}
}
var az1Gateway = newNode(scene,appNodeX+120,appNodeY+370,appNodeW,appNodeH,'az1Gateway');
container_az1.add(az1Gateway);
for(var i=0;i<data.az1GatewayIps.length;i++){
var azIp=newNodeForIp(scene,appNodeX+120-20,appNodeY+370+60+i*10,1,1,data.az1GatewayIps[i]);
azIp.textPosition = 'Middle_Right';
container_az1.add(azIp);
}
/*var grayGateway = newNode(scene,appNodeX+230,appNodeY+390,appNodeW,appNodeH,'grayGateway');
container_az1.add(grayGateway);
for(var i=0;i<data.grayGatewayIps.length;i++){
var azIp=newNodeForIp(scene,appNodeX+230-15,appNodeY+370+60+i*10,1,1,data.grayGatewayIps[i]);
azIp.textPosition = 'Middle_Right';
container_az1.add(azIp);
}*/
var az2Gateway = newNode(scene,appNodeX+450,appNodeY+370,appNodeW,appNodeH,'az2Gateway');
container_az2.add(az2Gateway);
for(var i=0;i<data.az2GatewayIps.length;i++){
var az2NginxIp=newNodeForIp(scene,appNodeX+450-20,appNodeY+370+60+i*10,1,1,data.az2GatewayIps[i]);
az2NginxIp.textPosition = 'Middle_Right';
container_az2.add(az2NginxIp);
}
var az3Gateway = newNode(scene,appNodeX+450+340,appNodeY+370,appNodeW,appNodeH,'az3Gateway');
container_az3.add(az3Gateway);
for(var i=0;i<data.az3GatewayIps.length;i++){
var tmpNginxIp=newNodeForIp(scene,appNodeX+450+340-20,appNodeY+370+60+i*10,1,1,data.az3GatewayIps[i]);
tmpNginxIp.textPosition = 'Middle_Right';
container_az3.add(tmpNginxIp);
}
var link = newLink(scene,az1Nginx, az1Gateway,"");
link.arrowsRadius = 10;
var link = newLink(scene,az2Nginx, az2Gateway,"");
link.arrowsRadius = 10;
var link = newLink(scene,az3Nginx, az3Gateway,"");
link.arrowsRadius = 10;
//nginx切换区域
$("#nginxSwitchDiv").show();
//创建lua切换按钮
//createLuaSwitchButton(data.luaType);
//创建入口切换按钮
/* if('aws' == data.defaultDns){
var link = newFoldLink(scene,appNode, awsElb, 'dns','',5);
link.arrowsRadius = 10;
}else if('qq' == data.defaultDns){
var link = newFoldLink(scene,appNode, qqElb, 'dns','',5);
link.arrowsRadius = 10;
}*/
//createDnsSwitchButton(data.luaType);
}
function resetLbNodeIp(node,data) {
var oldText=node.text;
if(oldText.indexOf("inner")>=0){
// 填充颜色
node.fillColor = '85,107,47';
}else{
node.fillColor='210,105,30';
}
if(data[oldText]){
node.text = data[oldText];
}
}
/**
* "切向*"按钮点击事件,打开确认操作对话框
* @param cloudName 源中心名称
* @param target 目标中心名称
* @param onlineOrGray 切换:线上/灰度
*/
function nginxInitSwitch(cloudName) {
var target ="";
var arr = ["az1","az2","az3"];
for(var i= 0;i<arr.length;i++){
var inputSliderId=cloudName+"_input_slider_"+arr[i];
var weight=$("#"+inputSliderId).slider("getValue");
if(weight>0){
if(target.length>0){
target += ",";
}
target += arr[i]+":"+weight;
}
}
if(!target){
prompt("提示", "请选择<span style='color:red'>["+cloudName+"区]</span>目标nginx!");
return;
}
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title: "你确定切换吗",
backdrop: "static",
content: "你确定要将 " + cloudName + " 上的lb " + "流量切向<span style='color:red'> " + target + " </span>吗?",
buttons: [{
text: "否",
className: "btn-danger",
onclick: function () {
dialog.dialog("hide");
}
}, {
text: "是",
className: "btn-success",
onclick: function () {
var param = {
cloudName: cloudName,
target: target
};
var layerMirror=layer.open( {
type:3,
//area: ['800px', '500px'],
content:"准备切换,请等待",
time: 0 //不自动关闭
});
//提示信息框内容置空
$("#infoDive").html("");
$.ajax({
url: contextPath+'topoSwitch/switchLbWeight',
type: "post",
dataType: "json",
data: param ,
success: function (data) {
console.log(data);
if(data==null||data.code != 200){
layer.close(layerMirror);
alert("发生错误:"+data.message);
}else{
//调用切换成功之后,打开提示框,查看返回结果
layer.open( {
type:1,
closeBtn:0,
skin:"layer-info-class",
title:"进度详情",
area: ['800px', '500px'],
content:$("#infoDive"),
time: 0 //不自动关闭
});
//异步返回结果
var rtnID=data.data;
var count=0;
var intervalIndex = setInterval(function() {
$.ajax({
url: contextPath+"/topoSwitch/getLbSwitchResult",
type: "post",
dataType: "json",
data: {
rtnID:rtnID
},
success: function (checkResponse) {
count++;
console.log("time is "+count);
if(count > 50){
clearInterval(intervalIndex);
window.location.href = contextPath + "topoSwitch/toTopoSwitch";
}
if(checkResponse==null){
$("#infoDive").append("time is "+count);
$("#infoDive").append("response is null");
}else{
$("#infoDive").html("");
$("#infoDive").append("time is "+count);
if(checkResponse.code==200){
clearInterval(intervalIndex);
if(checkResponse.message!=null&&checkResponse.message.indexOf("error")>=0){
//发生了错误
for(var key in checkResponse.data){
$("#infoDive").append(checkResponse.data[key]);
$("#infoDive").append("<br/><br/><br/>");
}
$("#infoDive").append("切换发生错误,终止!");
}else{
window.location.href = contextPath + "topoSwitch/toTopoSwitch";
}
}else{
for(var key in checkResponse.data){
$("#infoDive").append(checkResponse.data[key]);
$("#infoDive").append("<br/><br/><br/>");
}
}
}
},
error: function (e) {
console.log("getLbSwitchResult"+e);
}
});
}, 15000);//15s
//window.location.href = contextPath + "topoSwitch/toTopoSwitch";
}
},
error: function (e) {
//alert("系统错误");
console.log(e);
layer.close(layerMirror);
alert("网络错误:异常"+e.message);
window.location.href = contextPath + "topoSwitch/toTopoSwitch";
}
});
dialog.dialog("hide");
}
}]
});
}
/**
* 创建lua切换按钮
* @param luaType
*/
function createLuaSwitchButton(luaType){
if(luaType == ""){
return;
}
var awsButton = "<button class=\"btn btn-sm btn-success\" onclick=\"luaInitSwitch(\'aws\')\"> <em class=\"icon-cogs bigger-110\"></em>切向aws</button>";
var qqButton = "<button class=\"btn btn-sm btn-success\" onclick=\"luaInitSwitch(\'qcloud\')\"> <em class=\"icon-cogs bigger-110\"></em>切向qcloud</button>";
var mixButton = "<button class=\"btn btn-sm btn-success\" onclick=\"luaInitSwitch(\'mix\')\"> <em class=\"icon-cogs bigger-110\"></em>切向双云</button>";
if(luaType == 'aws'){
$("#lua-div").html(qqButton + mixButton);
}else if (luaType == 'qq'){
$("#lua-div").html(awsButton + mixButton);
}else{
$("#lua-div").html(awsButton + qqButton);
}
}
/**
* "*切换"按钮点击事件,打开确认操作对话框
* @param cloudName 目标中心名称
*/
function luaInitSwitch(cloudName) {
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title: "你确定切换吗",
backdrop: "static",
content: "你确定要将Lua脚本切换至" + cloudName + "吗?",
buttons: [{
text: "否",
className: "btn-danger",
onclick: function () {
dialog.dialog("hide");
}
}, {
text: "是",
className: "btn-success",
onclick: function () {
var param = {
cloudName: cloudName
};
sendAjax("post", getUrlBasePath() + "/luaswitch/viewToChangeLuaConf", param, "text", luaViewToChangeSuccess, errorFunc);
dialog.dialog("hide");
toWait();
}
}]
});
}
/**
* 打开对话框,展示切换后的配置
* @param resp 切换后的响应数据
*/
function luaViewToChangeSuccess(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");
}
}, {
text: "确定",
className: "btn-success",
onclick: function () {
sendAjax("post", getUrlBasePath() + "/luaswitch/switchConf", {}, "text", switchSuccess, errorFunc);
dialog.dialog("hide");
toWait();
}
}]
}).find(".modal-body").css({
height: "650px"
});
}
/**
* 创建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");
toWait();
}
}]
});
}
/**
* 查看当前入口配置
*/
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 style='width:568px'>" + data.data + "</pre>",
buttons: [{
text: "确定",
className: "btn-danger",
onclick: function () {
dialog.dialog("hide");
}
}]
}).find(".modal-body").css({
height: "280px",
width: "600px"
});
}
/**
* 查看当前lua配置
*/
function luaViewConf(){
sendAjax("post", getUrlBasePath() + "/luaswitch/viewCurrentConf", {}, "text", viewCurrentConf, errorFunc);
}
/**
* 查看当前nginx配置
*/
function nginxViewConf(cloud){
sendAjax("post", getUrlBasePath() + "/nginxswitch/viewCurrentConf", {cloudName:cloud}, "text", viewCurrentConf, errorFunc);
}
/**
* 切换配置成功,跳转回首页
*/
function switchSuccess() {
window.location.href = getUrlBasePath() + "/topoSwitch/toTopoSwitch";
}
/**
* 打开对话框,展示切换后的配置
* @param resp 切换后的响应数据
*/
function nginxViewToChangeSuccess(resp) {
var data = JSON.parse(resp);
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title: "切换结果",
backdrop: "static",
content: "<pre>" + data.data.result + "</pre>",
buttons: [{
text: "否",
className: "btn-danger",
onclick: function () {
dialog.dialog("hide");
}
}, {
text: "确定",
className: "btn-success",
onclick: function () {
var param = {
cloudName: data.data.cloudName
};
sendAjax("post", getUrlBasePath() + "/nginxswitch/switchNginxConf", param, "text", switchSuccess, errorFunc);
dialog.dialog("hide");
toWait();
}
}]
}).find(".modal-body").css({
height: "650px"
});
}
/**
* 打开对话框,查看当前配置
* @param resp 切换后的响应数据
*/
function viewCurrentConf(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"
});
}
/**
* 获取不切换的服务器ip(由于线上和灰度同在nginx.conf配置中,模板须设计两个占位符,所以切换某一处时,须将不切换的ip提交到后台)
* @param cloudName 切换的中心aws/qcloud
* @param onlineOrGray 切换线上/灰度
* @returns {Array} 不切换服务器的ip列表
*/
function getNoChangeIpArr(cloudName, onlineOrGray) {
var list = $("." + cloudName + ("online" === onlineOrGray ? "grayapigateway" : "apigateway") + "Ips");
if (undefined === list || null === list || 0 === list.length) {
return [];
}
var result = [];
list.each(function () {
result.push($(this).text().split(":")[0]);
});
return result;
}
/**
* 提示函数
* @param title 标题
* @param content 内容
*/
function prompt(title, content) {
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title: title,
backdrop: "static",
content: content,
buttons: [{
text: "关闭",
className: "btn-danger",
onclick: function () {
dialog.dialog("hide");
}
}]
});
}
/**
* 发送ajax请求
* @param type 请求方法post/get
* @param url 请求url
* @param data 请求参数数据
* @param dataType 请求参数类型
* @param success 请求成功回调函数
* @param error 请求异常回调函数
*/
function sendAjax(type, url, data, dataType, success, error) {
$.ajax({
type: type,
url: url,
data: data,
dataType: dataType,
success: success,
error: error
});
}
/**
* ajax请求异常回调函数
*/
function errorFunc() {
layer.msg("Token异常", {icon: 2});
}
/**
* 打开等待对话框
*/
function toWait() {
$("<div>").appendTo($("body")).dialog({
title: "提示",
backdrop: "static",
content: "正在切换,请稍后..."
});
}
// 节点
function newNode(scene,x, y, w, h, text) {
var node = new JTopo.Node(text);
node.setLocation(x, y);
node.setSize(w, h);
if("APP"==text){
node.setImage(contextPath + 'img/pstn/host.png', true);
}else if("问询服务器"==text){
node.setImage(contextPath + 'img/pstn/terminal.png', true);
}else if(text!=null&&text.toLowerCase().indexOf("elb")>=0){
///node.setImage(contextPath + 'img/pstn/cloud.png', true);
node.setSize(100, 30);
node.borderRadius = 5; // 圆角
node.borderWidth = 1; // 边框的宽度
node.borderColor = '255,255,255'; //边框颜色
// node.alpha = 0.7; //透明度
node.textPosition = 'Middle_Center';// 文字居中
}else if(text!=null&&text.toLowerCase().indexOf("nginx")>=0){
node.setImage(contextPath + 'img/pstn/router2.png', true);
//node.textPosition = 'Top_Left';// 文字居中
}else if("az3Gateway"==text||"qqGateway"==text||"az1Gateway"==text||"az2Gateway"==text){
node.setImage(contextPath + 'img/pstn/msc.png', true);
//node.alarm = "";
//node.alarmColor = '0,255,0';
}else if("grayGateway"==text){
node.setImage(contextPath + 'img/pstn/router.png', true);
}
scene.add(node);
return node;
}
function newNodeForIp(scene,x, y, w, h, text) {
var node=newNode(scene,x, y, w, h, text);
node.fontColor='50,180,202'
return node;
}
// 简单连线
function newLink(scene,nodeA, nodeZ, text, dashedPattern) {
var link = new JTopo.Link(nodeA, nodeZ, text);
link.lineWidth = 3; // 线宽
link.dashedPattern = dashedPattern; // 虚线
link.bundleOffset = 60; // 折线拐角处的长度
link.bundleGap = 20; // 线条之间的间隔
link.textOffsetY = 3; // 文本偏移量(向下3个像素)
link.strokeColor = '0,200,255';
scene.add(link);
return link;
}
// 折线
function newFoldLink(scene,nodeA, nodeZ, text, direction, dashedPattern) {
var link = new JTopo.FoldLink(nodeA, nodeZ, text);
link.direction = direction || 'horizontal';
link.arrowsRadius = 15; //箭头大小
link.lineWidth = 3; // 线宽
link.bundleOffset = 60; // 折线拐角处的长度
link.bundleGap = 20; // 线条之间的间隔
link.textOffsetY = 3; // 文本偏移量(向下3个像素)
//link.strokeColor = JTopo.util.randomColor(); // 线条颜色随机
link.dashedPattern = dashedPattern;
if(dashedPattern){
link.strokeColor = "255,255,0";
}else{
link.strokeColor = "34,139,34";
}
scene.add(link);
return link;
}
// 二次折线
function newFlexionalLink(scene,nodeA, nodeZ, text, direction, dashedPattern) {
var link = new JTopo.FlexionalLink(nodeA, nodeZ, text);
link.direction = direction || 'horizontal';
link.arrowsRadius = 10;
link.lineWidth = 3; // 线宽
link.offsetGap = 35;
link.bundleGap = 15; // 线条之间的间隔
link.textOffsetY = 10; // 文本偏移量(向下15个像素)
link.strokeColor = '0,250,0';
link.dashedPattern = dashedPattern;
scene.add(link);
return link;
}
// 曲线
function newCurveLink(scene,nodeA, nodeZ, text) {
var link = new JTopo.CurveLink(nodeA, nodeZ, text);
link.lineWidth = 3; // 线宽
scene.add(link);
return link;
}