Search in sources :

Example 1 with ConnectionPool

use of com.netflix.astyanax.connectionpool.ConnectionPool in project coprhd-controller by CoprHD.

the class SchemaUtil method dropColumnFamily.

/**
 * Drop CF
 *
 * @param cfName column family name
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
public String dropColumnFamily(final String cfName, AstyanaxContext<Cluster> context) {
    final KeyspaceTracerFactory ks = EmptyKeyspaceTracerFactory.getInstance();
    ConnectionPool<Cassandra.Client> pool = (ConnectionPool<Cassandra.Client>) context.getConnectionPool();
    _log.info("Dropping CF: {}", cfName);
    try {
        return pool.executeWithFailover(new AbstractOperationImpl<String>(ks.newTracer(CassandraOperationType.UPDATE_COLUMN_FAMILY)) {

            @Override
            public String internalExecute(Cassandra.Client client, ConnectionContext context) throws Exception {
                client.set_keyspace(_keyspaceName);
                return client.system_drop_column_family(cfName);
            }
        }, context.getAstyanaxConfiguration().getRetryPolicy().duplicate()).getResult();
    } catch (final OperationException e) {
        throw DatabaseException.retryables.operationFailed(e);
    } catch (final ConnectionException e) {
        throw DatabaseException.retryables.connectionFailed(e);
    }
}
Also used : ConnectionPool(com.netflix.astyanax.connectionpool.ConnectionPool) AbstractOperationImpl(com.netflix.astyanax.thrift.AbstractOperationImpl) Cassandra(org.apache.cassandra.thrift.Cassandra) KeyspaceTracerFactory(com.netflix.astyanax.KeyspaceTracerFactory) EmptyKeyspaceTracerFactory(com.netflix.astyanax.shallows.EmptyKeyspaceTracerFactory) ConnectionContext(com.netflix.astyanax.connectionpool.ConnectionContext) DbClient(com.emc.storageos.db.client.DbClient) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) OperationException(com.netflix.astyanax.connectionpool.exceptions.OperationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 2 with ConnectionPool

use of com.netflix.astyanax.connectionpool.ConnectionPool in project coprhd-controller by CoprHD.

the class DbClientContext method alterKeyspaceWithThrift.

/**
 * Update the keyspace definition using low-level thrift API
 * This is to bypass the precheck logic in Astyanax that throws SchemaDisagreementException when there are
 * unreachable nodes in the cluster. Refer to https://github.com/Netflix/astyanax/issues/443 for details.
 *
 * @param kd existing keyspace definition, could be null
 * @param update new keyspace definition
 * @return new schema version after the update
 */
private String alterKeyspaceWithThrift(KeyspaceDefinition kd, KeyspaceDefinition update) throws ConnectionException {
    final KeyspaceTracerFactory ks = EmptyKeyspaceTracerFactory.getInstance();
    ConnectionPool<Cassandra.Client> pool = (ConnectionPool<Cassandra.Client>) clusterContext.getConnectionPool();
    final KsDef def = ((ThriftKeyspaceDefinitionImpl) update).getThriftKeyspaceDefinition();
    if (kd != null) {
        return pool.executeWithFailover(new AbstractOperationImpl<String>(ks.newTracer(CassandraOperationType.UPDATE_KEYSPACE)) {

            @Override
            public String internalExecute(Cassandra.Client client, ConnectionContext context) throws Exception {
                return client.system_update_keyspace(def);
            }
        }, clusterContext.getAstyanaxConfiguration().getRetryPolicy().duplicate()).getResult();
    } else {
        return pool.executeWithFailover(new AbstractOperationImpl<String>(ks.newTracer(CassandraOperationType.ADD_KEYSPACE)) {

            @Override
            public String internalExecute(Cassandra.Client client, ConnectionContext context) throws Exception {
                return client.system_add_keyspace(def);
            }
        }, clusterContext.getAstyanaxConfiguration().getRetryPolicy().duplicate()).getResult();
    }
}
Also used : ConnectionPool(com.netflix.astyanax.connectionpool.ConnectionPool) AbstractOperationImpl(com.netflix.astyanax.thrift.AbstractOperationImpl) Cassandra(org.apache.cassandra.thrift.Cassandra) EmptyKeyspaceTracerFactory(com.netflix.astyanax.shallows.EmptyKeyspaceTracerFactory) KeyspaceTracerFactory(com.netflix.astyanax.KeyspaceTracerFactory) KsDef(org.apache.cassandra.thrift.KsDef) ConnectionContext(com.netflix.astyanax.connectionpool.ConnectionContext) SSLConnectionContext(com.netflix.astyanax.connectionpool.SSLConnectionContext) ThriftKeyspaceDefinitionImpl(com.netflix.astyanax.thrift.ddl.ThriftKeyspaceDefinitionImpl)

Example 3 with ConnectionPool

use of com.netflix.astyanax.connectionpool.ConnectionPool in project coprhd-controller by CoprHD.

the class SchemaUtil method updateColumnFamily.

/**
 * Updates CF
 *
 * @param def
 * @return
 */
@SuppressWarnings("unchecked")
public String updateColumnFamily(final ThriftColumnFamilyDefinitionImpl def) {
    AstyanaxContext<Cluster> context = clientContext.getClusterContext();
    final KeyspaceTracerFactory ks = EmptyKeyspaceTracerFactory.getInstance();
    ConnectionPool<Cassandra.Client> pool = (ConnectionPool<Cassandra.Client>) context.getConnectionPool();
    _log.info("Updating CF: {}", def.getName());
    try {
        return pool.executeWithFailover(new AbstractOperationImpl<String>(ks.newTracer(CassandraOperationType.UPDATE_COLUMN_FAMILY)) {

            @Override
            public String internalExecute(Cassandra.Client client, ConnectionContext context) throws Exception {
                client.set_keyspace(_keyspaceName);
                return client.system_update_column_family(def.getThriftColumnFamilyDefinition());
            }
        }, context.getAstyanaxConfiguration().getRetryPolicy().duplicate()).getResult();
    } catch (final OperationException e) {
        throw DatabaseException.retryables.operationFailed(e);
    } catch (final ConnectionException e) {
        throw DatabaseException.retryables.connectionFailed(e);
    }
}
Also used : ConnectionPool(com.netflix.astyanax.connectionpool.ConnectionPool) AbstractOperationImpl(com.netflix.astyanax.thrift.AbstractOperationImpl) Cassandra(org.apache.cassandra.thrift.Cassandra) Cluster(com.netflix.astyanax.Cluster) KeyspaceTracerFactory(com.netflix.astyanax.KeyspaceTracerFactory) EmptyKeyspaceTracerFactory(com.netflix.astyanax.shallows.EmptyKeyspaceTracerFactory) ConnectionContext(com.netflix.astyanax.connectionpool.ConnectionContext) DbClient(com.emc.storageos.db.client.DbClient) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) OperationException(com.netflix.astyanax.connectionpool.exceptions.OperationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 4 with ConnectionPool

use of com.netflix.astyanax.connectionpool.ConnectionPool in project coprhd-controller by CoprHD.

the class SchemaUtil method addColumnFamily.

/**
 * Adds CF to keyspace
 *
 * @param def
 * @return
 */
@SuppressWarnings("unchecked")
public String addColumnFamily(final ThriftColumnFamilyDefinitionImpl def) {
    AstyanaxContext<Cluster> context = clientContext.getClusterContext();
    final KeyspaceTracerFactory ks = EmptyKeyspaceTracerFactory.getInstance();
    ConnectionPool<Cassandra.Client> pool = (ConnectionPool<Cassandra.Client>) context.getConnectionPool();
    final String cfname = def.getName();
    _log.info("Adding CF: {}", cfname);
    try {
        return pool.executeWithFailover(new AbstractOperationImpl<String>(ks.newTracer(CassandraOperationType.ADD_COLUMN_FAMILY)) {

            @Override
            public String internalExecute(Cassandra.Client client, ConnectionContext context) throws Exception {
                client.set_keyspace(_keyspaceName);
                // This method can be retried several times, so server may already have received the 'creating CF' request
                // and created the CF, we check the existence of the CF first before issuing another 'creating CF' request
                // which will cause the 'CF already exists' exception
                KsDef kd = client.describe_keyspace(_keyspaceName);
                List<CfDef> cfs = kd.getCf_defs();
                for (CfDef cf : cfs) {
                    if (cf.getName().equals(cfname)) {
                        _log.info("The CF {} has already been created", cfname);
                        return null;
                    }
                }
                _log.info("To create CF {}", cfname);
                return client.system_add_column_family(def.getThriftColumnFamilyDefinition());
            }
        }, context.getAstyanaxConfiguration().getRetryPolicy().duplicate()).getResult();
    } catch (final OperationException e) {
        throw DatabaseException.retryables.operationFailed(e);
    } catch (final ConnectionException e) {
        throw DatabaseException.retryables.connectionFailed(e);
    }
}
Also used : ConnectionPool(com.netflix.astyanax.connectionpool.ConnectionPool) AbstractOperationImpl(com.netflix.astyanax.thrift.AbstractOperationImpl) Cassandra(org.apache.cassandra.thrift.Cassandra) Cluster(com.netflix.astyanax.Cluster) KeyspaceTracerFactory(com.netflix.astyanax.KeyspaceTracerFactory) EmptyKeyspaceTracerFactory(com.netflix.astyanax.shallows.EmptyKeyspaceTracerFactory) KsDef(org.apache.cassandra.thrift.KsDef) ConnectionContext(com.netflix.astyanax.connectionpool.ConnectionContext) DbClient(com.emc.storageos.db.client.DbClient) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) CfDef(org.apache.cassandra.thrift.CfDef) OperationException(com.netflix.astyanax.connectionpool.exceptions.OperationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Aggregations

KeyspaceTracerFactory (com.netflix.astyanax.KeyspaceTracerFactory)4 ConnectionContext (com.netflix.astyanax.connectionpool.ConnectionContext)4 ConnectionPool (com.netflix.astyanax.connectionpool.ConnectionPool)4 EmptyKeyspaceTracerFactory (com.netflix.astyanax.shallows.EmptyKeyspaceTracerFactory)4 AbstractOperationImpl (com.netflix.astyanax.thrift.AbstractOperationImpl)4 Cassandra (org.apache.cassandra.thrift.Cassandra)4 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)3 DbClient (com.emc.storageos.db.client.DbClient)3 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)3 OperationException (com.netflix.astyanax.connectionpool.exceptions.OperationException)3 Cluster (com.netflix.astyanax.Cluster)2 KsDef (org.apache.cassandra.thrift.KsDef)2 SSLConnectionContext (com.netflix.astyanax.connectionpool.SSLConnectionContext)1 ThriftKeyspaceDefinitionImpl (com.netflix.astyanax.thrift.ddl.ThriftKeyspaceDefinitionImpl)1 CfDef (org.apache.cassandra.thrift.CfDef)1