final String schemaText = versionInfo.getSchemaText();
final String schemaText = versionInfo.getSchemaText();
private String getResultantSchema(SchemaVersionKey schemaVersionKey, Map<String, SchemaParsingState> schemaParsingStates) throws InvalidSchemaException, SchemaNotFoundException { String schemaText = schemaVersionRetriever.retrieveSchemaVersion(schemaVersionKey).getSchemaText(); return getResultantSchema(schemaText, schemaParsingStates); }
private String getResultantSchema(SchemaVersionKey schemaVersionKey, Map<String, SchemaParsingState> schemaParsingStates) throws InvalidSchemaException, SchemaNotFoundException { String schemaText = schemaVersionRetriever.retrieveSchemaVersion(schemaVersionKey).getSchemaText(); return getResultantSchema(schemaText, schemaParsingStates); }
@GET @Path("/{schemaName}/versions/{version}") @Timed @Produces(MediaType.APPLICATION_JSON) public Response getSchemaForVersion(@PathParam("schemaName") String schemaName, @PathParam("version") String version, @Context SecurityContext securityContext) { try { LOG.info("Get schema:version [{}:{}]", schemaName, version); SchemaVersionInfo schemaVersionInfo = schemaRegistryClient.getSchemaVersionInfo(new SchemaVersionKey(schemaName, Integer.parseInt(version))); if (schemaVersionInfo != null) { LOG.debug("Received schema version from schema registry: [{}]", schemaVersionInfo); String schema = schemaVersionInfo.getSchemaText(); if (schema != null && !schema.isEmpty()) { schema = AvroStreamlineSchemaConverter.convertAvroSchemaToStreamlineSchema(schema); } LOG.debug("Converted schema: [{}]", schema); return WSUtils.respondEntity(schema, OK); } else { throw new SchemaNotFoundException("Version " + version + " of schema " + schemaName + " not found "); } } catch (SchemaNotFoundException e) { LOG.error("Schema not found: [{}]", schemaName, e); throw EntityNotFoundException.byName(schemaName); } catch (Exception e) { throw new RuntimeException(e); } }
@GET @Path("/schemas/ids/{id}") @ApiOperation(value = "Get schema version by id", response = Schema.class, tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response getSchemaById(@ApiParam(value = "schema version id", required = true) @PathParam("id") Long id) { Response response; try { SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(new SchemaIdVersion(id)); SchemaString schema = new SchemaString(); schema.setSchema(schemaVersionInfo.getSchemaText()); response = WSUtils.respondEntity(schema, Response.Status.OK); } catch (SchemaNotFoundException ex) { LOG.error("No schema version found with id [{}]", id, ex); response = schemaNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving Schema with id: [{}]", id, ex); response = serverError(); } return response; }
@GET @Path("/schemas/ids/{id}") @ApiOperation(value = "Get schema version by id", response = Schema.class, tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response getSchemaById(@ApiParam(value = "schema version id", required = true) @PathParam("id") Long id) { Response response; try { SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(new SchemaIdVersion(id)); SchemaString schema = new SchemaString(); schema.setSchema(schemaVersionInfo.getSchemaText()); response = WSUtils.respondEntity(schema, Response.Status.OK); } catch (SchemaNotFoundException ex) { LOG.error("No schema version found with id [{}]", id, ex); response = schemaNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving Schema with id: [{}]", id, ex); response = serverError(); } return response; }
@POST @Path("/subjects/{subject}") @ApiOperation(value = "Get schema information for the given schema subject and schema text", response = Schema.class, tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response lookupSubjectVersion(@ApiParam(value = "Schema subject", required = true) @PathParam("subject") String subject, @ApiParam(value = "The schema ", required = true) String schema) { Response response; try { SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(subject, schemaStringFromJson(schema).getSchema()); if (schemaVersionInfo != null) { response = WSUtils.respondEntity(new Schema(schemaVersionInfo.getName(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText()), Response.Status.OK); } else { response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, subject); } } catch (InvalidSchemaException ex) { LOG.error("Given schema is invalid", ex); response = invalidSchemaError(); } catch (SchemaNotFoundException ex) { LOG.error("No schema found with subject [{}]", subject, ex); response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving schema version with subject: [{}]", subject, ex); response = serverError(); } return response; }
@POST @Path("/subjects/{subject}") @ApiOperation(value = "Get schema information for the given schema subject and schema text", response = Schema.class, tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response lookupSubjectVersion(@ApiParam(value = "Schema subject", required = true) @PathParam("subject") String subject, @ApiParam(value = "The schema ", required = true) String schema) { Response response; try { SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(subject, schemaStringFromJson(schema).getSchema()); if (schemaVersionInfo != null) { response = WSUtils.respondEntity(new Schema(schemaVersionInfo.getName(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText()), Response.Status.OK); } else { response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, subject); } } catch (InvalidSchemaException ex) { LOG.error("Given schema is invalid", ex); response = invalidSchemaError(); } catch (SchemaNotFoundException ex) { LOG.error("No schema found with subject [{}]", subject, ex); response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving schema version with subject: [{}]", subject, ex); response = serverError(); } return response; }
String schemaText = schemaVersionInfo.getSchemaText(); List<SchemaVersionInfo> allEnabledSchemaVersions = schemaVersionService.getAllSchemaVersions(SchemaBranch.MASTER_BRANCH, schemaName) schemaMetadata, schemaText, curSchemaVersionInfo.getSchemaText()); } else { checkCompatibility(schemaVersionService, schemaMetadata, curSchemaVersionInfo.getSchemaText(), schemaText); int size = sortedSchemaVersionInfos.size(); for (; i < size && sortedSchemaVersionInfos.get(i).getVersion() < schemaVersion; i++) { String fromSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText(); checkCompatibility(schemaVersionService, schemaMetadata, schemaText, fromSchemaText); String toSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText(); checkCompatibility(schemaVersionService, schemaMetadata, toSchemaText, schemaText);
String schemaText = schemaVersionInfo.getSchemaText(); List<SchemaVersionInfo> allEnabledSchemaVersions = schemaVersionService.getAllSchemaVersions(SchemaBranch.MASTER_BRANCH, schemaName) schemaMetadata, schemaText, curSchemaVersionInfo.getSchemaText()); } else { checkCompatibility(schemaVersionService, schemaMetadata, curSchemaVersionInfo.getSchemaText(), schemaText); int size = sortedSchemaVersionInfos.size(); for (; i < size && sortedSchemaVersionInfos.get(i).getVersion() < schemaVersion; i++) { String fromSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText(); checkCompatibility(schemaVersionService, schemaMetadata, schemaText, fromSchemaText); String toSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText(); checkCompatibility(schemaVersionService, schemaMetadata, toSchemaText, schemaText);
schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText()); response = WSUtils.respondEntity(schema, Response.Status.OK);
schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText()); response = WSUtils.respondEntity(schema, Response.Status.OK);
@Override public byte[] serialize(String topic, StreamlineEvent streamlineEvent) { SchemaMetadata schemaMetadata = getSchemaKey(topic, false); SchemaVersionInfo schemaVersionInfo; try { schemaMetadata = schemaRegistryClient.getSchemaMetadataInfo(schemaMetadata.getName()).getSchemaMetadata(); if (writerSchemaVersion != null) { schemaVersionInfo = schemaRegistryClient.getSchemaVersionInfo(new SchemaVersionKey(schemaMetadata.getName(), writerSchemaVersion)); } else { schemaVersionInfo = schemaRegistryClient.getLatestSchemaVersionInfo(schemaMetadata.getName()); } } catch (SchemaNotFoundException e) { LOG.error("Exception occured while getting SchemaVersionInfo for " + schemaMetadata, e); throw new RuntimeException(e); } if (streamlineEvent == null || streamlineEvent.isEmpty()) { return null; } else { return avroSnapshotSerializer.serialize(getAvroRecord(streamlineEvent, new Schema.Parser().parse(schemaVersionInfo.getSchemaText())), schemaMetadata); } }
schemaMetadataInfo.getSchemaMetadata() .getType(), schemaVersionInfo.getSchemaText(), schemaMetadataInfo.getSchemaMetadata() .getName()); schemaMetadataInfo.getSchemaMetadata(), schemaMetadataInfo.getId(), new SchemaVersion(schemaVersionInfo.getSchemaText(), schemaVersionInfo.getDescription(), SchemaVersionLifecycleStates.INITIATED.getId(),
compatibilityResult = checkCompatibility(schemaMetadata.getType(), toSchema, latestSchemaVersionInfo.getSchemaText(), schemaMetadata.getCompatibility()); if (!compatibilityResult.isCompatible()) { compatibilityResult = checkCompatibility(schemaMetadata.getType(), toSchema, schemaVersionInfo.getSchemaText(), schemaMetadata.getCompatibility()); if (!compatibilityResult.isCompatible()) {
Assert.assertEquals(schemaVersionInfo1.getSchemaText(), schema1); Assert.assertEquals(schemaVersionInfo2.getSchemaText(), schema2);
@Test public void testHASanity() throws Exception { SchemaRegistryTestServerClientWrapper followerServer = followerSchemaRegistryServer(); SchemaRegistryClient schemaRegistryClient = followerServer.getClient(); // registering schema metadata on follower, this should have been redirected to leader. String schemaName = "foo"; SchemaMetadata schemaMetadata = new SchemaMetadata.Builder(schemaName).type("avro").build(); Long schemaId = schemaRegistryClient.registerSchemaMetadata(schemaMetadata); Assert.assertNotNull(schemaId); // registering a new schema on follower, this should have been redirected to leader. String schema1 = IOUtils.toString(LocalRegistryServerTest.class.getResourceAsStream("/schema-1.avsc"), "UTF-8"); SchemaIdVersion v1 = schemaRegistryClient.addSchemaVersion(schemaName, new SchemaVersion(schema1, "Initial version of the schema")); // retrieve schema on leader as the schema data is stored in memory in leader. this data does not exist on // followers as the storage is inmemory. SchemaRegistryTestServerClientWrapper leaderServer = leaderSchemaRegistryServer(); int leaderPort = leaderServer.getLocalPort(); SchemaRegistryClient leaderClient = leaderServer.getClient(); SchemaMetadataInfo schemaMetadataInfo = leaderClient.getSchemaMetadataInfo(schemaName); Assert.assertEquals(schemaMetadata, schemaMetadataInfo.getSchemaMetadata()); // stop the leader server leaderServer.stopTestServer(); // get the new leader server and run operations. SchemaRegistryTestServerClientWrapper newLeaderServer = leaderSchemaRegistryServer(); Assert.assertNotEquals(leaderPort, newLeaderServer.getLocalPort()); leaderClient = newLeaderServer.getClient(); String receivedSchema = leaderClient.getSchemaVersionInfo(new SchemaVersionKey(schemaName, v1.getVersion())).getSchemaText(); Assert.assertEquals(schema1, receivedSchema); }