Search in sources :

Example 21 with KsDef

use of org.apache.cassandra.thrift.KsDef in project coprhd-controller by CoprHD.

the class GeoDbSvcStartupTest method checkSchema.

@Test
public void checkSchema() throws Exception {
    // Check if snitch setup is OK
    NodeProbe cmd = new NodeProbe(HOST, JMX_PORT);
    String dc = cmd.getDataCenter();
    Assert.assertTrue("Unexpected DC name " + dc, "vdc1".equalsIgnoreCase(dc));
    // Check schema setup is OK
    TSocket socket = new TSocket(HOST, RPC_PORT);
    TTransport transport = new TFastFramedTransport(socket);
    transport.open();
    try {
        Cassandra.Client client = new Cassandra.Client(new TBinaryProtocol(transport, true, true));
        KsDef def = client.describe_keyspace(DbClientContext.GEO_KEYSPACE_NAME);
        String strategyClass = def.strategy_class;
        log.info("Current strategy class in geodb schema: " + strategyClass);
        Assert.assertTrue("Unexpected strategy class " + strategyClass, strategyClass.contains("NetworkTopologyStrategy"));
        Map<String, String> strategyOptions = def.getStrategy_options();
        Assert.assertTrue(strategyOptions.size() > 0);
    } finally {
        transport.close();
    }
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) Cassandra(org.apache.cassandra.thrift.Cassandra) TFastFramedTransport(org.apache.thrift.transport.TFastFramedTransport) TTransport(org.apache.thrift.transport.TTransport) KsDef(org.apache.cassandra.thrift.KsDef) DbClient(com.emc.storageos.db.client.DbClient) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) NodeProbe(org.apache.cassandra.tools.NodeProbe) TSocket(org.apache.thrift.transport.TSocket) Test(org.junit.Test)

Example 22 with KsDef

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

the class AbstractIntegrationTest method setup.

/**
 * Starts embedded cassandra server.
 *
 * @throws Exception
 *             if an error occurs
 */
public static void setup(List<CfDef> columnDefinitions) throws Exception {
    if (cassandraServer == null) {
        cassandraServer = new EmbeddedCassandraServer();
        cassandraServer.start();
        // wait until cassandra server starts up. could wait less time, but
        // 2 seconds to be sure.
        Thread.sleep(2000);
    }
    colFamilyDefs = columnDefinitions;
    keyspaceManager = new KeyspaceManager(cluster);
    columnFamilyManager = new ColumnFamilyManager(cluster, KEYSPACE);
    List<KsDef> keyspaces = keyspaceManager.getKeyspaceNames();
    for (KsDef ksDef : keyspaces) if (ksDef.name.equals(KEYSPACE)) {
        keyspaceManager.dropKeyspace(KEYSPACE);
    }
    KsDef keyspaceDefinition = new KsDef(KEYSPACE, KeyspaceManager.KSDEF_STRATEGY_SIMPLE, new ArrayList<CfDef>());
    Map<String, String> strategyOptions = new HashMap<String, String>();
    strategyOptions.put("replication_factor", "1");
    keyspaceDefinition.setStrategy_options(strategyOptions);
    for (CfDef colFamilyDef : colFamilyDefs) {
        keyspaceDefinition.addToCf_defs(colFamilyDef);
    }
    keyspaceManager.addKeyspace(keyspaceDefinition);
}
Also used : KeyspaceManager(org.scale7.cassandra.pelops.KeyspaceManager) ColumnFamilyManager(org.scale7.cassandra.pelops.ColumnFamilyManager) HashMap(java.util.HashMap) KsDef(org.apache.cassandra.thrift.KsDef) CfDef(org.apache.cassandra.thrift.CfDef)

Example 23 with KsDef

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

the class KSMetaData method toThrift.

public KsDef toThrift() {
    List<CfDef> cfDefs = new ArrayList<CfDef>();
    for (CFMetaData cfm : cfMetaData().values()) cfDefs.add(cfm.toThrift());
    KsDef ksdef = new KsDef(name, strategyClass.getName(), cfDefs);
    ksdef.setStrategy_options(strategyOptions);
    if (strategyOptions != null && strategyOptions.containsKey("replication_factor"))
        ksdef.setReplication_factor(Integer.parseInt(strategyOptions.get("replication_factor")));
    ksdef.setDurable_writes(durableWrites);
    return ksdef;
}
Also used : KsDef(org.apache.cassandra.thrift.KsDef) CfDef(org.apache.cassandra.thrift.CfDef)

Example 24 with KsDef

use of org.apache.cassandra.thrift.KsDef in project titan by thinkaurelius.

the class CassandraThriftStoreManager method ensureKeyspaceExists.

private KsDef ensureKeyspaceExists(String keyspaceName) throws NotFoundException, InvalidRequestException, TException, SchemaDisagreementException, StorageException {
    CTConnection connection = null;
    try {
        connection = pool.borrowObject(SYSTEM_KS);
        Cassandra.Client client = connection.getClient();
        try {
            // Side effect: throws Exception if keyspaceName doesn't exist
            // Don't remove
            client.set_keyspace(keyspaceName);
            client.set_keyspace(SYSTEM_KS);
            log.debug("Found existing keyspace {}", keyspaceName);
        } catch (InvalidRequestException e) {
            // Keyspace didn't exist; create it
            log.debug("Creating keyspace {}...", keyspaceName);
            KsDef ksdef = new KsDef().setName(keyspaceName).setCf_defs(// cannot be null but can be empty
            new LinkedList<CfDef>()).setStrategy_class("org.apache.cassandra.locator.SimpleStrategy").setStrategy_options(ImmutableMap.of("replication_factor", String.valueOf(replicationFactor)));
            client.set_keyspace(SYSTEM_KS);
            try {
                client.system_add_keyspace(ksdef);
                log.debug("Created keyspace {}", keyspaceName);
            } catch (InvalidRequestException ire) {
                log.error("system_add_keyspace failed for keyspace=" + keyspaceName, ire);
                throw ire;
            }
        }
        return client.describe_keyspace(keyspaceName);
    } catch (Exception e) {
        throw new TemporaryStorageException(e);
    } finally {
        pool.returnObjectUnsafe(SYSTEM_KS, connection);
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) Cassandra(org.apache.cassandra.thrift.Cassandra) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) KsDef(org.apache.cassandra.thrift.KsDef) LinkedList(java.util.LinkedList) NotFoundException(org.apache.cassandra.thrift.NotFoundException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TException(org.apache.thrift.TException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException)

Example 25 with KsDef

use of org.apache.cassandra.thrift.KsDef in project titan by thinkaurelius.

the class CassandraThriftStoreManager method getCompressionOptions.

@Override
public Map<String, String> getCompressionOptions(String cf) throws StorageException {
    CTConnection conn = null;
    Map<String, String> result = null;
    try {
        conn = pool.borrowObject(keySpaceName);
        Cassandra.Client client = conn.getClient();
        KsDef ksDef = client.describe_keyspace(keySpaceName);
        for (CfDef cfDef : ksDef.getCf_defs()) {
            if (null != cfDef && cfDef.getName().equals(cf)) {
                result = cfDef.getCompression_options();
                break;
            }
        }
        return result;
    } catch (InvalidRequestException e) {
        log.debug("Keyspace {} does not exist", keySpaceName);
        return null;
    } catch (Exception e) {
        throw new TemporaryStorageException(e);
    } finally {
        pool.returnObjectUnsafe(keySpaceName, conn);
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) Cassandra(org.apache.cassandra.thrift.Cassandra) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) KsDef(org.apache.cassandra.thrift.KsDef) CfDef(org.apache.cassandra.thrift.CfDef) NotFoundException(org.apache.cassandra.thrift.NotFoundException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TException(org.apache.thrift.TException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException)

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