use of org.apache.thrift.transport.TFramedTransport in project eiger by wlloyd.
the class ColumnFamilyOutputFormat method createAuthenticatedClient.
/**
* Return a client based on the given socket that points to the configured
* keyspace, and is logged in with the configured credentials.
*
* @param socket a socket pointing to a particular node, seed or otherwise
* @param conf a job configuration
* @return a cassandra client
* @throws InvalidRequestException
* @throws TException
* @throws AuthenticationException
* @throws AuthorizationException
*/
public static Cassandra.Client createAuthenticatedClient(TSocket socket, Configuration conf) throws InvalidRequestException, TException, AuthenticationException, AuthorizationException {
TBinaryProtocol binaryProtocol = new TBinaryProtocol(new TFramedTransport(socket));
Cassandra.Client client = new Cassandra.Client(binaryProtocol);
socket.open();
client.set_keyspace(ConfigHelper.getOutputKeyspace(conf), LamportClock.COPS_UNSUPPORTED);
if (ConfigHelper.getOutputKeyspaceUserName(conf) != null) {
Map<String, String> creds = new HashMap<String, String>();
creds.put(IAuthenticator.USERNAME_KEY, ConfigHelper.getOutputKeyspaceUserName(conf));
creds.put(IAuthenticator.PASSWORD_KEY, ConfigHelper.getOutputKeyspacePassword(conf));
AuthenticationRequest authRequest = new AuthenticationRequest(creds);
client.login(authRequest, LamportClock.COPS_UNSUPPORTED);
}
return client;
}
use of org.apache.thrift.transport.TFramedTransport 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();
}
use of org.apache.thrift.transport.TFramedTransport in project eiger by wlloyd.
the class WordCountSetup method createConnection.
private static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws TTransportException {
TSocket socket = new TSocket(host, port);
TTransport trans = framed ? new TFramedTransport(socket) : socket;
trans.open();
TProtocol protocol = new TBinaryProtocol(trans);
return new Cassandra.Client(protocol);
}
use of org.apache.thrift.transport.TFramedTransport in project eiger by wlloyd.
the class MultiDcCops2Test method setup.
@BeforeClass
public static void setup() throws IOException, InterruptedException, ConfigurationException, InvalidRequestException, SchemaDisagreementException, TException {
Integer numDatacenters = Integer.getInteger("cassandra.multiDcTest.numDatacenters");
assert numDatacenters != null : "You must set the numDatacenters to run the multiDc Tests";
Integer nodesPerDatacenter = Integer.getInteger("cassandra.multiDcTest.nodesPerDatacenter");
assert nodesPerDatacenter != null : "You must set nodesPerDatacenter to run the multiDc Tests";
// Create a keyspace with a replication factor of 1 for each datacenter
TTransport tr = new TFramedTransport(new TSocket("127.0.0.1", DEFAULT_THRIFT_PORT));
TProtocol proto = new TBinaryProtocol(tr);
Cassandra.Client client = new Cassandra.Client(proto);
tr.open();
// set the replication factor to 1 for each datacenter
Map<String, String> ntsOptions = new HashMap<String, String>();
assert numDatacenters > 0;
for (int i = 0; i < numDatacenters; ++i) {
ntsOptions.put("DC" + i, "1");
}
// We'll use the same set of columns as is used in the EmbeddedCassandraService
// and we'll set the index type to KEYS so thrift doesn't complain
Map<String, CFMetaData> cfDefs = schemaDefinition().iterator().next().cfMetaData();
for (Entry<String, CFMetaData> cfEntry : cfDefs.entrySet()) {
assert cfEntry.getKey() == cfEntry.getValue().cfName;
for (ColumnDefinition colDef : cfEntry.getValue().getColumn_metadata().values()) {
colDef.setIndexType(IndexType.KEYS, null);
}
cfEntry.getValue().readRepairChance(0);
}
KSMetaData keyspace1 = KSMetaData.testMetadataNotDurable("Keyspace1", NetworkTopologyStrategy.class, ntsOptions, cfDefs.values());
client.system_add_keyspace(keyspace1.toThrift());
// setup the normal test
HashMap<String, Integer> localServerIPAndPorts = new HashMap<String, Integer>();
for (int i = 1; i <= nodesPerDatacenter; ++i) {
localServerIPAndPorts.put("127.0.0." + i, DEFAULT_THRIFT_PORT);
}
List<Map<String, Integer>> dcToServerIPAndPorts = new ArrayList();
for (int dc = 0; dc < numDatacenters; ++dc) {
HashMap<String, Integer> serverIPAndPorts = new HashMap<String, Integer>();
for (int i = 0; i < nodesPerDatacenter; ++i) {
int ipIndex = 1 + dc * nodesPerDatacenter + i;
serverIPAndPorts.put("127.0.0." + ipIndex, DEFAULT_THRIFT_PORT);
}
dcToServerIPAndPorts.add(serverIPAndPorts);
}
Cops2Test.setLocalServerIPAndPorts(localServerIPAndPorts);
Cops2Test.setDcToServerIPAndPorts(dcToServerIPAndPorts);
Cops2Test.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);
// wait for the keyspace to show up at all nodes
HashMap<String, Integer> allServerIPAndPorts = new HashMap<String, Integer>();
for (int i = 1; i <= numDatacenters * nodesPerDatacenter; ++i) {
allServerIPAndPorts.put("127.0.0." + i, DEFAULT_THRIFT_PORT);
}
waitForKeyspacePropagation(allServerIPAndPorts, "Keyspace1");
}
use of org.apache.thrift.transport.TFramedTransport in project eiger by wlloyd.
the class MultiDcCops2Test method waitForKeyspacePropagation.
private static void waitForKeyspacePropagation(Map<String, Integer> allServerIPAndPorts, String keyspace) throws TException {
for (Entry<String, Integer> ipAndPort : allServerIPAndPorts.entrySet()) {
String ip = ipAndPort.getKey();
Integer port = ipAndPort.getValue();
TTransport tFramedTransport = new TFramedTransport(new TSocket(ip, port));
TProtocol binaryProtoOnFramed = new TBinaryProtocol(tFramedTransport);
Cassandra.Client client = new Cassandra.Client(binaryProtoOnFramed);
tFramedTransport.open();
// FIXME: This is a hideous way to ensure the earlier system_add_keyspace has propagated everywhere
while (true) {
try {
client.set_keyspace(keyspace, LamportClock.sendTimestamp());
break;
} catch (InvalidRequestException e) {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// ignore
}
}
}
}
}
Aggregations