Skip to content
This repository was archived by the owner on Jun 29, 2018. It is now read-only.

Commit e1d81ac

Browse files
committed
Merge pull request #67 from joshiste/more-urls
separate health, management and service url
2 parents 0c2cf04 + 742fa8a commit e1d81ac

File tree

25 files changed

+486
-171
lines changed

25 files changed

+486
-171
lines changed

spring-boot-admin-server-ui/app/js/controller/overviewCtrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function ($scope, $location, $interval, $q, Application) {
3030
var getHealth = function (app) {
3131
return app.getHealth()
3232
.success(function (response) {
33-
app.status = response.status;
33+
app.status = response.status || 'UP';
3434
})
3535
.error(function (response, httpStatus) {
3636
if (httpStatus === 503) {
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="navbar">
1+
<div class="navbar" style="margin-bottom: 0px;">
22
<div class="navbar-inner">
33
<span class="brand">{{ application.name }}</span>
44
<ul class="nav pull-right">
@@ -8,7 +8,15 @@
88
<li class="navbar-link" ui-sref-active="active" ><a ui-sref="apps.threads({id: application.id})">Threads</a></li>
99
<li class="navbar-link" ui-sref-active="active" ><a ui-sref="apps.trace({id: application.id})">Trace</a></li>
1010
</ul>
11-
<small class="navbar-text">{{ application.url }}</small>
11+
</div>
12+
</div>
13+
<div class="navbar">
14+
<div class="navbar-inner">
15+
<ul class="nav" style="width: 100%;">
16+
<li style="width: 33%; text-align: center;"><a href="{{ application.serviceUrl }}" title="Service URL"><i class="icon-home" ></i> {{ application.serviceUrl }}</a></li>
17+
<li style="width: 33%; text-align: center;"><a href="{{ application.healthUrl }}" title="Health URL"><i class="icon-heart" ></i> {{ application.healthUrl }}</a></li>
18+
<li style="width: 33%; text-align: center;"><a href="{{ application.managementUrl }}" title="Management URL"><i class="icon-wrench"></i> {{ application.managementUrl }}</a></li>
19+
</ul>
1220
</div>
1321
</div>
1422
<div ui-view></div>

spring-boot-admin-server-ui/app/views/apps/details.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="row">
77
<div class="span6">
88
<table class="table">
9-
<thead><tr><th colspan="2">Application <small class="pull-right"><a href="{{ application.url }}/info">raw JSON</a></small></th></tr></thead>
9+
<thead><tr><th colspan="2">Application <small class="pull-right"><a href="{{ application.managementUrl }}/info">raw JSON</a></small></th></tr></thead>
1010
<tbody>
1111
<tr ng-repeat="(key, value) in info" >
1212
<td>{{ key }}</td><td>{{ value }}</td>
@@ -17,7 +17,7 @@
1717
<div class="span6">
1818
<table class="table">
1919
<thead>
20-
<tr><th colspan="2">Health Checks <small class="pull-right"><a href="{{ application.url }}/health">raw JSON</a></small></th></tr>
20+
<tr><th colspan="2">Health Checks <small class="pull-right"><a href="{{ application.healthUrl }}">raw JSON</a></small></th></tr>
2121
</thead>
2222
<tbody>
2323
<tr><td ng-init="name= 'Application'" ng-include="'health.html'"></td></tr>
@@ -63,7 +63,7 @@
6363

6464
<div class="span6">
6565
<table class="table">
66-
<thead><tr><th colspan="2">JVM <small class="pull-right"><a href="{{ application.url }}/metrics">raw JSON</a></small></th></tr></thead>
66+
<thead><tr><th colspan="2">JVM <small class="pull-right"><a href="{{ application.managementUrl }}/metrics">raw JSON</a></small></th></tr></thead>
6767
<tbody>
6868
<tr ng-if="metrics['systemload.average'] != null && metrics['systemload.average'] >= 0.0">
6969
<td>Systemload</td>

spring-boot-admin-server-ui/app/views/apps/details/classpath.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<col style="width:auto">
44
<thead>
55
<tr>
6-
<th>Classpath <small class="pull-right"><a href="{{ application.url }}/env">raw JSON</a></small></th>
6+
<th>Classpath <small class="pull-right"><a href="{{ application.managementUrl }}/env">raw JSON</a></small></th>
77
</tr>
88
</thead>
99
<tbody>

spring-boot-admin-server-ui/app/views/apps/details/env.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<thead>
55
<tr>
66
<th>Property</th>
7-
<th>Value <small class="pull-right"><a href="{{ application.url }}/env">raw JSON</a></small></th>
7+
<th>Value <small class="pull-right"><a href="{{ application.managementUrl }}/env">raw JSON</a></small></th>
88
</tr>
99
</thead>
1010
<tbody>

spring-boot-admin-server-ui/app/views/apps/details/props.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<thead>
55
<tr>
66
<th>Property</th>
7-
<th>Value <small class="pull-right"><a href="{{ application.url }}/env">raw JSON</a></small></th>
7+
<th>Value <small class="pull-right"><a href="{{ application.managementUrl }}/env">raw JSON</a></small></th>
88
</tr>
99
</thead>
1010
<tbody>

spring-boot-admin-server-ui/app/views/overview.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ <h2 >Spring-Boot applications<br>
1616
</thead>
1717
<tbody>
1818
<tr ng-repeat="application in applications|orderBy:order.column:order.descending|orderBy:'status':false track by application.id">
19-
<td>{{ application.name }}<br/><span class="muted">{{ application.url }}</span></td>
19+
<td>{{ application.name }}<br/><span class="muted">{{ application.serviceUrl || application.managementUrl || application.healthUrl }}</span></td>
2020
<td>{{ application.version }}</td>
2121
<td><span ng-repeat="(name, value) in application.info track by name">{{name}}: {{value}}<br></span></td>
2222
<td><span class="status-{{application.status}}">{{ application.status }}</span>
2323
<span ng-show="application.refreshing" class="refresh"></span></td>
2424
<td style="text-align: right;">
25-
<div class="btn-group" ng-hide="application.status == null || application.status == 'OFFLINE'">
25+
<div class="btn-group" ng-hide="application.managementUrl == null || application.status == null || application.status == 'OFFLINE'">
2626
<a ng-disabled="!application.providesLogfile" target="_self" class="btn btn-success" ng-href="{{application.providesLogfile ? application.url + '/logfile' :''}}"><i class="icon-file icon-white"></i>Log</a>
2727
<a ui-sref="apps.details.metrics({id: application.id})" class="btn btn-success">Details</a>
2828
<a class="btn btn-success dropdown-toggle" data-toggle="dropdown">

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/discovery/ApplicationDiscoveryListener.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public class ApplicationDiscoveryListener implements ApplicationListener<Applica
4040

4141
private String managementContextPath = "";
4242

43+
private String serviceContextPath = "";
44+
45+
private String healthEndpoint = "health";
46+
4347

4448
public ApplicationDiscoveryListener(DiscoveryClient discoveryClient, ApplicationRegistry registry) {
4549
this.discoveryClient = discoveryClient;
@@ -77,13 +81,28 @@ public void discover() {
7781
}
7882

7983
private Application convert(ServiceInstance instance) {
80-
String url = instance.getUri()
81-
.resolve(managementContextPath.startsWith("/") ? managementContextPath : "/" + managementContextPath)
84+
String managementUrl = instance.getUri()
85+
.resolve(managementContextPath)
8286
.toString();
83-
return new Application(url, instance.getServiceId());
87+
String serviceUrl = instance.getUri()
88+
.resolve(serviceContextPath)
89+
.toString();
90+
String healthUrl = managementUrl + "/" + healthEndpoint;
91+
92+
return new Application(healthUrl, managementUrl, serviceUrl, instance.getServiceId());
8493
}
8594

8695
public void setManagementContextPath(String managementContextPath) {
87-
this.managementContextPath = managementContextPath;
96+
this.managementContextPath = managementContextPath.startsWith("/") ? managementContextPath
97+
: "/" + managementContextPath;
98+
}
99+
100+
public void setServiceContextPath(String serviceContextPath) {
101+
this.serviceContextPath = serviceContextPath.startsWith("/") ? serviceContextPath
102+
: "/" + serviceContextPath;
103+
}
104+
105+
public void setHealthEndpoint(String healthEndpoint) {
106+
this.healthEndpoint = healthEndpoint;
88107
}
89108
}

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/registry/ApplicationRegistry.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.slf4j.LoggerFactory;
2525
import org.springframework.context.ApplicationContext;
2626
import org.springframework.context.ApplicationContextAware;
27+
import org.springframework.util.Assert;
28+
import org.springframework.util.StringUtils;
2729

2830
import de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent;
2931
import de.codecentric.boot.admin.event.ClientApplicationUnregisteredEvent;
@@ -53,21 +55,30 @@ public ApplicationRegistry(ApplicationStore store, ApplicationIdGenerator genera
5355
* @return the registered application.
5456
*/
5557
public Application register(Application app) {
56-
Validate.notNull(app, "Application must not be null");
57-
Validate.notNull(app.getUrl(), "URL must not be null");
58-
Validate.isTrue(checkUrl(app.getUrl()), "URL is not valid");
58+
Assert.notNull(app, "Application must not be null");
59+
Assert.hasText(app.getName(), "Name must not be null");
60+
Assert.hasText(app.getHealthUrl(), "Health-URL must not be null");
61+
Assert.isTrue(checkUrl(app.getHealthUrl()), "Health-URL is not valid");
62+
Assert.isTrue(
63+
StringUtils.isEmpty(app.getManagementUrl())
64+
|| checkUrl(app.getManagementUrl()), "URL is not valid");
65+
Assert.isTrue(
66+
StringUtils.isEmpty(app.getServiceUrl()) || checkUrl(app.getServiceUrl()),
67+
"URL is not valid");
5968

6069
String applicationId = generator.generateId(app);
6170
Validate.notNull(applicationId, "ID must not be null");
6271

63-
Application newApp = new Application(app.getUrl(), app.getName(), applicationId);
72+
Application newApp = new Application(app.getHealthUrl(), app.getManagementUrl(),
73+
app.getServiceUrl(), app.getName(), applicationId);
6474
Application oldApp = store.save(newApp);
6575

6676
if (oldApp == null) {
6777
LOGGER.info("New Application {} registered ", newApp);
6878
context.publishEvent(new ClientApplicationRegisteredEvent(this, newApp));
6979
} else {
70-
if ((app.getUrl().equals(oldApp.getUrl()) && app.getName().equals(oldApp.getName()))) {
80+
if ((newApp.getId().equals(oldApp.getId()) && app.getName().equals(
81+
oldApp.getName()))) {
7182
LOGGER.debug("Application {} refreshed", newApp);
7283
} else {
7384
LOGGER.warn("Application {} replaced by Application {}", newApp, oldApp);

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/registry/HashingApplicationUrlIdGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public class HashingApplicationUrlIdGenerator implements ApplicationIdGenerator
3232
public String generateId(Application a) {
3333
try {
3434
MessageDigest digest = MessageDigest.getInstance("SHA-1");
35-
byte[] bytes = digest.digest(a.getUrl().getBytes(StandardCharsets.UTF_8));
35+
byte[] bytes = digest.digest(a.getHealthUrl()
36+
.getBytes(StandardCharsets.UTF_8));
3637
return new String(encodeHex(bytes, 0, 8));
3738
}
3839
catch (NoSuchAlgorithmException e) {

0 commit comments

Comments
 (0)