Search in sources :

Example 1 with KSMetaData

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);
    }
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) KSMetaData(org.apache.cassandra.config.KSMetaData)

Example 2 with KSMetaData

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");
}
Also used : ColumnDefinition(org.apache.cassandra.config.ColumnDefinition) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) CFMetaData(org.apache.cassandra.config.CFMetaData) KSMetaData(org.apache.cassandra.config.KSMetaData) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket) BeforeClass(org.junit.BeforeClass)

Example 3 with KSMetaData

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;
}
Also used : KSMetaData(org.apache.cassandra.config.KSMetaData) CFMetaData(org.apache.cassandra.config.CFMetaData)

Example 4 with KSMetaData

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);
    }
}
Also used : HashMap(java.util.HashMap) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) KSMetaData(org.apache.cassandra.config.KSMetaData)

Example 5 with KSMetaData

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();
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) KSMetaData(org.apache.cassandra.config.KSMetaData) UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer)

Aggregations

KSMetaData (org.apache.cassandra.config.KSMetaData)10 ByteBuffer (java.nio.ByteBuffer)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 CFMetaData (org.apache.cassandra.config.CFMetaData)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 Schema (org.apache.avro.Schema)1 ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)1 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TFramedTransport (org.apache.thrift.transport.TFramedTransport)1 TSocket (org.apache.thrift.transport.TSocket)1 TTransport (org.apache.thrift.transport.TTransport)1 BeforeClass (org.junit.BeforeClass)1