Search in sources :

Example 1 with AuthenticationException

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);
    }
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) NoHostAvailableException(com.datastax.driver.core.exceptions.NoHostAvailableException) AuthenticationException(com.datastax.driver.core.exceptions.AuthenticationException) ComponentLog(org.apache.nifi.logging.ComponentLog) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 2 with AuthenticationException

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());
}
Also used : AuthenticationException(com.datastax.driver.core.exceptions.AuthenticationException) InetSocketAddress(java.net.InetSocketAddress) Level(org.apache.log4j.Level) Test(org.testng.annotations.Test)

Aggregations

AuthenticationException (com.datastax.driver.core.exceptions.AuthenticationException)2 NoHostAvailableException (com.datastax.driver.core.exceptions.NoHostAvailableException)1 InetSocketAddress (java.net.InetSocketAddress)1 Level (org.apache.log4j.Level)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 ComponentLog (org.apache.nifi.logging.ComponentLog)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1 Test (org.testng.annotations.Test)1