Search in sources :

Example 1 with RestInvalidCompatibilityException

use of io.confluent.kafka.schemaregistry.rest.exceptions.RestInvalidCompatibilityException in project schema-registry by confluentinc.

the class ConfigResource method updateSubjectLevelConfig.

@Path("/{subject}")
@PUT
@Operation(summary = "Update compatibility level for the specified subject.", responses = { @ApiResponse(responseCode = "422", description = "Error code 42203 -- Invalid compatibility level\n" + "Error code 40402 -- Version not found"), @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the backend data store\n" + "Error code 50003 -- Error while forwarding the request to the primary") })
public ConfigUpdateRequest updateSubjectLevelConfig(@Parameter(description = "Name of the subject", required = true) @PathParam("subject") String subject, @Context HttpHeaders headers, @Parameter(description = "Config Update Request", required = true) @NotNull ConfigUpdateRequest request) {
    CompatibilityLevel compatibilityLevel = CompatibilityLevel.forName(request.getCompatibilityLevel());
    if (compatibilityLevel == null) {
        throw new RestInvalidCompatibilityException();
    }
    if (subject != null && (CharMatcher.javaIsoControl().matchesAnyOf(subject) || QualifiedSubject.create(this.schemaRegistry.tenant(), subject).getSubject().equals(GLOBAL_RESOURCE_NAME))) {
        throw Errors.invalidSubjectException(subject);
    }
    subject = QualifiedSubject.normalize(schemaRegistry.tenant(), subject);
    try {
        Map<String, String> headerProperties = requestHeaderBuilder.buildRequestHeaders(headers, schemaRegistry.config().whitelistHeaders());
        schemaRegistry.updateConfigOrForward(subject, compatibilityLevel, headerProperties);
    } catch (OperationNotPermittedException e) {
        throw Errors.operationNotPermittedException(e.getMessage());
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException("Failed to update compatibility level", e);
    } catch (UnknownLeaderException e) {
        throw Errors.unknownLeaderException("Failed to update compatibility level", e);
    } catch (SchemaRegistryRequestForwardingException e) {
        throw Errors.requestForwardingFailedException("Error while forwarding update config request" + " to the leader", e);
    }
    return request;
}
Also used : RestInvalidCompatibilityException(io.confluent.kafka.schemaregistry.rest.exceptions.RestInvalidCompatibilityException) CompatibilityLevel(io.confluent.kafka.schemaregistry.CompatibilityLevel) UnknownLeaderException(io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException) SchemaRegistryRequestForwardingException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) Path(javax.ws.rs.Path) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT)

Example 2 with RestInvalidCompatibilityException

use of io.confluent.kafka.schemaregistry.rest.exceptions.RestInvalidCompatibilityException in project schema-registry by confluentinc.

the class ConfigResource method updateTopLevelConfig.

@PUT
@Operation(summary = "Update global compatibility level.", responses = { @ApiResponse(responseCode = "422", description = "Error code 42203 -- Invalid compatibility" + " level"), @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the backend data store\n" + "Error code 50003 -- Error while forwarding the request to the primary\n") })
public ConfigUpdateRequest updateTopLevelConfig(@Context HttpHeaders headers, @Parameter(description = "Config Update Request", required = true) @NotNull ConfigUpdateRequest request) {
    CompatibilityLevel compatibilityLevel = CompatibilityLevel.forName(request.getCompatibilityLevel());
    if (compatibilityLevel == null) {
        throw new RestInvalidCompatibilityException();
    }
    try {
        Map<String, String> headerProperties = requestHeaderBuilder.buildRequestHeaders(headers, schemaRegistry.config().whitelistHeaders());
        schemaRegistry.updateConfigOrForward(null, compatibilityLevel, headerProperties);
    } catch (OperationNotPermittedException e) {
        throw Errors.operationNotPermittedException(e.getMessage());
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException("Failed to update compatibility level", e);
    } catch (UnknownLeaderException e) {
        throw Errors.unknownLeaderException("Failed to update compatibility level", e);
    } catch (SchemaRegistryRequestForwardingException e) {
        throw Errors.requestForwardingFailedException("Error while forwarding update config request" + " to the leader", e);
    }
    return request;
}
Also used : RestInvalidCompatibilityException(io.confluent.kafka.schemaregistry.rest.exceptions.RestInvalidCompatibilityException) CompatibilityLevel(io.confluent.kafka.schemaregistry.CompatibilityLevel) UnknownLeaderException(io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException) SchemaRegistryRequestForwardingException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT)

Aggregations

CompatibilityLevel (io.confluent.kafka.schemaregistry.CompatibilityLevel)2 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)2 SchemaRegistryRequestForwardingException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException)2 SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)2 UnknownLeaderException (io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException)2 RestInvalidCompatibilityException (io.confluent.kafka.schemaregistry.rest.exceptions.RestInvalidCompatibilityException)2 Operation (io.swagger.v3.oas.annotations.Operation)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)1