Skip to content

Commit 1f52965

Browse files
committed
Merge pull request #9 from ArpNetworking/update_status
merge status response into cluster status response
2 parents e826be6 + d9c911e commit 1f52965

File tree

2 files changed

+128
-25
lines changed

2 files changed

+128
-25
lines changed

src/main/java/com/arpnetworking/clusteraggregator/http/Routes.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
import com.fasterxml.jackson.databind.ObjectMapper;
4646
import com.fasterxml.jackson.databind.SerializerProvider;
4747
import com.fasterxml.jackson.databind.module.SimpleModule;
48-
import com.google.common.base.Charsets;
49-
import com.google.common.io.Resources;
5048
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
5149
import scala.compat.java8.FutureConverters;
5250
import scala.concurrent.Future;
@@ -131,11 +129,6 @@ private CompletionStage<HttpResponse> process(final HttpRequest request) {
131129
+ (isHealthy ? HEALTHY_STATE : UNHEALTHY_STATE)
132130
+ "\"}")));
133131
} else if (_statusPath.equals(request.getUri().path())) {
134-
return CompletableFuture.completedFuture(
135-
HttpResponse.create()
136-
.withStatus(StatusCodes.OK)
137-
.withEntity(JSON_CONTENT_TYPE, ByteString.fromString(STATUS_JSON)));
138-
} else if (STATUS_PATH.equals(request.getUri().path())) {
139132
return ask("/user/status", new Status.StatusRequest(), (StatusResponse) null)
140133
.thenApply(
141134
status -> {
@@ -197,29 +190,11 @@ private String createTimerName(final HttpRequest request) {
197190
CacheDirectives.MUST_REVALIDATE);
198191
private static final String UNHEALTHY_STATE = "UNHEALTHY";
199192
private static final String HEALTHY_STATE = "HEALTHY";
200-
private static final String STATUS_JSON;
201193

202194
private static final ContentType JSON_CONTENT_TYPE = ContentTypes.APPLICATION_JSON;
203195

204196
private static final long serialVersionUID = -1573473630801540757L;
205197

206-
static {
207-
String statusJson = "{}";
208-
try {
209-
statusJson = Resources.toString(Resources.getResource("status.json"), Charsets.UTF_8);
210-
// CHECKSTYLE.OFF: IllegalCatch - Prevent program shutdown
211-
} catch (final Exception e) {
212-
// CHECKSTYLE.ON: IllegalCatch
213-
LOGGER.error()
214-
.setMessage("Resource load failure")
215-
.addData("resource", "status.json")
216-
.setThrowable(e)
217-
.log();
218-
}
219-
STATUS_JSON = statusJson;
220-
221-
}
222-
223198
private static class MemberSerializer extends JsonSerializer<Member> {
224199
@Override
225200
public void serialize(

src/main/java/com/arpnetworking/clusteraggregator/models/StatusResponse.java

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@
1919
import akka.cluster.Member;
2020
import com.arpnetworking.clusteraggregator.ClusterStatusCache;
2121
import com.arpnetworking.commons.builder.OvalBuilder;
22+
import com.arpnetworking.commons.jackson.databind.ObjectMapperFactory;
23+
import com.arpnetworking.steno.Logger;
24+
import com.arpnetworking.steno.LoggerFactory;
2225
import com.fasterxml.jackson.annotation.JsonProperty;
2326
import com.fasterxml.jackson.core.JsonGenerator;
2427
import com.fasterxml.jackson.databind.JsonSerializer;
2528
import com.fasterxml.jackson.databind.SerializerProvider;
2629
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
30+
import com.google.common.base.Charsets;
2731
import com.google.common.base.Optional;
2832
import com.google.common.collect.Iterables;
33+
import com.google.common.io.Resources;
34+
import net.sf.oval.constraint.NotEmpty;
35+
import net.sf.oval.constraint.NotNull;
2936
import org.joda.time.Period;
3037
import scala.collection.JavaConversions;
3138

@@ -70,6 +77,18 @@ public Optional<List<ShardAllocation>> getAllocations() {
7077
return _allocations.transform(Collections::unmodifiableList);
7178
}
7279

80+
public String getVersion() {
81+
return VERSION_INFO.getVersion();
82+
}
83+
84+
public String getName() {
85+
return VERSION_INFO.getName();
86+
}
87+
88+
public String getSha() {
89+
return VERSION_INFO.getSha();
90+
}
91+
7392
private StatusResponse(final Builder builder) {
7493
if (builder._clusterState == null) {
7594
_clusterLeader = null;
@@ -101,6 +120,31 @@ private <T> Optional<T> flatten(final Optional<Optional<T>> value) {
101120
private final Map<Period, PeriodMetrics> _localMetrics;
102121
private final Optional<List<ShardAllocation>> _allocations;
103122

123+
private static final VersionInfo VERSION_INFO;
124+
private static final Logger LOGGER = LoggerFactory.getLogger(StatusResponse.class);
125+
126+
static {
127+
StatusResponse.VersionInfo versionInfo = null;
128+
try {
129+
versionInfo =
130+
ObjectMapperFactory.getInstance().readValue(
131+
Resources.toString(Resources.getResource("status.json"), Charsets.UTF_8),
132+
StatusResponse.VersionInfo.class);
133+
} catch (final IOException e) {
134+
LOGGER.error()
135+
.setMessage("Resource load failure")
136+
.addData("resource", "status.json")
137+
.setThrowable(e)
138+
.log();
139+
versionInfo = new StatusResponse.VersionInfo.Builder()
140+
.setVersion("UNKNOWN")
141+
.setName("UNKNOWN")
142+
.setSha("")
143+
.build();
144+
}
145+
VERSION_INFO = versionInfo;
146+
}
147+
104148
/**
105149
* Builder for a {@link StatusResponse}.
106150
*/
@@ -162,6 +206,90 @@ public Builder setLocalMetrics(final Map<Period, PeriodMetrics> value) {
162206
private Map<Period, PeriodMetrics> _localMetrics;
163207
}
164208

209+
/**
210+
* Represents the model for the version of the service currently running.
211+
*
212+
* @author Brandon Arp (brandon dot arp at smartsheet dot com)
213+
*/
214+
private static final class VersionInfo {
215+
public String getName() {
216+
return _name;
217+
}
218+
219+
public String getVersion() {
220+
return _version;
221+
}
222+
223+
public String getSha() {
224+
return _sha;
225+
}
226+
227+
private VersionInfo(final Builder builder) {
228+
_name = builder._name;
229+
_version = builder._version;
230+
_sha = builder._sha;
231+
}
232+
233+
private String _name;
234+
private String _version;
235+
private String _sha;
236+
237+
/**
238+
* Builder for a {@link VersionInfo}.
239+
*/
240+
private static final class Builder extends OvalBuilder<VersionInfo> {
241+
/**
242+
* Public constructor.
243+
*/
244+
private Builder() {
245+
super(VersionInfo::new);
246+
}
247+
248+
/**
249+
* Sets the name of the application. Required. Cannot be null. Cannot be empty.
250+
*
251+
* @param value The name of the application.
252+
* @return This builder.
253+
*/
254+
public Builder setName(final String value) {
255+
_name = value;
256+
return this;
257+
}
258+
259+
/**
260+
* Sets the name or tag of the version. Required. Cannot be null. Cannot be empty.
261+
*
262+
* @param value The name of the version.
263+
* @return This builder.
264+
*/
265+
public Builder setVersion(final String value) {
266+
_version = value;
267+
return this;
268+
}
269+
270+
/**
271+
* Sets the SHA. Required. Cannot be null. Cannot be empty.
272+
*
273+
* @param value The SHA.
274+
* @return This builder.
275+
*/
276+
public Builder setSha(final String value) {
277+
_sha = value;
278+
return this;
279+
}
280+
281+
@NotNull
282+
@NotEmpty
283+
private String _name;
284+
@NotNull
285+
@NotEmpty
286+
private String _version;
287+
@NotNull
288+
@NotEmpty
289+
private String _sha;
290+
}
291+
}
292+
165293
private static final class MemberSerializer extends JsonSerializer<Member> {
166294
/**
167295
* {@inheritDoc}

0 commit comments

Comments
 (0)