Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
monitor-service
·
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
qinchao
7 years ago
Commit
07e1edc48fa34cbe1474fcc29b5f9c212a3e7a99
1 parent
ff5f53e2
内部负载均衡器切换增加了single
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
26 deletions
monitor-service-switch/src/main/java/com/monitor/switchs/NginxSwitchCtrl.java
monitor-service-switch/src/main/java/com/monitor/switchs/NginxSwitchCtrl.java
View file @
07e1edc
...
...
@@ -69,13 +69,13 @@ public class NginxSwitchCtrl {
if
(
lbList
==
null
||
lbList
.
size
()<=
0
){
return
new
BaseResponse
(
201
,
"源lb为空,请检测参数:"
+
cloudName
);
}
Map
<
String
,
String
>
innerListenerMap
=
getLbListerner
(
true
);
Map
<
String
,
String
>
outerListenerMap
=
getLbListerner
(
false
);
Map
<
String
,
List
<
String
>>
innerListenerMap
=
getLbListerner
(
true
);
Map
<
String
,
List
<
String
>>
outerListenerMap
=
getLbListerner
(
false
);
for
(
LbModel
lb:
lbList
){
if
(
lb
.
isClbFlag
()){
switchClb
(
targetMap
,
lb
);
}
else
{
Map
<
String
,
String
>
listenerMap
=
outerListenerMap
;
Map
<
String
,
List
<
String
>
>
listenerMap
=
outerListenerMap
;
if
(
lb
.
isInnerFlag
())
{
listenerMap
=
innerListenerMap
;
}
...
...
@@ -90,7 +90,7 @@ public class NginxSwitchCtrl {
*
* 切换alb
*/
private
BaseResponse
switchAlb
(
Map
<
String
,
String
>
listenerMap
,
Map
<
String
,
Integer
>
targetMap
,
LbModel
lb
){
private
BaseResponse
switchAlb
(
Map
<
String
,
List
<
String
>
>
listenerMap
,
Map
<
String
,
Integer
>
targetMap
,
LbModel
lb
){
QcloudForwardLbModel
forwardLbModel
=
getAlbFromQcloud
(
lb
);
if
(
forwardLbModel
==
null
)
{
...
...
@@ -102,32 +102,35 @@ public class NginxSwitchCtrl {
String
[]
protoAndPortArray
=
protoTypeAndPort
.
split
(
","
);
String
protocolType
=
protoAndPortArray
[
0
];
int
port
=
Integer
.
parseInt
(
protoAndPortArray
[
1
]);
String
domain
=
listenerMap
.
get
(
protoTypeAndPort
);
List
<
String
>
domainList
=
listenerMap
.
get
(
protoTypeAndPort
);
List
<
String
>
locationIdList
=
new
ArrayList
<>();
for
(
QcloudForwardLbModelData
data
:
forwardLbModel
.
getData
())
{
if
(
StringUtils
.
equals
(
protocolType
,
data
.
getProtocolType
())
&&
port
==
data
.
getLoadBalancerPort
())
{
String
listenerId
=
data
.
getListenerId
();
albModelClass
.
setListenerId
(
listenerId
);
for
(
QcloudForwardLbModelDataRule
rule
:
data
.
getRules
())
{
if
(
StringUtils
.
equals
(
domain
,
rule
.
getDomain
()))
{
if
(
domainList
.
contains
(
rule
.
getDomain
()))
{
locationIdList
.
add
(
rule
.
getLocationId
());
List
<
List
<
QcloudLbModelBackend
>>
ls
=
getNeedChangedWei
(
rule
.
getBackends
(),
targetMap
);
List
<
QcloudLbModelBackend
>
needAddWeight
=
ls
.
get
(
0
);
List
<
QcloudLbModelBackend
>
needRemoveWeight
=
ls
.
get
(
1
);
if
(
domainList
.
get
(
0
).
equals
(
rule
.
getDomain
())){
List
<
List
<
QcloudLbModelBackend
>>
ls
=
getNeedChangedWei
(
rule
.
getBackends
(),
targetMap
);
List
<
QcloudLbModelBackend
>
needAddWeight
=
ls
.
get
(
0
);
List
<
QcloudLbModelBackend
>
needRemoveWeight
=
ls
.
get
(
1
);
albModelClass
.
setListenerId
(
listenerId
);
albModelClass
.
setLocationIdList
(
locationIdList
);
albModelClass
.
setNeedAddWeight
(
needAddWeight
);
albModelClass
.
setNeedRemoveWeight
(
needRemoveWeight
);
dealAlb
.
add
(
albModelClass
);
albModelClass
.
setNeedAddWeight
(
needAddWeight
);
albModelClass
.
setNeedRemoveWeight
(
needRemoveWeight
);
}
}
}
albModelClass
.
setLocationIdList
(
locationIdList
);
dealAlb
.
add
(
albModelClass
);
}
}
}
logger
.
info
(
" switchAlb with {}"
,
dealAlb
);
for
(
AlbModelClass
albModelClass
:
dealAlb
)
{
//操作weight,
List
<
QcloudLbModelBackend
>
needAddWeight
=
albModelClass
.
getNeedAddWeight
();
...
...
@@ -388,8 +391,8 @@ public class NginxSwitchCtrl {
Set
<
String
>
java_nginx_az1
=
new
HashSet
<>();
Set
<
String
>
java_nginx_az2
=
new
HashSet
<>();
Set
<
String
>
java_nginx_az3
=
new
HashSet
<>();
Map
<
String
,
String
>
innerListenerMap
=
getLbListerner
(
true
);
Map
<
String
,
String
>
outerListenerMap
=
getLbListerner
(
false
);
Map
<
String
,
List
<
String
>>
innerListenerMap
=
getLbListerner
(
true
);
Map
<
String
,
List
<
String
>>
outerListenerMap
=
getLbListerner
(
false
);
for
(
LbModel
lb:
lbList
){
if
(
lb
.
isClbFlag
()){
...
...
@@ -407,7 +410,7 @@ public class NginxSwitchCtrl {
return
new
BaseResponse
(
201
,
"请求lb信息error,lb:"
+
lb
.
getLbId
());
}
Map
<
String
,
String
>
listenerMap
=
outerListenerMap
;
Map
<
String
,
List
<
String
>
>
listenerMap
=
outerListenerMap
;
if
(
lb
.
isInnerFlag
()){
listenerMap
=
innerListenerMap
;
}
...
...
@@ -418,13 +421,30 @@ public class NginxSwitchCtrl {
String
protocolType
=
protoAndPortArray
[
0
];
int
port
=
Integer
.
parseInt
(
protoAndPortArray
[
1
]);
String
domain
=
listenerMap
.
get
(
protoTypeAndPort
);
List
<
String
>
domainList
=
listenerMap
.
get
(
protoTypeAndPort
);
for
(
QcloudForwardLbModelData
data:
tmp
.
getData
()){
if
(
StringUtils
.
equals
(
protocolType
,
data
.
getProtocolType
())&&
port
==
data
.
getLoadBalancerPort
()){
for
(
QcloudForwardLbModelDataRule
rule:
data
.
getRules
()){
if
(
StringUtils
.
equals
(
domain
,
rule
.
getDomain
())){
addJavaNgingList
(
rule
.
getBackends
(),
ipInWeight
,
java_nginx_az1
,
java_nginx_az2
,
java_nginx_az3
);
if
(
domainList
.
contains
(
rule
.
getDomain
()))
{
if
(
domainList
.
get
(
0
).
equals
(
rule
.
getDomain
())){
addJavaNgingList
(
rule
.
getBackends
(),
ipInWeight
,
java_nginx_az1
,
java_nginx_az2
,
java_nginx_az3
);
}
else
{
/*Map<String,Integer> tmp_ipInWeight=new HashMap<>();
Set<String> tmp_java_nginx_az1=new HashSet<>();
Set<String> tmp_java_nginx_az2=new HashSet<>();
Set<String> tmp_java_nginx_az3=new HashSet<>();
addJavaNgingList(rule.getBackends(),tmp_ipInWeight,tmp_java_nginx_az1,tmp_java_nginx_az2,tmp_java_nginx_az3);
*//*if(!CollectionUtils.isEqualCollection(ipInWeight.keySet(),tmp_ipInWeight.keySet())){
return new BaseResponse(201, "负载均衡domain指定主机数量不一致,lb ->"+lb.getLbId()+":"+protoTypeAndPort+":"+rule.getDomain());
}*//*
System.out.println("tmp_java_nginx_az1 ->" +tmp_java_nginx_az1+" : "+java_nginx_az1);
System.out.println("tmp_java_nginx_az2 ->" +tmp_java_nginx_az2+" : "+java_nginx_az2);
System.out.println("tmp_java_nginx_az3 ->" +tmp_java_nginx_az3+" : "+java_nginx_az3);
System.out.println("tmp_ipInWeight ->" +tmp_ipInWeight+" : "+ipInWeight);*/
}
}
}
}
...
...
@@ -514,13 +534,13 @@ public class NginxSwitchCtrl {
}
}
private
Map
<
String
,
String
>
getLbListerner
(
boolean
innerFlag
){
Map
<
String
,
String
>
lb_domain_port
=
new
HashMap
<>();
private
Map
<
String
,
List
<
String
>>
getLbListerner
(
boolean
innerFlag
){
Map
<
String
,
List
<
String
>>
lb_domain_port
=
new
HashMap
<>();
if
(
innerFlag
){
lb_domain_port
.
put
(
"http,80"
,
"*.yoho.yohoops.org"
);
lb_domain_port
.
put
(
"http,80"
,
Lists
.
newArrayList
(
"*.yoho.yohoops.org"
,
"single.yohoops.org"
)
);
}
else
{
lb_domain_port
.
put
(
"http,80"
,
"*.yoho.cn"
);
lb_domain_port
.
put
(
"https,443"
,
"*.yoho.cn"
);
lb_domain_port
.
put
(
"http,80"
,
Lists
.
newArrayList
(
"*.yoho.cn"
));
lb_domain_port
.
put
(
"https,443"
,
Lists
.
newArrayList
(
"*.yoho.cn"
));
}
return
lb_domain_port
;
}
...
...
Please
register
or
login
to post a comment