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);
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations