Search in sources :

Example 31 with TTransport

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");
}
Also used : ColumnDefinition(org.apache.cassandra.config.ColumnDefinition) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) CFMetaData(org.apache.cassandra.config.CFMetaData) KSMetaData(org.apache.cassandra.config.KSMetaData) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket) BeforeClass(org.junit.BeforeClass)

Example 32 with TTransport

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
                }
            }
        }
    }
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 33 with TTransport

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;
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) UnknownHostException(java.net.UnknownHostException) ConfigurationException(org.apache.cassandra.config.ConfigurationException) TSocket(org.apache.thrift.transport.TSocket)

Example 34 with TTransport

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;
    }
}
Also used : TException(org.apache.thrift.TException) BufferedInputStream(java.io.BufferedInputStream) TProtocol(org.apache.thrift.protocol.TProtocol) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TTransport(org.apache.thrift.transport.TTransport)

Example 35 with TTransport

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);
    }
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport)

Aggregations

TTransport (org.apache.thrift.transport.TTransport)99 TSocket (org.apache.thrift.transport.TSocket)43 TProtocol (org.apache.thrift.protocol.TProtocol)42 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)36 TFramedTransport (org.apache.thrift.transport.TFramedTransport)28 TTransportException (org.apache.thrift.transport.TTransportException)20 Test (org.junit.Test)20 TException (org.apache.thrift.TException)18 IOException (java.io.IOException)12 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 ArrayList (java.util.ArrayList)9 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)8 HashMap (java.util.HashMap)6 Socket (java.net.Socket)5 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)5 THttpClient (org.apache.thrift.transport.THttpClient)4 TSaslClientTransport (org.apache.thrift.transport.TSaslClientTransport)4 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)3