use of com.datastax.driver.core.exceptions.AuthenticationException in project nifi by apache.
the class QueryCassandra method onScheduled.
@OnScheduled
public void onScheduled(final ProcessContext context) {
ComponentLog log = getLogger();
try {
connectToCassandra(context);
final int fetchSize = context.getProperty(FETCH_SIZE).evaluateAttributeExpressions().asInteger();
if (fetchSize > 0) {
synchronized (cluster.get()) {
cluster.get().getConfiguration().getQueryOptions().setFetchSize(fetchSize);
}
}
} catch (final NoHostAvailableException nhae) {
log.error("No host in the Cassandra cluster can be contacted successfully to execute this query", nhae);
// Log up to 10 error messages. Otherwise if a 1000-node cluster was specified but there was no connectivity,
// a thousand error messages would be logged. However we would like information from Cassandra itself, so
// cap the error limit at 10, format the messages, and don't include the stack trace (it is displayed by the
// logger message above).
log.error(nhae.getCustomMessage(10, true, false));
throw new ProcessException(nhae);
} catch (final AuthenticationException ae) {
log.error("Invalid username/password combination", ae);
throw new ProcessException(ae);
}
}
use of com.datastax.driver.core.exceptions.AuthenticationException in project java-driver by datastax.
the class AuthenticationTest method should_not_create_pool_with_wrong_credentials.
/**
* Ensures that when a host replies with AuthenticationException
* during connection pool initialization the pool creation is aborted.
*
* @jira_ticket JAVA-1431
*/
@Test(groups = "short")
public void should_not_create_pool_with_wrong_credentials() throws InterruptedException {
PlainTextAuthProvider authProvider = new PlainTextAuthProvider("cassandra", "cassandra");
Cluster cluster = register(Cluster.builder().addContactPoints(getContactPoints()).withPort(ccm().getBinaryPort()).withAuthProvider(authProvider).build());
cluster.init();
authProvider.setPassword("wrong");
Level previous = TestUtils.setLogLevel(Session.class, Level.WARN);
MemoryAppender logs = new MemoryAppender().enableFor(Session.class);
Session session;
try {
session = cluster.connect();
} finally {
TestUtils.setLogLevel(Session.class, previous);
logs.disableFor(Session.class);
}
assertThat(session.getState().getConnectedHosts()).isEmpty();
InetSocketAddress host = ccm().addressOfNode(1);
assertThat(logs.get()).contains("Error creating pool to " + host, "Authentication error on host " + host, AuthenticationException.class.getSimpleName());
}
Aggregations