Search in sources :

Example 1 with GatewaySchema

use of com.bakdata.quick.common.api.model.manager.GatewaySchema in project quick by bakdata.

the class KafkaTopicService method getQuickSchemas.

private Single<Optional<QuickSchemas>> getQuickSchemas(final GatewaySchema gatewaySchema) {
    if (gatewaySchema == null) {
        return Single.just(Optional.empty());
    }
    // make sure the gateway exists
    return this.gatewayService.getGateway(gatewaySchema.getGateway()).flatMap(ignored -> this.gatewayClient.getWriteSchema(gatewaySchema.getGateway(), gatewaySchema.getType())).map(schemaResponse -> {
        final String graphQLSchema = schemaResponse.getSchema();
        final Schema avroSchema = graphQLToAvroConverter.convertToSchema(graphQLSchema);
        return Optional.of(new QuickSchemas(graphQLSchema, avroSchema));
    });
}
Also used : MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) TopicRegistryClient(com.bakdata.quick.common.api.client.TopicRegistryClient) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) KEY(com.bakdata.quick.common.api.model.KeyValueEnum.KEY) TopicWriteType(com.bakdata.quick.common.api.model.TopicWriteType) Completable(io.reactivex.Completable) GatewayClient(com.bakdata.quick.common.api.client.GatewayClient) Singleton(javax.inject.Singleton) Single(io.reactivex.Single) Supplier(java.util.function.Supplier) GraphQLToAvroConverter(com.bakdata.quick.manager.graphql.GraphQLToAvroConverter) Value(lombok.Value) AdminClient(org.apache.kafka.clients.admin.AdminClient) KafkaConfig(com.bakdata.quick.common.config.KafkaConfig) MirrorService(com.bakdata.quick.manager.mirror.MirrorService) Duration(java.time.Duration) KeyValueEnum(com.bakdata.quick.common.api.model.KeyValueEnum) QuickTopicConfig(com.bakdata.quick.common.config.QuickTopicConfig) QuickTopicType(com.bakdata.quick.common.type.QuickTopicType) Schema(org.apache.avro.Schema) ResourcePrefix(com.bakdata.quick.manager.k8s.resource.QuickResources.ResourcePrefix) NewTopic(org.apache.kafka.clients.admin.NewTopic) GatewaySchema(com.bakdata.quick.common.api.model.manager.GatewaySchema) IOException(java.io.IOException) VALUE(com.bakdata.quick.common.api.model.KeyValueEnum.VALUE) BadArgumentException(com.bakdata.quick.common.exception.BadArgumentException) TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) TopicData(com.bakdata.quick.common.api.model.TopicData) GatewayService(com.bakdata.quick.manager.gateway.GatewayService) Optional(java.util.Optional) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) Schema(org.apache.avro.Schema) GatewaySchema(com.bakdata.quick.common.api.model.manager.GatewaySchema)

Example 2 with GatewaySchema

use of com.bakdata.quick.common.api.model.manager.GatewaySchema in project quick by bakdata.

the class TopicControllerTest method testCreateTopicWhenQueryIsNotDefined.

@Test
void testCreateTopicWhenQueryIsNotDefined() {
    when(this.service.createTopic(anyString(), any(), any(), any())).thenReturn(Completable.complete());
    final TopicCreationData creationData = new TopicCreationData(TopicWriteType.MUTABLE, null, new GatewaySchema("test", "test"), null);
    this.client.toBlocking().exchange(POST(baseUri, creationData));
    verify(this.service).createTopic(NAME, QuickTopicType.LONG, QuickTopicType.SCHEMA, creationData);
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) GatewaySchema(com.bakdata.quick.common.api.model.manager.GatewaySchema) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Example 3 with GatewaySchema

use of com.bakdata.quick.common.api.model.manager.GatewaySchema in project quick by bakdata.

the class KubernetesGatewayService method getGatewayWriteSchema.

@Override
public Single<SchemaData> getGatewayWriteSchema(final String name, final String type, final SchemaFormat format) {
    final GatewaySchema gatewaySchema = new GatewaySchema(name, type);
    // make sure the gateway exists
    final Completable exists = this.kubernetesManagerClient.checkDeploymentExistence(ResourcePrefix.GATEWAY, name);
    final Action logAccess = () -> log.debug("Retrieve schema in '{}' gateway for type '{}' in '{}'", name, type, format.getName());
    final Single<SchemaData> fetchSchema = this.gatewayClient.getWriteSchema(gatewaySchema.getGateway(), gatewaySchema.getType()).map(response -> {
        String schema = response.getSchema();
        if (format == SchemaFormat.AVRO) {
            schema = graphQLToAvroConverter.convertToSchema(schema).toString();
        }
        return new SchemaData(schema);
    });
    return exists.doOnComplete(logAccess).andThen(fetchSchema);
}
Also used : Completable(io.reactivex.Completable) Action(io.reactivex.functions.Action) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewaySchema(com.bakdata.quick.common.api.model.manager.GatewaySchema)

Aggregations

GatewaySchema (com.bakdata.quick.common.api.model.manager.GatewaySchema)3 TopicCreationData (com.bakdata.quick.common.api.model.manager.creation.TopicCreationData)2 Completable (io.reactivex.Completable)2 GatewayClient (com.bakdata.quick.common.api.client.GatewayClient)1 TopicRegistryClient (com.bakdata.quick.common.api.client.TopicRegistryClient)1 KeyValueEnum (com.bakdata.quick.common.api.model.KeyValueEnum)1 KEY (com.bakdata.quick.common.api.model.KeyValueEnum.KEY)1 VALUE (com.bakdata.quick.common.api.model.KeyValueEnum.VALUE)1 TopicData (com.bakdata.quick.common.api.model.TopicData)1 TopicWriteType (com.bakdata.quick.common.api.model.TopicWriteType)1 SchemaData (com.bakdata.quick.common.api.model.gateway.SchemaData)1 MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)1 KafkaConfig (com.bakdata.quick.common.config.KafkaConfig)1 QuickTopicConfig (com.bakdata.quick.common.config.QuickTopicConfig)1 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)1 QuickTopicType (com.bakdata.quick.common.type.QuickTopicType)1 GatewayService (com.bakdata.quick.manager.gateway.GatewayService)1 GraphQLToAvroConverter (com.bakdata.quick.manager.graphql.GraphQLToAvroConverter)1 ResourcePrefix (com.bakdata.quick.manager.k8s.resource.QuickResources.ResourcePrefix)1 MirrorService (com.bakdata.quick.manager.mirror.MirrorService)1