Search in sources :

Example 6 with KeyspaceMetadata

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;
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)

Example 7 with KeyspaceMetadata

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));
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) MutableCodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.MutableCodecRegistry) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)

Example 8 with KeyspaceMetadata

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;
}
Also used : KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)

Example 9 with KeyspaceMetadata

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;
}
Also used : KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)

Example 10 with 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));
}
Also used : Statement(com.datastax.oss.driver.api.core.cql.Statement) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) KeyColumnValueStoreTest(org.janusgraph.diskstorage.KeyColumnValueStoreTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)16 Test (org.junit.jupiter.api.Test)9 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)7 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)5 Statement (com.datastax.oss.driver.api.core.cql.Statement)4 KeyColumnValueStoreTest (org.janusgraph.diskstorage.KeyColumnValueStoreTest)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)3 Node (com.datastax.oss.driver.api.core.metadata.Node)3 Test (org.junit.Test)2 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)1 MutableCodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.MutableCodecRegistry)1 Resources.resourceToString (zipkin2.storage.cassandra.internal.Resources.resourceToString)1