Add support for metadata es_port. If you run on a specific port, it will indicate it to GCE plugin. By default, 9300 will be used.

This commit is contained in:
David Pilato 2013-07-08 15:44:24 +02:00
parent ca45569f0e
commit aaa4768131
4 changed files with 66 additions and 13 deletions

View File

@ -249,6 +249,44 @@ Then, define it in `elasticsearch.yml`:
tags: elasticsearch, dev
```
Changing default transport port
-------------------------------
By default, elasticsearch GCE plugin assumes that you run elasticsearch on 9300 default port.
But you can specify the port value elasticsearch is meant to use using google compute engine metadata `es_port`:
### When creating instance
Add `--metadata=es_port:9301` option:
```sh
# when creating first instance
gcutil --project=es-cloud addinstance myesnode1 --service_account_scope=compute-rw,storage-full --persistent_boot_disk --metadata=es_port:9301
# when creating an instance from an image
gcutil --project=es-cloud addinstance --image=elasticsearch-0-90-2 \
--kernel=projects/google/global/kernels/gce-v20130603 myesnode2 \
--zone europe-west1-a --machine_type f1-micro --service_account_scope=compute-rw \
--persistent_boot_disk --metadata=es_port:9301
```
### On a running instance
```sh
# Get metadata fingerprint
gcutil --project=es-cloud getinstance myesnode1 --zone=europe-west1-a
+------------------------+---------------------------------------------------------------------------------------------------------+
| property | value |
+------------------------+---------------------------------------------------------------------------------------------------------+
| metadata | |
| fingerprint | 42WmSpB8rSM= |
+------------------------+---------------------------------------------------------------------------------------------------------+
# Use that fingerprint
gcutil --project=es-cloud setinstancemetadata myesnode1 --zone=europe-west1-a --metadata=es_port:9301 --fingerprint=42WmSpB8rSM=
```
Tips
----

View File

@ -168,11 +168,11 @@ public class GceUnicastHostsProvider extends AbstractComponent implements Unicas
}
}
if (filterByTag) {
logger.trace("*** filtering out instance {} based tags {}, not part of {}", name, tags,
logger.trace("filtering out instance {} based tags {}, not part of {}", name, tags,
instance.getTags() == null ? "" : instance.getTags().getItems());
continue;
} else {
logger.trace("*** instance {} with tags {} is added to discovery", name, tags);
logger.trace("instance {} with tags {} is added to discovery", name, tags);
}
String ip_public = null;
@ -207,7 +207,22 @@ public class GceUnicastHostsProvider extends AbstractComponent implements Unicas
// We can ignore it in the list of DiscoveryNode
logger.trace("current node found. Ignoring {} - {}", name, ip_private);
} else {
TransportAddress[] addresses = transportService.addressesFromString(ip_private);
String address = ip_private;
// Test if we have es_port metadata defined here
if (instance.getMetadata() != null && instance.getMetadata().containsKey("es_port")) {
Object es_port = instance.getMetadata().get("es_port");
logger.trace("es_port is defined with {}", es_port);
if (es_port instanceof String) {
address = address.concat(":").concat((String) es_port);
} else {
// Ignoring other values
logger.trace("es_port is instance of {}. Ignoring...", es_port.getClass().getName());
}
}
// ip_private is a single IP Address. We need to build a TransportAddress from it
TransportAddress[] addresses = transportService.addressesFromString(address);
// we only limit to 1 addresses, makes no sense to ping 100 ports
for (int i = 0; (i < addresses.length && i < UnicastZenPing.LIMIT_PORTS_COUNT); i++) {
logger.trace("adding {}, type {}, image {}, address {}, transport_address {}, status {}", name, type,

View File

@ -20,6 +20,7 @@
package org.elasticsearch.cloud.gce.tests;
import com.google.api.services.compute.model.Instance;
import com.google.api.services.compute.model.Metadata;
import com.google.api.services.compute.model.NetworkInterface;
import com.google.api.services.compute.model.Tags;
import org.elasticsearch.ElasticSearchException;
@ -52,6 +53,7 @@ public abstract class GceComputeServiceAbstractMock extends AbstractLifecycleCom
Collection<Instance> instances = new ArrayList<Instance>();
// For each instance (item of tags)
int port = 9300;
for (List<String> tags : getTags()) {
Instance instance = new Instance();
instance.setName("Mock Node " + tags);
@ -67,7 +69,13 @@ public abstract class GceComputeServiceAbstractMock extends AbstractLifecycleCom
networkInterfaces.add(networkInterface);
instance.setNetworkInterfaces(networkInterfaces);
// Add metadata es_port:930X where X is the instance number
Metadata metadata = new Metadata();
metadata.put("es_port", "" + port);
instance.setMetadata(metadata);
instances.add(instance);
port++;
}

View File

@ -47,11 +47,7 @@ public class GceDifferentTagsTest extends GceAbstractTest {
nodeBuilder("elasticsearch,dev");
// We expect having 1 node as part of the cluster, let's test that
// TODO Fix that test as we don't filter yet on port, each node can see each other
checkNumberOfNodes(2);
// Should be
// checkNumberOfNodes(1);
checkNumberOfNodes(1);
}
@Test
@ -63,10 +59,6 @@ public class GceDifferentTagsTest extends GceAbstractTest {
nodeBuilder("elasticsearch");
// We expect having 1 nodes as part of the cluster, let's test that
// TODO Fix that test as we don't filter yet on port, each node can see each other
checkNumberOfNodes(2);
// Should be
// checkNumberOfNodes(1);
checkNumberOfNodes(1);
}
}