Problem creating elasticsearch client under Apache Tomcat 7

Hi,

I am running Apache Tomcat 7 from within Eclipse and running elasticsearch
(port 9300/9200) on the same machine.

I am initializing the node within my ServletContextListener contextInitialized
method using the following code:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I am getting the following exception:

org.elasticsearch.discovery.MasterNotDiscoveredException: waited for
[30s] at
org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(
TransportMasterNodeOperationAction.java:169)

            at 

org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(*
InternalClusterService.java:371*)

            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(*

ThreadPoolExecutor.java:886*)

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(*

ThreadPoolExecutor.java:908*)

            at java.lang.Thread.run(*Thread.java:662*)

If I remove client(true) part:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… it starts without an exception but it also starts another server
listening on 9301 (I have checked it using netstat).

Anybody has got clue what is going on here?

Regards,
Janusz

--

Hi,

Starting a Client Node requires:

  • A running Elasticsearch node
  • With the same clustername

So, check that you have already a node running before starting your webapp.
Check the clustername of this running node and check if you set the same cluster
name for the embedded node. For example, add in your src/resources dir a copy of
your elasticsearch.yml file or set the clusterName using the Java API.

Also, check if you have firewall rules that could block somehow your requests.

Does it help?

Le 16 janvier 2013 à 10:05, JD jdalecki@tycoint.com a écrit :

Hi,

I am running Apache Tomcat 7 from within Eclipse and running elasticsearch
(port 9300/9200) on the same machine.

I am initializing the node within my ServletContextListener
contextInitialized method using the following code:

   // Then we start our node for tests

   node = NodeBuilder.nodeBuilder().client(true).node();

   // We wait now for the yellow (or green) status


  node.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I am getting the following exception:

org.elasticsearch.discovery.MasterNotDiscoveredException: waited for [30s] at
org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(TransportMasterNodeOperationAction.java:169)

             at

org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(InternalClusterService.java:371)

             at

java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

             at

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

             at java.lang.Thread.run(Thread.java:662)

If I remove client(true) part:

   // Then we start our node for tests

   node = NodeBuilder.nodeBuilder().client(true).node();

   // We wait now for the yellow (or green) status


  node.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… it starts without an exception but it also starts another server listening
on 9301 (I have checked it using netstat).

Anybody has got clue what is going on here?

Regards,
Janusz

--

--
David Pilato
http://www.scrutmydocs.org/
http://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

David is right. That error means that you are most likely creating a brand
new cluster with only the node that you create via java code.
Saying client(true) is just a shortcut to say that the node won't contain
data and cannot become a master. Of course if that's the only node in your
cluster you have a problem because you must have a master in the cluster
thus you get back that exception.

If you remove the client(true) your node can become master, thus no error,
but you are still not joining the existing cluster that you meant to join.

As David wrote, you just need to check the name of the running cluster that
you want to join (configured in config/elasticsearch.yml) and use it when
you create the node like this:

node = NodeBuilder.nodeBuilder
().clusterName("your_cluster_name").client(true).node();

Otherwise the default cluster name used is "elasticsearch".

Cheers,
Luca

On Wednesday, January 16, 2013 10:05:51 AM UTC+1, JD wrote:

Hi,

I am running Apache Tomcat 7 from within Eclipse and running elasticsearch
(port 9300/9200) on the same machine.

I am initializing the node within my ServletContextListener contextInitialized
method using the following code:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I am getting the following exception:

org.elasticsearch.discovery.MasterNotDiscoveredException: waited for
[30s] at
org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(
TransportMasterNodeOperationAction.java:169)

            at 

org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(
InternalClusterService.java:371)

            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(

ThreadPoolExecutor.java:886)

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(*

ThreadPoolExecutor.java:908*)

            at java.lang.Thread.run(*Thread.java:662*)

If I remove client(true) part:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… it starts without an exception but it also starts another server
listening on 9301 (I have checked it using netstat).

Anybody has got clue what is going on here?

Regards,
Janusz

--

Hi David,

  1.  I have a running Elasticsearch local node – cluster name is 
    

“elasticsearch”

  1.  Firewall is switched off
    
  2.  I Have changed the code to:
    

    // Then we start our node for tests

    node = NodeBuilder.nodeBuilder().clusterName("elasticsearch"
    ).data(false).client(true).node();

    // We wait now for the yellow (or green) status

    node
    .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I get the same problem.

Regards,

Janusz

On Wednesday, 16 January 2013 20:05:51 UTC+11, JD wrote:

Hi,

I am running Apache Tomcat 7 from within Eclipse and running elasticsearch
(port 9300/9200) on the same machine.

I am initializing the node within my ServletContextListener contextInitialized
method using the following code:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I am getting the following exception:

org.elasticsearch.discovery.MasterNotDiscoveredException: waited for
[30s] at
org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(
TransportMasterNodeOperationAction.java:169)

            at 

org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(
InternalClusterService.java:371)

            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(

ThreadPoolExecutor.java:886)

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(*

ThreadPoolExecutor.java:908*)

            at java.lang.Thread.run(*Thread.java:662*)

If I remove client(true) part:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… it starts without an exception but it also starts another server
listening on 9301 (I have checked it using netstat).

Anybody has got clue what is going on here?

Regards,
Janusz

--

Are you using the same version of elasticsearch for client and server?

On Wednesday, January 16, 2013 5:58:40 PM UTC-5, JD wrote:

Hi David,

  1.  I have a running Elasticsearch local node – cluster name is 
    

“elasticsearch”

  1.  Firewall is switched off
    
  2.  I Have changed the code to:
    

    // Then we start our node for tests

    node = NodeBuilder.nodeBuilder().clusterName("elasticsearch"
    ).data(false).client(true).node();

    // We wait now for the yellow (or green) status

    node
    .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I get the same problem.

Regards,

Janusz

On Wednesday, 16 January 2013 20:05:51 UTC+11, JD wrote:

Hi,

I am running Apache Tomcat 7 from within Eclipse and running
elasticsearch (port 9300/9200) on the same machine.

I am initializing the node within my ServletContextListener contextInitialized
method using the following code:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I am getting the following exception:

org.elasticsearch.discovery.MasterNotDiscoveredException: waited for
[30s] at
org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(
TransportMasterNodeOperationAction.java:169)

            at 

org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(
InternalClusterService.java:371)

            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(

ThreadPoolExecutor.java:886)

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(*

ThreadPoolExecutor.java:908*)

            at java.lang.Thread.run(*Thread.java:662*)

If I remove client(true) part:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… it starts without an exception but it also starts another server
listening on 9301 (I have checked it using netstat).

Anybody has got clue what is going on here?

Regards,
Janusz

--

I am positive. Both elasticsearch and web server (WEB-INF\lib) are using
elasticsearch-0.20.1.jar

Regards,
Janusz

On Wednesday, January 16, 2013 8:05:51 PM UTC+11, JD wrote:

Hi,

I am running Apache Tomcat 7 from within Eclipse and running elasticsearch
(port 9300/9200) on the same machine.

I am initializing the node within my ServletContextListener contextInitialized
method using the following code:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I am getting the following exception:

org.elasticsearch.discovery.MasterNotDiscoveredException: waited for
[30s] at
org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(
TransportMasterNodeOperationAction.java:169)

            at 

org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(
InternalClusterService.java:371)

            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(

ThreadPoolExecutor.java:886)

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(*

ThreadPoolExecutor.java:908*)

            at java.lang.Thread.run(*Thread.java:662*)

If I remove client(true) part:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… it starts without an exception but it also starts another server
listening on 9301 (I have checked it using netstat).

Anybody has got clue what is going on here?

Regards,
Janusz

--

Did you change elasticsearch config in any way? Could you post
elasticsearch server log here?

On Friday, January 18, 2013 11:30:12 PM UTC-5, JD wrote:

I am positive. Both elasticsearch and web server (WEB-INF\lib) are using
elasticsearch-0.20.1.jar

Regards,
Janusz

On Wednesday, January 16, 2013 8:05:51 PM UTC+11, JD wrote:

Hi,

I am running Apache Tomcat 7 from within Eclipse and running
elasticsearch (port 9300/9200) on the same machine.

I am initializing the node within my ServletContextListener contextInitialized
method using the following code:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I am getting the following exception:

org.elasticsearch.discovery.MasterNotDiscoveredException: waited for
[30s] at
org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(
TransportMasterNodeOperationAction.java:169)

            at 

org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(
InternalClusterService.java:371)

            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(

ThreadPoolExecutor.java:886)

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(*

ThreadPoolExecutor.java:908*)

            at java.lang.Thread.run(*Thread.java:662*)

If I remove client(true) part:

  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… it starts without an exception but it also starts another server
listening on 9301 (I have checked it using netstat).

Anybody has got clue what is going on here?

Regards,
Janusz

--

Hi,
I am also facing the same issue.

Did you manage to resolve this?

Please let me know.

Arun

Hi,
any news here ?
Please help
Arun