use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException in project registry by hortonworks.
the class SchemaRegistryClient method mergeSchemaVersion.
@Override
public SchemaVersionMergeResult mergeSchemaVersion(Long schemaVersionId) throws SchemaNotFoundException, IncompatibleSchemaException {
WebTarget target = currentSchemaRegistryTargets().schemasTarget.path(schemaVersionId + "/merge");
Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {
@Override
public Response run() {
return target.request().post(null);
}
});
int status = response.getStatus();
if (status == Response.Status.OK.getStatusCode()) {
String msg = response.readEntity(String.class);
return readEntity(msg, SchemaVersionMergeResult.class);
} else if (status == Response.Status.NOT_FOUND.getStatusCode()) {
throw new SchemaNotFoundException(response.readEntity(String.class));
} else if (status == Response.Status.BAD_REQUEST.getStatusCode()) {
throw new IncompatibleSchemaException(response.readEntity(String.class));
} else {
throw new RuntimeException(response.readEntity(String.class));
}
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException in project registry by hortonworks.
the class SchemaRegistryClient method handleSchemaLifeCycleResponse.
private boolean handleSchemaLifeCycleResponse(Response response) throws SchemaNotFoundException, SchemaLifecycleException {
boolean result;
int status = response.getStatus();
if (status == Response.Status.OK.getStatusCode()) {
result = response.readEntity(Boolean.class);
} else if (status == Response.Status.NOT_FOUND.getStatusCode()) {
throw new SchemaNotFoundException(response.readEntity(String.class));
} else if (status == Response.Status.BAD_REQUEST.getStatusCode()) {
CatalogResponse catalogResponse = readCatalogResponse(response.readEntity(String.class));
if (catalogResponse.getResponseCode() == CatalogResponse.ResponseMessage.INCOMPATIBLE_SCHEMA.getCode()) {
throw new SchemaLifecycleException(new IncompatibleSchemaException(catalogResponse.getResponseMessage()));
}
throw new SchemaLifecycleException(catalogResponse.getResponseMessage());
} else {
throw new RuntimeException(response.readEntity(String.class));
}
return result;
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException in project registry by hortonworks.
the class SchemaRegistryClient method doAddSchemaVersion.
private SchemaIdVersion doAddSchemaVersion(String schemaBranchName, String schemaName, SchemaVersion schemaVersion) throws IncompatibleSchemaException, InvalidSchemaException, SchemaNotFoundException {
SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaName);
if (schemaMetadataInfo == null) {
throw new SchemaNotFoundException("Schema with name " + schemaName + " not found");
}
WebTarget target = currentSchemaRegistryTargets().schemasTarget.path(schemaName).path("/versions").queryParam("branch", schemaBranchName);
Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {
@Override
public Response run() {
return target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(schemaVersion), Response.class);
}
});
return handleSchemaIdVersionResponse(schemaMetadataInfo, response);
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException in project registry by hortonworks.
the class SchemaRegistryClient method getSchemaBranches.
@Override
public Collection<SchemaBranch> getSchemaBranches(String schemaName) throws SchemaNotFoundException {
WebTarget target = currentSchemaRegistryTargets().schemasTarget.path(encode(schemaName) + "/branches");
Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {
@Override
public Response run() {
return target.request().get();
}
});
int status = response.getStatus();
if (status == Response.Status.NOT_FOUND.getStatusCode()) {
throw new SchemaNotFoundException(response.readEntity(String.class));
} else if (status != Response.Status.OK.getStatusCode()) {
throw new RuntimeException(response.readEntity(String.class));
}
return parseResponseAsEntities(response.readEntity(String.class), SchemaBranch.class);
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException in project registry by hortonworks.
the class SchemaRegistryClient method uploadSchemaVersion.
public SchemaIdVersion uploadSchemaVersion(final String schemaBranchName, final String schemaName, final String description, final InputStream schemaVersionInputStream) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException {
SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaName);
if (schemaMetadataInfo == null) {
throw new SchemaNotFoundException("Schema with name " + schemaName + " not found");
}
StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart("file", schemaVersionInputStream);
WebTarget target = currentSchemaRegistryTargets().schemasTarget.path(schemaName).path("/versions/upload").queryParam("branch", schemaBranchName);
MultiPart multipartEntity = new FormDataMultiPart().field("description", description, MediaType.APPLICATION_JSON_TYPE).bodyPart(streamDataBodyPart);
Entity<MultiPart> multiPartEntity = Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA);
Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {
@Override
public Response run() {
return target.request().post(multiPartEntity, Response.class);
}
});
return handleSchemaIdVersionResponse(schemaMetadataInfo, response);
}
Aggregations