4

I am trying to connect to cassandra using Java (Hadoop2), but it is throwing the below error

Connecting to IP Address 127.0.0.1:9042...
16/04/12 10:35:13 INFO core.NettyUtil: Found Netty's native epoll     transport in the classpath, using it
Exception in thread "main" java.lang.NoSuchMethodError:    com.google.common.util.concurrent.Futures.withFallback(Lcom/google/common  /util/concurrent/ListenableFuture;Lcom/google/common/util/concurrent  /FutureFallback;Ljava/util/concurrent/Executor;)Lcom/google/common/util/concurrent/ListenableFuture;
    at com.datastax.driver.core.Connection.initAsync(Connection.java:177)
    at com.datastax.driver.core.Connection$Factory.open(Connection.java:731)
    at com.datastax.driver.core.ControlConnection.tryConnect(ControlConnection.java:251)
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:199)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:77)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1414)
    at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:393)
    at cassandra.CassandraConnector.connect(CassandraConnector.java:42)
    at cassandra.Main.main(Main.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
  • Please see the cassandra environment details::

    • Connected to Test Cluster at 127.0.0.1:9042.
    • [cqlsh 5.0.1 | Cassandra 2.2.5 | CQL spec 3.3.1 | Native protocol v4]
  • Jars i am using::

    • cassandra-driver-core-3.0.0.jar
    • guava-19.0.jar
    • netty-all-4.1.0.CR7.jar

I have tried other jars( guava >=16.01 ,netty-all-4.0...,cassandra-driver-core-2.2.0). but always it is throwing more or less similar error.

please see below the code snippet used for establishing connection:

public void connect(final String node, final int port)

     {

        this.cluster =  Cluster.builder().addContactPoint(node).withPort(port)
            .build();

       final Metadata metadata = cluster.getMetadata();
       ProtocolVersion myCurrentVersion = cluster.getConfiguration()
            .getProtocolOptions()
            .getProtocolVersion();
       System.out.println(myCurrentVersion);

       out.printf("Connected to cluster: %s\n",  metadata.getClusterName());

       for (final Host host : metadata.getAllHosts())

          {

            out.printf("Datacenter: %s; Host: %s; Rack: %s\n",

            host.getDatacenter(), host.getAddress(), host.getRack());

          }

         session = cluster.connect();

     }

  public static void main(String[] args) {
        // TODO Auto-generated method stub

          final CassandraConnector client = new CassandraConnector();

          final String ipAddress = args.length > 0 ? args[0] : "127.0.0.1";

          final int port = args.length > 1 ? Integer.parseInt(args[1]) : 9042;

          out.println("Connecting to IP Address " + ipAddress + ":" + port + "...");

          client.connect(ipAddress, port);

          client.close();

    }

I think it might be because of some version conflict, but unable to find the correct version. Have checked some other similar posts and tried the solutions (using different jars) but could not resolve the issue Any help will be highly appreciated.

B K
  • 723
  • 8
  • 17
  • Can you please give more information like, hadoop version, Cassandra version, which building tool you are using(eg. maven), are you building a fat jar and are you using YARN? – Abhinandan Satpute Apr 12 '16 at 09:14
  • Futures.withFallback has been introduced in Guava 14.0. Your Hadoop jobs must be using an older version. – adutra Apr 12 '16 at 15:34

1 Answers1

1

Yes.You are correct.This issue occurs due to the version conflict. I will recommend you to use guava Jar and remove other unnecessary Jars. Also please have a look at this answer, it might help you.

Community
  • 1
  • 1
Abhinandan Satpute
  • 2,558
  • 6
  • 25
  • 43
  • Hadoop Version : Hadoop 2.5.0-cdh5.3.8 , Cassandra version: [cqlsh 5.0.1 | Cassandra 2.2.5 | CQL spec 3.3.1 | Native protocol v4] . My cluster has 8 nodes. I have installed cassandra in one of the node only (standalone), it is not configured. Actually i am not sure whether i need to configure cassandra in cluster so i can execute the java jar using 'hadoop jar jarname classname' – B K Apr 12 '16 at 09:41
  • I created a jar file provided all the jars in referenced library, then i created the jar and exported to my particular node. When i execute using command 'java -jar jarname', it is working now. But when i am trying to execute using 'hadoop jar jarname classname' it is throwing exception. – B K Apr 12 '16 at 09:45
  • have you removed unnecessary jars? – Abhinandan Satpute Apr 12 '16 at 10:08
  • cassandra-driver-core-3.0.0.jar guava-19.0.jar netty-all-4.1.0.CR7.jar are necessary jar it seems and it is connecting as standalone. problem occurs when i execute in hadoop – B K Apr 12 '16 at 10:34
  • It simply means hadoop is not able to resolve the necessary dependencies. Can you please give me the complete run command you are using? – Abhinandan Satpute Apr 12 '16 at 11:08