Debug ES 2.0 plugin in eclipse

Hi folks,

I have a jvm plugin with rest-action, which I wanted to upgrade to ES 2.0. But I was not able to debug in Eclipse anymore, how it does in former versions. The plugin simply does not get started.

I have a maven-project with ES 2.0 in the dependencies.
My run configuration has:
org.elasticsearch.bootstrap.Elasticsearch as Main-Class
start as argument
and as VM arguments:

 -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=logs/heapdump.hprof -Delasticsearch -Des.foreground=yes -ea -Des.path.home=/path/to/my/plugin/ -Des.security.manager.enabled=false -Des.http.cors.enabled=true -Des.http.cors.allow-origin=*

In classpath, there is JRE[J2SE-1.5], my plugin-project and maven dependencies

Any suggestions how I get debugging and startup of my plugin done out of eclipse?

No ideas at all?
How do you guys develop your plugins? Which IDE do you use?

You should use Java 8 and not Java 5.

Start a node with settings like this

Settings settings = Settings.settingsBuilder()
                .put("cluster.name", cluster)
                .put("path.home", getHome())
                .put("plugin.types", MyPlugin.class.getName())
                .build();

and then

Node node = NodeBuilder.nodeBuilder().settings(settings).build();
node.start();

At node start, plugin is loaded and you can test it.

Hi Jörg,

Thank you for the hint. My setting was J2SE 1.5 out of Java 8?!
I currently noticed, that Java 8 has all the 'old' J2SE included! :slight_smile:

I will try to get my environment running with this.

So from my understanding, I have to write my own startup main-class instead of using the default
org.elasticsearch.bootstrap.Elasticsearch to use plugin-types within the settings?
Is wonder this is really the only way? What has changed in 2.0.0, that debugging does not work then with the versions before? Sure, ElasticsearchF has gone, but is this the reason?
Or am I missing something else?

Why a main class?

If you study the org.elasticsearch.bootstrap.* source code, you can see they are simply a wrapper around NodeBuilder.nodeBuilder().settings(settings).build() adding features that are orthogonal to ES plugins i.e. JNA, OS specific settings, CLI, logging etc.

Beside API and layout changes, ES 2.0 has added a lot more security settings which can easily get in your way while plugin testing. I recommend to just start a node for easy plugin unit testing.

So for unit testing, It is clear to me what you meant.
But what I wanted to reach is simply upstart Elastic WITH loaded plugin in debug-mode in eclipse, like I did for former versions with main-class from bootstrap.ElasticsearchF.

Let's recap. Have you followed the instructions?

https://www.elastic.co/guide/en/elasticsearch/plugins/2.0/plugin-authors.html

It's hard to give useful advise to the statement "The plugin simply does not get started". Maybe you can describe the steps you made more closely so that it can be reproduced.

Hi dduft.

I had the same problem as you.

  1. Steps to solve it:
  2. Create a folder for your es_home.
  3. Configure Run/Debug configuration:
    • main class: org.elasticsearch.bootstrap.Elasticsearch
    • vm options: -Des.path.home=<path_to_prev_created_folder>
    • program args: start
  4. Start the application. The proper structure will be created in es.path.home folder.
  5. Stop the application.
  6. Create a folder ${es.path.home}/plugins/<plugin_name>
  7. Copy your plugin-descriptor.properties in this folder.
  8. Start the application in debug mode.

Now it should work, since all your sources in the classpath and plugin descriptor in the proper place.

2 Likes

Uladzimir, you saved my day! Thank you very much for the instructions!

HI Uladzimir
I start my plugin as your step,
But there are strange error log as below:

er]Exception in thread "main" java.lang.IllegalStateException: running tests but failed to invoke RandomizedContext#getRandom
Likely root cause: java.lang.IllegalStateException: No context information for thread: Thread[id=1, name=main, state=RUNNABLE, group=main]. Is this thread running under a class com.carrotsearch.randomizedtesting.RandomizedRunner runner context? Add @RunWith(class com.carrotsearch.randomizedtesting.RandomizedRunner.class) to your test class. Make sure your code accesses random contexts within @BeforeClass and @AfterClass boundary (for example, static test class initializers are not permitted to access random contexts).
at com.carrotsearch.randomizedtesting.RandomizedContext.context(RandomizedContext.java:244)
at com.carrotsearch.randomizedtesting.RandomizedContext.current(RandomizedContext.java:151)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.elasticsearch.common.Randomness.get(Randomness.java:101)
at org.elasticsearch.node.internal.InternalSettingsPreparer.randomNodeName(InternalSettingsPreparer.java:205)
at org.elasticsearch.node.internal.InternalSettingsPreparer.finalizeSettings(InternalSettingsPreparer.java:177)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:106)
at org.elasticsearch.common.cli.CliTool.(CliTool.java:107)
at org.elasticsearch.common.cli.CliTool.(CliTool.java:98)
at org.elasticsearch.bootstrap.BootstrapCLIParser.(BootstrapCLIParser.java:49)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:247)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.

I'm not sure reviving a super old thread is the right way to get help for this, but I'll try.

You can see that error if you try and run the tests without the RandomizedRunner that we use for all of our tests. It looks like you are trying to run a main class though so I'm not sure what is up. Are your tests somehow leaking into your main classes?

Hi nik
When i import latest elk to eclipse, Sibling project named with ":" prefix. It leads to import failed.
Is it a bug