Commit 09f4dac8 by Nepxion

因为算法错误,去除RouterEndpoint的获取RouterEntity树接口中的customMap,改由“查看规则”功能来代替,同时重构了Console Desktop界面,并付诸功能变更

parent b52c684d
...@@ -12,7 +12,6 @@ package com.nepxion.discovery.common.entity; ...@@ -12,7 +12,6 @@ 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;
...@@ -28,7 +27,6 @@ public class RouterEntity implements Serializable { ...@@ -28,7 +27,6 @@ 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>();
...@@ -81,14 +79,6 @@ public class RouterEntity implements Serializable { ...@@ -81,14 +79,6 @@ 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;
} }
......
...@@ -100,6 +100,15 @@ public class ServiceController { ...@@ -100,6 +100,15 @@ public class ServiceController {
}); });
} }
public static List<String> getRules(RouterEntity routerEntity) {
String url = getUrl(routerEntity) + "config/view";
String result = restTemplate.getForEntity(url, String.class).getBody();
return RestUtil.fromJson(restTemplate, result, new TypeReference<List<String>>() {
});
}
public static RouterEntity routes(Instance instance, String routeServiceIds) { public static RouterEntity routes(Instance instance, String routeServiceIds) {
String url = getUrl(instance) + "router/routes"; String url = getUrl(instance) + "router/routes";
...@@ -261,6 +270,12 @@ public class ServiceController { ...@@ -261,6 +270,12 @@ public class ServiceController {
return url; return url;
} }
private static String getUrl(RouterEntity routerEntity) {
String url = "http://" + routerEntity.getHost() + ":" + routerEntity.getPort() + UrlUtil.formatContextPath(routerEntity.getContextPath());
return url;
}
private static String getInvokeType(boolean async) { private static String getInvokeType(boolean async) {
return async ? DiscoveryConstant.ASYNC : DiscoveryConstant.SYNC; return async ? DiscoveryConstant.ASYNC : DiscoveryConstant.SYNC;
} }
......
...@@ -11,6 +11,7 @@ package com.nepxion.discovery.console.desktop.workspace; ...@@ -11,6 +11,7 @@ package com.nepxion.discovery.console.desktop.workspace;
import twaver.Generator; import twaver.Generator;
import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
...@@ -19,8 +20,8 @@ import java.awt.event.HierarchyEvent; ...@@ -19,8 +20,8 @@ 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.BorderFactory;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel; import javax.swing.JLabel;
...@@ -30,7 +31,6 @@ import javax.swing.JSlider; ...@@ -30,7 +31,6 @@ 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;
...@@ -62,6 +62,9 @@ import com.nepxion.swing.handle.HandleManager; ...@@ -62,6 +62,9 @@ import com.nepxion.swing.handle.HandleManager;
import com.nepxion.swing.listener.DisplayAbilityListener; import com.nepxion.swing.listener.DisplayAbilityListener;
import com.nepxion.swing.locale.SwingLocale; import com.nepxion.swing.locale.SwingLocale;
import com.nepxion.swing.optionpane.JBasicOptionPane; import com.nepxion.swing.optionpane.JBasicOptionPane;
import com.nepxion.swing.scrollpane.JBasicScrollPane;
import com.nepxion.swing.tabbedpane.JBasicTabbedPane;
import com.nepxion.swing.textarea.JBasicTextArea;
import com.nepxion.swing.textfield.JBasicTextField; import com.nepxion.swing.textfield.JBasicTextField;
public class RouterTopology extends AbstractTopology { public class RouterTopology extends AbstractTopology {
...@@ -74,6 +77,7 @@ public class RouterTopology extends AbstractTopology { ...@@ -74,6 +77,7 @@ public class RouterTopology extends AbstractTopology {
private JBasicComboBox comboBox; private JBasicComboBox comboBox;
private JBasicTextField textField; private JBasicTextField textField;
private ActionListener layoutActionListener; private ActionListener layoutActionListener;
private RulePanel rulePanel;
private Instance instance; private Instance instance;
...@@ -110,6 +114,7 @@ public class RouterTopology extends AbstractTopology { ...@@ -110,6 +114,7 @@ public class RouterTopology extends AbstractTopology {
toolBar.add(textField); toolBar.add(textField);
toolBar.add(new JClassicButton(createExecuteRouterAction())); toolBar.add(new JClassicButton(createExecuteRouterAction()));
toolBar.add(new JClassicButton(createClearRouterAction())); toolBar.add(new JClassicButton(createClearRouterAction()));
toolBar.add(new JClassicButton(createViewRuleAction()));
ButtonManager.updateUI(toolBar); ButtonManager.updateUI(toolBar);
} }
...@@ -158,7 +163,7 @@ public class RouterTopology extends AbstractTopology { ...@@ -158,7 +163,7 @@ public class RouterTopology extends AbstractTopology {
graph.getLayoutInternalFrame().setLocation(3000, 3000); graph.getLayoutInternalFrame().setLocation(3000, 3000);
// graph.adjustComponentPosition(graph.getLayoutInternalFrame()); // graph.adjustComponentPosition(graph.getLayoutInternalFrame());
RouterTopology.this.setPreferredSize(new Dimension(RouterTopology.this.getPreferredSize().width - 82, 900)); RouterTopology.this.setPreferredSize(new Dimension(RouterTopology.this.getPreferredSize().width - 100, 900));
removeHierarchyListener(this); removeHierarchyListener(this);
} }
...@@ -209,13 +214,6 @@ public class RouterTopology extends AbstractTopology { ...@@ -209,13 +214,6 @@ public class RouterTopology extends AbstractTopology {
stringBuilder.append("\n [Region=").append(routerEntity.getRegion()).append("]"); stringBuilder.append("\n [Region=").append(routerEntity.getRegion()).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());
} }
...@@ -356,4 +354,81 @@ public class RouterTopology extends AbstractTopology { ...@@ -356,4 +354,81 @@ public class RouterTopology extends AbstractTopology {
return action; return action;
} }
private JSecurityAction createViewRuleAction() {
JSecurityAction action = new JSecurityAction(ConsoleLocale.getString("view_rule"), ConsoleIconFactory.getSwingIcon("component/file_chooser_16.png"), ConsoleLocale.getString("view_rule")) {
private static final long serialVersionUID = 1L;
public void execute(ActionEvent e) {
TNode node = TElementManager.getSelectedNode(dataBox);
if (node == null) {
JBasicOptionPane.showMessageDialog(HandleManager.getFrame(RouterTopology.this), ConsoleLocale.getString("select_a_node"), SwingLocale.getString("warning"), JBasicOptionPane.WARNING_MESSAGE);
return;
}
Object userObject = node.getUserObject();
RouterEntity routerEntity = (RouterEntity) userObject;
List<String> rules = ServiceController.getRules(routerEntity);
String dynamicRule = rules.get(1);
String localRule = rules.get(0);
if (rulePanel == null) {
rulePanel = new RulePanel();
rulePanel.setPreferredSize(new Dimension(800, 600));
}
rulePanel.setDynamicRule(dynamicRule);
rulePanel.setLocalRule(localRule);
JBasicOptionPane.showOptionDialog(HandleManager.getFrame(RouterTopology.this), rulePanel, ConsoleLocale.getString("view_rule"), JBasicOptionPane.DEFAULT_OPTION, JBasicOptionPane.PLAIN_MESSAGE, ConsoleIconFactory.getSwingIcon("banner/property.png"), new Object[] { SwingLocale.getString("close") }, null, true);
}
};
return action;
}
private class RulePanel extends JPanel {
private static final long serialVersionUID = 1L;
private JBasicTextArea dynamicRuleTextArea;
private JPanel dynamicRulePanel;
private JBasicTextArea localRuleTextArea;
private JPanel localRulePanel;
private JBasicTabbedPane ruleTabbedPane;
public RulePanel() {
setLayout(new BorderLayout());
add(createRuleTabbedPane(), BorderLayout.CENTER);
}
private JBasicTabbedPane createRuleTabbedPane() {
dynamicRuleTextArea = new JBasicTextArea();
dynamicRulePanel = new JPanel();
dynamicRulePanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
dynamicRulePanel.setLayout(new BorderLayout());
dynamicRulePanel.add(new JBasicScrollPane(dynamicRuleTextArea), BorderLayout.CENTER);
localRuleTextArea = new JBasicTextArea();
localRulePanel = new JPanel();
localRulePanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
localRulePanel.setLayout(new BorderLayout());
localRulePanel.add(new JBasicScrollPane(localRuleTextArea), BorderLayout.CENTER);
ruleTabbedPane = new JBasicTabbedPane();
ruleTabbedPane.addTab(ConsoleLocale.getString("label_dynamic_rule"), dynamicRulePanel, ConsoleLocale.getString("label_dynamic_rule"));
ruleTabbedPane.addTab(ConsoleLocale.getString("label_local_rule"), localRulePanel, ConsoleLocale.getString("label_local_rule"));
return ruleTabbedPane;
}
public void setDynamicRule(String dynamicRule) {
dynamicRuleTextArea.setText(dynamicRule);
}
public void setLocalRule(String localRule) {
localRuleTextArea.setText(localRule);
}
}
} }
\ No newline at end of file
...@@ -30,6 +30,7 @@ add_service=添加一个服务 ...@@ -30,6 +30,7 @@ add_service=添加一个服务
delete_service=删除一个服务 delete_service=删除一个服务
execute_router=执行路由 execute_router=执行路由
clear_router=清除路由 clear_router=清除路由
view_rule=查看规则
router_path_invalid=路由路径不能为空 router_path_invalid=路由路径不能为空
global_group=服务集群组 global_group=服务集群组
......
...@@ -30,6 +30,7 @@ add_service=\u6dfb\u52a0\u4e00\u4e2a\u670d\u52a1 ...@@ -30,6 +30,7 @@ add_service=\u6dfb\u52a0\u4e00\u4e2a\u670d\u52a1
delete_service=\u5220\u9664\u4e00\u4e2a\u670d\u52a1 delete_service=\u5220\u9664\u4e00\u4e2a\u670d\u52a1
execute_router=\u6267\u884c\u8def\u7531 execute_router=\u6267\u884c\u8def\u7531
clear_router=\u6e05\u9664\u8def\u7531 clear_router=\u6e05\u9664\u8def\u7531
view_rule=\u67e5\u770b\u89c4\u5219
router_path_invalid=\u8def\u7531\u8def\u5f84\u4e0d\u80fd\u4e3a\u7a7a router_path_invalid=\u8def\u7531\u8def\u5f84\u4e0d\u80fd\u4e3a\u7a7a
global_group=\u670d\u52a1\u96c6\u7fa4\u7ec4 global_group=\u670d\u52a1\u96c6\u7fa4\u7ec4
......
...@@ -38,7 +38,6 @@ import org.springframework.web.client.RestTemplate; ...@@ -38,7 +38,6 @@ 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.RegionWeightEntity; import com.nepxion.discovery.common.entity.RegionWeightEntity;
import com.nepxion.discovery.common.entity.RouterEntity; import com.nepxion.discovery.common.entity.RouterEntity;
...@@ -128,7 +127,6 @@ public class RouterEndpoint { ...@@ -128,7 +127,6 @@ public class RouterEndpoint {
String host = pluginAdapter.getHost(); String host = pluginAdapter.getHost();
int port = pluginAdapter.getPort(); int port = pluginAdapter.getPort();
int weight = getWeight(serviceId, version, region); int weight = getWeight(serviceId, version, region);
Map<String, String> customMap = getCustomMap(serviceId);
String contextPath = pluginAdapter.getContextPath(); String contextPath = pluginAdapter.getContextPath();
RouterEntity routerEntity = new RouterEntity(); RouterEntity routerEntity = new RouterEntity();
...@@ -138,7 +136,6 @@ public class RouterEndpoint { ...@@ -138,7 +136,6 @@ 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);
return routerEntity; return routerEntity;
...@@ -166,7 +163,6 @@ public class RouterEndpoint { ...@@ -166,7 +163,6 @@ public class RouterEndpoint {
String host = instance.getHost(); String host = instance.getHost();
int port = instance.getPort(); int port = instance.getPort();
int weight = getWeight(routeServiceId, version, region); int weight = getWeight(routeServiceId, version, region);
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();
...@@ -176,7 +172,6 @@ public class RouterEndpoint { ...@@ -176,7 +172,6 @@ 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);
...@@ -358,23 +353,4 @@ public class RouterEndpoint { ...@@ -358,23 +353,4 @@ 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
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