Search in sources :

Example 1 with CatalogResponse

use of com.hortonworks.registries.common.catalog.CatalogResponse in project registry by hortonworks.

the class SchemaRegistryClient method handleSchemaIdVersionResponse.

private SchemaIdVersion handleSchemaIdVersionResponse(SchemaMetadataInfo schemaMetadataInfo, Response response) throws IncompatibleSchemaException, InvalidSchemaException {
    int status = response.getStatus();
    String msg = response.readEntity(String.class);
    if (status == Response.Status.BAD_REQUEST.getStatusCode() || status == Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) {
        CatalogResponse catalogResponse = readCatalogResponse(msg);
        if (CatalogResponse.ResponseMessage.INCOMPATIBLE_SCHEMA.getCode() == catalogResponse.getResponseCode()) {
            throw new IncompatibleSchemaException(catalogResponse.getResponseMessage());
        } else if (CatalogResponse.ResponseMessage.INVALID_SCHEMA.getCode() == catalogResponse.getResponseCode()) {
            throw new InvalidSchemaException(catalogResponse.getResponseMessage());
        } else {
            throw new RuntimeException(catalogResponse.getResponseMessage());
        }
    }
    Integer version = readEntity(msg, Integer.class);
    SchemaVersionInfo schemaVersionInfo = doGetSchemaVersionInfo(new SchemaVersionKey(schemaMetadataInfo.getSchemaMetadata().getName(), version));
    return new SchemaIdVersion(schemaMetadataInfo.getId(), version, schemaVersionInfo.getId());
}
Also used : IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey)

Example 2 with CatalogResponse

use of com.hortonworks.registries.common.catalog.CatalogResponse 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;
}
Also used : IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)

Aggregations

CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)2 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)2 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)1 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)1 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)1 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)1 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)1 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)1