Search in sources :

Example 21 with CfDef

use of org.apache.cassandra.thrift.CfDef in project eiger by wlloyd.

the class CFMetaDataTest method testThriftToAvroConversion.

@Test
public void testThriftToAvroConversion() throws Exception {
    CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName()).setComment("Test comment").setColumn_metadata(columnDefs).setKeyspace(KEYSPACE).setName(COLUMN_FAMILY);
    // convert Thrift to CFMetaData
    CFMetaData cfMetaData = CFMetaData.fromThrift(cfDef);
    // make a correct Avro object
    org.apache.cassandra.db.migration.avro.CfDef avroCfDef = new org.apache.cassandra.db.migration.avro.CfDef();
    avroCfDef.keyspace = new Utf8(KEYSPACE);
    avroCfDef.name = new Utf8(COLUMN_FAMILY);
    avroCfDef.default_validation_class = new Utf8(cfDef.default_validation_class);
    avroCfDef.comment = new Utf8(cfDef.comment);
    avroCfDef.column_metadata = new ArrayList<org.apache.cassandra.db.migration.avro.ColumnDef>();
    for (ColumnDef columnDef : columnDefs) {
        org.apache.cassandra.db.migration.avro.ColumnDef c = new org.apache.cassandra.db.migration.avro.ColumnDef();
        c.name = ByteBufferUtil.clone(columnDef.name);
        c.validation_class = new Utf8(columnDef.getValidation_class());
        c.index_name = new Utf8(columnDef.getIndex_name());
        c.index_type = org.apache.cassandra.db.migration.avro.IndexType.KEYS;
        avroCfDef.column_metadata.add(c);
    }
    org.apache.cassandra.db.migration.avro.CfDef converted = cfMetaData.toAvro();
    assertEquals(avroCfDef.keyspace, converted.keyspace);
    assertEquals(avroCfDef.name, converted.name);
    assertEquals(avroCfDef.default_validation_class, converted.default_validation_class);
    assertEquals(avroCfDef.comment, converted.comment);
    assertEquals(avroCfDef.column_metadata, converted.column_metadata);
}
Also used : AsciiType(org.apache.cassandra.db.marshal.AsciiType) ColumnDef(org.apache.cassandra.thrift.ColumnDef) Utf8(org.apache.avro.util.Utf8) CfDef(org.apache.cassandra.thrift.CfDef) Test(org.junit.Test)

Example 22 with CfDef

use of org.apache.cassandra.thrift.CfDef in project brisk by riptano.

the class BriskSchema method createKeySpace.

public static KsDef createKeySpace() throws IOException {
    try {
        logger.info("Creating keyspace: " + KEYSPACE_NAME);
        Thread.sleep(new Random().nextInt(5000));
        KsDef cfsKs = checkKeyspace();
        if (cfsKs != null) {
            logger.info("keyspace already exists. Skipping creation.");
            return cfsKs;
        }
        List<CfDef> cfs = new ArrayList<CfDef>();
        CfDef cf = new CfDef();
        cf.setName(JOB_TRACKER_CF);
        cf.setComparator_type("BytesType");
        // there is only one row and one column.
        cf.setKey_cache_size(10);
        cf.setRow_cache_size(10);
        cf.setGc_grace_seconds(60);
        cf.setComment("Stores the current JobTracker node");
        cf.setKeyspace(KEYSPACE_NAME);
        cfs.add(cf);
        Map<String, String> stratOpts = new HashMap<String, String>();
        stratOpts.put(BriskSimpleSnitch.BRISK_DC, System.getProperty("cfs.replication", "1"));
        stratOpts.put(BriskSimpleSnitch.CASSANDRA_DC, "0");
        cfsKs = new KsDef().setName(KEYSPACE_NAME).setStrategy_class("org.apache.cassandra.locator.NetworkTopologyStrategy").setStrategy_options(stratOpts).setCf_defs(cfs);
        client.system_add_keyspace(cfsKs);
        waitForSchemaAgreement(client);
        return cfsKs;
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KsDef(org.apache.cassandra.thrift.KsDef) IOException(java.io.IOException) CfDef(org.apache.cassandra.thrift.CfDef) TException(org.apache.thrift.TException) IOException(java.io.IOException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException)

Example 23 with CfDef

use of org.apache.cassandra.thrift.CfDef in project brisk by riptano.

the class MetaStoreTestBase method setupOtherKeyspace.

protected KsDef setupOtherKeyspace(Configuration configuration, String ksName, String keyValidator, String comparator, boolean addMetaData) throws Exception {
    CfDef cf = new CfDef(ksName, "OtherCf1");
    cf.setKey_validation_class(keyValidator);
    cf.setComparator_type(comparator);
    if (addMetaData) {
        cf.addToColumn_metadata(new ColumnDef(ByteBufferUtil.bytes("col_name_utf8"), UTF8Type.class.getName()));
        cf.addToColumn_metadata(new ColumnDef(ByteBufferUtil.bytes("col_name_bytes"), BytesType.class.getName()));
        cf.addToColumn_metadata(new ColumnDef(ByteBufferUtil.bytes("col_name_int"), IntegerType.class.getName()));
        cf.addToColumn_metadata(new ColumnDef(ByteBufferUtil.bytes("col_name_long"), LongType.class.getName()));
        cf.addToColumn_metadata(new ColumnDef(ByteBufferUtil.bytes("col_name_timeuuid"), TimeUUIDType.class.getName()));
    }
    KsDef ks = new KsDef(ksName, "org.apache.cassandra.locator.SimpleStrategy", Arrays.asList(cf));
    ks.setStrategy_options(KSMetaData.optsWithRF(configuration.getInt(CassandraClientHolder.CONF_PARAM_REPLICATION_FACTOR, 1)));
    return ks;
}
Also used : ColumnDef(org.apache.cassandra.thrift.ColumnDef) KsDef(org.apache.cassandra.thrift.KsDef) CfDef(org.apache.cassandra.thrift.CfDef)

Example 24 with CfDef

use of org.apache.cassandra.thrift.CfDef 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

CfDef (org.apache.cassandra.thrift.CfDef)24 KsDef (org.apache.cassandra.thrift.KsDef)10 Test (org.junit.Test)7 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)6 NotFoundException (org.apache.cassandra.thrift.NotFoundException)6 TException (org.apache.thrift.TException)6 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)4 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)4 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)4 Cassandra (org.apache.cassandra.thrift.Cassandra)4 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)4 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)3 ColumnDef (org.apache.cassandra.thrift.ColumnDef)3 Cluster (com.netflix.astyanax.Cluster)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)2 OperationException (com.netflix.astyanax.connectionpool.exceptions.OperationException)2 HashMap (java.util.HashMap)2 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)1 DbClient (com.emc.storageos.db.client.DbClient)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1