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
e36f6fb3
Commit
e36f6fb3
authored
Aug 06, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加基于随机权重的平滑灰度发布功能
parent
74992ca5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
90 additions
and
35 deletions
+90
-35
discovery-common/pom.xml
+6
-0
discovery-common/src/main/java/com/nepxion/discovery/common/entity/RouterEntity.java
+9
-0
discovery-common/src/main/java/com/nepxion/discovery/common/util/JsonUtil.java
+2
-2
discovery-console-desktop/pom.xml
+0
-5
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
+2
-2
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/workspace/RouterTopology.java
+13
-3
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/RouterEndpoint.java
+58
-23
No files found.
discovery-common/pom.xml
View file @
e36f6fb3
...
@@ -29,5 +29,10 @@
...
@@ -29,5 +29,10 @@
<groupId>
commons-io
</groupId>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<artifactId>
commons-io
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
discovery-common/src/main/java/com/nepxion/discovery/common/entity/RouterEntity.java
View file @
e36f6fb3
...
@@ -25,6 +25,7 @@ public class RouterEntity implements Serializable {
...
@@ -25,6 +25,7 @@ public class RouterEntity implements Serializable {
private
String
version
;
private
String
version
;
private
String
host
;
private
String
host
;
private
int
port
;
private
int
port
;
private
int
weight
=
-
1
;
private
String
contextPath
;
private
String
contextPath
;
private
List
<
RouterEntity
>
nexts
=
new
ArrayList
<
RouterEntity
>();
private
List
<
RouterEntity
>
nexts
=
new
ArrayList
<
RouterEntity
>();
...
@@ -61,6 +62,14 @@ public class RouterEntity implements Serializable {
...
@@ -61,6 +62,14 @@ public class RouterEntity implements Serializable {
this
.
port
=
port
;
this
.
port
=
port
;
}
}
public
int
getWeight
()
{
return
weight
;
}
public
void
setWeight
(
int
weight
)
{
this
.
weight
=
weight
;
}
public
String
getContextPath
()
{
public
String
getContextPath
()
{
return
contextPath
;
return
contextPath
;
}
}
...
...
discovery-co
nsole-desktop/src/main/java/com/nepxion/discovery/console/desktop/serializer/JacksonSerializer
.java
→
discovery-co
mmon/src/main/java/com/nepxion/discovery/common/util/JsonUtil
.java
View file @
e36f6fb3
package
com
.
nepxion
.
discovery
.
co
nsole
.
desktop
.
serializer
;
package
com
.
nepxion
.
discovery
.
co
mmon
.
util
;
/**
/**
* <p>Title: Nepxion Discovery</p>
* <p>Title: Nepxion Discovery</p>
...
@@ -17,7 +17,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
...
@@ -17,7 +17,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
public
class
J
acksonSerializer
{
public
class
J
sonUtil
{
private
static
ObjectMapper
objectMapper
;
private
static
ObjectMapper
objectMapper
;
static
{
static
{
...
...
discovery-console-desktop/pom.xml
View file @
e36f6fb3
...
@@ -50,11 +50,6 @@
...
@@ -50,11 +50,6 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
</dependency>
<dependency>
<groupId>
com.lmax
</groupId>
<groupId>
com.lmax
</groupId>
<artifactId>
disruptor
</artifactId>
<artifactId>
disruptor
</artifactId>
<version>
${disruptor.version}
</version>
<version>
${disruptor.version}
</version>
...
...
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
View file @
e36f6fb3
...
@@ -21,10 +21,10 @@ import org.springframework.web.client.RestTemplate;
...
@@ -21,10 +21,10 @@ import org.springframework.web.client.RestTemplate;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.nepxion.discovery.common.entity.ResultEntity
;
import
com.nepxion.discovery.common.entity.ResultEntity
;
import
com.nepxion.discovery.common.entity.RouterEntity
;
import
com.nepxion.discovery.common.entity.RouterEntity
;
import
com.nepxion.discovery.common.util.JsonUtil
;
import
com.nepxion.discovery.common.util.UrlUtil
;
import
com.nepxion.discovery.common.util.UrlUtil
;
import
com.nepxion.discovery.console.desktop.context.PropertiesContext
;
import
com.nepxion.discovery.console.desktop.context.PropertiesContext
;
import
com.nepxion.discovery.console.desktop.entity.Instance
;
import
com.nepxion.discovery.console.desktop.entity.Instance
;
import
com.nepxion.discovery.console.desktop.serializer.JacksonSerializer
;
public
class
ServiceController
{
public
class
ServiceController
{
public
static
RestTemplate
restTemplate
;
public
static
RestTemplate
restTemplate
;
...
@@ -224,7 +224,7 @@ public class ServiceController {
...
@@ -224,7 +224,7 @@ public class ServiceController {
private
static
<
T
>
T
convert
(
String
result
,
TypeReference
<
T
>
typeReference
)
{
private
static
<
T
>
T
convert
(
String
result
,
TypeReference
<
T
>
typeReference
)
{
try
{
try
{
return
J
acksonSerializer
.
fromJson
(
result
,
typeReference
);
return
J
sonUtil
.
fromJson
(
result
,
typeReference
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
ServiceErrorHandler
errorHandler
=
(
ServiceErrorHandler
)
restTemplate
.
getErrorHandler
();
ServiceErrorHandler
errorHandler
=
(
ServiceErrorHandler
)
restTemplate
.
getErrorHandler
();
result
=
errorHandler
.
getCause
();
result
=
errorHandler
.
getCause
();
...
...
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/workspace/RouterTopology.java
View file @
e36f6fb3
...
@@ -142,10 +142,12 @@ public class RouterTopology extends AbstractTopology {
...
@@ -142,10 +142,12 @@ public class RouterTopology extends AbstractTopology {
typeComboBox
.
setSelectedIndex
(
2
);
typeComboBox
.
setSelectedIndex
(
2
);
JPanel
childPanel2
=
(
JPanel
)
layoutPanel
.
getComponent
(
1
);
JPanel
childPanel2
=
(
JPanel
)
layoutPanel
.
getComponent
(
1
);
JSlider
yOffsetSlider
=
(
JSlider
)
childPanel2
.
getComponent
(
11
);
yOffsetSlider
.
setValue
(
0
);
JSlider
xGapSlider
=
(
JSlider
)
childPanel2
.
getComponent
(
13
);
JSlider
xGapSlider
=
(
JSlider
)
childPanel2
.
getComponent
(
13
);
xGapSlider
.
setValue
(
200
);
xGapSlider
.
setValue
(
200
);
JSlider
yGapSlider
=
(
JSlider
)
childPanel2
.
getComponent
(
15
);
JSlider
yGapSlider
=
(
JSlider
)
childPanel2
.
getComponent
(
15
);
yGapSlider
.
setValue
(
1
0
0
);
yGapSlider
.
setValue
(
1
5
0
);
JPanel
childPanel3
=
(
JPanel
)
layoutPanel
.
getComponent
(
2
);
JPanel
childPanel3
=
(
JPanel
)
layoutPanel
.
getComponent
(
2
);
JBasicButton
runButton
=
(
JBasicButton
)
childPanel3
.
getComponent
(
1
);
JBasicButton
runButton
=
(
JBasicButton
)
childPanel3
.
getComponent
(
1
);
...
@@ -184,7 +186,7 @@ public class RouterTopology extends AbstractTopology {
...
@@ -184,7 +186,7 @@ public class RouterTopology extends AbstractTopology {
index
++;
index
++;
}
}
addLink
(
node
,
nextNode
);
addLink
(
node
,
nextNode
,
next
);
route
(
next
,
nextNode
,
index
);
route
(
next
,
nextNode
,
index
);
}
}
...
@@ -215,9 +217,17 @@ public class RouterTopology extends AbstractTopology {
...
@@ -215,9 +217,17 @@ public class RouterTopology extends AbstractTopology {
return
node
;
return
node
;
}
}
private
void
addLink
(
TNode
fromNode
,
TNode
toNode
)
{
private
void
addLink
(
TNode
fromNode
,
TNode
toNode
,
RouterEntity
routerEntity
)
{
int
weight
=
routerEntity
.
getWeight
();
TLink
link
=
createLink
(
fromNode
,
toNode
,
true
);
TLink
link
=
createLink
(
fromNode
,
toNode
,
true
);
link
.
putLinkToArrowColor
(
Color
.
yellow
);
link
.
putLinkToArrowColor
(
Color
.
yellow
);
if
(
weight
>
-
1
)
{
link
.
setName
(
"weight="
+
weight
);
link
.
putLinkFlowing
(
true
);
link
.
putLinkFlowingColor
(
new
Color
(
255
,
155
,
85
));
link
.
putLinkFlowingWidth
(
3
);
}
dataBox
.
addElement
(
link
);
dataBox
.
addElement
(
link
);
}
}
...
...
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/RouterEndpoint.java
View file @
e36f6fb3
...
@@ -19,6 +19,7 @@ import java.util.List;
...
@@ -19,6 +19,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.MapUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint
;
import
org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint
;
...
@@ -35,9 +36,15 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -35,9 +36,15 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.entity.DiscoveryEntity
;
import
com.nepxion.discovery.common.entity.RouterEntity
;
import
com.nepxion.discovery.common.entity.RouterEntity
;
import
com.nepxion.discovery.common.entity.RuleEntity
;
import
com.nepxion.discovery.common.entity.WeightEntity
;
import
com.nepxion.discovery.common.entity.WeightFilterEntity
;
import
com.nepxion.discovery.common.exception.DiscoveryException
;
import
com.nepxion.discovery.common.exception.DiscoveryException
;
import
com.nepxion.discovery.common.util.JsonUtil
;
import
com.nepxion.discovery.common.util.UrlUtil
;
import
com.nepxion.discovery.common.util.UrlUtil
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
...
@@ -149,6 +156,7 @@ public class RouterEndpoint {
...
@@ -149,6 +156,7 @@ public class RouterEndpoint {
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
String
host
=
instance
.
getHost
();
String
host
=
instance
.
getHost
();
int
port
=
instance
.
getPort
();
int
port
=
instance
.
getPort
();
int
weight
=
getWeight
(
routeServiceId
,
version
);
String
contextPath
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
String
contextPath
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
RouterEntity
routerEntity
=
new
RouterEntity
();
RouterEntity
routerEntity
=
new
RouterEntity
();
...
@@ -156,6 +164,7 @@ public class RouterEndpoint {
...
@@ -156,6 +164,7 @@ public class RouterEndpoint {
routerEntity
.
setVersion
(
version
);
routerEntity
.
setVersion
(
version
);
routerEntity
.
setHost
(
host
);
routerEntity
.
setHost
(
host
);
routerEntity
.
setPort
(
port
);
routerEntity
.
setPort
(
port
);
routerEntity
.
setWeight
(
weight
);
routerEntity
.
setContextPath
(
contextPath
);
routerEntity
.
setContextPath
(
contextPath
);
routerEntityList
.
add
(
routerEntity
);
routerEntityList
.
add
(
routerEntity
);
...
@@ -164,39 +173,22 @@ public class RouterEndpoint {
...
@@ -164,39 +173,22 @@ public class RouterEndpoint {
return
routerEntityList
;
return
routerEntityList
;
}
}
@SuppressWarnings
(
"unchecked"
)
public
List
<
RouterEntity
>
getRouterEntityList
(
String
routeServiceId
,
String
routeHost
,
int
routePort
,
String
routeContextPath
)
{
public
List
<
RouterEntity
>
getRouterEntityList
(
String
routeServiceId
,
String
routeHost
,
int
routePort
,
String
routeContextPath
)
{
String
url
=
"http://"
+
routeHost
+
":"
+
routePort
+
UrlUtil
.
formatContextPath
(
routeContextPath
)
+
"router/
instances
/"
+
routeServiceId
;
String
url
=
"http://"
+
routeHost
+
":"
+
routePort
+
UrlUtil
.
formatContextPath
(
routeContextPath
)
+
"router/
route
/"
+
routeServiceId
;
List
<
Map
<
String
,
?>>
instanceLis
t
=
null
;
String
resul
t
=
null
;
try
{
try
{
instanceList
=
routerRestTemplate
.
getForEntity
(
url
,
List
.
class
).
getBody
();
result
=
routerRestTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
}
catch
(
RestClientException
e
)
{
}
catch
(
RestClientException
e
)
{
throw
new
DiscoveryException
(
"Get instance list for route serviceId="
+
routeServiceId
+
" with url="
+
url
+
" failed"
,
e
);
throw
new
DiscoveryException
(
"Get instance list for route serviceId="
+
routeServiceId
+
" with url="
+
url
+
" failed"
,
e
);
}
}
if
(
CollectionUtils
.
isEmpty
(
instanceLis
t
))
{
if
(
StringUtils
.
isEmpty
(
resul
t
))
{
return
null
;
return
null
;
}
}
List
<
RouterEntity
>
routerEntityList
=
new
ArrayList
<
RouterEntity
>();
List
<
RouterEntity
>
routerEntityList
=
JsonUtil
.
fromJson
(
result
,
new
TypeReference
<
List
<
RouterEntity
>>()
{
for
(
Map
<
String
,
?>
instance
:
instanceList
)
{
});
Map
<
String
,
String
>
metadata
=
(
Map
<
String
,
String
>)
instance
.
get
(
DiscoveryConstant
.
METADATA
);
String
serviceId
=
instance
.
get
(
DiscoveryConstant
.
SERVICE_ID
).
toString
().
toLowerCase
();
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
String
host
=
instance
.
get
(
DiscoveryConstant
.
HOST
).
toString
();
Integer
port
=
(
Integer
)
instance
.
get
(
DiscoveryConstant
.
PORT
);
String
contextPath
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
RouterEntity
routerEntity
=
new
RouterEntity
();
routerEntity
.
setServiceId
(
serviceId
);
routerEntity
.
setVersion
(
version
);
routerEntity
.
setHost
(
host
);
routerEntity
.
setPort
(
port
);
routerEntity
.
setContextPath
(
contextPath
);
routerEntityList
.
add
(
routerEntity
);
}
return
routerEntityList
;
return
routerEntityList
;
}
}
...
@@ -266,4 +258,46 @@ public class RouterEndpoint {
...
@@ -266,4 +258,46 @@ public class RouterEndpoint {
return
routerEntityList
;
return
routerEntityList
;
}
}
private
int
getWeight
(
String
providerServiceId
,
String
providerVersion
)
{
RuleEntity
ruleEntity
=
pluginAdapter
.
getRule
();
if
(
ruleEntity
==
null
)
{
return
-
1
;
}
DiscoveryEntity
discoveryEntity
=
ruleEntity
.
getDiscoveryEntity
();
if
(
discoveryEntity
==
null
)
{
return
-
1
;
}
WeightFilterEntity
weightFilterEntity
=
discoveryEntity
.
getWeightFilterEntity
();
if
(
weightFilterEntity
==
null
)
{
return
-
1
;
}
Map
<
String
,
List
<
WeightEntity
>>
weightEntityMap
=
weightFilterEntity
.
getWeightEntityMap
();
if
(
MapUtils
.
isEmpty
(
weightEntityMap
))
{
return
-
1
;
}
String
serviceId
=
pluginAdapter
.
getServiceId
();
List
<
WeightEntity
>
weightEntityList
=
weightEntityMap
.
get
(
serviceId
);
if
(
CollectionUtils
.
isEmpty
(
weightEntityList
))
{
return
-
1
;
}
for
(
WeightEntity
weightEntity
:
weightEntityList
)
{
String
providerServiceName
=
weightEntity
.
getProviderServiceName
();
if
(
StringUtils
.
equalsIgnoreCase
(
providerServiceName
,
providerServiceId
))
{
Map
<
String
,
Integer
>
weightMap
=
weightEntity
.
getWeightMap
();
Integer
weight
=
weightMap
.
get
(
providerVersion
);
if
(
weight
!=
null
)
{
return
weight
;
}
}
}
return
-
1
;
}
}
}
\ 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