@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)); } }
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; }
private static void checkCompatibility(SchemaVersionService schemaVersionService, SchemaMetadata schemaMetadata, String toSchemaText, String fromSchemaText) throws IncompatibleSchemaException { CompatibilityResult compatibilityResult = schemaVersionService.checkForCompatibility(schemaMetadata, toSchemaText, fromSchemaText); if (!compatibilityResult.isCompatible()) { String errMsg = String.format("Given schema is not compatible with latest schema versions. \n" + "Error location: [%s] \n" + "Error encountered is: [%s]", compatibilityResult.getErrorLocation(), compatibilityResult.getErrorMessage()); throw new IncompatibleSchemaException(errMsg); } }
private static void checkCompatibility(SchemaVersionService schemaVersionService, SchemaMetadata schemaMetadata, String toSchemaText, String fromSchemaText) throws IncompatibleSchemaException { CompatibilityResult compatibilityResult = schemaVersionService.checkForCompatibility(schemaMetadata, toSchemaText, fromSchemaText); if (!compatibilityResult.isCompatible()) { String errMsg = String.format("Given schema is not compatible with latest schema versions. \n" + "Error location: [%s] \n" + "Error encountered is: [%s]", compatibilityResult.getErrorLocation(), compatibilityResult.getErrorMessage()); throw new IncompatibleSchemaException(errMsg); } }
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()); }
compatibilityResult.getErrorMessage()); LOG.error(errMsg); throw new IncompatibleSchemaException(errMsg);