Search in sources :

Example 11 with KeyspaceMetadata

use of com.datastax.driver.core.KeyspaceMetadata in project zipkin by openzipkin.

the class Schema method getKeyspaceMetadata.

static KeyspaceMetadata getKeyspaceMetadata(Session session) {
    String keyspace = session.getLoggedKeyspace();
    Cluster cluster = session.getCluster();
    KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace);
    if (keyspaceMetadata == null) {
        throw new IllegalStateException(String.format("Cannot read keyspace metadata for give keyspace: %s and cluster: %s", keyspace, cluster.getClusterName()));
    }
    return keyspaceMetadata;
}
Also used : Cluster(com.datastax.driver.core.Cluster) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 12 with KeyspaceMetadata

use of com.datastax.driver.core.KeyspaceMetadata in project zipkin by openzipkin.

the class Schema method ensureExists.

static void ensureExists(String keyspace, Session session) {
    KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace);
    if (keyspaceMetadata == null || keyspaceMetadata.getTable("traces") == null) {
        LOG.info("Installing schema {}", SCHEMA);
        applyCqlFile(keyspace, session, SCHEMA);
        // refresh metadata since we've installed the schema
        keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace);
    }
    if (!hasUpgrade1_defaultTtl(keyspaceMetadata)) {
        LOG.info("Upgrading schema {}", UPGRADE_1);
        applyCqlFile(keyspace, session, UPGRADE_1);
    }
}
Also used : KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 13 with KeyspaceMetadata

use of com.datastax.driver.core.KeyspaceMetadata in project zipkin by openzipkin.

the class EnsureSchemaTest method installsTablesWhenMissing.

@Test
public void installsTablesWhenMissing() {
    session.execute("CREATE KEYSPACE " + keyspace + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};");
    Schema.ensureExists(keyspace, session);
    KeyspaceMetadata metadata = session.getCluster().getMetadata().getKeyspace(keyspace);
    assertThat(metadata).isNotNull();
    assertThat(Schema.hasUpgrade1_defaultTtl(metadata)).isTrue();
}
Also used : KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) Test(org.junit.Test)

Example 14 with KeyspaceMetadata

use of com.datastax.driver.core.KeyspaceMetadata in project zipkin by openzipkin.

the class Schema method readMetadata.

static Metadata readMetadata(Session session) {
    KeyspaceMetadata keyspaceMetadata = getKeyspaceMetadata(session);
    Map<String, String> replication = keyspaceMetadata.getReplication();
    if ("SimpleStrategy".equals(replication.get("class")) && "1".equals(replication.get("replication_factor"))) {
        LOG.warn("running with RF=1, this is not suitable for production. Optimal is 3+");
    }
    String compactionClass = keyspaceMetadata.getTable("traces").getOptions().getCompaction().get("class");
    return new Metadata(compactionClass);
}
Also used : KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 15 with KeyspaceMetadata

use of com.datastax.driver.core.KeyspaceMetadata in project zipkin by openzipkin.

the class Schema method ensureExists.

static KeyspaceMetadata ensureExists(String keyspace, Session session) {
    KeyspaceMetadata result = session.getCluster().getMetadata().getKeyspace(keyspace);
    if (result == null || result.getTable("traces") == null) {
        LOG.info("Installing schema {}", SCHEMA_RESOURCE);
        applyCqlFile(keyspace, session, SCHEMA_RESOURCE);
        // refresh metadata since we've installed the schema
        result = session.getCluster().getMetadata().getKeyspace(keyspace);
    }
    return result;
}
Also used : KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Aggregations

KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)26 TableMetadata (com.datastax.driver.core.TableMetadata)9 DriverException (com.datastax.driver.core.exceptions.DriverException)7 Cluster (com.datastax.driver.core.Cluster)5 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)5 Test (org.junit.Test)5 ImmutableList (com.google.common.collect.ImmutableList)3 QualifiedName (com.netflix.metacat.common.QualifiedName)3 RegularStatement (com.datastax.driver.core.RegularStatement)2 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)2 ArrayList (java.util.ArrayList)2 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)1 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)1 MappingManager (com.datastax.driver.mapping.MappingManager)1 EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)1 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)1 PrestoException (com.facebook.presto.spi.PrestoException)1 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)1 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)1 AnnotationUDT (zipkin.storage.cassandra3.Schema.AnnotationUDT)1