Commit a20592a4 by Nepxion

增强多数据源数据库灰度发布的界面显示

parent 32983ad4
...@@ -12,6 +12,7 @@ package com.nepxion.discovery.common.entity; ...@@ -12,6 +12,7 @@ package com.nepxion.discovery.common.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder;
...@@ -26,6 +27,7 @@ public class RouterEntity implements Serializable { ...@@ -26,6 +27,7 @@ public class RouterEntity implements Serializable {
private String host; private String host;
private int port; private int port;
private int weight = -1; private int weight = -1;
private Map<String, String> customMap;
private String contextPath; private String contextPath;
private List<RouterEntity> nexts = new ArrayList<RouterEntity>(); private List<RouterEntity> nexts = new ArrayList<RouterEntity>();
...@@ -70,6 +72,14 @@ public class RouterEntity implements Serializable { ...@@ -70,6 +72,14 @@ public class RouterEntity implements Serializable {
this.weight = weight; this.weight = weight;
} }
public Map<String, String> getCustomMap() {
return customMap;
}
public void setCustomMap(Map<String, String> customMap) {
this.customMap = customMap;
}
public String getContextPath() { public String getContextPath() {
return contextPath; return contextPath;
} }
......
...@@ -19,6 +19,7 @@ import java.awt.event.HierarchyEvent; ...@@ -19,6 +19,7 @@ import java.awt.event.HierarchyEvent;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
...@@ -29,6 +30,7 @@ import javax.swing.JSlider; ...@@ -29,6 +30,7 @@ import javax.swing.JSlider;
import javax.swing.JToolBar; import javax.swing.JToolBar;
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 com.nepxion.cots.twaver.element.TElementManager; import com.nepxion.cots.twaver.element.TElementManager;
...@@ -203,6 +205,13 @@ public class RouterTopology extends AbstractTopology { ...@@ -203,6 +205,13 @@ public class RouterTopology extends AbstractTopology {
stringBuilder.append("\n [V").append(routerEntity.getVersion()).append("]"); stringBuilder.append("\n [V").append(routerEntity.getVersion()).append("]");
} }
Map<String, String> customMap = routerEntity.getCustomMap();
if (MapUtils.isNotEmpty(customMap)) {
for (Map.Entry<String, String> entry : customMap.entrySet()) {
stringBuilder.append("\n ").append(entry.getKey()).append("=").append(entry.getValue());
}
}
return ButtonManager.getHtmlText(stringBuilder.toString()); return ButtonManager.getHtmlText(stringBuilder.toString());
} }
......
...@@ -38,6 +38,7 @@ import org.springframework.web.client.RestTemplate; ...@@ -38,6 +38,7 @@ 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.constant.DiscoveryConstant; import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.common.entity.CustomizationEntity;
import com.nepxion.discovery.common.entity.DiscoveryEntity; 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.RuleEntity;
...@@ -157,6 +158,7 @@ public class RouterEndpoint { ...@@ -157,6 +158,7 @@ public class RouterEndpoint {
String host = instance.getHost(); String host = instance.getHost();
int port = instance.getPort(); int port = instance.getPort();
int weight = getWeight(routeServiceId, version); int weight = getWeight(routeServiceId, version);
Map<String, String> customMap = getCustomMap(serviceId);
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();
...@@ -165,6 +167,7 @@ public class RouterEndpoint { ...@@ -165,6 +167,7 @@ public class RouterEndpoint {
routerEntity.setHost(host); routerEntity.setHost(host);
routerEntity.setPort(port); routerEntity.setPort(port);
routerEntity.setWeight(weight); routerEntity.setWeight(weight);
routerEntity.setCustomMap(customMap);
routerEntity.setContextPath(contextPath); routerEntity.setContextPath(contextPath);
routerEntityList.add(routerEntity); routerEntityList.add(routerEntity);
...@@ -300,4 +303,23 @@ public class RouterEndpoint { ...@@ -300,4 +303,23 @@ public class RouterEndpoint {
return -1; return -1;
} }
private Map<String, String> getCustomMap(String serviceId) {
RuleEntity ruleEntity = pluginAdapter.getRule();
if (ruleEntity == null) {
return null;
}
CustomizationEntity customizationEntity = ruleEntity.getCustomizationEntity();
if (customizationEntity == null) {
return null;
}
Map<String, Map<String, String>> customizationMap = customizationEntity.getCustomizationMap();
if (MapUtils.isEmpty(customizationMap)) {
return null;
}
return customizationMap.get(serviceId);
}
} }
\ No newline at end of file
...@@ -78,8 +78,9 @@ ...@@ -78,8 +78,9 @@
<!-- 客户定制化控制,由远程推送客户化参数的改变,实现一些特色化的灰度发布,例如,基于数据库的灰度发布 --> <!-- 客户定制化控制,由远程推送客户化参数的改变,实现一些特色化的灰度发布,例如,基于数据库的灰度发布 -->
<customization> <customization>
<!-- 服务b有两个库的配置,分别是临时数据库(database的value为temp)和生产数据库(database的value为prod) --> <!-- 服务a和c分别有两个库的配置,分别是测试数据库(database的value为qa)和生产数据库(database的value为prod) -->
<!-- 上线后,一开始数据库指向临时数据库,对应value为temp,然后灰度发布的时候,改对应value为prod,即实现数据库的灰度发布 --> <!-- 上线后,一开始数据库指向测试数据库,对应value为qa,然后灰度发布的时候,改对应value为prod,即实现数据库的灰度发布 -->
<service service-name="discovery-springcloud-example-b" key="database" value="prod"/> <service service-name="discovery-springcloud-example-a" key="database" value="qa"/>
<service service-name="discovery-springcloud-example-c" key="database" value="prod"/>
</customization> </customization>
</rule> </rule>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment