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;
}
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);
}
}
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();
}
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);
}
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;
}
Aggregations