Search in sources :

Example 11 with TSocket

use of org.apache.thrift.transport.TSocket in project heron by twitter.

the class ScribeSink method open.

// Open the TTransport connection and client to scribe server
private boolean open() {
    try {
        TSocket socket = new TSocket((String) config.get(KEY_SCRIBE_HOST), TypeUtils.getInteger(config.get(KEY_SCRIBE_PORT)), TypeUtils.getInteger(config.get(KEY_SCRIBE_TIMEOUT_MS)));
        transport = new TFramedTransport(socket);
        transport.open();
    } catch (TException tx) {
        LOG.log(Level.SEVERE, "Failed to open connection to scribe server " + connectionString(), tx);
        return false;
    }
    LOG.info("Opened connection to scribe server " + connectionString());
    TProtocol protocol = new TBinaryProtocol(transport);
    client = new scribe.Client(protocol);
    return true;
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TSocket(org.apache.thrift.transport.TSocket) org.apache.scribe.scribe(org.apache.scribe.scribe)

Example 12 with TSocket

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

use of org.apache.thrift.transport.TSocket in project eiger by wlloyd.

the class CliMain method connect.

/**
     * Establish a thrift connection to cassandra instance
     *
     * @param server - hostname or IP of the server
     * @param port   - Thrift port number
     */
public static void connect(String server, int port) {
    TSocket socket = new TSocket(server, port);
    if (transport != null)
        transport.close();
    if (sessionState.framed) {
        transport = new TFramedTransport(socket);
    } else {
        transport = socket;
    }
    TBinaryProtocol binaryProtocol = new TBinaryProtocol(transport, true, true);
    Cassandra.Client cassandraClient = new Cassandra.Client(binaryProtocol);
    try {
        transport.open();
    } catch (Exception e) {
        e.printStackTrace(sessionState.err);
        String error = (e.getCause() == null) ? e.getMessage() : e.getCause().getMessage();
        throw new RuntimeException("Exception connecting to " + server + "/" + port + ". Reason: " + error + ".");
    }
    thriftClient = cassandraClient;
    cliClient = new CliClient(sessionState, thriftClient);
    if ((sessionState.username != null) && (sessionState.password != null)) {
        // Authenticate
        Map<String, String> credentials = new HashMap<String, String>();
        credentials.put(IAuthenticator.USERNAME_KEY, sessionState.username);
        credentials.put(IAuthenticator.PASSWORD_KEY, sessionState.password);
        AuthenticationRequest authRequest = new AuthenticationRequest(credentials);
        try {
            thriftClient.login(authRequest, LamportClock.sendTimestamp());
            cliClient.setUsername(sessionState.username);
        } catch (AuthenticationException e) {
            thriftClient = null;
            sessionState.err.println("Exception during authentication to the cassandra node, " + "Verify the keyspace exists, and that you are using the correct credentials.");
            return;
        } catch (AuthorizationException e) {
            thriftClient = null;
            sessionState.err.println("You are not authorized to use keyspace: " + sessionState.keyspace);
            return;
        } catch (TException e) {
            thriftClient = null;
            sessionState.err.println("Login failure. Did you specify 'keyspace', 'username' and 'password'?");
            return;
        }
    }
    if (sessionState.keyspace != null) {
        try {
            sessionState.keyspace = CliCompiler.getKeySpace(sessionState.keyspace, thriftClient.describe_keyspaces());
            ;
            thriftClient.set_keyspace(sessionState.keyspace, LamportClock.sendTimestamp());
            cliClient.setKeySpace(sessionState.keyspace);
            updateCompletor(CliUtils.getCfNamesByKeySpace(cliClient.getKSMetaData(sessionState.keyspace)));
        } catch (InvalidRequestException e) {
            sessionState.err.println("Keyspace " + sessionState.keyspace + " not found");
            return;
        } catch (TException e) {
            sessionState.err.println("Did you specify 'keyspace'?");
            return;
        } catch (NotFoundException e) {
            sessionState.err.println("Keyspace " + sessionState.keyspace + " not found");
            return;
        }
    }
    // Lookup the cluster name, this is to make it clear which cluster the user is connected to
    String clusterName;
    try {
        clusterName = thriftClient.describe_cluster_name();
    } catch (Exception e) {
        sessionState.err.println("Exception retrieving information about the cassandra node, check you have connected to the thrift port.");
        e.printStackTrace(sessionState.err);
        return;
    }
    sessionState.out.printf("Connected to: \"%s\" on %s/%d%n", clusterName, server, port);
}
Also used : TException(org.apache.thrift.TException) CharacterCodingException(java.nio.charset.CharacterCodingException) TException(org.apache.thrift.TException) IOException(java.io.IOException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 14 with TSocket

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

use of org.apache.thrift.transport.TSocket in project eiger by wlloyd.

the class TCustomServerSocket method acceptImpl.

@Override
protected TCustomSocket acceptImpl() throws TTransportException {
    if (serverSocket_ == null)
        throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket.");
    TCustomSocket tsocket = null;
    Socket socket = null;
    try {
        socket = serverSocket_.accept();
        tsocket = new TCustomSocket(socket);
        tsocket.setTimeout(0);
    } catch (IOException iox) {
        throw new TTransportException(iox);
    }
    try {
        socket.setKeepAlive(this.keepAlive);
    } catch (SocketException se) {
        logger.warn("Failed to set keep-alive on Thrift socket.", se);
    }
    if (this.sendBufferSize != null) {
        try {
            socket.setSendBufferSize(this.sendBufferSize.intValue());
        } catch (SocketException se) {
            logger.warn("Failed to set send buffer size on Thrift socket.", se);
        }
    }
    if (this.recvBufferSize != null) {
        try {
            socket.setReceiveBufferSize(this.recvBufferSize.intValue());
        } catch (SocketException se) {
            logger.warn("Failed to set receive buffer size on Thrift socket.", se);
        }
    }
    return tsocket;
}
Also used : SocketException(java.net.SocketException) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) TServerSocket(org.apache.thrift.transport.TServerSocket) Socket(java.net.Socket) 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