Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
monitor-ui
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
xuhui
8 years ago
Commit
791972ac84f5be01f66d5e492d60ee9ec092e0ac
1 parent
4ac5061d
优化nginx切换
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
86 deletions
monitor-ui-ctrl/src/main/java/com/ui/ctrl/TopoSwitchCtrl.java
monitor-ui-web/src/main/webapp/script/switch.js
monitor-ui-ctrl/src/main/java/com/ui/ctrl/TopoSwitchCtrl.java
View file @
791972a
package
com
.
ui
.
ctrl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.ui.contants.HttpUriContants
;
import
com.ui.http.HttpRestClient
;
import
com.ui.model.BaseResponse
;
...
...
@@ -53,95 +54,102 @@ public class TopoSwitchCtrl {
@RequestMapping
(
value
=
"getNgixnStatus"
)
@ResponseBody
public
BaseResponse
getNgixnStatus
()
{
//lua
String
luaResponse
=
httpRestClient
.
defaultGet
(
HttpUriContants
.
VIEW_LUA_CONF
,
String
.
class
,
null
);
//String luaResponse = "-- 1:aws ,2:qq ,3:aws+qq</br>context.cloud_flag = 1</br>";
String
luaType
=
"aws"
;
if
(
luaResponse
.
matches
(
".*context.cloud_flag\\s*=\\s*2.*"
))
{
luaType
=
"qq"
;
}
else
if
(
luaResponse
.
matches
(
".*context.cloud_flag\\s*=\\s*3.*"
))
{
luaType
=
"aws+qq"
;
}
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<>();
//nginx
BaseResponse
<
Map
<
String
,
List
<
Map
<
String
,
Object
>>>>
response
=
httpRestClient
.
exchangeForget
(
HttpUriContants
.
VIEW_NGINX_CONF
,
new
ParameterizedTypeReference
<
BaseResponse
<
Map
<
String
,
List
<
Map
<
String
,
Object
>>>>>()
{
},
null
);
Map
<
String
,
List
<
Map
<
String
,
Object
>>>
map
=
response
.
getData
();
List
<
Map
<
String
,
Object
>>
awsList
=
map
.
get
(
"awsList"
);
List
<
Map
<
String
,
Object
>>
qcloudList
=
map
.
get
(
"qcloudList"
);
String
awsApiNginx
=
"aws"
;
String
awsGrayNginx
=
"aws"
;
String
qqApiNginx
=
"qq"
;
String
qqGrayNginx
=
"qq"
;
for
(
Map
<
String
,
Object
>
apiMap
:
awsList
)
{
if
(
StringUtils
.
equals
(
"apigateway"
,
String
.
valueOf
(
apiMap
.
get
(
"name"
))))
{
List
<
String
>
serverList
=
(
List
<
String
>)
apiMap
.
get
(
"server"
);
if
(
serverList
.
get
(
0
).
startsWith
(
"10"
))
{
awsApiNginx
=
"qq"
;
try
{
//lua
String
luaResponse
=
httpRestClient
.
defaultGet
(
HttpUriContants
.
VIEW_LUA_CONF
,
String
.
class
,
null
);
String
luaType
=
""
;
if
(
StringUtils
.
isNotBlank
(
luaResponse
)){
if
(
luaResponse
.
matches
(
".*context.cloud_flag\\s*=\\s*2.*"
))
{
luaType
=
"qq"
;
}
else
if
(
luaResponse
.
matches
(
".*context.cloud_flag\\s*=\\s*3.*"
))
{
luaType
=
"aws+qq"
;
}
else
{
luaType
=
"aws"
;
}
}
if
(
StringUtils
.
equals
(
"grayapigateway"
,
String
.
valueOf
(
apiMap
.
get
(
"name"
))))
{
List
<
String
>
serverList
=
(
List
<
String
>)
apiMap
.
get
(
"server"
);
if
(
serverList
.
get
(
0
).
startsWith
(
"10"
))
{
awsGrayNginx
=
"qq"
;
//nginx
BaseResponse
<
Map
<
String
,
List
<
Map
<
String
,
Object
>>>>
response
=
httpRestClient
.
exchangeForget
(
HttpUriContants
.
VIEW_NGINX_CONF
,
new
ParameterizedTypeReference
<
BaseResponse
<
Map
<
String
,
List
<
Map
<
String
,
Object
>>>>>()
{
},
null
);
Map
<
String
,
List
<
Map
<
String
,
Object
>>>
map
=
response
.
getData
();
List
<
Map
<
String
,
Object
>>
awsList
=
map
.
get
(
"awsList"
);
List
<
Map
<
String
,
Object
>>
qcloudList
=
map
.
get
(
"qcloudList"
);
String
awsApiNginx
=
"aws"
;
String
awsGrayNginx
=
"aws"
;
String
qqApiNginx
=
"qq"
;
String
qqGrayNginx
=
"qq"
;
for
(
Map
<
String
,
Object
>
apiMap
:
awsList
)
{
if
(
StringUtils
.
equals
(
"apigateway"
,
String
.
valueOf
(
apiMap
.
get
(
"name"
))))
{
List
<
String
>
serverList
=
(
List
<
String
>)
apiMap
.
get
(
"server"
);
if
(
serverList
.
get
(
0
).
startsWith
(
"10"
))
{
awsApiNginx
=
"qq"
;
}
}
}
}
for
(
Map
<
String
,
Object
>
apiMap
:
qcloudList
)
{
if
(
StringUtils
.
equals
(
"apigateway"
,
String
.
valueOf
(
apiMap
.
get
(
"name"
))))
{
List
<
String
>
serverList
=
(
List
<
String
>)
apiMap
.
get
(
"server"
);
if
(
serverList
.
get
(
0
).
startsWith
(
"172"
))
{
qqApiNginx
=
"aws"
;
if
(
StringUtils
.
equals
(
"grayapigateway"
,
String
.
valueOf
(
apiMap
.
get
(
"name"
))))
{
List
<
String
>
serverList
=
(
List
<
String
>)
apiMap
.
get
(
"server"
);
if
(
serverList
.
get
(
0
).
startsWith
(
"10"
))
{
awsGrayNginx
=
"qq"
;
}
}
}
if
(
StringUtils
.
equals
(
"grayapigateway"
,
String
.
valueOf
(
apiMap
.
get
(
"name"
))))
{
List
<
String
>
serverList
=
(
List
<
String
>)
apiMap
.
get
(
"server"
);
if
(
serverList
.
get
(
0
).
startsWith
(
"172"
))
{
qqApiNginx
=
"aws"
;
for
(
Map
<
String
,
Object
>
apiMap
:
qcloudList
)
{
if
(
StringUtils
.
equals
(
"apigateway"
,
String
.
valueOf
(
apiMap
.
get
(
"name"
))))
{
List
<
String
>
serverList
=
(
List
<
String
>)
apiMap
.
get
(
"server"
);
if
(
serverList
.
get
(
0
).
startsWith
(
"172"
))
{
qqApiNginx
=
"aws"
;
}
}
}
}
//dns
String
defaultDns
=
"aws"
;
String
qqDns
=
"qq"
;
if
(
StringUtils
.
equals
(
"grayapigateway"
,
String
.
valueOf
(
apiMap
.
get
(
"name"
))))
{
List
<
String
>
serverList
=
(
List
<
String
>)
apiMap
.
get
(
"server"
);
if
(
serverList
.
get
(
0
).
startsWith
(
"172"
))
{
qqApiNginx
=
"aws"
;
}
}
}
MultiValueMap
<
String
,
String
>
requestEntity
=
new
LinkedMultiValueMap
<>();
requestEntity
.
add
(
"login_token"
,
"14365,5ced8b63875ed1643b9ffeb285180fa9"
);
requestEntity
.
add
(
"format"
,
"json"
);
requestEntity
.
add
(
"domain_id"
,
"16862974"
);
//requestEntity.add("record_id","183941138");
requestEntity
.
add
(
"record_id"
,
"293178513"
);
//dns
String
defaultDns
=
""
;
MultiValueMap
<
String
,
String
>
requestEntity
=
new
LinkedMultiValueMap
<>();
requestEntity
.
add
(
"login_token"
,
"31578,5f5402160468dc375159e2e94eeef1da"
);
requestEntity
.
add
(
"format"
,
"json"
);
requestEntity
.
add
(
"domain_id"
,
"16862974"
);
requestEntity
.
add
(
"record_id"
,
"293178513"
);
try
{
String
requestResponse
=
httpRestClient
.
post
(
"https://dnsapi.cn/Record.Info"
,
requestEntity
,
String
.
class
);
JSONObject
responseJSON
=
JSONObject
.
parseObject
(
requestResponse
);
JSONObject
responseStatus
=
JSONObject
.
parseObject
(
responseJSON
.
getString
(
"status"
));
if
(
"1"
.
equals
(
responseStatus
.
getString
(
"code"
))){
if
(
requestResponse
.
indexOf
(
"amazonaws"
)
==
-
1
){
defaultDns
=
"qq"
;
}
else
{
defaultDns
=
"aws"
;
}
}
else
{
logger
.
error
(
" TopoSwitchCtrl - getNgixnStatus - JSON - err:"
+
responseJSON
.
getString
(
"message"
));
}
}
catch
(
Exception
e
){
logger
.
error
(
" TopoSwitchCtrl - getNgixnStatus - https://dnsapi.cn/Record.Info - err"
,
e
);
}
String
requestResponse
=
httpRestClient
.
post
(
"https://dnsapi.cn/Record.Info"
,
requestEntity
,
String
.
class
);
if
(
requestResponse
.
indexOf
(
"amazonaws"
)
==
-
1
){
defaultDns
=
"qq"
;
resultMap
.
put
(
"luaType"
,
luaType
);
resultMap
.
put
(
"awsApiNginx"
,
awsApiNginx
);
resultMap
.
put
(
"awsGrayNginx"
,
awsGrayNginx
);
resultMap
.
put
(
"qqApiNginx"
,
qqApiNginx
);
resultMap
.
put
(
"qqGrayNginx"
,
qqGrayNginx
);
resultMap
.
put
(
"defaultDns"
,
defaultDns
);
}
catch
(
Exception
e
){
logger
.
error
(
" TopoSwitchCtrl - getNgixnStatus - err"
,
e
);
}
// requestEntity.add("record_id","188034065");
// String request2Response = httpRestClient.post("https://dnsapi.cn/Record.Info", requestEntity, String.class);
// if (request2Response.indexOf("amazonaws") != -1){
// qqDns = "aws";
// }
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<>();
resultMap
.
put
(
"luaType"
,
luaType
);
resultMap
.
put
(
"awsApiNginx"
,
awsApiNginx
);
resultMap
.
put
(
"awsGrayNginx"
,
awsGrayNginx
);
resultMap
.
put
(
"qqApiNginx"
,
qqApiNginx
);
resultMap
.
put
(
"qqGrayNginx"
,
qqGrayNginx
);
resultMap
.
put
(
"defaultDns"
,
defaultDns
);
// resultMap.put("qqDns", qqDns);
return
new
BaseResponse
(
resultMap
);
return
new
BaseResponse
(
resultMap
);
}
}
}
\ No newline at end of file
...
...
monitor-ui-web/src/main/webapp/script/switch.js
View file @
791972a
...
...
@@ -12,7 +12,7 @@ function drawData(resp) {
var
canvas
=
document
.
getElementById
(
'canvas'
);
var
stage
=
new
JTopo
.
Stage
(
canvas
);
//显示工具栏
showJTopoToobar
(
stage
);
//
showJTopoToobar(stage);
var
scene
=
new
JTopo
.
Scene
();
stage
.
add
(
scene
);
scene
.
background
=
contextPath
+
"img/bg.jpg"
;
...
...
@@ -66,7 +66,7 @@ function drawData(resp) {
}
else
if
(
'qq'
==
data
.
luaType
){
//app全部直连到qq
var
link
=
newLink
(
scene
,
appNode
,
qqElb
,
'直连'
);
link
.
arrowsRadius
=
10
;
}
else
{
//app分散直连
}
else
if
(
'aws+qq'
==
data
.
luaType
)
{
//app分散直连
var
link
=
newLink
(
scene
,
appNode
,
awsElb
,
'直连'
);
link
.
arrowsRadius
=
10
;
var
link
=
newLink
(
scene
,
appNode
,
qqElb
,
'直连'
);
...
...
@@ -108,18 +108,11 @@ function drawData(resp) {
if
(
'aws'
==
data
.
defaultDns
){
var
link
=
newFoldLink
(
scene
,
appNode
,
awsElb
,
'dns'
,
''
,
5
);
link
.
arrowsRadius
=
10
;
}
else
{
}
else
if
(
'qq'
==
data
.
defaultDns
)
{
var
link
=
newFoldLink
(
scene
,
appNode
,
qqElb
,
'dns'
,
''
,
5
);
link
.
arrowsRadius
=
10
;
}
//if('aws' == data.qqDns){
// var link = newFoldLink(scene,appNode, awsElb, 'otherDns','',5);
// link.arrowsRadius = 10;
//}else{
// var link = newFoldLink(scene,appNode, qqElb, 'otherDns','',5);
// link.arrowsRadius = 10;
//}
//创建lua切换按钮
createLuaSwitchButton
(
data
.
luaType
);
...
...
@@ -130,6 +123,9 @@ function drawData(resp) {
* @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>"
;
...
...
Please
register
or
login
to post a comment