Skip to content

Commit

Permalink
Support Multicast discovery for external clients, closes #1532.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Dec 11, 2011
1 parent 5258b50 commit de861d6
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 86 deletions.
Expand Up @@ -39,12 +39,10 @@

/**
* Node information (static, does not change over time).
*
*
*/
public class NodeInfo extends NodeOperationResponse {

private ImmutableMap<String, String> attributes;
private ImmutableMap<String, String> serviceAttributes;

private Settings settings;

Expand All @@ -63,11 +61,11 @@ public class NodeInfo extends NodeOperationResponse {
NodeInfo() {
}

public NodeInfo(DiscoveryNode node, ImmutableMap<String, String> attributes, Settings settings,
public NodeInfo(DiscoveryNode node, ImmutableMap<String, String> serviceAttributes, Settings settings,
OsInfo os, ProcessInfo process, JvmInfo jvm, NetworkInfo network,
TransportInfo transport, @Nullable HttpInfo http) {
super(node);
this.attributes = attributes;
this.serviceAttributes = serviceAttributes;
this.settings = settings;
this.os = os;
this.process = process;
Expand All @@ -78,17 +76,17 @@ public NodeInfo(DiscoveryNode node, ImmutableMap<String, String> attributes, Set
}

/**
* The attributes of the node.
* The service attributes of the node.
*/
public ImmutableMap<String, String> attributes() {
return this.attributes;
public ImmutableMap<String, String> serviceAttributes() {
return this.serviceAttributes;
}

/**
* The attributes of the node.
*/
public ImmutableMap<String, String> getAttributes() {
return attributes();
public ImmutableMap<String, String> getServiceAttributes() {
return serviceAttributes();
}

/**
Expand Down Expand Up @@ -191,7 +189,7 @@ public void readFrom(StreamInput in) throws IOException {
for (int i = 0; i < size; i++) {
builder.put(in.readUTF(), in.readUTF());
}
attributes = builder.build();
serviceAttributes = builder.build();
settings = ImmutableSettings.readSettingsFromStream(in);
if (in.readBoolean()) {
os = OsInfo.readOsInfo(in);
Expand All @@ -216,8 +214,8 @@ public void readFrom(StreamInput in) throws IOException {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(attributes.size());
for (Map.Entry<String, String> entry : attributes.entrySet()) {
out.writeVInt(serviceAttributes.size());
for (Map.Entry<String, String> entry : serviceAttributes.entrySet()) {
out.writeUTF(entry.getKey());
out.writeUTF(entry.getValue());
}
Expand Down
Expand Up @@ -20,11 +20,16 @@
package org.elasticsearch.discovery.zen;

import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.node.service.NodeService;

/**
*
*/
public interface DiscoveryNodesProvider {

DiscoveryNodes nodes();

@Nullable
NodeService nodeService();
}
14 changes: 14 additions & 0 deletions src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java
Expand Up @@ -33,6 +33,7 @@
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.component.Lifecycle;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.internal.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.discovery.Discovery;
Expand All @@ -45,6 +46,7 @@
import org.elasticsearch.discovery.zen.ping.ZenPingService;
import org.elasticsearch.discovery.zen.publish.PublishClusterStateAction;
import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.node.settings.NodeSettingsService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
Expand Down Expand Up @@ -106,6 +108,9 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen

private final AtomicBoolean initialStateSent = new AtomicBoolean();

@Nullable
private NodeService nodeService;

@Inject
public ZenDiscovery(Settings settings, ClusterName clusterName, ThreadPool threadPool,
TransportService transportService, ClusterService clusterService, NodeSettingsService nodeSettingsService,
Expand Down Expand Up @@ -137,6 +142,10 @@ public ZenDiscovery(Settings settings, ClusterName clusterName, ThreadPool threa
this.membership = new MembershipAction(settings, transportService, this, new MembershipListener());
}

public void setNodeService(@Nullable NodeService nodeService) {
this.nodeService = nodeService;
}

@Override
protected void doStart() throws ElasticSearchException {
Map<String, String> nodeAttributes = discoveryNodeService.buildAttributes();
Expand Down Expand Up @@ -227,6 +236,11 @@ public DiscoveryNodes nodes() {
return newNodesBuilder().put(localNode).localNodeId(localNode.id()).build();
}

@Override
public NodeService nodeService() {
return this.nodeService;
}

@Override
public void publish(ClusterState clusterState) {
if (!master) {
Expand Down

0 comments on commit de861d6

Please sign in to comment.