Search in sources :

Example 16 with KeyspaceMetadata

use of com.datastax.driver.core.KeyspaceMetadata in project cassandra-driver-mapping by valchkou.

the class SchemaSync method drop.

public static synchronized void drop(String keyspace, Session session, Class<?> clazz) {
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(clazz);
    entityMetadata.markUnSynced(keyspace);
    String table = entityMetadata.getTableName();
    Cluster cluster = session.getCluster();
    KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace);
    TableMetadata tableMetadata = keyspaceMetadata.getTable(table);
    if (tableMetadata != null) {
        session.execute("USE " + keyspace);
        // drop indexes
        /*for (ColumnMetadata columnMetadata: tableMetadata.getColumns()) {
    			if (columnMetadata.getIndex() != null) {
    				session.execute(new DropIndex(keyspace, columnMetadata.getIndex().getName()));
    			}
    		}*/
        // drop table
        session.execute(new DropTable(keyspace, entityMetadata));
    }
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Cluster(com.datastax.driver.core.Cluster) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 17 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 18 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 19 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 20 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)

Aggregations

KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)34 DriverException (com.datastax.driver.core.exceptions.DriverException)14 TableMetadata (com.datastax.driver.core.TableMetadata)13 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)10 QualifiedName (com.netflix.metacat.common.QualifiedName)6 Cluster (com.datastax.driver.core.Cluster)5 Test (org.junit.Test)5 ImmutableList (com.google.common.collect.ImmutableList)4 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)4 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)2 RegularStatement (com.datastax.driver.core.RegularStatement)2 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)2 ArrayList (java.util.ArrayList)2 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)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 AnnotationUDT (zipkin.storage.cassandra3.Schema.AnnotationUDT)1