Search in sources :

Example 11 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData 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)

Example 12 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class KubernetesGatewayService method updateSchema.

@Override
public Completable updateSchema(final String name, final String graphQLSchema) {
    // Check if the gateway exists or not
    final Completable resourceExists = this.kubernetesManagerClient.checkDeploymentExistence(ResourcePrefix.GATEWAY, name);
    // applies the definition to gateway but not persisting it yet
    final Completable updateSchema = this.gatewayClient.updateSchema(name, new SchemaData(graphQLSchema));
    // persisting the applied definition to the ConfigMap and update the data of the ConfigMap
    final Completable updateConfigMap = this.kubernetesManagerClient.updateConfigMap(GatewayResources.getConfigMapName(name), Map.of("schema.graphql", graphQLSchema));
    return resourceExists.andThen(updateSchema).andThen(updateConfigMap).onErrorResumeNext(ex -> GatewayResources.handleDefinitionCreationError(ex, name));
}
Also used : Completable(io.reactivex.Completable) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData)

Example 13 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class ControllerReturnSchemaTest method shouldReturnStringSchema.

@Test
void shouldReturnStringSchema() throws IOException {
    final String expectedProduct = Files.readString(workingDirectory.resolve("product.graphql"));
    final String expectedPurchase = Files.readString(workingDirectory.resolve("purchase.graphql"));
    final HttpRequest<?> productRequest = HttpRequest.create(HttpMethod.GET, "/schema/product");
    final SchemaData productResponse = this.httpClient.exchange(productRequest, Argument.of(SchemaData.class)).blockingFirst().body();
    assertThat(productResponse).isNotNull().extracting(SchemaData::getSchema).asString().isEqualToIgnoringWhitespace(expectedProduct);
    final HttpRequest<?> purchaseRequest = HttpRequest.create(HttpMethod.GET, "/schema/purchase");
    final SchemaData purchaseResponse = this.httpClient.exchange(purchaseRequest, Argument.of(SchemaData.class)).blockingFirst().body();
    assertThat(purchaseResponse).isNotNull().extracting(SchemaData::getSchema).asString().isEqualToIgnoringWhitespace(expectedPurchase);
}
Also used : SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Aggregations

SchemaData (com.bakdata.quick.common.api.model.gateway.SchemaData)13 Test (org.junit.jupiter.api.Test)10 GatewayDescription (com.bakdata.quick.common.api.model.manager.GatewayDescription)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Completable (io.reactivex.Completable)6 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)5 TopicCreationData (com.bakdata.quick.common.api.model.manager.creation.TopicCreationData)4 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)3 GatewaySchema (com.bakdata.quick.common.api.model.manager.GatewaySchema)2 GatewayClient (com.bakdata.quick.common.api.client.GatewayClient)1 ErrorMessage (com.bakdata.quick.common.api.model.ErrorMessage)1 TopicData (com.bakdata.quick.common.api.model.TopicData)1 GatewayCreationData (com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData)1 MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)1 GatewayResourceLoader (com.bakdata.quick.manager.gateway.resource.GatewayResourceLoader)1 GraphQLToAvroConverter (com.bakdata.quick.manager.graphql.GraphQLToAvroConverter)1 KubernetesResources (com.bakdata.quick.manager.k8s.KubernetesResources)1 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)1 MiddlewareList (com.bakdata.quick.manager.k8s.middleware.MiddlewareList)1 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1