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
b59e3c63
Commit
b59e3c63
authored
Sep 14, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构类结构
parent
ee6589f4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
80 deletions
+122
-80
discovery-common/src/main/java/com/nepxion/discovery/common/entity/InstanceEntityWrapper.java
+80
-0
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
+2
-1
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/entity/Instance.java
+0
-57
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/workspace/ServiceTopology.java
+40
-22
No files found.
discovery-common/src/main/java/com/nepxion/discovery/common/entity/InstanceEntityWrapper.java
0 → 100644
View file @
b59e3c63
package
com
.
nepxion
.
discovery
.
common
.
entity
;
/**
* <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
java.util.Map
;
import
org.apache.commons.lang3.StringUtils
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
public
class
InstanceEntityWrapper
{
public
static
String
getContextPath
(
InstanceEntity
instanceEntity
)
{
Map
<
String
,
String
>
metadata
=
instanceEntity
.
getMetadata
();
return
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
}
public
static
String
getGroup
(
InstanceEntity
instanceEntity
)
{
Map
<
String
,
String
>
metadata
=
instanceEntity
.
getMetadata
();
String
groupKey
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_GROUP_KEY
);
if
(
StringUtils
.
isEmpty
(
groupKey
))
{
return
StringUtils
.
EMPTY
;
}
String
filter
=
metadata
.
get
(
groupKey
);
if
(
filter
==
null
)
{
return
StringUtils
.
EMPTY
;
}
return
filter
;
}
public
static
String
getPlugin
(
InstanceEntity
instanceEntity
)
{
Map
<
String
,
String
>
metadata
=
instanceEntity
.
getMetadata
();
String
plugin
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_PLUGIN
);
if
(
plugin
==
null
)
{
return
StringUtils
.
EMPTY
;
}
return
plugin
;
}
public
static
boolean
isRegisterControlEnabled
(
InstanceEntity
instanceEntity
)
{
Map
<
String
,
String
>
metadata
=
instanceEntity
.
getMetadata
();
String
flag
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
);
if
(
flag
==
null
)
{
return
true
;
}
return
Boolean
.
valueOf
(
flag
);
}
public
static
boolean
isDiscoveryControlEnabled
(
InstanceEntity
instanceEntity
)
{
Map
<
String
,
String
>
metadata
=
instanceEntity
.
getMetadata
();
String
flag
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
);
if
(
flag
==
null
)
{
return
true
;
}
return
Boolean
.
valueOf
(
flag
);
}
public
static
boolean
isConfigRestControlEnabled
(
InstanceEntity
instanceEntity
)
{
Map
<
String
,
String
>
metadata
=
instanceEntity
.
getMetadata
();
String
flag
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED
);
if
(
flag
==
null
)
{
return
true
;
}
return
Boolean
.
valueOf
(
flag
);
}
}
\ No newline at end of file
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
View file @
b59e3c63
...
@@ -20,6 +20,7 @@ import org.springframework.web.client.RestTemplate;
...
@@ -20,6 +20,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.InstanceEntityWrapper
;
import
com.nepxion.discovery.common.entity.ResultEntity
;
import
com.nepxion.discovery.common.entity.ResultEntity
;
import
com.nepxion.discovery.common.entity.RouterEntity
;
import
com.nepxion.discovery.common.entity.RouterEntity
;
import
com.nepxion.discovery.common.handler.RestErrorHandler
;
import
com.nepxion.discovery.common.handler.RestErrorHandler
;
...
@@ -218,7 +219,7 @@ public class ServiceController {
...
@@ -218,7 +219,7 @@ public class ServiceController {
}
}
private
static
String
getUrl
(
Instance
instance
)
{
private
static
String
getUrl
(
Instance
instance
)
{
String
url
=
"http://"
+
instance
.
getHost
()
+
":"
+
instance
.
getPort
()
+
UrlUtil
.
formatContextPath
(
instance
.
getContextPath
(
));
String
url
=
"http://"
+
instance
.
getHost
()
+
":"
+
instance
.
getPort
()
+
UrlUtil
.
formatContextPath
(
InstanceEntityWrapper
.
getContextPath
(
instance
));
return
url
;
return
url
;
}
}
...
...
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/entity/Instance.java
View file @
b59e3c63
...
@@ -9,11 +9,6 @@ package com.nepxion.discovery.console.desktop.entity;
...
@@ -9,11 +9,6 @@ package com.nepxion.discovery.console.desktop.entity;
* @version 1.0
* @version 1.0
*/
*/
import
java.util.Map
;
import
org.apache.commons.lang3.StringUtils
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.entity.InstanceEntity
;
import
com.nepxion.discovery.common.entity.InstanceEntity
;
public
class
Instance
extends
InstanceEntity
{
public
class
Instance
extends
InstanceEntity
{
...
@@ -46,55 +41,4 @@ public class Instance extends InstanceEntity {
...
@@ -46,55 +41,4 @@ public class Instance extends InstanceEntity {
public
void
setDynamicRule
(
String
dynamicRule
)
{
public
void
setDynamicRule
(
String
dynamicRule
)
{
this
.
dynamicRule
=
dynamicRule
;
this
.
dynamicRule
=
dynamicRule
;
}
}
public
String
getContextPath
()
{
Map
<
String
,
String
>
metadata
=
getMetadata
();
return
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
}
public
String
getFilter
()
{
Map
<
String
,
String
>
metadata
=
getMetadata
();
String
filterKey
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_GROUP_KEY
);
if
(
StringUtils
.
isEmpty
(
filterKey
))
{
return
""
;
}
String
filter
=
metadata
.
get
(
filterKey
);
if
(
filter
==
null
)
{
return
""
;
}
return
filter
;
}
public
String
getPlugin
()
{
Map
<
String
,
String
>
metadata
=
getMetadata
();
String
plugin
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_PLUGIN
);
if
(
plugin
==
null
)
{
return
""
;
}
return
plugin
;
}
public
boolean
isDiscoveryControlEnabled
()
{
Map
<
String
,
String
>
metadata
=
getMetadata
();
String
flag
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
);
if
(
flag
==
null
)
{
return
true
;
}
return
Boolean
.
valueOf
(
flag
);
}
public
boolean
isConfigRestControlEnabled
()
{
Map
<
String
,
String
>
metadata
=
getMetadata
();
String
flag
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED
);
if
(
flag
==
null
)
{
return
true
;
}
return
Boolean
.
valueOf
(
flag
);
}
}
}
\ No newline at end of file
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/workspace/ServiceTopology.java
View file @
b59e3c63
...
@@ -47,6 +47,7 @@ import com.nepxion.cots.twaver.element.TGroupType;
...
@@ -47,6 +47,7 @@ import com.nepxion.cots.twaver.element.TGroupType;
import
com.nepxion.cots.twaver.element.TNode
;
import
com.nepxion.cots.twaver.element.TNode
;
import
com.nepxion.cots.twaver.graph.TGraphBackground
;
import
com.nepxion.cots.twaver.graph.TGraphBackground
;
import
com.nepxion.cots.twaver.graph.TGraphManager
;
import
com.nepxion.cots.twaver.graph.TGraphManager
;
import
com.nepxion.discovery.common.entity.InstanceEntityWrapper
;
import
com.nepxion.discovery.common.entity.ResultEntity
;
import
com.nepxion.discovery.common.entity.ResultEntity
;
import
com.nepxion.discovery.console.desktop.constant.ConsoleConstant
;
import
com.nepxion.discovery.console.desktop.constant.ConsoleConstant
;
import
com.nepxion.discovery.console.desktop.controller.ServiceController
;
import
com.nepxion.discovery.console.desktop.controller.ServiceController
;
...
@@ -117,7 +118,6 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -117,7 +118,6 @@ public class ServiceTopology extends AbstractTopology {
private
Map
<
String
,
List
<
Instance
>>
globalInstanceMap
;
private
Map
<
String
,
List
<
Instance
>>
globalInstanceMap
;
private
String
globalFilter
;
private
String
globalFilter
;
private
Vector
<
Object
>
globalFilterVector
=
new
Vector
<
Object
>();
public
ServiceTopology
()
{
public
ServiceTopology
()
{
initializeToolBar
();
initializeToolBar
();
...
@@ -269,8 +269,8 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -269,8 +269,8 @@ public class ServiceTopology extends AbstractTopology {
private
void
addInstances
(
TGroup
group
,
String
serviceId
,
List
<
Instance
>
instances
)
{
private
void
addInstances
(
TGroup
group
,
String
serviceId
,
List
<
Instance
>
instances
)
{
for
(
int
i
=
0
;
i
<
instances
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
instances
.
size
();
i
++)
{
Instance
instance
=
instances
.
get
(
i
);
Instance
instance
=
instances
.
get
(
i
);
String
filter
=
instance
.
getFilter
(
);
String
filter
=
InstanceEntityWrapper
.
getGroup
(
instance
);
String
plugin
=
instance
.
getPlugin
(
);
String
plugin
=
InstanceEntityWrapper
.
getPlugin
(
instance
);
String
nodeName
=
getNodeName
(
instance
);
String
nodeName
=
getNodeName
(
instance
);
TNode
node
=
createNode
(
nodeName
,
StringUtils
.
isNotEmpty
(
plugin
)
?
serviceNodeEntity
:
notServiceNodeEntity
,
nodeLocationEntity
,
i
);
TNode
node
=
createNode
(
nodeName
,
StringUtils
.
isNotEmpty
(
plugin
)
?
serviceNodeEntity
:
notServiceNodeEntity
,
nodeLocationEntity
,
i
);
...
@@ -293,7 +293,7 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -293,7 +293,7 @@ public class ServiceTopology extends AbstractTopology {
// 服务注册发现中心,必须有一个规范,即在同一个服务集群下,必须所有服务的metadata格式一致,例如一个服务配了group,另一个服务没有配group
// 服务注册发现中心,必须有一个规范,即在同一个服务集群下,必须所有服务的metadata格式一致,例如一个服务配了group,另一个服务没有配group
// 只取有值的那个
// 只取有值的那个
for
(
Instance
instance
:
instances
)
{
for
(
Instance
instance
:
instances
)
{
String
filter
=
instance
.
getFilter
(
);
String
filter
=
InstanceEntityWrapper
.
getGroup
(
instance
);
if
(
StringUtils
.
isNotEmpty
(
filter
))
{
if
(
StringUtils
.
isNotEmpty
(
filter
))
{
return
filter
;
return
filter
;
}
}
...
@@ -304,7 +304,7 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -304,7 +304,7 @@ public class ServiceTopology extends AbstractTopology {
private
String
getValidPlugin
(
List
<
Instance
>
instances
)
{
private
String
getValidPlugin
(
List
<
Instance
>
instances
)
{
for
(
Instance
instance
:
instances
)
{
for
(
Instance
instance
:
instances
)
{
String
plugin
=
instance
.
getPlugin
(
);
String
plugin
=
InstanceEntityWrapper
.
getPlugin
(
instance
);
if
(
StringUtils
.
isNotEmpty
(
plugin
))
{
if
(
StringUtils
.
isNotEmpty
(
plugin
))
{
return
plugin
;
return
plugin
;
}
}
...
@@ -313,13 +313,13 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -313,13 +313,13 @@ public class ServiceTopology extends AbstractTopology {
return
""
;
return
""
;
}
}
private
Object
[]
filter
(
Map
<
String
,
List
<
Instance
>>
instanceMap
)
{
private
Object
[]
filter
ToArray
(
Map
<
String
,
List
<
Instance
>>
instanceMap
)
{
List
<
String
>
filters
=
new
ArrayList
<
String
>();
List
<
String
>
filters
=
new
ArrayList
<
String
>();
for
(
Map
.
Entry
<
String
,
List
<
Instance
>>
entry
:
instanceMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
List
<
Instance
>>
entry
:
instanceMap
.
entrySet
())
{
List
<
Instance
>
instances
=
entry
.
getValue
();
List
<
Instance
>
instances
=
entry
.
getValue
();
for
(
Instance
instance
:
instances
)
{
for
(
Instance
instance
:
instances
)
{
String
filter
=
instance
.
getFilter
(
);
String
filter
=
InstanceEntityWrapper
.
getGroup
(
instance
);
String
plugin
=
instance
.
getPlugin
(
);
String
plugin
=
InstanceEntityWrapper
.
getPlugin
(
instance
);
if
(
StringUtils
.
isNotEmpty
(
plugin
)
&&
!
filters
.
contains
(
filter
))
{
if
(
StringUtils
.
isNotEmpty
(
plugin
)
&&
!
filters
.
contains
(
filter
))
{
filters
.
add
(
filter
);
filters
.
add
(
filter
);
}
}
...
@@ -334,6 +334,22 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -334,6 +334,22 @@ public class ServiceTopology extends AbstractTopology {
return
filters
.
toArray
();
return
filters
.
toArray
();
}
}
private
Vector
<
Object
>
filterToVector
(
Map
<
String
,
List
<
Instance
>>
instanceMap
)
{
Vector
<
Object
>
filters
=
new
Vector
<
Object
>();
for
(
Map
.
Entry
<
String
,
List
<
Instance
>>
entry
:
instanceMap
.
entrySet
())
{
List
<
Instance
>
instances
=
entry
.
getValue
();
for
(
Instance
instance
:
instances
)
{
String
filter
=
InstanceEntityWrapper
.
getGroup
(
instance
);
String
plugin
=
InstanceEntityWrapper
.
getPlugin
(
instance
);
if
(
StringUtils
.
isNotEmpty
(
plugin
)
&&
!
filters
.
contains
(
filter
))
{
filters
.
add
(
filter
);
}
}
}
return
filters
;
}
private
Object
[]
filterServices
(
TNode
node
,
Map
<
String
,
List
<
Instance
>>
instanceMap
)
{
private
Object
[]
filterServices
(
TNode
node
,
Map
<
String
,
List
<
Instance
>>
instanceMap
)
{
Set
<
String
>
services
=
instanceMap
.
keySet
();
Set
<
String
>
services
=
instanceMap
.
keySet
();
List
<
String
>
filterServices
=
new
ArrayList
<
String
>();
List
<
String
>
filterServices
=
new
ArrayList
<
String
>();
...
@@ -546,7 +562,7 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -546,7 +562,7 @@ public class ServiceTopology extends AbstractTopology {
return
;
return
;
}
}
Object
[]
filters
=
filter
(
instanceMap
);
Object
[]
filters
=
filter
ToArray
(
instanceMap
);
if
(
filterPanel
==
null
)
{
if
(
filterPanel
==
null
)
{
filterPanel
=
new
FilterPanel
();
filterPanel
=
new
FilterPanel
();
filterPanel
.
setPreferredSize
(
new
Dimension
(
320
,
60
));
filterPanel
.
setPreferredSize
(
new
Dimension
(
320
,
60
));
...
@@ -561,15 +577,6 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -561,15 +577,6 @@ public class ServiceTopology extends AbstractTopology {
globalInstanceMap
=
instanceMap
;
globalInstanceMap
=
instanceMap
;
globalFilter
=
filterPanel
.
getFilter
();
globalFilter
=
filterPanel
.
getFilter
();
globalFilterVector
.
clear
();
if
(!
StringUtils
.
equals
(
globalFilter
,
NO_FILTER
))
{
globalFilterVector
.
add
(
globalFilter
);
}
else
{
for
(
int
i
=
0
;
i
<
filters
.
length
-
1
;
i
++)
{
globalFilterVector
.
add
(
filters
[
i
]);
}
}
String
title
=
ConsoleLocale
.
getString
(
"title_service_cluster_gray_release"
);
String
title
=
ConsoleLocale
.
getString
(
"title_service_cluster_gray_release"
);
if
(!
StringUtils
.
equals
(
globalFilter
,
NO_FILTER
))
{
if
(!
StringUtils
.
equals
(
globalFilter
,
NO_FILTER
))
{
title
+=
" ["
+
globalFilter
+
"]"
;
title
+=
" ["
+
globalFilter
+
"]"
;
...
@@ -729,6 +736,17 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -729,6 +736,17 @@ public class ServiceTopology extends AbstractTopology {
return
;
return
;
}
}
Map
<
String
,
List
<
Instance
>>
instanceMap
=
null
;
try
{
instanceMap
=
ServiceController
.
getInstanceMap
();
}
catch
(
Exception
ex
)
{
JExceptionDialog
.
traceException
(
HandleManager
.
getFrame
(
ServiceTopology
.
this
),
ConsoleLocale
.
getString
(
"get_service_instances_failure"
),
ex
);
return
;
}
Vector
<
Object
>
globalFilterVector
=
filterToVector
(
instanceMap
);
if
(
globalGrayPanel
==
null
)
{
if
(
globalGrayPanel
==
null
)
{
globalGrayPanel
=
new
GlobalGrayPanel
();
globalGrayPanel
=
new
GlobalGrayPanel
();
globalGrayPanel
.
setPreferredSize
(
new
Dimension
(
1300
,
800
));
globalGrayPanel
.
setPreferredSize
(
new
Dimension
(
1300
,
800
));
...
@@ -1041,11 +1059,11 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -1041,11 +1059,11 @@ public class ServiceTopology extends AbstractTopology {
TNode
node
=
iterator
.
next
();
TNode
node
=
iterator
.
next
();
Instance
instance
=
(
Instance
)
node
.
getUserObject
();
Instance
instance
=
(
Instance
)
node
.
getUserObject
();
boolean
versionEnabled
=
instance
.
isDiscoveryControlEnabled
(
);
boolean
versionEnabled
=
InstanceEntityWrapper
.
isDiscoveryControlEnabled
(
instance
);
if
(
versionEnabled
)
{
if
(
versionEnabled
)
{
versionControlEnabled
=
true
;
versionControlEnabled
=
true
;
}
}
boolean
ruleEnabled
=
instance
.
isDiscoveryControlEnabled
()
&&
instance
.
isConfigRestControlEnabled
(
);
boolean
ruleEnabled
=
InstanceEntityWrapper
.
isDiscoveryControlEnabled
(
instance
)
&&
InstanceEntityWrapper
.
isConfigRestControlEnabled
(
instance
);
if
(
ruleEnabled
)
{
if
(
ruleEnabled
)
{
ruleControlEnabled
=
true
;
ruleControlEnabled
=
true
;
}
}
...
@@ -1092,8 +1110,8 @@ public class ServiceTopology extends AbstractTopology {
...
@@ -1092,8 +1110,8 @@ public class ServiceTopology extends AbstractTopology {
this
.
node
=
node
;
this
.
node
=
node
;
Instance
instance
=
(
Instance
)
node
.
getUserObject
();
Instance
instance
=
(
Instance
)
node
.
getUserObject
();
boolean
versionControlEnabled
=
instance
.
isDiscoveryControlEnabled
(
);
boolean
versionControlEnabled
=
InstanceEntityWrapper
.
isDiscoveryControlEnabled
(
instance
);
boolean
ruleControlEnabled
=
instance
.
isDiscoveryControlEnabled
()
&&
instance
.
isConfigRestControlEnabled
(
)
&&
!
ruleToConfigCenterRadioButtonMenuItem
.
isSelected
();
boolean
ruleControlEnabled
=
InstanceEntityWrapper
.
isDiscoveryControlEnabled
(
instance
)
&&
InstanceEntityWrapper
.
isConfigRestControlEnabled
(
instance
)
&&
!
ruleToConfigCenterRadioButtonMenuItem
.
isSelected
();
if
(
versionTabbedPane
.
getTabCount
()
==
1
)
{
if
(
versionTabbedPane
.
getTabCount
()
==
1
)
{
versionTabbedPane
.
addTab
(
ConsoleLocale
.
getString
(
"label_local_version"
),
localVersionPanel
,
ConsoleLocale
.
getString
(
"label_local_version"
));
versionTabbedPane
.
addTab
(
ConsoleLocale
.
getString
(
"label_local_version"
),
localVersionPanel
,
ConsoleLocale
.
getString
(
"label_local_version"
));
...
...
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