use of org.apache.cassandra.config.KSMetaData in project janusgraph by JanusGraph.
the class CassandraEmbeddedStoreManager method ensureKeyspaceExists.
private void ensureKeyspaceExists(String keyspaceName) throws BackendException {
if (null != Schema.instance.getKeyspaceInstance(keyspaceName))
return;
// Keyspace not found; create it
String strategyName = storageConfig.get(REPLICATION_STRATEGY);
KSMetaData ksm;
try {
ksm = KSMetaData.newKeyspace(keyspaceName, strategyName, strategyOptions, true);
} catch (ConfigurationException e) {
throw new PermanentBackendException("Failed to instantiate keyspace metadata for " + keyspaceName, e);
}
try {
MigrationManager.announceNewKeyspace(ksm);
log.info("Created keyspace {}", keyspaceName);
} catch (ConfigurationException e) {
throw new PermanentBackendException("Failed to create keyspace " + keyspaceName, e);
}
}
use of org.apache.cassandra.config.KSMetaData in project eiger by wlloyd.
the class MultiDcCops2Test method setup.
@BeforeClass
public static void setup() throws IOException, InterruptedException, ConfigurationException, InvalidRequestException, SchemaDisagreementException, TException {
Integer numDatacenters = Integer.getInteger("cassandra.multiDcTest.numDatacenters");
assert numDatacenters != null : "You must set the numDatacenters to run the multiDc Tests";
Integer nodesPerDatacenter = Integer.getInteger("cassandra.multiDcTest.nodesPerDatacenter");
assert nodesPerDatacenter != null : "You must set nodesPerDatacenter to run the multiDc Tests";
// Create a keyspace with a replication factor of 1 for each datacenter
TTransport tr = new TFramedTransport(new TSocket("127.0.0.1", DEFAULT_THRIFT_PORT));
TProtocol proto = new TBinaryProtocol(tr);
Cassandra.Client client = new Cassandra.Client(proto);
tr.open();
// set the replication factor to 1 for each datacenter
Map<String, String> ntsOptions = new HashMap<String, String>();
assert numDatacenters > 0;
for (int i = 0; i < numDatacenters; ++i) {
ntsOptions.put("DC" + i, "1");
}
// We'll use the same set of columns as is used in the EmbeddedCassandraService
// and we'll set the index type to KEYS so thrift doesn't complain
Map<String, CFMetaData> cfDefs = schemaDefinition().iterator().next().cfMetaData();
for (Entry<String, CFMetaData> cfEntry : cfDefs.entrySet()) {
assert cfEntry.getKey() == cfEntry.getValue().cfName;
for (ColumnDefinition colDef : cfEntry.getValue().getColumn_metadata().values()) {
colDef.setIndexType(IndexType.KEYS, null);
}
cfEntry.getValue().readRepairChance(0);
}
KSMetaData keyspace1 = KSMetaData.testMetadataNotDurable("Keyspace1", NetworkTopologyStrategy.class, ntsOptions, cfDefs.values());
client.system_add_keyspace(keyspace1.toThrift());
// setup the normal test
HashMap<String, Integer> localServerIPAndPorts = new HashMap<String, Integer>();
for (int i = 1; i <= nodesPerDatacenter; ++i) {
localServerIPAndPorts.put("127.0.0." + i, DEFAULT_THRIFT_PORT);
}
List<Map<String, Integer>> dcToServerIPAndPorts = new ArrayList();
for (int dc = 0; dc < numDatacenters; ++dc) {
HashMap<String, Integer> serverIPAndPorts = new HashMap<String, Integer>();
for (int i = 0; i < nodesPerDatacenter; ++i) {
int ipIndex = 1 + dc * nodesPerDatacenter + i;
serverIPAndPorts.put("127.0.0." + ipIndex, DEFAULT_THRIFT_PORT);
}
dcToServerIPAndPorts.add(serverIPAndPorts);
}
Cops2Test.setLocalServerIPAndPorts(localServerIPAndPorts);
Cops2Test.setDcToServerIPAndPorts(dcToServerIPAndPorts);
Cops2Test.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);
// wait for the keyspace to show up at all nodes
HashMap<String, Integer> allServerIPAndPorts = new HashMap<String, Integer>();
for (int i = 1; i <= numDatacenters * nodesPerDatacenter; ++i) {
allServerIPAndPorts.put("127.0.0." + i, DEFAULT_THRIFT_PORT);
}
waitForKeyspacePropagation(allServerIPAndPorts, "Keyspace1");
}
use of org.apache.cassandra.config.KSMetaData in project brisk by riptano.
the class BriskErrorServer method describe_keyspace.
public KsDef describe_keyspace(String table) throws NotFoundException, InvalidRequestException, TException {
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(table);
if (ksm == null)
throw new NotFoundException();
List<CfDef> cfDefs = new ArrayList<CfDef>();
for (CFMetaData cfm : ksm.cfMetaData().values()) cfDefs.add(CFMetaData.convertToThrift(cfm));
KsDef ksdef = new KsDef(ksm.name, ksm.strategyClass.getName(), cfDefs);
ksdef.setStrategy_options(ksm.strategyOptions);
return ksdef;
}
use of org.apache.cassandra.config.KSMetaData in project titan by thinkaurelius.
the class CassandraEmbeddedStoreManager method ensureKeyspaceExists.
private void ensureKeyspaceExists(String keyspaceName) throws StorageException {
if (null != Schema.instance.getTableInstance(keyspaceName))
return;
// Keyspace not found; create it
String strategyName = "org.apache.cassandra.locator.SimpleStrategy";
Map<String, String> options = new HashMap<String, String>() {
{
put("replication_factor", String.valueOf(replicationFactor));
}
};
KSMetaData ksm;
try {
ksm = KSMetaData.newKeyspace(keyspaceName, strategyName, options, true);
} catch (ConfigurationException e) {
throw new PermanentStorageException("Failed to instantiate keyspace metadata for " + keyspaceName, e);
}
try {
MigrationManager.announceNewKeyspace(ksm);
log.debug("Created keyspace {}", keyspaceName);
} catch (ConfigurationException e) {
throw new PermanentStorageException("Failed to create keyspace " + keyspaceName, e);
}
}
use of org.apache.cassandra.config.KSMetaData in project eiger by wlloyd.
the class SerializationsTest method testWrite.
private void testWrite() throws IOException, ConfigurationException {
for (int i = 0; i < ksCount; i++) {
String tableName = "Keyspace" + (i + 1);
KSMetaData ksm = Schema.instance.getKSMetaData(tableName);
UUID uuid = UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress());
Schema.instance.clearTableDefinition(ksm, uuid);
Migration m = new AddKeyspace(ksm);
ByteBuffer bytes = m.serialize();
DataOutputStream out = getOutput("db.migration." + tableName + ".bin");
out.writeUTF(new String(Base64.encodeBase64(bytes.array())));
out.close();
}
}
Aggregations