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

Commit 6967ddd

Browse files
committed
Make StatusUpdater more robust
Check if the status field is a String and don't propagate any Exception from the StatusUpdater, so that the application don't fail like in #120
1 parent 4726285 commit 6967ddd

File tree

1 file changed

+6
-9
lines changed
  • spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/registry

1 file changed

+6
-9
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.context.ApplicationEventPublisher;
2323
import org.springframework.context.ApplicationEventPublisherAware;
2424
import org.springframework.http.ResponseEntity;
25-
import org.springframework.web.client.RestClientException;
2625
import org.springframework.web.client.RestTemplate;
2726

2827
import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent;
@@ -34,7 +33,7 @@
3433
* The StatusUpdater is responsible for updatig the status of all or a single
3534
* application querying the healthUrl.
3635
*
37-
* @author Johannes Stelzer
36+
* @author Johannes Edmeier
3837
*
3938
*/
4039
public class StatusUpdater implements ApplicationEventPublisherAware {
@@ -50,7 +49,6 @@ public class StatusUpdater implements ApplicationEventPublisherAware {
5049
*/
5150
private long statusLifetime = 30_000L;
5251

53-
5452
public StatusUpdater(RestTemplate restTemplate, ApplicationStore store) {
5553
this.restTemplate = restTemplate;
5654
this.store = store;
@@ -59,7 +57,7 @@ public StatusUpdater(RestTemplate restTemplate, ApplicationStore store) {
5957
public void updateStatusForAllApplications() {
6058
long now = System.currentTimeMillis();
6159
for (Application application : store.findAll()) {
62-
if ( now - statusLifetime > application.getStatusInfo().getTimestamp()) {
60+
if (now - statusLifetime > application.getStatusInfo().getTimestamp()) {
6361
updateStatus(application);
6462
}
6563
}
@@ -85,18 +83,18 @@ private StatusInfo queryStatus(Application application) {
8583

8684
try {
8785
@SuppressWarnings("unchecked")
88-
ResponseEntity<Map<String, String>> response = restTemplate.getForEntity(application.getHealthUrl(), (Class<Map<String, String>>)(Class<?>) Map.class);
86+
ResponseEntity<Map<String, Object>> response = restTemplate.getForEntity(application.getHealthUrl(), (Class<Map<String, Object>>)(Class<?>) Map.class);
8987
LOGGER.debug("/health for {} responded with {}", application, response);
9088

91-
if (response.hasBody() && response.getBody().get("status") != null ) {
92-
return StatusInfo.valueOf(response.getBody().get("status"));
89+
if (response.hasBody() && response.getBody().get("status") instanceof String) {
90+
return StatusInfo.valueOf((String) response.getBody().get("status"));
9391
} else if (response.getStatusCode().is2xxSuccessful()) {
9492
return StatusInfo.ofUp();
9593
} else {
9694
return StatusInfo.ofDown();
9795
}
9896

99-
} catch (RestClientException ex){
97+
} catch (Exception ex){
10098
LOGGER.warn("Couldn't retrieve status for {}", application, ex);
10199
return StatusInfo.ofOffline();
102100
}
@@ -111,5 +109,4 @@ public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
111109
this.publisher = publisher;
112110
}
113111

114-
115112
}

0 commit comments

Comments
 (0)