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);
}
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();
}
Aggregations