Marvel: Remove and clean payload stuff

Closes elastic/elasticsearch#476

Original commit: elastic/x-pack-elasticsearch@9e90fe26f6
This commit is contained in:
Tanguy Leroux 2015-08-20 10:24:20 +02:00
parent 8bb35cd6c3
commit 392398c7aa
31 changed files with 201 additions and 364 deletions

View File

@ -54,9 +54,13 @@ public abstract class AbstractCollector<T> extends AbstractLifecycleComponent<T>
return false;
}
protected boolean localNodeMaster() {
return clusterService.state().nodes().localNodeMaster();
}
@Override
public Collection<MarvelDoc> collect() {
if (masterOnly() && !clusterService.state().nodes().localNodeMaster()) {
if (masterOnly() && !localNodeMaster()) {
logger.trace("collector [{}] runs on master only", name());
return null;
}

View File

@ -7,7 +7,6 @@ package org.elasticsearch.marvel.agent.collector.cluster;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -50,11 +49,7 @@ public class ClusterStateCollector extends AbstractCollector<ClusterStateCollect
ClusterState clusterState = clusterService.state();
ClusterHealthResponse clusterHealth = client.admin().cluster().prepareHealth().get(marvelSettings.clusterStateTimeout());
results.add(buildMarvelDoc(clusterUUID(), TYPE, System.currentTimeMillis(), clusterState, clusterHealth.getStatus()));
results.add(new ClusterStateMarvelDoc(clusterUUID(), TYPE, System.currentTimeMillis(), clusterState, clusterHealth.getStatus()));
return results.build();
}
protected MarvelDoc buildMarvelDoc(String clusterUUID, String type, long timestamp, ClusterState clusterState, ClusterHealthStatus status) {
return ClusterStateMarvelDoc.createMarvelDoc(clusterUUID, type, timestamp, clusterState, status);
}
}

View File

@ -9,40 +9,22 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
public class ClusterStateMarvelDoc extends MarvelDoc<ClusterStateMarvelDoc.Payload> {
public class ClusterStateMarvelDoc extends MarvelDoc {
private final Payload payload;
private final ClusterState clusterState;
private final ClusterHealthStatus status;
public ClusterStateMarvelDoc(String clusterUUID, String type, long timestamp, Payload payload) {
public ClusterStateMarvelDoc(String clusterUUID, String type, long timestamp, ClusterState clusterState, ClusterHealthStatus status) {
super(clusterUUID, type, timestamp);
this.payload = payload;
this.clusterState = clusterState;
this.status = status;
}
@Override
public ClusterStateMarvelDoc.Payload payload() {
return payload;
public ClusterState getClusterState() {
return clusterState;
}
public static ClusterStateMarvelDoc createMarvelDoc(String clusterUUID, String type, long timestamp, ClusterState clusterState, ClusterHealthStatus status) {
return new ClusterStateMarvelDoc(clusterUUID, type, timestamp, new Payload(clusterState, status));
}
public static class Payload {
private final ClusterState clusterState;
private final ClusterHealthStatus status;
Payload(ClusterState clusterState, ClusterHealthStatus status) {
this.clusterState = clusterState;
this.status = status;
}
public ClusterState getClusterState() {
return clusterState;
}
public ClusterHealthStatus getStatus() {
return status;
}
public ClusterHealthStatus getStatus() {
return status;
}
}

View File

@ -46,11 +46,7 @@ public class ClusterStatsCollector extends AbstractCollector<ClusterStatsCollect
ImmutableList.Builder<MarvelDoc> results = ImmutableList.builder();
ClusterStatsResponse clusterStatsResponse = client.admin().cluster().prepareClusterStats().get(marvelSettings.clusterStatsTimeout());
results.add(buildMarvelDoc(clusterUUID(), TYPE, System.currentTimeMillis(), clusterStatsResponse));
results.add(new ClusterStatsMarvelDoc(clusterUUID(), TYPE, System.currentTimeMillis(), clusterStatsResponse));
return results.build();
}
protected MarvelDoc buildMarvelDoc(String clusterUUID, String type, long timestamp, ClusterStatsResponse clusterStatsResponse) {
return ClusterStatsMarvelDoc.createMarvelDoc(clusterUUID, type, timestamp, clusterStatsResponse);
}
}

View File

@ -8,34 +8,16 @@ package org.elasticsearch.marvel.agent.collector.cluster;
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
public class ClusterStatsMarvelDoc extends MarvelDoc<ClusterStatsMarvelDoc.Payload> {
public class ClusterStatsMarvelDoc extends MarvelDoc {
private final Payload payload;
private final ClusterStatsResponse clusterStats;
public ClusterStatsMarvelDoc(String clusterUUID, String type, long timestamp, Payload payload) {
public ClusterStatsMarvelDoc(String clusterUUID, String type, long timestamp, ClusterStatsResponse clusterStats) {
super(clusterUUID, type, timestamp);
this.payload = payload;
this.clusterStats = clusterStats;
}
@Override
public ClusterStatsMarvelDoc.Payload payload() {
return payload;
}
public static ClusterStatsMarvelDoc createMarvelDoc(String clusterUUID, String type, long timestamp, ClusterStatsResponse clusterStats) {
return new ClusterStatsMarvelDoc(clusterUUID, type, timestamp, new Payload(clusterStats));
}
public static class Payload {
private final ClusterStatsResponse clusterStats;
Payload(ClusterStatsResponse clusterStats) {
this.clusterStats = clusterStats;
}
public ClusterStatsResponse getClusterStats() {
return clusterStats;
}
public ClusterStatsResponse getClusterStats() {
return clusterStats;
}
}

View File

@ -53,12 +53,8 @@ public class IndexRecoveryCollector extends AbstractCollector<IndexRecoveryColle
.get(marvelSettings.recoveryTimeout());
if (recoveryResponse.hasRecoveries()) {
results.add(buildMarvelDoc(clusterUUID(), TYPE, System.currentTimeMillis(), recoveryResponse));
results.add(new IndexRecoveryMarvelDoc(clusterUUID(), TYPE, System.currentTimeMillis(), recoveryResponse));
}
return results.build();
}
protected MarvelDoc buildMarvelDoc(String clusterUUID, String type, long timestamp, RecoveryResponse recoveryResponse) {
return IndexRecoveryMarvelDoc.createMarvelDoc(clusterUUID, type, timestamp, recoveryResponse);
}
}

View File

@ -8,36 +8,16 @@ package org.elasticsearch.marvel.agent.collector.indices;
import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
public class IndexRecoveryMarvelDoc extends MarvelDoc<IndexRecoveryMarvelDoc.Payload> {
public class IndexRecoveryMarvelDoc extends MarvelDoc {
private final Payload payload;
private final RecoveryResponse recoveryResponse;
public IndexRecoveryMarvelDoc(String clusterUUID, String type, long timestamp, Payload payload) {
public IndexRecoveryMarvelDoc(String clusterUUID, String type, long timestamp, RecoveryResponse recoveryResponse) {
super(clusterUUID, type, timestamp);
this.payload = payload;
this.recoveryResponse = recoveryResponse;
}
@Override
public IndexRecoveryMarvelDoc.Payload payload() {
return payload;
}
public static IndexRecoveryMarvelDoc createMarvelDoc(String clusterUUID, String type, long timestamp,
RecoveryResponse recoveryResponse) {
return new IndexRecoveryMarvelDoc(clusterUUID, type, timestamp, new Payload(recoveryResponse));
}
public static class Payload {
RecoveryResponse recoveryResponse;
public Payload(RecoveryResponse recoveryResponse) {
this.recoveryResponse = recoveryResponse;
}
public RecoveryResponse getRecoveryResponse() {
return recoveryResponse;
}
public RecoveryResponse getRecoveryResponse() {
return recoveryResponse;
}
}

View File

@ -56,12 +56,8 @@ public class IndexStatsCollector extends AbstractCollector<IndexStatsCollector>
long timestamp = System.currentTimeMillis();
String clusterUUID = clusterUUID();
for (IndexStats indexStats : indicesStats.getIndices().values()) {
results.add(buildMarvelDoc(clusterUUID, TYPE, timestamp, indexStats));
results.add(new IndexStatsMarvelDoc(clusterUUID, TYPE, timestamp, indexStats));
}
return results.build();
}
protected MarvelDoc buildMarvelDoc(String clusterUUID, String type, long timestamp, IndexStats indexStats) {
return IndexStatsMarvelDoc.createMarvelDoc(clusterUUID, type, timestamp, indexStats);
}
}

View File

@ -8,34 +8,16 @@ package org.elasticsearch.marvel.agent.collector.indices;
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
public class IndexStatsMarvelDoc extends MarvelDoc<IndexStatsMarvelDoc.Payload> {
public class IndexStatsMarvelDoc extends MarvelDoc {
private final Payload payload;
private final IndexStats indexStats;
public IndexStatsMarvelDoc(String clusterUUID, String type, long timestamp, Payload payload) {
public IndexStatsMarvelDoc(String clusterUUID, String type, long timestamp, IndexStats indexStats) {
super(clusterUUID, type, timestamp);
this.payload = payload;
this.indexStats = indexStats;
}
@Override
public IndexStatsMarvelDoc.Payload payload() {
return payload;
}
public static IndexStatsMarvelDoc createMarvelDoc(String clusterUUID, String type, long timestamp, IndexStats indexStats) {
return new IndexStatsMarvelDoc(clusterUUID, type, timestamp, new Payload(indexStats));
}
public static class Payload {
private final IndexStats indexStats;
Payload(IndexStats indexStats) {
this.indexStats = indexStats;
}
public IndexStats getIndexStats() {
return indexStats;
}
public IndexStats getIndexStats() {
return indexStats;
}
}

View File

@ -50,7 +50,7 @@ public class LicensesCollector extends AbstractCollector<LicensesMarvelDoc> {
List<License> licenses = licenseService.licenses();
if (licenses != null) {
String clusterUUID = clusterUUID();
results.add(LicensesMarvelDoc.createMarvelDoc(MarvelSettings.MARVEL_DATA_INDEX_NAME, TYPE, clusterUUID, clusterUUID, System.currentTimeMillis(),
results.add(new LicensesMarvelDoc(MarvelSettings.MARVEL_DATA_INDEX_NAME, TYPE, clusterUUID, clusterUUID, System.currentTimeMillis(),
clusterName.value(), Version.CURRENT.toString(), licenses));
}
return results.build();

View File

@ -10,46 +10,30 @@ import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import java.util.List;
public class LicensesMarvelDoc extends MarvelDoc<LicensesMarvelDoc.Payload> {
public class LicensesMarvelDoc extends MarvelDoc {
private final Payload payload;
private final String clusterName;
private final String version;
private final List<License> licenses;
LicensesMarvelDoc(String index, String type, String id, String clusterUUID, long timestamp, Payload payload) {
LicensesMarvelDoc(String index, String type, String id, String clusterUUID, long timestamp,
String clusterName, String version, List<License> licenses) {
super(index, type, id, clusterUUID, timestamp);
this.payload = payload;
this.clusterName = clusterName;
this.version = version;
this.licenses = licenses;
}
@Override
public LicensesMarvelDoc.Payload payload() {
return payload;
public String getClusterName() {
return clusterName;
}
public static LicensesMarvelDoc createMarvelDoc(String index, String type, String id, String clusterUUID, long timestamp, String clusterName, String version, List<License> licenses) {
return new LicensesMarvelDoc(index, type, id, clusterUUID, timestamp, new Payload(clusterName, version, licenses));
public String getVersion() {
return version;
}
public static class Payload {
private final String clusterName;
private final String version;
private final List<License> licenses;
public Payload(String clusterName, String version, List<License> licenses) {
this.clusterName = clusterName;
this.version = version;
this.licenses = licenses;
}
public String getClusterName() {
return clusterName;
}
public String getVersion() {
return version;
}
public List<License> getLicenses() {
return licenses;
}
public List<License> getLicenses() {
return licenses;
}
}

View File

@ -70,16 +70,10 @@ public class NodeStatsCollector extends AbstractCollector<NodeStatsCollector> {
Double diskThresholdWatermarkHigh = (diskThresholdDecider != null) ? 100.0 - diskThresholdDecider.getFreeDiskThresholdHigh() : -1;
boolean diskThresholdDeciderEnabled = (diskThresholdDecider != null) && diskThresholdDecider.isEnabled();
results.add(buildMarvelDoc(clusterUUID(), TYPE, System.currentTimeMillis(),
discoveryService.localNode().id(), clusterService.state().nodes().localNodeMaster(), nodeStats,
results.add(new NodeStatsMarvelDoc(clusterUUID(), TYPE, System.currentTimeMillis(),
discoveryService.localNode().id(), localNodeMaster(), nodeStats,
Bootstrap.isMemoryLocked(), diskThresholdWatermarkHigh, diskThresholdDeciderEnabled));
return results.build();
}
protected MarvelDoc buildMarvelDoc(String clusterUUID, String type, long timestamp,
String nodeId, boolean nodeMaster, NodeStats nodeStats,
boolean mlockall, Double diskThresholdWaterMarkHigh, boolean diskThresholdDeciderEnabled) {
return NodeStatsMarvelDoc.createMarvelDoc(clusterUUID, type, timestamp, nodeId, nodeMaster, nodeStats, mlockall, diskThresholdWaterMarkHigh, diskThresholdDeciderEnabled);
}
}

View File

@ -8,68 +8,49 @@ package org.elasticsearch.marvel.agent.collector.node;
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
public class NodeStatsMarvelDoc extends MarvelDoc<NodeStatsMarvelDoc.Payload> {
public class NodeStatsMarvelDoc extends MarvelDoc {
private final Payload payload;
private final String nodeId;
private final boolean nodeMaster;
private final NodeStats nodeStats;
public NodeStatsMarvelDoc(String clusterUUID, String type, long timestamp, Payload payload) {
private final boolean mlockall;
private final Double diskThresholdWaterMarkHigh;
private final boolean diskThresholdDeciderEnabled;
public NodeStatsMarvelDoc(String clusterUUID, String type, long timestamp,
String nodeId, boolean nodeMaster, NodeStats nodeStats, boolean mlockall, Double diskThresholdWaterMarkHigh, boolean diskThresholdDeciderEnabled) {
super(clusterUUID, type, timestamp);
this.payload = payload;
this.nodeId = nodeId;
this.nodeMaster = nodeMaster;
this.nodeStats = nodeStats;
this.mlockall = mlockall;
this.diskThresholdWaterMarkHigh = diskThresholdWaterMarkHigh;
this.diskThresholdDeciderEnabled = diskThresholdDeciderEnabled;
}
@Override
public Payload payload() {
return payload;
public String getNodeId() {
return nodeId;
}
public static NodeStatsMarvelDoc createMarvelDoc(String clusterUUID, String type, long timestamp,
String nodeId, boolean nodeMaster, NodeStats nodeStats,
boolean mlockall, Double diskThresholdWaterMarkHigh, boolean diskThresholdDeciderEnabled) {
return new NodeStatsMarvelDoc(clusterUUID, type, timestamp, new Payload(nodeId, nodeMaster, nodeStats, mlockall, diskThresholdWaterMarkHigh, diskThresholdDeciderEnabled));
public boolean isNodeMaster() {
return nodeMaster;
}
public static class Payload {
public NodeStats getNodeStats() {
return nodeStats;
}
private final String nodeId;
private final boolean nodeMaster;
private final NodeStats nodeStats;
public boolean isMlockall() {
return mlockall;
}
private final boolean mlockall;
private final Double diskThresholdWaterMarkHigh;
private final boolean diskThresholdDeciderEnabled;
public Double getDiskThresholdWaterMarkHigh() {
return diskThresholdWaterMarkHigh;
}
Payload(String nodeId, boolean nodeMaster, NodeStats nodeStats, boolean mlockall, Double diskThresholdWaterMarkHigh, boolean diskThresholdDeciderEnabled) {
this.nodeId = nodeId;
this.nodeMaster = nodeMaster;
this.nodeStats = nodeStats;
this.mlockall = mlockall;
this.diskThresholdWaterMarkHigh = diskThresholdWaterMarkHigh;
this.diskThresholdDeciderEnabled = diskThresholdDeciderEnabled;
}
public String getNodeId() {
return nodeId;
}
public boolean isNodeMaster() {
return nodeMaster;
}
public NodeStats getNodeStats() {
return nodeStats;
}
public boolean isMlockall() {
return mlockall;
}
public Double getDiskThresholdWaterMarkHigh() {
return diskThresholdWaterMarkHigh;
}
public boolean isDiskThresholdDeciderEnabled() {
return diskThresholdDeciderEnabled;
}
public boolean isDiskThresholdDeciderEnabled() {
return diskThresholdDeciderEnabled;
}
}

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.marvel.agent.exporter;
public abstract class MarvelDoc<T> {
public abstract class MarvelDoc {
private final String index;
private final String type;
@ -45,6 +45,4 @@ public abstract class MarvelDoc<T> {
public long timestamp() {
return timestamp;
}
public abstract T payload();
}

View File

@ -36,25 +36,22 @@ public class ClusterStateRenderer extends AbstractRenderer<ClusterStateMarvelDoc
protected void doRender(ClusterStateMarvelDoc marvelDoc, XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(Fields.CLUSTER_STATE);
ClusterStateMarvelDoc.Payload payload = marvelDoc.payload();
if (payload != null) {
ClusterState clusterState = payload.getClusterState();
if (clusterState != null) {
builder.field(Fields.STATUS, payload.getStatus().name().toLowerCase(Locale.ROOT));
ClusterState clusterState = marvelDoc.getClusterState();
if (clusterState != null) {
builder.field(Fields.STATUS, marvelDoc.getStatus().name().toLowerCase(Locale.ROOT));
clusterState.toXContent(builder, params);
clusterState.toXContent(builder, params);
RoutingTable routingTable = clusterState.routingTable();
if (routingTable != null) {
List<ShardRouting> shards = routingTable.allShards();
if (shards != null) {
RoutingTable routingTable = clusterState.routingTable();
if (routingTable != null) {
List<ShardRouting> shards = routingTable.allShards();
if (shards != null) {
builder.startArray(Fields.SHARDS);
for (ShardRouting shard : shards) {
shard.toXContent(builder, params);
}
builder.endArray();
builder.startArray(Fields.SHARDS);
for (ShardRouting shard : shards) {
shard.toXContent(builder, params);
}
builder.endArray();
}
}
}

View File

@ -37,12 +37,9 @@ public class ClusterStatsRenderer extends AbstractRenderer<ClusterStatsMarvelDoc
protected void doRender(ClusterStatsMarvelDoc marvelDoc, XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(Fields.CLUSTER_STATS);
ClusterStatsMarvelDoc.Payload payload = marvelDoc.payload();
if (payload != null) {
ClusterStatsResponse clusterStats = payload.getClusterStats();
if (clusterStats != null) {
clusterStats.toXContent(builder, params);
}
ClusterStatsResponse clusterStats = marvelDoc.getClusterStats();
if (clusterStats != null) {
clusterStats.toXContent(builder, params);
}
builder.endObject();

View File

@ -27,29 +27,27 @@ public class IndexRecoveryRenderer extends AbstractRenderer<IndexRecoveryMarvelD
protected void doRender(IndexRecoveryMarvelDoc marvelDoc, XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(Fields.INDEX_RECOVERY);
IndexRecoveryMarvelDoc.Payload payload = marvelDoc.payload();
if (payload != null) {
RecoveryResponse recovery = payload.getRecoveryResponse();
if (recovery != null) {
builder.startArray(Fields.SHARDS);
Map<String, List<ShardRecoveryResponse>> shards = recovery.shardResponses();
if (shards != null) {
for (Map.Entry<String, List<ShardRecoveryResponse>> shard : shards.entrySet()) {
RecoveryResponse recovery = marvelDoc.getRecoveryResponse();
if (recovery != null) {
builder.startArray(Fields.SHARDS);
Map<String, List<ShardRecoveryResponse>> shards = recovery.shardResponses();
if (shards != null) {
for (Map.Entry<String, List<ShardRecoveryResponse>> shard : shards.entrySet()) {
List<ShardRecoveryResponse> indexShards = shard.getValue();
if (indexShards != null) {
for (ShardRecoveryResponse indexShard : indexShards) {
builder.startObject();
builder.field(Fields.INDEX_NAME, shard.getKey());
indexShard.toXContent(builder, params);
builder.endObject();
}
List<ShardRecoveryResponse> indexShards = shard.getValue();
if (indexShards != null) {
for (ShardRecoveryResponse indexShard : indexShards) {
builder.startObject();
builder.field(Fields.INDEX_NAME, shard.getKey());
indexShard.toXContent(builder, params);
builder.endObject();
}
}
}
builder.endArray();
}
builder.endArray();
}
builder.endObject();
}

View File

@ -40,25 +40,23 @@ public class IndexStatsRenderer extends AbstractRenderer<IndexStatsMarvelDoc> {
protected void doRender(IndexStatsMarvelDoc marvelDoc, XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(Fields.INDEX_STATS);
IndexStatsMarvelDoc.Payload payload = marvelDoc.payload();
if (payload != null) {
IndexStats indexStats = payload.getIndexStats();
if (indexStats != null) {
builder.field(Fields.INDEX, indexStats.getIndex());
IndexStats indexStats = marvelDoc.getIndexStats();
if (indexStats != null) {
builder.field(Fields.INDEX, indexStats.getIndex());
builder.startObject(Fields.TOTAL);
if (indexStats.getTotal() != null) {
indexStats.getTotal().toXContent(builder, params);
}
builder.endObject();
builder.startObject(Fields.PRIMARIES);
if (indexStats.getPrimaries() != null) {
indexStats.getPrimaries().toXContent(builder, params);
}
builder.endObject();
builder.startObject(Fields.TOTAL);
if (indexStats.getTotal() != null) {
indexStats.getTotal().toXContent(builder, params);
}
builder.endObject();
builder.startObject(Fields.PRIMARIES);
if (indexStats.getPrimaries() != null) {
indexStats.getPrimaries().toXContent(builder, params);
}
builder.endObject();
}
builder.endObject();
}

View File

@ -26,32 +26,29 @@ public class LicensesRenderer extends AbstractRenderer<LicensesMarvelDoc> {
@Override
protected void doRender(LicensesMarvelDoc marvelDoc, XContentBuilder builder, ToXContent.Params params) throws IOException {
LicensesMarvelDoc.Payload payload = marvelDoc.payload();
if (payload != null) {
builder.field(Fields.CLUSTER_NAME, payload.getClusterName());
builder.field(Fields.VERSION, payload.getVersion());
builder.startArray(Fields.LICENSES);
builder.field(Fields.CLUSTER_NAME, marvelDoc.getClusterName());
builder.field(Fields.VERSION, marvelDoc.getVersion());
builder.startArray(Fields.LICENSES);
List<License> licenses = payload.getLicenses();
if (licenses != null) {
for (License license : licenses) {
builder.startObject();
builder.field(Fields.STATUS, status(license));
builder.field(Fields.UID, license.uid());
builder.field(Fields.TYPE, license.type());
builder.dateValueField(Fields.ISSUE_DATE_IN_MILLIS, Fields.ISSUE_DATE, license.issueDate());
builder.field(Fields.FEATURE, license.feature());
builder.dateValueField(Fields.EXPIRY_DATE_IN_MILLIS, Fields.EXPIRY_DATE, license.expiryDate());
builder.field(Fields.MAX_NODES, license.maxNodes());
builder.field(Fields.ISSUED_TO, license.issuedTo());
builder.field(Fields.ISSUER, license.issuer());
builder.field(Fields.HKEY, hash(license, payload.getClusterName()));
builder.endObject();
}
List<License> licenses = marvelDoc.getLicenses();
if (licenses != null) {
for (License license : licenses) {
builder.startObject();
builder.field(Fields.STATUS, status(license));
builder.field(Fields.UID, license.uid());
builder.field(Fields.TYPE, license.type());
builder.dateValueField(Fields.ISSUE_DATE_IN_MILLIS, Fields.ISSUE_DATE, license.issueDate());
builder.field(Fields.FEATURE, license.feature());
builder.dateValueField(Fields.EXPIRY_DATE_IN_MILLIS, Fields.EXPIRY_DATE, license.expiryDate());
builder.field(Fields.MAX_NODES, license.maxNodes());
builder.field(Fields.ISSUED_TO, license.issuedTo());
builder.field(Fields.ISSUER, license.issuer());
builder.field(Fields.HKEY, hash(license, marvelDoc.getClusterName()));
builder.endObject();
}
builder.endArray();
}
builder.endArray();
}
// TODO (tlrx): move status as a calculated getter in License class then remove this method

View File

@ -56,20 +56,17 @@ public class NodeStatsRenderer extends AbstractRenderer<NodeStatsMarvelDoc> {
protected void doRender(NodeStatsMarvelDoc marvelDoc, XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(Fields.NODE_STATS);
NodeStatsMarvelDoc.Payload payload = marvelDoc.payload();
if (payload != null) {
builder.field(Fields.NODE_ID, marvelDoc.getNodeId());
builder.field(Fields.NODE_MASTER, marvelDoc.isNodeMaster());
builder.field(Fields.MLOCKALL, marvelDoc.isMlockall());
builder.field(Fields.DISK_THRESHOLD_ENABLED, marvelDoc.isDiskThresholdDeciderEnabled());
builder.field(Fields.DISK_THRESHOLD_WATERMARK_HIGH, marvelDoc.getDiskThresholdWaterMarkHigh());
builder.field(Fields.NODE_ID, payload.getNodeId());
builder.field(Fields.NODE_MASTER, payload.isNodeMaster());
builder.field(Fields.MLOCKALL, payload.isMlockall());
builder.field(Fields.DISK_THRESHOLD_ENABLED, payload.isDiskThresholdDeciderEnabled());
builder.field(Fields.DISK_THRESHOLD_WATERMARK_HIGH, payload.getDiskThresholdWaterMarkHigh());
NodeStats nodeStats = payload.getNodeStats();
if (nodeStats != null) {
nodeStats.toXContent(builder, params);
}
NodeStats nodeStats = marvelDoc.getNodeStats();
if (nodeStats != null) {
nodeStats.toXContent(builder, params);
}
builder.endObject();
}

View File

@ -34,12 +34,9 @@ public class ClusterStateCollectorTests extends ESSingleNodeTestCase {
assertThat(clusterStateMarvelDoc.clusterUUID(), equalTo(client().admin().cluster().prepareState().setMetaData(true).get().getState().metaData().clusterUUID()));
assertThat(clusterStateMarvelDoc.timestamp(), greaterThan(0L));
assertThat(clusterStateMarvelDoc.type(), equalTo(ClusterStateCollector.TYPE));
assertNotNull(clusterStateMarvelDoc.getClusterState());
ClusterStateMarvelDoc.Payload payload = clusterStateMarvelDoc.payload();
assertNotNull(payload);
assertNotNull(payload.getClusterState());
ClusterState clusterState = payload.getClusterState();
ClusterState clusterState = clusterStateMarvelDoc.getClusterState();
assertThat(clusterState.getRoutingTable().allShards(), hasSize(0));
}
@ -67,11 +64,9 @@ public class ClusterStateCollectorTests extends ESSingleNodeTestCase {
assertThat(clusterStateMarvelDoc.timestamp(), greaterThan(0L));
assertThat(clusterStateMarvelDoc.type(), equalTo(ClusterStateCollector.TYPE));
ClusterStateMarvelDoc.Payload payload = clusterStateMarvelDoc.payload();
assertNotNull(payload);
assertNotNull(payload.getClusterState());
assertNotNull(clusterStateMarvelDoc.getClusterState());
ClusterState clusterState = payload.getClusterState();
ClusterState clusterState = clusterStateMarvelDoc.getClusterState();
assertThat(clusterState.getRoutingTable().allShards("test"), hasSize(nbShards));
}
@ -105,12 +100,9 @@ public class ClusterStateCollectorTests extends ESSingleNodeTestCase {
assertThat(clusterStateMarvelDoc.clusterUUID(), equalTo(client().admin().cluster().prepareState().setMetaData(true).get().getState().metaData().clusterUUID()));
assertThat(clusterStateMarvelDoc.timestamp(), greaterThan(0L));
assertThat(clusterStateMarvelDoc.type(), equalTo(ClusterStateCollector.TYPE));
assertNotNull(clusterStateMarvelDoc.getClusterState());
ClusterStateMarvelDoc.Payload payload = clusterStateMarvelDoc.payload();
assertNotNull(payload);
assertNotNull(payload.getClusterState());
ClusterState clusterState = payload.getClusterState();
ClusterState clusterState = clusterStateMarvelDoc.getClusterState();
for (int i = 0; i < nbIndices; i++) {
assertThat(clusterState.getRoutingTable().allShards("test-" + i), hasSize(shardsPerIndex[i]));
}

View File

@ -32,10 +32,8 @@ public class ClusterStatsCollectorTests extends ESIntegTestCase {
assertThat(clusterStatsMarvelDoc.timestamp(), greaterThan(0L));
assertThat(clusterStatsMarvelDoc.type(), equalTo(ClusterStatsCollector.TYPE));
ClusterStatsMarvelDoc.Payload payload = clusterStatsMarvelDoc.payload();
assertNotNull(payload);
assertNotNull(payload.getClusterStats());
assertThat(payload.getClusterStats().getNodesStats().getCounts().getTotal(), equalTo(internalCluster().getNodeNames().length));
assertNotNull(clusterStatsMarvelDoc.getClusterStats());
assertThat(clusterStatsMarvelDoc.getClusterStats().getNodesStats().getCounts().getTotal(), equalTo(internalCluster().getNodeNames().length));
}
private ClusterStatsCollector newClusterStatsCollector() {

View File

@ -99,10 +99,7 @@ public class IndexRecoveryCollectorTests extends ESIntegTestCase {
assertThat(indexRecoveryMarvelDoc.timestamp(), greaterThan(0L));
assertThat(indexRecoveryMarvelDoc.type(), equalTo(IndexRecoveryCollector.TYPE));
IndexRecoveryMarvelDoc.Payload payload = indexRecoveryMarvelDoc.payload();
assertNotNull(payload);
RecoveryResponse recovery = payload.getRecoveryResponse();
RecoveryResponse recovery = indexRecoveryMarvelDoc.getRecoveryResponse();
assertNotNull(recovery);
Map<String, List<ShardRecoveryResponse>> shards = recovery.shardResponses();

View File

@ -7,6 +7,7 @@ package org.elasticsearch.marvel.agent.collector.indices;
import com.google.common.collect.ImmutableSet;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.common.settings.Settings;
@ -56,17 +57,16 @@ public class IndexStatsCollectorTests extends ESSingleNodeTestCase {
assertThat(indexStatsMarvelDoc.timestamp(), greaterThan(0L));
assertThat(indexStatsMarvelDoc.type(), equalTo(IndexStatsCollector.TYPE));
IndexStatsMarvelDoc.Payload payload = indexStatsMarvelDoc.payload();
assertNotNull(payload);
assertNotNull(payload.getIndexStats());
IndexStats indexStats = indexStatsMarvelDoc.getIndexStats();
assertNotNull(indexStats);
assertThat(payload.getIndexStats().getIndex(), equalTo("test"));
assertThat(payload.getIndexStats().getTotal().getDocs().getCount(), equalTo((long) nbDocs));
assertNotNull(payload.getIndexStats().getTotal().getStore());
assertThat(payload.getIndexStats().getTotal().getStore().getSizeInBytes(), greaterThan(0L));
assertThat(payload.getIndexStats().getTotal().getStore().getThrottleTime().millis(), equalTo(0L));
assertNotNull(payload.getIndexStats().getTotal().getIndexing());
assertThat(payload.getIndexStats().getTotal().getIndexing().getTotal().getThrottleTimeInMillis(), equalTo(0L));
assertThat(indexStats.getIndex(), equalTo("test"));
assertThat(indexStats.getTotal().getDocs().getCount(), equalTo((long) nbDocs));
assertNotNull(indexStats.getTotal().getStore());
assertThat(indexStats.getTotal().getStore().getSizeInBytes(), greaterThan(0L));
assertThat(indexStats.getTotal().getStore().getThrottleTime().millis(), equalTo(0L));
assertNotNull(indexStats.getTotal().getIndexing());
assertThat(indexStats.getTotal().getIndexing().getTotal().getThrottleTimeInMillis(), equalTo(0L));
}
@Test
@ -101,23 +101,21 @@ public class IndexStatsCollectorTests extends ESSingleNodeTestCase {
assertThat(marvelDoc, instanceOf(IndexStatsMarvelDoc.class));
IndexStatsMarvelDoc indexStatsMarvelDoc = (IndexStatsMarvelDoc) marvelDoc;
IndexStats indexStats = indexStatsMarvelDoc.getIndexStats();
assertNotNull(indexStats);
IndexStatsMarvelDoc.Payload payload = indexStatsMarvelDoc.payload();
assertNotNull(payload);
assertNotNull(payload.getIndexStats());
if (payload.getIndexStats().getIndex().equals("test-" + i)) {
if (indexStats.getIndex().equals("test-" + i)) {
assertThat(indexStatsMarvelDoc.clusterUUID(), equalTo(clusterUUID));
assertThat(indexStatsMarvelDoc.timestamp(), greaterThan(0L));
assertThat(indexStatsMarvelDoc.type(), equalTo(IndexStatsCollector.TYPE));
assertNotNull(payload.getIndexStats().getTotal().getDocs());
assertThat(payload.getIndexStats().getTotal().getDocs().getCount(), equalTo((long) docsPerIndex[i]));
assertNotNull(payload.getIndexStats().getTotal().getStore());
assertThat(payload.getIndexStats().getTotal().getStore().getSizeInBytes(), greaterThan(0L));
assertThat(payload.getIndexStats().getTotal().getStore().getThrottleTime().millis(), equalTo(0L));
assertNotNull(payload.getIndexStats().getTotal().getIndexing());
assertThat(payload.getIndexStats().getTotal().getIndexing().getTotal().getThrottleTimeInMillis(), equalTo(0L));
assertNotNull(indexStats.getTotal().getDocs());
assertThat(indexStats.getTotal().getDocs().getCount(), equalTo((long) docsPerIndex[i]));
assertNotNull(indexStats.getTotal().getStore());
assertThat(indexStats.getTotal().getStore().getSizeInBytes(), greaterThan(0L));
assertThat(indexStats.getTotal().getStore().getThrottleTime().millis(), equalTo(0L));
assertNotNull(indexStats.getTotal().getIndexing());
assertThat(indexStats.getTotal().getIndexing().getTotal().getThrottleTimeInMillis(), equalTo(0L));
found = true;
}
}

View File

@ -40,15 +40,13 @@ public class NodeStatsCollectorTests extends ESIntegTestCase {
assertThat(nodeStatsMarvelDoc.timestamp(), greaterThan(0L));
assertThat(nodeStatsMarvelDoc.type(), equalTo(NodeStatsCollector.TYPE));
NodeStatsMarvelDoc.Payload payload = nodeStatsMarvelDoc.payload();
assertNotNull(payload);
assertThat(payload.getNodeId(), equalTo(internalCluster().getInstance(DiscoveryService.class, node).localNode().id()));
assertThat(payload.isNodeMaster(), equalTo(node.equals(internalCluster().getMasterName())));
assertThat(payload.isMlockall(), equalTo(Bootstrap.isMemoryLocked()));
assertNotNull(payload.isDiskThresholdDeciderEnabled());
assertNotNull(payload.getDiskThresholdWaterMarkHigh());
assertThat(nodeStatsMarvelDoc.getNodeId(), equalTo(internalCluster().getInstance(DiscoveryService.class, node).localNode().id()));
assertThat(nodeStatsMarvelDoc.isNodeMaster(), equalTo(node.equals(internalCluster().getMasterName())));
assertThat(nodeStatsMarvelDoc.isMlockall(), equalTo(Bootstrap.isMemoryLocked()));
assertNotNull(nodeStatsMarvelDoc.isDiskThresholdDeciderEnabled());
assertNotNull(nodeStatsMarvelDoc.getDiskThresholdWaterMarkHigh());
assertNotNull(payload.getNodeStats());
assertNotNull(nodeStatsMarvelDoc.getNodeStats());
}
}

View File

@ -220,7 +220,7 @@ public class HttpESExporterTests extends ESIntegTestCase {
}
private MarvelDoc newRandomMarvelDoc() {
return IndexStatsMarvelDoc.createMarvelDoc(internalCluster().getClusterName(), "test_marvelDoc", timeStampGenerator.incrementAndGet(),
return new IndexStatsMarvelDoc(internalCluster().getClusterName(), "test_marvelDoc", timeStampGenerator.incrementAndGet(),
new IndexStats("test_index", null));
}

View File

@ -36,7 +36,7 @@ public class ClusterStateRendererTests extends ESSingleNodeTestCase {
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().get();
logger.debug("--> creating the cluster state marvel document");
ClusterStateMarvelDoc marvelDoc = ClusterStateMarvelDoc.createMarvelDoc("test", "marvel_cluster_state", 1437580442979L,
ClusterStateMarvelDoc marvelDoc = new ClusterStateMarvelDoc("test", "marvel_cluster_state", 1437580442979L,
clusterState, clusterHealth.getStatus());
logger.debug("--> rendering the document");

View File

@ -25,7 +25,7 @@ public class ClusterStatsRendererTests extends ESSingleNodeTestCase {
ClusterStatsResponse clusterStats = client().admin().cluster().prepareClusterStats().get();
logger.debug("--> creating the cluster stats marvel document");
ClusterStatsMarvelDoc marvelDoc = ClusterStatsMarvelDoc.createMarvelDoc("test", "marvel_cluster_stats", 1437580442979L, clusterStats);
ClusterStatsMarvelDoc marvelDoc = new ClusterStatsMarvelDoc("test", "marvel_cluster_stats", 1437580442979L, clusterStats);
logger.debug("--> rendering the document");
Renderer renderer = new ClusterStatsRenderer();

View File

@ -53,7 +53,7 @@ public class IndexRecoveryRendererTests extends ESTestCase {
RecoveryResponse recoveryResponse = new RecoveryResponse(2, 2, 2, false, shardResponses, null);
IndexRecoveryMarvelDoc marvelDoc = IndexRecoveryMarvelDoc.createMarvelDoc("test", "marvel_index_recovery", 1437580442979L, recoveryResponse);
IndexRecoveryMarvelDoc marvelDoc = new IndexRecoveryMarvelDoc("test", "marvel_index_recovery", 1437580442979L, recoveryResponse);
logger.debug("--> rendering the document");
Renderer renderer = new IndexRecoveryRenderer();

View File

@ -29,7 +29,7 @@ public class IndexStatsRendererTests extends ESTestCase {
@Test
public void testIndexStatsRenderer() throws Exception {
logger.debug("--> creating the index stats marvel document");
IndexStatsMarvelDoc marvelDoc = IndexStatsMarvelDoc.createMarvelDoc("test", "marvel_index_stats", 1437580442979L,
IndexStatsMarvelDoc marvelDoc = new IndexStatsMarvelDoc("test", "marvel_index_stats", 1437580442979L,
new IndexStats("index-0", new ShardStats[0]) {
@Override
public CommonStats getTotal() {

View File

@ -27,7 +27,7 @@ public class NodeStatsRendererTests extends ESSingleNodeTestCase {
NodeStats nodeStats = getInstanceFromNode(NodeService.class).stats();
logger.debug("--> creating the node stats marvel document");
NodeStatsMarvelDoc marvelDoc = NodeStatsMarvelDoc.createMarvelDoc("test", "marvel_node_stats", 1437580442979L,
NodeStatsMarvelDoc marvelDoc = new NodeStatsMarvelDoc("test", "marvel_node_stats", 1437580442979L,
"node-0", true, nodeStats, false, 90.0, true);
logger.debug("--> rendering the document");