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);
}
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);
}
}
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;
}
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);
}
}
Aggregations