logger.error(nae.getMessage()); throw nae;
@Override public NoHostAvailableException copy() { return new NoHostAvailableException(getMessage(), this, errors); }
@Override protected Connection tryReconnect() throws ConnectionException { if (isShutdown) throw new ConnectionException(null, "Control connection was shut down"); try { return reconnectInternal(queryPlan(), false); } catch (NoHostAvailableException e) { throw new ConnectionException(null, e.getMessage()); } catch (UnsupportedProtocolVersionException e) { // reconnectInternal only propagate those if we've not decided on the protocol version // yet, // which should only happen on the initial connection and thus in connect() but never // here. throw new AssertionError(); } }
/** * @return Result of healthy or unhealthy based on the cql statement */ @Override public Result check() { boolean res = false; String msg = ""; try { // this.session.execute( getBoundedStatemen() ); this.session.execute(SELECT_NOW_FROM_SYSTEM_LOCAL); res = true; } catch (NoHostAvailableException ex) { LOGGER.error("No hosts available", ex); msg = ex.getMessage(); } return res ? Result.healthy() : Result.unhealthy(msg); } }
@Test(groups = "unit") public void should_build_default_message_when_less_than_3_errors() { NoHostAvailableException e = new NoHostAvailableException(buildMockErrors(3)); String message = e.getMessage(); assertThat(message).startsWith("All host(s) tried for query failed"); assertThat(message) .contains( "/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)"); assertThat(message) .contains( "/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)"); assertThat(message) .contains( "/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)"); }
@Test(groups = "unit") public void should_build_default_message_when_more_than_3_errors() { NoHostAvailableException e = new NoHostAvailableException(buildMockErrors(4)); String message = e.getMessage(); assertThat(message).startsWith("All host(s) tried for query failed"); assertThat(message) .contains( "/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)"); assertThat(message) .contains( "/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)"); assertThat(message) .contains( "/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)"); assertThat(message) .contains("only showing errors of first 3 hosts, use getErrors() for more details"); }
/** * Tests the NoHostAvailableException. by attempting to build a cluster using the IP address * "255.255.255.255" and test all available exception methods. */ @Test(groups = "short") public void noHostAvailableException() throws Exception { try { Cluster.builder().addContactPoints("255.255.255.255").build(); } catch (NoHostAvailableException e) { assertEquals(e.getErrors().size(), 1); assertTrue( e.getErrors() .values() .iterator() .next() .toString() .contains("[/255.255.255.255] Cannot connect")); NoHostAvailableException copy = (NoHostAvailableException) e.copy(); assertEquals(copy.getMessage(), e.getMessage()); assertEquals(copy.getErrors(), e.getErrors()); } }
@Override public DriverException copy() { return new NoHostAvailableException(getMessage(), this, errors); }
@Override protected Connection tryReconnect() throws ConnectionException { try { return reconnectInternal(); } catch (NoHostAvailableException e) { throw new ConnectionException(null, e.getMessage()); } catch (UnsupportedProtocolVersionException e) { // reconnectInternal only propagate those if we've not decided on the protocol version yet, // which should only happen on the initial connection and thus in connect() but never here. throw new AssertionError(); } }
@Override public NoHostAvailableException copy() { return new NoHostAvailableException(getMessage(), this, errors); }
@Override public NoHostAvailableException copy() { return new NoHostAvailableException(getMessage(), this, errors); }
@Override public NoHostAvailableException copy() { return new NoHostAvailableException(getMessage(), this, errors); }
@Override protected Connection tryReconnect() throws ConnectionException { if (isShutdown) throw new ConnectionException(null, "Control connection was shut down"); try { return reconnectInternal(queryPlan(), false); } catch (NoHostAvailableException e) { throw new ConnectionException(null, e.getMessage()); } catch (UnsupportedProtocolVersionException e) { // reconnectInternal only propagate those if we've not decided on the protocol version yet, // which should only happen on the initial connection and thus in connect() but never here. throw new AssertionError(); } }
@Override protected Connection tryReconnect() throws ConnectionException { if (isShutdown) throw new ConnectionException(null, "Control connection was shut down"); try { return reconnectInternal(queryPlan(), false); } catch (NoHostAvailableException e) { throw new ConnectionException(null, e.getMessage()); } catch (UnsupportedProtocolVersionException e) { // reconnectInternal only propagate those if we've not decided on the protocol version yet, // which should only happen on the initial connection and thus in connect() but never here. throw new AssertionError(); } }
@Override protected Connection tryReconnect() throws ConnectionException { if (isShutdown) throw new ConnectionException(null, "Control connection was shut down"); try { return reconnectInternal(queryPlan(), false); } catch (NoHostAvailableException e) { throw new ConnectionException(null, e.getMessage()); } catch (UnsupportedProtocolVersionException e) { // reconnectInternal only propagate those if we've not decided on the protocol version yet, // which should only happen on the initial connection and thus in connect() but never here. throw new AssertionError(); } }
@Test(groups = "unit") public void should_build_default_message_when_less_than_3_errors() { NoHostAvailableException e = new NoHostAvailableException(buildMockErrors(3)); String message = e.getMessage(); assertThat(message).startsWith("All host(s) tried for query failed"); assertThat(message) .contains( "/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)"); assertThat(message) .contains( "/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)"); assertThat(message) .contains( "/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)"); }
@Test(groups = "unit") public void should_build_default_message_when_more_than_3_errors() { NoHostAvailableException e = new NoHostAvailableException(buildMockErrors(4)); String message = e.getMessage(); assertThat(message).startsWith("All host(s) tried for query failed"); assertThat(message) .contains( "/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)"); assertThat(message) .contains( "/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)"); assertThat(message) .contains( "/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)"); assertThat(message) .contains("only showing errors of first 3 hosts, use getErrors() for more details"); }
/** * Tests the NoHostAvailableException. by attempting to build a cluster using the IP address * "255.255.255.255" and test all available exception methods. */ @Test(groups = "short") public void noHostAvailableException() throws Exception { try { Cluster.builder().addContactPoints("255.255.255.255").build(); } catch (NoHostAvailableException e) { assertEquals(e.getErrors().size(), 1); assertTrue( e.getErrors() .values() .iterator() .next() .toString() .contains("[/255.255.255.255] Cannot connect")); NoHostAvailableException copy = (NoHostAvailableException) e.copy(); assertEquals(copy.getMessage(), e.getMessage()); assertEquals(copy.getErrors(), e.getErrors()); } }
public CassandraConfig(DataService dataService, String configId, Map<String, String> properties, boolean odataEnable) throws DataServiceFault { super(dataService, configId, DataSourceTypes.CASSANDRA, properties, odataEnable); Builder builder = Cluster.builder(); this.populateSettings(builder, properties); String keyspace = properties.get(DBConstants.Cassandra.KEYSPACE); this.cluster = builder.build(); try { if (keyspace != null && keyspace.trim().length() > 0) { this.session = this.cluster.connect(keyspace); } else { this.session = this.cluster.connect(); } this.nativeBatchRequestsSupported = this.session.getCluster(). getConfiguration().getProtocolOptions().getProtocolVersion().toInt() > 1; } catch (NoHostAvailableException e) { throw new DataServiceFault(e, DBConstants.FaultCodes.CONNECTION_UNAVAILABLE_ERROR, e.getMessage()); } }
/** * Initialize the connection to the underlying database. * * @param config The {@link com.stratio.connector.cassandra.engine.EngineConfig}. * @return A new Session. */ private Session initializeDB(EngineConfig config) throws ConnectionException { Cluster cluster = Cluster.builder() .addContactPoints(config.getCassandraHosts()) .withPort(config.getCassandraPort()).build(); //TODO When credential exists change cluster builder to add withCredentials method to it LOG.info("Connecting to Cassandra Cluster on " + Arrays.toString(config.getCassandraHosts()) + ":" + config.getCassandraPort()); Session result; try { result = cluster.connect(); } catch (NoHostAvailableException nhae) { throw new ConnectionException(nhae.getMessage(), nhae); } return result; }