-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add Schema Registry Client SDK #10660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
29f7f6c
init
arerlend ba86f02
Merge remote-tracking branch 'upstream/master'
arerlend 4e94edf
remove kafka
arerlend 54d5ad8
azure- artifact ids
arerlend 98ce87d
azure-core + version change
arerlend 21b663d
progress snapshot before swapping autorest client
arerlend be646ab
swagger generated http client
arerlend 8fa8f89
update common package
arerlend 305ffa5
junit engine
arerlend 7eb5a2f
fix versioning
arerlend e13f670
javadoc checkstyle
arerlend 59c1c07
javadoc checkstyle
arerlend 492a77e
checkstyle javadoc
arerlend 07fcff1
spotbugs override for serializing null value
arerlend 16ec23e
add service client annotation
arerlend a6b56a8
service client style
arerlend 309b0bb
fix dep management tags
arerlend 51db740
add module-info and initial readme
arerlend 7492f73
add readme sections
arerlend c1ac6c6
fix readme section case
arerlend 47dba95
add src clients to jacoco
arerlend 198a030
add latest swagger
arerlend 24381c0
add basic readme intros
arerlend f2a69b4
Merge branch 'master' into arerlend.src
arerlend 09d2745
Update sdk/schemaregistry/azure-schemaregistry-client/src/main/java/c…
arerlend 866fe7f
fix comments
arerlend abc131d
Merge branch 'arerlend.src' of https://github.com/arerlend/azure-sdk-…
arerlend d4e5340
Update sdk/schemaregistry/azure-schemaregistry-client/src/main/java/c…
arerlend f0a35a9
default retry policy on null
arerlend 6199719
Merge branch 'arerlend.src' of https://github.com/arerlend/azure-sdk-…
arerlend 2a216c3
remove unused headers policy
arerlend d25047f
netty dep
arerlend 9cd191e
hashmap to concurrent hashmap, slf4j format pattern
arerlend 59d8f9d
builder cleanup
arerlend a04c383
remove runtime error from method signature
arerlend 1656da9
comments
arerlend 81682bc
change group name
arerlend b855cd0
move rest service builder
arerlend 850201a
update dirs and repo files
arerlend 6b1ee4e
update package structure
arerlend d6e0941
update versioning
arerlend c1f7199
fix jacoco test pom
arerlend 93defa9
fix eng system comments
arerlend cea60ee
Update sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml
arerlend 6ffe759
Update sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/jav…
arerlend e5c40b1
fix comments
arerlend 101aeeb
spotbugs update
arerlend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
sdk/schemaregistry/azure-data-schemaregistry-avro/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Azure Schema Registry Avro Serializer/Deserializer client library for Java | ||
|
|
||
| This library contains Avro-specific implementations of Azure Schema Registry-back serializers and deserializers, in addition to builder classes that specify required configurations. | ||
|
|
||
| This class requires a Maven dependency on `org.apache.avro:avro:1.9.2`. | ||
|
|
||
| ## Getting started | ||
|
|
||
| ## Key concepts | ||
|
|
||
| ## Examples | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ## Next steps | ||
|
|
||
| ## Contributing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- | ||
| ~ Copyright (c) Microsoft Corporation. All rights reserved. | ||
| ~ Licensed under the MIT License. | ||
| --> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>com.azure</groupId> | ||
| <artifactId>azure-client-sdk-parent</artifactId> | ||
| <version>1.7.0</version> <!-- {x-version-update;com.azure:azure-client-sdk-parent;current} --> | ||
| <relativePath>../../parents/azure-client-sdk-parent</relativePath> | ||
| </parent> | ||
|
|
||
| <groupId>com.azure</groupId> | ||
| <artifactId>azure-data-schemaregistry-avro</artifactId> | ||
| <version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-data-schemaregistry-avro;current} --> | ||
|
|
||
| <name>Microsoft Azure Schema Registry - Avro-specific package for client library</name> | ||
| <description>Avro-specific package for Azure Schema Registry client library</description> | ||
| <url>https://github.com/Azure/azure-sdk-for-java</url> | ||
|
|
||
| <distributionManagement> | ||
| <site> | ||
| <id>azure-java-build-docs</id> | ||
| <url>${site.url}/site/${project.artifactId}</url> | ||
| </site> | ||
| </distributionManagement> | ||
|
|
||
| <scm> | ||
| <url>scm:git:https://github.com/Azure/azure-sdk-for-java</url> | ||
| <connection>scm:git:git@github.com:Azure/azure-sdk-for-java.git</connection> | ||
| <tag>HEAD</tag> | ||
| </scm> | ||
|
|
||
| <properties> | ||
| <!-- SchemaRegistrySkip temporarily relaxing code coverage --> | ||
| <jacoco.skip.coverage.check>true</jacoco.skip.coverage.check> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.azure</groupId> | ||
| <artifactId>azure-data-schemaregistry</artifactId> | ||
| <version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-data-schemaregistry;dependency} --> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.avro</groupId> | ||
| <artifactId>avro</artifactId> | ||
| <version>1.9.2</version> <!-- {x-version-update;org.apache.avro:avro;external_dependency} --> | ||
| </dependency> | ||
|
|
||
| <!-- Test dependencies --> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
| <version>5.6.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} --> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-engine</artifactId> | ||
| <version>5.6.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} --> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-params</artifactId> | ||
| <version>5.6.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-params;external_dependency} --> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
arerlend marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-enforcer-plugin</artifactId> | ||
| <version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-enforcer-plugin;external_dependency} --> | ||
| <configuration> | ||
| <rules> | ||
| <bannedDependencies> | ||
| <includes> | ||
| <include>com.azure:*</include> | ||
| <include>org.apache.avro:avro:[1.9.2]</include> <!-- {x-include-update;org.apache.avro:avro;external_dependency} --> | ||
| </includes> | ||
| </bannedDependencies> | ||
| </rules> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
86 changes: 86 additions & 0 deletions
86
...schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.data.schemaregistry.avro; | ||
|
|
||
| import com.azure.core.util.logging.ClientLogger; | ||
| import com.azure.data.schemaregistry.ByteDecoder; | ||
| import com.azure.data.schemaregistry.SerializationException; | ||
| import org.apache.avro.Schema; | ||
| import org.apache.avro.generic.GenericDatumReader; | ||
| import org.apache.avro.io.DatumReader; | ||
| import org.apache.avro.io.DecoderFactory; | ||
| import org.apache.avro.specific.SpecificDatumReader; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Apache Avro ByteDecoder implementation with all Avro-specific functionality required to deserialize byte arrays | ||
| * given an Avro schema. | ||
| */ | ||
| public class AvroByteDecoder extends AvroCodec | ||
arerlend marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| implements ByteDecoder { | ||
| private final ClientLogger logger = new ClientLogger(AvroByteDecoder.class); | ||
| private static final DecoderFactory DECODER_FACTORY = DecoderFactory.get(); | ||
| private final boolean avroSpecificReader; | ||
|
|
||
| /** | ||
| * Instantiates AvroByteDecoder instance | ||
| * @param avroSpecificReader flag indicating if attempting to decode as Avro SpecificRecord | ||
| */ | ||
| public AvroByteDecoder(boolean avroSpecificReader) { | ||
| this.avroSpecificReader = avroSpecificReader; | ||
| } | ||
|
|
||
| /** | ||
| * @param b byte array containing encoded bytes | ||
| * @param object schema for Avro reader read - fetched from Azure Schema Registry | ||
| * @return deserialized object | ||
| * @throws SerializationException upon deserialization failure | ||
| */ | ||
| public Object decodeBytes(byte[] b, Object object) { | ||
| Objects.requireNonNull(object, "Schema must not be null."); | ||
|
|
||
| if (!(object instanceof Schema)) { | ||
arerlend marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw logger.logExceptionAsError( | ||
| new SerializationException("Object must be an Avro schema.")); | ||
| } | ||
| Schema schema = (Schema) object; | ||
|
|
||
| if (schema.getType().equals(Schema.Type.BYTES)) { | ||
| return b; | ||
| } | ||
arerlend marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| DatumReader<?> reader = getDatumReader(schema); | ||
|
|
||
| try { | ||
| Object result = reader.read(null, DECODER_FACTORY.binaryDecoder(b, null)); | ||
|
|
||
| if (schema.getType().equals(Schema.Type.STRING)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also conditionally check |
||
| return result.toString(); | ||
| } | ||
|
|
||
| return result; | ||
| } catch (IOException | RuntimeException e) { | ||
| // avro deserialization may throw AvroRuntimeException, NullPointerException, etc | ||
| throw logger.logExceptionAsError(new SerializationException("Error deserializing Avro message.", e)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns correct reader for decoding payload. | ||
| * | ||
| * @param writerSchema Avro schema fetched from schema registry store | ||
| * @return correct Avro DatumReader object given encoder configuration | ||
| */ | ||
| private DatumReader<?> getDatumReader(Schema writerSchema) { | ||
| boolean writerSchemaIsPrimitive = AvroSchemaUtils.getPrimitiveSchemas().values().contains(writerSchema); | ||
| // do not use SpecificDatumReader if writerSchema is a primitive | ||
| if (avroSpecificReader && !writerSchemaIsPrimitive) { | ||
| return new SpecificDatumReader<>(writerSchema); | ||
| } else { | ||
| return new GenericDatumReader<>(writerSchema); | ||
| } | ||
| } | ||
| } | ||
82 changes: 82 additions & 0 deletions
82
...schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.data.schemaregistry.avro; | ||
|
|
||
| import com.azure.core.util.logging.ClientLogger; | ||
| import com.azure.data.schemaregistry.ByteEncoder; | ||
| import com.azure.data.schemaregistry.SerializationException; | ||
| import org.apache.avro.Schema; | ||
| import org.apache.avro.generic.GenericDatumWriter; | ||
| import org.apache.avro.io.BinaryEncoder; | ||
| import org.apache.avro.io.DatumWriter; | ||
| import org.apache.avro.io.EncoderFactory; | ||
| import org.apache.avro.specific.SpecificDatumWriter; | ||
| import org.apache.avro.specific.SpecificRecord; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * ByteEncoder implementation with all Avro-specific functionality required to serialize Java objects into byte arrays. | ||
| */ | ||
| public class AvroByteEncoder extends AvroCodec | ||
| implements ByteEncoder { | ||
| private final ClientLogger logger = new ClientLogger(AvroByteEncoder.class); | ||
| private static final EncoderFactory ENCODER_FACTORY = EncoderFactory.get(); | ||
|
|
||
| /** | ||
| * @param object Schema object used to generate schema string | ||
| * @see AvroSchemaUtils for distinction between primitive and Avro schema generation | ||
| * @return string representation of schema | ||
| */ | ||
| @Override | ||
| public String getSchemaString(Object object) { | ||
| Schema schema = AvroSchemaUtils.getSchema(object); | ||
| return schema.toString(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns schema name for storing schemas in schema registry store. | ||
| * | ||
| * @param object Schema object used to generate schema path | ||
| * @return schema name as string | ||
| */ | ||
| @Override | ||
| public String getSchemaName(Object object) { | ||
| return AvroSchemaUtils.getSchema(object).getFullName(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns ByteArrayOutputStream containing Avro encoding of object parameter | ||
| * @param object Object to be encoded into byte stream | ||
| * @return closed ByteArrayOutputStream | ||
| * @throws SerializationException wraps runtime exceptions | ||
| */ | ||
| @Override | ||
| public ByteArrayOutputStream encode(Object object) { | ||
| Schema schema = AvroSchemaUtils.getSchema(object); | ||
|
|
||
| try { | ||
| ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
| if (object instanceof byte[]) { | ||
| out.write((byte[]) object); // todo: real avro byte arrays require writing array size to buffer | ||
| } else { | ||
| BinaryEncoder encoder = ENCODER_FACTORY.directBinaryEncoder(out, null); | ||
| DatumWriter<Object> writer; | ||
| if (object instanceof SpecificRecord) { | ||
| writer = new SpecificDatumWriter<>(schema); | ||
| } else { | ||
| writer = new GenericDatumWriter<>(schema); | ||
| } | ||
| writer.write(object, encoder); | ||
| encoder.flush(); | ||
| } | ||
| return out; | ||
| } catch (IOException | RuntimeException e) { | ||
| // Avro serialization can throw AvroRuntimeException, NullPointerException, ClassCastException, etc | ||
| throw logger.logExceptionAsError( | ||
| new SerializationException("Error serializing Avro message", e)); | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.data.schemaregistry.avro; | ||
|
|
||
| import com.azure.data.schemaregistry.Codec; | ||
| import org.apache.avro.Schema; | ||
|
|
||
| /** | ||
| * Base Codec class for Avro encoder and decoder implementations | ||
| */ | ||
| abstract class AvroCodec implements Codec { | ||
| @Override | ||
| public String schemaType() { | ||
arerlend marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return "avro"; | ||
| } | ||
|
|
||
| /** | ||
| * @param schemaString string representation of schema | ||
| * @return avro schema | ||
| */ | ||
| @Override | ||
| public Schema parseSchemaString(String schemaString) { | ||
| return (new Schema.Parser()).parse(schemaString); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.