Search in sources :

Example 11 with KsDef

use of org.apache.cassandra.thrift.KsDef in project scale7-pelops by s7.

the class Cluster method refreshInternal.

/**
 * Refresh the snapshot of the list of nodes currently believed to exist in the Cassandra cluster.
 * @return the list of nodes
 */
private String[] refreshInternal() throws Exception {
    KeyspaceManager kspcMngr = new ClusterKeyspaceManager(this);
    List<KsDef> keyspaces = kspcMngr.getKeyspaceNames();
    Iterator<KsDef> k = keyspaces.iterator();
    KsDef appKeyspace = null;
    while (k.hasNext()) {
        KsDef keyspace = k.next();
        if (!keyspace.getName().equals("system")) {
            appKeyspace = keyspace;
            break;
        }
    }
    if (appKeyspace == null)
        throw new Exception("Cannot obtain a node list from a ring mapping. No keyspaces are defined for this cluster.");
    return refreshInternal(appKeyspace.getName());
}
Also used : KsDef(org.apache.cassandra.thrift.KsDef)

Example 12 with KsDef

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

the class CliCompiler method getKeySpace.

public static String getKeySpace(String ksName, List<KsDef> keyspaces) {
    int matches = 0;
    String lastMatchedName = "";
    for (KsDef ksDef : keyspaces) {
        if (ksDef.name.equals(ksName)) {
            return ksName;
        } else if (ksDef.name.toUpperCase().equals(ksName.toUpperCase())) {
            lastMatchedName = ksDef.name;
            matches++;
        }
    }
    if (matches > 1 || matches == 0)
        throw new RuntimeException("Keyspace '" + ksName + "' not found.");
    return lastMatchedName;
}
Also used : KsDef(org.apache.cassandra.thrift.KsDef)

Example 13 with KsDef

use of org.apache.cassandra.thrift.KsDef 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 14 with KsDef

use of org.apache.cassandra.thrift.KsDef 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 15 with KsDef

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

the class SchemaManagerServiceTest method testCreateKeyspaceSchema.

@Test
public void testCreateKeyspaceSchema() throws Exception {
    KsDef ksDef = setupOtherKeyspace(configuration, "CreatedKeyspace", false);
    cassandraClientHolder.getClient().system_add_keyspace(ksDef);
    schemaManagerService.createKeyspaceSchema(ksDef);
    List<KsDef> keyspaces = schemaManagerService.findUnmappedKeyspaces();
    // don't impose a keyspace maintenance burden. Looking for specifics is good enough
    for (KsDef ks : keyspaces) {
        if (StringUtils.equals(ks.name, "CreatedKeyspace")) {
            fail("created was not synched");
        }
    }
}
Also used : KsDef(org.apache.cassandra.thrift.KsDef) Test(org.junit.Test)

Aggregations

KsDef (org.apache.cassandra.thrift.KsDef)25 CfDef (org.apache.cassandra.thrift.CfDef)11 Cassandra (org.apache.cassandra.thrift.Cassandra)7 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)7 NotFoundException (org.apache.cassandra.thrift.NotFoundException)7 Test (org.junit.Test)7 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 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)4 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)4 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)2 DbClient (com.emc.storageos.db.client.DbClient)2 KeyspaceTracerFactory (com.netflix.astyanax.KeyspaceTracerFactory)2 ConnectionContext (com.netflix.astyanax.connectionpool.ConnectionContext)2 ConnectionPool (com.netflix.astyanax.connectionpool.ConnectionPool)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2