Search in sources :

Example 11 with TFramedTransport

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;
}
Also used : HashMap(java.util.HashMap) TFramedTransport(org.apache.thrift.transport.TFramedTransport)

Example 12 with TFramedTransport

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();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) Cassandra(org.apache.cassandra.thrift.Cassandra) SocketException(java.net.SocketException) ConfigurationException(org.apache.cassandra.config.ConfigurationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) AuthenticationRequest(org.apache.cassandra.thrift.AuthenticationRequest) TSocket(org.apache.thrift.transport.TSocket)

Example 13 with TFramedTransport

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);
}
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 14 with TFramedTransport

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");
}
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 15 with TFramedTransport

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
                }
            }
        }
    }
}
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)

Aggregations

TFramedTransport (org.apache.thrift.transport.TFramedTransport)45 TSocket (org.apache.thrift.transport.TSocket)41 TTransport (org.apache.thrift.transport.TTransport)32 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)25 TProtocol (org.apache.thrift.protocol.TProtocol)24 TException (org.apache.thrift.TException)14 IOException (java.io.IOException)11 TTransportException (org.apache.thrift.transport.TTransportException)11 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 Cassandra (org.apache.cassandra.thrift.Cassandra)4 Hello (org.tech.model.Hello)4 SocketException (java.net.SocketException)3 HashMap (java.util.HashMap)3 GameRPC (com.code.server.rpc.idl.GameRPC)2 UnknownHostException (java.net.UnknownHostException)2 SSLSocket (javax.net.ssl.SSLSocket)2 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)2 ConfigurationException (org.apache.cassandra.config.ConfigurationException)2 AuthenticationRequest (org.apache.cassandra.thrift.AuthenticationRequest)2 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)2