Skip to content

Instantly share code, notes, and snippets.

@ianibo
Created February 18, 2012 10:23
Show Gist options
  • Save ianibo/1858624 to your computer and use it in GitHub Desktop.
Save ianibo/1858624 to your computer and use it in GitHub Desktop.
A Groovy Elasticsearch scriptlet that will not join a cluster because of the resolver strategy in GXContextBuilder
#!/usr/bin/groovy
@GrabResolver(name='es', root='https://oss.sonatype.org/content/repositories/releases')
@Grapes([
@Grab(group='org.elasticsearch', module='elasticsearch', version='0.19.0.RC2'),
@Grab(group='org.elasticsearch', module='elasticsearch-lang-groovy', version='1.1.0')])
import org.elasticsearch.groovy.client.GClient
import org.elasticsearch.groovy.node.GNode
import org.apache.log4j.*
LogManager.rootLogger.level = Level.DEBUG
println("Init");
GNode esnode = inites();
GClient client = esnode.getClient();
esnode.stop().close();
println("All done");
System.exit(0);
def inites() {
println("Init");
org.elasticsearch.groovy.node.GNodeBuilder nodeBuilder = new org.elasticsearch.groovy.node.GNodeBuilder()
// Warning **This does not do what you want it to**. Because the scriptlet appears to implement
// the setProperty method, the setters here will be called against the DemoContextProblem class and not
// the nodeBuilder as you want. Thus, this class can never join the cluster as it
// never receives any config properties. Although everything looks normal,
// you will always see "ping response {none}" in the logs if you're running a non-default cluster name.
nodeBuilder.settings {
node {
client = true
}
cluster {
name = "aggr"
}
http {
enabled = false
}
}
nodeBuilder.node()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment