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
d36e1da7
Commit
d36e1da7
authored
Jul 10, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
控制台增加接口
parent
bb0498d0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
2 deletions
+123
-2
discovery-console/pom.xml
+5
-0
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
+44
-2
discovery-console/src/main/java/com/nepxion/discovery/console/entity/ServiceEntity.java
+74
-0
No files found.
discovery-console/pom.xml
View file @
d36e1da7
...
...
@@ -16,6 +16,11 @@
<dependencies>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter
</artifactId>
</dependency>
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
View file @
d36e1da7
...
...
@@ -13,7 +13,10 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
...
...
@@ -28,6 +31,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.nepxion.discovery.console.entity.ServiceEntity
;
@RestController
@Api
(
tags
=
{
"控制台接口"
})
@ManagedResource
(
description
=
"Console Endpoint"
)
...
...
@@ -48,17 +53,54 @@ public class ConsoleEndpoint implements MvcEndpoint {
@ResponseBody
@ManagedOperation
public
List
<
ServiceInstance
>
instances
(
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
)
{
return
getInstanceList
(
serviceId
);
return
getInstances
(
serviceId
);
}
@RequestMapping
(
path
=
"/console/service-map"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
value
=
"获取服务注册中心的服务和实例的Map"
,
notes
=
""
,
response
=
Map
.
class
,
httpMethod
=
"GET"
)
@ResponseBody
@ManagedOperation
public
Map
<
String
,
List
<
ServiceEntity
>>
serviceMap
()
{
return
getServiceMap
();
}
public
List
<
String
>
getServices
()
{
return
discoveryClient
.
getServices
();
}
public
List
<
ServiceInstance
>
getInstance
List
(
String
serviceId
)
{
public
List
<
ServiceInstance
>
getInstance
s
(
String
serviceId
)
{
return
discoveryClient
.
getInstances
(
serviceId
);
}
public
Map
<
String
,
List
<
ServiceEntity
>>
getServiceMap
()
{
List
<
String
>
services
=
getServices
();
Map
<
String
,
List
<
ServiceEntity
>>
serviceMap
=
new
LinkedHashMap
<
String
,
List
<
ServiceEntity
>>(
services
.
size
());
for
(
String
service
:
services
)
{
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
service
);
for
(
ServiceInstance
serviceInstance
:
serviceInstances
)
{
String
serviceId
=
serviceInstance
.
getServiceId
().
toLowerCase
();
String
version
=
serviceInstance
.
getMetadata
().
get
(
"version"
);
String
host
=
serviceInstance
.
getHost
();
int
port
=
serviceInstance
.
getPort
();
ServiceEntity
serviceEntity
=
new
ServiceEntity
();
serviceEntity
.
setServiceId
(
serviceId
);
serviceEntity
.
setVersion
(
version
);
serviceEntity
.
setHost
(
host
);
serviceEntity
.
setPort
(
port
);
List
<
ServiceEntity
>
serviceEntityList
=
serviceMap
.
get
(
service
);
if
(
serviceEntityList
==
null
)
{
serviceEntityList
=
new
ArrayList
<
ServiceEntity
>();
serviceMap
.
put
(
service
,
serviceEntityList
);
}
serviceEntityList
.
add
(
serviceEntity
);
}
}
return
serviceMap
;
}
@Override
public
String
getPath
()
{
return
"/"
;
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/entity/ServiceEntity.java
0 → 100644
View file @
d36e1da7
package
com
.
nepxion
.
discovery
.
console
.
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.io.Serializable
;
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
public
class
ServiceEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
3001191508072178378L
;
private
String
serviceId
;
private
String
version
;
private
String
host
;
private
int
port
;
public
String
getServiceId
()
{
return
serviceId
;
}
public
void
setServiceId
(
String
serviceId
)
{
this
.
serviceId
=
serviceId
;
}
public
String
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
public
String
getHost
()
{
return
host
;
}
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
public
int
getPort
()
{
return
port
;
}
public
void
setPort
(
int
port
)
{
this
.
port
=
port
;
}
@Override
public
int
hashCode
()
{
return
HashCodeBuilder
.
reflectionHashCode
(
this
);
}
@Override
public
boolean
equals
(
Object
object
)
{
return
EqualsBuilder
.
reflectionEquals
(
this
,
object
);
}
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
MULTI_LINE_STYLE
);
}
}
\ 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