SchemaVersion schemaVersion = null; try { schemaVersion = new SchemaVersion(IOUtils.toString(inputStream, "UTF-8"), description); response = addSchemaVersion(schemaBranchName, schemaName, schemaVersion, uriInfo);
@Override public SchemaIdVersion addSchemaVersion(String schemaName, SchemaVersion schemaVersion) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException { try { return schemaRegistry.addSchemaVersion(schemaName, new SchemaVersion(schemaVersion.getSchemaText(), schemaVersion.getDescription())); } catch (UnsupportedSchemaTypeException e) { throw new RuntimeException(e); } }
@Override public SchemaIdVersion addSchemaVersion(SchemaMetadata schemaMetadata, SchemaVersion schemaVersion) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException { try { return schemaRegistry.addSchemaVersion(schemaMetadata, new SchemaVersion(schemaVersion.getSchemaText(), schemaMetadata.getDescription())); } catch (UnsupportedSchemaTypeException e) { throw new RuntimeException(e); } }
final String fingerprint = getFingerprint(type, schemaVersion.getSchemaText()); final String schemaName = schemaMetadata.getName(); schemaVersionStorable.setSchemaText(schemaVersion.getSchemaText()); schemaVersionStorable.setDescription(schemaVersion.getDescription()); schemaVersionStorable.setTimestamp(System.currentTimeMillis()); schemaVersion.setState(SchemaVersionLifecycleStates.INITIATED.getId()); schemaVersion.setStateDetails(null); Byte initialState = schemaVersion.getInitialState(); if (schemaMetadata.isEvolve()) { SchemaVersionLifecycleStates.INITIATED.getId().equals(initialState)) { CompatibilityResult compatibilityResult = checkCompatibility(schemaBranchName, schemaName, schemaVersion .getSchemaText()); if (!compatibilityResult.isCompatible()) { String errMsg = String.format("Given schema is not compatible with latest schema versions. \n" + updateSchemaVersionState(schemaVersionStorable.getId(), 1, initialState, schemaVersion.getStateDetails());
private SchemaDigestEntry buildSchemaTextEntry(SchemaVersion schemaVersion, String name) { byte[] digest; try { digest = MessageDigest.getInstance("MD5").digest(schemaVersion.getSchemaText().getBytes("UTF-8")); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } // storing schema text string is expensive, so storing digest in cache's key. return new SchemaDigestEntry(name, digest); }
public SchemaIdVersion addSchemaVersion(String schemaBranchName, String schemaName, SchemaVersion schemaVersion) throws SchemaNotFoundException, IncompatibleSchemaException, InvalidSchemaException, SchemaBranchNotFoundException { Preconditions.checkNotNull(schemaBranchName, "Schema branch name can't be null"); Preconditions.checkNotNull(schemaName, "schemaName can't be null"); Preconditions.checkNotNull(schemaVersion, "schemaVersion can't be null"); checkSchemaText(schemaVersion.getSchemaText()); // check whether there exists schema-metadata for schema-metadata-key SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaName); if (schemaMetadataInfo != null) { return addSchemaVersion(schemaBranchName, schemaMetadataInfo, schemaVersion); } else { throw new SchemaNotFoundException("SchemaMetadata not found with the schemaName: " + schemaName); } }
SchemaVersion schemaVersion = null; try { schemaVersion = new SchemaVersion(IOUtils.toString(inputStream, "UTF-8"), description); response = addSchemaVersion(schemaBranchName, schemaName, schemaVersion, uriInfo);
LOG.info("Registered schemaMetadataId [{}] for schema with name:[{}]", schemaMetadataId, schemaName); String streamsSchemaText = streamsSchemaInfo.getSchemaVersion().getSchemaText(); try { SchemaVersion avroSchemaVersion = new SchemaVersion(avroSchemaText, streamsSchemaInfo.getSchemaVersion().getDescription()); schemaIdVersion = schemaRegistryClient.addSchemaVersion(schemaName, avroSchemaVersion); } catch (InvalidSchemaException e) {
Preconditions.checkNotNull(schemaVersion, "schemaVersion can't be null"); checkSchemaText(schemaVersion.getSchemaText()); schemaMetadataId = retrievedschemaMetadataInfo.getId(); schemaVersionInfo = getSchemaVersionInfo(schemaName, schemaVersion.getSchemaText()); if (schemaVersionInfo == null) { schemaVersionInfo = createSchemaVersion(schemaBranchName,
@Override public final O serialize(I input, SchemaMetadata schemaMetadata) throws SerDesException { ensureInitialized(); // compute schema based on input object String schema = getSchemaText(input); // register that schema and get the version try { SchemaIdVersion schemaIdVersion = schemaRegistryClient.addSchemaVersion(schemaMetadata, new SchemaVersion(schema, "Schema registered by serializer:" + this.getClass())); // write the version and given object to the output return doSerialize(input, schemaIdVersion); } catch (SchemaNotFoundException | IncompatibleSchemaException | InvalidSchemaException | SchemaBranchNotFoundException e) { throw new RegistryException(e); } }
public SchemaIdVersion addSchemaVersion(String schemaBranchName, SchemaMetadataInfo schemaMetadataInfo, SchemaVersion schemaVersion) throws SchemaNotFoundException, IncompatibleSchemaException, InvalidSchemaException, SchemaBranchNotFoundException { Preconditions.checkNotNull(schemaBranchName, "Schema branch name can't be null"); checkSchemaText(schemaVersion.getSchemaText()); SchemaVersionInfo schemaVersionInfo; // check whether there exists schema-metadata for schema-metadata-key SchemaMetadata schemaMetadata = schemaMetadataInfo.getSchemaMetadata(); // check whether the same schema text exists schemaVersionInfo = findSchemaVersion(schemaBranchName, schemaMetadata.getType(), schemaVersion.getSchemaText(), schemaMetadataInfo .getSchemaMetadata().getName()); if (schemaVersionInfo == null) { schemaVersionInfo = createSchemaVersion(schemaBranchName, schemaMetadata, schemaMetadataInfo.getId(), schemaVersion); } return new SchemaIdVersion(schemaMetadataInfo.getId(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId()); }
public void runCustomSerDesApi() throws Exception { // upload jar file String serdesJarName = "/serdes-examples.jar"; InputStream serdesJarInputStream = SampleSchemaRegistryClientApp.class.getResourceAsStream(serdesJarName); if (serdesJarInputStream == null) { throw new RuntimeException("Jar " + serdesJarName + " could not be loaded"); } String fileId = schemaRegistryClient.uploadFile(serdesJarInputStream); SchemaMetadata schemaMetadata = createSchemaMetadata("serdes-device-" + System.currentTimeMillis()); SchemaIdVersion v1 = schemaRegistryClient.addSchemaVersion(schemaMetadata, new SchemaVersion(getSchema("/device.avsc"), "Initial version of the schema")); // register serializer/deserializer Long serDesId = registerSimpleSerDes(fileId); // map serializer and deserializer with schemakey // for each schema, one serializer/deserializer is sufficient unless someone want to maintain multiple implementations of serializers/deserializers String schemaName = schemaMetadata.getName(); schemaRegistryClient.mapSchemaWithSerDes(schemaName, serDesId); SnapshotSerializer<Object, byte[], SchemaMetadata> snapshotSerializer = getSnapshotSerializer(schemaMetadata); String payload = "Random text: " + new Random().nextLong(); byte[] serializedBytes = snapshotSerializer.serialize(payload, schemaMetadata); SnapshotDeserializer<byte[], Object, Integer> snapshotdeserializer = getSnapshotDeserializer(schemaMetadata); Object deserializedObject = snapshotdeserializer.deserialize(serializedBytes, null); LOG.info("Given payload and deserialized object are equal: " + payload.equals(deserializedObject)); }
private SchemaIdVersion addSchemaVersion(String schemaBranchName, SchemaMetadata schemaMetadata, String pathToSchema) throws IOException, SchemaNotFoundException, InvalidSchemaException, IncompatibleSchemaException { String schema = AvroSchemaRegistryClientUtil.getSchema(pathToSchema); SchemaIdVersion schemaIdVersion = schemaRegistryClient.addSchemaVersion(schemaBranchName, schemaMetadata, new SchemaVersion(schema, "schema version description")); return schemaIdVersion; }
@Test(expected = SchemaNotFoundException.class) public void testAddVersionToNonExistingSchema() throws SchemaNotFoundException, IncompatibleSchemaException, InvalidSchemaException, SchemaBranchNotFoundException { schemaRegistry.addSchemaVersion(INVALID_SCHEMA_METADATA_KEY, new SchemaVersion("foo", "dummy")); }
SchemaIdVersion v1 = schemaRegistryClient.addSchemaVersion(schemaMetadata, new SchemaVersion(schema1, "Initial version of the schema")); LOG.info("Registered schema [{}] and returned version [{}]", schema1, v1); SchemaVersion schemaInfo2 = new SchemaVersion(schema2, "second version"); SchemaIdVersion v2 = schemaRegistryClient.addSchemaVersion(schemaMetadata, schemaInfo2); LOG.info("Registered schema [{}] and returned version [{}]", schema2, v2);
new SchemaVersion(schemaStringFromJson(schema).getSchema(), null));
new SchemaVersion(schemaStringFromJson(schema).getSchema(), null));
@Test(expected = IncompatibleSchemaException.class) public void testIncompatibleSchemas() throws Exception { String schema = AvroSchemaRegistryClientUtil.getSchema("/device.avsc"); String incompatSchema = AvroSchemaRegistryClientUtil.getSchema("/device-incompat.avsc"); SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD); // registering a new schema SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(schema, "Initial version of the schema")); // adding a new version of the schema SchemaVersion incompatSchemaInfo = new SchemaVersion(incompatSchema, "second version"); SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, incompatSchemaInfo); }
@Test(expected = InvalidSchemaException.class) public void testInvalidSchema() throws Exception { String schema = "--- random invalid schema ---" + new Date(); SchemaMetadata schemaMetadataInfo = createSchemaInfo(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD); // registering a new schema Integer v1 = schemaRegistry.addSchemaVersion(schemaMetadataInfo, new SchemaVersion(schema, "Initial version of the schema")) .getVersion(); }
@Test(expected = InvalidSchemaException.class) public void testInvalidSchema() throws Exception { String schema = "--- invalid schema ---"; SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD); SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(schema, "Initial version of the schema")); }