Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-boot-admin
Commits
137e2838
Commit
137e2838
authored
Sep 02, 2017
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unwanted commons-lang usage in DefaultServiceInstanceConverter
parent
d35c1505
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
102 deletions
+109
-102
DefaultServiceInstanceConverter.java
...boot/admin/discovery/DefaultServiceInstanceConverter.java
+101
-94
ApplicationDiscoveryListenerTest.java
...oot/admin/discovery/ApplicationDiscoveryListenerTest.java
+2
-2
DefaultServiceInstanceConverterTest.java
.../admin/discovery/DefaultServiceInstanceConverterTest.java
+4
-4
EurekaServiceInstanceConverterTest.java
...t/admin/discovery/EurekaServiceInstanceConverterTest.java
+2
-2
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/discovery/DefaultServiceInstanceConverter.java
View file @
137e2838
...
...
@@ -15,8 +15,6 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
discovery
;
import
static
org
.
apache
.
commons
.
lang
.
StringUtils
.
defaultIfEmpty
;
import
static
org
.
apache
.
commons
.
lang
.
StringUtils
.
stripStart
;
import
java.net.URI
;
import
java.util.Map
;
...
...
@@ -24,10 +22,14 @@ import java.util.Map;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
org.springframework.web.util.UriUtils
;
import
de.codecentric.boot.admin.model.Application
;
import
static
org
.
springframework
.
util
.
StringUtils
.*;
/**
* Converts any {@link ServiceInstance}s to {@link Application}s. To customize the health- or
* management-url for all applications you can set healthEndpointPath or managementContextPath
...
...
@@ -38,96 +40,101 @@ import de.codecentric.boot.admin.model.Application;
* @author Johannes Edmeier
*/
public
class
DefaultServiceInstanceConverter
implements
ServiceInstanceConverter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DefaultServiceInstanceConverter
.
class
);
private
static
final
String
KEY_MANAGEMENT_PORT
=
"management.port"
;
private
static
final
String
KEY_MANAGEMENT_PATH
=
"management.context-path"
;
private
static
final
String
KEY_HEALTH_PATH
=
"health.path"
;
/**
* Default context-path to be appended to the url of the discovered service for the
* managment-url.
*/
private
String
managementContextPath
=
""
;
/**
* Default path of the health-endpoint to be used for the health-url of the discovered service.
*/
private
String
healthEndpointPath
=
"health"
;
@Override
public
Application
convert
(
ServiceInstance
instance
)
{
LOGGER
.
debug
(
"Converting service '{}' running at '{}' with metadata {}"
,
instance
.
getServiceId
(),
instance
.
getUri
(),
instance
.
getMetadata
());
Application
.
Builder
builder
=
Application
.
create
(
instance
.
getServiceId
());
URI
healthUrl
=
getHealthUrl
(
instance
);
if
(
healthUrl
!=
null
)
{
builder
.
withHealthUrl
(
healthUrl
.
toString
());
}
URI
managementUrl
=
getManagementUrl
(
instance
);
if
(
managementUrl
!=
null
)
{
builder
.
withManagementUrl
(
managementUrl
.
toString
());
}
URI
serviceUrl
=
getServiceUrl
(
instance
);
if
(
serviceUrl
!=
null
)
{
builder
.
withServiceUrl
(
serviceUrl
.
toString
());
}
Map
<
String
,
String
>
metadata
=
getMetadata
(
instance
);
if
(
metadata
!=
null
)
{
builder
.
withMetadata
(
metadata
);
}
return
builder
.
build
();
}
protected
URI
getHealthUrl
(
ServiceInstance
instance
)
{
String
healthPath
=
defaultIfEmpty
(
instance
.
getMetadata
().
get
(
KEY_HEALTH_PATH
),
healthEndpointPath
);
healthPath
=
stripStart
(
healthPath
,
"/"
);
return
UriComponentsBuilder
.
fromUri
(
getManagementUrl
(
instance
)).
pathSegment
(
healthPath
)
.
build
().
toUri
();
}
protected
URI
getManagementUrl
(
ServiceInstance
instance
)
{
String
managamentPath
=
defaultIfEmpty
(
instance
.
getMetadata
().
get
(
KEY_MANAGEMENT_PATH
),
managementContextPath
);
managamentPath
=
stripStart
(
managamentPath
,
"/"
);
URI
serviceUrl
=
getServiceUrl
(
instance
);
String
managamentPort
=
defaultIfEmpty
(
instance
.
getMetadata
().
get
(
KEY_MANAGEMENT_PORT
),
String
.
valueOf
(
serviceUrl
.
getPort
()));
return
UriComponentsBuilder
.
fromUri
(
serviceUrl
).
port
(
managamentPort
)
.
pathSegment
(
managamentPath
).
build
().
toUri
();
}
protected
URI
getServiceUrl
(
ServiceInstance
instance
)
{
return
instance
.
getUri
();
}
protected
Map
<
String
,
String
>
getMetadata
(
ServiceInstance
instance
)
{
return
instance
.
getMetadata
();
}
public
void
setManagementContextPath
(
String
managementContextPath
)
{
this
.
managementContextPath
=
managementContextPath
;
}
public
String
getManagementContextPath
()
{
return
managementContextPath
;
}
public
void
setHealthEndpointPath
(
String
healthEndpointPath
)
{
this
.
healthEndpointPath
=
healthEndpointPath
;
}
public
String
getHealthEndpointPath
()
{
return
healthEndpointPath
;
}
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DefaultServiceInstanceConverter
.
class
);
private
static
final
String
KEY_MANAGEMENT_PORT
=
"management.port"
;
private
static
final
String
KEY_MANAGEMENT_PATH
=
"management.context-path"
;
private
static
final
String
KEY_HEALTH_PATH
=
"health.path"
;
/**
* Default context-path to be appended to the url of the discovered service for the
* managment-url.
*/
private
String
managementContextPath
=
""
;
/**
* Default path of the health-endpoint to be used for the health-url of the discovered service.
*/
private
String
healthEndpointPath
=
"health"
;
@Override
public
Application
convert
(
ServiceInstance
instance
)
{
LOGGER
.
debug
(
"Converting service '{}' running at '{}' with metadata {}"
,
instance
.
getServiceId
(),
instance
.
getUri
(),
instance
.
getMetadata
());
Application
.
Builder
builder
=
Application
.
create
(
instance
.
getServiceId
());
URI
healthUrl
=
getHealthUrl
(
instance
);
if
(
healthUrl
!=
null
)
{
builder
.
withHealthUrl
(
healthUrl
.
toString
());
}
URI
managementUrl
=
getManagementUrl
(
instance
);
if
(
managementUrl
!=
null
)
{
builder
.
withManagementUrl
(
managementUrl
.
toString
());
}
URI
serviceUrl
=
getServiceUrl
(
instance
);
if
(
serviceUrl
!=
null
)
{
builder
.
withServiceUrl
(
serviceUrl
.
toString
());
}
Map
<
String
,
String
>
metadata
=
getMetadata
(
instance
);
if
(
metadata
!=
null
)
{
builder
.
withMetadata
(
metadata
);
}
return
builder
.
build
();
}
protected
URI
getHealthUrl
(
ServiceInstance
instance
)
{
String
healthPath
=
instance
.
getMetadata
().
get
(
KEY_HEALTH_PATH
);
if
(
isEmpty
(
healthPath
))
{
healthPath
=
healthEndpointPath
;
}
return
UriComponentsBuilder
.
fromUri
(
getManagementUrl
(
instance
)).
path
(
"/"
).
path
(
healthPath
).
build
().
toUri
();
}
protected
URI
getManagementUrl
(
ServiceInstance
instance
)
{
String
managamentPath
=
instance
.
getMetadata
().
get
(
KEY_MANAGEMENT_PATH
);
if
(
isEmpty
(
managamentPath
))
{
managamentPath
=
managementContextPath
;
}
URI
serviceUrl
=
getServiceUrl
(
instance
);
String
managamentPort
=
instance
.
getMetadata
().
get
(
KEY_MANAGEMENT_PORT
);
if
(
isEmpty
(
managamentPort
))
{
managamentPort
=
String
.
valueOf
(
serviceUrl
.
getPort
());
}
return
UriComponentsBuilder
.
fromUri
(
serviceUrl
)
.
port
(
managamentPort
)
.
path
(
"/"
)
.
path
(
managamentPath
)
.
build
()
.
toUri
();
}
protected
URI
getServiceUrl
(
ServiceInstance
instance
)
{
return
UriComponentsBuilder
.
fromUri
(
instance
.
getUri
()).
path
(
"/"
).
build
().
toUri
();
}
protected
Map
<
String
,
String
>
getMetadata
(
ServiceInstance
instance
)
{
return
instance
.
getMetadata
();
}
public
void
setManagementContextPath
(
String
managementContextPath
)
{
this
.
managementContextPath
=
managementContextPath
;
}
public
String
getManagementContextPath
()
{
return
managementContextPath
;
}
public
void
setHealthEndpointPath
(
String
healthEndpointPath
)
{
this
.
healthEndpointPath
=
healthEndpointPath
;
}
public
String
getHealthEndpointPath
()
{
return
healthEndpointPath
;
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/discovery/ApplicationDiscoveryListenerTest.java
View file @
137e2838
...
...
@@ -145,8 +145,8 @@ public class ApplicationDiscoveryListenerTest {
Application
application
=
registry
.
getApplications
().
iterator
().
next
();
assertEquals
(
"http://localhost:80/health"
,
application
.
getHealthUrl
());
assertEquals
(
"http://localhost:80"
,
application
.
getManagementUrl
());
assertEquals
(
"http://localhost:80"
,
application
.
getServiceUrl
());
assertEquals
(
"http://localhost:80
/
"
,
application
.
getManagementUrl
());
assertEquals
(
"http://localhost:80
/
"
,
application
.
getServiceUrl
());
assertEquals
(
"service"
,
application
.
getName
());
}
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/discovery/DefaultServiceInstanceConverterTest.java
View file @
137e2838
...
...
@@ -22,8 +22,8 @@ public class DefaultServiceInstanceConverterTest {
assertThat
(
application
.
getId
(),
nullValue
());
assertThat
(
application
.
getName
(),
is
(
"test"
));
assertThat
(
application
.
getServiceUrl
(),
is
(
"http://localhost:80"
));
assertThat
(
application
.
getManagementUrl
(),
is
(
"http://localhost:80"
));
assertThat
(
application
.
getServiceUrl
(),
is
(
"http://localhost:80
/
"
));
assertThat
(
application
.
getManagementUrl
(),
is
(
"http://localhost:80
/
"
));
assertThat
(
application
.
getHealthUrl
(),
is
(
"http://localhost:80/health"
));
}
...
...
@@ -38,7 +38,7 @@ public class DefaultServiceInstanceConverterTest {
assertThat
(
application
.
getId
(),
nullValue
());
assertThat
(
application
.
getName
(),
is
(
"test"
));
assertThat
(
application
.
getServiceUrl
(),
is
(
"http://localhost:80"
));
assertThat
(
application
.
getServiceUrl
(),
is
(
"http://localhost:80
/
"
));
assertThat
(
application
.
getManagementUrl
(),
is
(
"http://localhost:80/mgmt"
));
assertThat
(
application
.
getHealthUrl
(),
is
(
"http://localhost:80/mgmt/ping"
));
}
...
...
@@ -56,7 +56,7 @@ public class DefaultServiceInstanceConverterTest {
assertThat
(
application
.
getId
(),
nullValue
());
assertThat
(
application
.
getName
(),
is
(
"test"
));
assertThat
(
application
.
getServiceUrl
(),
is
(
"http://localhost:80"
));
assertThat
(
application
.
getServiceUrl
(),
is
(
"http://localhost:80
/
"
));
assertThat
(
application
.
getManagementUrl
(),
is
(
"http://localhost:1234/mgmt"
));
assertThat
(
application
.
getHealthUrl
(),
is
(
"http://localhost:1234/mgmt/ping"
));
assertThat
(
application
.
getMetadata
(),
is
(
metadata
));
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/discovery/EurekaServiceInstanceConverterTest.java
View file @
137e2838
...
...
@@ -33,7 +33,7 @@ public class EurekaServiceInstanceConverterTest {
assertThat
(
application
.
getId
(),
nullValue
());
assertThat
(
application
.
getName
(),
is
(
"test"
));
assertThat
(
application
.
getServiceUrl
(),
is
(
"http://localhost:80"
));
assertThat
(
application
.
getServiceUrl
(),
is
(
"http://localhost:80
/
"
));
assertThat
(
application
.
getManagementUrl
(),
is
(
"http://localhost:80/mgmt"
));
assertThat
(
application
.
getHealthUrl
(),
is
(
"http://localhost:80/mgmt/ping"
));
}
...
...
@@ -49,7 +49,7 @@ public class EurekaServiceInstanceConverterTest {
Application
application
=
new
EurekaServiceInstanceConverter
().
convert
(
service
);
assertThat
(
application
.
getManagementUrl
(),
is
(
"http://localhost:80"
));
assertThat
(
application
.
getManagementUrl
(),
is
(
"http://localhost:80
/
"
));
}
@Test
...
...
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