From d31983d6b62bdc9fd9c6d473893b2215976444cb Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 29 Mar 2016 12:34:14 +0200 Subject: [PATCH] adapt to additional changes, attributes is now a regular map in DiscoveryNode Original commit: elastic/x-pack-elasticsearch@0ba590ed9b7f4b33bdc5227fcda7240d507d5fcd --- .../marvel/agent/exporter/MonitoringDoc.java | 37 +++++++++---------- .../cluster/DiscoveryNodeResolver.java | 6 +-- .../marvel/action/MonitoringBulkDocTests.java | 12 +++--- .../agent/exporter/MonitoringDocTests.java | 9 ++--- 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java index e439b4758f2..e1be3f48510 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java @@ -5,9 +5,7 @@ */ package org.elasticsearch.marvel.agent.exporter; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -16,6 +14,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; /** * Base class for all monitoring documents. @@ -107,23 +108,20 @@ public class MonitoringDoc implements Writeable { private String transportAddress; private String ip; private String name; - private ImmutableOpenMap attributes; + private Map attributes; public Node(String uuid, String host, String transportAddress, String ip, String name, - ImmutableOpenMap attributes) { + Map attributes) { this.uuid = uuid; this.host = host; this.transportAddress = transportAddress; this.ip = ip; this.name = name; - - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(); - if (attributes != null) { - for (ObjectObjectCursor entry : attributes) { - builder.put(entry.key.intern(), entry.value.intern()); - } + if (attributes == null) { + this.attributes = new HashMap<>(); + } else { + this.attributes = Collections.unmodifiableMap(attributes); } - this.attributes = builder.build(); } public Node(StreamInput in) throws IOException { @@ -133,11 +131,10 @@ public class MonitoringDoc implements Writeable { ip = in.readOptionalString(); name = in.readOptionalString(); int size = in.readVInt(); - ImmutableOpenMap.Builder attributes = ImmutableOpenMap.builder(size); + this.attributes = new HashMap<>(); for (int i = 0; i < size; i++) { - attributes.put(in.readOptionalString(), in.readOptionalString()); + attributes.put(in.readString(), in.readString()); } - this.attributes = attributes.build(); } public String getUUID() { @@ -160,7 +157,7 @@ public class MonitoringDoc implements Writeable { return name; } - public ImmutableOpenMap getAttributes() { + public Map getAttributes() { return attributes; } @@ -174,8 +171,8 @@ public class MonitoringDoc implements Writeable { builder.field(Fields.NAME, getName()); builder.startObject(Fields.ATTRIBUTES); - for (ObjectObjectCursor attr : getAttributes()) { - builder.field(attr.key, attr.value); + for (Map.Entry entry : getAttributes().entrySet()) { + builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); return builder.endObject(); @@ -190,9 +187,9 @@ public class MonitoringDoc implements Writeable { out.writeOptionalString(name); if (attributes != null) { out.writeVInt(attributes.size()); - for (ObjectObjectCursor entry : attributes) { - out.writeOptionalString(entry.key); - out.writeOptionalString(entry.value); + for (Map.Entry entry : attributes.entrySet()) { + out.writeString(entry.getKey()); + out.writeString(entry.getValue()); } } else { out.writeVInt(0); diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/DiscoveryNodeResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/DiscoveryNodeResolver.java index 7742f8d2c3a..4c641dc4a8c 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/DiscoveryNodeResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/DiscoveryNodeResolver.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.marvel.agent.resolver.cluster; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -14,6 +13,7 @@ import org.elasticsearch.marvel.agent.collector.cluster.DiscoveryNodeMonitoringD import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; import java.io.IOException; +import java.util.Map; public class DiscoveryNodeResolver extends MonitoringIndexNameResolver.Data { @@ -44,8 +44,8 @@ public class DiscoveryNodeResolver extends MonitoringIndexNameResolver.Data attr : node.getAttributes()) { - builder.field(attr.key, attr.value); + for (Map.Entry entry : node.getAttributes().entrySet()) { + builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); builder.field(Fields.ID, node.getId()); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/MonitoringBulkDocTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/MonitoringBulkDocTests.java index 7dc931dfe57..ca6914f3e95 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/MonitoringBulkDocTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/MonitoringBulkDocTests.java @@ -7,13 +7,14 @@ package org.elasticsearch.marvel.action; import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.test.ESTestCase; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.Matchers.equalTo; @@ -78,7 +79,7 @@ public class MonitoringBulkDocTests extends ESTestCase { String ip = null; String transportAddress = null; String host = null; - ImmutableOpenMap attributes = null; + Map attributes = null; if (frequently()) { uuid = randomAsciiOfLength(5); @@ -91,14 +92,11 @@ public class MonitoringBulkDocTests extends ESTestCase { } if (rarely()) { int nbAttributes = randomIntBetween(0, 5); - - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(); + attributes = new HashMap<>(); for (int i = 0; i < nbAttributes; i++) { - builder.put("key#" + i, String.valueOf(i)); + attributes.put("key#" + i, String.valueOf(i)); } - attributes = builder.build(); } return new MonitoringDoc.Node(uuid, host, transportAddress, ip, name, attributes); } - } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MonitoringDocTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MonitoringDocTests.java index 31e4f2df5e3..f33892c3b58 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MonitoringDocTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MonitoringDocTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.marvel.agent.exporter; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.transport.DummyTransportAddress; @@ -101,7 +100,7 @@ public class MonitoringDocTests extends ESTestCase { String ip = null; String transportAddress = null; String host = null; - ImmutableOpenMap attributes = null; + Map attributes = null; if (frequently()) { uuid = randomAsciiOfLength(5); @@ -114,12 +113,10 @@ public class MonitoringDocTests extends ESTestCase { } if (rarely()) { int nbAttributes = randomIntBetween(0, 5); - - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(); + attributes = new HashMap<>(); for (int i = 0; i < nbAttributes; i++) { - builder.put("key#" + i, String.valueOf(i)); + attributes.put("key#" + i, String.valueOf(i)); } - attributes = builder.build(); } return new MonitoringDoc.Node(uuid, host, transportAddress, ip, name, attributes); }