Java Code Examples for org.apache.cassandra.thrift.Cassandra#Client

The following examples show how to use org.apache.cassandra.thrift.Cassandra#Client . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRingCache.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void setup(String server, int port) throws Exception
{
    /* Establish a thrift connection to the cassandra instance */
    TSocket socket = new TSocket(server, port);
    System.out.println(" connected to " + server + ":" + port + ".");
    TBinaryProtocol binaryProtocol = new TBinaryProtocol(new TFramedTransport(socket));
    Cassandra.Client cassandraClient = new Cassandra.Client(binaryProtocol);
    socket.open();
    thriftClient = cassandraClient;
    String seed = DatabaseDescriptor.getSeeds().iterator().next().getHostAddress();
    conf = new Configuration();
    ConfigHelper.setOutputPartitioner(conf, DatabaseDescriptor.getPartitioner().getClass().getName());
    ConfigHelper.setOutputInitialAddress(conf, seed);
    ConfigHelper.setOutputRpcPort(conf, Integer.toString(DatabaseDescriptor.getRpcPort()));

}
 
Example 2
Source File: CassandraThriftFacade.java    From emodb with Apache License 2.0 5 votes vote down vote up
public CassandraThriftFacade(TFramedTransport transport) {
    _transport = transport;
    _client = new Cassandra.Client(new TBinaryProtocol(_transport));
    try {
        _transport.open();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
 
Example 3
Source File: PigTestBase.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
protected static Cassandra.Client getClient() throws TTransportException
{
    TTransport tr = new TFramedTransport(new TSocket("localhost", 9170));
    TProtocol proto = new TBinaryProtocol(tr);
    Cassandra.Client client = new Cassandra.Client(proto);
    tr.open();
    return client;
}
 
Example 4
Source File: AbstractColumnFamilyInputFormat.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static Cassandra.Client createAuthenticatedClient(String location, int port, Configuration conf) throws Exception
{
    logger.debug("Creating authenticated client for CF input format");
    TTransport transport;
    try
    {
        transport = ConfigHelper.getClientTransportFactory(conf).openTransport(location, port);
    }
    catch (Exception e)
    {
        throw new TTransportException("Failed to open a transport to " + location + ":" + port + ".", e);
    }
    TProtocol binaryProtocol = new TBinaryProtocol(transport, true, true);
    Cassandra.Client client = new Cassandra.Client(binaryProtocol);

    // log in
    client.set_keyspace(ConfigHelper.getInputKeyspace(conf));
    if ((ConfigHelper.getInputKeyspaceUserName(conf) != null) && (ConfigHelper.getInputKeyspacePassword(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);
    }
    logger.debug("Authenticated client for CF input format created successfully");
    return client;
}
 
Example 5
Source File: AbstractCassandraInputAdapter.java    From OpenRate with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to connect to Cassandra.
 *
 * @throws OpenRate.exception.InitializationException
 */
public void initCassandraConnection() throws InitializationException {
  tr = new TFramedTransport(new TSocket(cassandraIPAddr, cassandraPort));
  TProtocol proto = new TBinaryProtocol(tr);
  client = new Cassandra.Client(proto);

  try {
    tr.open();
  } catch (TTransportException ex) {
    message = "Transport exception opening Cassandra transport";
    throw new InitializationException(message, ex, getSymbolicName());
  }
}
 
Example 6
Source File: AbstractCassandraInputAdapter.java    From OpenRate with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to connect to Cassandra.
 *
 * @throws OpenRate.exception.ProcessingException
 */
public void openCassandraConnection() throws ProcessingException {
  tr = new TFramedTransport(new TSocket(cassandraIPAddr, 9160));
  TProtocol proto = new TBinaryProtocol(tr);
  client = new Cassandra.Client(proto);

  try {
    tr.open();
  } catch (TTransportException ex) {
    message = "Transport exception opening Cassandra transport";
    throw new ProcessingException(message, ex, getSymbolicName());
  }
}
 
Example 7
Source File: AbstractCassandraOutputAdapter.java    From OpenRate with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to connect to Cassandra.
 *
 * @throws OpenRate.exception.ProcessingException
 */
public void openCassandraConnection() throws ProcessingException {
  tr = new TFramedTransport(new TSocket(cassandraIPAddr, 9160));
  TProtocol proto = new TBinaryProtocol(tr);
  client = new Cassandra.Client(proto);

  try {
    tr.open();
  } catch (TTransportException ex) {
    message = "Transport exception opening Cassandra transport";
    throw new ProcessingException(message, ex, getSymbolicName());
  }
}
 
Example 8
Source File: AbstractCassandraOutputAdapter.java    From OpenRate with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to connect to Cassandra.
 *
 * @throws OpenRate.exception.InitializationException
 */
public void initCassandraConnection() throws InitializationException {
  tr = new TFramedTransport(new TSocket(cassandraIPAddr, cassandraPort));
  TProtocol proto = new TBinaryProtocol(tr);
  client = new Cassandra.Client(proto);

  try {
    tr.open();
  } catch (TTransportException ex) {
    message = "Transport exception opening Cassandra transport";
    throw new InitializationException(message, ex, getSymbolicName());
  }
}
 
Example 9
Source File: CassandraClientHolder.java    From Hive-Cassandra with Apache License 2.0 5 votes vote down vote up
private void initClient() throws CassandraException
{
    try
    {
        transport.open();
    } catch (TTransportException e)
    {
        throw new CassandraException("unable to connect to server", e);
    }

    client = new Cassandra.Client(new TBinaryProtocol(transport));

    // connect to last known keyspace
    setKeyspace(keyspace);
}
 
Example 10
Source File: ThriftColumnFamilyTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private String getColumnValue(String ks, String cf, String colName, String key, String validator)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, IOException
{
    Cassandra.Client client = getClient();
    client.set_keyspace(ks);

    ByteBuffer key_user_id = ByteBufferUtil.bytes(key);
    ColumnPath cp = new ColumnPath(cf);
    cp.column = ByteBufferUtil.bytes(colName);

    // read
    ColumnOrSuperColumn got = client.get(key_user_id, cp, ConsistencyLevel.ONE);
    return parseType(validator).getString(got.getColumn().value);
}
 
Example 11
Source File: Schema.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
private void dropOldKeyspace() throws InvalidRequestException, SchemaDisagreementException, TException {
  TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
  TProtocol proto = new TBinaryProtocol(tr);
  Cassandra.Client client = new Cassandra.Client(proto);
  tr.open();

  client.system_drop_keyspace(JANUSGRAPH);
  LOGGER.info("DROPPED keyspace janusgraph");
  tr.close();
}
 
Example 12
Source File: AbstractCassandraOutputAdapter.java    From OpenRate with Apache License 2.0 4 votes vote down vote up
/**
 * @return the client
 */
public Cassandra.Client getClient() {
  return client;
}
 
Example 13
Source File: AbstractCassandraOutputAdapter.java    From OpenRate with Apache License 2.0 4 votes vote down vote up
/**
 * @param client the client to set
 */
public void setClient(Cassandra.Client client) {
  this.client = client;
}
 
Example 14
Source File: AbstractCassandraInputAdapter.java    From OpenRate with Apache License 2.0 4 votes vote down vote up
/**
 * @return the client
 */
public Cassandra.Client getClient() {
  return client;
}
 
Example 15
Source File: AbstractCassandraInputAdapter.java    From OpenRate with Apache License 2.0 4 votes vote down vote up
/**
 * @param client the client to set
 */
public void setClient(Cassandra.Client client) {
  this.client = client;
}
 
Example 16
Source File: KeyspaceUtil.java    From emodb with Apache License 2.0 4 votes vote down vote up
private Keyspace pinToVerifiedHost(Host host) throws ConnectionException {
    //noinspection unchecked
    PinnedConnectionPool<Cassandra.Client> pinnedPool = new PinnedConnectionPool(_keyspace.getConnectionPool(), host);
    return new ThriftKeyspaceImpl(
            _keyspace.getKeyspaceName(), pinnedPool, _keyspace.getConfig(), EmptyKeyspaceTracerFactory.getInstance());
}
 
Example 17
Source File: StressSettings.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public Cassandra.Client getRawThriftClient(boolean setKeyspace)
{
    return getRawThriftClient(node.randomNode(), setKeyspace);
}
 
Example 18
Source File: CassandraClientHolder.java    From Hive-Cassandra with Apache License 2.0 4 votes vote down vote up
public Cassandra.Client getClient()
{
    return client;
}
 
Example 19
Source File: CassandraConnection.java    From learning-hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Get the encapsulated Cassandra.Client object
 * 
 * @return the encapsulated Cassandra.Client object
 */
public Cassandra.Client getClient() {
  return m_client;
}
 
Example 20
Source File: DBConn.java    From Doradus with Apache License 2.0 2 votes vote down vote up
/**
 * Get this DBConn's Cassandra.Client session. This should only be used temporarily
 * since it is shared with this DBConn object.
 * 
 * @return  This DBConn's Cassandra.Client session, which will be a keyspace or a
 *          no-keyspace session depending on how this object was constructed.
 */
public Cassandra.Client getClientSession() {
    return m_client;
}