Search in sources :

Example 16 with TSocket

use of org.apache.thrift.transport.TSocket 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 17 with TSocket

use of org.apache.thrift.transport.TSocket 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 18 with TSocket

use of org.apache.thrift.transport.TSocket 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 19 with TSocket

use of org.apache.thrift.transport.TSocket in project brisk by riptano.

the class CassandraStorage method createConnection.

private static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws IOException {
    TSocket socket = new TSocket(host, port);
    TTransport trans = framed ? new TFramedTransport(socket) : socket;
    try {
        trans.open();
    } catch (TTransportException e) {
        throw new IOException("unable to connect to server", e);
    }
    return new Cassandra.Client(new TBinaryProtocol(trans));
}
Also used : TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Example 20 with TSocket

use of org.apache.thrift.transport.TSocket in project cogcomp-nlp by CogComp.

the class CuratorClient method addRecordViewFromCurator.

/**
     * Does the network call to the Curator and fetches a record that has a particular view.
     *
     * @param text The raw text (this will be used if {@link #respectTokenization} is false.
     * @param sentences The list of tokenized sentences (will be {@code null} if
     *        {@link #respectTokenization} is true.
     * @param viewName The view to get (according to the Curator lingo.)
     * @return A {@link edu.illinois.cs.cogcomp.thrift.curator.Record} with the requested view
     */
private Record addRecordViewFromCurator(String text, List<String> sentences, String viewName) throws ServiceUnavailableException, AnnotationFailedException, TException, SocketException {
    viewName = convertCuratorViewName(viewName);
    TTransport transport = new TSocket(this.curatorHost, this.curatorPort);
    logger.debug("Calling curator on host '" + curatorHost + "', port '" + curatorPort + "' for view '" + viewName + "'...");
    try {
        ((TSocket) transport).getSocket().setReuseAddress(true);
    } catch (SocketException e) {
        logger.error("Unable to setReuseAddress!", e);
        throw e;
    }
    transport = new TFramedTransport(transport);
    TProtocol protocol = new TBinaryProtocol(transport);
    transport.open();
    Curator.Client client = new Curator.Client(protocol);
    Record newRecord;
    if (respectTokenization) {
        newRecord = client.wsprovide(viewName, sentences, forceUpdate);
    } else {
        newRecord = client.provide(viewName, text, forceUpdate);
    }
    transport.close();
    return newRecord;
}
Also used : SocketException(java.net.SocketException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) Curator(edu.illinois.cs.cogcomp.thrift.curator.Curator) Record(edu.illinois.cs.cogcomp.thrift.curator.Record) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

TSocket (org.apache.thrift.transport.TSocket)66 TTransport (org.apache.thrift.transport.TTransport)43 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)41 TProtocol (org.apache.thrift.protocol.TProtocol)36 TFramedTransport (org.apache.thrift.transport.TFramedTransport)33 IOException (java.io.IOException)16 TException (org.apache.thrift.TException)16 TTransportException (org.apache.thrift.transport.TTransportException)15 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)9 Cassandra (org.apache.cassandra.thrift.Cassandra)5 ImageDatasetService (org.vcell.imagedataset.ImageDatasetService)5 Socket (java.net.Socket)4 SocketException (java.net.SocketException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Hello (org.tech.model.Hello)4 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)3 ByteBuffer (java.nio.ByteBuffer)3 SSLSocket (javax.net.ssl.SSLSocket)3 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)3