1
votes

Had a fresh installation of Apache Cassandra version 3.7

Installation was successful and i could access cqlsh with out any issues.

[dpmuser@LOGDPM01 bin]$ cqlsh Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.7 | CQL spec 3.4.2 | Native protocol v4]

But when i try to connect via DataStax Cassandra client , I am hitting NoHostAvailableException .

Here is the sample code i tried

import com.datastax.driver.core.*;
public class DBHitTEst {
public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    Session session = null; 
    Cluster cluster = Cluster.builder()
            .addContactPoints("127.0.0.1").withPort(9042)
            .build();
    System.out.println("Connecting to cluster ...");
    session = cluster.connect();
    System.out.print("Connected !"+session);
}}

Exception in console shown below.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Connecting to cluster ... Aug 10, 2017 7:58:23 AM io.netty.channel.ChannelInitializer channelRegistered WARNING: Failed to initialize a channel. Closing: [id: 0x7d2724c5] java.lang.NoSuchMethodError: io.netty.util.AttributeKey.valueOf(Ljava/lang/String;)Lio/netty/util/AttributeKey; at com.datastax.driver.core.Message.(Message.java:39) at com.datastax.driver.core.Connection$Initializer.initChannel(Connection.java:1425) . . . Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1:9042 (com.datastax.driver.core.exceptions.TransportException: [/127.0.0.1:9042] Cannot connect)) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:232) at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79) at com.datastax.driver.core.Cluster$Manager.negotiateProtocolVersionAndConnect(Cluster.java:1600) at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1518) at com.datastax.driver.core.Cluster.init(Cluster.java:159) at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:330) at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:305) at com.datastax.driver.core.Cluster.connect(Cluster.java:247) at com.cassandra.db.executables.DBHitTEst.main(DBHitTEst.java:14)

Libraries References

cassandra-driver-core-3.3.0.jar
guava-23.0.jar
log4j-api-2.8.2.jar
metrics-core-3.0.2.jar
netty-all-4.0.9.Final.jar
slf4j-api-1.7.25.jar

Important configs is cassandra.yaml

start_rpc: false
start_native_transport: true
native_transport_port: 9042
rpc_address: localhost
rpc_port: 9160
listen_address: localhost
seeds: "127.0.0.1"

Other system particulars

[dpmuser@LOGDPM01 conf]$ hostname
LOGDPM01

[dpmuser@LOGDPM01 conf]$ more /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[dpmuser@LOGDPM01 conf]$ ping LOGDPM01
PING LOGDPM01 (10.0.2.15) 56(84) bytes of data.
64 bytes from LOGDPM01 (10.0.2.15): icmp_seq=1 ttl=64 time=0.055 ms

Running centos VM.Kindly let me know where am i wrong ?

1
are you running C* on the vm and trying to run your code from outside that VM? run netstat -anp | grep 9042 on the host your running your code from.Chris Lohfink
Nope both C* and code are in same VMuser3619698
run netstat -anp | grep 9042 before starting app and give outputChris Lohfink
"$ netstat -anp | grep 9042 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 127.0.0.1:9042 0.0.0.0:* LISTEN 11551/java tcp 0 0 127.0.0.1:46988 127.0.0.1:9042 ESTABLISHED 16883/python tcp 0 0 127.0.0.1:9042 127.0.0.1:46989 ESTABLISHED 11551/java tcp 0 0 127.0.0.1:9042 127.0.0.1:46988 ESTABLISHED 11551/java tcp 0 0 127.0.0.1:46989 127.0.0.1:9042 ESTABLISHED 16883/python"user3619698
Excuse me for bad edit . Couldnt get it aligned .user3619698

1 Answers

0
votes

Library mismatch was throwing the warning I observed in console .

WARNING: Failed to initialize a channel. Closing: [id: 0x7d2724c5] java.lang.NoSuchMethodError: io.netty.util.AttributeKey.valueOf(Ljava/lang/String;)Lio/netty/util/AttributeKey; at com.datastax.driver.core.Message.(Message.java:39) at com.datastax.driver.core.Connection$Initializer.initChannel(Connection.java:1425) . . .

On choosing the correct libraries from the lib folder of Cassandra installation directly sorted the issue .