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
db9b63cd
Commit
db9b63cd
authored
Jul 10, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
控制台增加接口
parent
d36e1da7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
18 deletions
+47
-18
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
+46
-17
discovery-console/src/main/java/com/nepxion/discovery/console/entity/InstanceEntity.java
+1
-1
No files found.
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
View file @
db9b63cd
...
@@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
...
@@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.nepxion.discovery.console.entity.
Servi
ceEntity
;
import
com.nepxion.discovery.console.entity.
Instan
ceEntity
;
@RestController
@RestController
@Api
(
tags
=
{
"控制台接口"
})
@Api
(
tags
=
{
"控制台接口"
})
...
@@ -56,12 +56,20 @@ public class ConsoleEndpoint implements MvcEndpoint {
...
@@ -56,12 +56,20 @@ public class ConsoleEndpoint implements MvcEndpoint {
return
getInstances
(
serviceId
);
return
getInstances
(
serviceId
);
}
}
@RequestMapping
(
path
=
"/console/
service-map
"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/console/
instance-list/{serviceId}
"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
value
=
"获取服务注册中心
的服务和实例的Map"
,
notes
=
""
,
response
=
Map
.
class
,
httpMethod
=
"GET"
)
@ApiOperation
(
value
=
"获取服务注册中心
服务的实例列表(精简数据)"
,
notes
=
""
,
response
=
List
.
class
,
httpMethod
=
"GET"
)
@ResponseBody
@ResponseBody
@ManagedOperation
@ManagedOperation
public
Map
<
String
,
List
<
ServiceEntity
>>
serviceMap
()
{
public
List
<
InstanceEntity
>
instanceList
(
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
)
{
return
getServiceMap
();
return
getInstanceList
(
serviceId
);
}
@RequestMapping
(
path
=
"/console/instance-map"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
value
=
"获取服务注册中心的服务和实例的Map(精简数据)"
,
notes
=
""
,
response
=
Map
.
class
,
httpMethod
=
"GET"
)
@ResponseBody
@ManagedOperation
public
Map
<
String
,
List
<
InstanceEntity
>>
instanceMap
()
{
return
getInstanceMap
();
}
}
public
List
<
String
>
getServices
()
{
public
List
<
String
>
getServices
()
{
...
@@ -72,9 +80,30 @@ public class ConsoleEndpoint implements MvcEndpoint {
...
@@ -72,9 +80,30 @@ public class ConsoleEndpoint implements MvcEndpoint {
return
discoveryClient
.
getInstances
(
serviceId
);
return
discoveryClient
.
getInstances
(
serviceId
);
}
}
public
Map
<
String
,
List
<
ServiceEntity
>>
getServiceMap
()
{
public
List
<
InstanceEntity
>
getInstanceList
(
String
service
)
{
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
service
);
List
<
InstanceEntity
>
instanceEntityList
=
new
ArrayList
<
InstanceEntity
>(
serviceInstances
.
size
());
for
(
ServiceInstance
serviceInstance
:
serviceInstances
)
{
String
serviceId
=
serviceInstance
.
getServiceId
().
toLowerCase
();
String
version
=
serviceInstance
.
getMetadata
().
get
(
"version"
);
String
host
=
serviceInstance
.
getHost
();
int
port
=
serviceInstance
.
getPort
();
InstanceEntity
instanceEntity
=
new
InstanceEntity
();
instanceEntity
.
setServiceId
(
serviceId
);
instanceEntity
.
setVersion
(
version
);
instanceEntity
.
setHost
(
host
);
instanceEntity
.
setPort
(
port
);
instanceEntityList
.
add
(
instanceEntity
);
}
return
instanceEntityList
;
}
public
Map
<
String
,
List
<
InstanceEntity
>>
getInstanceMap
()
{
List
<
String
>
services
=
getServices
();
List
<
String
>
services
=
getServices
();
Map
<
String
,
List
<
ServiceEntity
>>
serviceMap
=
new
LinkedHashMap
<
String
,
List
<
Servi
ceEntity
>>(
services
.
size
());
Map
<
String
,
List
<
InstanceEntity
>>
serviceMap
=
new
LinkedHashMap
<
String
,
List
<
Instan
ceEntity
>>(
services
.
size
());
for
(
String
service
:
services
)
{
for
(
String
service
:
services
)
{
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
service
);
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
service
);
for
(
ServiceInstance
serviceInstance
:
serviceInstances
)
{
for
(
ServiceInstance
serviceInstance
:
serviceInstances
)
{
...
@@ -83,18 +112,18 @@ public class ConsoleEndpoint implements MvcEndpoint {
...
@@ -83,18 +112,18 @@ public class ConsoleEndpoint implements MvcEndpoint {
String
host
=
serviceInstance
.
getHost
();
String
host
=
serviceInstance
.
getHost
();
int
port
=
serviceInstance
.
getPort
();
int
port
=
serviceInstance
.
getPort
();
ServiceEntity
serviceEntity
=
new
Servi
ceEntity
();
InstanceEntity
instanceEntity
=
new
Instan
ceEntity
();
servi
ceEntity
.
setServiceId
(
serviceId
);
instan
ceEntity
.
setServiceId
(
serviceId
);
servi
ceEntity
.
setVersion
(
version
);
instan
ceEntity
.
setVersion
(
version
);
servi
ceEntity
.
setHost
(
host
);
instan
ceEntity
.
setHost
(
host
);
servi
ceEntity
.
setPort
(
port
);
instan
ceEntity
.
setPort
(
port
);
List
<
ServiceEntity
>
servi
ceEntityList
=
serviceMap
.
get
(
service
);
List
<
InstanceEntity
>
instan
ceEntityList
=
serviceMap
.
get
(
service
);
if
(
servi
ceEntityList
==
null
)
{
if
(
instan
ceEntityList
==
null
)
{
serviceEntityList
=
new
ArrayList
<
ServiceEntity
>(
);
instanceEntityList
=
new
ArrayList
<
InstanceEntity
>(
serviceInstances
.
size
()
);
serviceMap
.
put
(
service
,
servi
ceEntityList
);
serviceMap
.
put
(
service
,
instan
ceEntityList
);
}
}
serviceEntityList
.
add
(
servi
ceEntity
);
instanceEntityList
.
add
(
instan
ceEntity
);
}
}
}
}
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/entity/
Servi
ceEntity.java
→
discovery-console/src/main/java/com/nepxion/discovery/console/entity/
Instan
ceEntity.java
View file @
db9b63cd
...
@@ -16,7 +16,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
...
@@ -16,7 +16,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
public
class
Servi
ceEntity
implements
Serializable
{
public
class
Instan
ceEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
3001191508072178378L
;
private
static
final
long
serialVersionUID
=
-
3001191508072178378L
;
private
String
serviceId
;
private
String
serviceId
;
...
...
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