Search in sources :

Example 1 with OperationException

use of com.netflix.astyanax.connectionpool.exceptions.OperationException 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 OperationException

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

the class Resource3NewFlagsInitializer method process.

@Override
public void process() {
    DbClient dbClient = getDbClient();
    // check if we need to inject
    if (injectFault) {
        faultInjected = true;
        throw DatabaseException.retryables.operationFailed(new OperationException("Custom callback execuction error. Injected fault"));
    }
    // check if we need to inject
    if (injectFatalFault) {
        faultInjected = true;
        throw DatabaseException.fatals.failedDuringUpgrade("Injected fatal exception during upgrade", null);
    }
    // Check Resource3
    List<URI> res3Keys = dbClient.queryByType(Resource3.class, false);
    Iterator<Resource3> res3Objs = dbClient.queryIterativeObjects(Resource3.class, res3Keys);
    while (res3Objs.hasNext()) {
        Resource3 res3 = res3Objs.next();
        // Resource3FlagsInitializer should be executed first so extraFlags has value
        Long extraFlags = res3.getExtraFlags();
        if (extraFlags == null) {
            throw new IllegalStateException("Custom callback order error. Resource3FlagsInitializer should be executed first for Resource3.");
        }
        // Current value for new flag - should be zero always
        // Custom callback should be executed only once even referenced by many fields
        Long currentValue = res3.getNewFlags();
        if (currentValue != null) {
            throw new IllegalStateException("Custom callback order error. Resource3NewFlagsInitializer should not be executed twice.");
        }
        res3.setNewFlags(extraFlags);
        dbClient.persistObject(res3);
    }
    // Check Resource6
    List<URI> res6Keys = dbClient.queryByType(Resource6.class, false);
    Iterator<Resource6> res6Objs = dbClient.queryIterativeObjects(Resource6.class, res6Keys);
    while (res6Objs.hasNext()) {
        Resource6 res6 = res6Objs.next();
        // Resource3FlagsInitializer should be executed first so extraFlags has value
        Long extraFlags = res6.getExtraFlags();
        if (extraFlags == null) {
            throw new IllegalStateException("Custom callback order error. Resource3FlagsInitializer should be executed first for Resource6.");
        }
        // Current value for new flag - should be zero always
        // Custom callback should be executed only once even referenced by many fields
        Long currentValue = res6.getNewFlags();
        if (currentValue != null) {
            throw new IllegalStateException("Custom callback order error. Resource3NewFlagsInitializer should not be executed twice.");
        }
        res6.setNewFlags(extraFlags);
        res6.setDupTestFlags(extraFlags);
        dbClient.persistObject(res6);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) Resource6(com.emc.storageos.db.server.upgrade.util.models.updated2.Resource6) Resource3(com.emc.storageos.db.server.upgrade.util.models.updated2.Resource3) URI(java.net.URI) OperationException(com.netflix.astyanax.connectionpool.exceptions.OperationException)

Example 3 with OperationException

use of com.netflix.astyanax.connectionpool.exceptions.OperationException 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 OperationException

use of com.netflix.astyanax.connectionpool.exceptions.OperationException 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

DbClient (com.emc.storageos.db.client.DbClient)4 OperationException (com.netflix.astyanax.connectionpool.exceptions.OperationException)4 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)3 KeyspaceTracerFactory (com.netflix.astyanax.KeyspaceTracerFactory)3 ConnectionContext (com.netflix.astyanax.connectionpool.ConnectionContext)3 ConnectionPool (com.netflix.astyanax.connectionpool.ConnectionPool)3 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)3 EmptyKeyspaceTracerFactory (com.netflix.astyanax.shallows.EmptyKeyspaceTracerFactory)3 AbstractOperationImpl (com.netflix.astyanax.thrift.AbstractOperationImpl)3 Cassandra (org.apache.cassandra.thrift.Cassandra)3 Cluster (com.netflix.astyanax.Cluster)2 Resource3 (com.emc.storageos.db.server.upgrade.util.models.updated2.Resource3)1 Resource6 (com.emc.storageos.db.server.upgrade.util.models.updated2.Resource6)1 URI (java.net.URI)1 CfDef (org.apache.cassandra.thrift.CfDef)1 KsDef (org.apache.cassandra.thrift.KsDef)1