* @param kijiURI The KijiURI specifying the Kiji instance for the CassandraAdmin.
* Note: Must be an instance of CassandraKijiURI.
* @return A CassandraAdmin for the given Kiji instance.
*/
public static DefaultCassandraAdmin makeFromKijiURI(KijiURI kijiURI) {
CassandraKijiURI cassandraKijiURI;
if (kijiURI instanceof CassandraKijiURI) {
cassandraKijiURI = (CassandraKijiURI) kijiURI;
} else {
throw new KijiIOException("Need a Cassandra URI for a CassandraAdmin.");
}
final List<String> hosts = cassandraKijiURI.getContactPoints();
final String[] hostStrings = hosts.toArray(new String[hosts.size()]);
int port = cassandraKijiURI.getContactPort();
final Cluster.Builder clusterBuilder = Cluster
.builder()
.addContactPoints(hostStrings)
.withPort(port);
if (null != cassandraKijiURI.getUsername()) {
clusterBuilder.withAuthProvider(
new PlainTextAuthProvider(cassandraKijiURI.getUsername(), cassandraKijiURI.getPassword())
);
}
final Cluster cluster = clusterBuilder.build();
final Session cassandraSession = cluster.connect();