use of com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata in project zipkin by openzipkin.
the class InternalForTests method mockSession.
static CqlSession mockSession() {
CqlSession session = mock(CqlSession.class);
Metadata metadata = mock(Metadata.class);
Node node = mock(Node.class);
when(session.getMetadata()).thenReturn(metadata);
when(metadata.getNodes()).thenReturn(Collections.singletonMap(UUID.fromString("11111111-1111-1111-1111-111111111111"), node));
when(node.getCassandraVersion()).thenReturn(Version.parse("3.11.9"));
KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
when(session.getMetadata()).thenReturn(metadata);
when(metadata.getKeyspace("zipkin2")).thenReturn(Optional.of(keyspaceMetadata));
when(keyspaceMetadata.getTable(TABLE_SERVICE_REMOTE_SERVICES)).thenReturn(Optional.of(mock(TableMetadata.class)));
return session;
}
use of com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata in project zipkin by openzipkin.
the class DefaultSessionFactory method initializeUDTs.
static void initializeUDTs(CqlSession session, String keyspace) {
KeyspaceMetadata ks = session.getMetadata().getKeyspace(keyspace).get();
MutableCodecRegistry codecRegistry = (MutableCodecRegistry) session.getContext().getCodecRegistry();
TypeCodec<UdtValue> annotationUDTCodec = codecRegistry.codecFor(ks.getUserDefinedType("annotation").get());
codecRegistry.register(new AnnotationCodec(annotationUDTCodec));
LOG.debug("Registering endpoint and annotation UDTs to keyspace {}", keyspace);
TypeCodec<UdtValue> endpointUDTCodec = codecRegistry.codecFor(ks.getUserDefinedType("endpoint").get());
codecRegistry.register(new EndpointCodec(endpointUDTCodec));
}
use of com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata in project zipkin by openzipkin.
the class Schema method ensureExists.
static KeyspaceMetadata ensureExists(String keyspace, boolean searchEnabled, CqlSession session) {
KeyspaceMetadata result = session.getMetadata().getKeyspace(keyspace).orElse(null);
if (result == null || !result.getTable(Schema.TABLE_SPAN).isPresent()) {
LOG.info("Installing schema {} for keyspace {}", SCHEMA_RESOURCE, keyspace);
applyCqlFile(keyspace, session, SCHEMA_RESOURCE);
if (searchEnabled) {
LOG.info("Installing indexes {} for keyspace {}", INDEX_RESOURCE, keyspace);
applyCqlFile(keyspace, session, INDEX_RESOURCE);
}
// refresh metadata since we've installed the schema
result = ensureKeyspaceMetadata(session, keyspace);
}
if (searchEnabled && !hasUpgrade1_autocompleteTags(result)) {
LOG.info("Upgrading schema {}", UPGRADE_1);
applyCqlFile(keyspace, session, UPGRADE_1);
}
if (searchEnabled && !hasUpgrade2_remoteService(result)) {
LOG.info("Upgrading schema {}", UPGRADE_2);
applyCqlFile(keyspace, session, UPGRADE_2);
}
return result;
}
use of com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata in project zipkin by openzipkin.
the class Schema method ensureKeyspaceMetadata.
static KeyspaceMetadata ensureKeyspaceMetadata(CqlSession session, String keyspace) {
ensureVersion(session.getMetadata());
KeyspaceMetadata keyspaceMetadata = session.getMetadata().getKeyspace(keyspace).orElse(null);
if (keyspaceMetadata == null) {
throw new IllegalStateException(String.format("Cannot read keyspace metadata for keyspace: %s and cluster: %s", keyspace, session.getMetadata().getClusterName()));
}
return keyspaceMetadata;
}
use of com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata in project janusgraph by JanusGraph.
the class CQLStoreTest method testNewTableOpenDatabase.
@Test
public void testNewTableOpenDatabase() throws BackendException {
// arrange
String someTableName = "foo";
Metadata metadata = mock(Metadata.class);
KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
when(keyspaceMetadata.getTable(someTableName)).thenReturn(Optional.empty());
when(session.getMetadata()).thenReturn(metadata);
when(metadata.getKeyspace(mockManager.getKeyspaceName())).thenReturn(Optional.of(keyspaceMetadata));
// act
mockManager.openDatabase(someTableName, null);
// assert
verify(session, times(1)).execute(any(Statement.class));
}
Aggregations