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
09f4dac8
Commit
09f4dac8
authored
Jun 03, 2019
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
因为算法错误,去除RouterEndpoint的获取RouterEntity树接口中的customMap,改由“查看规则”功能来代替,同时重构了Console Desktop界面,并付诸功能变更
parent
b52c684d
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
45 deletions
+103
-45
discovery-common/src/main/java/com/nepxion/discovery/common/entity/RouterEntity.java
+0
-10
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
+15
-0
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/workspace/RouterTopology.java
+86
-10
discovery-console-desktop/src/main/resources/com/nepxion/discovery/console/desktop/locale/Locale.properties
+1
-0
discovery-console-desktop/src/main/resources/com/nepxion/discovery/console/desktop/locale/Locale_zh_CN.properties
+1
-0
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/RouterEndpoint.java
+0
-25
No files found.
discovery-common/src/main/java/com/nepxion/discovery/common/entity/RouterEntity.java
View file @
09f4dac8
...
...
@@ -12,7 +12,6 @@ package com.nepxion.discovery.common.entity;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
...
...
@@ -28,7 +27,6 @@ public class RouterEntity implements Serializable {
private
String
host
;
private
int
port
;
private
int
weight
=
-
1
;
private
Map
<
String
,
String
>
customMap
;
private
String
contextPath
;
private
List
<
RouterEntity
>
nexts
=
new
ArrayList
<
RouterEntity
>();
...
...
@@ -81,14 +79,6 @@ public class RouterEntity implements Serializable {
this
.
weight
=
weight
;
}
public
Map
<
String
,
String
>
getCustomMap
()
{
return
customMap
;
}
public
void
setCustomMap
(
Map
<
String
,
String
>
customMap
)
{
this
.
customMap
=
customMap
;
}
public
String
getContextPath
()
{
return
contextPath
;
}
...
...
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
View file @
09f4dac8
...
...
@@ -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
)
{
String
url
=
getUrl
(
instance
)
+
"router/routes"
;
...
...
@@ -261,6 +270,12 @@ public class ServiceController {
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
)
{
return
async
?
DiscoveryConstant
.
ASYNC
:
DiscoveryConstant
.
SYNC
;
}
...
...
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/workspace/RouterTopology.java
View file @
09f4dac8
...
...
@@ -11,6 +11,7 @@ package com.nepxion.discovery.console.desktop.workspace;
import
twaver.Generator
;
import
java.awt.BorderLayout
;
import
java.awt.Color
;
import
java.awt.Dimension
;
import
java.awt.event.ActionEvent
;
...
...
@@ -19,8 +20,8 @@ import java.awt.event.HierarchyEvent;
import
java.awt.event.ItemEvent
;
import
java.awt.event.ItemListener
;
import
java.util.List
;
import
java.util.Map
;
import
javax.swing.BorderFactory
;
import
javax.swing.Box
;
import
javax.swing.DefaultComboBoxModel
;
import
javax.swing.JLabel
;
...
...
@@ -30,7 +31,6 @@ import javax.swing.JSlider;
import
javax.swing.JToolBar
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.MapUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
com.nepxion.cots.twaver.element.TElementManager
;
...
...
@@ -62,6 +62,9 @@ import com.nepxion.swing.handle.HandleManager;
import
com.nepxion.swing.listener.DisplayAbilityListener
;
import
com.nepxion.swing.locale.SwingLocale
;
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
;
public
class
RouterTopology
extends
AbstractTopology
{
...
...
@@ -74,6 +77,7 @@ public class RouterTopology extends AbstractTopology {
private
JBasicComboBox
comboBox
;
private
JBasicTextField
textField
;
private
ActionListener
layoutActionListener
;
private
RulePanel
rulePanel
;
private
Instance
instance
;
...
...
@@ -110,6 +114,7 @@ public class RouterTopology extends AbstractTopology {
toolBar
.
add
(
textField
);
toolBar
.
add
(
new
JClassicButton
(
createExecuteRouterAction
()));
toolBar
.
add
(
new
JClassicButton
(
createClearRouterAction
()));
toolBar
.
add
(
new
JClassicButton
(
createViewRuleAction
()));
ButtonManager
.
updateUI
(
toolBar
);
}
...
...
@@ -158,7 +163,7 @@ public class RouterTopology extends AbstractTopology {
graph
.
getLayoutInternalFrame
().
setLocation
(
3000
,
3000
);
// 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
);
}
...
...
@@ -209,13 +214,6 @@ public class RouterTopology extends AbstractTopology {
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
());
}
...
...
@@ -356,4 +354,81 @@ public class RouterTopology extends AbstractTopology {
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
discovery-console-desktop/src/main/resources/com/nepxion/discovery/console/desktop/locale/Locale.properties
View file @
09f4dac8
...
...
@@ -30,6 +30,7 @@ add_service=添加一个服务
delete_service
=
删除一个服务
execute_router
=
执行路由
clear_router
=
清除路由
view_rule
=
查看规则
router_path_invalid
=
路由路径不能为空
global_group
=
服务集群组
...
...
discovery-console-desktop/src/main/resources/com/nepxion/discovery/console/desktop/locale/Locale_zh_CN.properties
View file @
09f4dac8
...
...
@@ -30,6 +30,7 @@ add_service=\u6dfb\u52a0\u4e00\u4e2a\u670d\u52a1
delete_service
=
\u5220\u9664\u
4e00
\u
4e2a
\u
670d
\u
52a1
execute_router
=
\u6267\u
884c
\u
8def
\u7531
clear_router
=
\u
6e05
\u9664\u
8def
\u7531
view_rule
=
\u
67e5
\u
770b
\u
89c4
\u5219
router_path_invalid
=
\u
8def
\u7531\u
8def
\u
5f84
\u
4e0d
\u
80fd
\u
4e3a
\u
7a7a
global_group
=
\u
670d
\u
52a1
\u
96c6
\u
7fa4
\u
7ec4
...
...
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/RouterEndpoint.java
View file @
09f4dac8
...
...
@@ -38,7 +38,6 @@ 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.entity.CustomizationEntity
;
import
com.nepxion.discovery.common.entity.DiscoveryEntity
;
import
com.nepxion.discovery.common.entity.RegionWeightEntity
;
import
com.nepxion.discovery.common.entity.RouterEntity
;
...
...
@@ -128,7 +127,6 @@ public class RouterEndpoint {
String
host
=
pluginAdapter
.
getHost
();
int
port
=
pluginAdapter
.
getPort
();
int
weight
=
getWeight
(
serviceId
,
version
,
region
);
Map
<
String
,
String
>
customMap
=
getCustomMap
(
serviceId
);
String
contextPath
=
pluginAdapter
.
getContextPath
();
RouterEntity
routerEntity
=
new
RouterEntity
();
...
...
@@ -138,7 +136,6 @@ public class RouterEndpoint {
routerEntity
.
setHost
(
host
);
routerEntity
.
setPort
(
port
);
routerEntity
.
setWeight
(
weight
);
routerEntity
.
setCustomMap
(
customMap
);
routerEntity
.
setContextPath
(
contextPath
);
return
routerEntity
;
...
...
@@ -166,7 +163,6 @@ public class RouterEndpoint {
String
host
=
instance
.
getHost
();
int
port
=
instance
.
getPort
();
int
weight
=
getWeight
(
routeServiceId
,
version
,
region
);
Map
<
String
,
String
>
customMap
=
getCustomMap
(
serviceId
);
String
contextPath
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
RouterEntity
routerEntity
=
new
RouterEntity
();
...
...
@@ -176,7 +172,6 @@ public class RouterEndpoint {
routerEntity
.
setHost
(
host
);
routerEntity
.
setPort
(
port
);
routerEntity
.
setWeight
(
weight
);
routerEntity
.
setCustomMap
(
customMap
);
routerEntity
.
setContextPath
(
contextPath
);
routerEntityList
.
add
(
routerEntity
);
...
...
@@ -358,23 +353,4 @@ public class RouterEndpoint {
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
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