Added a time stamp to the cluster stats response

Making it consistent with NodeStats
This commit is contained in:
Boaz Leskes 2013-12-17 16:04:55 +01:00
parent d97a00d4a7
commit 33bb2ecfa8
3 changed files with 13 additions and 3 deletions

View File

@ -37,22 +37,27 @@ import java.util.Map;
*/
public class ClusterStatsResponse extends NodesOperationResponse<ClusterStatsNodeResponse> implements ToXContent {
ClusterStatsNodes nodesStats;
ClusterStatsIndices indicesStats;
String clusterUUID;
long timestamp;
ClusterStatsResponse() {
}
public ClusterStatsResponse(ClusterName clusterName, String clusterUUID, ClusterStatsNodeResponse[] nodes) {
public ClusterStatsResponse(long timestamp, ClusterName clusterName, String clusterUUID, ClusterStatsNodeResponse[] nodes) {
super(clusterName, null);
this.timestamp = timestamp;
this.clusterUUID = clusterUUID;
nodesStats = new ClusterStatsNodes(nodes);
indicesStats = new ClusterStatsIndices(nodes);
}
public long getTimestamp() {
return this.timestamp;
}
public ClusterStatsNodes getNodesStats() {
return nodesStats;
}
@ -84,6 +89,7 @@ public class ClusterStatsResponse extends NodesOperationResponse<ClusterStatsNod
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
timestamp = in.readVLong();
clusterUUID = in.readString();
nodesStats = ClusterStatsNodes.readNodeStats(in);
indicesStats = ClusterStatsIndices.readIndicesStats(in);
@ -92,6 +98,7 @@ public class ClusterStatsResponse extends NodesOperationResponse<ClusterStatsNod
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVLong(timestamp);
out.writeString(clusterUUID);
nodesStats.writeTo(out);
indicesStats.writeTo(out);
@ -106,6 +113,7 @@ public class ClusterStatsResponse extends NodesOperationResponse<ClusterStatsNod
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("timestamp", getTimestamp());
builder.field(Fields.CLUSTER_NAME, getClusterName().value());
if (params.paramAsBoolean("output_uuid", false)) {
builder.field(Fields.UUID, clusterUUID);

View File

@ -86,7 +86,8 @@ public class TransportClusterStatsAction extends TransportNodesOperationAction<C
nodeStats.add((ClusterStatsNodeResponse) resp);
}
}
return new ClusterStatsResponse(clusterName, clusterService.state().metaData().uuid(), nodeStats.toArray(new ClusterStatsNodeResponse[nodeStats.size()]));
return new ClusterStatsResponse(System.currentTimeMillis(), clusterName,
clusterService.state().metaData().uuid(), nodeStats.toArray(new ClusterStatsNodeResponse[nodeStats.size()]));
}
@Override

View File

@ -112,6 +112,7 @@ public class ClusterStatsTests extends ElasticsearchIntegrationTest {
index("test1", "type", "1", "f", "f");
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
assertThat(response.getTimestamp(), Matchers.greaterThan(946681200000l)); // 1 Jan 2000
assertThat(response.indicesStats.getStore().getSizeInBytes(), Matchers.greaterThan(0l));
assertThat(response.nodesStats.getFs().getTotal().bytes(), Matchers.greaterThan(0l));