Playing with GroovyConsole


(David Hernández) #1

Hi I'm playing with the Groovy API inside Groovy Console

@GrabResolver(name='elasticsearch',
root='http://oss.sonatype.org/content/repositories/releases/')
@GrabResolver(name='maven', root='http://repo1.maven.org/maven2/')
@Grab('org.elasticsearch:elasticsearch-client-groovy:0.10.0')
import org.elasticsearch.groovy.client.GClient
import org.elasticsearch.groovy.node.GNode
import org.elasticsearch.groovy.node.GNodeBuilder
import static org.elasticsearch.groovy.node.GNodeBuilder.*

GNodeBuilder nodeBuilder = nodeBuilder();
nodeBuilder.settings {
node {
client = true
}
cluster {
name = "elasticsearch"
}
}

GNode node = nodeBuilder.node()
node.stop().close()

I'm getting always this exception about configuration of names.txt :S

org.elasticsearch.env.FailedToResolveConfigException: Failed to
resolve config path [names.txt], tried file path [names.txt], path
file [C:\develop\Groovy-1.7.6\bin\config\names.txt], and classpath

at org.elasticsearch.env.Environment.resolveConfig(Environment.java:163)

I have running a node in localhost

curl -XGET 'http://localhost:9200/_cluster/health'
{"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":5,"active_shards"
:5,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":5}
hernand@UKLON-05916 ~/tomcat/bin

$ curl -XGET 'http://localhost:9200/'
{
"ok" : true,
"name" : "Solitaire",
"version" : {
"number" : "0.14.4",
"date" : "2011-01-31T21:37:39",
"snapshot_build" : false
},
.....

Any ideas what happend?

Regards
David H


(Enrique Medina Montenegro) #2

Hi David,

Try this out. It worked for me:

Regards.

On Tue, Feb 8, 2011 at 5:43 PM, David Hernández dahernan@gmail.com wrote:

Hi I'm playing with the Groovy API inside Groovy Console

@GrabResolver(name='elasticsearch',
root='http://oss.sonatype.org/content/repositories/releases/')
@GrabResolver(name='maven', root='http://repo1.maven.org/maven2/')
@Grab('org.elasticsearch:elasticsearch-client-groovy:0.10.0')
import org.elasticsearch.groovy.client.GClient
import org.elasticsearch.groovy.node.GNode
import org.elasticsearch.groovy.node.GNodeBuilder
import static org.elasticsearch.groovy.node.GNodeBuilder.*

GNodeBuilder nodeBuilder = nodeBuilder();
nodeBuilder.settings {
node {
client = true
}
cluster {
name = "elasticsearch"
}
}

GNode node = nodeBuilder.node()
node.stop().close()

I'm getting always this exception about configuration of names.txt :S

org.elasticsearch.env.FailedToResolveConfigException: Failed to
resolve config path [names.txt], tried file path [names.txt], path
file [C:\develop\Groovy-1.7.6\bin\config\names.txt], and classpath

   at

org.elasticsearch.env.Environment.resolveConfig(Environment.java:163)

I have running a node in localhost

curl -XGET 'http://localhost:9200/_cluster/health'

{"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":5,"active_shards"
:5,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":5}
hernand@UKLON-05916 ~/tomcat/bin

$ curl -XGET 'http://localhost:9200/'
{
"ok" : true,
"name" : "Solitaire",
"version" : {
"number" : "0.14.4",
"date" : "2011-01-31T21:37:39",
"snapshot_build" : false
},
.....

Any ideas what happend?

Regards
David H


(David Hernández) #3

I'm afraid it doesn't :frowning:

groovy> @GrabResolver(name='Codehaus', root='http://repository.codehaus.org')
groovy> @GrabResolver(name='Codehaus.Snapshots',
root='http://snapshots.repository.codehaus.org')
groovy> @GrabResolver(name='Codehaus.Snapshots',
root='http://oss.sonatype.org/content/repositories/releases/')
groovy> @GrabResolver(name='Codehaus.Snapshots',
root='http://repo1.maven.org/maven2/')
groovy> @Grapes([
groovy> @Grab(group='org.codehaus.groovy.modules.http-builder',
module='http-builder', version='0.5.1'),
groovy> @Grab(group='org.elasticsearch',
module='elasticsearch-client-groovy', version='0.10.0'),
groovy> @Grab(group='org.elasticsearch',
module='elasticsearch-lang-groovy', version='0.14.3'),
groovy> @Grab(group='org.apache.lucene', module='lucene-highlighter',
version='3.0.3'),
groovy> @GrabExclude(group='xerces', module='xercesImpl')])
groovy> import groovyx.net.http.*
groovy> import static groovyx.net.http.Method.*
groovy> import static groovyx.net.http.ContentType.*
groovy> import org.elasticsearch.common.xcontent.*
groovy> import static org.elasticsearch.common.xcontent.XContentFactory.*
groovy> import org.elasticsearch.groovy.node.GNode
groovy> import org.elasticsearch.groovy.client.*
groovy> import org.elasticsearch.groovy.node.GNodeBuilder
groovy> import static org.elasticsearch.groovy.node.GNodeBuilder.*
groovy> // Conectar con el servidor ES.
groovy> GNode node = nodeBuilder().node();
groovy> GClient client = node.client();
groovy> println client
groovy> node.close()

Exception thrown
08-Feb-2011 17:17:03 org.codehaus.groovy.runtime.StackTraceUtils sanitize

WARNING: Sanitizing stacktrace:

org.elasticsearch.env.FailedToResolveConfigException: Failed to
resolve config path [names.txt], tried file path [names.txt], path
file [C:\develop\Groovy-1.7.6\bin\config\names.txt], and classpath

at org.elasticsearch.env.Environment.resolveConfig(Environment.java:163)

On 8 February 2011 16:50, Enrique Medina Montenegro
e.medina.m@gmail.com wrote:

Hi David,
Try this out. It worked for me:
https://gist.github.com/816732
Regards.


(Shay Banon) #4

There is a single groovy client, no need for the client-groovy, just the lang-groovy (it was renamed). And it should be the same version as ES repo.

That names.txt file should be in the elasticsearch jar file.

-shay.banon
On Tuesday, February 8, 2011 at 7:19 PM, David Hernández wrote:

I'm afraid it doesn't :frowning:

groovy> @GrabResolver(name='Codehaus', root='http://repository.codehaus.org')
groovy> @GrabResolver(name='Codehaus.Snapshots',
root='http://snapshots.repository.codehaus.org')
groovy> @GrabResolver(name='Codehaus.Snapshots',
root='http://oss.sonatype.org/content/repositories/releases/')
groovy> @GrabResolver(name='Codehaus.Snapshots',
root='http://repo1.maven.org/maven2/')
groovy> @Grapes([
groovy> @Grab(group='org.codehaus.groovy.modules.http-builder',
module='http-builder', version='0.5.1'),
groovy> @Grab(group='org.elasticsearch',
module='elasticsearch-client-groovy', version='0.10.0'),
groovy> @Grab(group='org.elasticsearch',
module='elasticsearch-lang-groovy', version='0.14.3'),
groovy> @Grab(group='org.apache.lucene', module='lucene-highlighter',
version='3.0.3'),
groovy> @GrabExclude(group='xerces', module='xercesImpl')])
groovy> import groovyx.net.http.*
groovy> import static groovyx.net.http.Method.*
groovy> import static groovyx.net.http.ContentType.*
groovy> import org.elasticsearch.common.xcontent.*
groovy> import static org.elasticsearch.common.xcontent.XContentFactory.*
groovy> import org.elasticsearch.groovy.node.GNode
groovy> import org.elasticsearch.groovy.client.*
groovy> import org.elasticsearch.groovy.node.GNodeBuilder
groovy> import static org.elasticsearch.groovy.node.GNodeBuilder.*
groovy> // Conectar con el servidor ES.
groovy> GNode node = nodeBuilder().node();
groovy> GClient client = node.client();
groovy> println client
groovy> node.close()

Exception thrown
08-Feb-2011 17:17:03 org.codehaus.groovy.runtime.StackTraceUtils sanitize

WARNING: Sanitizing stacktrace:

org.elasticsearch.env.FailedToResolveConfigException: Failed to
resolve config path [names.txt], tried file path [names.txt], path
file [C:\develop\Groovy-1.7.6\bin\config\names.txt], and classpath

at org.elasticsearch.env.Environment.resolveConfig(Environment.java:163)

On 8 February 2011 16:50, Enrique Medina Montenegro
e.medina.m@gmail.com wrote:

Hi David,
Try this out. It worked for me:
https://gist.github.com/816732
Regards.


(David Hernández) #5

Still not working with the correct client but I put manually
"names.txt" in C:\develop\Groovy-1.7.6\bin\config\names.txt
and it works like a charm.

It could be a classpath issue using Groovy Console

Here the code:

@GrabResolver(name='elasticsearch',root='http://oss.sonatype.org/content/groups/staging/')
@GrabResolver(name='maven', root='http://repo1.maven.org/maven2/')
@Grab('org.elasticsearch:elasticsearch-lang-groovy:0.14.4')
import org.elasticsearch.groovy.client.GClient
import org.elasticsearch.groovy.node.GNode
import org.elasticsearch.groovy.node.GNodeBuilder
import static org.elasticsearch.groovy.node.GNodeBuilder.*

GNodeBuilder nodeBuilder = nodeBuilder();
nodeBuilder.settings {
node {
client = true
}
cluster {
name = "elasticsearch"
}
}
GNode node = nodeBuilder.node()
node.stop().close()

org.elasticsearch.env.FailedToResolveConfigException: Failed to
resolve config path [names.txt], tried file path [names.txt], path
file [C:\develop\Groovy-1.7.6\bin\config\names.txt], and classpath

at org.elasticsearch.env.Environment.resolveConfig(Environment.java:191)

On 8 February 2011 18:14, Shay Banon shay.banon@elasticsearch.com wrote:

There is a single groovy client, no need for the client-groovy, just the
lang-groovy (it was renamed). And it should be the same version as ES repo.
That names.txt file should be in the elasticsearch jar file.
-shay.banon


(system) #6