use of org.apache.thrift.transport.TTransport 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.TTransport 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
}
}
}
}
}
use of org.apache.thrift.transport.TTransport in project eiger by wlloyd.
the class Session method getClient.
/**
* Thrift client connection
* @param setKeyspace - should we set keyspace for client or not
* @return cassandra client connection
*/
public Cassandra.Client getClient(boolean setKeyspace) {
// random node selection for fake load balancing
String currentNode = nodes[Stress.randomizer.nextInt(nodes.length)];
TSocket socket = new TSocket(currentNode, port);
TTransport transport = (isUnframed()) ? socket : new TFramedTransport(socket);
Cassandra.Client client = new Cassandra.Client(new TBinaryProtocol(transport));
try {
transport.open();
if (setKeyspace) {
client.set_keyspace("Keyspace1", LamportClock.sendTimestamp());
}
} catch (InvalidRequestException e) {
throw new RuntimeException(e.getWhy());
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return client;
}
use of org.apache.thrift.transport.TTransport in project jena by apache.
the class TRDF method protocol.
/**
* Create Thrift protocol for the InputStream.
* @param in InputStream
*/
public static TProtocol protocol(InputStream in) {
try {
if (!(in instanceof BufferedInputStream))
in = new BufferedInputStream(in, InputBufferSize);
TTransport transport = new TIOStreamTransport(in);
transport.open();
TProtocol protocol = protocol(transport);
return protocol;
} catch (TException ex) {
TRDF.exception(ex);
return null;
}
}
use of org.apache.thrift.transport.TTransport in project presto by prestodb.
the class Transport method create.
public static TTransport create(String host, int port, HostAndPort socksProxy, int timeoutMillis, HiveMetastoreAuthentication authentication) throws TTransportException {
try {
TTransport rawTransport = createRaw(host, port, socksProxy, timeoutMillis);
TTransport authenticatedTransport = authentication.authenticate(rawTransport, host);
if (!authenticatedTransport.isOpen()) {
authenticatedTransport.open();
}
return new TTransportWrapper(authenticatedTransport, host);
} catch (TTransportException e) {
throw rewriteException(e, host);
}
}
Aggregations