|
@@ -19,13 +19,15 @@
|
|
|
|
|
|
package org.elasticsearch.cluster.node;
|
|
|
|
|
|
-import com.google.common.collect.ImmutableMap;
|
|
|
+import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
|
|
|
|
|
import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.common.Booleans;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
-import org.elasticsearch.common.io.stream.*;
|
|
|
-import org.elasticsearch.common.network.NetworkUtils;
|
|
|
+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.Streamable;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.transport.TransportAddress;
|
|
|
import org.elasticsearch.common.transport.TransportAddressSerializers;
|
|
@@ -33,7 +35,6 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.net.InetAddress;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -100,7 +101,7 @@ public class DiscoveryNode implements Streamable, ToXContent {
|
|
|
private String hostName;
|
|
|
private String hostAddress;
|
|
|
private TransportAddress address;
|
|
|
- private Map<String, String> attributes;
|
|
|
+ private ImmutableOpenMap<String, String> attributes;
|
|
|
private Version version = Version.CURRENT;
|
|
|
|
|
|
DiscoveryNode() {
|
|
@@ -143,7 +144,7 @@ public class DiscoveryNode implements Streamable, ToXContent {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Creates a new {@link DiscoveryNode}
|
|
|
+ * Creates a new {@link DiscoveryNode}.
|
|
|
* <p>
|
|
|
* <b>Note:</b> if the version of the node is unknown {@link #MINIMUM_DISCOVERY_NODE_VERSION} should be used.
|
|
|
* it corresponds to the minimum version this elasticsearch version can communicate with. If a higher version is used
|
|
@@ -163,7 +164,7 @@ public class DiscoveryNode implements Streamable, ToXContent {
|
|
|
if (nodeName != null) {
|
|
|
this.nodeName = nodeName.intern();
|
|
|
}
|
|
|
- ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
|
|
+ ImmutableOpenMap.Builder<String, String> builder = ImmutableOpenMap.builder();
|
|
|
for (Map.Entry<String, String> entry : attributes.entrySet()) {
|
|
|
builder.put(entry.getKey().intern(), entry.getValue().intern());
|
|
|
}
|
|
@@ -175,6 +176,39 @@ public class DiscoveryNode implements Streamable, ToXContent {
|
|
|
this.version = version;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Creates a new {@link DiscoveryNode}.
|
|
|
+ * <p>
|
|
|
+ * <b>Note:</b> if the version of the node is unknown {@link #MINIMUM_DISCOVERY_NODE_VERSION} should be used.
|
|
|
+ * it corresponds to the minimum version this elasticsearch version can communicate with. If a higher version is used
|
|
|
+ * the node might not be able to communicate with the remove node. After initial handshakes node versions will be discovered
|
|
|
+ * and updated.
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param nodeName the nodes name
|
|
|
+ * @param nodeId the nodes unique id.
|
|
|
+ * @param hostName the nodes hostname
|
|
|
+ * @param hostAddress the nodes host address
|
|
|
+ * @param address the nodes transport address
|
|
|
+ * @param attributes node attributes
|
|
|
+ * @param version the version of the node.
|
|
|
+ */
|
|
|
+ public DiscoveryNode(String nodeName, String nodeId, String hostName, String hostAddress, TransportAddress address, ImmutableOpenMap<String, String> attributes, Version version) {
|
|
|
+ if (nodeName != null) {
|
|
|
+ this.nodeName = nodeName.intern();
|
|
|
+ }
|
|
|
+ ImmutableOpenMap.Builder<String, String> builder = ImmutableOpenMap.builder();
|
|
|
+ for (ObjectObjectCursor<String, String> entry : attributes) {
|
|
|
+ builder.put(entry.key.intern(), entry.value.intern());
|
|
|
+ }
|
|
|
+ this.attributes = builder.build();
|
|
|
+ this.nodeId = nodeId.intern();
|
|
|
+ this.hostName = hostName.intern();
|
|
|
+ this.hostAddress = hostAddress.intern();
|
|
|
+ this.address = address;
|
|
|
+ this.version = version;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Should this node form a connection to the provided node.
|
|
|
*/
|
|
@@ -230,14 +264,14 @@ public class DiscoveryNode implements Streamable, ToXContent {
|
|
|
/**
|
|
|
* The node attributes.
|
|
|
*/
|
|
|
- public Map<String, String> attributes() {
|
|
|
+ public ImmutableOpenMap<String, String> attributes() {
|
|
|
return this.attributes;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* The node attributes.
|
|
|
*/
|
|
|
- public Map<String, String> getAttributes() {
|
|
|
+ public ImmutableOpenMap<String, String> getAttributes() {
|
|
|
return attributes();
|
|
|
}
|
|
|
|
|
@@ -319,11 +353,11 @@ public class DiscoveryNode implements Streamable, ToXContent {
|
|
|
hostAddress = in.readString().intern();
|
|
|
address = TransportAddressSerializers.addressFromStream(in);
|
|
|
int size = in.readVInt();
|
|
|
- ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
|
|
+ ImmutableOpenMap.Builder<String, String> attributes = ImmutableOpenMap.builder(size);
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
- builder.put(in.readString().intern(), in.readString().intern());
|
|
|
+ attributes.put(in.readString().intern(), in.readString().intern());
|
|
|
}
|
|
|
- attributes = builder.build();
|
|
|
+ this.attributes = attributes.build();
|
|
|
version = Version.readVersion(in);
|
|
|
}
|
|
|
|
|
@@ -335,9 +369,9 @@ public class DiscoveryNode implements Streamable, ToXContent {
|
|
|
out.writeString(hostAddress);
|
|
|
addressToStream(out, address);
|
|
|
out.writeVInt(attributes.size());
|
|
|
- for (Map.Entry<String, String> entry : attributes.entrySet()) {
|
|
|
- out.writeString(entry.getKey());
|
|
|
- out.writeString(entry.getValue());
|
|
|
+ for (ObjectObjectCursor<String, String> entry : attributes) {
|
|
|
+ out.writeString(entry.key);
|
|
|
+ out.writeString(entry.value);
|
|
|
}
|
|
|
Version.writeVersion(version, out);
|
|
|
}
|
|
@@ -385,8 +419,8 @@ public class DiscoveryNode implements Streamable, ToXContent {
|
|
|
builder.field("transport_address", address().toString());
|
|
|
|
|
|
builder.startObject("attributes");
|
|
|
- for (Map.Entry<String, String> attr : attributes().entrySet()) {
|
|
|
- builder.field(attr.getKey(), attr.getValue());
|
|
|
+ for (ObjectObjectCursor<String, String> attr : attributes) {
|
|
|
+ builder.field(attr.key, attr.value);
|
|
|
}
|
|
|
builder.endObject();
|
|
|
|