All host(s) tried for query failed

cassandra, cluster-computing, google-compute-engine, yaml

Solution

It seems to be a firewall problem. After allowing traffic on both 9160 and 9042, the connection is finally established.

Problem

I used Google compute engine to set up a cluster of three cassandra nodes. After running the "nodetool status" I get: ``` antoniogallo88@cassandra-7m0w:~$ nodetool status Datacenter: europe-west1 ======================== Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 10.240.41.185 56.28 KB 256 33.2% edf4c2c8-f746-4c86-8b1e-4d4317788de9 b UN 10.240.145.130 56.31 KB 256 30.6% 76025d1d-b5e4-4510-afd9-e0c52ae4aa2b b UN 10.240.194.231 60.94 KB 256 36.2% 1c5594d6-4a62-4cb7-bb4e-ab15545af6a0 b ``` So, all works fine. Also the cqlsh command works well. My problem is when I run the following: ``` package com.example.cassandra; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Host; import com.datastax.driver.core.Metadata; public class SimpleClient { private Cluster cluster; public void connect(String node, int port) { cluster = Cluster.builder() // .addContactPoints("10.240.41.185", "10.240.145.130", "10.240.194.231").withPort(port).build(); .addContactPoints(node).withPort(port).build(); Metadata metadata = cluster.getMetadata(); System.out.printf("Connected to cluster: %s\n", metadata.getClusterName()); for ( Host host : metadata.getAllHosts() ) { System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack()); } } public void close() { cluster.close();; } public static void main(String[] args) { SimpleClient client = new SimpleClient(); client.connect("10.240.41.185", 9042); client.close(); } } ``` I then get: ``` SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /10.240.41.185:9042 (com.datastax.driver.core.TransportException: [/10.240.41.185:9042] Cannot connect)) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:193) at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79) at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1148) at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:313) at com.example.cassandra.SimpleClient.connect(SimpleClient.java:15) at com.example.cassandra.SimpleClient.main(SimpleClient.java:30) ``` In cassandra.yaml: ``` start_native_transport: true rpc_address = 0.0.0.0 native_transport_port: 9042 listen_address: 10.240.145.130 ``` If i have to edit cassandra.yaml file, how I could do this if I'm using google compute engine? Thanks

Original source