use of io.confluent.kafka.schemaregistry.client.rest.entities.Mode in project schema-registry by confluentinc.
the class RestService method deleteSubjectMode.
public Mode deleteSubjectMode(Map<String, String> requestProperties, String subject) throws IOException, RestClientException {
UriBuilder builder = UriBuilder.fromPath("/mode/{subject}");
String path = builder.build(subject).toString();
Mode response = httpRequest(path, "DELETE", null, requestProperties, DELETE_SUBJECT_MODE_RESPONSE_TYPE);
return response;
}
use of io.confluent.kafka.schemaregistry.client.rest.entities.Mode in project schema-registry by confluentinc.
the class RestService method getMode.
public Mode getMode(String subject, boolean defaultToGlobal) throws IOException, RestClientException {
String path = subject != null ? UriBuilder.fromPath("/mode/{subject}").queryParam("defaultToGlobal", defaultToGlobal).build(subject).toString() : "/mode";
Mode mode = httpRequest(path, "GET", null, DEFAULT_REQUEST_PROPERTIES, GET_MODE_RESPONSE_TYPE);
return mode;
}
use of io.confluent.kafka.schemaregistry.client.rest.entities.Mode in project schema-registry by confluentinc.
the class CachedSchemaRegistryClientTest method testGetMode.
@Test
public void testGetMode() throws Exception {
final String mode = "READONLY";
reset(restService);
Mode modeGetResponse = new Mode(mode);
expect(restService.getMode()).andReturn(modeGetResponse);
replay(restService);
assertEquals(mode, client.getMode());
verify(restService);
}
use of io.confluent.kafka.schemaregistry.client.rest.entities.Mode 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;
}
use of io.confluent.kafka.schemaregistry.client.rest.entities.Mode 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);
}
Aggregations