Search in sources :

Example 1 with RestInvalidModeException

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

the class ModeResource method updateMode.

@Path("/{subject}")
@PUT
@Operation(summary = "Update mode for the specified subject.", responses = { @ApiResponse(responseCode = "422", description = "Error code 42204 -- Invalid mode\n" + "Error code 42205 -- Operation not permitted"), @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" + "Error code 50004 -- Unknown leader") })
public ModeUpdateRequest updateMode(@Parameter(description = "Name of the subject", required = true) @PathParam("subject") String subject, @Context HttpHeaders headers, @Parameter(description = "Update Request", required = true) @NotNull ModeUpdateRequest request, @Parameter(description = "Whether to force update if setting mode to IMPORT and schemas currently exist") @QueryParam("force") boolean force) {
    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);
    io.confluent.kafka.schemaregistry.storage.Mode mode;
    try {
        mode = Enum.valueOf(io.confluent.kafka.schemaregistry.storage.Mode.class, request.getMode().toUpperCase(Locale.ROOT));
    } catch (IllegalArgumentException e) {
        throw new RestInvalidModeException();
    }
    try {
        Map<String, String> headerProperties = requestHeaderBuilder.buildRequestHeaders(headers, schemaRegistry.config().whitelistHeaders());
        schemaRegistry.setModeOrForward(subject, mode, force, headerProperties);
    } catch (OperationNotPermittedException e) {
        throw Errors.operationNotPermittedException(e.getMessage());
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException("Failed to update mode", e);
    } catch (UnknownLeaderException e) {
        throw Errors.unknownLeaderException("Failed to update mode", e);
    } catch (SchemaRegistryRequestForwardingException e) {
        throw Errors.requestForwardingFailedException("Error while forwarding update mode request" + " to the leader", e);
    }
    return request;
}
Also used : UnknownLeaderException(io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException) SchemaRegistryRequestForwardingException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException) Mode(io.confluent.kafka.schemaregistry.client.rest.entities.Mode) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) RestInvalidModeException(io.confluent.kafka.schemaregistry.rest.exceptions.RestInvalidModeException) Path(javax.ws.rs.Path) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT)

Aggregations

Mode (io.confluent.kafka.schemaregistry.client.rest.entities.Mode)1 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)1 SchemaRegistryRequestForwardingException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException)1 SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)1 UnknownLeaderException (io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException)1 RestInvalidModeException (io.confluent.kafka.schemaregistry.rest.exceptions.RestInvalidModeException)1 Operation (io.swagger.v3.oas.annotations.Operation)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1