forked from Nepxion/Discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
支持同时多个DiscoveryEnabledStrategy的联合判断;支持网关动态选择子环境的功能;修复子环境过滤为判断元数据中的env…
…为空的Bug
- Loading branch information
Showing
5 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...nepxion/discovery/plugin/strategy/adapter/DefaultEnvironmentDiscoveryEnabledStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.nepxion.discovery.plugin.strategy.adapter; | ||
|
||
/** | ||
* <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.StringUtils; | ||
|
||
import com.nepxion.discovery.common.constant.DiscoveryConstant; | ||
import com.netflix.loadbalancer.Server; | ||
|
||
public class DefaultEnvironmentDiscoveryEnabledStrategy extends DefaultDiscoveryEnabledStrategy { | ||
@Override | ||
public boolean apply(Server server) { | ||
String environment = pluginAdapter.getEnvironment(); | ||
// 本地配置了environment,说明本服务(一般来说是网关)也处在子环境里,则由EnvironmentFilterLoadBalanceListener方式去执行环境隔离,返回true | ||
if (!StringUtils.equals(environment, DiscoveryConstant.DEFAULT)) { | ||
return true; | ||
} | ||
|
||
String headerEnvironment = strategyContextHolder.getHeader(DiscoveryConstant.ENVIRONMENT); | ||
// 传入headerEnvironment为空,返回true | ||
if (StringUtils.isEmpty(headerEnvironment)) { | ||
return true; | ||
} | ||
|
||
String serverEnvironment = pluginAdapter.getServerEnvironment(server); | ||
|
||
// 本服务(一般来说是网关)不隶属任何子环境,由它来调度子环境的服务调用 | ||
return StringUtils.equals(headerEnvironment, serverEnvironment); | ||
} | ||
} |