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
5012a387
Commit
5012a387
authored
Apr 24, 2019
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加全链路路由的配置中心配置方式
parent
f309179b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
152 additions
and
0 deletions
+152
-0
discovery-common/src/main/java/com/nepxion/discovery/common/entity/RuleEntity.java
+9
-0
discovery-common/src/main/java/com/nepxion/discovery/common/entity/StrategyEntity.java
+65
-0
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/constant/ConfigConstant.java
+2
-0
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/parser/xml/XmlConfigParser.java
+27
-0
discovery-plugin-strategy/src/main/java/com/nepxion/discovery/plugin/strategy/adapter/AbstractDiscoveryEnabledAdapter.java
+36
-0
discovery-springcloud-example-service/src/main/resources/rule.json
+5
-0
discovery-springcloud-example-service/src/main/resources/rule.xml
+8
-0
No files found.
discovery-common/src/main/java/com/nepxion/discovery/common/entity/RuleEntity.java
View file @
5012a387
...
...
@@ -21,6 +21,7 @@ public class RuleEntity implements Serializable {
private
RegisterEntity
registerEntity
;
private
DiscoveryEntity
discoveryEntity
;
private
StrategyEntity
strategyEntity
;
private
CustomizationEntity
customizationEntity
;
private
String
content
;
...
...
@@ -48,6 +49,14 @@ public class RuleEntity implements Serializable {
this
.
customizationEntity
=
customizationEntity
;
}
public
StrategyEntity
getStrategyEntity
()
{
return
strategyEntity
;
}
public
void
setStrategyEntity
(
StrategyEntity
strategyEntity
)
{
this
.
strategyEntity
=
strategyEntity
;
}
public
String
getContent
()
{
return
content
;
}
...
...
discovery-common/src/main/java/com/nepxion/discovery/common/entity/StrategyEntity.java
0 → 100644
View file @
5012a387
package
com
.
nepxion
.
discovery
.
common
.
entity
;
import
java.io.Serializable
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
public
class
StrategyEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
588258474716367451L
;
private
String
versionValue
;
private
String
regionValue
;
private
String
addressValue
;
public
String
getVersionValue
()
{
return
versionValue
;
}
public
void
setVersionValue
(
String
versionValue
)
{
this
.
versionValue
=
versionValue
;
}
public
String
getRegionValue
()
{
return
regionValue
;
}
public
void
setRegionValue
(
String
regionValue
)
{
this
.
regionValue
=
regionValue
;
}
public
String
getAddressValue
()
{
return
addressValue
;
}
public
void
setAddressValue
(
String
addressValue
)
{
this
.
addressValue
=
addressValue
;
}
@Override
public
int
hashCode
()
{
return
HashCodeBuilder
.
reflectionHashCode
(
this
);
}
@Override
public
boolean
equals
(
Object
object
)
{
return
EqualsBuilder
.
reflectionEquals
(
this
,
object
);
}
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
MULTI_LINE_STYLE
);
}
}
\ No newline at end of file
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/constant/ConfigConstant.java
View file @
5012a387
...
...
@@ -13,6 +13,7 @@ public class ConfigConstant {
public
static
final
String
RULE_ELEMENT_NAME
=
"rule"
;
public
static
final
String
REGISTER_ELEMENT_NAME
=
"register"
;
public
static
final
String
DISCOVERY_ELEMENT_NAME
=
"discovery"
;
public
static
final
String
STRATEGY_ELEMENT_NAME
=
"strategy"
;
public
static
final
String
CUSTOMIZATION_ELEMENT_NAME
=
"customization"
;
public
static
final
String
SERVICE_ELEMENT_NAME
=
"service"
;
public
static
final
String
REGION_ELEMENT_NAME
=
"region"
;
...
...
@@ -21,6 +22,7 @@ public class ConfigConstant {
public
static
final
String
COUNT_ELEMENT_NAME
=
"count"
;
public
static
final
String
VERSION_ELEMENT_NAME
=
"version"
;
public
static
final
String
WEIGHT_ELEMENT_NAME
=
"weight"
;
public
static
final
String
ADDRESS_ELEMENT_NAME
=
"address"
;
public
static
final
String
FILTER_VALUE_ATTRIBUTE_NAME
=
"filter-value"
;
public
static
final
String
SERVICE_NAME_ATTRIBUTE_NAME
=
"service-name"
;
public
static
final
String
CONSUMER_SERVICE_NAME_ATTRIBUTE_NAME
=
"consumer-service-name"
;
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/parser/xml/XmlConfigParser.java
View file @
5012a387
...
...
@@ -32,6 +32,7 @@ import com.nepxion.discovery.common.entity.HostFilterEntity;
import
com.nepxion.discovery.common.entity.RegionWeightEntity
;
import
com.nepxion.discovery.common.entity.RegisterEntity
;
import
com.nepxion.discovery.common.entity.RuleEntity
;
import
com.nepxion.discovery.common.entity.StrategyEntity
;
import
com.nepxion.discovery.common.entity.VersionEntity
;
import
com.nepxion.discovery.common.entity.VersionFilterEntity
;
import
com.nepxion.discovery.common.entity.WeightEntity
;
...
...
@@ -83,6 +84,7 @@ public class XmlConfigParser implements PluginConfigParser {
RegisterEntity
registerEntity
=
null
;
DiscoveryEntity
discoveryEntity
=
null
;
StrategyEntity
strategyEntity
=
null
;
CustomizationEntity
customizationEntity
=
null
;
for
(
Iterator
elementIterator
=
element
.
elementIterator
();
elementIterator
.
hasNext
();)
{
Object
childElementObject
=
elementIterator
.
next
();
...
...
@@ -95,6 +97,9 @@ public class XmlConfigParser implements PluginConfigParser {
}
else
if
(
StringUtils
.
equals
(
childElement
.
getName
(),
ConfigConstant
.
DISCOVERY_ELEMENT_NAME
))
{
discoveryEntity
=
new
DiscoveryEntity
();
parseDiscovery
(
childElement
,
discoveryEntity
);
}
else
if
(
StringUtils
.
equals
(
childElement
.
getName
(),
ConfigConstant
.
STRATEGY_ELEMENT_NAME
))
{
strategyEntity
=
new
StrategyEntity
();
parseStrategy
(
childElement
,
strategyEntity
);
}
else
if
(
StringUtils
.
equals
(
childElement
.
getName
(),
ConfigConstant
.
CUSTOMIZATION_ELEMENT_NAME
))
{
customizationEntity
=
new
CustomizationEntity
();
parseCustomization
(
childElement
,
customizationEntity
);
...
...
@@ -105,6 +110,7 @@ public class XmlConfigParser implements PluginConfigParser {
RuleEntity
ruleEntity
=
new
RuleEntity
();
ruleEntity
.
setRegisterEntity
(
registerEntity
);
ruleEntity
.
setDiscoveryEntity
(
discoveryEntity
);
ruleEntity
.
setStrategyEntity
(
strategyEntity
);
ruleEntity
.
setCustomizationEntity
(
customizationEntity
);
ruleEntity
.
setContent
(
config
);
...
...
@@ -152,6 +158,27 @@ public class XmlConfigParser implements PluginConfigParser {
}
@SuppressWarnings
(
"rawtypes"
)
private
void
parseStrategy
(
Element
element
,
StrategyEntity
strategyEntity
)
{
for
(
Iterator
elementIterator
=
element
.
elementIterator
();
elementIterator
.
hasNext
();)
{
Object
childElementObject
=
elementIterator
.
next
();
if
(
childElementObject
instanceof
Element
)
{
Element
childElement
=
(
Element
)
childElementObject
;
if
(
StringUtils
.
equals
(
childElement
.
getName
(),
ConfigConstant
.
VERSION_ELEMENT_NAME
))
{
String
versionValue
=
childElement
.
getTextTrim
();
strategyEntity
.
setVersionValue
(
versionValue
);
}
else
if
(
StringUtils
.
equals
(
childElement
.
getName
(),
ConfigConstant
.
REGION_ELEMENT_NAME
))
{
String
regionValue
=
childElement
.
getTextTrim
();
strategyEntity
.
setRegionValue
(
regionValue
);
}
else
if
(
StringUtils
.
equals
(
childElement
.
getName
(),
ConfigConstant
.
ADDRESS_ELEMENT_NAME
))
{
String
addressValue
=
childElement
.
getTextTrim
();
strategyEntity
.
setAddressValue
(
addressValue
);
}
}
}
}
@SuppressWarnings
(
"rawtypes"
)
private
void
parseCustomization
(
Element
element
,
CustomizationEntity
customizationEntity
)
{
Map
<
String
,
Map
<
String
,
String
>>
customizationMap
=
customizationEntity
.
getCustomizationMap
();
for
(
Iterator
elementIterator
=
element
.
elementIterator
();
elementIterator
.
hasNext
();)
{
...
...
discovery-plugin-strategy/src/main/java/com/nepxion/discovery/plugin/strategy/adapter/AbstractDiscoveryEnabledAdapter.java
View file @
5012a387
...
...
@@ -16,14 +16,20 @@ import org.apache.commons.lang3.StringUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.entity.RuleEntity
;
import
com.nepxion.discovery.common.entity.StrategyEntity
;
import
com.nepxion.discovery.common.util.JsonUtil
;
import
com.nepxion.discovery.common.util.StringUtil
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.netflix.loadbalancer.Server
;
public
abstract
class
AbstractDiscoveryEnabledAdapter
implements
DiscoveryEnabledAdapter
{
@Autowired
(
required
=
false
)
private
DiscoveryEnabledStrategy
discoveryEnabledStrategy
;
@Autowired
private
PluginAdapter
pluginAdapter
;
@Override
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
boolean
enabled
=
applyVersion
(
server
,
metadata
);
...
...
@@ -48,6 +54,16 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
private
boolean
applyVersion
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
String
versionValue
=
getVersionValue
(
server
);
if
(
StringUtils
.
isEmpty
(
versionValue
))
{
RuleEntity
ruleEntity
=
pluginAdapter
.
getRule
();
if
(
ruleEntity
!=
null
)
{
StrategyEntity
strategyEntity
=
ruleEntity
.
getStrategyEntity
();
if
(
strategyEntity
!=
null
)
{
versionValue
=
strategyEntity
.
getVersionValue
();
}
}
}
if
(
StringUtils
.
isEmpty
(
versionValue
))
{
return
true
;
}
...
...
@@ -81,6 +97,16 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
private
boolean
applyRegion
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
String
regionValue
=
getRegionValue
(
server
);
if
(
StringUtils
.
isEmpty
(
regionValue
))
{
RuleEntity
ruleEntity
=
pluginAdapter
.
getRule
();
if
(
ruleEntity
!=
null
)
{
StrategyEntity
strategyEntity
=
ruleEntity
.
getStrategyEntity
();
if
(
strategyEntity
!=
null
)
{
regionValue
=
strategyEntity
.
getRegionValue
();
}
}
}
if
(
StringUtils
.
isEmpty
(
regionValue
))
{
return
true
;
}
...
...
@@ -114,6 +140,16 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
private
boolean
applyAddress
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
String
addressValue
=
getAddressValue
(
server
);
if
(
StringUtils
.
isEmpty
(
addressValue
))
{
RuleEntity
ruleEntity
=
pluginAdapter
.
getRule
();
if
(
ruleEntity
!=
null
)
{
StrategyEntity
strategyEntity
=
ruleEntity
.
getStrategyEntity
();
if
(
strategyEntity
!=
null
)
{
addressValue
=
strategyEntity
.
getAddressValue
();
}
}
}
if
(
StringUtils
.
isEmpty
(
addressValue
))
{
return
true
;
}
...
...
discovery-springcloud-example-service/src/main/resources/rule.json
View file @
5012a387
...
...
@@ -112,6 +112,11 @@
}
}
},
"strategyEntity"
:
{
"versionValue"
:
"{
\"
discovery-springcloud-example-a
\"
:
\"
1.0
\"
,
\"
discovery-springcloud-example-b
\"
:
\"
1.0
\"
,
\"
discovery-springcloud-example-c
\"
:
\"
1.0;1.2
\"
}"
,
"regionValue"
:
"{
\"
discovery-springcloud-example-a
\"
:
\"
qa;dev
\"
,
\"
discovery-springcloud-example-b
\"
:
\"
dev
\"
,
\"
discovery-springcloud-example-c
\"
:
\"
qa
\"
}"
,
"addressValue"
:
"{
\"
discovery-springcloud-example-a
\"
:
\"
192.168.43.101:1100
\"
,
\"
discovery-springcloud-example-b
\"
:
\"
192.168.43.101:1201
\"
,
\"
discovery-springcloud-example-c
\"
:
\"
192.168.43.101:1300
\"
}"
},
"customizationEntity"
:
{
"customizationMap"
:
{
"discovery-springcloud-example-a"
:
{
...
...
discovery-springcloud-example-service/src/main/resources/rule.xml
View file @
5012a387
...
...
@@ -88,6 +88,14 @@
</weight>
</discovery>
<strategy>
<!-- <version>{"discovery-springcloud-example-a":"1.0", "discovery-springcloud-example-b":"1.0", "discovery-springcloud-example-c":"1.0;1.2"}</version> -->
<!-- <version>1.0</version> -->
<!-- <region>{"discovery-springcloud-example-a":"qa;dev", "discovery-springcloud-example-b":"dev", "discovery-springcloud-example-c":"qa"}</region> -->
<!-- <region>dev</region> -->
<!-- <address>{"discovery-springcloud-example-a":"192.168.43.101:1100", "discovery-springcloud-example-b":"192.168.43.101:1201", "discovery-springcloud-example-c":"192.168.43.101:1300"}</address> -->
</strategy>
<!-- 客户定制化控制,由远程推送客户化参数的改变,实现一些特色化的灰度发布,例如,基于数据库的灰度发布 -->
<customization>
<!-- 服务a和c分别有两个库的配置,分别是测试数据库(database的value为qa)和生产数据库(database的value为prod) -->
...
...
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