Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
e962149a
Commit
e962149a
authored
Jul 28, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改测试用例
parent
4a09d1a8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
19 deletions
+22
-19
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/extension/MyDiscoveryEnabledAdapter.java
+4
-1
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/extension/MyDiscoveryEnabledAdapter.java
+15
-16
discovery-springcloud-example-zuul/src/main/java/com/nepxion/discovery/plugin/example/zuul/extension/MyDiscoveryEnabledAdapter.java
+3
-2
No files found.
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/extension/MyDiscoveryEnabledAdapter.java
View file @
e962149a
...
...
@@ -41,7 +41,10 @@ public class MyDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
LOG
.
info
(
"Gateway端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, context={}"
,
serviceId
,
server
.
toString
(),
metadata
,
context
);
if
(
StringUtils
.
equals
(
token
,
"abc"
))
{
String
filterToken
=
"abc"
;
if
(
StringUtils
.
isNotEmpty
(
token
)
&&
token
.
contains
(
filterToken
))
{
LOG
.
info
(
"过滤条件:当Token含有'{}'的时候,不能被Ribbon负载均衡到"
,
filterToken
);
return
false
;
}
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/extension/MyDiscoveryEnabledAdapter.java
View file @
e962149a
...
...
@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.strategy.discovery.DiscoveryEnabledAdapter
;
import
com.nepxion.discovery.plugin.strategy.extension.service.constant.ServiceStrategyConstant
;
import
com.nepxion.discovery.plugin.strategy.extension.service.context.ServiceStrategyContext
;
...
...
@@ -33,29 +34,28 @@ public class MyDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
public
boolean
apply
(
Server
server
)
{
ServiceStrategyContext
context
=
ServiceStrategyContext
.
getCurrentContext
();
Map
<
String
,
Object
>
attributes
=
context
.
getAttributes
();
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
();
Map
<
String
,
String
>
metadata
=
pluginAdapter
.
getServerMetadata
(
server
);
String
version
=
metadata
.
get
(
PluginConstant
.
VERSION
);
LOG
.
info
(
"Serivice端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, context={}"
,
serviceId
,
server
.
toString
(),
metadata
,
context
);
if
(
attributes
.
containsKey
(
ServiceStrategyConstant
.
PARAMETER_MAP
))
{
Map
<
String
,
Object
>
parameterMap
=
(
Map
<
String
,
Object
>)
attributes
.
get
(
ServiceStrategyConstant
.
PARAMETER_MAP
);
String
value
=
parameterMap
.
get
(
"value"
).
toString
();
if
(
StringUtils
.
isNotEmpty
(
value
)
&&
value
.
contains
(
"abc"
))
{
LOG
.
info
(
"过滤条件:当前端输入值包含'abc'的时候,不能被Ribbon负载均衡到"
);
return
false
;
String
filterServiceId
=
"discovery-springcloud-example-c"
;
String
filterVersion
=
"1.0"
;
String
filterBusinessValue
=
"abc"
;
if
(
StringUtils
.
equals
(
serviceId
,
filterServiceId
)
&&
StringUtils
.
equals
(
version
,
filterVersion
))
{
if
(
attributes
.
containsKey
(
ServiceStrategyConstant
.
PARAMETER_MAP
))
{
Map
<
String
,
Object
>
parameterMap
=
(
Map
<
String
,
Object
>)
attributes
.
get
(
ServiceStrategyConstant
.
PARAMETER_MAP
);
String
value
=
parameterMap
.
get
(
"value"
).
toString
();
if
(
StringUtils
.
isNotEmpty
(
value
)
&&
value
.
contains
(
filterBusinessValue
))
{
LOG
.
info
(
"过滤条件:当serviceId={} && version={} && 业务参数含有'{}'的时候,不能被Ribbon负载均衡到"
,
filterServiceId
,
filterVersion
,
filterBusinessValue
);
return
false
;
}
}
}
/*String version = metadata.get(PluginConstant.VERSION);
if (StringUtils.equals(serviceId, "discovery-springcloud-example-c") && StringUtils.equals(version, "1.0")) {
LOG.info("过滤条件:当serviceId={},version={}的时候,不能被Ribbon负载均衡到", serviceId, version);
return false;
}*/
return
true
;
}
}
\ No newline at end of file
discovery-springcloud-example-zuul/src/main/java/com/nepxion/discovery/plugin/example/zuul/extension/MyDiscoveryEnabledAdapter.java
View file @
e962149a
...
...
@@ -38,8 +38,9 @@ public class MyDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
LOG
.
info
(
"Zuul端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, context={}"
,
serviceId
,
server
.
toString
(),
metadata
,
context
);
if
(
StringUtils
.
isNotEmpty
(
token
)
&&
token
.
contains
(
"abc"
))
{
LOG
.
info
(
"过滤条件:当前端输入值包含'abc'的时候,不能被Ribbon负载均衡到"
);
String
filterToken
=
"abc"
;
if
(
StringUtils
.
isNotEmpty
(
token
)
&&
token
.
contains
(
filterToken
))
{
LOG
.
info
(
"过滤条件:当Token含有'{}'的时候,不能被Ribbon负载均衡到"
,
filterToken
);
return
false
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment