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
acbf93e3
Commit
acbf93e3
authored
Aug 25, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加Zone路由功能
parent
872bc230
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
8 deletions
+62
-8
discovery-common/src/main/java/com/nepxion/discovery/common/constant/DiscoveryConstant.java
+1
-0
discovery-plugin-strategy-extension-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/extension/gateway/adapter/DefaultDiscoveryEnabledAdapter.java
+9
-1
discovery-plugin-strategy-extension-service/src/main/java/com/nepxion/discovery/plugin/strategy/extension/service/adapter/DefaultDiscoveryEnabledAdapter.java
+12
-1
discovery-plugin-strategy-extension-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/extension/zuul/adapter/DefaultDiscoveryEnabledAdapter.java
+9
-1
discovery-plugin-strategy/src/main/java/com/nepxion/discovery/plugin/strategy/adapter/AbstractDiscoveryEnabledAdapter.java
+31
-5
No files found.
discovery-common/src/main/java/com/nepxion/discovery/common/constant/DiscoveryConstant.java
View file @
acbf93e3
...
@@ -21,6 +21,7 @@ public class DiscoveryConstant {
...
@@ -21,6 +21,7 @@ public class DiscoveryConstant {
public
static
final
String
SPRING_APPLICATION_NAME
=
"spring.application.name"
;
public
static
final
String
SPRING_APPLICATION_NAME
=
"spring.application.name"
;
public
static
final
String
GROUP
=
"group"
;
public
static
final
String
GROUP
=
"group"
;
public
static
final
String
ZONE
=
"zone"
;
public
static
final
String
SERVICE_ID
=
"serviceId"
;
public
static
final
String
SERVICE_ID
=
"serviceId"
;
public
static
final
String
HOST
=
"host"
;
public
static
final
String
HOST
=
"host"
;
public
static
final
String
PORT
=
"port"
;
public
static
final
String
PORT
=
"port"
;
...
...
discovery-plugin-strategy-extension-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/extension/gateway/adapter/DefaultDiscoveryEnabledAdapter.java
View file @
acbf93e3
...
@@ -15,9 +15,16 @@ import com.nepxion.discovery.plugin.strategy.extension.gateway.context.GatewaySt
...
@@ -15,9 +15,16 @@ import com.nepxion.discovery.plugin.strategy.extension.gateway.context.GatewaySt
public
class
DefaultDiscoveryEnabledAdapter
extends
AbstractDiscoveryEnabledAdapter
{
public
class
DefaultDiscoveryEnabledAdapter
extends
AbstractDiscoveryEnabledAdapter
{
@Override
@Override
protected
String
getVersion
Json
()
{
protected
String
getVersion
Value
()
{
GatewayStrategyContext
context
=
GatewayStrategyContext
.
getCurrentContext
();
GatewayStrategyContext
context
=
GatewayStrategyContext
.
getCurrentContext
();
return
context
.
getExchange
().
getRequest
().
getHeaders
().
getFirst
(
DiscoveryConstant
.
VERSION
);
return
context
.
getExchange
().
getRequest
().
getHeaders
().
getFirst
(
DiscoveryConstant
.
VERSION
);
}
}
@Override
protected
String
getZoneValue
()
{
GatewayStrategyContext
context
=
GatewayStrategyContext
.
getCurrentContext
();
return
context
.
getExchange
().
getRequest
().
getHeaders
().
getFirst
(
DiscoveryConstant
.
ZONE
);
}
}
}
\ No newline at end of file
discovery-plugin-strategy-extension-service/src/main/java/com/nepxion/discovery/plugin/strategy/extension/service/adapter/DefaultDiscoveryEnabledAdapter.java
View file @
acbf93e3
...
@@ -17,7 +17,7 @@ import com.nepxion.discovery.plugin.strategy.adapter.AbstractDiscoveryEnabledAda
...
@@ -17,7 +17,7 @@ import com.nepxion.discovery.plugin.strategy.adapter.AbstractDiscoveryEnabledAda
public
class
DefaultDiscoveryEnabledAdapter
extends
AbstractDiscoveryEnabledAdapter
{
public
class
DefaultDiscoveryEnabledAdapter
extends
AbstractDiscoveryEnabledAdapter
{
@Override
@Override
protected
String
getVersion
Json
()
{
protected
String
getVersion
Value
()
{
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
if
(
attributes
==
null
)
{
if
(
attributes
==
null
)
{
return
null
;
return
null
;
...
@@ -25,4 +25,14 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
...
@@ -25,4 +25,14 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
return
attributes
.
getRequest
().
getHeader
(
DiscoveryConstant
.
VERSION
);
return
attributes
.
getRequest
().
getHeader
(
DiscoveryConstant
.
VERSION
);
}
}
@Override
protected
String
getZoneValue
()
{
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
if
(
attributes
==
null
)
{
return
null
;
}
return
attributes
.
getRequest
().
getHeader
(
DiscoveryConstant
.
ZONE
);
}
}
}
\ No newline at end of file
discovery-plugin-strategy-extension-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/extension/zuul/adapter/DefaultDiscoveryEnabledAdapter.java
View file @
acbf93e3
...
@@ -15,9 +15,16 @@ import com.netflix.zuul.context.RequestContext;
...
@@ -15,9 +15,16 @@ import com.netflix.zuul.context.RequestContext;
public
class
DefaultDiscoveryEnabledAdapter
extends
AbstractDiscoveryEnabledAdapter
{
public
class
DefaultDiscoveryEnabledAdapter
extends
AbstractDiscoveryEnabledAdapter
{
@Override
@Override
protected
String
getVersion
Json
()
{
protected
String
getVersion
Value
()
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
RequestContext
context
=
RequestContext
.
getCurrentContext
();
return
context
.
getRequest
().
getHeader
(
DiscoveryConstant
.
VERSION
);
return
context
.
getRequest
().
getHeader
(
DiscoveryConstant
.
VERSION
);
}
}
@Override
protected
String
getZoneValue
()
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
return
context
.
getRequest
().
getHeader
(
DiscoveryConstant
.
ZONE
);
}
}
}
\ No newline at end of file
discovery-plugin-strategy/src/main/java/com/nepxion/discovery/plugin/strategy/adapter/AbstractDiscoveryEnabledAdapter.java
View file @
acbf93e3
...
@@ -29,23 +29,28 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
...
@@ -29,23 +29,28 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
return
false
;
return
false
;
}
}
enabled
=
applyZone
(
server
,
metadata
);
if
(!
enabled
)
{
return
false
;
}
return
applyStrategy
(
server
,
metadata
);
return
applyStrategy
(
server
,
metadata
);
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
private
boolean
applyVersion
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
private
boolean
applyVersion
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
String
version
Json
=
getVersionJson
();
String
version
Value
=
getVersionValue
();
if
(
StringUtils
.
isEmpty
(
version
Json
))
{
if
(
StringUtils
.
isEmpty
(
version
Value
))
{
return
true
;
return
true
;
}
}
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
();
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
();
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
if
(
StringUtils
.
isEmpty
(
version
))
{
if
(
StringUtils
.
isEmpty
(
version
))
{
return
tru
e
;
return
fals
e
;
}
}
Map
<
String
,
String
>
versionMap
=
JsonUtil
.
fromJson
(
version
Json
,
Map
.
class
);
Map
<
String
,
String
>
versionMap
=
JsonUtil
.
fromJson
(
version
Value
,
Map
.
class
);
String
versions
=
versionMap
.
get
(
serviceId
);
String
versions
=
versionMap
.
get
(
serviceId
);
if
(
versions
==
null
)
{
if
(
versions
==
null
)
{
return
true
;
return
true
;
...
@@ -58,6 +63,24 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
...
@@ -58,6 +63,24 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
return
false
;
return
false
;
}
}
private
boolean
applyZone
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
String
zoneValue
=
getZoneValue
();
if
(
StringUtils
.
isEmpty
(
zoneValue
))
{
return
true
;
}
String
zone
=
metadata
.
get
(
DiscoveryConstant
.
ZONE
);
if
(
StringUtils
.
isEmpty
(
zone
))
{
return
false
;
}
if
(
StringUtils
.
equals
(
zoneValue
,
zone
))
{
return
true
;
}
return
false
;
}
private
boolean
applyStrategy
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
private
boolean
applyStrategy
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
if
(
discoveryEnabledStrategy
==
null
)
{
if
(
discoveryEnabledStrategy
==
null
)
{
return
true
;
return
true
;
...
@@ -66,5 +89,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
...
@@ -66,5 +89,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
return
discoveryEnabledStrategy
.
apply
(
server
,
metadata
);
return
discoveryEnabledStrategy
.
apply
(
server
,
metadata
);
}
}
protected
abstract
String
getVersionJson
();
protected
abstract
String
getVersionValue
();
protected
abstract
String
getZoneValue
();
}
}
\ No newline at end of file
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