Search in sources :

Example 1 with AuthenticationRequest

use of org.apache.cassandra.thrift.AuthenticationRequest in project scale7-pelops by s7.

the class ClusterUnitTest method testClusterNodeConnectionAuthenticator.

/**
     * Tests that a connection authenticator on a cluster is configured correctly
     */
@Test
public void testClusterNodeConnectionAuthenticator() {
    String node = "node1";
    Cluster cluster = new Cluster(node, 5555, false, new SimpleConnectionAuthenticator(USERNAME, PASSWORD));
    assertNotNull("Incorrect connection authentication config", cluster.getConnectionConfig().getConnectionAuthenticator());
    assertEquals("Incorrect connection authenticator class", cluster.getConnectionConfig().getConnectionAuthenticator().getClass(), SimpleConnectionAuthenticator.class);
    AuthenticationRequest request = cluster.getConnectionConfig().getConnectionAuthenticator().getAuthenticationRequest();
    assertNotNull("Invalid authentication request", request);
    assertNotNull("Invalid authentication request credentials", request.getCredentials());
    assertEquals("Invalid authentication username", request.getCredentials().get(SimpleConnectionAuthenticator.USERNAME_KEY), USERNAME);
    assertEquals("Invalid authentication username", request.getCredentials().get(SimpleConnectionAuthenticator.PASSWORD_KEY), PASSWORD);
}
Also used : AuthenticationRequest(org.apache.cassandra.thrift.AuthenticationRequest) Test(org.junit.Test)

Example 2 with AuthenticationRequest

use of org.apache.cassandra.thrift.AuthenticationRequest in project eiger by wlloyd.

the class ColumnFamilyRecordReader method initialize.

@Override
public void initialize(InputSplit split, TaskAttemptContext context) throws IOException {
    this.split = (ColumnFamilySplit) split;
    Configuration conf = context.getConfiguration();
    predicate = ConfigHelper.getInputSlicePredicate(conf);
    isEmptyPredicate = isEmptyPredicate(predicate);
    totalRowCount = ConfigHelper.getInputSplitSize(conf);
    batchRowCount = ConfigHelper.getRangeBatchSize(conf);
    cfName = ConfigHelper.getInputColumnFamily(conf);
    consistencyLevel = ConsistencyLevel.valueOf(ConfigHelper.getReadConsistencyLevel(conf));
    keyspace = ConfigHelper.getInputKeyspace(conf);
    try {
        // only need to connect once
        if (socket != null && socket.isOpen())
            return;
        // create connection using thrift
        String location = getLocation();
        socket = new TSocket(location, ConfigHelper.getInputRpcPort(conf));
        TBinaryProtocol binaryProtocol = new TBinaryProtocol(new TFramedTransport(socket));
        client = new Cassandra.Client(binaryProtocol);
        socket.open();
        // log in
        client.set_keyspace(keyspace, LamportClock.COPS_UNSUPPORTED);
        if (ConfigHelper.getInputKeyspaceUserName(conf) != null) {
            Map<String, String> creds = new HashMap<String, String>();
            creds.put(IAuthenticator.USERNAME_KEY, ConfigHelper.getInputKeyspaceUserName(conf));
            creds.put(IAuthenticator.PASSWORD_KEY, ConfigHelper.getInputKeyspacePassword(conf));
            AuthenticationRequest authRequest = new AuthenticationRequest(creds);
            client.login(authRequest, LamportClock.COPS_UNSUPPORTED);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    iter = new RowIterator();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) Cassandra(org.apache.cassandra.thrift.Cassandra) SocketException(java.net.SocketException) ConfigurationException(org.apache.cassandra.config.ConfigurationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) AuthenticationRequest(org.apache.cassandra.thrift.AuthenticationRequest) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

AuthenticationRequest (org.apache.cassandra.thrift.AuthenticationRequest)2 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 ConfigurationException (org.apache.cassandra.config.ConfigurationException)1 Cassandra (org.apache.cassandra.thrift.Cassandra)1 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)1 Configuration (org.apache.hadoop.conf.Configuration)1 TException (org.apache.thrift.TException)1 TFramedTransport (org.apache.thrift.transport.TFramedTransport)1 TSocket (org.apache.thrift.transport.TSocket)1 Test (org.junit.Test)1