1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.web.health;
17
18 import org.codehaus.jackson.annotate.JsonIgnore;
19 import org.codehaus.jackson.annotate.JsonProperty;
20 import org.codehaus.jackson.map.annotate.JsonSerialize;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25
26
27
28
29
30
31
32
33 public class HealthStatus {
34
35 public static final String OK = "Ok";
36 public static final String FAILED = "Failed";
37
38 @JsonProperty("Status")
39 private String statusCode;
40
41 @JsonProperty("Message")
42 @JsonSerialize(include=JsonSerialize.Inclusion.NON_EMPTY)
43 private String message;
44
45 @JsonProperty("Metrics")
46 private List<HealthMetric> metrics;
47
48 public HealthStatus() {
49 this(OK);
50 }
51
52 public HealthStatus(String statusCode) {
53 setStatusCode(statusCode);
54 setMetrics(new ArrayList<HealthMetric>());
55 }
56
57 @JsonIgnore
58 public boolean isOk() {
59 return OK.equals(statusCode);
60 }
61
62 public String getStatusCode() {
63 return statusCode;
64 }
65
66 public void setStatusCode(String statusCode) {
67 if (!statusCode.equals(OK) && !statusCode.equals(FAILED)) {
68 throw new IllegalArgumentException("Status code must be one of '" + OK + "' or '" + FAILED + "'");
69 }
70 this.statusCode = statusCode;
71 }
72
73 public String getMessage() {
74 return message;
75 }
76
77 public void setMessage(String message) {
78 this.message = message;
79 }
80
81 public List<HealthMetric> getMetrics() {
82 return metrics;
83 }
84
85 public void setMetrics(List<HealthMetric> metrics) {
86 if (metrics == null) {
87 throw new IllegalArgumentException("metrics list must not be null");
88 }
89 this.metrics = metrics;
90 }
91
92 public void appendMessage(String metricName, String message) {
93 String fullMessage = "* " + metricName + " -> " + message;
94 if (getMessage() == null) {
95 setMessage(fullMessage);
96 } else {
97 setMessage(getMessage() + " " + fullMessage);
98 }
99 }
100
101 }