Search in sources :

Example 11 with SchemaRegistryRequestForwardingException

use of io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException 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 12 with SchemaRegistryRequestForwardingException

use of io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException 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 13 with SchemaRegistryRequestForwardingException

use of io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException 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)

Example 14 with SchemaRegistryRequestForwardingException

use of io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException 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)

Example 15 with SchemaRegistryRequestForwardingException

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

the class ModeResource method deleteSubjectMode.

@DELETE
@Path("/{subject}")
@Operation(summary = "Deletes the specified subject-level mode and revert to " + "the global default.", responses = { @ApiResponse(content = @Content(schema = @Schema(implementation = io.confluent.kafka.schemaregistry.storage.Mode.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 deleteSubjectMode(@Suspended final AsyncResponse asyncResponse, @Context HttpHeaders headers, @Parameter(description = "Name of the subject", required = true) @PathParam("subject") String subject) {
    log.info("Deleting mode for subject {}", subject);
    subject = QualifiedSubject.normalize(schemaRegistry.tenant(), subject);
    io.confluent.kafka.schemaregistry.storage.Mode deletedMode;
    Mode deleteModeResponse;
    try {
        deletedMode = schemaRegistry.getMode(subject);
        if (deletedMode == null) {
            throw Errors.subjectNotFoundException(subject);
        }
        Map<String, String> headerProperties = requestHeaderBuilder.buildRequestHeaders(headers, schemaRegistry.config().whitelistHeaders());
        schemaRegistry.deleteSubjectModeOrForward(subject, headerProperties);
        deleteModeResponse = new Mode(deletedMode.name());
    } catch (OperationNotPermittedException e) {
        throw Errors.operationNotPermittedException(e.getMessage());
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException("Failed to delete mode", e);
    } catch (UnknownLeaderException e) {
        throw Errors.unknownLeaderException("Failed to delete mode", e);
    } catch (SchemaRegistryRequestForwardingException e) {
        throw Errors.requestForwardingFailedException("Error while forwarding delete mode request" + " to the leader", e);
    }
    asyncResponse.resume(deleteModeResponse);
}
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) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

SchemaRegistryRequestForwardingException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException)15 SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)8 UnknownLeaderException (io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException)8 Operation (io.swagger.v3.oas.annotations.Operation)8 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)7 UrlList (io.confluent.kafka.schemaregistry.client.rest.utils.UrlList)7 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)7 RestException (io.confluent.rest.exceptions.RestException)7 IOException (java.io.IOException)7 Path (javax.ws.rs.Path)5 CompatibilityLevel (io.confluent.kafka.schemaregistry.CompatibilityLevel)4 DELETE (javax.ws.rs.DELETE)4 PUT (javax.ws.rs.PUT)3 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)2 Config (io.confluent.kafka.schemaregistry.client.rest.entities.Config)2 Mode (io.confluent.kafka.schemaregistry.client.rest.entities.Mode)2 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)2 SchemaRegistryException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException)2 SchemaRegistryTimeoutException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException)2 RestInvalidCompatibilityException (io.confluent.kafka.schemaregistry.rest.exceptions.RestInvalidCompatibilityException)2