Search in sources :

Example 1 with Config

use of io.confluent.kafka.schemaregistry.client.rest.entities.Config 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 Config

use of io.confluent.kafka.schemaregistry.client.rest.entities.Config 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 Config

use of io.confluent.kafka.schemaregistry.client.rest.entities.Config 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 Config

use of io.confluent.kafka.schemaregistry.client.rest.entities.Config 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)

Example 5 with Config

use of io.confluent.kafka.schemaregistry.client.rest.entities.Config in project schema-registry by confluentinc.

the class RestService method getConfig.

public Config getConfig(Map<String, String> requestProperties, String subject, boolean defaultToGlobal) throws IOException, RestClientException {
    String path = subject != null ? UriBuilder.fromPath("/config/{subject}").queryParam("defaultToGlobal", defaultToGlobal).build(subject).toString() : "/config";
    Config config = httpRequest(path, "GET", null, requestProperties, GET_CONFIG_RESPONSE_TYPE);
    return config;
}
Also used : Config(io.confluent.kafka.schemaregistry.client.rest.entities.Config) SchemaRegistryClientConfig(io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig) SchemaString(io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)

Aggregations

Config (io.confluent.kafka.schemaregistry.client.rest.entities.Config)6 CompatibilityLevel (io.confluent.kafka.schemaregistry.CompatibilityLevel)4 SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)4 Operation (io.swagger.v3.oas.annotations.Operation)4 SchemaRegistryClientConfig (io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig)2 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)2 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)2 SchemaRegistryRequestForwardingException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException)2 UnknownLeaderException (io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2