Search in sources :

Example 1 with CompatibilityLevel

use of io.confluent.kafka.schemaregistry.CompatibilityLevel in project schema-registry by confluentinc.

the class ConfigResource method deleteTopLevelConfig.

@DELETE
@Operation(summary = "Deletes the Global-level compatibility level config and " + "revert to the global default.", responses = { @ApiResponse(content = @Content(schema = @Schema(implementation = CompatibilityLevel.class))), @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the backend " + "datastore") })
public void deleteTopLevelConfig(@Suspended final AsyncResponse asyncResponse, @Context HttpHeaders headers) {
    log.info("Deleting Global compatibility setting and reverting back to default");
    Config deletedConfig;
    try {
        CompatibilityLevel currentCompatibility = schemaRegistry.getCompatibilityLevel(null);
        Map<String, String> headerProperties = requestHeaderBuilder.buildRequestHeaders(headers, schemaRegistry.config().whitelistHeaders());
        schemaRegistry.deleteCompatibilityConfigOrForward(null, headerProperties);
        deletedConfig = new Config(currentCompatibility.name);
    } catch (OperationNotPermittedException e) {
        throw Errors.operationNotPermittedException(e.getMessage());
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException("Failed to delete compatibility level", e);
    } catch (UnknownLeaderException e) {
        throw Errors.unknownLeaderException("Failed to delete compatibility level", e);
    } catch (SchemaRegistryRequestForwardingException e) {
        throw Errors.requestForwardingFailedException("Error while forwarding delete config request" + " to the leader", e);
    }
    asyncResponse.resume(deletedConfig);
}
Also used : CompatibilityLevel(io.confluent.kafka.schemaregistry.CompatibilityLevel) UnknownLeaderException(io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException) SchemaRegistryRequestForwardingException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException) Config(io.confluent.kafka.schemaregistry.client.rest.entities.Config) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) DELETE(javax.ws.rs.DELETE) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with CompatibilityLevel

use of io.confluent.kafka.schemaregistry.CompatibilityLevel in project schema-registry by confluentinc.

the class ConfigResource method getSubjectLevelConfig.

@Path("/{subject}")
@GET
@Operation(summary = "Get compatibility level for a subject.", responses = { @ApiResponse(responseCode = "404", description = "Subject not found"), @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the backend " + "data store") })
public Config getSubjectLevelConfig(@Parameter(description = "Name of the subject", required = true) @PathParam("subject") String subject, @Parameter(description = "Whether to return the global compatibility level " + " if subject compatibility level not found") @QueryParam("defaultToGlobal") boolean defaultToGlobal) {
    subject = QualifiedSubject.normalize(schemaRegistry.tenant(), subject);
    Config config;
    try {
        CompatibilityLevel compatibilityLevel = defaultToGlobal ? schemaRegistry.getCompatibilityLevelInScope(subject) : schemaRegistry.getCompatibilityLevel(subject);
        if (compatibilityLevel == null) {
            throw Errors.subjectLevelCompatibilityNotConfiguredException(subject);
        }
        config = new Config(compatibilityLevel.name);
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException("Failed to get the configs for subject " + subject, e);
    }
    return config;
}
Also used : CompatibilityLevel(io.confluent.kafka.schemaregistry.CompatibilityLevel) Config(io.confluent.kafka.schemaregistry.client.rest.entities.Config) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 3 with CompatibilityLevel

use of io.confluent.kafka.schemaregistry.CompatibilityLevel in project schema-registry by confluentinc.

the class ConfigResource method getTopLevelConfig.

@GET
@Operation(summary = "Get global compatibility level.", responses = { @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the backend " + "data store") })
public Config getTopLevelConfig() {
    Config config;
    try {
        CompatibilityLevel compatibilityLevel = schemaRegistry.getCompatibilityLevel(null);
        config = new Config(compatibilityLevel == null ? null : compatibilityLevel.name);
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException("Failed to get compatibility level", e);
    }
    return config;
}
Also used : CompatibilityLevel(io.confluent.kafka.schemaregistry.CompatibilityLevel) Config(io.confluent.kafka.schemaregistry.client.rest.entities.Config) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 4 with CompatibilityLevel

use of io.confluent.kafka.schemaregistry.CompatibilityLevel in project schema-registry by confluentinc.

the class TestLocalCompatibilityMojo method execute.

public void execute() throws MojoExecutionException {
    List<SchemaProvider> providers = MojoUtils.defaultSchemaProviders();
    Map<String, SchemaProvider> schemaProviders = providers.stream().collect(Collectors.toMap(SchemaProvider::schemaType, p -> p));
    getLog().debug(String.format("Loading Schema at %s", schemaPath));
    ParsedSchema schema = loadSchema(schemaPath, schemaProviders);
    getLog().debug("Loading Previous Schemas");
    ArrayList<ParsedSchema> previousSchemas = new ArrayList<>();
    for (File previousSchemaPath : previousSchemaPaths) {
        previousSchemas.add(loadSchema(previousSchemaPath, schemaProviders));
    }
    CompatibilityChecker checker = CompatibilityChecker.checker(compatibilityLevel);
    List<String> errorMessages = checker.isCompatible(schema, previousSchemas);
    if (previousSchemas.size() > 1 && (compatibilityLevel == CompatibilityLevel.BACKWARD || compatibilityLevel == CompatibilityLevel.FORWARD || compatibilityLevel == CompatibilityLevel.FULL)) {
        getLog().info(String.format("Checking only with latest Schema at %s", previousSchemaPaths.get(previousSchemaPaths.size() - 1)));
    }
    success = errorMessages.isEmpty();
    if (success) {
        getLog().info(String.format("Schema is %s compatible with previous schemas", compatibilityLevel.name.toLowerCase()));
    } else {
        String errorLog = String.format("Schema is not %s compatible with previous schemas %n", compatibilityLevel.name.toLowerCase()) + errorMessages.get(0);
        getLog().error(errorLog);
    }
}
Also used : IOException(java.io.IOException) CompatibilityChecker(io.confluent.kafka.schemaregistry.CompatibilityChecker) Parameter(org.apache.maven.plugins.annotations.Parameter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) ArrayList(java.util.ArrayList) Mojo(org.apache.maven.plugins.annotations.Mojo) List(java.util.List) CompatibilityLevel(io.confluent.kafka.schemaregistry.CompatibilityLevel) SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) Map(java.util.Map) Optional(java.util.Optional) SchemaReference(io.confluent.kafka.schemaregistry.client.rest.entities.SchemaReference) AbstractMojo(org.apache.maven.plugin.AbstractMojo) ArrayList(java.util.ArrayList) SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) File(java.io.File) CompatibilityChecker(io.confluent.kafka.schemaregistry.CompatibilityChecker)

Example 5 with CompatibilityLevel

use of io.confluent.kafka.schemaregistry.CompatibilityLevel in project schema-registry by confluentinc.

the class ConfigResource method deleteSubjectConfig.

@DELETE
@Path("/{subject}")
@Operation(summary = "Deletes the specified subject-level compatibility level config and " + "revert to the global default.", responses = { @ApiResponse(content = @Content(schema = @Schema(implementation = CompatibilityLevel.class))), @ApiResponse(responseCode = "404", description = "Error code 40401 -- Subject not found"), @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the backend " + "datastore") })
public void deleteSubjectConfig(@Suspended final AsyncResponse asyncResponse, @Context HttpHeaders headers, @Parameter(description = "Name of the subject", required = true) @PathParam("subject") String subject) {
    log.info("Deleting compatibility setting for subject {}", subject);
    subject = QualifiedSubject.normalize(schemaRegistry.tenant(), subject);
    Config deletedConfig;
    try {
        CompatibilityLevel currentCompatibility = schemaRegistry.getCompatibilityLevel(subject);
        if (currentCompatibility == null) {
            throw Errors.subjectNotFoundException(subject);
        }
        Map<String, String> headerProperties = requestHeaderBuilder.buildRequestHeaders(headers, schemaRegistry.config().whitelistHeaders());
        schemaRegistry.deleteCompatibilityConfigOrForward(subject, headerProperties);
        deletedConfig = new Config(currentCompatibility.name);
    } catch (OperationNotPermittedException e) {
        throw Errors.operationNotPermittedException(e.getMessage());
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException("Failed to delete compatibility level", e);
    } catch (UnknownLeaderException e) {
        throw Errors.unknownLeaderException("Failed to delete compatibility level", e);
    } catch (SchemaRegistryRequestForwardingException e) {
        throw Errors.requestForwardingFailedException("Error while forwarding delete config request" + " to the leader", e);
    }
    asyncResponse.resume(deletedConfig);
}
Also used : CompatibilityLevel(io.confluent.kafka.schemaregistry.CompatibilityLevel) UnknownLeaderException(io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException) SchemaRegistryRequestForwardingException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException) Config(io.confluent.kafka.schemaregistry.client.rest.entities.Config) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

CompatibilityLevel (io.confluent.kafka.schemaregistry.CompatibilityLevel)9 SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)6 Operation (io.swagger.v3.oas.annotations.Operation)6 Config (io.confluent.kafka.schemaregistry.client.rest.entities.Config)4 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)4 SchemaRegistryRequestForwardingException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException)4 UnknownLeaderException (io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException)4 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 RestInvalidCompatibilityException (io.confluent.kafka.schemaregistry.rest.exceptions.RestInvalidCompatibilityException)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2 PUT (javax.ws.rs.PUT)2 CompatibilityChecker (io.confluent.kafka.schemaregistry.CompatibilityChecker)1 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)1 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)1 SchemaReference (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaReference)1 File (java.io.File)1 IOException (java.io.IOException)1