Reputation: 22956
Error is
Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /172.17.1.XX:9160 (com.datastax.driver.core.TransportException: [/172.17.1.XX:9160] Cannot connect))
at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:196)
at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:80)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1145)
at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:313)
at com.example.cassandra.Client.connect(Client.java:18)
at com.example.cassandra.Client.main(Client.java:74)
Version of datastax is dse 4.5.2
Line where error occurs is connect(node)
cluster = Cluster.builder().addContactPoint(node).withPort(9160).build();
Metadata metadata = cluster.getMetadata(); //Error at this line
Call to the function is
public static void main(String a[])
{
System.out.println("I am in");
Client client = new Client();
client.connect("172.17.1.XX");
client.close();
}
pom.xml is
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.cassandra</groupId>
<artifactId>simple-client</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.apache-extras.cassandra-jdbc</groupId>
<artifactId>cassandra-jdbc</artifactId>
<version>1.2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<mainClass>com.example.cassandra.Client</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I reffered this link
Then i tried
telnet 172.17.1.XX 9160
Trying 172.17.1.XX...
Connected to 172.17.1.XX.
Escape character is '^]'.
If i type something, it says connection closed by foreign agent
netstat -plten
on 172.17.1.XX
shows
tcp 0 0 127.0.0.1:8984 0.0.0.0:* LISTEN 0 73148094 19145/java
tcp 0 0 127.0.0.1:7000 0.0.0.0:* LISTEN 0 73148635 19145/java
tcp 0 0 0.0.0.0:7199 0.0.0.0:* LISTEN 0 73148631 19145/java
tcp 0 0 0.0.0.0:50370 0.0.0.0:* LISTEN 0 73148632 19145/java
tcp 0 0 0.0.0.0:9160 0.0.0.0:* LISTEN 0 73148104 19145/java
tcp 0 0 0.0.0.0:33935 0.0.0.0:* LISTEN 0 73148630 19145/java
tcp 0 0 0.0.0.0:9042 0.0.0.0:* LISTEN 0 73148103 19145/java
tcp 0 0 0.0.0.0:8983 0.0.0.0:* LISTEN 0 73148083 19145/java
So how do i solve this issue? Any solutions?
Upvotes: 1
Views: 2144
Reputation: 4667
You're connecting to the wrong port: Java Driver connects to the Native Port (usually 9042) and not the Thrift Port (usually 9160). Change this line
cluster = Cluster.builder().addContactPoint(node).withPort(9042).build();
Upvotes: 2