From 29f7f6c0130463e16bb643a6b3f0e27375ebed50 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 30 Apr 2020 22:51:40 -0700 Subject: [PATCH 01/43] init --- sdk/schemaregistry/.gitignore | 49 +++ sdk/schemaregistry/client/pom.xml | 49 +++ .../client/CachedSchemaRegistryClient.java | 269 +++++++++++++ .../client/MockSchemaRegistryClient.java | 75 ++++ .../azure/schemaregistry/client/SRObject.java | 60 +++ .../client/SchemaRegistryClient.java | 96 +++++ .../client/SchemaRegistryClientException.java | 16 + .../client/rest/RestService.java | 376 ++++++++++++++++++ .../client/rest/entities/ErrorMessage.java | 43 ++ .../responses/RegisterSchemaResponse.java | 37 ++ .../responses/SchemaObjectResponse.java | 51 +++ .../rest/exceptions/RestClientException.java | 25 ++ .../CachedSchemaRegistryClientTest.java | 138 +++++++ .../client/RestServiceTest.java | 48 +++ sdk/schemaregistry/codec/codec-avro/pom.xml | 50 +++ .../schemaregistry/avro/AvroByteDecoder.java | 97 +++++ .../schemaregistry/avro/AvroByteEncoder.java | 90 +++++ .../azure/schemaregistry/avro/AvroCodec.java | 26 ++ .../schemaregistry/avro/AvroSchemaUtils.java | 65 +++ .../avro/AvroByteDecoderTest.java | 31 ++ .../avro/AvroByteEncoderTest.java | 38 ++ sdk/schemaregistry/codec/pom.xml | 40 ++ sdk/schemaregistry/pom.xml | 45 +++ sdk/schemaregistry/serde/common/pom.xml | 59 +++ .../AbstractDataDeserializer.java | 115 ++++++ .../schemaregistry/AbstractDataSerDe.java | 34 ++ .../AbstractDataSerializer.java | 129 ++++++ .../com/azure/schemaregistry/ByteDecoder.java | 17 + .../com/azure/schemaregistry/ByteEncoder.java | 38 ++ .../java/com/azure/schemaregistry/Codec.java | 26 ++ .../SerializationException.java | 19 + .../AbstractDataDeserializerTest.java | 120 ++++++ .../AbstractDataSerializerTest.java | 122 ++++++ .../schemaregistry/SampleByteDecoder.java | 29 ++ .../schemaregistry/SampleByteEncoder.java | 48 +++ .../schemaregistry/TestDummyDeserializer.java | 31 ++ .../schemaregistry/TestDummySerializer.java | 43 ++ sdk/schemaregistry/serde/generic-avro/pom.xml | 40 ++ .../avro/SchemaRegistryAvroDeserializer.java | 83 ++++ .../avro/SchemaRegistryAvroSerializer.java | 89 +++++ .../SchemaRegistryAvroDeserializerTest.java | 31 ++ .../SchemaRegistryAvroSerializerTest.java | 31 ++ sdk/schemaregistry/serde/kafka/pom.xml | 46 +++ .../serializers/AbstractKafkaSerdeConfig.java | 10 + .../serializers/KafkaAvroDeserializer.java | 79 ++++ .../KafkaAvroDeserializerConfig.java | 14 + .../serializers/KafkaAvroSerializer.java | 95 +++++ .../KafkaAvroSerializerConfig.java | 11 + .../KafkaAvroDeserializerTest.java | 43 ++ .../KafkaAvroSerializerTest.java | 39 ++ sdk/schemaregistry/serde/pom.xml | 42 ++ 51 files changed, 3297 insertions(+) create mode 100644 sdk/schemaregistry/.gitignore create mode 100644 sdk/schemaregistry/client/pom.xml create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SRObject.java create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java create mode 100644 sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java create mode 100644 sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java create mode 100644 sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java create mode 100644 sdk/schemaregistry/codec/codec-avro/pom.xml create mode 100644 sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java create mode 100644 sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java create mode 100644 sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java create mode 100644 sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java create mode 100644 sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java create mode 100644 sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java create mode 100644 sdk/schemaregistry/codec/pom.xml create mode 100644 sdk/schemaregistry/pom.xml create mode 100644 sdk/schemaregistry/serde/common/pom.xml create mode 100644 sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java create mode 100644 sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java create mode 100644 sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java create mode 100644 sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteDecoder.java create mode 100644 sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteEncoder.java create mode 100644 sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/Codec.java create mode 100644 sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/SerializationException.java create mode 100644 sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java create mode 100644 sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java create mode 100644 sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java create mode 100644 sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java create mode 100644 sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java create mode 100644 sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java create mode 100644 sdk/schemaregistry/serde/generic-avro/pom.xml create mode 100644 sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java create mode 100644 sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java create mode 100644 sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroDeserializerTest.java create mode 100644 sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroSerializerTest.java create mode 100644 sdk/schemaregistry/serde/kafka/pom.xml create mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/AbstractKafkaSerdeConfig.java create mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializer.java create mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializerConfig.java create mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializer.java create mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializerConfig.java create mode 100644 sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroDeserializerTest.java create mode 100644 sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroSerializerTest.java create mode 100644 sdk/schemaregistry/serde/pom.xml diff --git a/sdk/schemaregistry/.gitignore b/sdk/schemaregistry/.gitignore new file mode 100644 index 000000000000..4f6742eed8ef --- /dev/null +++ b/sdk/schemaregistry/.gitignore @@ -0,0 +1,49 @@ +# Compiled class file +*.class +*.classpath + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +.vscode/ +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +target/ +.project +.idea/ +.settings/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +*.iml +.DS_Store diff --git a/sdk/schemaregistry/client/pom.xml b/sdk/schemaregistry/client/pom.xml new file mode 100644 index 000000000000..82ebe3c33b92 --- /dev/null +++ b/sdk/schemaregistry/client/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + + + com.azure + schemaregistry-parent + 0.5-preview + + + schemaregistry-client + jar + 0.5-preview + schemaregistry-client + + + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + org.easymock + easymock + 4.1 + test + + + com.fasterxml.jackson.core + jackson-databind + 2.10.2 + + + org.slf4j + slf4j-api + + + diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java new file mode 100644 index 000000000000..34c5ab92610e --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -0,0 +1,269 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client; + +import com.azure.schemaregistry.client.rest.RestService; +import com.azure.schemaregistry.client.rest.entities.responses.SchemaObjectResponse; +import com.azure.schemaregistry.client.rest.exceptions.RestClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.function.Function; + +/** + * HTTP-based client that interacts with Azure Schema Registry service to store and retrieve schemas on demand. + * + * Utilizes in-memory HashMap caching to minimize network I/O. + * + * Max HashMap size can be configured when instantiating. + * Two maps are maintained - + * - SRObject cache by GUID - accessed when consuming, store GUIDs previously seen in payloads + * - SRObject cache by schema string - accessed when sending, minimizes HTTP calls when payloads of same schema + * + * TODO: implement max age for schema maps? or will schemas always be immutable? + * + * @see SchemaRegistryClient Implements SchemaRegistryClient interface to allow for testing with mock + * @see CachedSchemaRegistryClient.Builder Follows static builder pattern for object instantiation + */ +public class CachedSchemaRegistryClient implements SchemaRegistryClient { + private static final Logger log = LoggerFactory.getLogger(CachedSchemaRegistryClient.class); + + public static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; + public static final int MAX_SCHEMA_MAP_SIZE_MINIMUM = 10; + + private int maxSchemaMapSize; + private final RestService restService; + private final HashMap> typeParserDictionary; + + private HashMap> guidCache; + private HashMap> schemaStringCache; + + private CachedSchemaRegistryClient( + String registryUrl, + int maxSchemaMapSize, + HashMap> typeParserDictionary, + String credentials) + { + if (registryUrl == null || registryUrl.isEmpty()) { + throw new IllegalArgumentException("Schema Registry URL cannot be null or empty."); + } + + this.restService = new RestService(registryUrl, credentials); + this.maxSchemaMapSize = maxSchemaMapSize; + this.typeParserDictionary = typeParserDictionary; + this.guidCache = new HashMap<>(); + this.schemaStringCache = new HashMap<>(); + } + + // testing + CachedSchemaRegistryClient( + RestService restService, + HashMap> guidCache, + HashMap> schemaStringCache, + HashMap> typeParserDictionary) { + this.restService = restService; // mockable + this.guidCache = guidCache; + this.schemaStringCache = schemaStringCache; + this.typeParserDictionary = typeParserDictionary; + } + + public synchronized void loadSchemaParser(String serializationType, Function parseMethod) { + if (serializationType == null || serializationType.isEmpty()) { + throw new IllegalArgumentException("Serialization type cannot be null or empty."); + } + if (this.typeParserDictionary.containsKey(serializationType.toLowerCase())) { + throw new IllegalArgumentException("Multiple parse methods for single serialization type may not be added."); + } + this.typeParserDictionary.put(serializationType.toLowerCase(), parseMethod); + log.debug(String.format("Loaded parser for '%s' serialization format.", serializationType.toLowerCase())); + } + + @Override + public synchronized SRObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws IOException, SchemaRegistryClientException { + if (schemaStringCache.containsKey(schemaString)) { + log.debug(String.format("Cache hit schema string. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", + schemaGroup, schemaName, serializationType, schemaString)); + return schemaStringCache.get(schemaString); + } + + log.debug(String.format("Registering schema. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", + schemaGroup, schemaName, serializationType, schemaString)); + + String schemaGuid; + try { + schemaGuid = this.restService.registerSchema(schemaGroup, schemaName, schemaString, serializationType); + } catch (RestClientException e) { + throw new SchemaRegistryClientException("Schema registration failed.", e); + } + + + SRObject registered = new SRObject<>(schemaGuid, + serializationType, + schemaString.getBytes(RestService.SERVICE_CHARSET), + getParseFunc(serializationType)); + + resetIfNeeded(); + schemaStringCache.put(schemaString, registered); + log.debug(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + return registered; + } + + @Override + public synchronized SRObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException { + if (guidCache.containsKey(schemaGuid)) { + log.debug(String.format("Cache hit for schema guid '%s'", schemaGuid)); + return guidCache.get(schemaGuid); + } + + SchemaObjectResponse response; + try { + response = this.restService.getSchemaByGuid(schemaGuid); + } catch (RestClientException e) { + throw new SchemaRegistryClientException(String.format("Failed to get schema for guid %s.", schemaGuid), e); + } + + SRObject schemaObject = new SRObject<>(response.schemaGuid, + response.serializationType, + response.schemaByteArray, + getParseFunc(response.serializationType)); + + resetIfNeeded(); + guidCache.put(schemaGuid, schemaObject); + log.debug(String.format("Cached schema object. Path: '%s'", schemaGuid)); + return schemaObject; + } + + @Override + public synchronized String getGuid(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws IOException, SchemaRegistryClientException { + if (schemaStringCache.containsKey(schemaString)) { + log.debug(String.format("Cache hit schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + return schemaStringCache.get(schemaString).schemaGuid; + } + + String schemaGuid; + try { + schemaGuid = this.restService.getGuid(schemaGroup, schemaName, schemaString, serializationType); + } + catch(RestClientException e){ + throw new SchemaRegistryClientException( + String.format("Failed to fetch schema guid for schema. Group: '%s', name: '%s'", schemaGroup, schemaName), + e); + } + + resetIfNeeded(); + schemaStringCache.put( + schemaString, + new SRObject<>( + schemaGuid, + serializationType, + schemaString.getBytes(RestService.SERVICE_CHARSET), + getParseFunc(serializationType))); + log.debug(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + return schemaGuid; + } + + @Override + public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) throws IOException, SchemaRegistryClientException { + // return this.restService.deleteSchemaVersion(schemaName, version); + // remove from cache + return null; + } + + @Override + public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) throws IOException, SchemaRegistryClientException { + // return this.restService.deleteSchemaVersion(schemaName, null); + // remove from cache + return null; + } + + @Override + public List deleteSchema(String schemaGroup, String schemaName) throws IOException, SchemaRegistryClientException { + // return this.restService.deleteSchema(); + // remove from cache + return null; + } + + public synchronized void reset() { + guidCache.clear(); + schemaStringCache.clear(); + typeParserDictionary.clear(); + } + + /** + * Checks if caches should be reinitialized to satisfy initial configuration + */ + private synchronized void resetIfNeeded() { + // don't call clear, just re-instantiate and let gc collect + // don't clear parser dictionary + if (guidCache.size() > this.maxSchemaMapSize) { + guidCache = new HashMap<>(); + } + if (schemaStringCache.size() > this.maxSchemaMapSize) { + schemaStringCache = new HashMap<>(); + } + } + + private Function getParseFunc(String serializationType) throws IOException { + Function parseFunc = typeParserDictionary.get(serializationType.toLowerCase()); + + if (parseFunc == null) { + log.error(String.format("No loaded schema parser for serialization type: '%s'", serializationType)); + throw new IOException(String.format("Unexpected serialization type '%s' received. Currently loaded parsers: %s", + serializationType, + typeParserDictionary.keySet().toString())); + } + return parseFunc; + } + + public static class Builder { + private final String schemaRegistryUrl; + private final HashMap> typeParserDictionary; + private int maxSchemaMapSize; + + public Builder(String schemaRegistryUrl) { + if (schemaRegistryUrl == null || schemaRegistryUrl.isEmpty()) { + throw new IllegalArgumentException("Schema Registry URL cannot be empty."); + } + this.schemaRegistryUrl = schemaRegistryUrl; + this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + this.typeParserDictionary = new HashMap<>(); + } + + public CachedSchemaRegistryClient build() { + return new CachedSchemaRegistryClient(schemaRegistryUrl, maxSchemaMapSize, typeParserDictionary, null); + } + + public Builder maxSchemaMapSize(int maxSchemaMapSize) throws IllegalArgumentException { + if (maxSchemaMapSize < CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM) { + throw new IllegalArgumentException( + String.format("Schema map size must be greater than %s entries", + CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM)); + } + this.maxSchemaMapSize = maxSchemaMapSize; + return this; + } + + public Builder credential() { + return this; + } + + public Builder loadSchemaParser(String serializationType, Function parseMethod) { + if (serializationType == null || serializationType.isEmpty()) { + throw new IllegalArgumentException("Serialization type cannot be null or empty."); + } + if (this.typeParserDictionary.containsKey(serializationType.toLowerCase())) { + throw new IllegalArgumentException("Multiple parse methods for single serialization type may not be added."); + } + this.typeParserDictionary.put(serializationType.toLowerCase(), parseMethod); + return this; + } + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java new file mode 100644 index 000000000000..22d80b07cead --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.function.Function; + +public class MockSchemaRegistryClient implements SchemaRegistryClient { + + public final HashMap> typeParserDictionary; + + public final HashMap> guidCache; + public final HashMap> schemaStringCache; + + public MockSchemaRegistryClient() { + this.guidCache = new HashMap>(); + this.schemaStringCache = new HashMap>(); + this.typeParserDictionary = new HashMap>(); + } + + public void loadSchemaParser(String serializationFormat, Function f) {} + + @Override + public SRObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws IOException, SchemaRegistryClientException { + if (schemaStringCache.containsKey(schemaString)) { + return schemaStringCache.get(schemaString); + } + + return null; + } + + @Override + public SRObject getSchemaByGuid(String schemaGuid) + throws IOException, SchemaRegistryClientException { + if (guidCache.containsKey(schemaGuid)) { + return guidCache.get(schemaGuid); + } + return null; + } + + @Override + public String getGuid(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws IOException, SchemaRegistryClientException { + if (schemaStringCache.containsKey(schemaString)) { + return schemaStringCache.get(schemaString).schemaGuid; + } + + return null; + } + + @Override + public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) + throws IOException, SchemaRegistryClientException { + return null; + } + + @Override + public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) + throws IOException, SchemaRegistryClientException { + return null; + } + + @Override + public List deleteSchema(String schemaGroup, String schemaName) + throws IOException, SchemaRegistryClientException { + return new ArrayList(); + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SRObject.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SRObject.java new file mode 100644 index 000000000000..c55d6ac4c923 --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SRObject.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client; + +import com.azure.schemaregistry.client.rest.RestService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.charset.Charset; +import java.util.function.Function; + +/** + * Stores all relevant information returned from SchemaRegistryClient layer. + * + * @param is derived from the parser function that is passed in the constructor. + */ +public class SRObject { + private final Logger log; + + public final String schemaGuid; + public final String serializationType; + private final Charset encoding = RestService.SERVICE_CHARSET; + + private Function parseMethod; + + public byte[] schemaByteArray; + private T deserialized; + + public SRObject( + String schemaGuid, + String serializationType, + byte[] schemaByteArray, + Function parseMethod) { + this.schemaGuid = schemaGuid; + this.serializationType = serializationType; + this.schemaByteArray = schemaByteArray; + this.deserialized = null; + this.parseMethod = parseMethod; + this.log = LoggerFactory.getLogger(this.schemaGuid); + } + + /** + * @return schema object of type T, deserialized using stored schema parser method. + */ + public T deserialize() { + if (parseMethod == null) { + log.warn(String.format("No loaded parser for %s format. Schema guid: %s", this.serializationType, this.schemaGuid)); + return null; + } + + if (this.deserialized == null) { + log.debug(String.format("Deserializing schema %s", new String(this.schemaByteArray, encoding))); + this.deserialized = parseMethod.apply(new String(this.schemaByteArray, encoding)); + } + return deserialized; + } +} diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java new file mode 100644 index 000000000000..ecc66a07c707 --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client; + +import java.io.IOException; +import java.util.List; +import java.util.function.Function; + +/** + * Interface that defines operation for registering and fetching schemas and schema information to and from a + * schema registry store. + */ +public interface SchemaRegistryClient { + /** + * Loads function for a given serialization format that can parse the registry-stored schema string into + * usable schema object. + * @param serializationType tag used by schema registry store to identify schema serialization type, e.g. "avro" + * @param parseMethod function to parse string into usable schema object + */ + public void loadSchemaParser(String serializationType, Function parseMethod); + + /** + * Registers a schema against backing schema registry store. + * + * @param schemaGroup schema group name + * @param schemaName schema name + * @param schemaString string representation of schema + * @param serializationType string representation of serialization format type + * @return SRObject containing information regarding registered schema. + * @throws IOException + * @throws SchemaRegistryClientException if registration operation fails + */ + public SRObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws IOException, SchemaRegistryClientException; + + /** + * Fetches schema specified by the GUID. + * + * GUID can be assumed to be unique within a schema registry store. + * + * @param schemaGuid GUID reference to specific schema within configured schema registry store. + * @return SRObject containing information regarding matching schema. + * @throws IOException + * @throws SchemaRegistryClientException if fetch operation fails + */ + public SRObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException; + + /** + * Fetches schema GUID given schema group, name, string representation, and serialization type + * @param schemaGroup schema group name + * @param schemaName schema name + * @param schemaString String representation of schema + * @param serializationType String representation of serialization format type + * @return SRObject containing information regarding requested schema. + * @throws IOException + * @throws SchemaRegistryClientException if fetch operation fails + */ + public String getGuid(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws IOException, SchemaRegistryClientException; + + /** + * Not currently implemented. + * @param schemaGroup schema group name + * @param schemaName schema name + * @param version + * @return GUID of delete schema + * @throws IOException + * @throws SchemaRegistryClientException + */ + public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) + throws IOException, SchemaRegistryClientException; + + /** + * Not currently implemented. + * @param schemaGroup schema group name + * @param schemaName schema name + * @return GUID of deleted schema + * @throws IOException + * @throws SchemaRegistryClientException + */ + public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) + throws IOException, SchemaRegistryClientException; + + /** + * Not currently implemented. + * @param schemaGroup schema group name + * @param schemaName schema name + * @return list of GUID references to deleted schemas + * @throws IOException + * @throws SchemaRegistryClientException + */ + public List deleteSchema(String schemaGroup, String schemaName) throws IOException, SchemaRegistryClientException; +} diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java new file mode 100644 index 000000000000..9e66012210a6 --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client; + +public class SchemaRegistryClientException extends Exception { + public SchemaRegistryClientException(String s) { + super(s); + } + + public SchemaRegistryClientException(String s, Throwable cause) { + super(s, cause); + } +} diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java new file mode 100644 index 000000000000..8ef1de38d897 --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java @@ -0,0 +1,376 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client.rest; + +import com.azure.schemaregistry.client.rest.entities.ErrorMessage; +import com.azure.schemaregistry.client.rest.entities.responses.RegisterSchemaResponse; +import com.azure.schemaregistry.client.rest.entities.responses.SchemaObjectResponse; +import com.azure.schemaregistry.client.rest.exceptions.RestClientException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSocketFactory; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.Map; + +public class RestService { + private static final Logger log = LoggerFactory.getLogger(RestService.class); + private static final TypeReference REGISTER_RESPONSE_TYPE = + new TypeReference() { + }; + private static final TypeReference GET_SCHEMA_BY_GUID_RESPONSE_TYPE = + new TypeReference() { + }; + private static final TypeReference GET_LATEST_SCHEMA_RESPONSE_TYPE = + new TypeReference() { + }; + private static final TypeReference GET_SCHEMA_BY_VERSION_RESPONSE_TYPE = + new TypeReference() { + }; + + private static final int HTTP_CONNECT_TIMEOUT_MS = 60000; + private static final int HTTP_READ_TIMEOUT_MS = 60000; + + private static final int JSON_PARSE_ERROR_CODE = 50005; + private static ObjectMapper jsonDeserializer = new ObjectMapper(); + + public static Charset SERVICE_CHARSET = StandardCharsets.UTF_8; + + private static final String AUTHORIZATION_HEADER = "Authorization"; + + public static Map getDefaultRequestProperties(Map contentTypeEntryMap) { + String contentTypeValue = "application/json"; + if (contentTypeEntryMap != null) { + for (Map.Entry p : contentTypeEntryMap.entrySet()) { + contentTypeValue += ";" + p.getKey() + "=" + p.getValue(); + } + } + return Collections.singletonMap("Content-Type", contentTypeValue); + } + + private String registryUrl; + private String credentials; + private SSLSocketFactory sslSocketFactory; + private Map httpHeaders; + private Proxy proxy; + + public RestService(String registryUrl, String credentials) { + if (!validateRegistryNamespace(registryUrl)) { + throw new IllegalArgumentException(String.format("Improper registry namespace: %s", registryUrl)); + } + this.registryUrl = registryUrl; + this.credentials = credentials; + } + + private static boolean isNonEmpty(String s) { + return s != null && !s.isEmpty(); + } + + private static boolean isValidProxyConfig(String proxyHost, Integer proxyPort) { + return isNonEmpty(proxyHost) && proxyPort != null && proxyPort > 0; + } + + public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) { + this.sslSocketFactory = sslSocketFactory; + } + + /** + * @param requestUrl HTTP connection will be established with this url. + * @param method HTTP method ("GET", "POST", "PUT", etc.) + * @param requestBodyData Bytes to be sent in the request body. + * @param requestProperties HTTP header properties. + * @param responseFormat Expected format of the response to the HTTP request. + * @param The type of the deserialized response to the HTTP request. + * @return The deserialized response to the HTTP request, or null if no data is expected. + */ + private T sendHttpRequest(String requestUrl, String method, byte[] requestBodyData, + Map requestProperties, + TypeReference responseFormat) + throws IOException, RestClientException { + String requestData = requestBodyData == null + ? "null" + : new String(requestBodyData, StandardCharsets.UTF_8); + + HttpURLConnection connection = null; + try { + URL url = new URL(requestUrl); + + connection = buildConnection(url, method, requestProperties); + + log.debug(String.format("Sending %s with input %s to %s. Connection hc: %d.", + method, requestData, requestUrl, connection.hashCode())); + + if (requestBodyData != null) { + connection.setDoOutput(true); + try (OutputStream os = connection.getOutputStream()) { + os.write(requestBodyData); + os.flush(); + } catch (IOException e) { + log.error("Failed to send HTTP request to endpoint: " + url, e); + throw e; + } + } + + int responseCode = connection.getResponseCode(); + log.debug(String.format("Response code received: HTTP%d. Connection hc: %d.", + responseCode, connection.hashCode())); + if (responseCode == HttpURLConnection.HTTP_OK) { + T result; + if (responseFormat.getType().equals(SchemaObjectResponse.class)) { + result = (T)new SchemaObjectResponse(connection); + } + else { + InputStream is = connection.getInputStream(); + result = jsonDeserializer.readValue(is, responseFormat); + is.close(); + } + return result; + } else if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) { + return null; + } else { + ErrorMessage errorMessage; + try (InputStream es = connection.getErrorStream()) { + java.io.ByteArrayOutputStream streamContent = new java.io.ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int length; + while ((length = es.read(buffer)) != -1) { + streamContent.write(buffer, 0, length); + } + log.debug(new String(streamContent.toByteArray())); + errorMessage = jsonDeserializer.readValue(es, ErrorMessage.class); + } catch (JsonProcessingException e) { + errorMessage = new ErrorMessage(JSON_PARSE_ERROR_CODE, e.getMessage()); + } + throw new RestClientException(errorMessage.getMessage(), responseCode, + errorMessage.getErrorCode()); + } + + } finally { + if (connection != null) { + connection.disconnect(); + } + } + } + + private HttpURLConnection buildConnection(URL url, String method, Map requestProperties) + throws IOException { + HttpURLConnection connection = null; + if (proxy == null) { + connection = (HttpURLConnection) url.openConnection(); + } else { + connection = (HttpURLConnection) url.openConnection(proxy); + } + + connection.setConnectTimeout(HTTP_CONNECT_TIMEOUT_MS); + connection.setReadTimeout(HTTP_READ_TIMEOUT_MS); + + setupSsl(connection); + connection.setRequestMethod(method); + setAuthRequestHeaders(connection); + setCustomHeaders(connection); + // connection.getResponseCode() implicitly calls getInputStream, so always set to true. + // On the other hand, leaving this out breaks nothing. + connection.setDoInput(true); + + for (Map.Entry entry : requestProperties.entrySet()) { + connection.setRequestProperty(entry.getKey(), entry.getValue()); + } + + connection.setUseCaches(false); + + return connection; + } + + private void setupSsl(HttpURLConnection connection) { + if (connection instanceof HttpsURLConnection && sslSocketFactory != null) { + ((HttpsURLConnection)connection).setSSLSocketFactory(sslSocketFactory); + } + } + + private T httpRequest(String schemaGroup, + String schemaName, + String schemaVersion, + String method, + byte[] requestBodyData, + Map requestProperties, + Map queryMap, + TypeReference responseFormat) + throws IOException, RestClientException { + int retryCount = 3; + while (true) { + String requestUrl = buildRequestUrl(this.registryUrl, schemaGroup, schemaName, schemaVersion, queryMap); + try { + return sendHttpRequest(requestUrl, + method, + requestBodyData, + requestProperties, + responseFormat); + } catch (IOException e) { + retryCount--; + if (retryCount == 0) { + throw e; + } + } + } + } + + + /** + * @param registryUrl registry namespace + * @param schemaGroup group, may be null + * @param schemaName schema name, may be null + * @param schemaVersion schema version, may be null + * @param queryMap + * @return + */ + static String buildRequestUrl(String registryUrl, String schemaGroup, String schemaName, String schemaVersion, Map queryMap) { + StringBuilder builder = new StringBuilder(); + + builder.append("https://") + .append(registryUrl) + .append("/$schemagroups"); + + if (schemaGroup != null) { + builder.append("/") + .append(schemaGroup); + } + + if (schemaName != null) { + builder.append("/schemas/") + .append(schemaName); + } + + if (schemaVersion != null) { + builder.append("/versions/") + .append(schemaVersion); + } + + builder.append("?api-version=2017-04"); + + if (queryMap != null) { + for (String key : queryMap.keySet()) { + builder.append("&").append(key.trim()).append("=").append(queryMap.get(key).trim()); + } + } + + return builder.toString(); + } + + public String registerSchema(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, RestClientException { + RegisterSchemaResponse response = httpRequest( + schemaGroup, + schemaName, + null + , "PUT", + schemaString.getBytes(SERVICE_CHARSET), + getDefaultRequestProperties(Collections.singletonMap("serialization", serializationType)), + null, + REGISTER_RESPONSE_TYPE); + + return response.getId(); + } + + public String getGuid(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, RestClientException { + RegisterSchemaResponse response = httpRequest( + schemaGroup, schemaName, null, + "PUT", + schemaString.getBytes(SERVICE_CHARSET), + getDefaultRequestProperties(Collections.singletonMap("serialization", serializationType)), + null, + REGISTER_RESPONSE_TYPE); + + return response.getId(); + } + + public SchemaObjectResponse getSchemaByGuid(String schemaGuid) throws IOException, RestClientException { + Map queryMap = Collections.singletonMap("schema-id", schemaGuid); + return httpRequest( + null,null,null, + "GET", + null, + getDefaultRequestProperties(null), + queryMap, + GET_SCHEMA_BY_GUID_RESPONSE_TYPE); + } + + public SchemaObjectResponse getSchema(String schemaGroup, String schemaName, int version) throws IOException, RestClientException { + SchemaObjectResponse response; + + // latest version + if (version == -1) { + String path = String.format("/%s", schemaName); + response = httpRequest( + schemaGroup, + schemaName, + null, + "GET", + null, + getDefaultRequestProperties(null), + null, + GET_LATEST_SCHEMA_RESPONSE_TYPE); + } + else { + String path = String.format("/%s/$versions/%d", schemaName, version); + response = httpRequest( + schemaGroup, + schemaName, + String.valueOf(version), + "GET", + null, + getDefaultRequestProperties(null), + null, + GET_SCHEMA_BY_VERSION_RESPONSE_TYPE); + } + + return response; + } + + private void setAuthRequestHeaders(HttpURLConnection connection) { +// if (bearerAuthCredentialProvider != null) { +// String bearerToken = bearerAuthCredentialProvider.getBearerToken(connection.getURL()); +// if (bearerToken != null) { +// connection.setRequestProperty(AUTHORIZATION_HEADER, "Bearer " + bearerToken); +// } +// } + } + + private void setCustomHeaders(HttpURLConnection connection) { + if (httpHeaders != null) { + httpHeaders.forEach((k, v) -> connection.setRequestProperty(k, v)); + } + } +// +// public void setBearerAuthCredentialProvider( +// BearerAuthCredentialProvider bearerAuthCredentialProvider) { +// this.bearerAuthCredentialProvider = bearerAuthCredentialProvider; +// } + + public void setHttpHeaders(Map httpHeaders) { + this.httpHeaders = httpHeaders; + } + + public void setProxy(String proxyHost, int proxyPort) { + this.proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); + } + + private boolean validateRegistryNamespace(String registryNamespace) { + return registryNamespace.contains(".net") && !registryNamespace.contains("//"); + } +} diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java new file mode 100644 index 000000000000..c1a2c483a3e7 --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client.rest.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Generic JSON error message. + */ +public class ErrorMessage { + + private int errorCode; + private String message; + + public ErrorMessage(@JsonProperty("error_code") int errorCode, + @JsonProperty("message") String message) { + this.errorCode = errorCode; + this.message = message; + } + + @JsonProperty("error_code") + public int getErrorCode() { + return errorCode; + } + + @JsonProperty("error_code") + public void setErrorCode(int error_code) { + this.errorCode = error_code; + } + + @JsonProperty + public String getMessage() { + return message; + } + + @JsonProperty + public void setMessage(String message) { + this.message = message; + } +} diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java new file mode 100644 index 000000000000..ec9f668804cf --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client.rest.entities.responses; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; + +public class RegisterSchemaResponse { + + private String schemaGuid; + + public static RegisterSchemaResponse fromJson(String json) throws IOException { + return new ObjectMapper() + .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true) + .readValue(json, RegisterSchemaResponse.class); + } + + public String toJson() throws IOException { + return new ObjectMapper().writeValueAsString(this); + } + + @JsonProperty("Id") + public String getId() { + return this.schemaGuid; + } + + @JsonProperty("Id") + public void setId(String schemaGuid) { + this.schemaGuid = schemaGuid; + } +} diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java new file mode 100644 index 000000000000..0896e9b88f3c --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client.rest.entities.responses; + +import com.azure.schemaregistry.client.rest.exceptions.RestClientException; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; + +public class SchemaObjectResponse { + public final byte[] schemaByteArray; + public final String serializationType; + public final String schemaGuid; + + public SchemaObjectResponse(HttpURLConnection connection) throws RestClientException, IOException { + this.serializationType = getSerializationType(connection.getHeaderField("content-type")); + this.schemaGuid = connection.getHeaderField("Schema-Id"); + + InputStream is = connection.getInputStream(); + ByteArrayOutputStream streamContent = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int length; + while ((length = is.read(buffer)) != -1) { + streamContent.write(buffer, 0, length); + } + schemaByteArray = streamContent.toByteArray(); + is.close(); + } + + // for testing + public SchemaObjectResponse(byte[] schemaByteArray, String serializationType, String schemaGuid) { + this.schemaByteArray = schemaByteArray; + this.serializationType = serializationType; + this.schemaGuid = schemaGuid; + } + + static String getSerializationType(String contentTypeHeader) throws RestClientException { + String[] contentTypeTokens = contentTypeHeader.split(";"); + for (String contentTypeToken : contentTypeTokens) { + if (contentTypeToken.contains("serialization")) { + return contentTypeToken.split("=")[1]; + } + } + throw new RestClientException(String.format("No serialization type defined in header: %s", contentTypeHeader), 0 , 0); + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java new file mode 100644 index 000000000000..a6f3be3c67d2 --- /dev/null +++ b/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client.rest.exceptions; + +public class RestClientException extends Exception { + private final int status; + private final int errorCode; + + public RestClientException(final String message, final int status, final int errorCode) { + super(message + "; error code: " + errorCode); + this.status = status; + this.errorCode = errorCode; + } + + public int getStatus() { + return status; + } + + public int getErrorCode() { + return errorCode; + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java b/sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java new file mode 100644 index 000000000000..4769dabe8f68 --- /dev/null +++ b/sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client; + +import com.azure.schemaregistry.client.rest.RestService; +import com.azure.schemaregistry.client.rest.entities.responses.SchemaObjectResponse; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.util.HashMap; +import java.util.function.Function; + +import static org.easymock.EasyMock.*; + +public class CachedSchemaRegistryClientTest extends TestCase { + private static final String MOCK_SERIALIZATION = "mock_serialization_type"; + private static final String MOCK_GUID = "mock_guid"; + private static final String MOCK_GROUP = "mockgroup"; + private static final String MOCK_SCHEMA_NAME = "mockname"; + private static final String MOCK_AVRO_SCHEMA = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; + + private CachedSchemaRegistryClient client; + private RestService restService; + private HashMap> guidCache; + private HashMap> schemaStringCache; + private HashMap> typeParserDictionary; + + public CachedSchemaRegistryClientTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(CachedSchemaRegistryClientTest.class); + } + + protected void setUp() { + this.guidCache = new HashMap>(); + this.schemaStringCache = new HashMap>(); + + this.typeParserDictionary = new HashMap>(); + this.typeParserDictionary.put(MOCK_SERIALIZATION, (s)->s); + + this.restService = createNiceMock(RestService.class); + this.client = new CachedSchemaRegistryClient( + this.restService, + this.guidCache, + this.schemaStringCache, + this.typeParserDictionary); + } + + protected void tearDown() { + } + + public void testRegisterThenSchemaCacheHit() throws Exception { + expect(restService.registerSchema(anyString(), anyString(), anyString(), anyString())) + .andReturn(MOCK_GUID) + .once(); + + replay(restService); + + assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); + assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); + + verify(restService); + } + + public void testGetGuidThenSchemaCacheHit() throws Exception { + expect(restService.getGuid(anyString(), anyString(), anyString(), anyString())) + .andReturn(MOCK_GUID) + .once(); + + replay(restService); + + assertEquals(MOCK_GUID, client.getGuid(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); + assertEquals(MOCK_GUID, client.getGuid(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); + + verify(restService); + } + + public void testGetSchemaThenGuidCacheHit() throws Exception { + expect(restService.getSchemaByGuid(anyString())) + .andReturn(new SchemaObjectResponse(null, MOCK_SERIALIZATION, MOCK_GUID)) + .once(); + + replay(restService); + + assertEquals(MOCK_GUID, client.getSchemaByGuid(MOCK_GUID).schemaGuid); + assertEquals(MOCK_GUID, client.getSchemaByGuid(MOCK_GUID).schemaGuid); + + verify(restService); + } + + public void testClientReset() throws Exception { + expect(restService.registerSchema(anyString(), anyString(), anyString(), anyString())) + .andReturn(MOCK_GUID) + .times(2); + + replay(restService); + + assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); + + client.reset(); + + assertEquals(0, guidCache.size()); + assertEquals(0, schemaStringCache.size()); + assertEquals(0, this.typeParserDictionary.size()); + + this.typeParserDictionary.put(MOCK_SERIALIZATION, (s)->s); + + assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); + + verify(restService); + } + + // builder tests + public void testBuilderIfRegistryUrlNullOrEmptyThrow() { + try { + new CachedSchemaRegistryClient.Builder("") + .loadSchemaParser(null, null) + .build(); + fail(); + } catch (IllegalArgumentException e) { + assertTrue(true); + } + + try { + new CachedSchemaRegistryClient.Builder(null) + .build(); + fail(); + } catch (IllegalArgumentException e) { + assertTrue(true); + } + } +} diff --git a/sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java b/sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java new file mode 100644 index 000000000000..da4c3232e691 --- /dev/null +++ b/sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.client; + +import com.azure.schemaregistry.client.rest.RestService; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.util.ArrayList; + +public class RestServiceTest extends TestCase{ + public RestServiceTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(RestServiceTest.class); + } + + protected void setUp() { + } + + protected void tearDown() { + } + + public void testValidateRegistryUrl() { + ArrayList badUrls = new ArrayList(); + badUrls.add("mock"); + badUrls.add("sb://contoso.servicebus.onebox.windows-int.net:4446"); + + for (String badUrl : badUrls) { + try { + new RestService(badUrl, null); + assertTrue(false); + } catch (IllegalArgumentException e) { + assertTrue(true); + } + } + + new RestService("contoso.servicebus.onebox.windows-int.net:4446", null); // testing + new RestService("contoso.servicebus.windows.net", null); + assertTrue(true); + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/codec/codec-avro/pom.xml b/sdk/schemaregistry/codec/codec-avro/pom.xml new file mode 100644 index 000000000000..c55062ca315a --- /dev/null +++ b/sdk/schemaregistry/codec/codec-avro/pom.xml @@ -0,0 +1,50 @@ + + + + + + 4.0.0 + + + com.azure + schemaregistry-codec + 0.5-preview + + + com.azure + schemaregistry-codec-avro + 0.5-preview + + schemaregistry-codec-avro + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 4.11 + test + + + org.apache.avro + avro + 1.9.2 + + + com.azure + schemaregistry-serde-common + 0.5-preview + compile + + + + diff --git a/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java b/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java new file mode 100644 index 000000000000..7e8ef3f050d6 --- /dev/null +++ b/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import com.azure.schemaregistry.ByteDecoder; +import com.azure.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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * ByteDecoder implementation with all Avro-specific functionality required to deserialize byte arrays given Avro schema. + */ +public class AvroByteDecoder extends AvroCodec + implements ByteDecoder { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final DecoderFactory decoderFactory = DecoderFactory.get(); + + private AvroByteDecoder(Boolean avroSpecificReader) { + this.avroSpecificReader = avroSpecificReader; + } + + private final boolean 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 + */ + public Object decodeBytes(byte[] b, Object object) throws SerializationException { + if (!(object instanceof Schema)) { + throw new SerializationException("Attempted to decode with non-Avro schema object in AvroByteDecoder"); + } + Schema schema = (Schema)object; + + if (schema.getType().equals(Schema.Type.BYTES)) { + return b; + } + + DatumReader reader = getDatumReader(schema); + + try { + Object result = reader.read(null, decoderFactory.binaryDecoder(b, null)); + + if (schema.getType().equals(Schema.Type.STRING)) { + return result.toString(); + } + + return result; + } catch (IOException | RuntimeException e) { + // avro deserialization may throw AvroRuntimeException, NullPointerException, etc + throw new SerializationException("Error deserializing Avro message.", e); + } + } + + + /** + * Returns correct reader for decoding payload + * + * @param writerSchema Avro schema fetched from schema registry store + * @return + */ + 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); + } + } + + public static class Builder { + private Boolean avroSpecificReader = false; + + public Builder() {} + + public Builder avroSpecificReader(Boolean avroSpecificReader) { + this.avroSpecificReader = avroSpecificReader; + return this; + } + + public AvroByteDecoder build() { + return new AvroByteDecoder(this.avroSpecificReader); + } + } +} diff --git a/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java b/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java new file mode 100644 index 000000000000..e7099aea2380 --- /dev/null +++ b/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import com.azure.schemaregistry.ByteEncoder; +import com.azure.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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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 static final Logger log = LoggerFactory.getLogger(AvroByteEncoder.class); + private final EncoderFactory encoderFactory = EncoderFactory.get(); + + private AvroByteEncoder() {} + + /** + * @param object Schema object used to generate schema string + * @see AvroSchemaUtils for distinction between primitive and Avro schema generation + */ + 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 + */ + 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 + */ + public ByteArrayOutputStream encode(Object object) throws SerializationException { + Schema schema = AvroSchemaUtils.getSchema(object); + + try { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + if (object instanceof byte[]) { + out.write((byte[]) object); + } else { + BinaryEncoder encoder = encoderFactory.directBinaryEncoder(out, null); + DatumWriter writer; + if (object instanceof SpecificRecord) { + writer = new SpecificDatumWriter<>(schema); + } else { + writer = new GenericDatumWriter<>(schema); + } + writer.write(object, encoder); + encoder.flush(); + } + out.close(); + return out; + } catch (IOException | RuntimeException e) { + // Avro serialization can throw AvroRuntimeException, NullPointerException, ClassCastException, etc + throw new SerializationException("Error serializing Avro message", e); + } + } + + public static class Builder { + public Builder() {} + public AvroByteEncoder build() { + return new AvroByteEncoder(); + } + } +} diff --git a/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java b/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java new file mode 100644 index 000000000000..dbfaea5a8651 --- /dev/null +++ b/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import com.azure.schemaregistry.Codec; +import org.apache.avro.Schema; + +/** + * Base Codec class for Avro encoder and decoder implementations + */ +public abstract class AvroCodec implements Codec { + public String serializationFormat() { + return "Avro"; + } + + /** + * @param schemaString string representation of schema + * @return Avro schema + */ + public Schema parseSchemaString(String schemaString) { + return (new Schema.Parser()).parse(schemaString); + } +} diff --git a/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java b/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java new file mode 100644 index 000000000000..374c611c9832 --- /dev/null +++ b/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericContainer; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class AvroSchemaUtils { + private static final Map primitiveSchemas; + + static { + Schema.Parser parser = new Schema.Parser(); + primitiveSchemas = new HashMap<>(); + primitiveSchemas.put("Null", createPrimitiveSchema(parser, "null")); + primitiveSchemas.put("Boolean", createPrimitiveSchema(parser, "boolean")); + primitiveSchemas.put("Integer", createPrimitiveSchema(parser, "int")); + primitiveSchemas.put("Long", createPrimitiveSchema(parser, "long")); + primitiveSchemas.put("Float", createPrimitiveSchema(parser, "float")); + primitiveSchemas.put("Double", createPrimitiveSchema(parser, "double")); + primitiveSchemas.put("String", createPrimitiveSchema(parser, "string")); + primitiveSchemas.put("Bytes", createPrimitiveSchema(parser, "bytes")); + } + + private static Schema createPrimitiveSchema(Schema.Parser parser, String type) { + String schemaString = String.format("{\"type\" : \"%s\"}", type); + return parser.parse(schemaString); + } + + public static Map getPrimitiveSchemas() { + return Collections.unmodifiableMap(primitiveSchemas); + } + + public static Schema getSchema(Object object) { + if (object == null) { + return primitiveSchemas.get("Null"); + } else if (object instanceof Boolean) { + return primitiveSchemas.get("Boolean"); + } else if (object instanceof Integer) { + return primitiveSchemas.get("Integer"); + } else if (object instanceof Long) { + return primitiveSchemas.get("Long"); + } else if (object instanceof Float) { + return primitiveSchemas.get("Float"); + } else if (object instanceof Double) { + return primitiveSchemas.get("Double"); + } else if (object instanceof CharSequence) { + return primitiveSchemas.get("String"); + } else if (object instanceof byte[]) { + return primitiveSchemas.get("Bytes"); + } else if (object instanceof GenericContainer) { + return ((GenericContainer) object).getSchema(); + } else { + throw new IllegalArgumentException( + "Unsupported Avro type. Supported types are null, Boolean, Integer, Long, " + + "Float, Double, String, byte[] and IndexedRecord"); + } + } +} diff --git a/sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java b/sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java new file mode 100644 index 000000000000..7f7fc42db326 --- /dev/null +++ b/sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class AvroByteDecoderTest extends TestCase { + public AvroByteDecoderTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(AvroByteDecoderTest.class); + } + + protected void setUp() { + } + + protected void tearDown() { + } + + public void testShouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java b/sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java new file mode 100644 index 000000000000..f9f8b5cb9284 --- /dev/null +++ b/sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class AvroByteEncoderTest extends TestCase { + private static final String MOCK_AVRO_SCHEMA_STRING = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; + private static final Character namespaceDelimiter = '/'; + + public AvroByteEncoderTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(AvroByteEncoderTest.class); + } + + protected void setUp() { + } + + protected void tearDown() { + } + + public void testPlaceholder() { + getEncoder(); + assertTrue(true); + } + + private AvroByteEncoder getEncoder() { + return new AvroByteEncoder.Builder().build(); + } +} diff --git a/sdk/schemaregistry/codec/pom.xml b/sdk/schemaregistry/codec/pom.xml new file mode 100644 index 000000000000..9c308963554c --- /dev/null +++ b/sdk/schemaregistry/codec/pom.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + + com.azure + schemaregistry-parent + 0.5-preview + + + com.azure + schemaregistry-codec + pom + 0.5-preview + schemaregistry-codec + + + 1.8 + 1.8 + + + + codec-avro + + + + + junit + junit + 3.8.1 + test + + + diff --git a/sdk/schemaregistry/pom.xml b/sdk/schemaregistry/pom.xml new file mode 100644 index 000000000000..186e4e3bc1c4 --- /dev/null +++ b/sdk/schemaregistry/pom.xml @@ -0,0 +1,45 @@ + + + + + 4.0.0 + + com.azure + 0.5-preview + schemaregistry-parent + pom + schemaregistry-parent + + + client + serde + codec + + + + 1.8 + 1.8 + 2.10.2 + + + + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + junit + junit + 3.8.1 + test + + + + diff --git a/sdk/schemaregistry/serde/common/pom.xml b/sdk/schemaregistry/serde/common/pom.xml new file mode 100644 index 000000000000..9e6e0755fde6 --- /dev/null +++ b/sdk/schemaregistry/serde/common/pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + + + com.azure + schemaregistry-serde + 0.5-preview + + + schemaregistry-serde-common + jar + schemaregistry-serde-common + + + + org.easymock + easymock + 4.1 + test + + + junit + junit + test + + + com.azure + schemaregistry-client + 0.5-preview + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + org.apache.avro + avro + 1.9.2 + test + + + diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java new file mode 100644 index 000000000000..c2adafe7473a --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import com.azure.schemaregistry.client.SRObject; +import com.azure.schemaregistry.client.SchemaRegistryClient; +import com.azure.schemaregistry.client.SchemaRegistryClientException; + +import java.io.IOException; +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public abstract class AbstractDataDeserializer extends AbstractDataSerDe { + protected final Map byteDecoderMap = new ConcurrentHashMap<>(); + + protected AbstractDataDeserializer(SchemaRegistryClient schemaRegistryClient) { + super(schemaRegistryClient); + } + + // special case for KafkaAvroDeserializer + protected AbstractDataDeserializer() { + } + + protected Object deserialize(byte[] payload) throws SerializationException { + if (payload == null) { + return null; + } + + ByteBuffer buffer = getByteBuffer(payload); + String schemaGuid = getSchemaGuidFromPayload(buffer); + SRObject registryObject = null; + Object payloadSchema = null; + + try { + registryObject = this.schemaRegistryClient.getSchemaByGuid(schemaGuid); + payloadSchema = registryObject.deserialize(); + } catch (IOException | SchemaRegistryClientException e) { + throw new SerializationException("Failed to retrieve schema for id " + schemaGuid, e); + } + + // TODO: how to handle unknown formats + if (payloadSchema == null) { + throw new SerializationException( + String.format("Cast failure for REST object from registry. Object type: %s", + registryObject.deserialize().getClass().getName())); + } + + int start = buffer.position() + buffer.arrayOffset(); + int length = buffer.limit() - AbstractDataSerDe.idSize; + byte[] b = Arrays.copyOfRange(buffer.array(), start, start + length); + + ByteDecoder byteDecoder = getByteDecoder(registryObject); + return byteDecoder.decodeBytes(b, payloadSchema); + } + + + private ByteDecoder getByteDecoder(SRObject registryObject) throws SerializationException { + ByteDecoder decoder = byteDecoderMap.get(registryObject.serializationType); + if (decoder == null) { + throw new SerializationException("No decoder class found for serialization type " + + registryObject.serializationType); + } + return decoder; + } + + private ByteBuffer getByteBuffer(byte[] payload) { + ByteBuffer buffer = ByteBuffer.wrap(payload); + return buffer; + } + + protected String getSchemaGuidFromPayload(ByteBuffer buffer) throws SerializationException { + byte[] schemaGuidByteArray = new byte[AbstractDataSerDe.idSize]; + try { + buffer.get(schemaGuidByteArray); + } catch (BufferUnderflowException e) { + throw new SerializationException("Payload too short, no readable guid.", e); + } + + return new String(schemaGuidByteArray); + } + + protected void loadByteDecoder(ByteDecoder decoder) { + this.byteDecoderMap.put(decoder.serializationFormat(), decoder); + this.schemaRegistryClient.loadSchemaParser( + decoder.serializationFormat(), + (s) -> decoder.parseSchemaString(s)); + } + + protected static abstract class AbstractBuilder { + protected B deserializerBuilder; + protected static SchemaRegistryClient schemaRegistryClient; + protected ArrayList byteDecoders; + + protected abstract B getActualBuilder(); + + protected AbstractBuilder(SchemaRegistryClient schemaRegistryClient) { + this.schemaRegistryClient = schemaRegistryClient; + this.byteDecoders = new ArrayList<>(); + + deserializerBuilder = getActualBuilder(); + } + + public B byteDecoder(ByteDecoder decoder) { + byteDecoders.add(decoder); + return deserializerBuilder; + } + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java new file mode 100644 index 000000000000..91b14539e234 --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import com.azure.schemaregistry.client.SchemaRegistryClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Common fields and helper methods for both the serializer and the deserializer. + */ +public abstract class AbstractDataSerDe { + protected final Logger log = LoggerFactory.getLogger(getClass()); + + public static final Character SCHEMA_PATH_DELIMITER = '.'; + public static final int idSize = 64; + + protected SchemaRegistryClient schemaRegistryClient; + + protected AbstractDataSerDe(SchemaRegistryClient schemaRegistryClient) { + if (schemaRegistryClient == null) { + throw new IllegalArgumentException("Schema registry client must be initialized and passed into builder."); + } + this.schemaRegistryClient = schemaRegistryClient; + } + + // special case for Kafka serializer/deserializer + public AbstractDataSerDe() { + + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java new file mode 100644 index 000000000000..c4a9b7805c88 --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import com.azure.schemaregistry.client.SchemaRegistryClient; +import com.azure.schemaregistry.client.SchemaRegistryClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + +public abstract class AbstractDataSerializer extends AbstractDataSerDe { + private static final Logger log = LoggerFactory.getLogger(AbstractDataSerializer.class); + + public static Boolean AUTO_REGISTER_SCHEMAS_DEFAULT = false; + public static String SCHEMA_GROUP_DEFAULT = "$default"; + + protected ByteEncoder byteEncoder = null; + protected String serializationFormat; + protected Boolean autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; + protected String schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; + + public AbstractDataSerializer(SchemaRegistryClient schemaRegistryClient) { + super(schemaRegistryClient); + } + + // special case for KafkaAvroSerializer + public AbstractDataSerializer() { + } + + protected void setByteEncoder(ByteEncoder byteEncoder) { + if (this.byteEncoder != null) { + throw new IllegalArgumentException("Setting multiple encoders on serializer not permitted"); + } + this.byteEncoder = byteEncoder; + this.schemaRegistryClient.loadSchemaParser( + byteEncoder.serializationFormat(), + (s) -> byteEncoder.parseSchemaString(s)); + } + + protected byte[] serializeImpl(Object object) throws SerializationException { + if (object == null) { + throw new SerializationException( + "Null object. Null object case should be handled in concrete serializer class." + + "Please file an issue."); + } + + if (byteEncoder == null) { + throw new SerializationException("Byte encoder null, serializer must be initialized with a byte encoder."); + } + + if (serializationFormat == null) { + serializationFormat = byteEncoder.serializationFormat(); + } + + String schemaString = byteEncoder.getSchemaString(object); + String schemaName = byteEncoder.getSchemaName(object); + + try { + String schemaGuid = maybeRegisterSchema(this.schemaGroup, schemaName, schemaString, this.serializationFormat); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + // utf8 swap todo + ByteBuffer guidBuffer = ByteBuffer.allocate(AbstractDataSerDe.idSize) + .put(schemaGuid.getBytes(Charset.forName("UTF-8"))); + out.write(guidBuffer.array()); + byteEncoder.encode(object).writeTo(out); + return out.toByteArray(); + } catch (SchemaRegistryClientException | IOException e) { + if (this.autoRegisterSchemas) { + throw new SerializationException( + String.format("Error registering Avro schema. Group: %s, name: %s", schemaGroup, schemaName), + e); + } else { + throw new SerializationException( + String.format("Error retrieving Avro schema. Group: %s, name: %s", schemaGroup, schemaName), + e); + } + } + } + + private String maybeRegisterSchema(String schemaGroup, String schemaName, String schemaString, String serializationFormatString) + throws IOException, SchemaRegistryClientException { + if (this.autoRegisterSchemas) { + return this.schemaRegistryClient.register(schemaGroup, schemaName, schemaString, + serializationFormatString).schemaGuid; + } else { + return this.schemaRegistryClient.getGuid(schemaGroup, schemaName, schemaString, serializationFormatString); + } + } + + protected static abstract class AbstractBuilder { + protected B serializerBuilder; + protected SchemaRegistryClient schemaRegistryClient; + + protected Boolean autoRegisterSchemas = false; + protected ByteEncoder byteEncoder; + protected String schemaGroup; + + protected abstract B getActualBuilder(); + + public AbstractBuilder(SchemaRegistryClient schemaRegistryClient) { + this.schemaRegistryClient = schemaRegistryClient; + this.byteEncoder = null; + + serializerBuilder = getActualBuilder(); + } + + public B schemaGroup(String schemaGroup) { + this.schemaGroup = schemaGroup; + return serializerBuilder; + } + + public B byteEncoder(ByteEncoder byteEncoder) { + this.byteEncoder = byteEncoder; + return serializerBuilder; + } + + public B autoRegisterSchemas(Boolean autoRegisterSchemas) { + this.autoRegisterSchemas = autoRegisterSchemas; + return serializerBuilder; + } + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteDecoder.java b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteDecoder.java new file mode 100644 index 000000000000..99ad2ea776b8 --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteDecoder.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +public interface ByteDecoder extends Codec { + /** + * Decodes byte array into Object given provided schema object. + * @param encodedBytes payload to be decoded + * @param schemaObject object used to decode the payload + * @return deserialized object + * @throws SerializationException + */ + public Object decodeBytes(byte[] encodedBytes, Object schemaObject) throws SerializationException; +} diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteEncoder.java b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteEncoder.java new file mode 100644 index 000000000000..6f6e578fb99e --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteEncoder.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import java.io.ByteArrayOutputStream; + +public interface ByteEncoder extends Codec { + /** + * Return schema name for storing in registry store + * @param object Schema object + * Refer to Schema Registry documentation for information on schema grouping and naming. + * + * @return schema name + * @throws SerializationException + */ + public String getSchemaName(Object object) throws SerializationException; + + /** + * Returns string representation of schema object to be stored in the service. + * + * @param object Schema object used to generate schema string + * @return String representation of schema object parameter + * @throws SerializationException + */ + public String getSchemaString(Object object) throws SerializationException; + + /** + * Converts object into stream containing the encoded representation of the object. + * @param object Object to be encoded into byte stream + * + * TODO: Method does not currently require schema object to be passed since schemas can be derived from + * Avro objects. JSON implementation would be the same. + */ + public ByteArrayOutputStream encode(Object object) throws SerializationException; +} diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/Codec.java b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/Codec.java new file mode 100644 index 000000000000..0a7c627fd613 --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/Codec.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +/** + * Base interface for all ByteEncoder and ByteDecoder interfaces + */ +public interface Codec { + /** + * @return String representation of serialization format type, e.g. "avro" or "json". + * + * Utilized by schema registry store and client as non-case-sensitive tags for + * schemas of specific serialization format. + */ + public String serializationFormat(); + + /** + * Parses string representation of schema into schema Object + * @param schemaString string representation of schema + * @return schema object to be used for decoding payloads + */ + public Object parseSchemaString(String schemaString); +} diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/SerializationException.java b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/SerializationException.java new file mode 100644 index 000000000000..a456264c18a6 --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/SerializationException.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +/** + * Exception thrown by Schema Registry client deserializer implementations for runtime error cases. + */ +public class SerializationException extends Exception { + public SerializationException(String s) { + super(s); + } + + public SerializationException(String s, Throwable cause) { + super(s, cause); + } +} diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java new file mode 100644 index 000000000000..6482a0e1fef9 --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import com.azure.schemaregistry.client.MockSchemaRegistryClient; +import com.azure.schemaregistry.client.SRObject; +import com.azure.schemaregistry.client.SchemaRegistryClientException; +import com.azure.schemaregistry.client.rest.RestService; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData; +import org.apache.avro.generic.GenericDatumWriter; +import org.apache.avro.generic.GenericRecord; +import org.apache.avro.io.BinaryEncoder; +import org.apache.avro.io.EncoderFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + +public class AbstractDataDeserializerTest extends TestCase { + private static final String MOCK_GUID = new String(new char[AbstractDataSerDe.idSize]).replace("\0", "a"); + private static final String MOCK_AVRO_SCHEMA_STRING = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; + + private final EncoderFactory encoderFactory = EncoderFactory.get(); + private final Schema MOCK_AVRO_SCHEMA; + + public AbstractDataDeserializerTest(String testName) { + super(testName); + this.MOCK_AVRO_SCHEMA = (new Schema.Parser()).parse(MOCK_AVRO_SCHEMA_STRING); + } + + public static Test suite() { + return new TestSuite(AbstractDataDeserializerTest.class); + } + + public void testLoadDecoder() throws IOException, SchemaRegistryClientException, SerializationException { + // add standard avro decoder class and test that it is used for decoding payload + SampleByteDecoder decoder = new SampleByteDecoder(); + + // manually add SRObject to cache + SRObject registered = new SRObject<>(MOCK_GUID, + decoder.serializationFormat(), + MOCK_AVRO_SCHEMA_STRING.getBytes(RestService.SERVICE_CHARSET), + s -> decoder.parseSchemaString(s)); + + assertTrue(registered.deserialize() != null); + + MockSchemaRegistryClient mockRegistryClient = new MockSchemaRegistryClient(); + mockRegistryClient.guidCache.put(MOCK_GUID, registered); + TestDummyDeserializer deserializer = new TestDummyDeserializer.Builder(mockRegistryClient) + .byteDecoder(new SampleByteDecoder()) + .build(); + + assertEquals(MOCK_GUID, deserializer.schemaRegistryClient.getSchemaByGuid(MOCK_GUID).schemaGuid); + assertEquals(decoder.samplePayload, deserializer.deserialize(getPayload())); + } + + public void testNullPayload() throws IOException, SchemaRegistryClientException, SerializationException { + TestDummyDeserializer deserializer = new TestDummyDeserializer.Builder(new MockSchemaRegistryClient()) + .build(); + + assertEquals(null, deserializer.deserialize(null)); + } + + public void testIfTooShortPayloadThrow() { + TestDummyDeserializer deserializer = new TestDummyDeserializer.Builder(new MockSchemaRegistryClient()) + .build(); + + try { + deserializer.deserialize("bad payload".getBytes()); + fail("Too short payload did not throw SerializationException"); + } catch (SerializationException e) { + assertTrue(true); + } + } + + // TODO: add for non-existing guid + + // builder tests + public void testBuilderIfRegistryNullOnBuildThrow() { + try { + TestDummyDeserializer deserializer = new TestDummyDeserializer.Builder(null).build(); + assert(deserializer == null); + fail("should not get here."); + } catch (IllegalArgumentException e) { + // good + } catch (Exception e) { + fail("Building deserializer with null registry should fail with IllegalArgumentException"); + } + } + + private byte[] getPayload() throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + out.write(ByteBuffer.allocate(AbstractDataSerDe.idSize) + .put(MOCK_GUID.getBytes(Charset.forName("UTF-8"))) + .array()); + GenericRecord record = getAvroRecord(); + BinaryEncoder encoder = encoderFactory.directBinaryEncoder(out, null); + GenericDatumWriter writer = new GenericDatumWriter<>(MOCK_AVRO_SCHEMA); + writer.write(record, encoder); + encoder.flush(); + byte[] bytes = out.toByteArray(); + return bytes; + } + + + private GenericRecord getAvroRecord() { + GenericRecord avroRecord = new GenericData.Record(MOCK_AVRO_SCHEMA); + avroRecord.put("name", "arthur"); + avroRecord.put("favorite_number", 23); + return avroRecord; + } +} diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java new file mode 100644 index 000000000000..4a7ac04f563f --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import com.azure.schemaregistry.client.MockSchemaRegistryClient; +import com.azure.schemaregistry.client.SRObject; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Random; + +public class AbstractDataSerializerTest extends TestCase { + public AbstractDataSerializerTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(AbstractDataSerializerTest.class); + } + + public void testRegistryGuidPrefixedToPayload() { + Random rnd = new Random(); + String MOCK_GUID = ""; + for (int i = 0; i < AbstractDataSerDe.idSize; i++) { + MOCK_GUID += (char)(rnd.nextInt(26) + 'a'); + } + + // manually add SRObject into mock registry client cache + SampleByteEncoder encoder = new SampleByteEncoder(); + SRObject registered = new SRObject<>(MOCK_GUID, + encoder.serializationFormat(), + encoder.getSchemaString(null).getBytes(), // always returns same schema string + s -> encoder.parseSchemaString(s)); + + assertEquals(encoder.getSchemaString(null), registered.deserialize()); + + MockSchemaRegistryClient mockRegistryClient = new MockSchemaRegistryClient(); + mockRegistryClient.schemaStringCache.put(encoder.getSchemaString(null), registered); + + TestDummySerializer serializer = new TestDummySerializer.Builder(mockRegistryClient) + .byteEncoder(encoder) + .build(); + + try { + byte[] payload = serializer.serializeImpl(1); + ByteBuffer buffer = ByteBuffer.wrap(payload); + byte[] schemaGuidByteArray = new byte[AbstractDataSerDe.idSize]; + try { + buffer.get(schemaGuidByteArray); + } catch (BufferUnderflowException e) { + throw new SerializationException("Payload too short, no readable guid.", e); + } + + assertEquals(MOCK_GUID, new String(schemaGuidByteArray)); // guid should match preloaded SRObject guid + + int start = buffer.position() + buffer.arrayOffset(); + int length = buffer.limit() - AbstractDataSerDe.idSize; + byte[] encodedBytes = Arrays.copyOfRange(buffer.array(), start, start + length); + assertTrue(Arrays.equals(encoder.encode(null).toByteArray(), encodedBytes)); + } catch (SerializationException e) { + e.printStackTrace(); + fail(); + } + } + + public void testNullPayloadThrowsSerializationException() { + TestDummySerializer serializer = new TestDummySerializer.Builder(new MockSchemaRegistryClient()) + .byteEncoder(new SampleByteEncoder()) + .build(); + + try { + serializer.serializeImpl(null); + fail("Serializing null payload failed to throw SerializationException"); + } catch (SerializationException e) { + assertTrue(true); + } + } + + public void testSerializeWithNullByteEncoderThrows() { + // don't set byte encoder on constructor + TestDummySerializer serializer = new TestDummySerializer.Builder(new MockSchemaRegistryClient()) + .constructWithoutByteEncoder() + .build(); + + try { + serializer.serializeImpl(1); + } catch (SerializationException e) { + assert(true); + } + } + + public void testBuilderIfRegistryNullThrow() { + try { + TestDummySerializer serializer = new TestDummySerializer.Builder(null).build(); + fail("Building serializer instance with null registry client failed to throw"); + } catch (IllegalArgumentException e) { + assertTrue(true); + } catch (Exception e) { + fail("Building serializer instance with null registry client should throw illegal argument exception"); + } + } + + public void testBuilderAutoRegister() { + TestDummySerializer serializer = new TestDummySerializer.Builder(new MockSchemaRegistryClient()) + .constructWithoutByteEncoder() // doesn't matter + .build(); + assertEquals(false, (boolean) serializer.autoRegisterSchemas); + + serializer = new TestDummySerializer.Builder(new MockSchemaRegistryClient()) + .constructWithoutByteEncoder() // doesn't matter + .autoRegisterSchemas(true) + .build(); + assertEquals(true, (boolean) serializer.autoRegisterSchemas); + } +} diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java new file mode 100644 index 000000000000..91853b8ad539 --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import org.apache.avro.Schema; + +public class SampleByteDecoder implements ByteDecoder { + public SampleByteDecoder() {} + + @Override + public String serializationFormat() { + return "sample"; + } + + public static final String samplePayload = "sample payload!"; + + @Override + public Object decodeBytes(byte[] bytes, Object o) throws SerializationException { + return samplePayload; + } + + @Override + public Schema parseSchemaString(String s) { + return new Schema.Parser().parse(s); + } +} diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java new file mode 100644 index 000000000000..6469c3177455 --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class SampleByteEncoder implements ByteEncoder { + + public SampleByteEncoder() {} + + @Override + public String getSchemaName(Object object) throws SerializationException { + return null; + } + + @Override + public String getSchemaString(Object object) { + return "string representation of schema"; + } + + @Override + public ByteArrayOutputStream encode(Object object) throws SerializationException { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try { + outputStream.write("sample payload".getBytes()); + outputStream.flush(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + throw new SerializationException("this should never happen", e); + } + return outputStream; + } + + @Override + public String serializationFormat() { + return "test"; + } + + @Override + public String parseSchemaString(String s) { + return s; + } +} diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java new file mode 100644 index 000000000000..a49a8a459b04 --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import com.azure.schemaregistry.client.SchemaRegistryClient; + +public class TestDummyDeserializer extends AbstractDataDeserializer { + private TestDummyDeserializer(Builder builder) { + super(builder.schemaRegistryClient); + for (ByteDecoder decoder: builder.byteDecoders) + this.byteDecoderMap.put(decoder.serializationFormat(), decoder); + } + + public static class Builder extends AbstractDataDeserializer.AbstractBuilder { + public Builder(SchemaRegistryClient schemaRegistryClient) { + super(schemaRegistryClient); + } + + @Override + public Builder getActualBuilder() { + return this; + } + + public TestDummyDeserializer build() { + return new TestDummyDeserializer(this); + } + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java new file mode 100644 index 000000000000..443cf4923b8f --- /dev/null +++ b/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import com.azure.schemaregistry.client.SchemaRegistryClient; + +public class TestDummySerializer extends AbstractDataSerializer { + private TestDummySerializer(Builder builder) { + super(builder.schemaRegistryClient); + + // allows simulating improperly written serializer constructor that does not initialize byte encoder + if (!builder.constructWithoutByteEncoder) { + setByteEncoder(builder.byteEncoder); + } + + this.autoRegisterSchemas = builder.autoRegisterSchemas; + } + + public static class Builder extends AbstractDataSerializer.AbstractBuilder { + private boolean constructWithoutByteEncoder = false; + + public Builder(SchemaRegistryClient schemaRegistryClient) { + super(schemaRegistryClient); + } + + @Override + public Builder getActualBuilder() { + return this; + } + + public TestDummySerializer build() { + return new TestDummySerializer(this); + } + + public Builder constructWithoutByteEncoder() { + this.constructWithoutByteEncoder = true; + return this; + } + } +} diff --git a/sdk/schemaregistry/serde/generic-avro/pom.xml b/sdk/schemaregistry/serde/generic-avro/pom.xml new file mode 100644 index 000000000000..a8a617e888b2 --- /dev/null +++ b/sdk/schemaregistry/serde/generic-avro/pom.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + + com.azure + schemaregistry-serde + 0.5-preview + + + com.azure + schemaregistry-serde-avro + schemaregistry-serde-avro + + + + junit + junit + 3.8.1 + test + + + com.azure + schemaregistry-serde-common + 0.5-preview + + + com.azure + schemaregistry-codec-avro + 0.5-preview + compile + + + diff --git a/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java b/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java new file mode 100644 index 000000000000..c378c82a1ccf --- /dev/null +++ b/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import com.azure.schemaregistry.AbstractDataDeserializer; +import com.azure.schemaregistry.SerializationException; +import com.azure.schemaregistry.client.CachedSchemaRegistryClient; + +/** + * A deserializer implementation capable of automatedly deserializing encoded byte array payloads into Java objects by + * fetching payload-specified schemas from the Azure Schema Registry store. + * + * SchemaRegistryAvroDeserializer instances should be built using the static Builder class. + * + * Pluggable with the core Azure SDK Deserializer interface. + * + * @see AbstractDataDeserializer See AbstractDataDeserializer for internal deserialization implementation + * @see SchemaRegistryAvroDeserializer.Builder See Builder for documentation on builder parameters + */ +public class SchemaRegistryAvroDeserializer extends AbstractDataDeserializer { + private SchemaRegistryAvroDeserializer(Builder builder) { + super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) + .credential() + .maxSchemaMapSize(builder.maxSchemaMapSize) + .build()); + + loadByteDecoder(new AvroByteDecoder.Builder() + .avroSpecificReader(builder.avroSpecificReader) + .build()); + } + + /** + * Deserializes byte array into Java object using payload-specified schema. + * + * @param data Byte array containing serialized bytes + * @return Java object. + * + * Object type is testable with instanceof operator. Return value can be casted in the caller layer. + * + * @throws SerializationException Throws on deserialization failure. + * Exception may contain inner exceptions detailing failure condition. + */ + public Object deserializeSync(byte[] data) throws SerializationException { + return super.deserialize(data); + + } + + public static class Builder { + private final String registryUrl; + private int maxSchemaMapSize; + private String credential; + private boolean avroSpecificReader; + + public Builder(String registryUrl) { + this.registryUrl = registryUrl; + this.credential = null; + this.avroSpecificReader = false; + this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + } + + public SchemaRegistryAvroDeserializer build() { + return new SchemaRegistryAvroDeserializer(this); + } + + public Builder credential(String credential) { + this.credential = credential; + return this; + } + + public Builder avroSpecificReader(boolean avroSpecificReader) { + this.avroSpecificReader = avroSpecificReader; + return this; + } + + public Builder maxSchemaMapSize(int maxSchemaMapSize) { + this.maxSchemaMapSize = maxSchemaMapSize; + return this; + } + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java b/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java new file mode 100644 index 000000000000..addbe482b899 --- /dev/null +++ b/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import com.azure.schemaregistry.AbstractDataSerializer; +import com.azure.schemaregistry.SerializationException; +import com.azure.schemaregistry.client.CachedSchemaRegistryClient; + +/** + * A serializer implementation capable of serializing objects and automatedly storing serialization schemas + * in the Azure Schema Registry store. + * + * SchemaRegistryAvroSerializer instances should be built using the static Builder class. + * + * Pluggable with the core Azure SDK Serializer interface. + * + * @see AbstractDataSerializer See AbstractDataSerializer for internal serialization implementation + * @see SchemaRegistryAvroSerializer.Builder See Builder for documentation on required parameters + */ +public class SchemaRegistryAvroSerializer extends AbstractDataSerializer { + private SchemaRegistryAvroSerializer(Builder builder) { + super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) + .maxSchemaMapSize(builder.maxSchemaMapSize) + .build()); + + setByteEncoder(new AvroByteEncoder.Builder().build()); + this.serializationFormat = this.byteEncoder.serializationFormat(); + this.autoRegisterSchemas = builder.autoRegisterSchemas; + this.schemaGroup = builder.schemaGroup; + } + + /** + * Serializes object into byte array payload using the configured byte encoder. + * @param object target of serialization + * @return byte array containing GUID reference to schema, then the object serialized into bytes + * @throws SerializationException Throws on serialization failure. + * Exception may contain inner exceptions detailing failure condition. + */ + public byte[] serializeSync(Object object) throws SerializationException { + if (object == null) { + return null; + } + return serializeImpl(object); + } + + public static class Builder { + private final String registryUrl; + private boolean autoRegisterSchemas; + private String credential; + private int maxSchemaMapSize; + private String schemaGroup; + + public Builder(String registryUrl) { + this.registryUrl = registryUrl; + this.credential = null; + this.autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; + this.schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; + this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + } + + public SchemaRegistryAvroSerializer build() { + return new SchemaRegistryAvroSerializer(this); + } + + public Builder schemaGroup(String schemaGroup) { + this.schemaGroup = schemaGroup; + return this; + } + + public Builder credential(String credential) { + this.credential = credential; + return this; + } + + public Builder autoRegisterSchema(boolean autoRegisterSchemas) { + this.autoRegisterSchemas = autoRegisterSchemas; + return this; + } + + public Builder maxSchemaMapSize(int maxSchemaMapSize) { + this.maxSchemaMapSize = maxSchemaMapSize; + return this; + } + } +} + diff --git a/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroDeserializerTest.java b/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroDeserializerTest.java new file mode 100644 index 000000000000..fbd8a9955581 --- /dev/null +++ b/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroDeserializerTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class SchemaRegistryAvroDeserializerTest extends TestCase{ + public SchemaRegistryAvroDeserializerTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(SchemaRegistryAvroDeserializerTest.class); + } + + protected void setUp() { + } + + protected void tearDown() { + } + + public void testShouldAnswerWithTrue() + { + assertTrue( true ); + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroSerializerTest.java b/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroSerializerTest.java new file mode 100644 index 000000000000..e732a9025ada --- /dev/null +++ b/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroSerializerTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class SchemaRegistryAvroSerializerTest extends TestCase{ + public SchemaRegistryAvroSerializerTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(SchemaRegistryAvroSerializerTest.class); + } + + protected void setUp() { + } + + protected void tearDown() { + } + + public void testShouldAnswerWithTrue() + { + assertTrue( true ); + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/kafka/pom.xml b/sdk/schemaregistry/serde/kafka/pom.xml new file mode 100644 index 000000000000..332d3be7aa32 --- /dev/null +++ b/sdk/schemaregistry/serde/kafka/pom.xml @@ -0,0 +1,46 @@ + + + + + 4.0.0 + + + com.azure + schemaregistry-serde + 0.5-preview + + + com.azure + schemaregistry-serde-kafka-avro + 0.5-preview + schemaregistry-serde-kafka-avro + + + + junit + junit + 3.8.1 + test + + + org.apache.kafka + kafka_2.12 + 2.3.1 + + + com.azure + schemaregistry-serde-common + 0.5-preview + + + com.azure + schemaregistry-codec-avro + 0.5-preview + compile + + + diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/AbstractKafkaSerdeConfig.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/AbstractKafkaSerdeConfig.java new file mode 100644 index 000000000000..459eda040d80 --- /dev/null +++ b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/AbstractKafkaSerdeConfig.java @@ -0,0 +1,10 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.kafka.serializers; + +public class AbstractKafkaSerdeConfig { + public static String SCHEMA_REGISTRY_URL_CONFIG = "schema.registry.url"; +} diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializer.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializer.java new file mode 100644 index 000000000000..f44fb9b10fe7 --- /dev/null +++ b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializer.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.kafka.serializers; + +import com.azure.schemaregistry.AbstractDataDeserializer; +import com.azure.schemaregistry.avro.AvroByteDecoder; +import com.azure.schemaregistry.client.CachedSchemaRegistryClient; +import org.apache.kafka.common.errors.SerializationException; +import org.apache.kafka.common.serialization.Deserializer; + +import java.util.Map; + +/** + * Deserializer implementation for Kafka consumer, implementing Kafka Deserializer interface. + * + * Byte arrays are converted into Java objects by using the schema referenced by GUID prefix to deserialize the payload. + * + * Receiving Avro GenericRecords and SpecificRecords is supported. Avro reflection capabilities have been disabled on + * com.azure.schemaregistry.kafka.KafkaAvroSerializer. + * + * @see AbstractDataDeserializer See abstract parent class for implementation details + * @see KafkaAvroSerializer See serializer class for upstream serializer implementation + */ +public class KafkaAvroDeserializer extends AbstractDataDeserializer + implements Deserializer { + + // Constructor used by Kafka consumer. + public KafkaAvroDeserializer() { + super(); + } + + /** + * Configures deserializer instance. + * + * @param props Map of properties used to configure instance + * @param isKey Indicates if deserializing record key or value. Required by Kafka deserializer interface, + * no specific functionality has been implemented for key use. + * + * @see KafkaAvroDeserializerConfig Deserializer will use configs found in here and inherited classes. + */ + @Override + public void configure(Map props, boolean isKey) { + String registryUrl = (String) props.get(KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG); + + Boolean useAvroSpecificReader = (Boolean) props.get(KafkaAvroDeserializerConfig.AVRO_SPECIFIC_READER_CONFIG); + AvroByteDecoder.Builder decoderBuilder = new AvroByteDecoder.Builder(); + if (useAvroSpecificReader != null) { + decoderBuilder = decoderBuilder.avroSpecificReader(useAvroSpecificReader); + } + AvroByteDecoder decoder = decoderBuilder.build(); + this.schemaRegistryClient = new CachedSchemaRegistryClient.Builder(registryUrl) + .loadSchemaParser(decoder.serializationFormat(), (s) -> decoder.parseSchemaString(s)) + .build(); + + this.byteDecoderMap.put(decoder.serializationFormat(), decoder); + } + + /** + * Deserializes byte array into Java object + * @param topic topic associated with the record bytes + * @param bytes serialized bytes, may be null + * @return deserialize object, may be null + * @throws SerializationException catchable by core Kafka fetcher code + */ + @Override + public Object deserialize(String topic, byte[] bytes) throws SerializationException { + try { + return deserialize(bytes); + } catch (com.azure.schemaregistry.SerializationException e) { + throw new SerializationException(e.getCause()); + } + } + + @Override + public void close() { } +} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializerConfig.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializerConfig.java new file mode 100644 index 000000000000..1c112576b582 --- /dev/null +++ b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializerConfig.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.kafka.serializers; + +public class KafkaAvroDeserializerConfig extends AbstractKafkaSerdeConfig { + + /** + * Configures deserializer to look up and decode into SpecificRecord class instance when reading encoded bytes + */ + public static String AVRO_SPECIFIC_READER_CONFIG = "specific.avro.reader"; +} diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializer.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializer.java new file mode 100644 index 000000000000..2b6706f754a6 --- /dev/null +++ b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializer.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.kafka.serializers; + +import com.azure.schemaregistry.AbstractDataSerializer; +import com.azure.schemaregistry.avro.AvroByteEncoder; +import com.azure.schemaregistry.client.CachedSchemaRegistryClient; +import org.apache.kafka.common.errors.SerializationException; +import org.apache.kafka.common.serialization.Serializer; + +import java.util.Map; + +/** + * Serializer implementation for Kafka producer, implementing the Kafka Serializer interface. + * + * Objects are converted to byte arrays containing an Avro-encoded payload and is prefixed with a GUID pointing + * to the matching Avro schema in Azure Schema Registry. + * + * Currently, sending Avro GenericRecords and SpecificRecords is supported. Avro reflection has been disabled. + * + * @see AbstractDataSerializer See abstract parent class for implementation details + * @see KafkaAvroDeserializer See deserializer class for downstream deserializer implementation + */ +public class KafkaAvroSerializer extends AbstractDataSerializer + implements Serializer { + + // Constructor used by Kafka producer. + public KafkaAvroSerializer() { + super(); + } + + /** + * Configures serializer instance. + * + * @param props Map of properties used to configure instance. + * @param isKey Indicates if serializing record key or value. Required by Kafka serializer interface, + * no specific functionality implemented for key use. + * + * @see KafkaAvroSerializerConfig Serializer will use configs found in KafkaAvroSerializerConfig and inherited classes. + */ + @Override + public void configure(Map props, boolean isKey) { + this.byteEncoder = new AvroByteEncoder.Builder().build(); + this.serializationFormat = this.byteEncoder.serializationFormat(); + String registryUrl = (String) props.get(KafkaAvroSerializerConfig.SCHEMA_REGISTRY_URL_CONFIG); + this.schemaRegistryClient = new CachedSchemaRegistryClient.Builder(registryUrl) + .loadSchemaParser(serializationFormat, (s) -> byteEncoder.parseSchemaString(s)) + .build(); + + if (props.containsKey(KafkaAvroSerializerConfig.AUTO_REGISTER_SCHEMAS_CONFIG)) { + this.autoRegisterSchemas = (Boolean)props.get(KafkaAvroSerializerConfig.AUTO_REGISTER_SCHEMAS_CONFIG); + } + + if (props.containsKey(KafkaAvroSerializerConfig.SCHEMA_GROUP_CONFIG)) { + this.schemaGroup = (String) props.get(KafkaAvroSerializerConfig.SCHEMA_GROUP_CONFIG); + } + } + + + /** + * Serializes GenericRecord or SpecificRecord into a byte array, containing a GUID reference to schema + * and the encoded payload. + * + * Null behavior matches Kafka treatment of null values. + * + * @param topic Topic destination for record. Required by Kafka serializer interface, currently not used. + * @param record Object to be serialized, may be null + * @return byte[] payload for sending to EH Kafka service, may be null + * @throws SerializationException Exception catchable by core Kafka producer code + */ + @Override + public byte[] serialize(String topic, Object record) throws SerializationException { + // null needs to treated specially since the client most likely just wants to send + // an individual null value instead of making the subject a null type. Also, null in + // Kafka has a special meaning for deletion in a topic with the compact retention policy. + // Therefore, we will bypass schema registration and return a null value in Kafka, instead + // of an Avro encoded null. + if (record == null) { + return null; + } + + try { + return serializeImpl(record); + } catch (com.azure.schemaregistry.SerializationException e) { + // convert into kafka exception + throw new SerializationException(e.getCause()); + } + } + + @Override + public void close() { } +} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializerConfig.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializerConfig.java new file mode 100644 index 000000000000..c29a41a35a83 --- /dev/null +++ b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializerConfig.java @@ -0,0 +1,11 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.kafka.serializers; + +public class KafkaAvroSerializerConfig extends AbstractKafkaSerdeConfig { + public static String AUTO_REGISTER_SCHEMAS_CONFIG = "auto.register.schemas"; + public static String SCHEMA_GROUP_CONFIG = "schema.group"; +} diff --git a/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroDeserializerTest.java b/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroDeserializerTest.java new file mode 100644 index 000000000000..ad6b177b84a8 --- /dev/null +++ b/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroDeserializerTest.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class KafkaAvroDeserializerTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public KafkaAvroDeserializerTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( KafkaAvroDeserializerTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroSerializerTest.java b/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroSerializerTest.java new file mode 100644 index 000000000000..ba4680e75af8 --- /dev/null +++ b/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroSerializerTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import com.azure.kafka.serializers.KafkaAvroSerializer; +import com.azure.kafka.serializers.KafkaAvroSerializerConfig; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.util.HashMap; +import java.util.Map; + +public class KafkaAvroSerializerTest extends TestCase { + + public KafkaAvroSerializerTest( String testName ) + { + super( testName ); + } + + public static Test suite() + { + return new TestSuite( KafkaAvroSerializerTest.class ); + } + + public void testMinimalConfigShouldNotLeaveNullRequiredFields() + { + KafkaAvroSerializer s = new KafkaAvroSerializer(); + Map props = new HashMap<>(); + props.put(KafkaAvroSerializerConfig.SCHEMA_REGISTRY_URL_CONFIG, "dummy.servicebus.windows.net"); + s.configure(props, false); + assertEquals(AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT, s.autoRegisterSchemas); + assertEquals(AbstractDataSerializer.SCHEMA_GROUP_DEFAULT, s.schemaGroup); + assertEquals(s.byteEncoder.serializationFormat(), s.serializationFormat); + } +} diff --git a/sdk/schemaregistry/serde/pom.xml b/sdk/schemaregistry/serde/pom.xml new file mode 100644 index 000000000000..6e89bcf5cf87 --- /dev/null +++ b/sdk/schemaregistry/serde/pom.xml @@ -0,0 +1,42 @@ + + + + + 4.0.0 + + + com.azure + schemaregistry-parent + 0.5-preview + + + com.azure + schemaregistry-serde + pom + 0.5-preview + schemaregistry-serde + + + common + generic-avro + kafka + + + + + com.azure + schemaregistry-client + 0.5-preview + compile + + + junit + junit + test + + + \ No newline at end of file From 4e94edfd3863ce656887c0af5b5bb37eb8e14d19 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Fri, 1 May 2020 11:34:33 -0700 Subject: [PATCH 02/43] remove kafka --- sdk/schemaregistry/.gitignore | 49 ---------- sdk/schemaregistry/client/pom.xml | 5 - sdk/schemaregistry/codec/codec-avro/pom.xml | 6 -- sdk/schemaregistry/codec/pom.xml | 5 - sdk/schemaregistry/serde/kafka/pom.xml | 46 --------- .../serializers/AbstractKafkaSerdeConfig.java | 10 -- .../serializers/KafkaAvroDeserializer.java | 79 --------------- .../KafkaAvroDeserializerConfig.java | 14 --- .../serializers/KafkaAvroSerializer.java | 95 ------------------- .../KafkaAvroSerializerConfig.java | 11 --- .../KafkaAvroDeserializerTest.java | 43 --------- .../KafkaAvroSerializerTest.java | 39 -------- sdk/schemaregistry/serde/pom.xml | 3 +- 13 files changed, 1 insertion(+), 404 deletions(-) delete mode 100644 sdk/schemaregistry/.gitignore delete mode 100644 sdk/schemaregistry/serde/kafka/pom.xml delete mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/AbstractKafkaSerdeConfig.java delete mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializer.java delete mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializerConfig.java delete mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializer.java delete mode 100644 sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializerConfig.java delete mode 100644 sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroDeserializerTest.java delete mode 100644 sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroSerializerTest.java diff --git a/sdk/schemaregistry/.gitignore b/sdk/schemaregistry/.gitignore deleted file mode 100644 index 4f6742eed8ef..000000000000 --- a/sdk/schemaregistry/.gitignore +++ /dev/null @@ -1,49 +0,0 @@ -# Compiled class file -*.class -*.classpath - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -.vscode/ -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -target/ -.project -.idea/ -.settings/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -# https://github.com/takari/maven-wrapper#usage-without-binary-jar -.mvn/wrapper/maven-wrapper.jar - -*.iml -.DS_Store diff --git a/sdk/schemaregistry/client/pom.xml b/sdk/schemaregistry/client/pom.xml index 82ebe3c33b92..ca97b7c68a60 100644 --- a/sdk/schemaregistry/client/pom.xml +++ b/sdk/schemaregistry/client/pom.xml @@ -18,11 +18,6 @@ 0.5-preview schemaregistry-client - - 1.8 - 1.8 - - junit diff --git a/sdk/schemaregistry/codec/codec-avro/pom.xml b/sdk/schemaregistry/codec/codec-avro/pom.xml index c55062ca315a..85af7f5c985c 100644 --- a/sdk/schemaregistry/codec/codec-avro/pom.xml +++ b/sdk/schemaregistry/codec/codec-avro/pom.xml @@ -21,12 +21,6 @@ schemaregistry-codec-avro - - UTF-8 - 1.8 - 1.8 - - junit diff --git a/sdk/schemaregistry/codec/pom.xml b/sdk/schemaregistry/codec/pom.xml index 9c308963554c..394a325dd5fb 100644 --- a/sdk/schemaregistry/codec/pom.xml +++ b/sdk/schemaregistry/codec/pom.xml @@ -20,11 +20,6 @@ 0.5-preview schemaregistry-codec - - 1.8 - 1.8 - - codec-avro diff --git a/sdk/schemaregistry/serde/kafka/pom.xml b/sdk/schemaregistry/serde/kafka/pom.xml deleted file mode 100644 index 332d3be7aa32..000000000000 --- a/sdk/schemaregistry/serde/kafka/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - 4.0.0 - - - com.azure - schemaregistry-serde - 0.5-preview - - - com.azure - schemaregistry-serde-kafka-avro - 0.5-preview - schemaregistry-serde-kafka-avro - - - - junit - junit - 3.8.1 - test - - - org.apache.kafka - kafka_2.12 - 2.3.1 - - - com.azure - schemaregistry-serde-common - 0.5-preview - - - com.azure - schemaregistry-codec-avro - 0.5-preview - compile - - - diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/AbstractKafkaSerdeConfig.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/AbstractKafkaSerdeConfig.java deleted file mode 100644 index 459eda040d80..000000000000 --- a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/AbstractKafkaSerdeConfig.java +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.kafka.serializers; - -public class AbstractKafkaSerdeConfig { - public static String SCHEMA_REGISTRY_URL_CONFIG = "schema.registry.url"; -} diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializer.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializer.java deleted file mode 100644 index f44fb9b10fe7..000000000000 --- a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializer.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.kafka.serializers; - -import com.azure.schemaregistry.AbstractDataDeserializer; -import com.azure.schemaregistry.avro.AvroByteDecoder; -import com.azure.schemaregistry.client.CachedSchemaRegistryClient; -import org.apache.kafka.common.errors.SerializationException; -import org.apache.kafka.common.serialization.Deserializer; - -import java.util.Map; - -/** - * Deserializer implementation for Kafka consumer, implementing Kafka Deserializer interface. - * - * Byte arrays are converted into Java objects by using the schema referenced by GUID prefix to deserialize the payload. - * - * Receiving Avro GenericRecords and SpecificRecords is supported. Avro reflection capabilities have been disabled on - * com.azure.schemaregistry.kafka.KafkaAvroSerializer. - * - * @see AbstractDataDeserializer See abstract parent class for implementation details - * @see KafkaAvroSerializer See serializer class for upstream serializer implementation - */ -public class KafkaAvroDeserializer extends AbstractDataDeserializer - implements Deserializer { - - // Constructor used by Kafka consumer. - public KafkaAvroDeserializer() { - super(); - } - - /** - * Configures deserializer instance. - * - * @param props Map of properties used to configure instance - * @param isKey Indicates if deserializing record key or value. Required by Kafka deserializer interface, - * no specific functionality has been implemented for key use. - * - * @see KafkaAvroDeserializerConfig Deserializer will use configs found in here and inherited classes. - */ - @Override - public void configure(Map props, boolean isKey) { - String registryUrl = (String) props.get(KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG); - - Boolean useAvroSpecificReader = (Boolean) props.get(KafkaAvroDeserializerConfig.AVRO_SPECIFIC_READER_CONFIG); - AvroByteDecoder.Builder decoderBuilder = new AvroByteDecoder.Builder(); - if (useAvroSpecificReader != null) { - decoderBuilder = decoderBuilder.avroSpecificReader(useAvroSpecificReader); - } - AvroByteDecoder decoder = decoderBuilder.build(); - this.schemaRegistryClient = new CachedSchemaRegistryClient.Builder(registryUrl) - .loadSchemaParser(decoder.serializationFormat(), (s) -> decoder.parseSchemaString(s)) - .build(); - - this.byteDecoderMap.put(decoder.serializationFormat(), decoder); - } - - /** - * Deserializes byte array into Java object - * @param topic topic associated with the record bytes - * @param bytes serialized bytes, may be null - * @return deserialize object, may be null - * @throws SerializationException catchable by core Kafka fetcher code - */ - @Override - public Object deserialize(String topic, byte[] bytes) throws SerializationException { - try { - return deserialize(bytes); - } catch (com.azure.schemaregistry.SerializationException e) { - throw new SerializationException(e.getCause()); - } - } - - @Override - public void close() { } -} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializerConfig.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializerConfig.java deleted file mode 100644 index 1c112576b582..000000000000 --- a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroDeserializerConfig.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.kafka.serializers; - -public class KafkaAvroDeserializerConfig extends AbstractKafkaSerdeConfig { - - /** - * Configures deserializer to look up and decode into SpecificRecord class instance when reading encoded bytes - */ - public static String AVRO_SPECIFIC_READER_CONFIG = "specific.avro.reader"; -} diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializer.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializer.java deleted file mode 100644 index 2b6706f754a6..000000000000 --- a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializer.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.kafka.serializers; - -import com.azure.schemaregistry.AbstractDataSerializer; -import com.azure.schemaregistry.avro.AvroByteEncoder; -import com.azure.schemaregistry.client.CachedSchemaRegistryClient; -import org.apache.kafka.common.errors.SerializationException; -import org.apache.kafka.common.serialization.Serializer; - -import java.util.Map; - -/** - * Serializer implementation for Kafka producer, implementing the Kafka Serializer interface. - * - * Objects are converted to byte arrays containing an Avro-encoded payload and is prefixed with a GUID pointing - * to the matching Avro schema in Azure Schema Registry. - * - * Currently, sending Avro GenericRecords and SpecificRecords is supported. Avro reflection has been disabled. - * - * @see AbstractDataSerializer See abstract parent class for implementation details - * @see KafkaAvroDeserializer See deserializer class for downstream deserializer implementation - */ -public class KafkaAvroSerializer extends AbstractDataSerializer - implements Serializer { - - // Constructor used by Kafka producer. - public KafkaAvroSerializer() { - super(); - } - - /** - * Configures serializer instance. - * - * @param props Map of properties used to configure instance. - * @param isKey Indicates if serializing record key or value. Required by Kafka serializer interface, - * no specific functionality implemented for key use. - * - * @see KafkaAvroSerializerConfig Serializer will use configs found in KafkaAvroSerializerConfig and inherited classes. - */ - @Override - public void configure(Map props, boolean isKey) { - this.byteEncoder = new AvroByteEncoder.Builder().build(); - this.serializationFormat = this.byteEncoder.serializationFormat(); - String registryUrl = (String) props.get(KafkaAvroSerializerConfig.SCHEMA_REGISTRY_URL_CONFIG); - this.schemaRegistryClient = new CachedSchemaRegistryClient.Builder(registryUrl) - .loadSchemaParser(serializationFormat, (s) -> byteEncoder.parseSchemaString(s)) - .build(); - - if (props.containsKey(KafkaAvroSerializerConfig.AUTO_REGISTER_SCHEMAS_CONFIG)) { - this.autoRegisterSchemas = (Boolean)props.get(KafkaAvroSerializerConfig.AUTO_REGISTER_SCHEMAS_CONFIG); - } - - if (props.containsKey(KafkaAvroSerializerConfig.SCHEMA_GROUP_CONFIG)) { - this.schemaGroup = (String) props.get(KafkaAvroSerializerConfig.SCHEMA_GROUP_CONFIG); - } - } - - - /** - * Serializes GenericRecord or SpecificRecord into a byte array, containing a GUID reference to schema - * and the encoded payload. - * - * Null behavior matches Kafka treatment of null values. - * - * @param topic Topic destination for record. Required by Kafka serializer interface, currently not used. - * @param record Object to be serialized, may be null - * @return byte[] payload for sending to EH Kafka service, may be null - * @throws SerializationException Exception catchable by core Kafka producer code - */ - @Override - public byte[] serialize(String topic, Object record) throws SerializationException { - // null needs to treated specially since the client most likely just wants to send - // an individual null value instead of making the subject a null type. Also, null in - // Kafka has a special meaning for deletion in a topic with the compact retention policy. - // Therefore, we will bypass schema registration and return a null value in Kafka, instead - // of an Avro encoded null. - if (record == null) { - return null; - } - - try { - return serializeImpl(record); - } catch (com.azure.schemaregistry.SerializationException e) { - // convert into kafka exception - throw new SerializationException(e.getCause()); - } - } - - @Override - public void close() { } -} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializerConfig.java b/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializerConfig.java deleted file mode 100644 index c29a41a35a83..000000000000 --- a/sdk/schemaregistry/serde/kafka/src/main/java/com/azure/kafka/serializers/KafkaAvroSerializerConfig.java +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.kafka.serializers; - -public class KafkaAvroSerializerConfig extends AbstractKafkaSerdeConfig { - public static String AUTO_REGISTER_SCHEMAS_CONFIG = "auto.register.schemas"; - public static String SCHEMA_GROUP_CONFIG = "schema.group"; -} diff --git a/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroDeserializerTest.java b/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroDeserializerTest.java deleted file mode 100644 index ad6b177b84a8..000000000000 --- a/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroDeserializerTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class KafkaAvroDeserializerTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public KafkaAvroDeserializerTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( KafkaAvroDeserializerTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} diff --git a/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroSerializerTest.java b/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroSerializerTest.java deleted file mode 100644 index ba4680e75af8..000000000000 --- a/sdk/schemaregistry/serde/kafka/src/test/java/com/azure/schemaregistry/KafkaAvroSerializerTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry; - -import com.azure.kafka.serializers.KafkaAvroSerializer; -import com.azure.kafka.serializers.KafkaAvroSerializerConfig; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import java.util.HashMap; -import java.util.Map; - -public class KafkaAvroSerializerTest extends TestCase { - - public KafkaAvroSerializerTest( String testName ) - { - super( testName ); - } - - public static Test suite() - { - return new TestSuite( KafkaAvroSerializerTest.class ); - } - - public void testMinimalConfigShouldNotLeaveNullRequiredFields() - { - KafkaAvroSerializer s = new KafkaAvroSerializer(); - Map props = new HashMap<>(); - props.put(KafkaAvroSerializerConfig.SCHEMA_REGISTRY_URL_CONFIG, "dummy.servicebus.windows.net"); - s.configure(props, false); - assertEquals(AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT, s.autoRegisterSchemas); - assertEquals(AbstractDataSerializer.SCHEMA_GROUP_DEFAULT, s.schemaGroup); - assertEquals(s.byteEncoder.serializationFormat(), s.serializationFormat); - } -} diff --git a/sdk/schemaregistry/serde/pom.xml b/sdk/schemaregistry/serde/pom.xml index 6e89bcf5cf87..384bb590f538 100644 --- a/sdk/schemaregistry/serde/pom.xml +++ b/sdk/schemaregistry/serde/pom.xml @@ -23,7 +23,6 @@ common generic-avro - kafka @@ -39,4 +38,4 @@ test - \ No newline at end of file + From 54d5ad837bedb3b753f770a300ad1c1a218c9848 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 7 May 2020 17:21:48 -0700 Subject: [PATCH 03/43] azure- artifact ids --- sdk/schemaregistry/client/pom.xml | 6 +++--- sdk/schemaregistry/codec/codec-avro/pom.xml | 11 ++++------- sdk/schemaregistry/codec/pom.xml | 6 +++--- sdk/schemaregistry/pom.xml | 10 +++++----- sdk/schemaregistry/serde/common/pom.xml | 8 ++++---- sdk/schemaregistry/serde/generic-avro/pom.xml | 10 +++++----- sdk/schemaregistry/serde/pom.xml | 8 ++++---- 7 files changed, 28 insertions(+), 31 deletions(-) diff --git a/sdk/schemaregistry/client/pom.xml b/sdk/schemaregistry/client/pom.xml index ca97b7c68a60..808d32ddda24 100644 --- a/sdk/schemaregistry/client/pom.xml +++ b/sdk/schemaregistry/client/pom.xml @@ -9,14 +9,14 @@ com.azure - schemaregistry-parent + azure-schemaregistry-parent 0.5-preview - schemaregistry-client + azure-schemaregistry-client jar 0.5-preview - schemaregistry-client + azure-schemaregistry-client diff --git a/sdk/schemaregistry/codec/codec-avro/pom.xml b/sdk/schemaregistry/codec/codec-avro/pom.xml index 85af7f5c985c..e0a7d433ca88 100644 --- a/sdk/schemaregistry/codec/codec-avro/pom.xml +++ b/sdk/schemaregistry/codec/codec-avro/pom.xml @@ -11,22 +11,19 @@ com.azure - schemaregistry-codec + azure-schemaregistry-codec 0.5-preview com.azure - schemaregistry-codec-avro + azure-schemaregistry-codec-avro 0.5-preview - - schemaregistry-codec-avro + azure-schemaregistry-codec-avro junit junit - 4.11 - test org.apache.avro @@ -35,7 +32,7 @@ com.azure - schemaregistry-serde-common + azure-schemaregistry-serde-common 0.5-preview compile diff --git a/sdk/schemaregistry/codec/pom.xml b/sdk/schemaregistry/codec/pom.xml index 394a325dd5fb..cf82181d7a5e 100644 --- a/sdk/schemaregistry/codec/pom.xml +++ b/sdk/schemaregistry/codec/pom.xml @@ -10,15 +10,15 @@ com.azure - schemaregistry-parent + azure-schemaregistry-parent 0.5-preview com.azure - schemaregistry-codec + azure-schemaregistry-codec pom 0.5-preview - schemaregistry-codec + azure-schemaregistry-codec codec-avro diff --git a/sdk/schemaregistry/pom.xml b/sdk/schemaregistry/pom.xml index 186e4e3bc1c4..c6954363859f 100644 --- a/sdk/schemaregistry/pom.xml +++ b/sdk/schemaregistry/pom.xml @@ -10,9 +10,9 @@ com.azure 0.5-preview - schemaregistry-parent + azure-schemaregistry-parent pom - schemaregistry-parent + azure-schemaregistry-parent client @@ -29,9 +29,9 @@ - org.slf4j - slf4j-api - 1.7.30 + com.azure + azure-core + 0.9.8 compile diff --git a/sdk/schemaregistry/serde/common/pom.xml b/sdk/schemaregistry/serde/common/pom.xml index 9e6e0755fde6..9efd555f8376 100644 --- a/sdk/schemaregistry/serde/common/pom.xml +++ b/sdk/schemaregistry/serde/common/pom.xml @@ -9,13 +9,13 @@ com.azure - schemaregistry-serde + azure-schemaregistry-serde 0.5-preview - schemaregistry-serde-common + azure-schemaregistry-serde-common jar - schemaregistry-serde-common + azure-schemaregistry-serde-common @@ -31,7 +31,7 @@ com.azure - schemaregistry-client + azure-schemaregistry-client 0.5-preview diff --git a/sdk/schemaregistry/serde/generic-avro/pom.xml b/sdk/schemaregistry/serde/generic-avro/pom.xml index a8a617e888b2..64bcd02bb26b 100644 --- a/sdk/schemaregistry/serde/generic-avro/pom.xml +++ b/sdk/schemaregistry/serde/generic-avro/pom.xml @@ -10,13 +10,13 @@ com.azure - schemaregistry-serde + azure-schemaregistry-serde 0.5-preview com.azure - schemaregistry-serde-avro - schemaregistry-serde-avro + azure-schemaregistry-serde-avro + azure-schemaregistry-serde-avro @@ -27,12 +27,12 @@ com.azure - schemaregistry-serde-common + azure-schemaregistry-serde-common 0.5-preview com.azure - schemaregistry-codec-avro + azure-schemaregistry-codec-avro 0.5-preview compile diff --git a/sdk/schemaregistry/serde/pom.xml b/sdk/schemaregistry/serde/pom.xml index 384bb590f538..0d4c68b58cbe 100644 --- a/sdk/schemaregistry/serde/pom.xml +++ b/sdk/schemaregistry/serde/pom.xml @@ -10,15 +10,15 @@ com.azure - schemaregistry-parent + azure-schemaregistry-parent 0.5-preview com.azure - schemaregistry-serde + azure-schemaregistry-serde pom 0.5-preview - schemaregistry-serde + azure-schemaregistry-serde common @@ -28,7 +28,7 @@ com.azure - schemaregistry-client + azure-schemaregistry-client 0.5-preview compile From 98ce87d6e289725830d190e2b71c71e0ec7bc4f1 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 7 May 2020 17:47:12 -0700 Subject: [PATCH 04/43] azure-core + version change --- sdk/schemaregistry/client/pom.xml | 17 ++++------- sdk/schemaregistry/codec/codec-avro/pom.xml | 6 ++-- sdk/schemaregistry/codec/pom.xml | 8 +++-- sdk/schemaregistry/pom.xml | 5 ++-- sdk/schemaregistry/serde/common/pom.xml | 4 +-- sdk/schemaregistry/serde/generic-avro/pom.xml | 6 ++-- sdk/schemaregistry/serde/pom.xml | 30 +++++++++++-------- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/sdk/schemaregistry/client/pom.xml b/sdk/schemaregistry/client/pom.xml index 808d32ddda24..a59b7cdc34fe 100644 --- a/sdk/schemaregistry/client/pom.xml +++ b/sdk/schemaregistry/client/pom.xml @@ -10,12 +10,12 @@ com.azure azure-schemaregistry-parent - 0.5-preview + 1.0.0-beta.1 azure-schemaregistry-client jar - 0.5-preview + 1.0.0-beta.1 azure-schemaregistry-client @@ -25,20 +25,15 @@ 3.8.1 test + + com.azure + azure-core + org.easymock easymock 4.1 test - - com.fasterxml.jackson.core - jackson-databind - 2.10.2 - - - org.slf4j - slf4j-api - diff --git a/sdk/schemaregistry/codec/codec-avro/pom.xml b/sdk/schemaregistry/codec/codec-avro/pom.xml index e0a7d433ca88..ab1524b60d42 100644 --- a/sdk/schemaregistry/codec/codec-avro/pom.xml +++ b/sdk/schemaregistry/codec/codec-avro/pom.xml @@ -12,12 +12,12 @@ com.azure azure-schemaregistry-codec - 0.5-preview + 1.0.0-beta.1 com.azure azure-schemaregistry-codec-avro - 0.5-preview + 1.0.0-beta.1 azure-schemaregistry-codec-avro @@ -33,7 +33,7 @@ com.azure azure-schemaregistry-serde-common - 0.5-preview + 1.0.0-beta.1 compile diff --git a/sdk/schemaregistry/codec/pom.xml b/sdk/schemaregistry/codec/pom.xml index cf82181d7a5e..e34d90e7dd25 100644 --- a/sdk/schemaregistry/codec/pom.xml +++ b/sdk/schemaregistry/codec/pom.xml @@ -11,13 +11,13 @@ com.azure azure-schemaregistry-parent - 0.5-preview + 1.0.0-beta.1 com.azure azure-schemaregistry-codec pom - 0.5-preview + 1.0.0-beta.1 azure-schemaregistry-codec @@ -25,6 +25,10 @@ + + com.azure + azure-core + junit junit diff --git a/sdk/schemaregistry/pom.xml b/sdk/schemaregistry/pom.xml index c6954363859f..a988c54b2237 100644 --- a/sdk/schemaregistry/pom.xml +++ b/sdk/schemaregistry/pom.xml @@ -9,7 +9,7 @@ 4.0.0 com.azure - 0.5-preview + 1.0.0-beta.1 azure-schemaregistry-parent pom azure-schemaregistry-parent @@ -31,8 +31,7 @@ com.azure azure-core - 0.9.8 - compile + 1.5.0 junit diff --git a/sdk/schemaregistry/serde/common/pom.xml b/sdk/schemaregistry/serde/common/pom.xml index 9efd555f8376..986bef8a9d80 100644 --- a/sdk/schemaregistry/serde/common/pom.xml +++ b/sdk/schemaregistry/serde/common/pom.xml @@ -10,7 +10,7 @@ com.azure azure-schemaregistry-serde - 0.5-preview + 1.0.0-beta.1 azure-schemaregistry-serde-common @@ -32,7 +32,7 @@ com.azure azure-schemaregistry-client - 0.5-preview + 1.0.0-beta.1 com.fasterxml.jackson.core diff --git a/sdk/schemaregistry/serde/generic-avro/pom.xml b/sdk/schemaregistry/serde/generic-avro/pom.xml index 64bcd02bb26b..0cf601b271a1 100644 --- a/sdk/schemaregistry/serde/generic-avro/pom.xml +++ b/sdk/schemaregistry/serde/generic-avro/pom.xml @@ -11,7 +11,7 @@ com.azure azure-schemaregistry-serde - 0.5-preview + 1.0.0-beta.1 com.azure @@ -28,12 +28,12 @@ com.azure azure-schemaregistry-serde-common - 0.5-preview + 1.0.0-beta.1 com.azure azure-schemaregistry-codec-avro - 0.5-preview + 1.0.0-beta.1 compile diff --git a/sdk/schemaregistry/serde/pom.xml b/sdk/schemaregistry/serde/pom.xml index 0d4c68b58cbe..0c50934e8503 100644 --- a/sdk/schemaregistry/serde/pom.xml +++ b/sdk/schemaregistry/serde/pom.xml @@ -11,13 +11,13 @@ com.azure azure-schemaregistry-parent - 0.5-preview + 1.0.0-beta.1 com.azure azure-schemaregistry-serde pom - 0.5-preview + 1.0.0-beta.1 azure-schemaregistry-serde @@ -26,16 +26,20 @@ - - com.azure - azure-schemaregistry-client - 0.5-preview - compile - - - junit - junit - test - + + com.azure + azure-core + + + com.azure + azure-schemaregistry-client + 1.0.0-beta.1 + compile + + + junit + junit + test + From 21b663dd43d0355c9411d56a0bc62e4e3609b52a Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Tue, 12 May 2020 11:29:25 -0700 Subject: [PATCH 05/43] progress snapshot before swapping autorest client --- eng/versioning/external_dependencies.txt | 1 + .../pom.xml | 37 ++++++-- .../client/CachedSchemaRegistryClient.java | 31 ++++--- .../client/MockSchemaRegistryClient.java | 30 +++---- .../client/SchemaRegistryClient.java | 30 +++---- .../client/SchemaRegistryClientException.java | 0 .../client/SchemaRegistryObject.java} | 6 +- .../schemaregistry/client/package-info.java | 4 + .../client/rest/RestService.java | 1 + .../client/rest/entities/ErrorMessage.java | 0 .../responses/RegisterSchemaResponse.java | 0 .../responses/SchemaObjectResponse.java | 0 .../rest/exceptions/RestClientException.java | 0 .../CachedSchemaRegistryClientTest.java | 24 ++--- .../client/RestServiceTest.java | 0 .../azure-schemaregistry-serde-avro/pom.xml | 79 ++++++++++++++++ .../schemaregistry/avro/AvroByteDecoder.java | 0 .../schemaregistry/avro/AvroByteEncoder.java | 0 .../azure/schemaregistry/avro/AvroCodec.java | 0 .../schemaregistry/avro/AvroSchemaUtils.java | 0 .../SchemaRegistryAvroAsyncDeserializer.java | 83 +++++++++++++++++ .../SchemaRegistryAvroAsyncSerializer.java | 51 +++++++++++ ...emaRegistryAvroAsyncSerializerBuilder.java | 73 +++++++++++++++ .../SchemaRegistryAvroSyncDeserializer.java} | 18 ++-- .../SchemaRegistryAvroSyncSerializer.java} | 12 +-- .../avro/AvroByteDecoderTest.java | 0 .../avro/AvroByteEncoderTest.java | 0 .../azure-schemaregistry-serde-common/pom.xml | 89 +++++++++++++++++++ .../AbstractDataDeserializer.java | 33 ++----- .../schemaregistry/AbstractDataSerDe.java | 0 .../AbstractDataSerializer.java | 42 +-------- .../com/azure/schemaregistry/ByteDecoder.java | 0 .../com/azure/schemaregistry/ByteEncoder.java | 0 .../java/com/azure/schemaregistry/Codec.java | 0 .../SerializationException.java | 0 .../AbstractDataDeserializerTest.java | 8 +- .../AbstractDataSerializerTest.java | 8 +- .../schemaregistry/SampleByteDecoder.java | 0 .../schemaregistry/SampleByteEncoder.java | 0 .../schemaregistry/TestDummyDeserializer.java | 0 .../schemaregistry/TestDummySerializer.java | 0 sdk/schemaregistry/codec/codec-avro/pom.xml | 41 --------- sdk/schemaregistry/codec/pom.xml | 39 -------- sdk/schemaregistry/pom.xml | 41 ++------- sdk/schemaregistry/serde/common/pom.xml | 59 ------------ sdk/schemaregistry/serde/generic-avro/pom.xml | 40 --------- .../SchemaRegistryAvroDeserializerTest.java | 31 ------- .../SchemaRegistryAvroSerializerTest.java | 31 ------- sdk/schemaregistry/serde/pom.xml | 45 ---------- 49 files changed, 510 insertions(+), 477 deletions(-) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/pom.xml (51%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java (91%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java (79%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java (73%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java (100%) rename sdk/schemaregistry/{client/src/main/java/com/azure/schemaregistry/client/SRObject.java => azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java} (96%) create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/main/java/com/azure/schemaregistry/client/rest/RestService.java (99%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java (100%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java (100%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java (100%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java (100%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java (93%) rename sdk/schemaregistry/{client => azure-schemaregistry-client}/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java (100%) create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml rename sdk/schemaregistry/{codec/codec-avro => azure-schemaregistry-serde-avro}/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java (100%) rename sdk/schemaregistry/{codec/codec-avro => azure-schemaregistry-serde-avro}/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java (100%) rename sdk/schemaregistry/{codec/codec-avro => azure-schemaregistry-serde-avro}/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java (100%) rename sdk/schemaregistry/{codec/codec-avro => azure-schemaregistry-serde-avro}/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java (100%) create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializerBuilder.java rename sdk/schemaregistry/{serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java => azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncDeserializer.java} (81%) rename sdk/schemaregistry/{serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java => azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncSerializer.java} (86%) rename sdk/schemaregistry/{codec/codec-avro => azure-schemaregistry-serde-avro}/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java (100%) rename sdk/schemaregistry/{codec/codec-avro => azure-schemaregistry-serde-avro}/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java (100%) create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java (74%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java (100%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java (74%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/main/java/com/azure/schemaregistry/ByteDecoder.java (100%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/main/java/com/azure/schemaregistry/ByteEncoder.java (100%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/main/java/com/azure/schemaregistry/Codec.java (100%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/main/java/com/azure/schemaregistry/SerializationException.java (100%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java (95%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java (94%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java (100%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java (100%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java (100%) rename sdk/schemaregistry/{serde/common => azure-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/TestDummySerializer.java (100%) delete mode 100644 sdk/schemaregistry/codec/codec-avro/pom.xml delete mode 100644 sdk/schemaregistry/codec/pom.xml delete mode 100644 sdk/schemaregistry/serde/common/pom.xml delete mode 100644 sdk/schemaregistry/serde/generic-avro/pom.xml delete mode 100644 sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroDeserializerTest.java delete mode 100644 sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroSerializerTest.java delete mode 100644 sdk/schemaregistry/serde/pom.xml diff --git a/eng/versioning/external_dependencies.txt b/eng/versioning/external_dependencies.txt index 07ba36ba999b..89cfbd7f7aad 100644 --- a/eng/versioning/external_dependencies.txt +++ b/eng/versioning/external_dependencies.txt @@ -40,6 +40,7 @@ io.reactivex:rxjava;1.2.4 javax.annotation:javax.annotation-api;1.3.2 javax.servlet:javax.servlet-api;4.0.1 javax.validation:validation-api;2.0.1.Final +org.apache.avro:avro;1.9.2 org.apache.httpcomponents:httpclient;4.3.6 org.apache.logging.log4j:log4j-api;2.11.1 org.apache.logging.log4j:log4j-core;2.11.1 diff --git a/sdk/schemaregistry/client/pom.xml b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml similarity index 51% rename from sdk/schemaregistry/client/pom.xml rename to sdk/schemaregistry/azure-schemaregistry-client/pom.xml index a59b7cdc34fe..48e846820881 100644 --- a/sdk/schemaregistry/client/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml @@ -9,26 +9,47 @@ com.azure - azure-schemaregistry-parent - 1.0.0-beta.1 + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent azure-schemaregistry-client jar 1.0.0-beta.1 - azure-schemaregistry-client + + Microsoft Azure Schema Registry - REST Client + REST client implementation for Azure Schema Registry + https://github.com/Azure/azure-sdk-for-java + + + + azure-java-build-docs + ${site.url}/site/${project.artifactId} + + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + com.azure + azure-core + 1.5.0 + + + junit junit - 3.8.1 + 4.12 test - - com.azure - azure-core - org.easymock easymock diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java similarity index 91% rename from sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index 34c5ab92610e..5b3dab65eb7a 100644 --- a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -23,8 +23,8 @@ * * Max HashMap size can be configured when instantiating. * Two maps are maintained - - * - SRObject cache by GUID - accessed when consuming, store GUIDs previously seen in payloads - * - SRObject cache by schema string - accessed when sending, minimizes HTTP calls when payloads of same schema + * - SchemaRegistryObject cache by GUID - accessed when consuming, store GUIDs previously seen in payloads + * - SchemaRegistryObject cache by schema string - accessed when sending, minimizes HTTP calls when payloads of same schema * * TODO: implement max age for schema maps? or will schemas always be immutable? * @@ -40,9 +40,9 @@ public class CachedSchemaRegistryClient implements SchemaRegistryClient { private int maxSchemaMapSize; private final RestService restService; private final HashMap> typeParserDictionary; - - private HashMap> guidCache; - private HashMap> schemaStringCache; + + private HashMap> guidCache; + private HashMap> schemaStringCache; private CachedSchemaRegistryClient( String registryUrl, @@ -64,8 +64,8 @@ private CachedSchemaRegistryClient( // testing CachedSchemaRegistryClient( RestService restService, - HashMap> guidCache, - HashMap> schemaStringCache, + HashMap> guidCache, + HashMap> schemaStringCache, HashMap> typeParserDictionary) { this.restService = restService; // mockable this.guidCache = guidCache; @@ -85,7 +85,7 @@ public synchronized void loadSchemaParser(String serializationType, Function register(String schemaGroup, String schemaName, String schemaString, String serializationType) + public synchronized SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { log.debug(String.format("Cache hit schema string. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", @@ -103,8 +103,7 @@ public synchronized SRObject register(String schemaGroup, String schemaName, throw new SchemaRegistryClientException("Schema registration failed.", e); } - - SRObject registered = new SRObject<>(schemaGuid, + SchemaRegistryObject registered = new SchemaRegistryObject<>(schemaGuid, serializationType, schemaString.getBytes(RestService.SERVICE_CHARSET), getParseFunc(serializationType)); @@ -116,7 +115,7 @@ public synchronized SRObject register(String schemaGroup, String schemaName, } @Override - public synchronized SRObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException { + public synchronized SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException { if (guidCache.containsKey(schemaGuid)) { log.debug(String.format("Cache hit for schema guid '%s'", schemaGuid)); return guidCache.get(schemaGuid); @@ -128,8 +127,8 @@ public synchronized SRObject getSchemaByGuid(String schemaGuid) throws IOExce } catch (RestClientException e) { throw new SchemaRegistryClientException(String.format("Failed to get schema for guid %s.", schemaGuid), e); } - - SRObject schemaObject = new SRObject<>(response.schemaGuid, + + SchemaRegistryObject schemaObject = new SchemaRegistryObject<>(response.schemaGuid, response.serializationType, response.schemaByteArray, getParseFunc(response.serializationType)); @@ -161,14 +160,14 @@ public synchronized String getGuid(String schemaGroup, String schemaName, String resetIfNeeded(); schemaStringCache.put( schemaString, - new SRObject<>( + new SchemaRegistryObject<>( schemaGuid, serializationType, schemaString.getBytes(RestService.SERVICE_CHARSET), getParseFunc(serializationType))); log.debug(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); return schemaGuid; - } + } @Override public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) throws IOException, SchemaRegistryClientException { @@ -266,4 +265,4 @@ public Builder loadSchemaParser(String serializationType, Function> typeParserDictionary; - - public final HashMap> guidCache; - public final HashMap> schemaStringCache; - + + public final HashMap> guidCache; + public final HashMap> schemaStringCache; + public MockSchemaRegistryClient() { - this.guidCache = new HashMap>(); - this.schemaStringCache = new HashMap>(); + this.guidCache = new HashMap>(); + this.schemaStringCache = new HashMap>(); this.typeParserDictionary = new HashMap>(); } public void loadSchemaParser(String serializationFormat, Function f) {} @Override - public SRObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { return schemaStringCache.get(schemaString); - } - + } + return null; } - + @Override - public SRObject getSchemaByGuid(String schemaGuid) + public SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException { if (guidCache.containsKey(schemaGuid)) { return guidCache.get(schemaGuid); @@ -51,7 +51,7 @@ public String getGuid(String schemaGroup, String schemaName, String schemaString if (schemaStringCache.containsKey(schemaString)) { return schemaStringCache.get(schemaString).schemaGuid; } - + return null; } @@ -71,5 +71,5 @@ public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) public List deleteSchema(String schemaGroup, String schemaName) throws IOException, SchemaRegistryClientException { return new ArrayList(); - } -} \ No newline at end of file + } +} diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java similarity index 73% rename from sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java index ecc66a07c707..73c05e626dc0 100644 --- a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java @@ -29,11 +29,11 @@ public interface SchemaRegistryClient { * @param schemaName schema name * @param schemaString string representation of schema * @param serializationType string representation of serialization format type - * @return SRObject containing information regarding registered schema. - * @throws IOException + * @return SchemaRegistryObject containing information regarding registered schema. * @throws SchemaRegistryClientException if registration operation fails + * @throws IOException failed or interrupted I/O operation */ - public SRObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, SchemaRegistryClientException; /** @@ -42,11 +42,11 @@ public SRObject register(String schemaGroup, String schemaName, String schema * GUID can be assumed to be unique within a schema registry store. * * @param schemaGuid GUID reference to specific schema within configured schema registry store. - * @return SRObject containing information regarding matching schema. - * @throws IOException + * @return SchemaRegistryObject containing information regarding matching schema. * @throws SchemaRegistryClientException if fetch operation fails + * @throws IOException failed or interrupted I/O operation */ - public SRObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException; + public SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException; /** * Fetches schema GUID given schema group, name, string representation, and serialization type @@ -54,9 +54,9 @@ public SRObject register(String schemaGroup, String schemaName, String schema * @param schemaName schema name * @param schemaString String representation of schema * @param serializationType String representation of serialization format type - * @return SRObject containing information regarding requested schema. - * @throws IOException + * @return SchemaRegistryObject containing information regarding requested schema. * @throws SchemaRegistryClientException if fetch operation fails + * @throws IOException failed or interrupted I/O operation */ public String getGuid(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, SchemaRegistryClientException; @@ -65,10 +65,10 @@ public String getGuid(String schemaGroup, String schemaName, String schemaString * Not currently implemented. * @param schemaGroup schema group name * @param schemaName schema name - * @param version + * @param version schema version * @return GUID of delete schema - * @throws IOException - * @throws SchemaRegistryClientException + * @throws SchemaRegistryClientException deletion operation failed + * @throws IOException failed or interrupted I/O operation */ public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) throws IOException, SchemaRegistryClientException; @@ -78,8 +78,8 @@ public String deleteSchemaVersion(String schemaGroup, String schemaName, int ver * @param schemaGroup schema group name * @param schemaName schema name * @return GUID of deleted schema - * @throws IOException - * @throws SchemaRegistryClientException + * @throws SchemaRegistryClientException deletion operation failed + * @throws IOException failed or interrupted I/O operation */ public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) throws IOException, SchemaRegistryClientException; @@ -89,8 +89,8 @@ public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) * @param schemaGroup schema group name * @param schemaName schema name * @return list of GUID references to deleted schemas - * @throws IOException - * @throws SchemaRegistryClientException + * @throws SchemaRegistryClientException deletion operation failed + * @throws IOException failed or interrupted I/O operation */ public List deleteSchema(String schemaGroup, String schemaName) throws IOException, SchemaRegistryClientException; } diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java similarity index 100% rename from sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SRObject.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java similarity index 96% rename from sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SRObject.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java index c55d6ac4c923..9e2ead44a995 100644 --- a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/SRObject.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java @@ -17,19 +17,19 @@ * * @param is derived from the parser function that is passed in the constructor. */ -public class SRObject { +public class SchemaRegistryObject { private final Logger log; public final String schemaGuid; public final String serializationType; private final Charset encoding = RestService.SERVICE_CHARSET; - + private Function parseMethod; public byte[] schemaByteArray; private T deserialized; - public SRObject( + public SchemaRegistryObject( String schemaGuid, String serializationType, byte[] schemaByteArray, diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java new file mode 100644 index 000000000000..0347c296f364 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java @@ -0,0 +1,4 @@ +/** + * Package containing the classes for CachedSchemaRegistryClient and AzureSchemaRegistryRestService. + */ +package com.azure.schemaregistry.client; diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java similarity index 99% rename from sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java index 8ef1de38d897..99a7bc599dc9 100644 --- a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java @@ -99,6 +99,7 @@ public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) { * @param The type of the deserialized response to the HTTP request. * @return The deserialized response to the HTTP request, or null if no data is expected. */ + @SuppressWarnings("unchecked") private T sendHttpRequest(String requestUrl, String method, byte[] requestBodyData, Map requestProperties, TypeReference responseFormat) diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java similarity index 100% rename from sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java similarity index 100% rename from sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java similarity index 100% rename from sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java diff --git a/sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java similarity index 100% rename from sdk/schemaregistry/client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java diff --git a/sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java similarity index 93% rename from sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java index 4769dabe8f68..831c16b58cd7 100644 --- a/sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java @@ -22,11 +22,11 @@ public class CachedSchemaRegistryClientTest extends TestCase { private static final String MOCK_GROUP = "mockgroup"; private static final String MOCK_SCHEMA_NAME = "mockname"; private static final String MOCK_AVRO_SCHEMA = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; - + private CachedSchemaRegistryClient client; private RestService restService; - private HashMap> guidCache; - private HashMap> schemaStringCache; + private HashMap> guidCache; + private HashMap> schemaStringCache; private HashMap> typeParserDictionary; public CachedSchemaRegistryClientTest(String testName) { @@ -38,15 +38,15 @@ public static Test suite() { } protected void setUp() { - this.guidCache = new HashMap>(); - this.schemaStringCache = new HashMap>(); + this.guidCache = new HashMap>(); + this.schemaStringCache = new HashMap>(); this.typeParserDictionary = new HashMap>(); this.typeParserDictionary.put(MOCK_SERIALIZATION, (s)->s); this.restService = createNiceMock(RestService.class); this.client = new CachedSchemaRegistryClient( - this.restService, + this.restService, this.guidCache, this.schemaStringCache, this.typeParserDictionary); @@ -64,7 +64,7 @@ public void testRegisterThenSchemaCacheHit() throws Exception { assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); - + verify(restService); } @@ -72,12 +72,12 @@ public void testGetGuidThenSchemaCacheHit() throws Exception { expect(restService.getGuid(anyString(), anyString(), anyString(), anyString())) .andReturn(MOCK_GUID) .once(); - + replay(restService); assertEquals(MOCK_GUID, client.getGuid(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); assertEquals(MOCK_GUID, client.getGuid(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); - + verify(restService); } @@ -87,10 +87,10 @@ public void testGetSchemaThenGuidCacheHit() throws Exception { .once(); replay(restService); - + assertEquals(MOCK_GUID, client.getSchemaByGuid(MOCK_GUID).schemaGuid); assertEquals(MOCK_GUID, client.getSchemaByGuid(MOCK_GUID).schemaGuid); - + verify(restService); } @@ -112,7 +112,7 @@ public void testClientReset() throws Exception { this.typeParserDictionary.put(MOCK_SERIALIZATION, (s)->s); assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); - + verify(restService); } diff --git a/sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java similarity index 100% rename from sdk/schemaregistry/client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml new file mode 100644 index 000000000000..befa25c77c64 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml @@ -0,0 +1,79 @@ + + + + + + 4.0.0 + + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.azure + azure-schemaregistry-serde-avro + 1.0.0-beta.1 + + Microsoft Azure Schema Registry - Avro-specific package for client library + Avro-specific package for Azure Schema Registry client library + https://github.com/Azure/azure-sdk-for-java + + + + azure-java-build-docs + ${site.url}/site/${project.artifactId} + + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + + com.azure + azure-schemaregistry-serde-common + 1.0.0-beta.1 + compile + + + org.apache.avro + avro + 1.9.2 + compile + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + + org.apache.avro:avro:[1.9.2] + + + + + + + + diff --git a/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java similarity index 100% rename from sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java diff --git a/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java similarity index 100% rename from sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java diff --git a/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java similarity index 100% rename from sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java diff --git a/sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java similarity index 100% rename from sdk/schemaregistry/codec/codec-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java new file mode 100644 index 000000000000..4194d0a49cfe --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import com.azure.schemaregistry.AbstractDataDeserializer; +import com.azure.schemaregistry.SerializationException; +import com.azure.schemaregistry.client.CachedSchemaRegistryClient; + +/** + * A deserializer implementation capable of automatedly deserializing encoded byte array payloads into Java objects by + * fetching payload-specified schemas from the Azure Schema Registry store. + * + * SchemaRegistryAvroSyncDeserializer instances should be built using the static Builder class. + * + * Pluggable with the core Azure SDK Deserializer interface. + * + * @see AbstractDataDeserializer See AbstractDataDeserializer for internal deserialization implementation + * @see SchemaRegistryAvroAsyncDeserializer.Builder See Builder for documentation on builder parameters + */ +public class SchemaRegistryAvroAsyncDeserializer extends AbstractDataDeserializer { + private SchemaRegistryAvroAsyncDeserializer(Builder builder) { + super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) + .credential() + .maxSchemaMapSize(builder.maxSchemaMapSize) + .build()); + + loadByteDecoder(new AvroByteDecoder.Builder() + .avroSpecificReader(builder.avroSpecificReader) + .build()); + } + + /** + * Deserializes byte array into Java object using payload-specified schema. + * + * @param data Byte array containing serialized bytes + * @return Java object. + * + * Object type is testable with instanceof operator. Return value can be casted in the caller layer. + * + * @throws SerializationException Throws on deserialization failure. + * Exception may contain inner exceptions detailing failure condition. + */ + public Object deserializeSync(byte[] data) throws SerializationException { + return super.deserialize(data); + + } + + public static class Builder { + private final String registryUrl; + private int maxSchemaMapSize; + private String credential; + private boolean avroSpecificReader; + + public Builder(String registryUrl) { + this.registryUrl = registryUrl; + this.credential = null; + this.avroSpecificReader = false; + this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + } + + public SchemaRegistryAvroAsyncDeserializer build() { + return new SchemaRegistryAvroAsyncDeserializer(this); + } + + public Builder credential(String credential) { + this.credential = credential; + return this; + } + + public Builder avroSpecificReader(boolean avroSpecificReader) { + this.avroSpecificReader = avroSpecificReader; + return this; + } + + public Builder maxSchemaMapSize(int maxSchemaMapSize) { + this.maxSchemaMapSize = maxSchemaMapSize; + return this; + } + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java new file mode 100644 index 000000000000..84b64311cff7 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry.avro; + +import com.azure.schemaregistry.AbstractDataSerializer; +import com.azure.schemaregistry.SerializationException; +import com.azure.schemaregistry.client.CachedSchemaRegistryClient; + +/** + * A serializer implementation capable of serializing objects and automatedly storing serialization schemas + * in the Azure Schema Registry store. + * + * SchemaRegistryAvroSyncSerializer instances should be built using the static Builder class. + * + * Pluggable with the core Azure SDK Serializer interface. + * + * @see AbstractDataSerializer See AbstractDataSerializer for internal serialization implementation + * @see SchemaRegistryAvroAsyncSerializer.Builder See Builder for documentation on required parameters + */ +public class SchemaRegistryAvroAsyncSerializer extends AbstractDataSerializer { + private SchemaRegistryAvroAsyncSerializer(Builder builder) { + super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) + .maxSchemaMapSize(builder.maxSchemaMapSize) + .build()); + + setByteEncoder(new AvroByteEncoder.Builder().build()); + this.serializationFormat = this.byteEncoder.serializationFormat(); + this.autoRegisterSchemas = builder.autoRegisterSchemas; + this.schemaGroup = builder.schemaGroup; + } + + /** + * Serializes object into byte array payload using the configured byte encoder. + * @param object target of serialization + * @return byte array containing GUID reference to schema, then the object serialized into bytes + * @throws SerializationException Throws on serialization failure. + * Exception may contain inner exceptions detailing failure condition. + */ + public byte[] serializeSync(Object object) throws SerializationException { + if (object == null) { + return null; + } + return serializeImpl(object); + } + + +} + diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializerBuilder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializerBuilder.java new file mode 100644 index 000000000000..95d2600d6410 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializerBuilder.java @@ -0,0 +1,73 @@ +package com.azure.schemaregistry.avro; + +import com.azure.schemaregistry.AbstractDataSerializer; +import com.azure.schemaregistry.ByteEncoder; +import com.azure.schemaregistry.client.CachedSchemaRegistryClient; + +public final class SchemaRegistryAvroAsyncSerializerBuilder { + private final String registryUrl; + private String credential; + private boolean autoRegisterSchemas; + private String schemaGroup; + private int maxSchemaMapSize; + protected ByteEncoder byteEncoder = null; + + private SchemaRegistryAvroAsyncSerializerBuilder(String registryUrl) { + this.registryUrl = registryUrl; + this.credential = null; + this.autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; + this.schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; + this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + } + + public static SchemaRegistryAvroAsyncSerializerBuilder aSchemaRegistryAvroAsyncSerializer() { + return new SchemaRegistryAvroAsyncSerializerBuilder(); + } + + public SchemaRegistryAvroAsyncSerializerBuilder byteEncoder(ByteEncoder byteEncoder) { + this.byteEncoder = byteEncoder; + return this; + } + + public SchemaRegistryAvroAsyncSerializer build() { + SchemaRegistryAvroAsyncSerializer schemaRegistryAvroAsyncSerializer = new SchemaRegistryAvroAsyncSerializer(null); + schemaRegistryAvroAsyncSerializer.setByteEncoder(byteEncoder); + return schemaRegistryAvroAsyncSerializer; + } + + public static class Builder { + private final String registryUrl; + private boolean autoRegisterSchemas; + private String credential; + private int maxSchemaMapSize; + private String schemaGroup; + + public Builder(String registryUrl) { + + } + + public SchemaRegistryAvroAsyncSerializer build() { + return new SchemaRegistryAvroAsyncSerializer(this); + } + + public Builder schemaGroup(String schemaGroup) { + this.schemaGroup = schemaGroup; + return this; + } + + public Builder credential(String credential) { + this.credential = credential; + return this; + } + + public Builder autoRegisterSchema(boolean autoRegisterSchemas) { + this.autoRegisterSchemas = autoRegisterSchemas; + return this; + } + + public Builder maxSchemaMapSize(int maxSchemaMapSize) { + this.maxSchemaMapSize = maxSchemaMapSize; + return this; + } + } +} diff --git a/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncDeserializer.java similarity index 81% rename from sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncDeserializer.java index c378c82a1ccf..646acc7a1540 100644 --- a/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncDeserializer.java @@ -13,23 +13,23 @@ * A deserializer implementation capable of automatedly deserializing encoded byte array payloads into Java objects by * fetching payload-specified schemas from the Azure Schema Registry store. * - * SchemaRegistryAvroDeserializer instances should be built using the static Builder class. + * SchemaRegistryAvroSyncDeserializer instances should be built using the static Builder class. * * Pluggable with the core Azure SDK Deserializer interface. * * @see AbstractDataDeserializer See AbstractDataDeserializer for internal deserialization implementation - * @see SchemaRegistryAvroDeserializer.Builder See Builder for documentation on builder parameters + * @see SchemaRegistryAvroSyncDeserializer.Builder See Builder for documentation on builder parameters */ -public class SchemaRegistryAvroDeserializer extends AbstractDataDeserializer { - private SchemaRegistryAvroDeserializer(Builder builder) { +public class SchemaRegistryAvroSyncDeserializer extends AbstractDataDeserializer { + private SchemaRegistryAvroSyncDeserializer(Builder builder) { super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) .credential() .maxSchemaMapSize(builder.maxSchemaMapSize) .build()); loadByteDecoder(new AvroByteDecoder.Builder() - .avroSpecificReader(builder.avroSpecificReader) - .build()); + .avroSpecificReader(builder.avroSpecificReader) + .build()); } /** @@ -61,8 +61,8 @@ public Builder(String registryUrl) { this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; } - public SchemaRegistryAvroDeserializer build() { - return new SchemaRegistryAvroDeserializer(this); + public SchemaRegistryAvroSyncDeserializer build() { + return new SchemaRegistryAvroSyncDeserializer(this); } public Builder credential(String credential) { @@ -80,4 +80,4 @@ public Builder maxSchemaMapSize(int maxSchemaMapSize) { return this; } } -} \ No newline at end of file +} diff --git a/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncSerializer.java similarity index 86% rename from sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncSerializer.java index addbe482b899..a9922d5dd469 100644 --- a/sdk/schemaregistry/serde/generic-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncSerializer.java @@ -13,15 +13,15 @@ * A serializer implementation capable of serializing objects and automatedly storing serialization schemas * in the Azure Schema Registry store. * - * SchemaRegistryAvroSerializer instances should be built using the static Builder class. + * SchemaRegistryAvroSyncSerializer instances should be built using the static Builder class. * * Pluggable with the core Azure SDK Serializer interface. * * @see AbstractDataSerializer See AbstractDataSerializer for internal serialization implementation - * @see SchemaRegistryAvroSerializer.Builder See Builder for documentation on required parameters + * @see SchemaRegistryAvroSyncSerializer.Builder See Builder for documentation on required parameters */ -public class SchemaRegistryAvroSerializer extends AbstractDataSerializer { - private SchemaRegistryAvroSerializer(Builder builder) { +public class SchemaRegistryAvroSyncSerializer extends AbstractDataSerializer { + private SchemaRegistryAvroSyncSerializer(Builder builder) { super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) .maxSchemaMapSize(builder.maxSchemaMapSize) .build()); @@ -61,8 +61,8 @@ public Builder(String registryUrl) { this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; } - public SchemaRegistryAvroSerializer build() { - return new SchemaRegistryAvroSerializer(this); + public SchemaRegistryAvroSyncSerializer build() { + return new SchemaRegistryAvroSyncSerializer(this); } public Builder schemaGroup(String schemaGroup) { diff --git a/sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java similarity index 100% rename from sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java diff --git a/sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java similarity index 100% rename from sdk/schemaregistry/codec/codec-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml new file mode 100644 index 000000000000..5ad9775202eb --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml @@ -0,0 +1,89 @@ + + + + 4.0.0 + + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + azure-schemaregistry-serde-common + jar + 1.0.0-beta.1 + + Microsoft Azure Schema Registry - Common SerDe Package for client library + Common SerDe Package containing base serialization/deserialization implementation for Azure Schema Registry client library + https://github.com/Azure/azure-sdk-for-java + + + + azure-java-build-docs + ${site.url}/site/${project.artifactId} + + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + + com.azure + azure-core + 1.5.0 + + + com.azure + azure-schemaregistry-client + 1.0.0-beta.1 + + + + + org.easymock + easymock + 4.1 + test + + + junit + junit + 4.12 + test + + + org.apache.avro + avro + 1.9.2 + test + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + + org.apache.avro:avro:[1.9.2] + + + + + + + + diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java similarity index 74% rename from sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java index c2adafe7473a..caa0ce2d0369 100644 --- a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java @@ -5,14 +5,13 @@ package com.azure.schemaregistry; -import com.azure.schemaregistry.client.SRObject; +import com.azure.schemaregistry.client.SchemaRegistryObject; import com.azure.schemaregistry.client.SchemaRegistryClient; import com.azure.schemaregistry.client.SchemaRegistryClientException; import java.io.IOException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -35,7 +34,7 @@ protected Object deserialize(byte[] payload) throws SerializationException { ByteBuffer buffer = getByteBuffer(payload); String schemaGuid = getSchemaGuidFromPayload(buffer); - SRObject registryObject = null; + SchemaRegistryObject registryObject = null; Object payloadSchema = null; try { @@ -61,7 +60,7 @@ protected Object deserialize(byte[] payload) throws SerializationException { } - private ByteDecoder getByteDecoder(SRObject registryObject) throws SerializationException { + private ByteDecoder getByteDecoder(SchemaRegistryObject registryObject) throws SerializationException { ByteDecoder decoder = byteDecoderMap.get(registryObject.serializationType); if (decoder == null) { throw new SerializationException("No decoder class found for serialization type " + @@ -88,28 +87,6 @@ protected String getSchemaGuidFromPayload(ByteBuffer buffer) throws Serializatio protected void loadByteDecoder(ByteDecoder decoder) { this.byteDecoderMap.put(decoder.serializationFormat(), decoder); - this.schemaRegistryClient.loadSchemaParser( - decoder.serializationFormat(), - (s) -> decoder.parseSchemaString(s)); + this.schemaRegistryClient.loadSchemaParser(decoder.serializationFormat(), decoder::parseSchemaString); } - - protected static abstract class AbstractBuilder { - protected B deserializerBuilder; - protected static SchemaRegistryClient schemaRegistryClient; - protected ArrayList byteDecoders; - - protected abstract B getActualBuilder(); - - protected AbstractBuilder(SchemaRegistryClient schemaRegistryClient) { - this.schemaRegistryClient = schemaRegistryClient; - this.byteDecoders = new ArrayList<>(); - - deserializerBuilder = getActualBuilder(); - } - - public B byteDecoder(ByteDecoder decoder) { - byteDecoders.add(decoder); - return deserializerBuilder; - } - } -} \ No newline at end of file +} diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java similarity index 100% rename from sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java similarity index 74% rename from sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java index c4a9b7805c88..a8f4f62cd4ea 100644 --- a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; public abstract class AbstractDataSerializer extends AbstractDataSerDe { private static final Logger log = LoggerFactory.getLogger(AbstractDataSerializer.class); @@ -39,9 +40,7 @@ protected void setByteEncoder(ByteEncoder byteEncoder) { throw new IllegalArgumentException("Setting multiple encoders on serializer not permitted"); } this.byteEncoder = byteEncoder; - this.schemaRegistryClient.loadSchemaParser( - byteEncoder.serializationFormat(), - (s) -> byteEncoder.parseSchemaString(s)); + this.schemaRegistryClient.loadSchemaParser(byteEncoder.serializationFormat(), byteEncoder::parseSchemaString); } protected byte[] serializeImpl(Object object) throws SerializationException { @@ -67,7 +66,7 @@ protected byte[] serializeImpl(Object object) throws SerializationException { ByteArrayOutputStream out = new ByteArrayOutputStream(); // utf8 swap todo ByteBuffer guidBuffer = ByteBuffer.allocate(AbstractDataSerDe.idSize) - .put(schemaGuid.getBytes(Charset.forName("UTF-8"))); + .put(schemaGuid.getBytes(StandardCharsets.UTF_8)); out.write(guidBuffer.array()); byteEncoder.encode(object).writeTo(out); return out.toByteArray(); @@ -93,37 +92,4 @@ private String maybeRegisterSchema(String schemaGroup, String schemaName, String return this.schemaRegistryClient.getGuid(schemaGroup, schemaName, schemaString, serializationFormatString); } } - - protected static abstract class AbstractBuilder { - protected B serializerBuilder; - protected SchemaRegistryClient schemaRegistryClient; - - protected Boolean autoRegisterSchemas = false; - protected ByteEncoder byteEncoder; - protected String schemaGroup; - - protected abstract B getActualBuilder(); - - public AbstractBuilder(SchemaRegistryClient schemaRegistryClient) { - this.schemaRegistryClient = schemaRegistryClient; - this.byteEncoder = null; - - serializerBuilder = getActualBuilder(); - } - - public B schemaGroup(String schemaGroup) { - this.schemaGroup = schemaGroup; - return serializerBuilder; - } - - public B byteEncoder(ByteEncoder byteEncoder) { - this.byteEncoder = byteEncoder; - return serializerBuilder; - } - - public B autoRegisterSchemas(Boolean autoRegisterSchemas) { - this.autoRegisterSchemas = autoRegisterSchemas; - return serializerBuilder; - } - } -} \ No newline at end of file +} diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteDecoder.java similarity index 100% rename from sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteDecoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteDecoder.java diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java similarity index 100% rename from sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/ByteEncoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/Codec.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/Codec.java similarity index 100% rename from sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/Codec.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/Codec.java diff --git a/sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/SerializationException.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/SerializationException.java similarity index 100% rename from sdk/schemaregistry/serde/common/src/main/java/com/azure/schemaregistry/SerializationException.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/SerializationException.java diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java similarity index 95% rename from sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java index 6482a0e1fef9..1d7c0dee505b 100644 --- a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java @@ -6,7 +6,7 @@ package com.azure.schemaregistry; import com.azure.schemaregistry.client.MockSchemaRegistryClient; -import com.azure.schemaregistry.client.SRObject; +import com.azure.schemaregistry.client.SchemaRegistryObject; import com.azure.schemaregistry.client.SchemaRegistryClientException; import com.azure.schemaregistry.client.rest.RestService; import junit.framework.Test; @@ -27,7 +27,7 @@ public class AbstractDataDeserializerTest extends TestCase { private static final String MOCK_GUID = new String(new char[AbstractDataSerDe.idSize]).replace("\0", "a"); private static final String MOCK_AVRO_SCHEMA_STRING = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; - + private final EncoderFactory encoderFactory = EncoderFactory.get(); private final Schema MOCK_AVRO_SCHEMA; @@ -44,8 +44,8 @@ public void testLoadDecoder() throws IOException, SchemaRegistryClientException, // add standard avro decoder class and test that it is used for decoding payload SampleByteDecoder decoder = new SampleByteDecoder(); - // manually add SRObject to cache - SRObject registered = new SRObject<>(MOCK_GUID, + // manually add SchemaRegistryObject to cache + SchemaRegistryObject registered = new SchemaRegistryObject<>(MOCK_GUID, decoder.serializationFormat(), MOCK_AVRO_SCHEMA_STRING.getBytes(RestService.SERVICE_CHARSET), s -> decoder.parseSchemaString(s)); diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java similarity index 94% rename from sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java index 4a7ac04f563f..7bfd69f05b6d 100644 --- a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java @@ -6,7 +6,7 @@ package com.azure.schemaregistry; import com.azure.schemaregistry.client.MockSchemaRegistryClient; -import com.azure.schemaregistry.client.SRObject; +import com.azure.schemaregistry.client.SchemaRegistryObject; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -32,9 +32,9 @@ public void testRegistryGuidPrefixedToPayload() { MOCK_GUID += (char)(rnd.nextInt(26) + 'a'); } - // manually add SRObject into mock registry client cache + // manually add SchemaRegistryObject into mock registry client cache SampleByteEncoder encoder = new SampleByteEncoder(); - SRObject registered = new SRObject<>(MOCK_GUID, + SchemaRegistryObject registered = new SchemaRegistryObject<>(MOCK_GUID, encoder.serializationFormat(), encoder.getSchemaString(null).getBytes(), // always returns same schema string s -> encoder.parseSchemaString(s)); @@ -58,7 +58,7 @@ public void testRegistryGuidPrefixedToPayload() { throw new SerializationException("Payload too short, no readable guid.", e); } - assertEquals(MOCK_GUID, new String(schemaGuidByteArray)); // guid should match preloaded SRObject guid + assertEquals(MOCK_GUID, new String(schemaGuidByteArray)); // guid should match preloaded SchemaRegistryObject guid int start = buffer.position() + buffer.arrayOffset(); int length = buffer.limit() - AbstractDataSerDe.idSize; diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java similarity index 100% rename from sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java similarity index 100% rename from sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java similarity index 100% rename from sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java diff --git a/sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java similarity index 100% rename from sdk/schemaregistry/serde/common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java diff --git a/sdk/schemaregistry/codec/codec-avro/pom.xml b/sdk/schemaregistry/codec/codec-avro/pom.xml deleted file mode 100644 index ab1524b60d42..000000000000 --- a/sdk/schemaregistry/codec/codec-avro/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - 4.0.0 - - - com.azure - azure-schemaregistry-codec - 1.0.0-beta.1 - - - com.azure - azure-schemaregistry-codec-avro - 1.0.0-beta.1 - azure-schemaregistry-codec-avro - - - - junit - junit - - - org.apache.avro - avro - 1.9.2 - - - com.azure - azure-schemaregistry-serde-common - 1.0.0-beta.1 - compile - - - - diff --git a/sdk/schemaregistry/codec/pom.xml b/sdk/schemaregistry/codec/pom.xml deleted file mode 100644 index e34d90e7dd25..000000000000 --- a/sdk/schemaregistry/codec/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - 4.0.0 - - - com.azure - azure-schemaregistry-parent - 1.0.0-beta.1 - - - com.azure - azure-schemaregistry-codec - pom - 1.0.0-beta.1 - azure-schemaregistry-codec - - - codec-avro - - - - - com.azure - azure-core - - - junit - junit - 3.8.1 - test - - - diff --git a/sdk/schemaregistry/pom.xml b/sdk/schemaregistry/pom.xml index a988c54b2237..e82b93970121 100644 --- a/sdk/schemaregistry/pom.xml +++ b/sdk/schemaregistry/pom.xml @@ -4,41 +4,16 @@ ~ Licensed under the MIT License. --> - + 4.0.0 - com.azure - 1.0.0-beta.1 - azure-schemaregistry-parent + azure-schemaregistry pom - azure-schemaregistry-parent - + 1.0.0 - client - serde - codec + azure-schemaregistry-client + azure-schemaregistry-serde-common + azure-schemaregistry-serde-avro - - - 1.8 - 1.8 - 2.10.2 - - - - - - com.azure - azure-core - 1.5.0 - - - junit - junit - 3.8.1 - test - - - - + \ No newline at end of file diff --git a/sdk/schemaregistry/serde/common/pom.xml b/sdk/schemaregistry/serde/common/pom.xml deleted file mode 100644 index 986bef8a9d80..000000000000 --- a/sdk/schemaregistry/serde/common/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - 4.0.0 - - - com.azure - azure-schemaregistry-serde - 1.0.0-beta.1 - - - azure-schemaregistry-serde-common - jar - azure-schemaregistry-serde-common - - - - org.easymock - easymock - 4.1 - test - - - junit - junit - test - - - com.azure - azure-schemaregistry-client - 1.0.0-beta.1 - - - com.fasterxml.jackson.core - jackson-core - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - org.apache.avro - avro - 1.9.2 - test - - - diff --git a/sdk/schemaregistry/serde/generic-avro/pom.xml b/sdk/schemaregistry/serde/generic-avro/pom.xml deleted file mode 100644 index 0cf601b271a1..000000000000 --- a/sdk/schemaregistry/serde/generic-avro/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - 4.0.0 - - - com.azure - azure-schemaregistry-serde - 1.0.0-beta.1 - - - com.azure - azure-schemaregistry-serde-avro - azure-schemaregistry-serde-avro - - - - junit - junit - 3.8.1 - test - - - com.azure - azure-schemaregistry-serde-common - 1.0.0-beta.1 - - - com.azure - azure-schemaregistry-codec-avro - 1.0.0-beta.1 - compile - - - diff --git a/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroDeserializerTest.java b/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroDeserializerTest.java deleted file mode 100644 index fbd8a9955581..000000000000 --- a/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroDeserializerTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class SchemaRegistryAvroDeserializerTest extends TestCase{ - public SchemaRegistryAvroDeserializerTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(SchemaRegistryAvroDeserializerTest.class); - } - - protected void setUp() { - } - - protected void tearDown() { - } - - public void testShouldAnswerWithTrue() - { - assertTrue( true ); - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroSerializerTest.java b/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroSerializerTest.java deleted file mode 100644 index e732a9025ada..000000000000 --- a/sdk/schemaregistry/serde/generic-avro/src/test/java/com/microsoft/azure/SchemaRegistryAvroSerializerTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class SchemaRegistryAvroSerializerTest extends TestCase{ - public SchemaRegistryAvroSerializerTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(SchemaRegistryAvroSerializerTest.class); - } - - protected void setUp() { - } - - protected void tearDown() { - } - - public void testShouldAnswerWithTrue() - { - assertTrue( true ); - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/serde/pom.xml b/sdk/schemaregistry/serde/pom.xml deleted file mode 100644 index 0c50934e8503..000000000000 --- a/sdk/schemaregistry/serde/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - 4.0.0 - - - com.azure - azure-schemaregistry-parent - 1.0.0-beta.1 - - - com.azure - azure-schemaregistry-serde - pom - 1.0.0-beta.1 - azure-schemaregistry-serde - - - common - generic-avro - - - - - com.azure - azure-core - - - com.azure - azure-schemaregistry-client - 1.0.0-beta.1 - compile - - - junit - junit - test - - - From be646ab8560d73d83dc7eaff8944c4217d7b58bb Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 20 May 2020 00:14:24 -0700 Subject: [PATCH 06/43] swagger generated http client --- .../azure-schemaregistry-client/pom.xml | 12 +- .../azure-schemaregistry-client.properties | 2 + .../client/CachedSchemaRegistryClient.java | 180 +-- .../CachedSchemaRegistryClientBuilder.java | 228 +++ .../client/MockSchemaRegistryClient.java | 22 +- .../client/SchemaRegistryClient.java | 8 +- .../client/SchemaRegistryObject.java | 35 +- .../schemaregistry/client/package-info.java | 5 +- .../rest/AzureSchemaRegistryRestService.java | 1396 +++++++++++++++++ ...AzureSchemaRegistryRestServiceBuilder.java | 64 + .../client/rest/RestService.java | 377 ----- .../client/rest/entities/ErrorMessage.java | 43 - .../responses/RegisterSchemaResponse.java | 37 - .../responses/SchemaObjectResponse.java | 51 - .../rest/exceptions/RestClientException.java | 25 - .../rest/models/CreateGroupHeaders.java | 41 + .../rest/models/CreateGroupResponse.java | 22 + .../rest/models/CreateSchemaHeaders.java | 147 ++ .../rest/models/CreateSchemaResponse.java | 28 + .../models/GetIdBySchemaContentHeaders.java | 147 ++ .../models/GetIdBySchemaContentResponse.java | 32 + .../rest/models/GetLatestSchemaHeaders.java | 147 ++ .../rest/models/GetLatestSchemaResponse.java | 28 + .../rest/models/GetSchemaByIdHeaders.java | 147 ++ .../rest/models/GetSchemaByIdResponse.java | 28 + .../rest/models/GetSchemaVersionHeaders.java | 147 ++ .../rest/models/GetSchemaVersionResponse.java | 32 + .../rest/models/GetSchemaVersionsHeaders.java | 41 + .../models/GetSchemaVersionsResponse.java | 33 + .../rest/models/GetSchemasByGroupHeaders.java | 41 + .../models/GetSchemasByGroupResponse.java | 33 + .../client/rest/models/SchemaGroup.java | 173 ++ .../client/rest/models/SchemaId.java | 41 + .../client/rest/models/package-info.java | 2 + .../client/rest/package-info.java | 2 + .../CachedSchemaRegistryClientTest.java | 133 +- .../client/RestServiceTest.java | 48 - .../org.mockito.plugins.MockMaker | 1 + 38 files changed, 3176 insertions(+), 803 deletions(-) create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/resources/azure-schemaregistry-client.properties create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceBuilder.java delete mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java delete mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java delete mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java delete mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java delete mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/package-info.java delete mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml index 48e846820881..24ea54bc4253 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml @@ -45,15 +45,15 @@ - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-api + 5.6.2 test - org.easymock - easymock - 4.1 + org.mockito + mockito-core + 3.0.0 test diff --git a/sdk/schemaregistry/azure-schemaregistry-client/resources/azure-schemaregistry-client.properties b/sdk/schemaregistry/azure-schemaregistry-client/resources/azure-schemaregistry-client.properties new file mode 100644 index 000000000000..ca812989b4f2 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/resources/azure-schemaregistry-client.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +version=${project.version} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index 5b3dab65eb7a..499edf2ead6e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -5,15 +5,19 @@ package com.azure.schemaregistry.client; -import com.azure.schemaregistry.client.rest.RestService; -import com.azure.schemaregistry.client.rest.entities.responses.SchemaObjectResponse; -import com.azure.schemaregistry.client.rest.exceptions.RestClientException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.azure.core.credential.TokenCredential; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.HttpPipeline; +import com.azure.core.util.logging.ClientLogger; +import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestService; +import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestServiceBuilder; +import com.azure.schemaregistry.client.rest.models.GetSchemaByIdResponse; +import com.azure.schemaregistry.client.rest.models.SchemaId; import java.io.IOException; import java.util.HashMap; import java.util.List; +import java.util.UUID; import java.util.function.Function; /** @@ -29,32 +33,37 @@ * TODO: implement max age for schema maps? or will schemas always be immutable? * * @see SchemaRegistryClient Implements SchemaRegistryClient interface to allow for testing with mock - * @see CachedSchemaRegistryClient.Builder Follows static builder pattern for object instantiation + * @see CachedSchemaRegistryClientBuilder Follows builder pattern for object instantiation */ public class CachedSchemaRegistryClient implements SchemaRegistryClient { - private static final Logger log = LoggerFactory.getLogger(CachedSchemaRegistryClient.class); + private final ClientLogger log = new ClientLogger(CachedSchemaRegistryClient.class); public static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; public static final int MAX_SCHEMA_MAP_SIZE_MINIMUM = 10; private int maxSchemaMapSize; - private final RestService restService; - private final HashMap> typeParserDictionary; + private final AzureSchemaRegistryRestService restService; + private final HashMap> typeParserDictionary; - private HashMap> guidCache; - private HashMap> schemaStringCache; + private HashMap guidCache; + private HashMap schemaStringCache; - private CachedSchemaRegistryClient( + CachedSchemaRegistryClient( String registryUrl, + HttpPipeline pipeline, + TokenCredential credential, int maxSchemaMapSize, - HashMap> typeParserDictionary, - String credentials) + HashMap> typeParserDictionary) { if (registryUrl == null || registryUrl.isEmpty()) { throw new IllegalArgumentException("Schema Registry URL cannot be null or empty."); } - this.restService = new RestService(registryUrl, credentials); + this.restService = new AzureSchemaRegistryRestServiceBuilder() + .host(registryUrl) + .pipeline(pipeline) + .buildClient(); + this.maxSchemaMapSize = maxSchemaMapSize; this.typeParserDictionary = typeParserDictionary; this.guidCache = new HashMap<>(); @@ -63,17 +72,17 @@ private CachedSchemaRegistryClient( // testing CachedSchemaRegistryClient( - RestService restService, - HashMap> guidCache, - HashMap> schemaStringCache, - HashMap> typeParserDictionary) { + AzureSchemaRegistryRestService restService, + HashMap guidCache, + HashMap schemaStringCache, + HashMap> typeParserDictionary) { this.restService = restService; // mockable this.guidCache = guidCache; this.schemaStringCache = schemaStringCache; this.typeParserDictionary = typeParserDictionary; } - public synchronized void loadSchemaParser(String serializationType, Function parseMethod) { + public synchronized void loadSchemaParser(String serializationType, Function parseMethod) { if (serializationType == null || serializationType.isEmpty()) { throw new IllegalArgumentException("Serialization type cannot be null or empty."); } @@ -81,77 +90,84 @@ public synchronized void loadSchemaParser(String serializationType, Function register(String schemaGroup, String schemaName, String schemaString, String serializationType) + public synchronized SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { - log.debug(String.format("Cache hit schema string. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", + log.verbose(String.format("Cache hit schema string. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", schemaGroup, schemaName, serializationType, schemaString)); return schemaStringCache.get(schemaString); } - log.debug(String.format("Registering schema. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", + log.verbose(String.format("Registering schema. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", schemaGroup, schemaName, serializationType, schemaString)); - String schemaGuid; + SchemaId schemaId; try { - schemaGuid = this.restService.registerSchema(schemaGroup, schemaName, schemaString, serializationType); - } catch (RestClientException e) { - throw new SchemaRegistryClientException("Schema registration failed.", e); + schemaId = this.restService.createSchema(schemaGroup, schemaName, schemaString, serializationType); + } catch (HttpResponseException e) { + throw new SchemaRegistryClientException("Register operation failed.", e); } - SchemaRegistryObject registered = new SchemaRegistryObject<>(schemaGuid, + SchemaRegistryObject registered = new SchemaRegistryObject(schemaId.getId(), serializationType, - schemaString.getBytes(RestService.SERVICE_CHARSET), + schemaString.getBytes(), getParseFunc(serializationType)); resetIfNeeded(); schemaStringCache.put(schemaString, registered); - log.debug(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + log.verbose(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); return registered; } @Override - public synchronized SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException { - if (guidCache.containsKey(schemaGuid)) { - log.debug(String.format("Cache hit for schema guid '%s'", schemaGuid)); - return guidCache.get(schemaGuid); + public synchronized SchemaRegistryObject getSchemaByGuid(String schemaId) throws IOException, SchemaRegistryClientException { + if (guidCache.containsKey(schemaId)) { + log.verbose(String.format("Cache hit for schema id '%s'", schemaId)); + return guidCache.get(schemaId); } - SchemaObjectResponse response; + GetSchemaByIdResponse response; try { - response = this.restService.getSchemaByGuid(schemaGuid); - } catch (RestClientException e) { - throw new SchemaRegistryClientException(String.format("Failed to get schema for guid %s.", schemaGuid), e); + response = this.restService.getSchemaByIdWithResponseAsync(UUID.fromString(schemaId)).block(); + } + catch (HttpResponseException e) { + throw new SchemaRegistryClientException("Fetching schema failed.", e); + } + + if (response == null) { + throw new SchemaRegistryClientException("HTTP client returned null schema response"); } - SchemaRegistryObject schemaObject = new SchemaRegistryObject<>(response.schemaGuid, - response.serializationType, - response.schemaByteArray, - getParseFunc(response.serializationType)); + String schemaType = response.getDeserializedHeaders().getXSchemaType(); + + SchemaRegistryObject schemaObject = new SchemaRegistryObject(schemaId, + schemaType, + response.getValue().getBytes(), + getParseFunc(schemaType)); resetIfNeeded(); - guidCache.put(schemaGuid, schemaObject); - log.debug(String.format("Cached schema object. Path: '%s'", schemaGuid)); + guidCache.put(schemaId, schemaObject); + log.verbose(String.format("Cached schema object. Path: '%s'", schemaId)); return schemaObject; } @Override - public synchronized String getGuid(String schemaGroup, String schemaName, String schemaString, String serializationType) + public synchronized String getSchemaId(String schemaGroup, String schemaName, String schemaString, String schemaType) throws IOException, SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { - log.debug(String.format("Cache hit schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); - return schemaStringCache.get(schemaString).schemaGuid; + log.verbose(String.format("Cache hit schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + return schemaStringCache.get(schemaString).schemaId; } - String schemaGuid; + SchemaId schemaId; try { - schemaGuid = this.restService.getGuid(schemaGroup, schemaName, schemaString, serializationType); + schemaId = this.restService.getIdBySchemaContent(schemaGroup, schemaName, schemaType, schemaString); } - catch(RestClientException e){ + catch(HttpResponseException e){ throw new SchemaRegistryClientException( String.format("Failed to fetch schema guid for schema. Group: '%s', name: '%s'", schemaGroup, schemaName), e); @@ -160,13 +176,13 @@ public synchronized String getGuid(String schemaGroup, String schemaName, String resetIfNeeded(); schemaStringCache.put( schemaString, - new SchemaRegistryObject<>( - schemaGuid, - serializationType, - schemaString.getBytes(RestService.SERVICE_CHARSET), - getParseFunc(serializationType))); - log.debug(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); - return schemaGuid; + new SchemaRegistryObject( + schemaId.getId(), + schemaType, + schemaString.getBytes(), + getParseFunc(schemaType))); + log.verbose(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + return schemaId.getId(); } @Override @@ -210,8 +226,8 @@ private synchronized void resetIfNeeded() { } } - private Function getParseFunc(String serializationType) throws IOException { - Function parseFunc = typeParserDictionary.get(serializationType.toLowerCase()); + private Function getParseFunc(String serializationType) throws IOException { + Function parseFunc = typeParserDictionary.get(serializationType.toLowerCase()); if (parseFunc == null) { log.error(String.format("No loaded schema parser for serialization type: '%s'", serializationType)); @@ -221,48 +237,4 @@ private synchronized void resetIfNeeded() { } return parseFunc; } - - public static class Builder { - private final String schemaRegistryUrl; - private final HashMap> typeParserDictionary; - private int maxSchemaMapSize; - - public Builder(String schemaRegistryUrl) { - if (schemaRegistryUrl == null || schemaRegistryUrl.isEmpty()) { - throw new IllegalArgumentException("Schema Registry URL cannot be empty."); - } - this.schemaRegistryUrl = schemaRegistryUrl; - this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; - this.typeParserDictionary = new HashMap<>(); - } - - public CachedSchemaRegistryClient build() { - return new CachedSchemaRegistryClient(schemaRegistryUrl, maxSchemaMapSize, typeParserDictionary, null); - } - - public Builder maxSchemaMapSize(int maxSchemaMapSize) throws IllegalArgumentException { - if (maxSchemaMapSize < CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM) { - throw new IllegalArgumentException( - String.format("Schema map size must be greater than %s entries", - CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM)); - } - this.maxSchemaMapSize = maxSchemaMapSize; - return this; - } - - public Builder credential() { - return this; - } - - public Builder loadSchemaParser(String serializationType, Function parseMethod) { - if (serializationType == null || serializationType.isEmpty()) { - throw new IllegalArgumentException("Serialization type cannot be null or empty."); - } - if (this.typeParserDictionary.containsKey(serializationType.toLowerCase())) { - throw new IllegalArgumentException("Multiple parse methods for single serialization type may not be added."); - } - this.typeParserDictionary.put(serializationType.toLowerCase(), parseMethod); - return this; - } - } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java new file mode 100644 index 000000000000..2a7c83681e9d --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -0,0 +1,228 @@ +package com.azure.schemaregistry.client; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.AzureKeyCredentialPolicy; +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; + +import java.net.MalformedURLException; +import java.net.URL; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; +import java.util.Map; +import java.util.function.Function; + +public class CachedSchemaRegistryClientBuilder { + private final ClientLogger log = new ClientLogger(CachedSchemaRegistryClientBuilder.class); + + private static final String DEFAULT_SCOPE = "https://eventhubs.azure.com/.default"; + private static final String CLIENT_PROPERTIES = "azure-schemaregistry-client.properties"; + private static final String NAME = "name"; + private static final String VERSION = "version"; + + private final String schemaRegistryUrl; + private final HashMap> typeParserDictionary; + private final List policies; + private final String clientName; + private final String clientVersion; + private final HttpHeaders headers; + + private HttpClient httpClient; + private int maxSchemaMapSize; + private TokenCredential credential; + private HttpLogOptions httpLogOptions; + private HttpPipeline httpPipeline; + private RetryPolicy retryPolicy; + + /** + * Constructor. + * Sets the service endpoint for the Azure Schema Registry instance. + * Supplies client defaults. + * + * @param schemaRegistryUrl The URL of the Azure Schema Registry instance service requests to and receive responses from. + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. + * @throws NullPointerException if {@code endpoint} is null + * @throws IllegalArgumentException if {@code endpoint} cannot be parsed into a valid URL. + */ + public CachedSchemaRegistryClientBuilder(String schemaRegistryUrl) { + Objects.requireNonNull(schemaRegistryUrl, "'schemaRegistryUrl' cannot be null."); + + try { + new URL(schemaRegistryUrl); + } catch (MalformedURLException ex) { + throw log.logExceptionAsWarning(new IllegalArgumentException("'schemaRegistryUrl' must be a valid URL.", ex)); + } + + if (schemaRegistryUrl.endsWith("/")) { + this.schemaRegistryUrl = schemaRegistryUrl.substring(0, schemaRegistryUrl.length() - 1); + } else { + this.schemaRegistryUrl = schemaRegistryUrl; + } + + this.policies = new ArrayList<>(); + this.httpLogOptions = new HttpLogOptions(); + this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + this.typeParserDictionary = new HashMap<>(); + this.httpClient = null; + this.credential = null; + this.retryPolicy = new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS); + + Map properties = CoreUtils.getProperties(CLIENT_PROPERTIES); + clientName = properties.getOrDefault(NAME, "UnknownName"); + clientVersion = properties.getOrDefault(VERSION, "UnknownVersion"); + + this.headers = new HttpHeaders(); + } + + public CachedSchemaRegistryClientBuilder maxSchemaMapSize(int maxSchemaMapSize) throws IllegalArgumentException { + if (maxSchemaMapSize < CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM) { + throw new IllegalArgumentException( + String.format("Schema map size must be greater than %s entries", + CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM)); + } + this.maxSchemaMapSize = maxSchemaMapSize; + return this; + } + + public CachedSchemaRegistryClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * Sets the HTTP pipeline to use for the service client. + *

+ * If {@code pipeline} is set, all other HTTP settings are ignored to build {@link CachedSchemaRegistryClient}. + * + * @param httpPipeline The HTTP pipeline to use for sending service requests and receiving responses. + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. + */ + public CachedSchemaRegistryClientBuilder pipeline(HttpPipeline httpPipeline) { + if (this.httpPipeline != null && httpPipeline == null) { + log.info("HttpPipeline is being set to 'null' when it was previously configured."); + } + + this.httpPipeline = httpPipeline; + return this; + } + + + public CachedSchemaRegistryClientBuilder credential(TokenCredential credential) { + this.credential = Objects.requireNonNull(credential, "'credential' cannot be null."); + return this; + } + + /** + * Sets the logging configuration for HTTP requests and responses. + * + *

If logLevel is not provided, default value of {@link HttpLogDetailLevel#NONE} is set.

+ * + * @param logOptions The logging configuration to use when sending and receiving HTTP requests/responses. + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. + */ + public CachedSchemaRegistryClientBuilder httpLogOptions(HttpLogOptions logOptions) { + this.httpLogOptions = logOptions; + return this; + } + + /** + * Sets the {@link RetryPolicy} that is used when each request is sent. + *

+ * The default retry policy will be used if not provided to build {@link CachedSchemaRegistryClient} . + * + * @param retryPolicy user's retry policy applied to each request. + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. + */ + public CachedSchemaRegistryClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Adds a policy to the set of existing policies that are executed after required policies. + * + * @param policy The retry policy for service requests. + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. + * @throws NullPointerException If {@code policy} is {@code null}. + */ + public CachedSchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { + policies.add(Objects.requireNonNull(policy, "'policy' cannot be null.")); + return this; + } + + public CachedSchemaRegistryClientBuilder loadSchemaParser(String serializationType, Function parseMethod) { + if (serializationType == null || serializationType.isEmpty()) { + throw new IllegalArgumentException("Serialization type cannot be null or empty."); + } + if (this.typeParserDictionary.containsKey(serializationType.toLowerCase())) { + throw new IllegalArgumentException("Multiple parse methods for single serialization type may not be added."); + } + this.typeParserDictionary.put(serializationType.toLowerCase(), parseMethod); + return this; + } + + public CachedSchemaRegistryClient build() { + HttpPipeline pipeline = this.httpPipeline; + // Create a default Pipeline if it is not given + if (pipeline == null) { + // Closest to API goes first, closest to wire goes last. + final List policies = new ArrayList<>(); + + policies.add(new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, + Configuration.getGlobalConfiguration().clone())); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersPolicy(this.headers)); + + HttpPolicyProviders.addBeforeRetryPolicies(policies); + + policies.add(retryPolicy); + + policies.add(new AddDatePolicy()); + // Authentications + if (credential != null) { + // User token based policy + policies.add(new BearerTokenAuthenticationPolicy(credential, DEFAULT_SCOPE)); + } else { + // Throw exception that credential and tokenCredential cannot be null + throw log.logExceptionAsError( + new IllegalArgumentException("Missing credential information while building a client.")); + } + + policies.addAll(this.policies); + HttpPolicyProviders.addAfterRetryPolicies(policies); + + policies.add(new HttpLoggingPolicy(httpLogOptions)); + + pipeline = new HttpPipelineBuilder() + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .build(); + } + + return new CachedSchemaRegistryClient( + schemaRegistryUrl, + pipeline, + credential, + maxSchemaMapSize, + typeParserDictionary); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java index dc8f6fd1c240..3414679f2659 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java @@ -13,21 +13,21 @@ public class MockSchemaRegistryClient implements SchemaRegistryClient { - public final HashMap> typeParserDictionary; + public final HashMap> typeParserDictionary; - public final HashMap> guidCache; - public final HashMap> schemaStringCache; + public final HashMap guidCache; + public final HashMap schemaStringCache; public MockSchemaRegistryClient() { - this.guidCache = new HashMap>(); - this.schemaStringCache = new HashMap>(); - this.typeParserDictionary = new HashMap>(); + this.guidCache = new HashMap(); + this.schemaStringCache = new HashMap(); + this.typeParserDictionary = new HashMap>(); } - public void loadSchemaParser(String serializationFormat, Function f) {} + public void loadSchemaParser(String serializationFormat, Function f) {} @Override - public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { return schemaStringCache.get(schemaString); @@ -37,7 +37,7 @@ public SchemaRegistryObject register(String schemaGroup, String schemaName, S } @Override - public SchemaRegistryObject getSchemaByGuid(String schemaGuid) + public SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException { if (guidCache.containsKey(schemaGuid)) { return guidCache.get(schemaGuid); @@ -46,10 +46,10 @@ public SchemaRegistryObject getSchemaByGuid(String schemaGuid) } @Override - public String getGuid(String schemaGroup, String schemaName, String schemaString, String serializationType) + public String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { - return schemaStringCache.get(schemaString).schemaGuid; + return schemaStringCache.get(schemaString).schemaId; } return null; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java index 73c05e626dc0..33979ccb9af5 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java @@ -20,7 +20,7 @@ public interface SchemaRegistryClient { * @param serializationType tag used by schema registry store to identify schema serialization type, e.g. "avro" * @param parseMethod function to parse string into usable schema object */ - public void loadSchemaParser(String serializationType, Function parseMethod); + public void loadSchemaParser(String serializationType, Function parseMethod); /** * Registers a schema against backing schema registry store. @@ -33,7 +33,7 @@ public interface SchemaRegistryClient { * @throws SchemaRegistryClientException if registration operation fails * @throws IOException failed or interrupted I/O operation */ - public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, SchemaRegistryClientException; /** @@ -46,7 +46,7 @@ public SchemaRegistryObject register(String schemaGroup, String schemaName, S * @throws SchemaRegistryClientException if fetch operation fails * @throws IOException failed or interrupted I/O operation */ - public SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException; + public SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException; /** * Fetches schema GUID given schema group, name, string representation, and serialization type @@ -58,7 +58,7 @@ public SchemaRegistryObject register(String schemaGroup, String schemaName, S * @throws SchemaRegistryClientException if fetch operation fails * @throws IOException failed or interrupted I/O operation */ - public String getGuid(String schemaGroup, String schemaName, String schemaString, String serializationType) + public String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, SchemaRegistryClientException; /** diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java index 9e2ead44a995..ace30ea7f428 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java @@ -5,55 +5,48 @@ package com.azure.schemaregistry.client; -import com.azure.schemaregistry.client.rest.RestService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.charset.Charset; +import com.azure.core.util.logging.ClientLogger; import java.util.function.Function; /** * Stores all relevant information returned from SchemaRegistryClient layer. - * - * @param is derived from the parser function that is passed in the constructor. */ -public class SchemaRegistryObject { - private final Logger log; +public class SchemaRegistryObject { + private final ClientLogger log; - public final String schemaGuid; + public final String schemaId; public final String serializationType; - private final Charset encoding = RestService.SERVICE_CHARSET; - private Function parseMethod; + private Function parseMethod; public byte[] schemaByteArray; - private T deserialized; + private Object deserialized; public SchemaRegistryObject( - String schemaGuid, + String schemaId, String serializationType, byte[] schemaByteArray, - Function parseMethod) { - this.schemaGuid = schemaGuid; + Function parseMethod) { + this.schemaId = schemaId; this.serializationType = serializationType; this.schemaByteArray = schemaByteArray; this.deserialized = null; this.parseMethod = parseMethod; - this.log = LoggerFactory.getLogger(this.schemaGuid); + this.log = new ClientLogger(this.schemaId); } /** * @return schema object of type T, deserialized using stored schema parser method. */ - public T deserialize() { + public Object deserialize() { if (parseMethod == null) { - log.warn(String.format("No loaded parser for %s format. Schema guid: %s", this.serializationType, this.schemaGuid)); + log.warning(String.format("No loaded parser for %s format. Schema guid: %s", this.serializationType, this.schemaId)); return null; } if (this.deserialized == null) { - log.debug(String.format("Deserializing schema %s", new String(this.schemaByteArray, encoding))); - this.deserialized = parseMethod.apply(new String(this.schemaByteArray, encoding)); + log.verbose(String.format("Deserializing schema %s", new String(this.schemaByteArray))); + this.deserialized = parseMethod.apply(new String(this.schemaByteArray)); } return deserialized; } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java index 0347c296f364..fbd8c34c6a4d 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java @@ -1,4 +1,7 @@ /** - * Package containing the classes for CachedSchemaRegistryClient and AzureSchemaRegistryRestService. + * Package containing the classes for + * - SchemaRegistryClient interface + * - CachedSchemaRegistryClient + * - AzureSchemaRegistryRestService. */ package com.azure.schemaregistry.client; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java new file mode 100644 index 000000000000..f3fdef57df1a --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java @@ -0,0 +1,1396 @@ +package com.azure.schemaregistry.client.rest; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.Delete; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.schemaregistry.client.rest.models.CreateGroupResponse; +import com.azure.schemaregistry.client.rest.models.CreateSchemaResponse; +import com.azure.schemaregistry.client.rest.models.GetIdBySchemaContentResponse; +import com.azure.schemaregistry.client.rest.models.GetLatestSchemaResponse; +import com.azure.schemaregistry.client.rest.models.GetSchemaByIdResponse; +import com.azure.schemaregistry.client.rest.models.GetSchemaVersionResponse; +import com.azure.schemaregistry.client.rest.models.GetSchemaVersionsResponse; +import com.azure.schemaregistry.client.rest.models.GetSchemasByGroupResponse; +import com.azure.schemaregistry.client.rest.models.SchemaGroup; +import com.azure.schemaregistry.client.rest.models.SchemaId; +import java.util.List; +import java.util.UUID; +import reactor.core.publisher.Mono; + +/** Initializes a new instance of the AzureSchemaRegistryRestService type. */ +public final class AzureSchemaRegistryRestService { + /** The proxy service used to perform REST calls. */ + private final AzureSchemaRegistryRestServiceService service; + + /** server parameter. */ + private String host; + + /** + * Gets server parameter. + * + * @return the host value. + */ + public String getHost() { + return this.host; + } + + /** + * Sets server parameter. + * + * @param host the host value. + * @return the service client itself. + */ + public AzureSchemaRegistryRestService setHost(String host) { + this.host = host; + return this; + } + + /** The HTTP pipeline to send requests through. */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** Initializes an instance of AzureSchemaRegistryRestService client. */ + public AzureSchemaRegistryRestService() { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()).build()); + } + + /** + * Initializes an instance of AzureSchemaRegistryRestService client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + */ + public AzureSchemaRegistryRestService(HttpPipeline httpPipeline) { + this.httpPipeline = httpPipeline; + this.service = RestProxy.create(AzureSchemaRegistryRestServiceService.class, this.httpPipeline); + } + + /** + * The interface defining all the services for AzureSchemaRegistryRestService to be used by the proxy service to + * perform REST calls. + */ + @Host("{$host}") + @ServiceInterface(name = "AzureSchemaRegistryR") + private interface AzureSchemaRegistryRestServiceService { + @Get("/$schemagroups") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono>> getGroups(@HostParam("$host") String host, Context context); + + @Get("/$schemagroups/getSchemaById/{schema-id}") + @ExpectedResponses({200, 404}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono getSchemaById( + @HostParam("$host") String host, @PathParam("schema-id") UUID schemaId, Context context); + + @Get("/$schemagroups/{group-name}") + @ExpectedResponses({200, 404}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getGroup( + @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); + + @Put("/$schemagroups/{group-name}") + @ExpectedResponses({201, 409}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono createGroup( + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @BodyParam("application/json") SchemaGroup body, + Context context); + + @Delete("/$schemagroups/{group-name}") + @ExpectedResponses({204, 404}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> deleteGroup( + @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); + + @Get("/$schemagroups/{group-name}/schemas") + @ExpectedResponses({200, 404}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono getSchemasByGroup( + @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); + + @Delete("/$schemagroups/{group-name}/schemas") + @ExpectedResponses({204, 404}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> deleteSchemasByGroup( + @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); + + @Post("/$schemagroups/{group-name}/schemas/{schema-name}") + @ExpectedResponses({200, 404}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono getIdBySchemaContent( + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + @HeaderParam("X-Schema-Type") String xSchemaType, + @BodyParam("application/json") String body, + Context context); + + @Put("/$schemagroups/{group-name}/schemas/{schema-name}") + @ExpectedResponses({200, 400}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono createSchema( + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + @HeaderParam("X-Schema-Type") String xSchemaType, + @BodyParam("application/json") String body, + Context context); + + @Get("/$schemagroups/{group-name}/schemas/{schema-name}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono getLatestSchema( + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + Context context); + + @Delete("/$schemagroups/{group-name}/schemas/{schema-name}") + @ExpectedResponses({204, 404}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> deleteSchema( + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + Context context); + + @Get("/$schemagroups/{group-name}/schemas/{schema-name}/versions") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono getSchemaVersions( + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + Context context); + + @Get("/$schemagroups/{group-name}/schemas/{schema-name}/versions/{version-number}") + @ExpectedResponses({200, 404}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono getSchemaVersion( + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + @PathParam("version-number") int versionNumber, + Context context); + + @Delete("/$schemagroups/{group-name}/schemas/{schema-name}/versions/{version-number}") + @ExpectedResponses({204}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> deleteSchemaVersion( + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + @PathParam("version-number") int versionNumber, + Context context); + } + + /** + * Get all schema groups in namespace. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all schema groups in namespace. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono>> getGroupsWithResponseAsync() { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + return FluxUtil.withContext(context -> service.getGroups(this.getHost(), context)); + } + + /** + * Get all schema groups in namespace. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all schema groups in namespace. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono>> getGroupsWithResponseAsync(Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + return service.getGroups(this.getHost(), context); + } + + /** + * Get all schema groups in namespace. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all schema groups in namespace. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getGroupsAsync() { + return getGroupsWithResponseAsync() + .flatMap( + (SimpleResponse> res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Get all schema groups in namespace. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all schema groups in namespace. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public List getGroups() { + return getGroupsAsync().block(); + } + + /** + * Get schema by schema ID. + * + * @param schemaId schema ID referencing specific schema in registry namespace. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return schema by schema ID. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemaByIdWithResponseAsync(UUID schemaId) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (schemaId == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaId is required and cannot be null.")); + } + return FluxUtil.withContext(context -> service.getSchemaById(this.getHost(), schemaId, context)); + } + + /** + * Get schema by schema ID. + * + * @param schemaId schema ID referencing specific schema in registry namespace. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return schema by schema ID. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemaByIdWithResponseAsync(UUID schemaId, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (schemaId == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaId is required and cannot be null.")); + } + return service.getSchemaById(this.getHost(), schemaId, context); + } + + /** + * Get schema by schema ID. + * + * @param schemaId schema ID referencing specific schema in registry namespace. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return schema by schema ID. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemaByIdAsync(UUID schemaId) { + return getSchemaByIdWithResponseAsync(schemaId) + .flatMap( + (GetSchemaByIdResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Get schema by schema ID. + * + * @param schemaId schema ID referencing specific schema in registry namespace. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return schema by schema ID. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public String getSchemaById(UUID schemaId) { + return getSchemaByIdAsync(schemaId).block(); + + } + /** + * Get schema group description in registry namespace. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return schema group description in registry namespace. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getGroupWithResponseAsync(String groupName) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + return FluxUtil.withContext(context -> service.getGroup(this.getHost(), groupName, context)); + } + + /** + * Get schema group description in registry namespace. + * + * @param groupName schema group. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return schema group description in registry namespace. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getGroupWithResponseAsync(String groupName, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + return service.getGroup(this.getHost(), groupName, context); + } + + /** + * Get schema group description in registry namespace. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return schema group description in registry namespace. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getGroupAsync(String groupName) { + return getGroupWithResponseAsync(groupName) + .flatMap( + (SimpleResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Get schema group description in registry namespace. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return schema group description in registry namespace. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SchemaGroup getGroup(String groupName) { + return getGroupAsync(groupName).block(); + } + + /** + * Create schema group with specified schema type in registry namespace. + * + * @param groupName schema group. + * @param body schema group description. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono createGroupWithResponseAsync(String groupName, SchemaGroup body) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } else { + body.validate(); + } + return FluxUtil.withContext(context -> service.createGroup(this.getHost(), groupName, body, context)); + } + + /** + * Create schema group with specified schema type in registry namespace. + * + * @param groupName schema group. + * @param body schema group description. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono createGroupWithResponseAsync(String groupName, SchemaGroup body, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } else { + body.validate(); + } + return service.createGroup(this.getHost(), groupName, body, context); + } + + /** + * Create schema group with specified schema type in registry namespace. + * + * @param groupName schema group. + * @param body schema group description. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono createGroupAsync(String groupName, SchemaGroup body) { + return createGroupWithResponseAsync(groupName, body).flatMap((CreateGroupResponse res) -> Mono.empty()); + } + + /** + * Create schema group with specified schema type in registry namespace. + * + * @param groupName schema group. + * @param body schema group description. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void createGroup(String groupName, SchemaGroup body) { + createGroupAsync(groupName, body).block(); + } + + /** + * Delete schema group in schema registry namespace. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteGroupWithResponseAsync(String groupName) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + return FluxUtil.withContext(context -> service.deleteGroup(this.getHost(), groupName, context)); + } + + /** + * Delete schema group in schema registry namespace. + * + * @param groupName schema group. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteGroupWithResponseAsync(String groupName, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + return service.deleteGroup(this.getHost(), groupName, context); + } + + /** + * Delete schema group in schema registry namespace. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteGroupAsync(String groupName) { + return deleteGroupWithResponseAsync(groupName).flatMap((Response res) -> Mono.empty()); + } + + /** + * Delete schema group in schema registry namespace. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void deleteGroup(String groupName) { + deleteGroupAsync(groupName).block(); + } + + /** + * Returns schema by group name. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return array of String. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemasByGroupWithResponseAsync(String groupName) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + return FluxUtil.withContext(context -> service.getSchemasByGroup(this.getHost(), groupName, context)); + } + + /** + * Returns schema by group name. + * + * @param groupName schema group. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return array of String. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemasByGroupWithResponseAsync(String groupName, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + return service.getSchemasByGroup(this.getHost(), groupName, context); + } + + /** + * Returns schema by group name. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return array of String. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSchemasByGroupAsync(String groupName) { + return getSchemasByGroupWithResponseAsync(groupName) + .flatMap( + (GetSchemasByGroupResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Returns schema by group name. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return array of String. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public List getSchemasByGroup(String groupName) { + return getSchemasByGroupAsync(groupName).block(); + } + + /** + * Deletes all schemas under specified group name. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteSchemasByGroupWithResponseAsync(String groupName) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + return FluxUtil.withContext(context -> service.deleteSchemasByGroup(this.getHost(), groupName, context)); + } + + /** + * Deletes all schemas under specified group name. + * + * @param groupName schema group. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteSchemasByGroupWithResponseAsync(String groupName, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + return service.deleteSchemasByGroup(this.getHost(), groupName, context); + } + + /** + * Deletes all schemas under specified group name. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteSchemasByGroupAsync(String groupName) { + return deleteSchemasByGroupWithResponseAsync(groupName).flatMap((Response res) -> Mono.empty()); + } + + /** + * Deletes all schemas under specified group name. + * + * @param groupName schema group. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void deleteSchemasByGroup(String groupName) { + deleteSchemasByGroupAsync(groupName).block(); + } + + /** + * Get ID for schema with matching byte content and schema type. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param xSchemaType The xSchemaType parameter. + * @param body schema content. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return iD for schema with matching byte content and schema type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getIdBySchemaContentWithResponseAsync( + String groupName, String schemaName, String xSchemaType, String body) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + if (xSchemaType == null) { + return Mono.error(new IllegalArgumentException("Parameter xSchemaType is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } + return FluxUtil.withContext( + context -> + service.getIdBySchemaContent( + this.getHost(), groupName, schemaName, xSchemaType, body, context)); + } + + /** + * Get ID for schema with matching byte content and schema type. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param xSchemaType The xSchemaType parameter. + * @param body schema content. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return iD for schema with matching byte content and schema type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getIdBySchemaContentWithResponseAsync( + String groupName, String schemaName, String xSchemaType, String body, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + if (xSchemaType == null) { + return Mono.error(new IllegalArgumentException("Parameter xSchemaType is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } + return service.getIdBySchemaContent(this.getHost(), groupName, schemaName, xSchemaType, body, context); + } + + /** + * Get ID for schema with matching byte content and schema type. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param xSchemaType The xSchemaType parameter. + * @param body schema content. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return iD for schema with matching byte content and schema type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getIdBySchemaContentAsync( + String groupName, String schemaName, String xSchemaType, String body) { + return getIdBySchemaContentWithResponseAsync(groupName, schemaName, xSchemaType, body) + .flatMap( + (GetIdBySchemaContentResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Get ID for schema with matching byte content and schema type. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param xSchemaType The xSchemaType parameter. + * @param body schema content. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return iD for schema with matching byte content and schema type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SchemaId getIdBySchemaContent(String groupName, String schemaName, String xSchemaType, String body) { + return getIdBySchemaContentAsync(groupName, schemaName, xSchemaType, body).block(); + } + + /** + * Register schema. If schema of specified name does not exist in specified group, schema is created at version 1. + * If schema of specified name exists already in specified group, schema is created at latest version + 1. If schema + * with identical content already exists, existing schema's ID is returned. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param xSchemaType The xSchemaType parameter. + * @param body schema content. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono createSchemaWithResponseAsync( + String groupName, String schemaName, String xSchemaType, String body) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + if (xSchemaType == null) { + return Mono.error(new IllegalArgumentException("Parameter xSchemaType is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } + return FluxUtil.withContext( + context -> service.createSchema(this.getHost(), groupName, schemaName, xSchemaType, body, context)); + } + + /** + * Register schema. If schema of specified name does not exist in specified group, schema is created at version 1. + * If schema of specified name exists already in specified group, schema is created at latest version + 1. If schema + * with identical content already exists, existing schema's ID is returned. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param xSchemaType The xSchemaType parameter. + * @param body schema content. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono createSchemaWithResponseAsync( + String groupName, String schemaName, String xSchemaType, String body, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + if (xSchemaType == null) { + return Mono.error(new IllegalArgumentException("Parameter xSchemaType is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } + return service.createSchema(this.getHost(), groupName, schemaName, xSchemaType, body, context); + } + + /** + * Register schema. If schema of specified name does not exist in specified group, schema is created at version 1. + * If schema of specified name exists already in specified group, schema is created at latest version + 1. If schema + * with identical content already exists, existing schema's ID is returned. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param xSchemaType The xSchemaType parameter. + * @param body schema content. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono createSchemaAsync(String groupName, String schemaName, String xSchemaType, String body) { + return createSchemaWithResponseAsync(groupName, schemaName, xSchemaType, body) + .flatMap( + (CreateSchemaResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Register schema. If schema of specified name does not exist in specified group, schema is created at version 1. + * If schema of specified name exists already in specified group, schema is created at latest version + 1. If schema + * with identical content already exists, existing schema's ID is returned. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param xSchemaType The xSchemaType parameter. + * @param body schema content. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SchemaId createSchema(String groupName, String schemaName, String xSchemaType, String body) { + return createSchemaAsync(groupName, schemaName, xSchemaType, body).block(); + } + + /** + * Get latest version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return latest version of schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getLatestSchemaWithResponseAsync(String groupName, String schemaName) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return FluxUtil.withContext(context -> service.getLatestSchema(this.getHost(), groupName, schemaName, context)); + } + + /** + * Get latest version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return latest version of schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getLatestSchemaWithResponseAsync( + String groupName, String schemaName, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return service.getLatestSchema(this.getHost(), groupName, schemaName, context); + } + + /** + * Get latest version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return latest version of schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getLatestSchemaAsync(String groupName, String schemaName) { + return getLatestSchemaWithResponseAsync(groupName, schemaName) + .flatMap( + (GetLatestSchemaResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Get latest version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return latest version of schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public String getLatestSchema(String groupName, String schemaName) { + return getLatestSchemaAsync(groupName, schemaName).block(); + } + + /** + * Delete schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteSchemaWithResponseAsync(String groupName, String schemaName) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return FluxUtil.withContext(context -> service.deleteSchema(this.getHost(), groupName, schemaName, context)); + } + + /** + * Delete schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteSchemaWithResponseAsync(String groupName, String schemaName, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return service.deleteSchema(this.getHost(), groupName, schemaName, context); + } + + /** + * Delete schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteSchemaAsync(String groupName, String schemaName) { + return deleteSchemaWithResponseAsync(groupName, schemaName).flatMap((Response res) -> Mono.empty()); + } + + /** + * Delete schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void deleteSchema(String groupName, String schemaName) { + deleteSchemaAsync(groupName, schemaName).block(); + } + + /** + * Get list of versions for specified schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return list of versions for specified schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemaVersionsWithResponseAsync(String groupName, String schemaName) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return FluxUtil.withContext( + context -> service.getSchemaVersions(this.getHost(), groupName, schemaName, context)); + } + + /** + * Get list of versions for specified schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return list of versions for specified schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemaVersionsWithResponseAsync( + String groupName, String schemaName, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return service.getSchemaVersions(this.getHost(), groupName, schemaName, context); + } + + /** + * Get list of versions for specified schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return list of versions for specified schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSchemaVersionsAsync(String groupName, String schemaName) { + return getSchemaVersionsWithResponseAsync(groupName, schemaName) + .flatMap( + (GetSchemaVersionsResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Get list of versions for specified schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return list of versions for specified schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public List getSchemaVersions(String groupName, String schemaName) { + return getSchemaVersionsAsync(groupName, schemaName).block(); + } + + /** + * Get specified version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param versionNumber version number. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return specified version of schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemaVersionWithResponseAsync( + String groupName, String schemaName, int versionNumber) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return FluxUtil.withContext( + context -> service.getSchemaVersion(this.getHost(), groupName, schemaName, versionNumber, context)); + } + + /** + * Get specified version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param versionNumber version number. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return specified version of schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemaVersionWithResponseAsync( + String groupName, String schemaName, int versionNumber, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return service.getSchemaVersion(this.getHost(), groupName, schemaName, versionNumber, context); + } + + /** + * Get specified version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param versionNumber version number. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return specified version of schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSchemaVersionAsync(String groupName, String schemaName, int versionNumber) { + return getSchemaVersionWithResponseAsync(groupName, schemaName, versionNumber) + .flatMap( + (GetSchemaVersionResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Get specified version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param versionNumber version number. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return specified version of schema. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public String getSchemaVersion(String groupName, String schemaName, int versionNumber) { + return getSchemaVersionAsync(groupName, schemaName, versionNumber).block(); + } + + /** + * Delete specified version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param versionNumber version number. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteSchemaVersionWithResponseAsync( + String groupName, String schemaName, int versionNumber) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return FluxUtil.withContext( + context -> service.deleteSchemaVersion(this.getHost(), groupName, schemaName, versionNumber, context)); + } + + /** + * Delete specified version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param versionNumber version number. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteSchemaVersionWithResponseAsync( + String groupName, String schemaName, int versionNumber, Context context) { + if (this.getHost() == null) { + return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); + } + if (groupName == null) { + return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null.")); + } + if (schemaName == null) { + return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); + } + return service.deleteSchemaVersion(this.getHost(), groupName, schemaName, versionNumber, context); + } + + /** + * Delete specified version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param versionNumber version number. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteSchemaVersionAsync(String groupName, String schemaName, int versionNumber) { + return deleteSchemaVersionWithResponseAsync(groupName, schemaName, versionNumber) + .flatMap((Response res) -> Mono.empty()); + } + + /** + * Delete specified version of schema. + * + * @param groupName schema group. + * @param schemaName schema name. + * @param versionNumber version number. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void deleteSchemaVersion(String groupName, String schemaName, int versionNumber) { + deleteSchemaVersionAsync(groupName, schemaName, versionNumber).block(); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceBuilder.java new file mode 100644 index 000000000000..7a28963399e6 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceBuilder.java @@ -0,0 +1,64 @@ +package com.azure.schemaregistry.client.rest; + +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; + +/** A builder for creating a new instance of the AzureSchemaRegistryRestService type. */ +@ServiceClientBuilder(serviceClients = {AzureSchemaRegistryRestService.class}) +public final class AzureSchemaRegistryRestServiceBuilder { + /* + * server parameter + */ + private String host; + + /** + * Sets server parameter. + * + * @param host the host value. + * @return the AzureSchemaRegistryRestServiceBuilder. + */ + public AzureSchemaRegistryRestServiceBuilder host(String host) { + this.host = host; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the AzureSchemaRegistryRestServiceBuilder. + */ + public AzureSchemaRegistryRestServiceBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /** + * Builds an instance of AzureSchemaRegistryRestService with the provided parameters. + * + * @return an instance of AzureSchemaRegistryRestService. + */ + public AzureSchemaRegistryRestService buildClient() { + if (host == null) { + this.host = ""; + } + if (pipeline == null) { + this.pipeline = + new HttpPipelineBuilder() + .policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()) + .build(); + } + AzureSchemaRegistryRestService client = new AzureSchemaRegistryRestService(pipeline); + client.setHost(this.host); + return client; + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java deleted file mode 100644 index 99a7bc599dc9..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/RestService.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry.client.rest; - -import com.azure.schemaregistry.client.rest.entities.ErrorMessage; -import com.azure.schemaregistry.client.rest.entities.responses.RegisterSchemaResponse; -import com.azure.schemaregistry.client.rest.entities.responses.SchemaObjectResponse; -import com.azure.schemaregistry.client.rest.exceptions.RestClientException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSocketFactory; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.URL; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.Map; - -public class RestService { - private static final Logger log = LoggerFactory.getLogger(RestService.class); - private static final TypeReference REGISTER_RESPONSE_TYPE = - new TypeReference() { - }; - private static final TypeReference GET_SCHEMA_BY_GUID_RESPONSE_TYPE = - new TypeReference() { - }; - private static final TypeReference GET_LATEST_SCHEMA_RESPONSE_TYPE = - new TypeReference() { - }; - private static final TypeReference GET_SCHEMA_BY_VERSION_RESPONSE_TYPE = - new TypeReference() { - }; - - private static final int HTTP_CONNECT_TIMEOUT_MS = 60000; - private static final int HTTP_READ_TIMEOUT_MS = 60000; - - private static final int JSON_PARSE_ERROR_CODE = 50005; - private static ObjectMapper jsonDeserializer = new ObjectMapper(); - - public static Charset SERVICE_CHARSET = StandardCharsets.UTF_8; - - private static final String AUTHORIZATION_HEADER = "Authorization"; - - public static Map getDefaultRequestProperties(Map contentTypeEntryMap) { - String contentTypeValue = "application/json"; - if (contentTypeEntryMap != null) { - for (Map.Entry p : contentTypeEntryMap.entrySet()) { - contentTypeValue += ";" + p.getKey() + "=" + p.getValue(); - } - } - return Collections.singletonMap("Content-Type", contentTypeValue); - } - - private String registryUrl; - private String credentials; - private SSLSocketFactory sslSocketFactory; - private Map httpHeaders; - private Proxy proxy; - - public RestService(String registryUrl, String credentials) { - if (!validateRegistryNamespace(registryUrl)) { - throw new IllegalArgumentException(String.format("Improper registry namespace: %s", registryUrl)); - } - this.registryUrl = registryUrl; - this.credentials = credentials; - } - - private static boolean isNonEmpty(String s) { - return s != null && !s.isEmpty(); - } - - private static boolean isValidProxyConfig(String proxyHost, Integer proxyPort) { - return isNonEmpty(proxyHost) && proxyPort != null && proxyPort > 0; - } - - public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) { - this.sslSocketFactory = sslSocketFactory; - } - - /** - * @param requestUrl HTTP connection will be established with this url. - * @param method HTTP method ("GET", "POST", "PUT", etc.) - * @param requestBodyData Bytes to be sent in the request body. - * @param requestProperties HTTP header properties. - * @param responseFormat Expected format of the response to the HTTP request. - * @param The type of the deserialized response to the HTTP request. - * @return The deserialized response to the HTTP request, or null if no data is expected. - */ - @SuppressWarnings("unchecked") - private T sendHttpRequest(String requestUrl, String method, byte[] requestBodyData, - Map requestProperties, - TypeReference responseFormat) - throws IOException, RestClientException { - String requestData = requestBodyData == null - ? "null" - : new String(requestBodyData, StandardCharsets.UTF_8); - - HttpURLConnection connection = null; - try { - URL url = new URL(requestUrl); - - connection = buildConnection(url, method, requestProperties); - - log.debug(String.format("Sending %s with input %s to %s. Connection hc: %d.", - method, requestData, requestUrl, connection.hashCode())); - - if (requestBodyData != null) { - connection.setDoOutput(true); - try (OutputStream os = connection.getOutputStream()) { - os.write(requestBodyData); - os.flush(); - } catch (IOException e) { - log.error("Failed to send HTTP request to endpoint: " + url, e); - throw e; - } - } - - int responseCode = connection.getResponseCode(); - log.debug(String.format("Response code received: HTTP%d. Connection hc: %d.", - responseCode, connection.hashCode())); - if (responseCode == HttpURLConnection.HTTP_OK) { - T result; - if (responseFormat.getType().equals(SchemaObjectResponse.class)) { - result = (T)new SchemaObjectResponse(connection); - } - else { - InputStream is = connection.getInputStream(); - result = jsonDeserializer.readValue(is, responseFormat); - is.close(); - } - return result; - } else if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) { - return null; - } else { - ErrorMessage errorMessage; - try (InputStream es = connection.getErrorStream()) { - java.io.ByteArrayOutputStream streamContent = new java.io.ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int length; - while ((length = es.read(buffer)) != -1) { - streamContent.write(buffer, 0, length); - } - log.debug(new String(streamContent.toByteArray())); - errorMessage = jsonDeserializer.readValue(es, ErrorMessage.class); - } catch (JsonProcessingException e) { - errorMessage = new ErrorMessage(JSON_PARSE_ERROR_CODE, e.getMessage()); - } - throw new RestClientException(errorMessage.getMessage(), responseCode, - errorMessage.getErrorCode()); - } - - } finally { - if (connection != null) { - connection.disconnect(); - } - } - } - - private HttpURLConnection buildConnection(URL url, String method, Map requestProperties) - throws IOException { - HttpURLConnection connection = null; - if (proxy == null) { - connection = (HttpURLConnection) url.openConnection(); - } else { - connection = (HttpURLConnection) url.openConnection(proxy); - } - - connection.setConnectTimeout(HTTP_CONNECT_TIMEOUT_MS); - connection.setReadTimeout(HTTP_READ_TIMEOUT_MS); - - setupSsl(connection); - connection.setRequestMethod(method); - setAuthRequestHeaders(connection); - setCustomHeaders(connection); - // connection.getResponseCode() implicitly calls getInputStream, so always set to true. - // On the other hand, leaving this out breaks nothing. - connection.setDoInput(true); - - for (Map.Entry entry : requestProperties.entrySet()) { - connection.setRequestProperty(entry.getKey(), entry.getValue()); - } - - connection.setUseCaches(false); - - return connection; - } - - private void setupSsl(HttpURLConnection connection) { - if (connection instanceof HttpsURLConnection && sslSocketFactory != null) { - ((HttpsURLConnection)connection).setSSLSocketFactory(sslSocketFactory); - } - } - - private T httpRequest(String schemaGroup, - String schemaName, - String schemaVersion, - String method, - byte[] requestBodyData, - Map requestProperties, - Map queryMap, - TypeReference responseFormat) - throws IOException, RestClientException { - int retryCount = 3; - while (true) { - String requestUrl = buildRequestUrl(this.registryUrl, schemaGroup, schemaName, schemaVersion, queryMap); - try { - return sendHttpRequest(requestUrl, - method, - requestBodyData, - requestProperties, - responseFormat); - } catch (IOException e) { - retryCount--; - if (retryCount == 0) { - throw e; - } - } - } - } - - - /** - * @param registryUrl registry namespace - * @param schemaGroup group, may be null - * @param schemaName schema name, may be null - * @param schemaVersion schema version, may be null - * @param queryMap - * @return - */ - static String buildRequestUrl(String registryUrl, String schemaGroup, String schemaName, String schemaVersion, Map queryMap) { - StringBuilder builder = new StringBuilder(); - - builder.append("https://") - .append(registryUrl) - .append("/$schemagroups"); - - if (schemaGroup != null) { - builder.append("/") - .append(schemaGroup); - } - - if (schemaName != null) { - builder.append("/schemas/") - .append(schemaName); - } - - if (schemaVersion != null) { - builder.append("/versions/") - .append(schemaVersion); - } - - builder.append("?api-version=2017-04"); - - if (queryMap != null) { - for (String key : queryMap.keySet()) { - builder.append("&").append(key.trim()).append("=").append(queryMap.get(key).trim()); - } - } - - return builder.toString(); - } - - public String registerSchema(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, RestClientException { - RegisterSchemaResponse response = httpRequest( - schemaGroup, - schemaName, - null - , "PUT", - schemaString.getBytes(SERVICE_CHARSET), - getDefaultRequestProperties(Collections.singletonMap("serialization", serializationType)), - null, - REGISTER_RESPONSE_TYPE); - - return response.getId(); - } - - public String getGuid(String schemaGroup, String schemaName, String schemaString, String serializationType) throws IOException, RestClientException { - RegisterSchemaResponse response = httpRequest( - schemaGroup, schemaName, null, - "PUT", - schemaString.getBytes(SERVICE_CHARSET), - getDefaultRequestProperties(Collections.singletonMap("serialization", serializationType)), - null, - REGISTER_RESPONSE_TYPE); - - return response.getId(); - } - - public SchemaObjectResponse getSchemaByGuid(String schemaGuid) throws IOException, RestClientException { - Map queryMap = Collections.singletonMap("schema-id", schemaGuid); - return httpRequest( - null,null,null, - "GET", - null, - getDefaultRequestProperties(null), - queryMap, - GET_SCHEMA_BY_GUID_RESPONSE_TYPE); - } - - public SchemaObjectResponse getSchema(String schemaGroup, String schemaName, int version) throws IOException, RestClientException { - SchemaObjectResponse response; - - // latest version - if (version == -1) { - String path = String.format("/%s", schemaName); - response = httpRequest( - schemaGroup, - schemaName, - null, - "GET", - null, - getDefaultRequestProperties(null), - null, - GET_LATEST_SCHEMA_RESPONSE_TYPE); - } - else { - String path = String.format("/%s/$versions/%d", schemaName, version); - response = httpRequest( - schemaGroup, - schemaName, - String.valueOf(version), - "GET", - null, - getDefaultRequestProperties(null), - null, - GET_SCHEMA_BY_VERSION_RESPONSE_TYPE); - } - - return response; - } - - private void setAuthRequestHeaders(HttpURLConnection connection) { -// if (bearerAuthCredentialProvider != null) { -// String bearerToken = bearerAuthCredentialProvider.getBearerToken(connection.getURL()); -// if (bearerToken != null) { -// connection.setRequestProperty(AUTHORIZATION_HEADER, "Bearer " + bearerToken); -// } -// } - } - - private void setCustomHeaders(HttpURLConnection connection) { - if (httpHeaders != null) { - httpHeaders.forEach((k, v) -> connection.setRequestProperty(k, v)); - } - } -// -// public void setBearerAuthCredentialProvider( -// BearerAuthCredentialProvider bearerAuthCredentialProvider) { -// this.bearerAuthCredentialProvider = bearerAuthCredentialProvider; -// } - - public void setHttpHeaders(Map httpHeaders) { - this.httpHeaders = httpHeaders; - } - - public void setProxy(String proxyHost, int proxyPort) { - this.proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); - } - - private boolean validateRegistryNamespace(String registryNamespace) { - return registryNamespace.contains(".net") && !registryNamespace.contains("//"); - } -} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java deleted file mode 100644 index c1a2c483a3e7..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/ErrorMessage.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry.client.rest.entities; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Generic JSON error message. - */ -public class ErrorMessage { - - private int errorCode; - private String message; - - public ErrorMessage(@JsonProperty("error_code") int errorCode, - @JsonProperty("message") String message) { - this.errorCode = errorCode; - this.message = message; - } - - @JsonProperty("error_code") - public int getErrorCode() { - return errorCode; - } - - @JsonProperty("error_code") - public void setErrorCode(int error_code) { - this.errorCode = error_code; - } - - @JsonProperty - public String getMessage() { - return message; - } - - @JsonProperty - public void setMessage(String message) { - this.message = message; - } -} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java deleted file mode 100644 index ec9f668804cf..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/RegisterSchemaResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry.client.rest.entities.responses; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; - -import java.io.IOException; - -public class RegisterSchemaResponse { - - private String schemaGuid; - - public static RegisterSchemaResponse fromJson(String json) throws IOException { - return new ObjectMapper() - .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true) - .readValue(json, RegisterSchemaResponse.class); - } - - public String toJson() throws IOException { - return new ObjectMapper().writeValueAsString(this); - } - - @JsonProperty("Id") - public String getId() { - return this.schemaGuid; - } - - @JsonProperty("Id") - public void setId(String schemaGuid) { - this.schemaGuid = schemaGuid; - } -} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java deleted file mode 100644 index 0896e9b88f3c..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/entities/responses/SchemaObjectResponse.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry.client.rest.entities.responses; - -import com.azure.schemaregistry.client.rest.exceptions.RestClientException; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; - -public class SchemaObjectResponse { - public final byte[] schemaByteArray; - public final String serializationType; - public final String schemaGuid; - - public SchemaObjectResponse(HttpURLConnection connection) throws RestClientException, IOException { - this.serializationType = getSerializationType(connection.getHeaderField("content-type")); - this.schemaGuid = connection.getHeaderField("Schema-Id"); - - InputStream is = connection.getInputStream(); - ByteArrayOutputStream streamContent = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int length; - while ((length = is.read(buffer)) != -1) { - streamContent.write(buffer, 0, length); - } - schemaByteArray = streamContent.toByteArray(); - is.close(); - } - - // for testing - public SchemaObjectResponse(byte[] schemaByteArray, String serializationType, String schemaGuid) { - this.schemaByteArray = schemaByteArray; - this.serializationType = serializationType; - this.schemaGuid = schemaGuid; - } - - static String getSerializationType(String contentTypeHeader) throws RestClientException { - String[] contentTypeTokens = contentTypeHeader.split(";"); - for (String contentTypeToken : contentTypeTokens) { - if (contentTypeToken.contains("serialization")) { - return contentTypeToken.split("=")[1]; - } - } - throw new RestClientException(String.format("No serialization type defined in header: %s", contentTypeHeader), 0 , 0); - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java deleted file mode 100644 index a6f3be3c67d2..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/exceptions/RestClientException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry.client.rest.exceptions; - -public class RestClientException extends Exception { - private final int status; - private final int errorCode; - - public RestClientException(final String message, final int status, final int errorCode) { - super(message + "; error code: " + errorCode); - this.status = status; - this.errorCode = errorCode; - } - - public int getStatus() { - return status; - } - - public int getErrorCode() { - return errorCode; - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java new file mode 100644 index 000000000000..8b6f82ac1275 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java @@ -0,0 +1,41 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** The CreateGroupHeaders model. */ +@Fluent +public final class CreateGroupHeaders { + /* + * The Location property. + */ + @JsonProperty(value = "Location") + private String location; + + /** + * Get the location property: The Location property. + * + * @return the location value. + */ + public String getLocation() { + return this.location; + } + + /** + * Set the location property: The Location property. + * + * @param location the location value to set. + * @return the CreateGroupHeaders object itself. + */ + public CreateGroupHeaders setLocation(String location) { + this.location = location; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java new file mode 100644 index 000000000000..4c4e47bbd934 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java @@ -0,0 +1,22 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.rest.ResponseBase; + +/** Contains all response data for the createGroup operation. */ +public final class CreateGroupResponse extends ResponseBase { + /** + * Creates an instance of CreateGroupResponse. + * + * @param request the request which resulted in this CreateGroupResponse. + * @param statusCode the status code of the HTTP response. + * @param rawHeaders the raw headers of the HTTP response. + * @param value the deserialized value of the HTTP response. + * @param headers the deserialized headers of the HTTP response. + */ + public CreateGroupResponse( + HttpRequest request, int statusCode, HttpHeaders rawHeaders, Void value, CreateGroupHeaders headers) { + super(request, statusCode, rawHeaders, value, headers); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java new file mode 100644 index 000000000000..ee1dc4292e62 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java @@ -0,0 +1,147 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.net.URL; +import java.util.UUID; + +/** The CreateSchemaHeaders model. */ +@Fluent +public final class CreateSchemaHeaders { + /* + * The X-Schema-Version property. + */ + @JsonProperty(value = "X-Schema-Version") + private Integer xSchemaVersion; + + /* + * The X-Schema-Type property. + */ + @JsonProperty(value = "X-Schema-Type") + private String xSchemaType; + + /* + * The X-Schema-Id property. + */ + @JsonProperty(value = "X-Schema-Id") + private UUID xSchemaId; + + /* + * The X-Schema-Id-Location property. + */ + @JsonProperty(value = "X-Schema-Id-Location") + private URL xSchemaIdLocation; + + /* + * The Location property. + */ + @JsonProperty(value = "Location") + private String location; + + /** + * Get the xSchemaVersion property: The X-Schema-Version property. + * + * @return the xSchemaVersion value. + */ + public Integer getXSchemaVersion() { + return this.xSchemaVersion; + } + + /** + * Set the xSchemaVersion property: The X-Schema-Version property. + * + * @param xSchemaVersion the xSchemaVersion value to set. + * @return the CreateSchemaHeaders object itself. + */ + public CreateSchemaHeaders setXSchemaVersion(Integer xSchemaVersion) { + this.xSchemaVersion = xSchemaVersion; + return this; + } + + /** + * Get the xSchemaType property: The X-Schema-Type property. + * + * @return the xSchemaType value. + */ + public String getXSchemaType() { + return this.xSchemaType; + } + + /** + * Set the xSchemaType property: The X-Schema-Type property. + * + * @param xSchemaType the xSchemaType value to set. + * @return the CreateSchemaHeaders object itself. + */ + public CreateSchemaHeaders setXSchemaType(String xSchemaType) { + this.xSchemaType = xSchemaType; + return this; + } + + /** + * Get the xSchemaId property: The X-Schema-Id property. + * + * @return the xSchemaId value. + */ + public UUID getXSchemaId() { + return this.xSchemaId; + } + + /** + * Set the xSchemaId property: The X-Schema-Id property. + * + * @param xSchemaId the xSchemaId value to set. + * @return the CreateSchemaHeaders object itself. + */ + public CreateSchemaHeaders setXSchemaId(UUID xSchemaId) { + this.xSchemaId = xSchemaId; + return this; + } + + /** + * Get the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @return the xSchemaIdLocation value. + */ + public URL getXSchemaIdLocation() { + return this.xSchemaIdLocation; + } + + /** + * Set the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @param xSchemaIdLocation the xSchemaIdLocation value to set. + * @return the CreateSchemaHeaders object itself. + */ + public CreateSchemaHeaders setXSchemaIdLocation(URL xSchemaIdLocation) { + this.xSchemaIdLocation = xSchemaIdLocation; + return this; + } + + /** + * Get the location property: The Location property. + * + * @return the location value. + */ + public String getLocation() { + return this.location; + } + + /** + * Set the location property: The Location property. + * + * @param location the location value to set. + * @return the CreateSchemaHeaders object itself. + */ + public CreateSchemaHeaders setLocation(String location) { + this.location = location; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java new file mode 100644 index 000000000000..5320db393457 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java @@ -0,0 +1,28 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.rest.ResponseBase; + +/** Contains all response data for the createSchema operation. */ +public final class CreateSchemaResponse extends ResponseBase { + /** + * Creates an instance of CreateSchemaResponse. + * + * @param request the request which resulted in this CreateSchemaResponse. + * @param statusCode the status code of the HTTP response. + * @param rawHeaders the raw headers of the HTTP response. + * @param value the deserialized value of the HTTP response. + * @param headers the deserialized headers of the HTTP response. + */ + public CreateSchemaResponse( + HttpRequest request, int statusCode, HttpHeaders rawHeaders, SchemaId value, CreateSchemaHeaders headers) { + super(request, statusCode, rawHeaders, value, headers); + } + + /** @return the deserialized response body. */ + @Override + public SchemaId getValue() { + return super.getValue(); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java new file mode 100644 index 000000000000..ed46a2a0c16f --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java @@ -0,0 +1,147 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.net.URL; +import java.util.UUID; + +/** The GetIdBySchemaContentHeaders model. */ +@Fluent +public final class GetIdBySchemaContentHeaders { + /* + * The X-Schema-Version property. + */ + @JsonProperty(value = "X-Schema-Version") + private Integer xSchemaVersion; + + /* + * The X-Schema-Type property. + */ + @JsonProperty(value = "X-Schema-Type") + private String xSchemaType; + + /* + * The X-Schema-Id property. + */ + @JsonProperty(value = "X-Schema-Id") + private UUID xSchemaId; + + /* + * The X-Schema-Id-Location property. + */ + @JsonProperty(value = "X-Schema-Id-Location") + private URL xSchemaIdLocation; + + /* + * The Location property. + */ + @JsonProperty(value = "Location") + private String location; + + /** + * Get the xSchemaVersion property: The X-Schema-Version property. + * + * @return the xSchemaVersion value. + */ + public Integer getXSchemaVersion() { + return this.xSchemaVersion; + } + + /** + * Set the xSchemaVersion property: The X-Schema-Version property. + * + * @param xSchemaVersion the xSchemaVersion value to set. + * @return the GetIdBySchemaContentHeaders object itself. + */ + public GetIdBySchemaContentHeaders setXSchemaVersion(Integer xSchemaVersion) { + this.xSchemaVersion = xSchemaVersion; + return this; + } + + /** + * Get the xSchemaType property: The X-Schema-Type property. + * + * @return the xSchemaType value. + */ + public String getXSchemaType() { + return this.xSchemaType; + } + + /** + * Set the xSchemaType property: The X-Schema-Type property. + * + * @param xSchemaType the xSchemaType value to set. + * @return the GetIdBySchemaContentHeaders object itself. + */ + public GetIdBySchemaContentHeaders setXSchemaType(String xSchemaType) { + this.xSchemaType = xSchemaType; + return this; + } + + /** + * Get the xSchemaId property: The X-Schema-Id property. + * + * @return the xSchemaId value. + */ + public UUID getXSchemaId() { + return this.xSchemaId; + } + + /** + * Set the xSchemaId property: The X-Schema-Id property. + * + * @param xSchemaId the xSchemaId value to set. + * @return the GetIdBySchemaContentHeaders object itself. + */ + public GetIdBySchemaContentHeaders setXSchemaId(UUID xSchemaId) { + this.xSchemaId = xSchemaId; + return this; + } + + /** + * Get the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @return the xSchemaIdLocation value. + */ + public URL getXSchemaIdLocation() { + return this.xSchemaIdLocation; + } + + /** + * Set the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @param xSchemaIdLocation the xSchemaIdLocation value to set. + * @return the GetIdBySchemaContentHeaders object itself. + */ + public GetIdBySchemaContentHeaders setXSchemaIdLocation(URL xSchemaIdLocation) { + this.xSchemaIdLocation = xSchemaIdLocation; + return this; + } + + /** + * Get the location property: The Location property. + * + * @return the location value. + */ + public String getLocation() { + return this.location; + } + + /** + * Set the location property: The Location property. + * + * @param location the location value to set. + * @return the GetIdBySchemaContentHeaders object itself. + */ + public GetIdBySchemaContentHeaders setLocation(String location) { + this.location = location; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java new file mode 100644 index 000000000000..0e3ef3336879 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java @@ -0,0 +1,32 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.rest.ResponseBase; + +/** Contains all response data for the getIdBySchemaContent operation. */ +public final class GetIdBySchemaContentResponse extends ResponseBase { + /** + * Creates an instance of GetIdBySchemaContentResponse. + * + * @param request the request which resulted in this GetIdBySchemaContentResponse. + * @param statusCode the status code of the HTTP response. + * @param rawHeaders the raw headers of the HTTP response. + * @param value the deserialized value of the HTTP response. + * @param headers the deserialized headers of the HTTP response. + */ + public GetIdBySchemaContentResponse( + HttpRequest request, + int statusCode, + HttpHeaders rawHeaders, + SchemaId value, + GetIdBySchemaContentHeaders headers) { + super(request, statusCode, rawHeaders, value, headers); + } + + /** @return the deserialized response body. */ + @Override + public SchemaId getValue() { + return super.getValue(); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java new file mode 100644 index 000000000000..94072e763527 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java @@ -0,0 +1,147 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.net.URL; +import java.util.UUID; + +/** The GetLatestSchemaHeaders model. */ +@Fluent +public final class GetLatestSchemaHeaders { + /* + * The X-Schema-Version property. + */ + @JsonProperty(value = "X-Schema-Version") + private Integer xSchemaVersion; + + /* + * The X-Schema-Type property. + */ + @JsonProperty(value = "X-Schema-Type") + private String xSchemaType; + + /* + * The X-Schema-Id property. + */ + @JsonProperty(value = "X-Schema-Id") + private UUID xSchemaId; + + /* + * The X-Schema-Id-Location property. + */ + @JsonProperty(value = "X-Schema-Id-Location") + private URL xSchemaIdLocation; + + /* + * The Location property. + */ + @JsonProperty(value = "Location") + private String location; + + /** + * Get the xSchemaVersion property: The X-Schema-Version property. + * + * @return the xSchemaVersion value. + */ + public Integer getXSchemaVersion() { + return this.xSchemaVersion; + } + + /** + * Set the xSchemaVersion property: The X-Schema-Version property. + * + * @param xSchemaVersion the xSchemaVersion value to set. + * @return the GetLatestSchemaHeaders object itself. + */ + public GetLatestSchemaHeaders setXSchemaVersion(Integer xSchemaVersion) { + this.xSchemaVersion = xSchemaVersion; + return this; + } + + /** + * Get the xSchemaType property: The X-Schema-Type property. + * + * @return the xSchemaType value. + */ + public String getXSchemaType() { + return this.xSchemaType; + } + + /** + * Set the xSchemaType property: The X-Schema-Type property. + * + * @param xSchemaType the xSchemaType value to set. + * @return the GetLatestSchemaHeaders object itself. + */ + public GetLatestSchemaHeaders setXSchemaType(String xSchemaType) { + this.xSchemaType = xSchemaType; + return this; + } + + /** + * Get the xSchemaId property: The X-Schema-Id property. + * + * @return the xSchemaId value. + */ + public UUID getXSchemaId() { + return this.xSchemaId; + } + + /** + * Set the xSchemaId property: The X-Schema-Id property. + * + * @param xSchemaId the xSchemaId value to set. + * @return the GetLatestSchemaHeaders object itself. + */ + public GetLatestSchemaHeaders setXSchemaId(UUID xSchemaId) { + this.xSchemaId = xSchemaId; + return this; + } + + /** + * Get the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @return the xSchemaIdLocation value. + */ + public URL getXSchemaIdLocation() { + return this.xSchemaIdLocation; + } + + /** + * Set the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @param xSchemaIdLocation the xSchemaIdLocation value to set. + * @return the GetLatestSchemaHeaders object itself. + */ + public GetLatestSchemaHeaders setXSchemaIdLocation(URL xSchemaIdLocation) { + this.xSchemaIdLocation = xSchemaIdLocation; + return this; + } + + /** + * Get the location property: The Location property. + * + * @return the location value. + */ + public String getLocation() { + return this.location; + } + + /** + * Set the location property: The Location property. + * + * @param location the location value to set. + * @return the GetLatestSchemaHeaders object itself. + */ + public GetLatestSchemaHeaders setLocation(String location) { + this.location = location; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java new file mode 100644 index 000000000000..2f766f03f1b4 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java @@ -0,0 +1,28 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.rest.ResponseBase; + +/** Contains all response data for the getLatestSchema operation. */ +public final class GetLatestSchemaResponse extends ResponseBase { + /** + * Creates an instance of GetLatestSchemaResponse. + * + * @param request the request which resulted in this GetLatestSchemaResponse. + * @param statusCode the status code of the HTTP response. + * @param rawHeaders the raw headers of the HTTP response. + * @param value the deserialized value of the HTTP response. + * @param headers the deserialized headers of the HTTP response. + */ + public GetLatestSchemaResponse( + HttpRequest request, int statusCode, HttpHeaders rawHeaders, String value, GetLatestSchemaHeaders headers) { + super(request, statusCode, rawHeaders, value, headers); + } + + /** @return the deserialized response body. */ + @Override + public String getValue() { + return super.getValue(); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java new file mode 100644 index 000000000000..a41fd8e4c9de --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java @@ -0,0 +1,147 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.net.URL; +import java.util.UUID; + +/** The GetSchemaByIdHeaders model. */ +@Fluent +public final class GetSchemaByIdHeaders { + /* + * The X-Schema-Version property. + */ + @JsonProperty(value = "X-Schema-Version") + private Integer xSchemaVersion; + + /* + * The X-Schema-Type property. + */ + @JsonProperty(value = "X-Schema-Type") + private String xSchemaType; + + /* + * The X-Schema-Id property. + */ + @JsonProperty(value = "X-Schema-Id") + private UUID xSchemaId; + + /* + * The X-Schema-Id-Location property. + */ + @JsonProperty(value = "X-Schema-Id-Location") + private URL xSchemaIdLocation; + + /* + * The Location property. + */ + @JsonProperty(value = "Location") + private String location; + + /** + * Get the xSchemaVersion property: The X-Schema-Version property. + * + * @return the xSchemaVersion value. + */ + public Integer getXSchemaVersion() { + return this.xSchemaVersion; + } + + /** + * Set the xSchemaVersion property: The X-Schema-Version property. + * + * @param xSchemaVersion the xSchemaVersion value to set. + * @return the GetSchemaByIdHeaders object itself. + */ + public GetSchemaByIdHeaders setXSchemaVersion(Integer xSchemaVersion) { + this.xSchemaVersion = xSchemaVersion; + return this; + } + + /** + * Get the xSchemaType property: The X-Schema-Type property. + * + * @return the xSchemaType value. + */ + public String getXSchemaType() { + return this.xSchemaType; + } + + /** + * Set the xSchemaType property: The X-Schema-Type property. + * + * @param xSchemaType the xSchemaType value to set. + * @return the GetSchemaByIdHeaders object itself. + */ + public GetSchemaByIdHeaders setXSchemaType(String xSchemaType) { + this.xSchemaType = xSchemaType; + return this; + } + + /** + * Get the xSchemaId property: The X-Schema-Id property. + * + * @return the xSchemaId value. + */ + public UUID getXSchemaId() { + return this.xSchemaId; + } + + /** + * Set the xSchemaId property: The X-Schema-Id property. + * + * @param xSchemaId the xSchemaId value to set. + * @return the GetSchemaByIdHeaders object itself. + */ + public GetSchemaByIdHeaders setXSchemaId(UUID xSchemaId) { + this.xSchemaId = xSchemaId; + return this; + } + + /** + * Get the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @return the xSchemaIdLocation value. + */ + public URL getXSchemaIdLocation() { + return this.xSchemaIdLocation; + } + + /** + * Set the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @param xSchemaIdLocation the xSchemaIdLocation value to set. + * @return the GetSchemaByIdHeaders object itself. + */ + public GetSchemaByIdHeaders setXSchemaIdLocation(URL xSchemaIdLocation) { + this.xSchemaIdLocation = xSchemaIdLocation; + return this; + } + + /** + * Get the location property: The Location property. + * + * @return the location value. + */ + public String getLocation() { + return this.location; + } + + /** + * Set the location property: The Location property. + * + * @param location the location value to set. + * @return the GetSchemaByIdHeaders object itself. + */ + public GetSchemaByIdHeaders setLocation(String location) { + this.location = location; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java new file mode 100644 index 000000000000..2be80766be08 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java @@ -0,0 +1,28 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.rest.ResponseBase; + +/** Contains all response data for the getSchemaById operation. */ +public final class GetSchemaByIdResponse extends ResponseBase { + /** + * Creates an instance of GetSchemaByIdResponse. + * + * @param request the request which resulted in this GetSchemaByIdResponse. + * @param statusCode the status code of the HTTP response. + * @param rawHeaders the raw headers of the HTTP response. + * @param value the deserialized value of the HTTP response. + * @param headers the deserialized headers of the HTTP response. + */ + public GetSchemaByIdResponse( + HttpRequest request, int statusCode, HttpHeaders rawHeaders, String value, GetSchemaByIdHeaders headers) { + super(request, statusCode, rawHeaders, value, headers); + } + + /** @return the deserialized response body. */ + @Override + public String getValue() { + return super.getValue(); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java new file mode 100644 index 000000000000..e4742e04be7b --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java @@ -0,0 +1,147 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.net.URL; +import java.util.UUID; + +/** The GetSchemaVersionHeaders model. */ +@Fluent +public final class GetSchemaVersionHeaders { + /* + * The X-Schema-Version property. + */ + @JsonProperty(value = "X-Schema-Version") + private Integer xSchemaVersion; + + /* + * The X-Schema-Type property. + */ + @JsonProperty(value = "X-Schema-Type") + private String xSchemaType; + + /* + * The X-Schema-Id property. + */ + @JsonProperty(value = "X-Schema-Id") + private UUID xSchemaId; + + /* + * The X-Schema-Id-Location property. + */ + @JsonProperty(value = "X-Schema-Id-Location") + private URL xSchemaIdLocation; + + /* + * The Location property. + */ + @JsonProperty(value = "Location") + private String location; + + /** + * Get the xSchemaVersion property: The X-Schema-Version property. + * + * @return the xSchemaVersion value. + */ + public Integer getXSchemaVersion() { + return this.xSchemaVersion; + } + + /** + * Set the xSchemaVersion property: The X-Schema-Version property. + * + * @param xSchemaVersion the xSchemaVersion value to set. + * @return the GetSchemaVersionHeaders object itself. + */ + public GetSchemaVersionHeaders setXSchemaVersion(Integer xSchemaVersion) { + this.xSchemaVersion = xSchemaVersion; + return this; + } + + /** + * Get the xSchemaType property: The X-Schema-Type property. + * + * @return the xSchemaType value. + */ + public String getXSchemaType() { + return this.xSchemaType; + } + + /** + * Set the xSchemaType property: The X-Schema-Type property. + * + * @param xSchemaType the xSchemaType value to set. + * @return the GetSchemaVersionHeaders object itself. + */ + public GetSchemaVersionHeaders setXSchemaType(String xSchemaType) { + this.xSchemaType = xSchemaType; + return this; + } + + /** + * Get the xSchemaId property: The X-Schema-Id property. + * + * @return the xSchemaId value. + */ + public UUID getXSchemaId() { + return this.xSchemaId; + } + + /** + * Set the xSchemaId property: The X-Schema-Id property. + * + * @param xSchemaId the xSchemaId value to set. + * @return the GetSchemaVersionHeaders object itself. + */ + public GetSchemaVersionHeaders setXSchemaId(UUID xSchemaId) { + this.xSchemaId = xSchemaId; + return this; + } + + /** + * Get the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @return the xSchemaIdLocation value. + */ + public URL getXSchemaIdLocation() { + return this.xSchemaIdLocation; + } + + /** + * Set the xSchemaIdLocation property: The X-Schema-Id-Location property. + * + * @param xSchemaIdLocation the xSchemaIdLocation value to set. + * @return the GetSchemaVersionHeaders object itself. + */ + public GetSchemaVersionHeaders setXSchemaIdLocation(URL xSchemaIdLocation) { + this.xSchemaIdLocation = xSchemaIdLocation; + return this; + } + + /** + * Get the location property: The Location property. + * + * @return the location value. + */ + public String getLocation() { + return this.location; + } + + /** + * Set the location property: The Location property. + * + * @param location the location value to set. + * @return the GetSchemaVersionHeaders object itself. + */ + public GetSchemaVersionHeaders setLocation(String location) { + this.location = location; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java new file mode 100644 index 000000000000..1b96f7c670d1 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java @@ -0,0 +1,32 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.rest.ResponseBase; + +/** Contains all response data for the getSchemaVersion operation. */ +public final class GetSchemaVersionResponse extends ResponseBase { + /** + * Creates an instance of GetSchemaVersionResponse. + * + * @param request the request which resulted in this GetSchemaVersionResponse. + * @param statusCode the status code of the HTTP response. + * @param rawHeaders the raw headers of the HTTP response. + * @param value the deserialized value of the HTTP response. + * @param headers the deserialized headers of the HTTP response. + */ + public GetSchemaVersionResponse( + HttpRequest request, + int statusCode, + HttpHeaders rawHeaders, + String value, + GetSchemaVersionHeaders headers) { + super(request, statusCode, rawHeaders, value, headers); + } + + /** @return the deserialized response body. */ + @Override + public String getValue() { + return super.getValue(); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java new file mode 100644 index 000000000000..bc05b2c1c908 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java @@ -0,0 +1,41 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** The GetSchemaVersionsHeaders model. */ +@Fluent +public final class GetSchemaVersionsHeaders { + /* + * The X-Schema-Type property. + */ + @JsonProperty(value = "X-Schema-Type") + private String xSchemaType; + + /** + * Get the xSchemaType property: The X-Schema-Type property. + * + * @return the xSchemaType value. + */ + public String getXSchemaType() { + return this.xSchemaType; + } + + /** + * Set the xSchemaType property: The X-Schema-Type property. + * + * @param xSchemaType the xSchemaType value to set. + * @return the GetSchemaVersionsHeaders object itself. + */ + public GetSchemaVersionsHeaders setXSchemaType(String xSchemaType) { + this.xSchemaType = xSchemaType; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java new file mode 100644 index 000000000000..22d31d3264db --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java @@ -0,0 +1,33 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.rest.ResponseBase; +import java.util.List; + +/** Contains all response data for the getSchemaVersions operation. */ +public final class GetSchemaVersionsResponse extends ResponseBase> { + /** + * Creates an instance of GetSchemaVersionsResponse. + * + * @param request the request which resulted in this GetSchemaVersionsResponse. + * @param statusCode the status code of the HTTP response. + * @param rawHeaders the raw headers of the HTTP response. + * @param value the deserialized value of the HTTP response. + * @param headers the deserialized headers of the HTTP response. + */ + public GetSchemaVersionsResponse( + HttpRequest request, + int statusCode, + HttpHeaders rawHeaders, + List value, + GetSchemaVersionsHeaders headers) { + super(request, statusCode, rawHeaders, value, headers); + } + + /** @return the deserialized response body. */ + @Override + public List getValue() { + return super.getValue(); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java new file mode 100644 index 000000000000..1f4bddb08893 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java @@ -0,0 +1,41 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** The GetSchemasByGroupHeaders model. */ +@Fluent +public final class GetSchemasByGroupHeaders { + /* + * The X-Schema-Type property. + */ + @JsonProperty(value = "X-Schema-Type") + private String xSchemaType; + + /** + * Get the xSchemaType property: The X-Schema-Type property. + * + * @return the xSchemaType value. + */ + public String getXSchemaType() { + return this.xSchemaType; + } + + /** + * Set the xSchemaType property: The X-Schema-Type property. + * + * @param xSchemaType the xSchemaType value to set. + * @return the GetSchemasByGroupHeaders object itself. + */ + public GetSchemasByGroupHeaders setXSchemaType(String xSchemaType) { + this.xSchemaType = xSchemaType; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java new file mode 100644 index 000000000000..07e069e22c88 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java @@ -0,0 +1,33 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.rest.ResponseBase; +import java.util.List; + +/** Contains all response data for the getSchemasByGroup operation. */ +public final class GetSchemasByGroupResponse extends ResponseBase> { + /** + * Creates an instance of GetSchemasByGroupResponse. + * + * @param request the request which resulted in this GetSchemasByGroupResponse. + * @param statusCode the status code of the HTTP response. + * @param rawHeaders the raw headers of the HTTP response. + * @param value the deserialized value of the HTTP response. + * @param headers the deserialized headers of the HTTP response. + */ + public GetSchemasByGroupResponse( + HttpRequest request, + int statusCode, + HttpHeaders rawHeaders, + List value, + GetSchemasByGroupHeaders headers) { + super(request, statusCode, rawHeaders, value, headers); + } + + /** @return the deserialized response body. */ + @Override + public List getValue() { + return super.getValue(); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java new file mode 100644 index 000000000000..16e46234b171 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java @@ -0,0 +1,173 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.time.OffsetDateTime; +import java.util.Map; + +/** The SchemaGroup model. */ +@Fluent +public final class SchemaGroup { + /* + * The name property. + */ + @JsonProperty(value = "name") + private String name; + + /* + * The createdTimeUtc property. + */ + @JsonProperty(value = "createdTimeUtc") + private OffsetDateTime createdTimeUtc; + + /* + * The updatedTimeUtc property. + */ + @JsonProperty(value = "updatedTimeUtc") + private OffsetDateTime updatedTimeUtc; + + /* + * The schemaType property. + */ + @JsonProperty(value = "schemaType") + private String schemaType; + + /* + * schema compatibility mode enum, defined by supported schema type + */ + @JsonProperty(value = "schemaCompatibility") + private Integer schemaCompatibility; + + /* + * Dictionary of + */ + @JsonProperty(value = "groupProperties") + private Map groupProperties; + + /** + * Get the name property: The name property. + * + * @return the name value. + */ + public String getName() { + return this.name; + } + + /** + * Set the name property: The name property. + * + * @param name the name value to set. + * @return the SchemaGroup object itself. + */ + public SchemaGroup setName(String name) { + this.name = name; + return this; + } + + /** + * Get the createdTimeUtc property: The createdTimeUtc property. + * + * @return the createdTimeUtc value. + */ + public OffsetDateTime getCreatedTimeUtc() { + return this.createdTimeUtc; + } + + /** + * Set the createdTimeUtc property: The createdTimeUtc property. + * + * @param createdTimeUtc the createdTimeUtc value to set. + * @return the SchemaGroup object itself. + */ + public SchemaGroup setCreatedTimeUtc(OffsetDateTime createdTimeUtc) { + this.createdTimeUtc = createdTimeUtc; + return this; + } + + /** + * Get the updatedTimeUtc property: The updatedTimeUtc property. + * + * @return the updatedTimeUtc value. + */ + public OffsetDateTime getUpdatedTimeUtc() { + return this.updatedTimeUtc; + } + + /** + * Set the updatedTimeUtc property: The updatedTimeUtc property. + * + * @param updatedTimeUtc the updatedTimeUtc value to set. + * @return the SchemaGroup object itself. + */ + public SchemaGroup setUpdatedTimeUtc(OffsetDateTime updatedTimeUtc) { + this.updatedTimeUtc = updatedTimeUtc; + return this; + } + + /** + * Get the schemaType property: The schemaType property. + * + * @return the schemaType value. + */ + public String getSchemaType() { + return this.schemaType; + } + + /** + * Set the schemaType property: The schemaType property. + * + * @param schemaType the schemaType value to set. + * @return the SchemaGroup object itself. + */ + public SchemaGroup setSchemaType(String schemaType) { + this.schemaType = schemaType; + return this; + } + + /** + * Get the schemaCompatibility property: schema compatibility mode enum, defined by supported schema type. + * + * @return the schemaCompatibility value. + */ + public Integer getSchemaCompatibility() { + return this.schemaCompatibility; + } + + /** + * Set the schemaCompatibility property: schema compatibility mode enum, defined by supported schema type. + * + * @param schemaCompatibility the schemaCompatibility value to set. + * @return the SchemaGroup object itself. + */ + public SchemaGroup setSchemaCompatibility(Integer schemaCompatibility) { + this.schemaCompatibility = schemaCompatibility; + return this; + } + + /** + * Get the groupProperties property: Dictionary of <string>. + * + * @return the groupProperties value. + */ + public Map getGroupProperties() { + return this.groupProperties; + } + + /** + * Set the groupProperties property: Dictionary of <string>. + * + * @param groupProperties the groupProperties value to set. + * @return the SchemaGroup object itself. + */ + public SchemaGroup setGroupProperties(Map groupProperties) { + this.groupProperties = groupProperties; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java new file mode 100644 index 000000000000..3bf43b85aac4 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java @@ -0,0 +1,41 @@ +package com.azure.schemaregistry.client.rest.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** The SchemaId model. */ +@Fluent +public final class SchemaId { + /* + * The id property. + */ + @JsonProperty(value = "id") + private String id; + + /** + * Get the id property: The id property. + * + * @return the id value. + */ + public String getId() { + return this.id; + } + + /** + * Set the id property: The id property. + * + * @param id the id value to set. + * @return the SchemaId object itself. + */ + public SchemaId setId(String id) { + this.id = id; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java new file mode 100644 index 000000000000..3a0c9fe0490d --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java @@ -0,0 +1,2 @@ +/** Package containing the data models for AzureSchemaRegistryRestService. null. */ +package com.azure.schemaregistry.client.rest.models; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/package-info.java new file mode 100644 index 000000000000..3f07bf1c49c9 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/package-info.java @@ -0,0 +1,2 @@ +/** Package containing the classes for AzureSchemaRegistryRestService. null. */ +package com.azure.schemaregistry.client.rest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java index 831c16b58cd7..c5581660f9c5 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java @@ -5,46 +5,46 @@ package com.azure.schemaregistry.client; -import com.azure.schemaregistry.client.rest.RestService; -import com.azure.schemaregistry.client.rest.entities.responses.SchemaObjectResponse; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestService; +import com.azure.schemaregistry.client.rest.models.GetSchemaByIdHeaders; +import com.azure.schemaregistry.client.rest.models.GetSchemaByIdResponse; +import com.azure.schemaregistry.client.rest.models.SchemaId; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import reactor.core.publisher.Mono; import java.util.HashMap; +import java.util.UUID; import java.util.function.Function; -import static org.easymock.EasyMock.*; +import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class CachedSchemaRegistryClientTest extends TestCase { +public class CachedSchemaRegistryClientTest { private static final String MOCK_SERIALIZATION = "mock_serialization_type"; - private static final String MOCK_GUID = "mock_guid"; + private static final String MOCK_ID = "mock_guid"; + private static final SchemaId MOCK_SCHEMA_ID = new SchemaId(); private static final String MOCK_GROUP = "mockgroup"; private static final String MOCK_SCHEMA_NAME = "mockname"; private static final String MOCK_AVRO_SCHEMA = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; private CachedSchemaRegistryClient client; - private RestService restService; - private HashMap> guidCache; - private HashMap> schemaStringCache; - private HashMap> typeParserDictionary; - - public CachedSchemaRegistryClientTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(CachedSchemaRegistryClientTest.class); - } + private AzureSchemaRegistryRestService restService; + private HashMap guidCache; + private HashMap schemaStringCache; + private HashMap> typeParserDictionary; + @BeforeEach protected void setUp() { - this.guidCache = new HashMap>(); - this.schemaStringCache = new HashMap>(); + this.guidCache = new HashMap(); + this.schemaStringCache = new HashMap(); - this.typeParserDictionary = new HashMap>(); + this.typeParserDictionary = new HashMap>(); this.typeParserDictionary.put(MOCK_SERIALIZATION, (s)->s); - this.restService = createNiceMock(RestService.class); + this.restService = mock(AzureSchemaRegistryRestService.class); this.client = new CachedSchemaRegistryClient( this.restService, this.guidCache, @@ -53,55 +53,58 @@ protected void setUp() { } protected void tearDown() { + validateMockitoUsage(); } + @Test public void testRegisterThenSchemaCacheHit() throws Exception { - expect(restService.registerSchema(anyString(), anyString(), anyString(), anyString())) - .andReturn(MOCK_GUID) - .once(); + MOCK_SCHEMA_ID.setId(MOCK_ID); + when(restService.createSchema(anyString(), anyString(), anyString(), anyString())) + .thenReturn(MOCK_SCHEMA_ID); - replay(restService); + assertEquals(MOCK_ID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaId); + assertEquals(MOCK_ID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaId); - assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); - assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); - - verify(restService); + verify(restService, times(1)).createSchema(anyString(), anyString(), anyString(), anyString()); } + @Test public void testGetGuidThenSchemaCacheHit() throws Exception { - expect(restService.getGuid(anyString(), anyString(), anyString(), anyString())) - .andReturn(MOCK_GUID) - .once(); - - replay(restService); + MOCK_SCHEMA_ID.setId(MOCK_ID); + when(restService.getIdBySchemaContent(anyString(), anyString(), anyString(), anyString())) + .thenReturn(MOCK_SCHEMA_ID); - assertEquals(MOCK_GUID, client.getGuid(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); - assertEquals(MOCK_GUID, client.getGuid(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); + assertEquals(MOCK_ID, client.getSchemaId(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); + assertEquals(MOCK_ID, client.getSchemaId(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); - verify(restService); + verify(restService, times(1)).getIdBySchemaContent(anyString(), anyString(), anyString(), anyString()); } + @Test public void testGetSchemaThenGuidCacheHit() throws Exception { - expect(restService.getSchemaByGuid(anyString())) - .andReturn(new SchemaObjectResponse(null, MOCK_SERIALIZATION, MOCK_GUID)) - .once(); + UUID mockId = UUID.randomUUID(); + GetSchemaByIdHeaders mockHeaders = new GetSchemaByIdHeaders(); + mockHeaders.setXSchemaType(MOCK_SERIALIZATION); + when(restService.getSchemaByIdWithResponseAsync(mockId)) + .thenReturn( + Mono.just(new GetSchemaByIdResponse(null, 200, null, MOCK_AVRO_SCHEMA, mockHeaders))); - replay(restService); + SchemaRegistryObject first = client.getSchemaByGuid(mockId.toString()); + SchemaRegistryObject second = client.getSchemaByGuid(mockId.toString()); - assertEquals(MOCK_GUID, client.getSchemaByGuid(MOCK_GUID).schemaGuid); - assertEquals(MOCK_GUID, client.getSchemaByGuid(MOCK_GUID).schemaGuid); + assertTrue(first.equals(second)); + assertEquals(mockId.toString(), first.schemaId); - verify(restService); + verify(restService, times(1)).getSchemaByIdWithResponseAsync(mockId); } + @Test public void testClientReset() throws Exception { - expect(restService.registerSchema(anyString(), anyString(), anyString(), anyString())) - .andReturn(MOCK_GUID) - .times(2); - - replay(restService); + MOCK_SCHEMA_ID.setId(MOCK_ID); + when(restService.createSchema(anyString(), anyString(), anyString(), anyString())) + .thenReturn(MOCK_SCHEMA_ID); - assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); + assertEquals(MOCK_ID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaId); client.reset(); @@ -111,28 +114,8 @@ public void testClientReset() throws Exception { this.typeParserDictionary.put(MOCK_SERIALIZATION, (s)->s); - assertEquals(MOCK_GUID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaGuid); - - verify(restService); - } + assertEquals(MOCK_ID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaId); - // builder tests - public void testBuilderIfRegistryUrlNullOrEmptyThrow() { - try { - new CachedSchemaRegistryClient.Builder("") - .loadSchemaParser(null, null) - .build(); - fail(); - } catch (IllegalArgumentException e) { - assertTrue(true); - } - - try { - new CachedSchemaRegistryClient.Builder(null) - .build(); - fail(); - } catch (IllegalArgumentException e) { - assertTrue(true); - } + verify(restService, times(2)).createSchema(anyString(), anyString(), anyString(), anyString()); } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java deleted file mode 100644 index da4c3232e691..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/RestServiceTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry.client; - -import com.azure.schemaregistry.client.rest.RestService; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import java.util.ArrayList; - -public class RestServiceTest extends TestCase{ - public RestServiceTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(RestServiceTest.class); - } - - protected void setUp() { - } - - protected void tearDown() { - } - - public void testValidateRegistryUrl() { - ArrayList badUrls = new ArrayList(); - badUrls.add("mock"); - badUrls.add("sb://contoso.servicebus.onebox.windows-int.net:4446"); - - for (String badUrl : badUrls) { - try { - new RestService(badUrl, null); - assertTrue(false); - } catch (IllegalArgumentException e) { - assertTrue(true); - } - } - - new RestService("contoso.servicebus.onebox.windows-int.net:4446", null); // testing - new RestService("contoso.servicebus.windows.net", null); - assertTrue(true); - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/sdk/schemaregistry/azure-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 000000000000..1f0955d450f0 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline From 8fa8f89c9752d6c47f747a78e7daac35fa372fd2 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 20 May 2020 13:00:27 -0700 Subject: [PATCH 07/43] update common package --- .../azure-schemaregistry-serde-common/pom.xml | 37 ++------- .../AbstractDataDeserializer.java | 6 +- .../schemaregistry/AbstractDataSerDe.java | 5 +- .../AbstractDataSerializer.java | 8 +- .../AbstractDataDeserializerTest.java | 52 +++++------- .../AbstractDataSerializerTest.java | 52 +++++------- .../MockSchemaRegistryClient.java | 79 +++++++++++++++++++ .../schemaregistry/SampleByteDecoder.java | 4 +- .../schemaregistry/TestDummyDeserializer.java | 25 ++---- .../schemaregistry/TestDummySerializer.java | 38 ++++----- 10 files changed, 152 insertions(+), 154 deletions(-) create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml index 5ad9775202eb..2f919bd34914 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml @@ -39,51 +39,26 @@ com.azure azure-core - 1.5.0 + 1.5.0 com.azure azure-schemaregistry-client - 1.0.0-beta.1 + 1.0.0-beta.1 - org.easymock - easymock - 4.1 - test - - - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-api + 5.6.2 test org.apache.avro avro - 1.9.2 + 1.9.2 test - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M3 - - - - - org.apache.avro:avro:[1.9.2] - - - - - - - diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java index caa0ce2d0369..3ef9ce48d3ad 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java @@ -34,7 +34,7 @@ protected Object deserialize(byte[] payload) throws SerializationException { ByteBuffer buffer = getByteBuffer(payload); String schemaGuid = getSchemaGuidFromPayload(buffer); - SchemaRegistryObject registryObject = null; + SchemaRegistryObject registryObject = null; Object payloadSchema = null; try { @@ -60,7 +60,7 @@ protected Object deserialize(byte[] payload) throws SerializationException { } - private ByteDecoder getByteDecoder(SchemaRegistryObject registryObject) throws SerializationException { + private ByteDecoder getByteDecoder(SchemaRegistryObject registryObject) throws SerializationException { ByteDecoder decoder = byteDecoderMap.get(registryObject.serializationType); if (decoder == null) { throw new SerializationException("No decoder class found for serialization type " + @@ -74,7 +74,7 @@ private ByteBuffer getByteBuffer(byte[] payload) { return buffer; } - protected String getSchemaGuidFromPayload(ByteBuffer buffer) throws SerializationException { + private String getSchemaGuidFromPayload(ByteBuffer buffer) throws SerializationException { byte[] schemaGuidByteArray = new byte[AbstractDataSerDe.idSize]; try { buffer.get(schemaGuidByteArray); diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java index 91b14539e234..a01c3bac0a3c 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java @@ -13,9 +13,6 @@ * Common fields and helper methods for both the serializer and the deserializer. */ public abstract class AbstractDataSerDe { - protected final Logger log = LoggerFactory.getLogger(getClass()); - - public static final Character SCHEMA_PATH_DELIMITER = '.'; public static final int idSize = 64; protected SchemaRegistryClient schemaRegistryClient; @@ -31,4 +28,4 @@ protected AbstractDataSerDe(SchemaRegistryClient schemaRegistryClient) { public AbstractDataSerDe() { } -} \ No newline at end of file +} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java index a8f4f62cd4ea..2672d97eb09d 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java @@ -5,6 +5,7 @@ package com.azure.schemaregistry; +import com.azure.core.util.logging.ClientLogger; import com.azure.schemaregistry.client.SchemaRegistryClient; import com.azure.schemaregistry.client.SchemaRegistryClientException; import org.slf4j.Logger; @@ -13,12 +14,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; public abstract class AbstractDataSerializer extends AbstractDataSerDe { - private static final Logger log = LoggerFactory.getLogger(AbstractDataSerializer.class); - public static Boolean AUTO_REGISTER_SCHEMAS_DEFAULT = false; public static String SCHEMA_GROUP_DEFAULT = "$default"; @@ -87,9 +85,9 @@ private String maybeRegisterSchema(String schemaGroup, String schemaName, String throws IOException, SchemaRegistryClientException { if (this.autoRegisterSchemas) { return this.schemaRegistryClient.register(schemaGroup, schemaName, schemaString, - serializationFormatString).schemaGuid; + serializationFormatString).schemaId; } else { - return this.schemaRegistryClient.getGuid(schemaGroup, schemaName, schemaString, serializationFormatString); + return this.schemaRegistryClient.getSchemaId(schemaGroup, schemaName, schemaString, serializationFormatString); } } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java index 1d7c0dee505b..845bb157bee7 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java @@ -5,73 +5,60 @@ package com.azure.schemaregistry; -import com.azure.schemaregistry.client.MockSchemaRegistryClient; import com.azure.schemaregistry.client.SchemaRegistryObject; import com.azure.schemaregistry.client.SchemaRegistryClientException; -import com.azure.schemaregistry.client.rest.RestService; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericDatumWriter; import org.apache.avro.generic.GenericRecord; import org.apache.avro.io.BinaryEncoder; import org.apache.avro.io.EncoderFactory; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.Charset; -public class AbstractDataDeserializerTest extends TestCase { +import static org.junit.jupiter.api.Assertions.*; + +public class AbstractDataDeserializerTest { private static final String MOCK_GUID = new String(new char[AbstractDataSerDe.idSize]).replace("\0", "a"); private static final String MOCK_AVRO_SCHEMA_STRING = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; private final EncoderFactory encoderFactory = EncoderFactory.get(); - private final Schema MOCK_AVRO_SCHEMA; - - public AbstractDataDeserializerTest(String testName) { - super(testName); - this.MOCK_AVRO_SCHEMA = (new Schema.Parser()).parse(MOCK_AVRO_SCHEMA_STRING); - } - - public static Test suite() { - return new TestSuite(AbstractDataDeserializerTest.class); - } + private final Schema MOCK_AVRO_SCHEMA = (new Schema.Parser()).parse(MOCK_AVRO_SCHEMA_STRING); + @Test public void testLoadDecoder() throws IOException, SchemaRegistryClientException, SerializationException { // add standard avro decoder class and test that it is used for decoding payload SampleByteDecoder decoder = new SampleByteDecoder(); // manually add SchemaRegistryObject to cache - SchemaRegistryObject registered = new SchemaRegistryObject<>(MOCK_GUID, + SchemaRegistryObject registered = new SchemaRegistryObject(MOCK_GUID, decoder.serializationFormat(), - MOCK_AVRO_SCHEMA_STRING.getBytes(RestService.SERVICE_CHARSET), + MOCK_AVRO_SCHEMA_STRING.getBytes(), s -> decoder.parseSchemaString(s)); assertTrue(registered.deserialize() != null); MockSchemaRegistryClient mockRegistryClient = new MockSchemaRegistryClient(); mockRegistryClient.guidCache.put(MOCK_GUID, registered); - TestDummyDeserializer deserializer = new TestDummyDeserializer.Builder(mockRegistryClient) - .byteDecoder(new SampleByteDecoder()) - .build(); + TestDummyDeserializer deserializer = new TestDummyDeserializer(mockRegistryClient); // contains byte decoder - assertEquals(MOCK_GUID, deserializer.schemaRegistryClient.getSchemaByGuid(MOCK_GUID).schemaGuid); - assertEquals(decoder.samplePayload, deserializer.deserialize(getPayload())); + assertEquals(MOCK_GUID, deserializer.schemaRegistryClient.getSchemaByGuid(MOCK_GUID).schemaId); + assertEquals(decoder.constantPayload, deserializer.deserialize(getPayload())); } + @Test public void testNullPayload() throws IOException, SchemaRegistryClientException, SerializationException { - TestDummyDeserializer deserializer = new TestDummyDeserializer.Builder(new MockSchemaRegistryClient()) - .build(); - + TestDummyDeserializer deserializer = new TestDummyDeserializer(new MockSchemaRegistryClient()); assertEquals(null, deserializer.deserialize(null)); } + @Test public void testIfTooShortPayloadThrow() { - TestDummyDeserializer deserializer = new TestDummyDeserializer.Builder(new MockSchemaRegistryClient()) - .build(); + TestDummyDeserializer deserializer = new TestDummyDeserializer(new MockSchemaRegistryClient()); try { deserializer.deserialize("bad payload".getBytes()); @@ -83,16 +70,13 @@ public void testIfTooShortPayloadThrow() { // TODO: add for non-existing guid - // builder tests - public void testBuilderIfRegistryNullOnBuildThrow() { + @Test + public void testIfRegistryClientNullOnBuildThrow() { try { - TestDummyDeserializer deserializer = new TestDummyDeserializer.Builder(null).build(); - assert(deserializer == null); + TestDummyDeserializer deserializer = new TestDummyDeserializer(null); fail("should not get here."); } catch (IllegalArgumentException e) { // good - } catch (Exception e) { - fail("Building deserializer with null registry should fail with IllegalArgumentException"); } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java index 7bfd69f05b6d..71625d5e40a2 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java @@ -5,26 +5,19 @@ package com.azure.schemaregistry; -import com.azure.schemaregistry.client.MockSchemaRegistryClient; import com.azure.schemaregistry.client.SchemaRegistryObject; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Random; -public class AbstractDataSerializerTest extends TestCase { - public AbstractDataSerializerTest(String testName) { - super(testName); - } +import static org.junit.jupiter.api.Assertions.*; - public static Test suite() { - return new TestSuite(AbstractDataSerializerTest.class); - } +public class AbstractDataSerializerTest { + @Test public void testRegistryGuidPrefixedToPayload() { Random rnd = new Random(); String MOCK_GUID = ""; @@ -34,7 +27,7 @@ public void testRegistryGuidPrefixedToPayload() { // manually add SchemaRegistryObject into mock registry client cache SampleByteEncoder encoder = new SampleByteEncoder(); - SchemaRegistryObject registered = new SchemaRegistryObject<>(MOCK_GUID, + SchemaRegistryObject registered = new SchemaRegistryObject(MOCK_GUID, encoder.serializationFormat(), encoder.getSchemaString(null).getBytes(), // always returns same schema string s -> encoder.parseSchemaString(s)); @@ -44,9 +37,7 @@ public void testRegistryGuidPrefixedToPayload() { MockSchemaRegistryClient mockRegistryClient = new MockSchemaRegistryClient(); mockRegistryClient.schemaStringCache.put(encoder.getSchemaString(null), registered); - TestDummySerializer serializer = new TestDummySerializer.Builder(mockRegistryClient) - .byteEncoder(encoder) - .build(); + TestDummySerializer serializer = new TestDummySerializer(mockRegistryClient, true, false); try { byte[] payload = serializer.serializeImpl(1); @@ -70,10 +61,12 @@ public void testRegistryGuidPrefixedToPayload() { } } + @Test public void testNullPayloadThrowsSerializationException() { - TestDummySerializer serializer = new TestDummySerializer.Builder(new MockSchemaRegistryClient()) - .byteEncoder(new SampleByteEncoder()) - .build(); + TestDummySerializer serializer = new TestDummySerializer( + new MockSchemaRegistryClient(), + true, + false); try { serializer.serializeImpl(null); @@ -83,11 +76,10 @@ public void testNullPayloadThrowsSerializationException() { } } + @Test public void testSerializeWithNullByteEncoderThrows() { // don't set byte encoder on constructor - TestDummySerializer serializer = new TestDummySerializer.Builder(new MockSchemaRegistryClient()) - .constructWithoutByteEncoder() - .build(); + TestDummySerializer serializer = new TestDummySerializer(new MockSchemaRegistryClient(), false, false); try { serializer.serializeImpl(1); @@ -96,9 +88,10 @@ public void testSerializeWithNullByteEncoderThrows() { } } - public void testBuilderIfRegistryNullThrow() { + @Test + public void testIfRegistryNullThenThrow() { try { - TestDummySerializer serializer = new TestDummySerializer.Builder(null).build(); + TestDummySerializer serializer = new TestDummySerializer(null, true, false); fail("Building serializer instance with null registry client failed to throw"); } catch (IllegalArgumentException e) { assertTrue(true); @@ -107,16 +100,9 @@ public void testBuilderIfRegistryNullThrow() { } } - public void testBuilderAutoRegister() { - TestDummySerializer serializer = new TestDummySerializer.Builder(new MockSchemaRegistryClient()) - .constructWithoutByteEncoder() // doesn't matter - .build(); + @Test + public void testDefaultAutoRegister() { + TestDummySerializer serializer = new TestDummySerializer(new MockSchemaRegistryClient(), true); assertEquals(false, (boolean) serializer.autoRegisterSchemas); - - serializer = new TestDummySerializer.Builder(new MockSchemaRegistryClient()) - .constructWithoutByteEncoder() // doesn't matter - .autoRegisterSchemas(true) - .build(); - assertEquals(true, (boolean) serializer.autoRegisterSchemas); } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java new file mode 100644 index 000000000000..25277039b0dc --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +package com.azure.schemaregistry; + +import com.azure.schemaregistry.client.SchemaRegistryClient; +import com.azure.schemaregistry.client.SchemaRegistryClientException; +import com.azure.schemaregistry.client.SchemaRegistryObject; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.function.Function; + +public class MockSchemaRegistryClient implements SchemaRegistryClient { + + public final HashMap> typeParserDictionary; + + public final HashMap guidCache; + public final HashMap schemaStringCache; + + public MockSchemaRegistryClient() { + this.guidCache = new HashMap(); + this.schemaStringCache = new HashMap(); + this.typeParserDictionary = new HashMap>(); + } + + public void loadSchemaParser(String serializationFormat, Function f) {} + + @Override + public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws IOException, SchemaRegistryClientException { + if (schemaStringCache.containsKey(schemaString)) { + return schemaStringCache.get(schemaString); + } + + return null; + } + + @Override + public SchemaRegistryObject getSchemaByGuid(String schemaGuid) + throws IOException, SchemaRegistryClientException { + if (guidCache.containsKey(schemaGuid)) { + return guidCache.get(schemaGuid); + } + return null; + } + + @Override + public String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws IOException, SchemaRegistryClientException { + if (schemaStringCache.containsKey(schemaString)) { + return schemaStringCache.get(schemaString).schemaId; + } + + return null; + } + + @Override + public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) + throws IOException, SchemaRegistryClientException { + return null; + } + + @Override + public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) + throws IOException, SchemaRegistryClientException { + return null; + } + + @Override + public List deleteSchema(String schemaGroup, String schemaName) + throws IOException, SchemaRegistryClientException { + return new ArrayList(); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java index 91853b8ad539..9e2ce7f333cc 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java @@ -15,11 +15,11 @@ public String serializationFormat() { return "sample"; } - public static final String samplePayload = "sample payload!"; + public static final String constantPayload = "sample payload!"; @Override public Object decodeBytes(byte[] bytes, Object o) throws SerializationException { - return samplePayload; + return constantPayload; } @Override diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java index a49a8a459b04..044a63af93de 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java @@ -8,24 +8,9 @@ import com.azure.schemaregistry.client.SchemaRegistryClient; public class TestDummyDeserializer extends AbstractDataDeserializer { - private TestDummyDeserializer(Builder builder) { - super(builder.schemaRegistryClient); - for (ByteDecoder decoder: builder.byteDecoders) - this.byteDecoderMap.put(decoder.serializationFormat(), decoder); + TestDummyDeserializer(SchemaRegistryClient mockClient) { + super(mockClient); + ByteDecoder sampleDecoder = new SampleByteDecoder(); + this.byteDecoderMap.put(sampleDecoder.serializationFormat(), sampleDecoder); } - - public static class Builder extends AbstractDataDeserializer.AbstractBuilder { - public Builder(SchemaRegistryClient schemaRegistryClient) { - super(schemaRegistryClient); - } - - @Override - public Builder getActualBuilder() { - return this; - } - - public TestDummyDeserializer build() { - return new TestDummyDeserializer(this); - } - } -} \ No newline at end of file +} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java index 443cf4923b8f..de8a745c48ca 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java @@ -8,36 +8,30 @@ import com.azure.schemaregistry.client.SchemaRegistryClient; public class TestDummySerializer extends AbstractDataSerializer { - private TestDummySerializer(Builder builder) { - super(builder.schemaRegistryClient); + TestDummySerializer( + SchemaRegistryClient mockClient, + boolean byteEncoder, + boolean autoRegisterSchemas) { + super(mockClient); // allows simulating improperly written serializer constructor that does not initialize byte encoder - if (!builder.constructWithoutByteEncoder) { - setByteEncoder(builder.byteEncoder); + if (byteEncoder) { + setByteEncoder(new SampleByteEncoder()); } - this.autoRegisterSchemas = builder.autoRegisterSchemas; + this.autoRegisterSchemas = autoRegisterSchemas; } - public static class Builder extends AbstractDataSerializer.AbstractBuilder { - private boolean constructWithoutByteEncoder = false; + TestDummySerializer( + SchemaRegistryClient mockClient, + boolean byteEncoder) { + super(mockClient); - public Builder(SchemaRegistryClient schemaRegistryClient) { - super(schemaRegistryClient); - } - - @Override - public Builder getActualBuilder() { - return this; - } - - public TestDummySerializer build() { - return new TestDummySerializer(this); + // allows simulating improperly written serializer constructor that does not initialize byte encoder + if (byteEncoder) { + setByteEncoder(new SampleByteEncoder()); } - public Builder constructWithoutByteEncoder() { - this.constructWithoutByteEncoder = true; - return this; - } + // default auto register } } From 305ffa56f78e370864f606629efbc6d56c34b127 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 20 May 2020 13:08:59 -0700 Subject: [PATCH 08/43] junit engine --- .../azure-schemaregistry-client/pom.xml | 14 +++++++++- .../azure-schemaregistry-serde-avro/pom.xml | 26 +++++++++++++++---- .../azure-schemaregistry-serde-common/pom.xml | 14 +++++++++- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml index 24ea54bc4253..3129d1bce880 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml @@ -47,7 +47,19 @@ org.junit.jupiter junit-jupiter-api - 5.6.2 + 5.4.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 + test + + + org.junit.jupiter + junit-jupiter-params + 5.4.2 test diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml index befa25c77c64..561426967a6d 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml @@ -41,19 +41,34 @@ com.azure azure-schemaregistry-serde-common - 1.0.0-beta.1 + 1.0.0-beta.1 compile org.apache.avro avro - 1.9.2 + 1.9.2 compile + + + + + org.junit.jupiter + junit-jupiter-api + 5.4.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 + test + - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-params + 5.4.2 test @@ -68,6 +83,7 @@ + com.azure:* org.apache.avro:avro:[1.9.2] diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml index 2f919bd34914..a0008c2546c1 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml @@ -51,7 +51,19 @@ org.junit.jupiter junit-jupiter-api - 5.6.2 + 5.4.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 + test + + + org.junit.jupiter + junit-jupiter-params + 5.4.2 test From 7eb5a2f353cf28486485ed3119b86e69c96a2fa8 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 20 May 2020 13:11:01 -0700 Subject: [PATCH 09/43] fix versioning --- eng/versioning/external_dependencies.txt | 1 + eng/versioning/version_client.txt | 3 +++ pom.xml | 1 + 3 files changed, 5 insertions(+) diff --git a/eng/versioning/external_dependencies.txt b/eng/versioning/external_dependencies.txt index 89cfbd7f7aad..c1320a4f1370 100644 --- a/eng/versioning/external_dependencies.txt +++ b/eng/versioning/external_dependencies.txt @@ -122,6 +122,7 @@ org.openjdk.jmh:jmh-generator-annprocess;1.22 org.spockframework:spock-core;1.3-groovy-2.5 org.testng:testng;6.14.3 uk.org.lidalia:slf4j-test;1.2.0 +org.apache.avro:avro;1.9.2 ## Maven Tools versions com.azure:sdk-build-tools;1.0.0 diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index c7267222d449..ebd1b8f661c4 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -26,6 +26,9 @@ com.azure:azure-identity-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-messaging-eventhubs;5.1.0;5.2.0-beta.1 com.azure:azure-messaging-eventhubs-checkpointstore-blob;1.1.0;1.2.0-beta.1 com.azure:azure-messaging-servicebus;7.0.0-beta.2;7.0.0-beta.3 +com.azure:azure-schemaregistry-client;1.0.0-beta.1;1.0.0-beta.1 +com.azure:azure-schemaregistry-serde-common;1.0.0-beta.1;1.0.0-beta.1 +com.azure:azure-schemaregistry-serde-avro;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-search-documents;1.0.0-beta.3;1.0.0-beta.4 com.azure:azure-security-keyvault-certificates;4.1.0-beta.2;4.1.0-beta.3 com.azure:azure-security-keyvault-keys;4.2.0-beta.3;4.2.0-beta.4 diff --git a/pom.xml b/pom.xml index da436a3d829d..e3ed25ccadd1 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,7 @@ sdk/keyvault sdk/loganalytics sdk/mediaservices + sdk/schemaregistry sdk/search sdk/servicebus sdk/storage From e13f670dd838a875fe52555fc5609c01bd896ae5 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 14:16:36 -0700 Subject: [PATCH 10/43] javadoc checkstyle --- .../azure-schemaregistry-client/pom.xml | 6 + .../client/CachedSchemaRegistryClient.java | 145 ++++--- .../CachedSchemaRegistryClientBuilder.java | 97 ++++- .../client/MockSchemaRegistryClient.java | 75 ---- .../client/SchemaRegistryClient.java | 53 +-- .../client/SchemaRegistryClientException.java | 22 +- .../client/SchemaRegistryObject.java | 64 ++- .../rest/AzureSchemaRegistryRestService.java | 397 +++++++++--------- ...hemaRegistryRestServiceClientBuilder.java} | 13 +- .../rest/models/CreateGroupHeaders.java | 5 +- .../rest/models/CreateGroupResponse.java | 3 + .../rest/models/CreateSchemaHeaders.java | 5 +- .../rest/models/CreateSchemaResponse.java | 3 + .../models/GetIdBySchemaContentHeaders.java | 5 +- .../models/GetIdBySchemaContentResponse.java | 3 + .../rest/models/GetLatestSchemaHeaders.java | 5 +- .../rest/models/GetLatestSchemaResponse.java | 3 + .../rest/models/GetSchemaByIdHeaders.java | 5 +- .../rest/models/GetSchemaByIdResponse.java | 3 + .../rest/models/GetSchemaVersionHeaders.java | 5 +- .../rest/models/GetSchemaVersionResponse.java | 3 + .../rest/models/GetSchemaVersionsHeaders.java | 5 +- .../models/GetSchemaVersionsResponse.java | 3 + .../rest/models/GetSchemasByGroupHeaders.java | 5 +- .../models/GetSchemasByGroupResponse.java | 3 + .../client/rest/models/SchemaGroup.java | 5 +- .../client/rest/models/SchemaId.java | 5 +- .../client/rest/models/package-info.java | 1 + .../CachedSchemaRegistryClientTest.java | 46 +- 29 files changed, 571 insertions(+), 422 deletions(-) delete mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/{AzureSchemaRegistryRestServiceBuilder.java => AzureSchemaRegistryRestServiceClientBuilder.java} (79%) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml index 3129d1bce880..3f34a214af52 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml @@ -36,6 +36,12 @@ + + + 0.10 + 0.01 + + com.azure diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index 499edf2ead6e..5c7b144cbb40 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.client; @@ -10,13 +8,15 @@ import com.azure.core.http.HttpPipeline; import com.azure.core.util.logging.ClientLogger; import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestService; -import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestServiceBuilder; +import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestServiceClientBuilder; import com.azure.schemaregistry.client.rest.models.GetSchemaByIdResponse; import com.azure.schemaregistry.client.rest.models.SchemaId; -import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.UUID; import java.util.function.Function; @@ -27,8 +27,8 @@ * * Max HashMap size can be configured when instantiating. * Two maps are maintained - - * - SchemaRegistryObject cache by GUID - accessed when consuming, store GUIDs previously seen in payloads - * - SchemaRegistryObject cache by schema string - accessed when sending, minimizes HTTP calls when payloads of same schema + * - SchemaRegistryObject cache by GUID - stores GUIDs previously seen in payloads + * - SchemaRegistryObject cache by schema string - minimizes HTTP calls when sending payloads of same schema * * TODO: implement max age for schema maps? or will schemas always be immutable? * @@ -36,12 +36,13 @@ * @see CachedSchemaRegistryClientBuilder Follows builder pattern for object instantiation */ public class CachedSchemaRegistryClient implements SchemaRegistryClient { - private final ClientLogger log = new ClientLogger(CachedSchemaRegistryClient.class); + private final ClientLogger logger = new ClientLogger(CachedSchemaRegistryClient.class); public static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; public static final int MAX_SCHEMA_MAP_SIZE_MINIMUM = 10; + public static final Charset SCHEMA_REGISTRY_SERVICE_ENCODING = StandardCharsets.UTF_8; - private int maxSchemaMapSize; + private final int maxSchemaMapSize; private final AzureSchemaRegistryRestService restService; private final HashMap> typeParserDictionary; @@ -53,13 +54,12 @@ public class CachedSchemaRegistryClient implements SchemaRegistryClient { HttpPipeline pipeline, TokenCredential credential, int maxSchemaMapSize, - HashMap> typeParserDictionary) - { + HashMap> typeParserDictionary) { if (registryUrl == null || registryUrl.isEmpty()) { throw new IllegalArgumentException("Schema Registry URL cannot be null or empty."); } - this.restService = new AzureSchemaRegistryRestServiceBuilder() + this.restService = new AzureSchemaRegistryRestServiceClientBuilder() .host(registryUrl) .pipeline(pipeline) .buildClient(); @@ -80,97 +80,121 @@ public class CachedSchemaRegistryClient implements SchemaRegistryClient { this.guidCache = guidCache; this.schemaStringCache = schemaStringCache; this.typeParserDictionary = typeParserDictionary; + this.maxSchemaMapSize = MAX_SCHEMA_MAP_SIZE_DEFAULT; + } + + /** + * @return Azure Schema Registry service string encoding + */ + @Override + public Charset getEncoding() { + return CachedSchemaRegistryClient.SCHEMA_REGISTRY_SERVICE_ENCODING; } - public synchronized void loadSchemaParser(String serializationType, Function parseMethod) { - if (serializationType == null || serializationType.isEmpty()) { - throw new IllegalArgumentException("Serialization type cannot be null or empty."); + /** + * @param schemaType tag used by schema registry store to identify schema serialization type, e.g. "avro" + * @param parseMethod function to parse string into usable schema object + * + * @throws IllegalArgumentException on bad schema type or if parser for schema type has already been registered + */ + public synchronized void loadSchemaParser(String schemaType, Function parseMethod) { + if (schemaType == null || schemaType.isEmpty()) { + throw logger.logExceptionAsError( + new IllegalArgumentException("Serialization type cannot be null or empty.")); } - if (this.typeParserDictionary.containsKey(serializationType.toLowerCase())) { - throw new IllegalArgumentException("Multiple parse methods for single serialization type may not be added."); + if (this.typeParserDictionary.containsKey(schemaType.toLowerCase(Locale.ENGLISH))) { + throw logger.logExceptionAsError( + new IllegalArgumentException("Multiple parse methods for single serialization type may not be added.")); } - this.typeParserDictionary.put(serializationType.toLowerCase(), parseMethod); - log.verbose(String.format("Loaded parser for '%s' serialization format.", serializationType.toLowerCase())); + this.typeParserDictionary.put(schemaType.toLowerCase(Locale.ENGLISH), parseMethod); + logger.verbose( + String.format("Loaded parser for '%s' serialization format.", schemaType.toLowerCase(Locale.ENGLISH))); } @Override - public synchronized SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) - throws IOException, SchemaRegistryClientException { + public synchronized SchemaRegistryObject register( + String schemaGroup, String schemaName, String schemaString, String serializationType) + throws SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { - log.verbose(String.format("Cache hit schema string. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", + logger.verbose( + String.format( + "Cache hit schema string. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", schemaGroup, schemaName, serializationType, schemaString)); return schemaStringCache.get(schemaString); } - log.verbose(String.format("Registering schema. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", + logger.verbose( + String.format("Registering schema. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", schemaGroup, schemaName, serializationType, schemaString)); SchemaId schemaId; try { schemaId = this.restService.createSchema(schemaGroup, schemaName, schemaString, serializationType); } catch (HttpResponseException e) { - throw new SchemaRegistryClientException("Register operation failed.", e); + throw logger.logExceptionAsError(new SchemaRegistryClientException("Register operation failed.", e)); } SchemaRegistryObject registered = new SchemaRegistryObject(schemaId.getId(), serializationType, - schemaString.getBytes(), + schemaString.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING), getParseFunc(serializationType)); resetIfNeeded(); schemaStringCache.put(schemaString, registered); - log.verbose(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + logger.verbose(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); return registered; } @Override - public synchronized SchemaRegistryObject getSchemaByGuid(String schemaId) throws IOException, SchemaRegistryClientException { + public synchronized SchemaRegistryObject getSchemaByGuid(String schemaId) + throws SchemaRegistryClientException { if (guidCache.containsKey(schemaId)) { - log.verbose(String.format("Cache hit for schema id '%s'", schemaId)); + logger.verbose(String.format("Cache hit for schema id '%s'", schemaId)); return guidCache.get(schemaId); } GetSchemaByIdResponse response; try { response = this.restService.getSchemaByIdWithResponseAsync(UUID.fromString(schemaId)).block(); - } - catch (HttpResponseException e) { - throw new SchemaRegistryClientException("Fetching schema failed.", e); + } catch (HttpResponseException e) { + throw logger.logExceptionAsError(new SchemaRegistryClientException("Fetching schema failed.", e)); } if (response == null) { - throw new SchemaRegistryClientException("HTTP client returned null schema response"); + throw logger.logExceptionAsError( + new SchemaRegistryClientException("HTTP client returned null schema response")); } String schemaType = response.getDeserializedHeaders().getXSchemaType(); SchemaRegistryObject schemaObject = new SchemaRegistryObject(schemaId, schemaType, - response.getValue().getBytes(), + response.getValue().getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING), getParseFunc(schemaType)); resetIfNeeded(); guidCache.put(schemaId, schemaObject); - log.verbose(String.format("Cached schema object. Path: '%s'", schemaId)); + logger.verbose(String.format("Cached schema object. Path: '%s'", schemaId)); return schemaObject; } @Override - public synchronized String getSchemaId(String schemaGroup, String schemaName, String schemaString, String schemaType) - throws IOException, SchemaRegistryClientException { + public synchronized String getSchemaId( + String schemaGroup, String schemaName, String schemaString, String schemaType) + throws SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { - log.verbose(String.format("Cache hit schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); - return schemaStringCache.get(schemaString).schemaId; + logger.verbose(String.format("Cache hit schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + return schemaStringCache.get(schemaString).getSchemaId(); } SchemaId schemaId; try { schemaId = this.restService.getIdBySchemaContent(schemaGroup, schemaName, schemaType, schemaString); - } - catch(HttpResponseException e){ - throw new SchemaRegistryClientException( - String.format("Failed to fetch schema guid for schema. Group: '%s', name: '%s'", schemaGroup, schemaName), - e); + } catch (HttpResponseException e) { + throw logger.logExceptionAsError(new SchemaRegistryClientException( + String.format("Failed to fetch schema guid for schema. Group: '%s', name: '%s'", + schemaGroup, schemaName), + e)); } resetIfNeeded(); @@ -179,33 +203,39 @@ public synchronized String getSchemaId(String schemaGroup, String schemaName, St new SchemaRegistryObject( schemaId.getId(), schemaType, - schemaString.getBytes(), + schemaString.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING), getParseFunc(schemaType))); - log.verbose(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + logger.verbose(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); return schemaId.getId(); } @Override - public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) throws IOException, SchemaRegistryClientException { + public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) + throws SchemaRegistryClientException { // return this.restService.deleteSchemaVersion(schemaName, version); // remove from cache return null; } @Override - public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) throws IOException, SchemaRegistryClientException { + public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) + throws SchemaRegistryClientException { // return this.restService.deleteSchemaVersion(schemaName, null); // remove from cache return null; } @Override - public List deleteSchema(String schemaGroup, String schemaName) throws IOException, SchemaRegistryClientException { + public List deleteSchema(String schemaGroup, String schemaName) + throws SchemaRegistryClientException { // return this.restService.deleteSchema(); // remove from cache return null; } + /** + * Explicit call to clear all caches. + */ public synchronized void reset() { guidCache.clear(); schemaStringCache.clear(); @@ -226,14 +256,19 @@ private synchronized void resetIfNeeded() { } } - private Function getParseFunc(String serializationType) throws IOException { - Function parseFunc = typeParserDictionary.get(serializationType.toLowerCase()); + /** + * Return stored parse function for parsing schema payloads of specified schema type + * @param schemaType schema type of payload to be deserialized + * @return parse method for deserializing schema string + */ + private Function getParseFunc(String schemaType) { + Function parseFunc = typeParserDictionary.get(schemaType.toLowerCase(Locale.ENGLISH)); if (parseFunc == null) { - log.error(String.format("No loaded schema parser for serialization type: '%s'", serializationType)); - throw new IOException(String.format("Unexpected serialization type '%s' received. Currently loaded parsers: %s", - serializationType, - typeParserDictionary.keySet().toString())); + throw logger.logExceptionAsError(new SchemaRegistryClientException( + String.format("Unexpected serialization type '%s' received. Currently loaded parsers: %s", + schemaType, + typeParserDictionary.keySet().toString()))); } return parseFunc; } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index 2a7c83681e9d..86c3cca921cd 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -1,5 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client; +import com.azure.core.annotation.ServiceClientBuilder; import com.azure.core.credential.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpHeaders; @@ -7,7 +11,6 @@ import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.AddDatePolicy; import com.azure.core.http.policy.AddHeadersPolicy; -import com.azure.core.http.policy.AzureKeyCredentialPolicy; import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; @@ -27,12 +30,17 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Objects; +import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.function.Function; +/** + * + */ +@ServiceClientBuilder(serviceClients = CachedSchemaRegistryClient.class) public class CachedSchemaRegistryClientBuilder { - private final ClientLogger log = new ClientLogger(CachedSchemaRegistryClientBuilder.class); + private final ClientLogger logger = new ClientLogger(CachedSchemaRegistryClientBuilder.class); private static final String DEFAULT_SCOPE = "https://eventhubs.azure.com/.default"; private static final String CLIENT_PROPERTIES = "azure-schemaregistry-client.properties"; @@ -54,14 +62,12 @@ public class CachedSchemaRegistryClientBuilder { private RetryPolicy retryPolicy; /** - * Constructor. * Sets the service endpoint for the Azure Schema Registry instance. * Supplies client defaults. * - * @param schemaRegistryUrl The URL of the Azure Schema Registry instance service requests to and receive responses from. - * @return The updated {@link CachedSchemaRegistryClientBuilder} object. - * @throws NullPointerException if {@code endpoint} is null - * @throws IllegalArgumentException if {@code endpoint} cannot be parsed into a valid URL. + * @param schemaRegistryUrl The URL of the Azure Schema Registry instance + * @throws NullPointerException if {@code schemaRegistryUrl} is null + * @throws IllegalArgumentException if {@code schemaRegistryUrl} cannot be parsed into a valid URL. */ public CachedSchemaRegistryClientBuilder(String schemaRegistryUrl) { Objects.requireNonNull(schemaRegistryUrl, "'schemaRegistryUrl' cannot be null."); @@ -69,7 +75,8 @@ public CachedSchemaRegistryClientBuilder(String schemaRegistryUrl) { try { new URL(schemaRegistryUrl); } catch (MalformedURLException ex) { - throw log.logExceptionAsWarning(new IllegalArgumentException("'schemaRegistryUrl' must be a valid URL.", ex)); + throw logger.logExceptionAsWarning( + new IllegalArgumentException("'schemaRegistryUrl' must be a valid URL.", ex)); } if (schemaRegistryUrl.endsWith("/")) { @@ -93,16 +100,29 @@ public CachedSchemaRegistryClientBuilder(String schemaRegistryUrl) { this.headers = new HttpHeaders(); } + /** + * Sets schema cache size limit. If limit is exceeded on any cache, all caches are recycled. + * + * @param maxSchemaMapSize max size for internal schema caches in {@link CachedSchemaRegistryClient} + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. + * @throws IllegalArgumentException on invalid maxSchemaMapSize value + */ public CachedSchemaRegistryClientBuilder maxSchemaMapSize(int maxSchemaMapSize) throws IllegalArgumentException { if (maxSchemaMapSize < CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM) { - throw new IllegalArgumentException( + throw logger.logExceptionAsError(new IllegalArgumentException( String.format("Schema map size must be greater than %s entries", - CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM)); + CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM))); } this.maxSchemaMapSize = maxSchemaMapSize; return this; } + /** + * Sets the HTTP client to use for sending and receiving requests to and from the service. + * + * @param httpClient The HTTP client to use for requests. + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. + */ public CachedSchemaRegistryClientBuilder httpClient(HttpClient httpClient) { this.httpClient = httpClient; return this; @@ -118,7 +138,7 @@ public CachedSchemaRegistryClientBuilder httpClient(HttpClient httpClient) { */ public CachedSchemaRegistryClientBuilder pipeline(HttpPipeline httpPipeline) { if (this.httpPipeline != null && httpPipeline == null) { - log.info("HttpPipeline is being set to 'null' when it was previously configured."); + logger.info("HttpPipeline is being set to 'null' when it was previously configured."); } this.httpPipeline = httpPipeline; @@ -126,6 +146,14 @@ public CachedSchemaRegistryClientBuilder pipeline(HttpPipeline httpPipeline) { } + /** + * Sets the {@link TokenCredential} to use when authenticating HTTP requests for this + * {@link CachedSchemaRegistryClient}. + * + * @param credential {@link TokenCredential} + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. + * @throws NullPointerException If {@code credential} is {@code null} + */ public CachedSchemaRegistryClientBuilder credential(TokenCredential credential) { this.credential = Objects.requireNonNull(credential, "'credential' cannot be null."); return this; @@ -169,18 +197,47 @@ public CachedSchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { return this; } - public CachedSchemaRegistryClientBuilder loadSchemaParser(String serializationType, Function parseMethod) { - if (serializationType == null || serializationType.isEmpty()) { - throw new IllegalArgumentException("Serialization type cannot be null or empty."); + /** + * Loads a parser method Function object used to convert schema strings returned from the Schema Registry + * service into useable schema objects. + * + * Any com.azure.schemaregistry.ByteEncoder or com.azure.schemaregistry.ByteDecoder class will implement + * - serializationFormat(), which specifies schema type, and + * - parseSchemaString(), which parses schemas of the specified schema type from String to Object. + * This method can be used by passing in a method reference, e.g. ByteEncoder::parseSchemaString. + * + * The parseMethod argument should be a stateless, idempotent function. + * + * @param schemaType schema type for which the parse method should be applied. + * @param parseMethod function for deserializing registry-stored schema strings to Java Objects + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. + */ + public CachedSchemaRegistryClientBuilder loadSchemaParser( + String schemaType, Function parseMethod) { + if (schemaType == null || schemaType.isEmpty()) { + throw logger.logExceptionAsError( + new IllegalArgumentException("Serialization type cannot be null or empty.")); } - if (this.typeParserDictionary.containsKey(serializationType.toLowerCase())) { - throw new IllegalArgumentException("Multiple parse methods for single serialization type may not be added."); + if (this.typeParserDictionary.containsKey(schemaType.toLowerCase(Locale.ENGLISH))) { + throw logger.logExceptionAsError( + new IllegalArgumentException("Multiple parse methods for single serialization type may not be added.")); } - this.typeParserDictionary.put(serializationType.toLowerCase(), parseMethod); + this.typeParserDictionary.put(schemaType.toLowerCase(Locale.ENGLISH), parseMethod); return this; } - public CachedSchemaRegistryClient build() { + /** + * Creates a {@link CachedSchemaRegistryClient} based on options set in the builder. + * Every time {@code buildClient()} is called a new instance of {@link CachedSchemaRegistryClient} is created. + * + * If {@link #pipeline(HttpPipeline) pipeline} is set, then all HTTP pipeline related settings are ignored + * endpoint} are when creating the {@link CachedSchemaRegistryClient client}. + * + * @return A {@link CachedSchemaRegistryClient} with the options set from the builder. + * @throws NullPointerException if parameters are incorrectly set. + * @throws IllegalArgumentException if credential is not set. + */ + public CachedSchemaRegistryClient buildClient() { HttpPipeline pipeline = this.httpPipeline; // Create a default Pipeline if it is not given if (pipeline == null) { @@ -203,7 +260,7 @@ public CachedSchemaRegistryClient build() { policies.add(new BearerTokenAuthenticationPolicy(credential, DEFAULT_SCOPE)); } else { // Throw exception that credential and tokenCredential cannot be null - throw log.logExceptionAsError( + throw logger.logExceptionAsError( new IllegalArgumentException("Missing credential information while building a client.")); } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java deleted file mode 100644 index 3414679f2659..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/MockSchemaRegistryClient.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry.client; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.function.Function; - -public class MockSchemaRegistryClient implements SchemaRegistryClient { - - public final HashMap> typeParserDictionary; - - public final HashMap guidCache; - public final HashMap schemaStringCache; - - public MockSchemaRegistryClient() { - this.guidCache = new HashMap(); - this.schemaStringCache = new HashMap(); - this.typeParserDictionary = new HashMap>(); - } - - public void loadSchemaParser(String serializationFormat, Function f) {} - - @Override - public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) - throws IOException, SchemaRegistryClientException { - if (schemaStringCache.containsKey(schemaString)) { - return schemaStringCache.get(schemaString); - } - - return null; - } - - @Override - public SchemaRegistryObject getSchemaByGuid(String schemaGuid) - throws IOException, SchemaRegistryClientException { - if (guidCache.containsKey(schemaGuid)) { - return guidCache.get(schemaGuid); - } - return null; - } - - @Override - public String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType) - throws IOException, SchemaRegistryClientException { - if (schemaStringCache.containsKey(schemaString)) { - return schemaStringCache.get(schemaString).schemaId; - } - - return null; - } - - @Override - public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) - throws IOException, SchemaRegistryClientException { - return null; - } - - @Override - public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) - throws IOException, SchemaRegistryClientException { - return null; - } - - @Override - public List deleteSchema(String schemaGroup, String schemaName) - throws IOException, SchemaRegistryClientException { - return new ArrayList(); - } -} diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java index 33979ccb9af5..8b36bfca299f 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java @@ -1,26 +1,32 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.client; -import java.io.IOException; +import java.nio.charset.Charset; import java.util.List; import java.util.function.Function; /** - * Interface that defines operation for registering and fetching schemas and schema information to and from a - * schema registry store. + * Interface that defines operation for registering and fetching schemas and schema information to and from a + * schema registry store. */ public interface SchemaRegistryClient { + + /** + * Encoding used by registry client implementation. + * @return encoding for registry client implementation + */ + Charset getEncoding(); + /** * Loads function for a given serialization format that can parse the registry-stored schema string into * usable schema object. + * * @param serializationType tag used by schema registry store to identify schema serialization type, e.g. "avro" * @param parseMethod function to parse string into usable schema object */ - public void loadSchemaParser(String serializationType, Function parseMethod); + void loadSchemaParser(String serializationType, Function parseMethod); /** * Registers a schema against backing schema registry store. @@ -31,66 +37,63 @@ public interface SchemaRegistryClient { * @param serializationType string representation of serialization format type * @return SchemaRegistryObject containing information regarding registered schema. * @throws SchemaRegistryClientException if registration operation fails - * @throws IOException failed or interrupted I/O operation */ - public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) - throws IOException, SchemaRegistryClientException; + SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws SchemaRegistryClientException; /** * Fetches schema specified by the GUID. - * + *

* GUID can be assumed to be unique within a schema registry store. * * @param schemaGuid GUID reference to specific schema within configured schema registry store. * @return SchemaRegistryObject containing information regarding matching schema. * @throws SchemaRegistryClientException if fetch operation fails - * @throws IOException failed or interrupted I/O operation */ - public SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws IOException, SchemaRegistryClientException; + SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws SchemaRegistryClientException; /** * Fetches schema GUID given schema group, name, string representation, and serialization type + * * @param schemaGroup schema group name * @param schemaName schema name * @param schemaString String representation of schema * @param serializationType String representation of serialization format type * @return SchemaRegistryObject containing information regarding requested schema. * @throws SchemaRegistryClientException if fetch operation fails - * @throws IOException failed or interrupted I/O operation */ - public String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType) - throws IOException, SchemaRegistryClientException; + String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType) + throws SchemaRegistryClientException; /** * Not currently implemented. + * * @param schemaGroup schema group name * @param schemaName schema name * @param version schema version * @return GUID of delete schema * @throws SchemaRegistryClientException deletion operation failed - * @throws IOException failed or interrupted I/O operation */ - public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) - throws IOException, SchemaRegistryClientException; + String deleteSchemaVersion(String schemaGroup, String schemaName, int version) + throws SchemaRegistryClientException; /** * Not currently implemented. + * * @param schemaGroup schema group name * @param schemaName schema name * @return GUID of deleted schema * @throws SchemaRegistryClientException deletion operation failed - * @throws IOException failed or interrupted I/O operation */ - public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) - throws IOException, SchemaRegistryClientException; + String deleteLatestSchemaVersion(String schemaGroup, String schemaName) throws SchemaRegistryClientException; /** * Not currently implemented. + * * @param schemaGroup schema group name * @param schemaName schema name * @return list of GUID references to deleted schemas * @throws SchemaRegistryClientException deletion operation failed - * @throws IOException failed or interrupted I/O operation */ - public List deleteSchema(String schemaGroup, String schemaName) throws IOException, SchemaRegistryClientException; + List deleteSchema(String schemaGroup, String schemaName) throws SchemaRegistryClientException; } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java index 9e66012210a6..3dd6d00dbcb4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java @@ -1,16 +1,24 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.client; -public class SchemaRegistryClientException extends Exception { - public SchemaRegistryClientException(String s) { +/** + * Runtime exception to be returned from SchemaRegistryClient implementations. + */ +public class SchemaRegistryClientException extends RuntimeException { + /** + * @param s error message returned from schema registry client + */ + SchemaRegistryClientException(String s) { super(s); } - public SchemaRegistryClientException(String s, Throwable cause) { + /** + * @param s error message returned from schema registry client + * @param cause Throwable cause of the exception + */ + SchemaRegistryClientException(String s, Throwable cause) { super(s, cause); } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java index ace30ea7f428..f90901f50867 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.client; @@ -12,41 +10,69 @@ * Stores all relevant information returned from SchemaRegistryClient layer. */ public class SchemaRegistryObject { - private final ClientLogger log; - - public final String schemaId; - public final String serializationType; + private final ClientLogger logger = new ClientLogger(SchemaRegistryObject.class); - private Function parseMethod; + private final String schemaId; + private final String schemaType; + private final Function parseMethod; + private final byte[] schemaByteArray; - public byte[] schemaByteArray; private Object deserialized; + /** + * Initializes SchemaRegistryObject instance. + * + * @param schemaId schema ID + * @param schemaType type of schema, e.g. avro, json + * @param schemaByteArray byte payload representing schema, returned from Azure Schema Registry + * @param parseMethod method to deserialize schema payload into Object + */ public SchemaRegistryObject( String schemaId, - String serializationType, + String schemaType, byte[] schemaByteArray, Function parseMethod) { this.schemaId = schemaId; - this.serializationType = serializationType; - this.schemaByteArray = schemaByteArray; + this.schemaType = schemaType; + this.schemaByteArray = schemaByteArray.clone(); this.deserialized = null; this.parseMethod = parseMethod; - this.log = new ClientLogger(this.schemaId); } /** - * @return schema object of type T, deserialized using stored schema parser method. + * @return schema ID + */ + public String getSchemaId() { + return schemaId; + } + + /** + * @return schema type associated with the schema payload + */ + public String getSchemaType() { + return schemaType; + } + + /** + * Deserialize schema bytes returned from Schema Registry. If deserialization has happened once, the deserialized + * object is stored and returned. + * + * @return schema object, deserialized using stored schema parser method. */ public Object deserialize() { if (parseMethod == null) { - log.warning(String.format("No loaded parser for %s format. Schema guid: %s", this.serializationType, this.schemaId)); - return null; + throw logger.logExceptionAsError(new SchemaRegistryClientException( + String.format("No loaded parser for %s format. Schema guid: %s", + this.schemaType, this.schemaId))); } if (this.deserialized == null) { - log.verbose(String.format("Deserializing schema %s", new String(this.schemaByteArray))); - this.deserialized = parseMethod.apply(new String(this.schemaByteArray)); + logger.verbose( + String.format("Deserializing schema, id: %s, schema string %s", + this.schemaId, + new String(this.schemaByteArray, CachedSchemaRegistryClient.SCHEMA_REGISTRY_SERVICE_ENCODING))); + this.deserialized = parseMethod.apply( + new String(this.schemaByteArray, CachedSchemaRegistryClient.SCHEMA_REGISTRY_SERVICE_ENCODING)); } return deserialized; } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java index f3fdef57df1a..9059e387e5d5 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest; import com.azure.core.annotation.BodyParam; @@ -35,16 +38,23 @@ import com.azure.schemaregistry.client.rest.models.GetSchemasByGroupResponse; import com.azure.schemaregistry.client.rest.models.SchemaGroup; import com.azure.schemaregistry.client.rest.models.SchemaId; +import reactor.core.publisher.Mono; + import java.util.List; import java.util.UUID; -import reactor.core.publisher.Mono; -/** Initializes a new instance of the AzureSchemaRegistryRestService type. */ +/** + * Initializes a new instance of the AzureSchemaRegistryRestService type. + */ public final class AzureSchemaRegistryRestService { - /** The proxy service used to perform REST calls. */ + /** + * The proxy service used to perform REST calls. + */ private final AzureSchemaRegistryRestServiceService service; - /** server parameter. */ + /** + * server parameter. + */ private String host; /** @@ -67,7 +77,9 @@ public AzureSchemaRegistryRestService setHost(String host) { return this; } - /** The HTTP pipeline to send requests through. */ + /** + * The HTTP pipeline to send requests through. + */ private final HttpPipeline httpPipeline; /** @@ -79,7 +91,9 @@ public HttpPipeline getHttpPipeline() { return this.httpPipeline; } - /** Initializes an instance of AzureSchemaRegistryRestService client. */ + /** + * Initializes an instance of AzureSchemaRegistryRestService client. + */ public AzureSchemaRegistryRestService() { this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()).build()); } @@ -110,117 +124,117 @@ private interface AzureSchemaRegistryRestServiceService { @ExpectedResponses({200, 404}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono getSchemaById( - @HostParam("$host") String host, @PathParam("schema-id") UUID schemaId, Context context); + @HostParam("$host") String host, @PathParam("schema-id") UUID schemaId, Context context); @Get("/$schemagroups/{group-name}") @ExpectedResponses({200, 404}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono> getGroup( - @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); + @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); @Put("/$schemagroups/{group-name}") @ExpectedResponses({201, 409}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono createGroup( - @HostParam("$host") String host, - @PathParam("group-name") String groupName, - @BodyParam("application/json") SchemaGroup body, - Context context); + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @BodyParam("application/json") SchemaGroup body, + Context context); @Delete("/$schemagroups/{group-name}") @ExpectedResponses({204, 404}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono> deleteGroup( - @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); + @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); @Get("/$schemagroups/{group-name}/schemas") @ExpectedResponses({200, 404}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono getSchemasByGroup( - @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); + @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); @Delete("/$schemagroups/{group-name}/schemas") @ExpectedResponses({204, 404}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono> deleteSchemasByGroup( - @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); + @HostParam("$host") String host, @PathParam("group-name") String groupName, Context context); @Post("/$schemagroups/{group-name}/schemas/{schema-name}") @ExpectedResponses({200, 404}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono getIdBySchemaContent( - @HostParam("$host") String host, - @PathParam("group-name") String groupName, - @PathParam("schema-name") String schemaName, - @HeaderParam("X-Schema-Type") String xSchemaType, - @BodyParam("application/json") String body, - Context context); + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + @HeaderParam("X-Schema-Type") String xSchemaType, + @BodyParam("application/json") String body, + Context context); @Put("/$schemagroups/{group-name}/schemas/{schema-name}") @ExpectedResponses({200, 400}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono createSchema( - @HostParam("$host") String host, - @PathParam("group-name") String groupName, - @PathParam("schema-name") String schemaName, - @HeaderParam("X-Schema-Type") String xSchemaType, - @BodyParam("application/json") String body, - Context context); + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + @HeaderParam("X-Schema-Type") String xSchemaType, + @BodyParam("application/json") String body, + Context context); @Get("/$schemagroups/{group-name}/schemas/{schema-name}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono getLatestSchema( - @HostParam("$host") String host, - @PathParam("group-name") String groupName, - @PathParam("schema-name") String schemaName, - Context context); + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + Context context); @Delete("/$schemagroups/{group-name}/schemas/{schema-name}") @ExpectedResponses({204, 404}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono> deleteSchema( - @HostParam("$host") String host, - @PathParam("group-name") String groupName, - @PathParam("schema-name") String schemaName, - Context context); + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + Context context); @Get("/$schemagroups/{group-name}/schemas/{schema-name}/versions") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono getSchemaVersions( - @HostParam("$host") String host, - @PathParam("group-name") String groupName, - @PathParam("schema-name") String schemaName, - Context context); + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + Context context); @Get("/$schemagroups/{group-name}/schemas/{schema-name}/versions/{version-number}") @ExpectedResponses({200, 404}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono getSchemaVersion( - @HostParam("$host") String host, - @PathParam("group-name") String groupName, - @PathParam("schema-name") String schemaName, - @PathParam("version-number") int versionNumber, - Context context); + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + @PathParam("version-number") int versionNumber, + Context context); @Delete("/$schemagroups/{group-name}/schemas/{schema-name}/versions/{version-number}") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(HttpResponseException.class) Mono> deleteSchemaVersion( - @HostParam("$host") String host, - @PathParam("group-name") String groupName, - @PathParam("schema-name") String schemaName, - @PathParam("version-number") int versionNumber, - Context context); + @HostParam("$host") String host, + @PathParam("group-name") String groupName, + @PathParam("schema-name") String schemaName, + @PathParam("version-number") int versionNumber, + Context context); } /** * Get all schema groups in namespace. * + * @return all schema groups in namespace. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return all schema groups in namespace. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono>> getGroupsWithResponseAsync() { @@ -234,10 +248,10 @@ public Mono>> getGroupsWithResponseAsync() { * Get all schema groups in namespace. * * @param context The context to associate with this operation. + * @return all schema groups in namespace. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return all schema groups in namespace. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono>> getGroupsWithResponseAsync(Context context) { @@ -250,29 +264,29 @@ public Mono>> getGroupsWithResponseAsync(Context con /** * Get all schema groups in namespace. * + * @return all schema groups in namespace. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return all schema groups in namespace. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getGroupsAsync() { return getGroupsWithResponseAsync() - .flatMap( - (SimpleResponse> res) -> { - if (res.getValue() != null) { - return Mono.just(res.getValue()); - } else { - return Mono.empty(); - } - }); + .flatMap( + (SimpleResponse> res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); } /** * Get all schema groups in namespace. * + * @return all schema groups in namespace. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return all schema groups in namespace. */ @ServiceMethod(returns = ReturnType.SINGLE) public List getGroups() { @@ -283,10 +297,10 @@ public List getGroups() { * Get schema by schema ID. * * @param schemaId schema ID referencing specific schema in registry namespace. + * @return schema by schema ID. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return schema by schema ID. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemaByIdWithResponseAsync(UUID schemaId) { @@ -304,10 +318,10 @@ public Mono getSchemaByIdWithResponseAsync(UUID schemaId) * * @param schemaId schema ID referencing specific schema in registry namespace. * @param context The context to associate with this operation. + * @return schema by schema ID. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return schema by schema ID. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemaByIdWithResponseAsync(UUID schemaId, Context context) { @@ -324,46 +338,47 @@ public Mono getSchemaByIdWithResponseAsync(UUID schemaId, * Get schema by schema ID. * * @param schemaId schema ID referencing specific schema in registry namespace. + * @return schema by schema ID. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return schema by schema ID. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemaByIdAsync(UUID schemaId) { return getSchemaByIdWithResponseAsync(schemaId) - .flatMap( - (GetSchemaByIdResponse res) -> { - if (res.getValue() != null) { - return Mono.just(res.getValue()); - } else { - return Mono.empty(); - } - }); + .flatMap( + (GetSchemaByIdResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); } /** * Get schema by schema ID. * * @param schemaId schema ID referencing specific schema in registry namespace. + * @return schema by schema ID. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return schema by schema ID. */ @ServiceMethod(returns = ReturnType.SINGLE) public String getSchemaById(UUID schemaId) { return getSchemaByIdAsync(schemaId).block(); } + /** * Get schema group description in registry namespace. * * @param groupName schema group. + * @return schema group description in registry namespace. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return schema group description in registry namespace. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getGroupWithResponseAsync(String groupName) { @@ -381,10 +396,10 @@ public Mono> getGroupWithResponseAsync(String groupN * * @param groupName schema group. * @param context The context to associate with this operation. + * @return schema group description in registry namespace. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return schema group description in registry namespace. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getGroupWithResponseAsync(String groupName, Context context) { @@ -401,32 +416,32 @@ public Mono> getGroupWithResponseAsync(String groupN * Get schema group description in registry namespace. * * @param groupName schema group. + * @return schema group description in registry namespace. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return schema group description in registry namespace. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getGroupAsync(String groupName) { return getGroupWithResponseAsync(groupName) - .flatMap( - (SimpleResponse res) -> { - if (res.getValue() != null) { - return Mono.just(res.getValue()); - } else { - return Mono.empty(); - } - }); + .flatMap( + (SimpleResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); } /** * Get schema group description in registry namespace. * * @param groupName schema group. + * @return schema group description in registry namespace. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return schema group description in registry namespace. */ @ServiceMethod(returns = ReturnType.SINGLE) public SchemaGroup getGroup(String groupName) { @@ -438,10 +453,10 @@ public SchemaGroup getGroup(String groupName) { * * @param groupName schema group. * @param body schema group description. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createGroupWithResponseAsync(String groupName, SchemaGroup body) { @@ -465,10 +480,10 @@ public Mono createGroupWithResponseAsync(String groupName, * @param groupName schema group. * @param body schema group description. * @param context The context to associate with this operation. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createGroupWithResponseAsync(String groupName, SchemaGroup body, Context context) { @@ -491,10 +506,10 @@ public Mono createGroupWithResponseAsync(String groupName, * * @param groupName schema group. * @param body schema group description. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createGroupAsync(String groupName, SchemaGroup body) { @@ -519,10 +534,10 @@ public void createGroup(String groupName, SchemaGroup body) { * Delete schema group in schema registry namespace. * * @param groupName schema group. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteGroupWithResponseAsync(String groupName) { @@ -540,10 +555,10 @@ public Mono> deleteGroupWithResponseAsync(String groupName) { * * @param groupName schema group. * @param context The context to associate with this operation. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteGroupWithResponseAsync(String groupName, Context context) { @@ -560,10 +575,10 @@ public Mono> deleteGroupWithResponseAsync(String groupName, Conte * Delete schema group in schema registry namespace. * * @param groupName schema group. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteGroupAsync(String groupName) { @@ -587,10 +602,10 @@ public void deleteGroup(String groupName) { * Returns schema by group name. * * @param groupName schema group. + * @return array of String. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return array of String. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemasByGroupWithResponseAsync(String groupName) { @@ -608,10 +623,10 @@ public Mono getSchemasByGroupWithResponseAsync(String * * @param groupName schema group. * @param context The context to associate with this operation. + * @return array of String. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return array of String. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemasByGroupWithResponseAsync(String groupName, Context context) { @@ -628,32 +643,32 @@ public Mono getSchemasByGroupWithResponseAsync(String * Returns schema by group name. * * @param groupName schema group. + * @return array of String. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return array of String. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getSchemasByGroupAsync(String groupName) { return getSchemasByGroupWithResponseAsync(groupName) - .flatMap( - (GetSchemasByGroupResponse res) -> { - if (res.getValue() != null) { - return Mono.just(res.getValue()); - } else { - return Mono.empty(); - } - }); + .flatMap( + (GetSchemasByGroupResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); } /** * Returns schema by group name. * * @param groupName schema group. + * @return array of String. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return array of String. */ @ServiceMethod(returns = ReturnType.SINGLE) public List getSchemasByGroup(String groupName) { @@ -664,10 +679,10 @@ public List getSchemasByGroup(String groupName) { * Deletes all schemas under specified group name. * * @param groupName schema group. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteSchemasByGroupWithResponseAsync(String groupName) { @@ -685,10 +700,10 @@ public Mono> deleteSchemasByGroupWithResponseAsync(String groupNa * * @param groupName schema group. * @param context The context to associate with this operation. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteSchemasByGroupWithResponseAsync(String groupName, Context context) { @@ -705,10 +720,10 @@ public Mono> deleteSchemasByGroupWithResponseAsync(String groupNa * Deletes all schemas under specified group name. * * @param groupName schema group. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteSchemasByGroupAsync(String groupName) { @@ -735,14 +750,14 @@ public void deleteSchemasByGroup(String groupName) { * @param schemaName schema name. * @param xSchemaType The xSchemaType parameter. * @param body schema content. + * @return iD for schema with matching byte content and schema type. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return iD for schema with matching byte content and schema type. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getIdBySchemaContentWithResponseAsync( - String groupName, String schemaName, String xSchemaType, String body) { + String groupName, String schemaName, String xSchemaType, String body) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -759,9 +774,9 @@ public Mono getIdBySchemaContentWithResponseAsync( return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); } return FluxUtil.withContext( - context -> - service.getIdBySchemaContent( - this.getHost(), groupName, schemaName, xSchemaType, body, context)); + context -> + service.getIdBySchemaContent( + this.getHost(), groupName, schemaName, xSchemaType, body, context)); } /** @@ -772,14 +787,14 @@ public Mono getIdBySchemaContentWithResponseAsync( * @param xSchemaType The xSchemaType parameter. * @param body schema content. * @param context The context to associate with this operation. + * @return iD for schema with matching byte content and schema type. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return iD for schema with matching byte content and schema type. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getIdBySchemaContentWithResponseAsync( - String groupName, String schemaName, String xSchemaType, String body, Context context) { + String groupName, String schemaName, String xSchemaType, String body, Context context) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -805,23 +820,23 @@ public Mono getIdBySchemaContentWithResponseAsync( * @param schemaName schema name. * @param xSchemaType The xSchemaType parameter. * @param body schema content. + * @return iD for schema with matching byte content and schema type. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return iD for schema with matching byte content and schema type. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getIdBySchemaContentAsync( - String groupName, String schemaName, String xSchemaType, String body) { + String groupName, String schemaName, String xSchemaType, String body) { return getIdBySchemaContentWithResponseAsync(groupName, schemaName, xSchemaType, body) - .flatMap( - (GetIdBySchemaContentResponse res) -> { - if (res.getValue() != null) { - return Mono.just(res.getValue()); - } else { - return Mono.empty(); - } - }); + .flatMap( + (GetIdBySchemaContentResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); } /** @@ -831,10 +846,10 @@ public Mono getIdBySchemaContentAsync( * @param schemaName schema name. * @param xSchemaType The xSchemaType parameter. * @param body schema content. + * @return iD for schema with matching byte content and schema type. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return iD for schema with matching byte content and schema type. */ @ServiceMethod(returns = ReturnType.SINGLE) public SchemaId getIdBySchemaContent(String groupName, String schemaName, String xSchemaType, String body) { @@ -850,14 +865,14 @@ public SchemaId getIdBySchemaContent(String groupName, String schemaName, String * @param schemaName schema name. * @param xSchemaType The xSchemaType parameter. * @param body schema content. + * @return the response. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the response. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createSchemaWithResponseAsync( - String groupName, String schemaName, String xSchemaType, String body) { + String groupName, String schemaName, String xSchemaType, String body) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -874,7 +889,7 @@ public Mono createSchemaWithResponseAsync( return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); } return FluxUtil.withContext( - context -> service.createSchema(this.getHost(), groupName, schemaName, xSchemaType, body, context)); + context -> service.createSchema(this.getHost(), groupName, schemaName, xSchemaType, body, context)); } /** @@ -887,14 +902,14 @@ public Mono createSchemaWithResponseAsync( * @param xSchemaType The xSchemaType parameter. * @param body schema content. * @param context The context to associate with this operation. + * @return the response. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the response. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createSchemaWithResponseAsync( - String groupName, String schemaName, String xSchemaType, String body, Context context) { + String groupName, String schemaName, String xSchemaType, String body, Context context) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -922,22 +937,22 @@ public Mono createSchemaWithResponseAsync( * @param schemaName schema name. * @param xSchemaType The xSchemaType parameter. * @param body schema content. + * @return the response. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the response. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createSchemaAsync(String groupName, String schemaName, String xSchemaType, String body) { return createSchemaWithResponseAsync(groupName, schemaName, xSchemaType, body) - .flatMap( - (CreateSchemaResponse res) -> { - if (res.getValue() != null) { - return Mono.just(res.getValue()); - } else { - return Mono.empty(); - } - }); + .flatMap( + (CreateSchemaResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); } /** @@ -949,10 +964,10 @@ public Mono createSchemaAsync(String groupName, String schemaName, Str * @param schemaName schema name. * @param xSchemaType The xSchemaType parameter. * @param body schema content. + * @return the response. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the response. */ @ServiceMethod(returns = ReturnType.SINGLE) public SchemaId createSchema(String groupName, String schemaName, String xSchemaType, String body) { @@ -964,10 +979,10 @@ public SchemaId createSchema(String groupName, String schemaName, String xSchema * * @param groupName schema group. * @param schemaName schema name. + * @return latest version of schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return latest version of schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getLatestSchemaWithResponseAsync(String groupName, String schemaName) { @@ -989,14 +1004,14 @@ public Mono getLatestSchemaWithResponseAsync(String gro * @param groupName schema group. * @param schemaName schema name. * @param context The context to associate with this operation. + * @return latest version of schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return latest version of schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getLatestSchemaWithResponseAsync( - String groupName, String schemaName, Context context) { + String groupName, String schemaName, Context context) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -1014,22 +1029,22 @@ public Mono getLatestSchemaWithResponseAsync( * * @param groupName schema group. * @param schemaName schema name. + * @return latest version of schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return latest version of schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getLatestSchemaAsync(String groupName, String schemaName) { return getLatestSchemaWithResponseAsync(groupName, schemaName) - .flatMap( - (GetLatestSchemaResponse res) -> { - if (res.getValue() != null) { - return Mono.just(res.getValue()); - } else { - return Mono.empty(); - } - }); + .flatMap( + (GetLatestSchemaResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); } /** @@ -1037,10 +1052,10 @@ public Mono getLatestSchemaAsync(String groupName, String schemaName) { * * @param groupName schema group. * @param schemaName schema name. + * @return latest version of schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return latest version of schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public String getLatestSchema(String groupName, String schemaName) { @@ -1052,10 +1067,10 @@ public String getLatestSchema(String groupName, String schemaName) { * * @param groupName schema group. * @param schemaName schema name. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteSchemaWithResponseAsync(String groupName, String schemaName) { @@ -1077,10 +1092,10 @@ public Mono> deleteSchemaWithResponseAsync(String groupName, Stri * @param groupName schema group. * @param schemaName schema name. * @param context The context to associate with this operation. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteSchemaWithResponseAsync(String groupName, String schemaName, Context context) { @@ -1101,10 +1116,10 @@ public Mono> deleteSchemaWithResponseAsync(String groupName, Stri * * @param groupName schema group. * @param schemaName schema name. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteSchemaAsync(String groupName, String schemaName) { @@ -1130,10 +1145,10 @@ public void deleteSchema(String groupName, String schemaName) { * * @param groupName schema group. * @param schemaName schema name. + * @return list of versions for specified schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return list of versions for specified schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemaVersionsWithResponseAsync(String groupName, String schemaName) { @@ -1147,7 +1162,7 @@ public Mono getSchemaVersionsWithResponseAsync(String return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); } return FluxUtil.withContext( - context -> service.getSchemaVersions(this.getHost(), groupName, schemaName, context)); + context -> service.getSchemaVersions(this.getHost(), groupName, schemaName, context)); } /** @@ -1156,14 +1171,14 @@ public Mono getSchemaVersionsWithResponseAsync(String * @param groupName schema group. * @param schemaName schema name. * @param context The context to associate with this operation. + * @return list of versions for specified schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return list of versions for specified schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemaVersionsWithResponseAsync( - String groupName, String schemaName, Context context) { + String groupName, String schemaName, Context context) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -1181,22 +1196,22 @@ public Mono getSchemaVersionsWithResponseAsync( * * @param groupName schema group. * @param schemaName schema name. + * @return list of versions for specified schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return list of versions for specified schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getSchemaVersionsAsync(String groupName, String schemaName) { return getSchemaVersionsWithResponseAsync(groupName, schemaName) - .flatMap( - (GetSchemaVersionsResponse res) -> { - if (res.getValue() != null) { - return Mono.just(res.getValue()); - } else { - return Mono.empty(); - } - }); + .flatMap( + (GetSchemaVersionsResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); } /** @@ -1204,10 +1219,10 @@ public Mono> getSchemaVersionsAsync(String groupName, String schem * * @param groupName schema group. * @param schemaName schema name. + * @return list of versions for specified schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return list of versions for specified schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public List getSchemaVersions(String groupName, String schemaName) { @@ -1220,14 +1235,14 @@ public List getSchemaVersions(String groupName, String schemaName) { * @param groupName schema group. * @param schemaName schema name. * @param versionNumber version number. + * @return specified version of schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return specified version of schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemaVersionWithResponseAsync( - String groupName, String schemaName, int versionNumber) { + String groupName, String schemaName, int versionNumber) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -1238,7 +1253,7 @@ public Mono getSchemaVersionWithResponseAsync( return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); } return FluxUtil.withContext( - context -> service.getSchemaVersion(this.getHost(), groupName, schemaName, versionNumber, context)); + context -> service.getSchemaVersion(this.getHost(), groupName, schemaName, versionNumber, context)); } /** @@ -1248,14 +1263,14 @@ public Mono getSchemaVersionWithResponseAsync( * @param schemaName schema name. * @param versionNumber version number. * @param context The context to associate with this operation. + * @return specified version of schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return specified version of schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemaVersionWithResponseAsync( - String groupName, String schemaName, int versionNumber, Context context) { + String groupName, String schemaName, int versionNumber, Context context) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -1274,22 +1289,22 @@ public Mono getSchemaVersionWithResponseAsync( * @param groupName schema group. * @param schemaName schema name. * @param versionNumber version number. + * @return specified version of schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return specified version of schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSchemaVersionAsync(String groupName, String schemaName, int versionNumber) { return getSchemaVersionWithResponseAsync(groupName, schemaName, versionNumber) - .flatMap( - (GetSchemaVersionResponse res) -> { - if (res.getValue() != null) { - return Mono.just(res.getValue()); - } else { - return Mono.empty(); - } - }); + .flatMap( + (GetSchemaVersionResponse res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); } /** @@ -1298,10 +1313,10 @@ public Mono getSchemaVersionAsync(String groupName, String schemaName, i * @param groupName schema group. * @param schemaName schema name. * @param versionNumber version number. + * @return specified version of schema. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return specified version of schema. */ @ServiceMethod(returns = ReturnType.SINGLE) public String getSchemaVersion(String groupName, String schemaName, int versionNumber) { @@ -1314,14 +1329,14 @@ public String getSchemaVersion(String groupName, String schemaName, int versionN * @param groupName schema group. * @param schemaName schema name. * @param versionNumber version number. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteSchemaVersionWithResponseAsync( - String groupName, String schemaName, int versionNumber) { + String groupName, String schemaName, int versionNumber) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -1332,7 +1347,7 @@ public Mono> deleteSchemaVersionWithResponseAsync( return Mono.error(new IllegalArgumentException("Parameter schemaName is required and cannot be null.")); } return FluxUtil.withContext( - context -> service.deleteSchemaVersion(this.getHost(), groupName, schemaName, versionNumber, context)); + context -> service.deleteSchemaVersion(this.getHost(), groupName, schemaName, versionNumber, context)); } /** @@ -1342,14 +1357,14 @@ public Mono> deleteSchemaVersionWithResponseAsync( * @param schemaName schema name. * @param versionNumber version number. * @param context The context to associate with this operation. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteSchemaVersionWithResponseAsync( - String groupName, String schemaName, int versionNumber, Context context) { + String groupName, String schemaName, int versionNumber, Context context) { if (this.getHost() == null) { return Mono.error(new IllegalArgumentException("Parameter this.getHost() is required and cannot be null.")); } @@ -1368,15 +1383,15 @@ public Mono> deleteSchemaVersionWithResponseAsync( * @param groupName schema group. * @param schemaName schema name. * @param versionNumber version number. + * @return the completion. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the completion. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteSchemaVersionAsync(String groupName, String schemaName, int versionNumber) { return deleteSchemaVersionWithResponseAsync(groupName, schemaName, versionNumber) - .flatMap((Response res) -> Mono.empty()); + .flatMap((Response res) -> Mono.empty()); } /** diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceClientBuilder.java similarity index 79% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceBuilder.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceClientBuilder.java index 7a28963399e6..a1643a217ba8 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceClientBuilder.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest; import com.azure.core.annotation.ServiceClientBuilder; @@ -9,7 +12,7 @@ /** A builder for creating a new instance of the AzureSchemaRegistryRestService type. */ @ServiceClientBuilder(serviceClients = {AzureSchemaRegistryRestService.class}) -public final class AzureSchemaRegistryRestServiceBuilder { +public final class AzureSchemaRegistryRestServiceClientBuilder { /* * server parameter */ @@ -19,9 +22,9 @@ public final class AzureSchemaRegistryRestServiceBuilder { * Sets server parameter. * * @param host the host value. - * @return the AzureSchemaRegistryRestServiceBuilder. + * @return the AzureSchemaRegistryRestServiceClientBuilder. */ - public AzureSchemaRegistryRestServiceBuilder host(String host) { + public AzureSchemaRegistryRestServiceClientBuilder host(String host) { this.host = host; return this; } @@ -35,9 +38,9 @@ public AzureSchemaRegistryRestServiceBuilder host(String host) { * Sets The HTTP pipeline to send requests through. * * @param pipeline the pipeline value. - * @return the AzureSchemaRegistryRestServiceBuilder. + * @return the AzureSchemaRegistryRestServiceClientBuilder. */ - public AzureSchemaRegistryRestServiceBuilder pipeline(HttpPipeline pipeline) { + public AzureSchemaRegistryRestServiceClientBuilder pipeline(HttpPipeline pipeline) { this.pipeline = pipeline; return this; } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java index 8b6f82ac1275..8f50fa5babe8 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -37,5 +40,5 @@ public CreateGroupHeaders setLocation(String location) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java index 4c4e47bbd934..b62e9399f2f5 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.http.HttpHeaders; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java index ee1dc4292e62..e57cb556630c 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -143,5 +146,5 @@ public CreateSchemaHeaders setLocation(String location) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java index 5320db393457..1dec3c2aa724 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.http.HttpHeaders; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java index ed46a2a0c16f..dc77686dff43 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -143,5 +146,5 @@ public GetIdBySchemaContentHeaders setLocation(String location) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java index 0e3ef3336879..e26af9943bd6 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.http.HttpHeaders; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java index 94072e763527..9cdf385e0924 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -143,5 +146,5 @@ public GetLatestSchemaHeaders setLocation(String location) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java index 2f766f03f1b4..8dfcf1f9ec9e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.http.HttpHeaders; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java index a41fd8e4c9de..a6027973f53a 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -143,5 +146,5 @@ public GetSchemaByIdHeaders setLocation(String location) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java index 2be80766be08..8d80b74e1d70 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.http.HttpHeaders; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java index e4742e04be7b..c16879dac958 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -143,5 +146,5 @@ public GetSchemaVersionHeaders setLocation(String location) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java index 1b96f7c670d1..e310d36ec8d0 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.http.HttpHeaders; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java index bc05b2c1c908..03a25659f2eb 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -37,5 +40,5 @@ public GetSchemaVersionsHeaders setXSchemaType(String xSchemaType) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java index 22d31d3264db..0875be91a464 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.http.HttpHeaders; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java index 1f4bddb08893..1142e85b8e86 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -37,5 +40,5 @@ public GetSchemasByGroupHeaders setXSchemaType(String xSchemaType) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java index 07e069e22c88..e80e83544847 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.http.HttpHeaders; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java index 16e46234b171..b0285509e5af 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -169,5 +172,5 @@ public SchemaGroup setGroupProperties(Map groupProperties) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java index 3bf43b85aac4..4afc4840d571 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.schemaregistry.client.rest.models; import com.azure.core.annotation.Fluent; @@ -37,5 +40,5 @@ public SchemaId setId(String id) { * * @throws IllegalArgumentException thrown if the instance is not valid. */ - public void validate() {} + public void validate() { } } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java index 3a0c9fe0490d..ff2eadc27b1d 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java @@ -1,2 +1,3 @@ /** Package containing the data models for AzureSchemaRegistryRestService. null. */ + package com.azure.schemaregistry.client.rest.models; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java index c5581660f9c5..c6a96f56d91e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.client; @@ -9,6 +7,7 @@ import com.azure.schemaregistry.client.rest.models.GetSchemaByIdHeaders; import com.azure.schemaregistry.client.rest.models.GetSchemaByIdResponse; import com.azure.schemaregistry.client.rest.models.SchemaId; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,7 +41,7 @@ protected void setUp() { this.schemaStringCache = new HashMap(); this.typeParserDictionary = new HashMap>(); - this.typeParserDictionary.put(MOCK_SERIALIZATION, (s)->s); + this.typeParserDictionary.put(MOCK_SERIALIZATION, (s) -> s); this.restService = mock(AzureSchemaRegistryRestService.class); this.client = new CachedSchemaRegistryClient( @@ -52,6 +51,7 @@ protected void setUp() { this.typeParserDictionary); } + @AfterEach protected void tearDown() { validateMockitoUsage(); } @@ -62,10 +62,15 @@ public void testRegisterThenSchemaCacheHit() throws Exception { when(restService.createSchema(anyString(), anyString(), anyString(), anyString())) .thenReturn(MOCK_SCHEMA_ID); - assertEquals(MOCK_ID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaId); - assertEquals(MOCK_ID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaId); + assertEquals( + MOCK_ID, + client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).getSchemaId()); + assertEquals( + MOCK_ID, + client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).getSchemaId()); - verify(restService, times(1)).createSchema(anyString(), anyString(), anyString(), anyString()); + verify(restService, times(1)) + .createSchema(anyString(), anyString(), anyString(), anyString()); } @Test @@ -77,7 +82,8 @@ public void testGetGuidThenSchemaCacheHit() throws Exception { assertEquals(MOCK_ID, client.getSchemaId(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); assertEquals(MOCK_ID, client.getSchemaId(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION)); - verify(restService, times(1)).getIdBySchemaContent(anyString(), anyString(), anyString(), anyString()); + verify(restService, times(1)) + .getIdBySchemaContent(anyString(), anyString(), anyString(), anyString()); } @Test @@ -87,13 +93,18 @@ public void testGetSchemaThenGuidCacheHit() throws Exception { mockHeaders.setXSchemaType(MOCK_SERIALIZATION); when(restService.getSchemaByIdWithResponseAsync(mockId)) .thenReturn( - Mono.just(new GetSchemaByIdResponse(null, 200, null, MOCK_AVRO_SCHEMA, mockHeaders))); + Mono.just(new GetSchemaByIdResponse( + null, + 200, + null, + MOCK_AVRO_SCHEMA, + mockHeaders))); SchemaRegistryObject first = client.getSchemaByGuid(mockId.toString()); SchemaRegistryObject second = client.getSchemaByGuid(mockId.toString()); assertTrue(first.equals(second)); - assertEquals(mockId.toString(), first.schemaId); + assertEquals(mockId.toString(), first.getSchemaId()); verify(restService, times(1)).getSchemaByIdWithResponseAsync(mockId); } @@ -104,7 +115,9 @@ public void testClientReset() throws Exception { when(restService.createSchema(anyString(), anyString(), anyString(), anyString())) .thenReturn(MOCK_SCHEMA_ID); - assertEquals(MOCK_ID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaId); + assertEquals( + MOCK_ID, + client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).getSchemaId()); client.reset(); @@ -112,10 +125,13 @@ public void testClientReset() throws Exception { assertEquals(0, schemaStringCache.size()); assertEquals(0, this.typeParserDictionary.size()); - this.typeParserDictionary.put(MOCK_SERIALIZATION, (s)->s); + this.typeParserDictionary.put(MOCK_SERIALIZATION, (s) -> s); - assertEquals(MOCK_ID, client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).schemaId); + assertEquals( + MOCK_ID, + client.register(MOCK_GROUP, MOCK_SCHEMA_NAME, MOCK_AVRO_SCHEMA, MOCK_SERIALIZATION).getSchemaId()); - verify(restService, times(2)).createSchema(anyString(), anyString(), anyString(), anyString()); + verify(restService, times(2)) + .createSchema(anyString(), anyString(), anyString(), anyString()); } } From 59c1c07d195d29336b245b125d1525f244457685 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 14:22:58 -0700 Subject: [PATCH 11/43] javadoc checkstyle --- .../azure-schemaregistry-serde-common/pom.xml | 4 + .../AbstractDataDeserializer.java | 90 ++++++++++++------ .../schemaregistry/AbstractDataSerDe.java | 24 +++-- .../AbstractDataSerializer.java | 92 +++++++++++++------ .../com/azure/schemaregistry/ByteDecoder.java | 13 +-- .../com/azure/schemaregistry/ByteEncoder.java | 21 +++-- .../java/com/azure/schemaregistry/Codec.java | 10 +- .../SerializationException.java | 17 ++-- .../azure/schemaregistry/package-info.java | 4 + .../AbstractDataDeserializerTest.java | 20 ++-- .../AbstractDataSerializerTest.java | 40 ++++---- .../MockSchemaRegistryClient.java | 50 ++++++---- .../schemaregistry/SampleByteDecoder.java | 12 +-- .../schemaregistry/SampleByteEncoder.java | 8 +- .../schemaregistry/TestDummyDeserializer.java | 6 +- .../schemaregistry/TestDummySerializer.java | 6 +- 16 files changed, 255 insertions(+), 162 deletions(-) create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/package-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml index a0008c2546c1..6cc8028bee45 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml @@ -35,6 +35,10 @@ HEAD + + true + + com.azure diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java index 3ef9ce48d3ad..6bb9e074606c 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java @@ -1,58 +1,76 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; +import com.azure.core.util.logging.ClientLogger; import com.azure.schemaregistry.client.SchemaRegistryObject; import com.azure.schemaregistry.client.SchemaRegistryClient; import com.azure.schemaregistry.client.SchemaRegistryClientException; -import java.io.IOException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +/** + * Common implementation for all registry-based deserializers. + */ public abstract class AbstractDataDeserializer extends AbstractDataSerDe { + private final ClientLogger logger = new ClientLogger(AbstractDataDeserializer.class); + protected final Map byteDecoderMap = new ConcurrentHashMap<>(); + /** + * Constructor called by all concrete implementation constructors. + * Should only call parent constructor. + * @param schemaRegistryClient client to be used for fetching schemas by ID + */ protected AbstractDataDeserializer(SchemaRegistryClient schemaRegistryClient) { super(schemaRegistryClient); } - // special case for KafkaAvroDeserializer - protected AbstractDataDeserializer() { - } - + /** + * Special case constructor for Kafka deserializer's empty constructors. + */ + protected AbstractDataDeserializer() { } + + /** + * Fetches schema referenced by prefixed ID and deserializes the subsequent payload into Java object. + * + * @param payload byte payload, produced by an Azure Schema Registry client producer + * @return object, deserialized with the prefixed schema + * @throws SerializationException if deserialization of registry schema or message payload fails. + */ protected Object deserialize(byte[] payload) throws SerializationException { if (payload == null) { return null; } - ByteBuffer buffer = getByteBuffer(payload); + ByteBuffer buffer = ByteBuffer.wrap(payload); String schemaGuid = getSchemaGuidFromPayload(buffer); - SchemaRegistryObject registryObject = null; - Object payloadSchema = null; + SchemaRegistryObject registryObject; + Object payloadSchema; try { registryObject = this.schemaRegistryClient.getSchemaByGuid(schemaGuid); payloadSchema = registryObject.deserialize(); - } catch (IOException | SchemaRegistryClientException e) { - throw new SerializationException("Failed to retrieve schema for id " + schemaGuid, e); + } catch (SchemaRegistryClientException e) { + throw logger.logExceptionAsError( + new SerializationException(String.format("Failed to retrieve schema for id ", schemaGuid), e)); } // TODO: how to handle unknown formats if (payloadSchema == null) { - throw new SerializationException( + throw logger.logExceptionAsError( + new SerializationException( String.format("Cast failure for REST object from registry. Object type: %s", - registryObject.deserialize().getClass().getName())); + registryObject.deserialize().getClass().getName()))); } int start = buffer.position() + buffer.arrayOffset(); - int length = buffer.limit() - AbstractDataSerDe.idSize; + int length = buffer.limit() - AbstractDataSerDe.SCHEMA_ID_SIZE; byte[] b = Arrays.copyOfRange(buffer.array(), start, start + length); ByteDecoder byteDecoder = getByteDecoder(registryObject); @@ -60,32 +78,48 @@ protected Object deserialize(byte[] payload) throws SerializationException { } + /** + * Fetches the correct ByteDecoder based on schema type of the message. + * + * @param registryObject object returned from SchemaRegistryClient, contains schema type + * @return ByteDecoder to be used to deserialize encoded payload bytes + * @throws SerializationException if decoder for the required schema type has not been loaded + */ private ByteDecoder getByteDecoder(SchemaRegistryObject registryObject) throws SerializationException { - ByteDecoder decoder = byteDecoderMap.get(registryObject.serializationType); + ByteDecoder decoder = byteDecoderMap.get(registryObject.getSchemaType()); if (decoder == null) { - throw new SerializationException("No decoder class found for serialization type " + - registryObject.serializationType); + throw logger.logExceptionAsError( + new SerializationException( + String.format("No decoder class found for serialization type ", registryObject.getSchemaType()))); } return decoder; } - private ByteBuffer getByteBuffer(byte[] payload) { - ByteBuffer buffer = ByteBuffer.wrap(payload); - return buffer; - } - + /** + * @param buffer full payload bytes + * @return String representation of schema ID + * @throws SerializationException if schema ID could not be extracted from payload + */ private String getSchemaGuidFromPayload(ByteBuffer buffer) throws SerializationException { - byte[] schemaGuidByteArray = new byte[AbstractDataSerDe.idSize]; + byte[] schemaGuidByteArray = new byte[AbstractDataSerDe.SCHEMA_ID_SIZE]; try { buffer.get(schemaGuidByteArray); } catch (BufferUnderflowException e) { - throw new SerializationException("Payload too short, no readable guid.", e); + throw logger.logExceptionAsError(new SerializationException("Payload too short, no readable guid.", e)); } - return new String(schemaGuidByteArray); + return new String(schemaGuidByteArray, schemaRegistryClient.getEncoding()); } + /** + * Loads a ByteDecoder to be used for deserializing payloads of specified serialization format. + * @param decoder ByteDecoder class instance to be loaded + */ protected void loadByteDecoder(ByteDecoder decoder) { + if (decoder == null) { + throw logger.logExceptionAsError(new SerializationException("ByteDecoder cannot be null")); + } + this.byteDecoderMap.put(decoder.serializationFormat(), decoder); this.schemaRegistryClient.loadSchemaParser(decoder.serializationFormat(), decoder::parseSchemaString); } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java index a01c3bac0a3c..c02412a4e8e7 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java @@ -1,29 +1,37 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; +import com.azure.core.util.logging.ClientLogger; import com.azure.schemaregistry.client.SchemaRegistryClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Common fields and helper methods for both the serializer and the deserializer. */ public abstract class AbstractDataSerDe { - public static final int idSize = 64; + private final ClientLogger logger = new ClientLogger(AbstractDataSerDe.class); + + public static final int SCHEMA_ID_SIZE = 32; protected SchemaRegistryClient schemaRegistryClient; + /** + * Base constructor for all SerDe implementations. + * @param schemaRegistryClient client to be used for sending or fetching schemas. + * @throws IllegalArgumentException schemaRegistryClient parameter cannot be null + */ protected AbstractDataSerDe(SchemaRegistryClient schemaRegistryClient) { if (schemaRegistryClient == null) { - throw new IllegalArgumentException("Schema registry client must be initialized and passed into builder."); + throw logger.logExceptionAsError( + new IllegalArgumentException("Schema registry client must be initialized and passed into builder.")); } this.schemaRegistryClient = schemaRegistryClient; } + /** + * Special case for Kafka serializer/deserializer implementations. + */ // special case for Kafka serializer/deserializer public AbstractDataSerDe() { diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java index 2672d97eb09d..70a4240bdff8 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java @@ -1,55 +1,75 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; import com.azure.core.util.logging.ClientLogger; import com.azure.schemaregistry.client.SchemaRegistryClient; import com.azure.schemaregistry.client.SchemaRegistryClientException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +/** + * Common implementation for all registry-based serializers. + */ public abstract class AbstractDataSerializer extends AbstractDataSerDe { - public static Boolean AUTO_REGISTER_SCHEMAS_DEFAULT = false; - public static String SCHEMA_GROUP_DEFAULT = "$default"; + private final ClientLogger logger = new ClientLogger(AbstractDataSerializer.class); + + public static final Boolean AUTO_REGISTER_SCHEMAS_DEFAULT = false; + public static final String SCHEMA_GROUP_DEFAULT = "$default"; protected ByteEncoder byteEncoder = null; protected String serializationFormat; protected Boolean autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; protected String schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; + /** + * @param schemaRegistryClient registry client to be used for storing schemas. Not null. + */ public AbstractDataSerializer(SchemaRegistryClient schemaRegistryClient) { super(schemaRegistryClient); } - // special case for KafkaAvroSerializer + /** + * Special case constructor for Kafka serializer. + */ public AbstractDataSerializer() { } + /** + * Set ByteEncoder class to be used for serialized objects into bytes + * @param byteEncoder ByteEncoder instance + */ protected void setByteEncoder(ByteEncoder byteEncoder) { if (this.byteEncoder != null) { - throw new IllegalArgumentException("Setting multiple encoders on serializer not permitted"); + throw logger.logExceptionAsError( + new IllegalArgumentException("Setting multiple encoders on serializer not permitted")); } this.byteEncoder = byteEncoder; this.schemaRegistryClient.loadSchemaParser(byteEncoder.serializationFormat(), byteEncoder::parseSchemaString); } - protected byte[] serializeImpl(Object object) throws SerializationException { + /** + * Core implementation of registry-based serialization. + * ID for data schema is fetched from the registry and prefixed to the encoded byte array + * representation of the object param. + * + * @param object object to be serialized + * @return byte array containing encoded bytes with prefixed schema ID + * @throws SerializationException if serialization operation fails during runtime. + */ + protected byte[] serializeImpl(Object object) { if (object == null) { - throw new SerializationException( - "Null object. Null object case should be handled in concrete serializer class." + - "Please file an issue."); + throw logger.logExceptionAsError(new SerializationException( + "Null object, behavior should be defined in concrete serializer implementation.")); } if (byteEncoder == null) { - throw new SerializationException("Byte encoder null, serializer must be initialized with a byte encoder."); + throw logger.logExceptionAsError( + new SerializationException("Byte encoder null, serializer must be initialized with a byte encoder.")); } if (serializationFormat == null) { @@ -60,34 +80,50 @@ protected byte[] serializeImpl(Object object) throws SerializationException { String schemaName = byteEncoder.getSchemaName(object); try { - String schemaGuid = maybeRegisterSchema(this.schemaGroup, schemaName, schemaString, this.serializationFormat); + String schemaGuid = maybeRegisterSchema( + this.schemaGroup, schemaName, schemaString, this.serializationFormat); ByteArrayOutputStream out = new ByteArrayOutputStream(); - // utf8 swap todo - ByteBuffer guidBuffer = ByteBuffer.allocate(AbstractDataSerDe.idSize) - .put(schemaGuid.getBytes(StandardCharsets.UTF_8)); + ByteBuffer guidBuffer = ByteBuffer.allocate(AbstractDataSerDe.SCHEMA_ID_SIZE) + .put(schemaGuid.getBytes(StandardCharsets.UTF_8)); out.write(guidBuffer.array()); byteEncoder.encode(object).writeTo(out); return out.toByteArray(); } catch (SchemaRegistryClientException | IOException e) { if (this.autoRegisterSchemas) { - throw new SerializationException( + throw logger.logExceptionAsError( + new SerializationException( String.format("Error registering Avro schema. Group: %s, name: %s", schemaGroup, schemaName), - e); + e)); } else { - throw new SerializationException( + throw logger.logExceptionAsError( + new SerializationException( String.format("Error retrieving Avro schema. Group: %s, name: %s", schemaGroup, schemaName), - e); + e)); } } } - private String maybeRegisterSchema(String schemaGroup, String schemaName, String schemaString, String serializationFormatString) - throws IOException, SchemaRegistryClientException { + /** + * If auto-registering is enabled, register schema against SchemaRegistryClient. + * If auto-registering is disabled, fetch schema ID for provided schema. Requires pre-registering of schema + * against registry. + * + * @param schemaGroup Schema group where schema should be registered. + * @param schemaName name of schema + * @param schemaString string representation of schema being stored - must match group schema type + * @param schemaType type of schema being stored, e.g. avro + * @return string representation of schema ID + * @throws SchemaRegistryClientException upon registry client operation failure + */ + private String maybeRegisterSchema( + String schemaGroup, String schemaName, String schemaString, String schemaType) + throws SchemaRegistryClientException { if (this.autoRegisterSchemas) { - return this.schemaRegistryClient.register(schemaGroup, schemaName, schemaString, - serializationFormatString).schemaId; + return this.schemaRegistryClient.register(schemaGroup, schemaName, schemaString, schemaType) + .getSchemaId(); } else { - return this.schemaRegistryClient.getSchemaId(schemaGroup, schemaName, schemaString, serializationFormatString); + return this.schemaRegistryClient.getSchemaId( + schemaGroup, schemaName, schemaString, schemaType); } } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteDecoder.java index 99ad2ea776b8..41f3273106c1 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteDecoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteDecoder.java @@ -1,17 +1,18 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; +/** + * An interface defining operations required for registry deserializer to convert encoded bytes to Java object. + */ public interface ByteDecoder extends Codec { /** * Decodes byte array into Object given provided schema object. * @param encodedBytes payload to be decoded * @param schemaObject object used to decode the payload * @return deserialized object - * @throws SerializationException + * @throws SerializationException if decode operation fails */ - public Object decodeBytes(byte[] encodedBytes, Object schemaObject) throws SerializationException; + Object decodeBytes(byte[] encodedBytes, Object schemaObject) throws SerializationException; } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java index 6f6e578fb99e..10e6eab6a81b 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java @@ -1,12 +1,13 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; import java.io.ByteArrayOutputStream; +/** + * An interface defining operations required for registry serializer to convert object to bytes. + */ public interface ByteEncoder extends Codec { /** * Return schema name for storing in registry store @@ -14,25 +15,27 @@ public interface ByteEncoder extends Codec { * Refer to Schema Registry documentation for information on schema grouping and naming. * * @return schema name - * @throws SerializationException + * @throws SerializationException runtime exception in error cases */ - public String getSchemaName(Object object) throws SerializationException; + String getSchemaName(Object object) throws SerializationException; /** * Returns string representation of schema object to be stored in the service. * * @param object Schema object used to generate schema string * @return String representation of schema object parameter - * @throws SerializationException + * @throws SerializationException if generating string representation of schema fails */ - public String getSchemaString(Object object) throws SerializationException; + String getSchemaString(Object object) throws SerializationException; /** * Converts object into stream containing the encoded representation of the object. * @param object Object to be encoded into byte stream + * @return output stream containing byte representation of object + * @throws SerializationException if generating byte representation of object fails * * TODO: Method does not currently require schema object to be passed since schemas can be derived from * Avro objects. JSON implementation would be the same. */ - public ByteArrayOutputStream encode(Object object) throws SerializationException; + ByteArrayOutputStream encode(Object object) throws SerializationException; } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/Codec.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/Codec.java index 0a7c627fd613..5e13b747659e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/Codec.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/Codec.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; @@ -15,12 +13,12 @@ public interface Codec { * Utilized by schema registry store and client as non-case-sensitive tags for * schemas of specific serialization format. */ - public String serializationFormat(); + String serializationFormat(); /** * Parses string representation of schema into schema Object * @param schemaString string representation of schema * @return schema object to be used for decoding payloads */ - public Object parseSchemaString(String schemaString); + Object parseSchemaString(String schemaString); } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/SerializationException.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/SerializationException.java index a456264c18a6..6ca1c8d69e6e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/SerializationException.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/SerializationException.java @@ -1,18 +1,23 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; /** - * Exception thrown by Schema Registry client deserializer implementations for runtime error cases. + * Exception thrown by Schema Registry serializer/deserializer implementations for runtime error cases. */ -public class SerializationException extends Exception { +public class SerializationException extends RuntimeException { + /** + * @param s error message explaining serde operation failure + */ public SerializationException(String s) { super(s); } + /** + * @param s error message explaining serde operation failure + * @param cause Throwable cause of serialization failure + */ public SerializationException(String s, Throwable cause) { super(s, cause); } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/package-info.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/package-info.java new file mode 100644 index 000000000000..5e674e17640f --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/package-info.java @@ -0,0 +1,4 @@ +/** + * Package containing core serialization and deserialization implementations for Azure Schema Registry SDK. + */ +package com.azure.schemaregistry; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java index 845bb157bee7..4b2c25e7c275 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; @@ -23,11 +21,11 @@ import static org.junit.jupiter.api.Assertions.*; public class AbstractDataDeserializerTest { - private static final String MOCK_GUID = new String(new char[AbstractDataSerDe.idSize]).replace("\0", "a"); + private static final String MOCK_GUID = new String(new char[AbstractDataSerDe.SCHEMA_ID_SIZE]).replace("\0", "a"); private static final String MOCK_AVRO_SCHEMA_STRING = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; private final EncoderFactory encoderFactory = EncoderFactory.get(); - private final Schema MOCK_AVRO_SCHEMA = (new Schema.Parser()).parse(MOCK_AVRO_SCHEMA_STRING); + private static final Schema MOCK_AVRO_SCHEMA = (new Schema.Parser()).parse(MOCK_AVRO_SCHEMA_STRING); @Test public void testLoadDecoder() throws IOException, SchemaRegistryClientException, SerializationException { @@ -38,16 +36,16 @@ public void testLoadDecoder() throws IOException, SchemaRegistryClientException, SchemaRegistryObject registered = new SchemaRegistryObject(MOCK_GUID, decoder.serializationFormat(), MOCK_AVRO_SCHEMA_STRING.getBytes(), - s -> decoder.parseSchemaString(s)); + decoder::parseSchemaString); assertTrue(registered.deserialize() != null); MockSchemaRegistryClient mockRegistryClient = new MockSchemaRegistryClient(); - mockRegistryClient.guidCache.put(MOCK_GUID, registered); + mockRegistryClient.getGuidCache().put(MOCK_GUID, registered); TestDummyDeserializer deserializer = new TestDummyDeserializer(mockRegistryClient); // contains byte decoder - assertEquals(MOCK_GUID, deserializer.schemaRegistryClient.getSchemaByGuid(MOCK_GUID).schemaId); - assertEquals(decoder.constantPayload, deserializer.deserialize(getPayload())); + assertEquals(MOCK_GUID, deserializer.schemaRegistryClient.getSchemaByGuid(MOCK_GUID).getSchemaId()); + assertEquals(SampleByteDecoder.CONSTANT_PAYLOAD, deserializer.deserialize(getPayload())); } @Test @@ -82,7 +80,7 @@ public void testIfRegistryClientNullOnBuildThrow() { private byte[] getPayload() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); - out.write(ByteBuffer.allocate(AbstractDataSerDe.idSize) + out.write(ByteBuffer.allocate(AbstractDataSerDe.SCHEMA_ID_SIZE) .put(MOCK_GUID.getBytes(Charset.forName("UTF-8"))) .array()); GenericRecord record = getAvroRecord(); diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java index 71625d5e40a2..7166624fc616 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; @@ -11,48 +9,44 @@ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.util.Arrays; -import java.util.Random; import static org.junit.jupiter.api.Assertions.*; public class AbstractDataSerializerTest { + private static final String MOCK_GUID = new String(new char[AbstractDataSerDe.SCHEMA_ID_SIZE]).replace("\0", "a"); @Test public void testRegistryGuidPrefixedToPayload() { - Random rnd = new Random(); - String MOCK_GUID = ""; - for (int i = 0; i < AbstractDataSerDe.idSize; i++) { - MOCK_GUID += (char)(rnd.nextInt(26) + 'a'); - } - // manually add SchemaRegistryObject into mock registry client cache SampleByteEncoder encoder = new SampleByteEncoder(); SchemaRegistryObject registered = new SchemaRegistryObject(MOCK_GUID, - encoder.serializationFormat(), - encoder.getSchemaString(null).getBytes(), // always returns same schema string - s -> encoder.parseSchemaString(s)); + encoder.serializationFormat(), + encoder.getSchemaString(null).getBytes(), // always returns same schema string + encoder::parseSchemaString); assertEquals(encoder.getSchemaString(null), registered.deserialize()); MockSchemaRegistryClient mockRegistryClient = new MockSchemaRegistryClient(); - mockRegistryClient.schemaStringCache.put(encoder.getSchemaString(null), registered); + mockRegistryClient.getSchemaStringCache().put(encoder.getSchemaString(null), registered); - TestDummySerializer serializer = new TestDummySerializer(mockRegistryClient, true, false); + TestDummySerializer serializer = new TestDummySerializer( + mockRegistryClient, true, false); try { byte[] payload = serializer.serializeImpl(1); ByteBuffer buffer = ByteBuffer.wrap(payload); - byte[] schemaGuidByteArray = new byte[AbstractDataSerDe.idSize]; + byte[] schemaGuidByteArray = new byte[AbstractDataSerDe.SCHEMA_ID_SIZE]; try { buffer.get(schemaGuidByteArray); } catch (BufferUnderflowException e) { throw new SerializationException("Payload too short, no readable guid.", e); } - assertEquals(MOCK_GUID, new String(schemaGuidByteArray)); // guid should match preloaded SchemaRegistryObject guid + // guid should match preloaded SchemaRegistryObject guid + assertEquals(MOCK_GUID, new String(schemaGuidByteArray)); int start = buffer.position() + buffer.arrayOffset(); - int length = buffer.limit() - AbstractDataSerDe.idSize; + int length = buffer.limit() - AbstractDataSerDe.SCHEMA_ID_SIZE; byte[] encodedBytes = Arrays.copyOfRange(buffer.array(), start, start + length); assertTrue(Arrays.equals(encoder.encode(null).toByteArray(), encodedBytes)); } catch (SerializationException e) { @@ -79,19 +73,21 @@ public void testNullPayloadThrowsSerializationException() { @Test public void testSerializeWithNullByteEncoderThrows() { // don't set byte encoder on constructor - TestDummySerializer serializer = new TestDummySerializer(new MockSchemaRegistryClient(), false, false); + TestDummySerializer serializer = new TestDummySerializer( + new MockSchemaRegistryClient(), false, false); try { serializer.serializeImpl(1); } catch (SerializationException e) { - assert(true); + assert (true); } } @Test public void testIfRegistryNullThenThrow() { try { - TestDummySerializer serializer = new TestDummySerializer(null, true, false); + TestDummySerializer serializer = new TestDummySerializer( + null, true, false); fail("Building serializer instance with null registry client failed to throw"); } catch (IllegalArgumentException e) { assertTrue(true); diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java index 25277039b0dc..426c6dad5613 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; @@ -9,18 +7,17 @@ import com.azure.schemaregistry.client.SchemaRegistryClientException; import com.azure.schemaregistry.client.SchemaRegistryObject; -import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.function.Function; public class MockSchemaRegistryClient implements SchemaRegistryClient { - - public final HashMap> typeParserDictionary; - - public final HashMap guidCache; - public final HashMap schemaStringCache; + private final HashMap> typeParserDictionary; + private final HashMap guidCache; + private final HashMap schemaStringCache; public MockSchemaRegistryClient() { this.guidCache = new HashMap(); @@ -28,11 +25,16 @@ public MockSchemaRegistryClient() { this.typeParserDictionary = new HashMap>(); } - public void loadSchemaParser(String serializationFormat, Function f) {} + @Override + public Charset getEncoding() { + return StandardCharsets.UTF_8; + } + + public void loadSchemaParser(String serializationFormat, Function f) { } @Override public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) - throws IOException, SchemaRegistryClientException { + throws SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { return schemaStringCache.get(schemaString); } @@ -42,7 +44,7 @@ public SchemaRegistryObject register(String schemaGroup, String schemaName, Stri @Override public SchemaRegistryObject getSchemaByGuid(String schemaGuid) - throws IOException, SchemaRegistryClientException { + throws SchemaRegistryClientException { if (guidCache.containsKey(schemaGuid)) { return guidCache.get(schemaGuid); } @@ -51,9 +53,9 @@ public SchemaRegistryObject getSchemaByGuid(String schemaGuid) @Override public String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType) - throws IOException, SchemaRegistryClientException { + throws SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { - return schemaStringCache.get(schemaString).schemaId; + return schemaStringCache.get(schemaString).getSchemaId(); } return null; @@ -61,19 +63,31 @@ public String getSchemaId(String schemaGroup, String schemaName, String schemaSt @Override public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) - throws IOException, SchemaRegistryClientException { + throws SchemaRegistryClientException { return null; } @Override public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) - throws IOException, SchemaRegistryClientException { + throws SchemaRegistryClientException { return null; } @Override public List deleteSchema(String schemaGroup, String schemaName) - throws IOException, SchemaRegistryClientException { + throws SchemaRegistryClientException { return new ArrayList(); } + + public HashMap> getTypeParserDictionary() { + return typeParserDictionary; + } + + public HashMap getGuidCache() { + return guidCache; + } + + public HashMap getSchemaStringCache() { + return schemaStringCache; + } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java index 9e2ce7f333cc..a7bf175749c1 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java @@ -1,25 +1,23 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; import org.apache.avro.Schema; public class SampleByteDecoder implements ByteDecoder { - public SampleByteDecoder() {} + public SampleByteDecoder() { } @Override public String serializationFormat() { return "sample"; } - public static final String constantPayload = "sample payload!"; + public static final String CONSTANT_PAYLOAD = "sample payload!"; @Override public Object decodeBytes(byte[] bytes, Object o) throws SerializationException { - return constantPayload; + return CONSTANT_PAYLOAD; } @Override diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java index 6469c3177455..5d7b686fe480 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; @@ -10,7 +8,7 @@ public class SampleByteEncoder implements ByteEncoder { - public SampleByteEncoder() {} + public SampleByteEncoder() { } @Override public String getSchemaName(Object object) throws SerializationException { diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java index 044a63af93de..9c2027e4bcf1 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java index de8a745c48ca..a48cb3ac9f86 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry; From 492a77ed646237e05b9872a9477a3e521e80c4d6 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 17:18:31 -0700 Subject: [PATCH 12/43] checkstyle javadoc --- .../CachedSchemaRegistryClientBuilder.java | 2 +- .../azure-schemaregistry-serde-avro/pom.xml | 4 + .../schemaregistry/avro/AvroByteDecoder.java | 52 +++----- .../schemaregistry/avro/AvroByteEncoder.java | 27 ++-- .../azure/schemaregistry/avro/AvroCodec.java | 12 +- .../schemaregistry/avro/AvroSchemaUtils.java | 120 +++++++++++------- .../SchemaRegistryAvroAsyncDeserializer.java | 94 ++++---------- .../SchemaRegistryAvroAsyncSerializer.java | 63 +++++---- ...emaRegistryAvroAsyncSerializerBuilder.java | 73 ----------- .../avro/SchemaRegistryAvroDeserializer.java | 48 +++++++ ...SchemaRegistryAvroDeserializerBuilder.java | 91 +++++++++++++ .../avro/SchemaRegistryAvroSerializer.java | 52 ++++++++ .../SchemaRegistryAvroSerializerBuilder.java | 113 +++++++++++++++++ .../SchemaRegistryAvroSyncDeserializer.java | 83 ------------ .../SchemaRegistryAvroSyncSerializer.java | 89 ------------- .../schemaregistry/avro/package-info.java | 5 + .../avro/AvroByteDecoderTest.java | 32 ++--- .../avro/AvroByteEncoderTest.java | 32 ++--- .../AbstractDataSerializer.java | 1 + 19 files changed, 494 insertions(+), 499 deletions(-) delete mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializerBuilder.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java delete mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncDeserializer.java delete mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncSerializer.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/package-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index 86c3cca921cd..8eb2f5de998b 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -36,7 +36,7 @@ import java.util.function.Function; /** - * + * Builder implementation for {@link CachedSchemaRegistryClient}. */ @ServiceClientBuilder(serviceClients = CachedSchemaRegistryClient.class) public class CachedSchemaRegistryClientBuilder { diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml index 561426967a6d..09ee3410a3b8 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml @@ -37,6 +37,10 @@ HEAD + + true + + com.azure diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java index 7e8ef3f050d6..2dde25396263 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java @@ -1,10 +1,9 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.avro; +import com.azure.core.util.logging.ClientLogger; import com.azure.schemaregistry.ByteDecoder; import com.azure.schemaregistry.SerializationException; import org.apache.avro.Schema; @@ -12,36 +11,39 @@ import org.apache.avro.io.DatumReader; import org.apache.avro.io.DecoderFactory; import org.apache.avro.specific.SpecificDatumReader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; /** - * ByteDecoder implementation with all Avro-specific functionality required to deserialize byte arrays given Avro schema. + * ByteDecoder implementation with all Avro-specific functionality required to deserialize byte arrays + * given an Avro schema. */ public class AvroByteDecoder extends AvroCodec implements ByteDecoder { - private final Logger log = LoggerFactory.getLogger(getClass()); + private final ClientLogger logger = new ClientLogger(AvroByteDecoder.class); private final DecoderFactory decoderFactory = DecoderFactory.get(); + private final boolean avroSpecificReader; - private AvroByteDecoder(Boolean avroSpecificReader) { + /** + * Instantiates AvroByteDecoder instance + * @param avroSpecificReader flag indicating if attempting to decode as Avro SpecificRecord + */ + public AvroByteDecoder(Boolean avroSpecificReader) { this.avroSpecificReader = avroSpecificReader; } - private final boolean 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 + * @throws SerializationException upon deserialization failure */ public Object decodeBytes(byte[] b, Object object) throws SerializationException { if (!(object instanceof Schema)) { - throw new SerializationException("Attempted to decode with non-Avro schema object in AvroByteDecoder"); + throw logger.logExceptionAsError( + new SerializationException("Attempted to decode with non-Avro schema object in AvroByteDecoder")); } - Schema schema = (Schema)object; + Schema schema = (Schema) object; if (schema.getType().equals(Schema.Type.BYTES)) { return b; @@ -59,16 +61,15 @@ public Object decodeBytes(byte[] b, Object object) throws SerializationException return result; } catch (IOException | RuntimeException e) { // avro deserialization may throw AvroRuntimeException, NullPointerException, etc - throw new SerializationException("Error deserializing Avro message.", e); + throw logger.logExceptionAsError(new SerializationException("Error deserializing Avro message.", e)); } } - /** - * Returns correct reader for decoding payload + * Returns correct reader for decoding payload. * * @param writerSchema Avro schema fetched from schema registry store - * @return + * @return correct Avro DatumReader object given encoder configuration */ private DatumReader getDatumReader(Schema writerSchema) { boolean writerSchemaIsPrimitive = AvroSchemaUtils.getPrimitiveSchemas().values().contains(writerSchema); @@ -79,19 +80,4 @@ private DatumReader getDatumReader(Schema writerSchema) { return new GenericDatumReader<>(writerSchema); } } - - public static class Builder { - private Boolean avroSpecificReader = false; - - public Builder() {} - - public Builder avroSpecificReader(Boolean avroSpecificReader) { - this.avroSpecificReader = avroSpecificReader; - return this; - } - - public AvroByteDecoder build() { - return new AvroByteDecoder(this.avroSpecificReader); - } - } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java index e7099aea2380..20f9cf8566d8 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java @@ -1,10 +1,9 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.avro; +import com.azure.core.util.logging.ClientLogger; import com.azure.schemaregistry.ByteEncoder; import com.azure.schemaregistry.SerializationException; import org.apache.avro.Schema; @@ -14,8 +13,6 @@ import org.apache.avro.io.EncoderFactory; import org.apache.avro.specific.SpecificDatumWriter; import org.apache.avro.specific.SpecificRecord; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -25,14 +22,18 @@ */ public class AvroByteEncoder extends AvroCodec implements ByteEncoder { - private static final Logger log = LoggerFactory.getLogger(AvroByteEncoder.class); + private final ClientLogger logger = new ClientLogger(AvroByteEncoder.class); private final EncoderFactory encoderFactory = EncoderFactory.get(); - private AvroByteEncoder() {} + /** + * Instantiates AvroByteEncoder instance. + */ + public AvroByteEncoder() { } /** * @param object Schema object used to generate schema string * @see AvroSchemaUtils for distinction between primitive and Avro schema generation + * @return string representation of schema */ public String getSchemaString(Object object) { Schema schema = AvroSchemaUtils.getSchema(object); @@ -77,14 +78,8 @@ public ByteArrayOutputStream encode(Object object) throws SerializationException return out; } catch (IOException | RuntimeException e) { // Avro serialization can throw AvroRuntimeException, NullPointerException, ClassCastException, etc - throw new SerializationException("Error serializing Avro message", e); - } - } - - public static class Builder { - public Builder() {} - public AvroByteEncoder build() { - return new AvroByteEncoder(); + throw logger.logExceptionAsError( + new SerializationException("Error serializing Avro message", e)); } } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java index dbfaea5a8651..1ad70cc478b4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java @@ -1,7 +1,5 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.avro; @@ -11,14 +9,14 @@ /** * Base Codec class for Avro encoder and decoder implementations */ -public abstract class AvroCodec implements Codec { +abstract class AvroCodec implements Codec { public String serializationFormat() { - return "Avro"; + return "avro"; } /** * @param schemaString string representation of schema - * @return Avro schema + * @return avro schema */ public Schema parseSchemaString(String schemaString) { return (new Schema.Parser()).parse(schemaString); diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java index 374c611c9832..9449591d1d2e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java @@ -1,10 +1,9 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.avro; +import com.azure.core.util.logging.ClientLogger; import org.apache.avro.Schema; import org.apache.avro.generic.GenericContainer; @@ -12,54 +11,77 @@ import java.util.HashMap; import java.util.Map; -public class AvroSchemaUtils { - private static final Map primitiveSchemas; +/** + * Utility class for Avro schema functionality. + */ +class AvroSchemaUtils { + private static final Map PRIMITIVE_SCHEMAS; - static { - Schema.Parser parser = new Schema.Parser(); - primitiveSchemas = new HashMap<>(); - primitiveSchemas.put("Null", createPrimitiveSchema(parser, "null")); - primitiveSchemas.put("Boolean", createPrimitiveSchema(parser, "boolean")); - primitiveSchemas.put("Integer", createPrimitiveSchema(parser, "int")); - primitiveSchemas.put("Long", createPrimitiveSchema(parser, "long")); - primitiveSchemas.put("Float", createPrimitiveSchema(parser, "float")); - primitiveSchemas.put("Double", createPrimitiveSchema(parser, "double")); - primitiveSchemas.put("String", createPrimitiveSchema(parser, "string")); - primitiveSchemas.put("Bytes", createPrimitiveSchema(parser, "bytes")); - } + static { + Schema.Parser parser = new Schema.Parser(); + PRIMITIVE_SCHEMAS = new HashMap<>(); + PRIMITIVE_SCHEMAS.put("Null", createPrimitiveSchema(parser, "null")); + PRIMITIVE_SCHEMAS.put("Boolean", createPrimitiveSchema(parser, "boolean")); + PRIMITIVE_SCHEMAS.put("Integer", createPrimitiveSchema(parser, "int")); + PRIMITIVE_SCHEMAS.put("Long", createPrimitiveSchema(parser, "long")); + PRIMITIVE_SCHEMAS.put("Float", createPrimitiveSchema(parser, "float")); + PRIMITIVE_SCHEMAS.put("Double", createPrimitiveSchema(parser, "double")); + PRIMITIVE_SCHEMAS.put("String", createPrimitiveSchema(parser, "string")); + PRIMITIVE_SCHEMAS.put("Bytes", createPrimitiveSchema(parser, "bytes")); + } - private static Schema createPrimitiveSchema(Schema.Parser parser, String type) { - String schemaString = String.format("{\"type\" : \"%s\"}", type); - return parser.parse(schemaString); - } + /** + * Generates Avro Schema object for the specified primitive type. + * @param parser Avro schema parser + * @param type primitive schema type + * @return Avro Schema object for corresponding primitive type + */ + private static Schema createPrimitiveSchema(Schema.Parser parser, String type) { + String schemaString = String.format("{\"type\" : \"%s\"}", type); + return parser.parse(schemaString); + } - public static Map getPrimitiveSchemas() { - return Collections.unmodifiableMap(primitiveSchemas); - } + /** + * Maintains map of primitive schemas. + * @return Map containing string representation of primitive type to corresponding Avro primitive schema + */ + public static Map getPrimitiveSchemas() { + return Collections.unmodifiableMap(PRIMITIVE_SCHEMAS); + } - public static Schema getSchema(Object object) { - if (object == null) { - return primitiveSchemas.get("Null"); - } else if (object instanceof Boolean) { - return primitiveSchemas.get("Boolean"); - } else if (object instanceof Integer) { - return primitiveSchemas.get("Integer"); - } else if (object instanceof Long) { - return primitiveSchemas.get("Long"); - } else if (object instanceof Float) { - return primitiveSchemas.get("Float"); - } else if (object instanceof Double) { - return primitiveSchemas.get("Double"); - } else if (object instanceof CharSequence) { - return primitiveSchemas.get("String"); - } else if (object instanceof byte[]) { - return primitiveSchemas.get("Bytes"); - } else if (object instanceof GenericContainer) { - return ((GenericContainer) object).getSchema(); - } else { - throw new IllegalArgumentException( - "Unsupported Avro type. Supported types are null, Boolean, Integer, Long, " - + "Float, Double, String, byte[] and IndexedRecord"); + /** + * Returns Avro schema for specified object, including null values + * + * @param object object for which Avro schema is being returned + * @return Avro schema for object's data structure + * + * @throws IllegalArgumentException if object type is unsupported + */ + public static Schema getSchema(Object object) throws IllegalArgumentException { + if (object == null) { + return PRIMITIVE_SCHEMAS.get("Null"); + } else if (object instanceof Boolean) { + return PRIMITIVE_SCHEMAS.get("Boolean"); + } else if (object instanceof Integer) { + return PRIMITIVE_SCHEMAS.get("Integer"); + } else if (object instanceof Long) { + return PRIMITIVE_SCHEMAS.get("Long"); + } else if (object instanceof Float) { + return PRIMITIVE_SCHEMAS.get("Float"); + } else if (object instanceof Double) { + return PRIMITIVE_SCHEMAS.get("Double"); + } else if (object instanceof CharSequence) { + return PRIMITIVE_SCHEMAS.get("String"); + } else if (object instanceof byte[]) { + return PRIMITIVE_SCHEMAS.get("Bytes"); + } else if (object instanceof GenericContainer) { + return ((GenericContainer) object).getSchema(); + } else { + ClientLogger logger = new ClientLogger(AvroSchemaUtils.class); + throw logger.logExceptionAsError( + new IllegalArgumentException( + "Unsupported Avro type. Supported types are null, Boolean, Integer, Long, " + + "Float, Double, String, byte[] and IndexedRecord")); + } } - } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java index 4194d0a49cfe..11e670633d01 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java @@ -1,83 +1,43 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.avro; -import com.azure.schemaregistry.AbstractDataDeserializer; import com.azure.schemaregistry.SerializationException; -import com.azure.schemaregistry.client.CachedSchemaRegistryClient; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Scheduler; +import reactor.core.scheduler.Schedulers; + +import java.util.concurrent.Executors; /** - * A deserializer implementation capable of automatedly deserializing encoded byte array payloads into Java objects by - * fetching payload-specified schemas from the Azure Schema Registry store. - * - * SchemaRegistryAvroSyncDeserializer instances should be built using the static Builder class. - * - * Pluggable with the core Azure SDK Deserializer interface. - * - * @see AbstractDataDeserializer See AbstractDataDeserializer for internal deserialization implementation - * @see SchemaRegistryAvroAsyncDeserializer.Builder See Builder for documentation on builder parameters + * Asynchronous registry-based deserializer implementation. */ -public class SchemaRegistryAvroAsyncDeserializer extends AbstractDataDeserializer { - private SchemaRegistryAvroAsyncDeserializer(Builder builder) { - super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) - .credential() - .maxSchemaMapSize(builder.maxSchemaMapSize) - .build()); +public class SchemaRegistryAvroAsyncDeserializer { + private static final int DEFAULT_THREAD_POOL_SIZE = 8; - loadByteDecoder(new AvroByteDecoder.Builder() - .avroSpecificReader(builder.avroSpecificReader) - .build()); - } + private final SchemaRegistryAvroDeserializer deserializer; + private final Scheduler scheduler; /** - * Deserializes byte array into Java object using payload-specified schema. - * - * @param data Byte array containing serialized bytes - * @return Java object. + * Instantiates instance of async deserializer. * - * Object type is testable with instanceof operator. Return value can be casted in the caller layer. - * - * @throws SerializationException Throws on deserialization failure. - * Exception may contain inner exceptions detailing failure condition. + * @param deserializer synchronous internal deserializer implementation */ - public Object deserializeSync(byte[] data) throws SerializationException { - return super.deserialize(data); - + SchemaRegistryAvroAsyncDeserializer(SchemaRegistryAvroDeserializer deserializer) { + this.deserializer = deserializer; + this.scheduler = Schedulers.fromExecutor(Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE)); } - public static class Builder { - private final String registryUrl; - private int maxSchemaMapSize; - private String credential; - private boolean avroSpecificReader; - - public Builder(String registryUrl) { - this.registryUrl = registryUrl; - this.credential = null; - this.avroSpecificReader = false; - this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; - } - - public SchemaRegistryAvroAsyncDeserializer build() { - return new SchemaRegistryAvroAsyncDeserializer(this); - } - - public Builder credential(String credential) { - this.credential = credential; - return this; - } - - public Builder avroSpecificReader(boolean avroSpecificReader) { - this.avroSpecificReader = avroSpecificReader; - return this; - } - - public Builder maxSchemaMapSize(int maxSchemaMapSize) { - this.maxSchemaMapSize = maxSchemaMapSize; - return this; - } + /** + * Async wrapper around synchronous deserialization method + * @param data bytes containing schema ID and encoded byte representation of object + * @return Mono wrapper around deserialized object + * @throws SerializationException if deserialization operation fails + */ + public Mono deserializeAsync(byte[] data) throws SerializationException { + return Mono + .fromCallable(() -> this.deserializer.deserializeSync(data)) + .subscribeOn(scheduler); } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java index 84b64311cff7..a9e6458bec9b 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java @@ -1,51 +1,48 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.avro; import com.azure.schemaregistry.AbstractDataSerializer; import com.azure.schemaregistry.SerializationException; -import com.azure.schemaregistry.client.CachedSchemaRegistryClient; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Scheduler; +import reactor.core.scheduler.Schedulers; + +import java.util.concurrent.Executors; /** - * A serializer implementation capable of serializing objects and automatedly storing serialization schemas - * in the Azure Schema Registry store. - * - * SchemaRegistryAvroSyncSerializer instances should be built using the static Builder class. - * - * Pluggable with the core Azure SDK Serializer interface. - * - * @see AbstractDataSerializer See AbstractDataSerializer for internal serialization implementation - * @see SchemaRegistryAvroAsyncSerializer.Builder See Builder for documentation on required parameters + * Asynchronous registry-based serializer implementation. */ public class SchemaRegistryAvroAsyncSerializer extends AbstractDataSerializer { - private SchemaRegistryAvroAsyncSerializer(Builder builder) { - super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) - .maxSchemaMapSize(builder.maxSchemaMapSize) - .build()); - - setByteEncoder(new AvroByteEncoder.Builder().build()); - this.serializationFormat = this.byteEncoder.serializationFormat(); - this.autoRegisterSchemas = builder.autoRegisterSchemas; - this.schemaGroup = builder.schemaGroup; + private static final int DEFAULT_THREAD_POOL_SIZE = 8; + + private final SchemaRegistryAvroSerializer serializer; + private final Scheduler scheduler; + + /** + * @param serializer synchronous Avro serializer implementation + */ + SchemaRegistryAvroAsyncSerializer(SchemaRegistryAvroSerializer serializer) { + this.serializer = serializer; + this.scheduler = Schedulers.fromExecutor(Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE)); } /** - * Serializes object into byte array payload using the configured byte encoder. - * @param object target of serialization - * @return byte array containing GUID reference to schema, then the object serialized into bytes - * @throws SerializationException Throws on serialization failure. - * Exception may contain inner exceptions detailing failure condition. + * Async wrapper around sync serialization operation + * + * @param object object to be serialized to bytes + * @return Avro byte representation of object + * @throws SerializationException upon serialization operation failure */ - public byte[] serializeSync(Object object) throws SerializationException { + public Mono serializeAsync(Object object) throws SerializationException { if (object == null) { - return null; + return Mono.empty(); } - return serializeImpl(object); - } - + return Mono + .fromCallable(() -> this.serializer.serializeSync(object)) + .subscribeOn(scheduler); + } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializerBuilder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializerBuilder.java deleted file mode 100644 index 95d2600d6410..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializerBuilder.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.azure.schemaregistry.avro; - -import com.azure.schemaregistry.AbstractDataSerializer; -import com.azure.schemaregistry.ByteEncoder; -import com.azure.schemaregistry.client.CachedSchemaRegistryClient; - -public final class SchemaRegistryAvroAsyncSerializerBuilder { - private final String registryUrl; - private String credential; - private boolean autoRegisterSchemas; - private String schemaGroup; - private int maxSchemaMapSize; - protected ByteEncoder byteEncoder = null; - - private SchemaRegistryAvroAsyncSerializerBuilder(String registryUrl) { - this.registryUrl = registryUrl; - this.credential = null; - this.autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; - this.schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; - this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; - } - - public static SchemaRegistryAvroAsyncSerializerBuilder aSchemaRegistryAvroAsyncSerializer() { - return new SchemaRegistryAvroAsyncSerializerBuilder(); - } - - public SchemaRegistryAvroAsyncSerializerBuilder byteEncoder(ByteEncoder byteEncoder) { - this.byteEncoder = byteEncoder; - return this; - } - - public SchemaRegistryAvroAsyncSerializer build() { - SchemaRegistryAvroAsyncSerializer schemaRegistryAvroAsyncSerializer = new SchemaRegistryAvroAsyncSerializer(null); - schemaRegistryAvroAsyncSerializer.setByteEncoder(byteEncoder); - return schemaRegistryAvroAsyncSerializer; - } - - public static class Builder { - private final String registryUrl; - private boolean autoRegisterSchemas; - private String credential; - private int maxSchemaMapSize; - private String schemaGroup; - - public Builder(String registryUrl) { - - } - - public SchemaRegistryAvroAsyncSerializer build() { - return new SchemaRegistryAvroAsyncSerializer(this); - } - - public Builder schemaGroup(String schemaGroup) { - this.schemaGroup = schemaGroup; - return this; - } - - public Builder credential(String credential) { - this.credential = credential; - return this; - } - - public Builder autoRegisterSchema(boolean autoRegisterSchemas) { - this.autoRegisterSchemas = autoRegisterSchemas; - return this; - } - - public Builder maxSchemaMapSize(int maxSchemaMapSize) { - this.maxSchemaMapSize = maxSchemaMapSize; - return this; - } - } -} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java new file mode 100644 index 000000000000..c4b117af0ce3 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.schemaregistry.avro; + +import com.azure.core.credential.TokenCredential; +import com.azure.schemaregistry.AbstractDataDeserializer; +import com.azure.schemaregistry.SerializationException; +import com.azure.schemaregistry.client.CachedSchemaRegistryClientBuilder; + +/** + * A deserializer implementation capable of automatedly deserializing encoded byte array payloads into Java objects by + * fetching payload-specified schemas from the Azure Schema Registry store. + * + * SchemaRegistryAvroDeserializer instances should be built using the static Builder class. + * + * Pluggable with the core Azure SDK Deserializer interface. + * + * @see AbstractDataDeserializer See AbstractDataDeserializer for internal deserialization implementation + */ +public class SchemaRegistryAvroDeserializer extends AbstractDataDeserializer { + SchemaRegistryAvroDeserializer(String registryUrl, + TokenCredential credential, + boolean avroSpecificReader, + int maxSchemaMapSize) { + super(new CachedSchemaRegistryClientBuilder(registryUrl) + .credential(credential) + .maxSchemaMapSize(maxSchemaMapSize) + .buildClient()); + + loadByteDecoder(new AvroByteDecoder(avroSpecificReader)); + } + + /** + * Deserializes byte array into Java object using payload-specified schema. + * + * @param data Byte array containing serialized bytes + * @return Java object. + * + * Object type is testable with instanceof operator. Return value can be casted in the caller layer. + * + * @throws SerializationException Throws on deserialization failure. + * Exception may contain inner exceptions detailing failure condition. + */ + public Object deserializeSync(byte[] data) throws SerializationException { + return super.deserialize(data); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java new file mode 100644 index 000000000000..bcce9ba0cd6e --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java @@ -0,0 +1,91 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.schemaregistry.avro; + +import com.azure.core.credential.TokenCredential; +import com.azure.schemaregistry.client.CachedSchemaRegistryClient; + +/** + * Builder class for constructing {@link SchemaRegistryAvroDeserializer} and {@link SchemaRegistryAvroAsyncDeserializer} + */ +public class SchemaRegistryAvroDeserializerBuilder { + + private final String registryUrl; + private TokenCredential credential; + private boolean avroSpecificReader; + private int maxSchemaMapSize; + + /** + * Instantiates instance of Builder class. + * Supplies client defaults. + * + * @param registryUrl base schema registry URL for storing and fetching schemas + */ + public SchemaRegistryAvroDeserializerBuilder(String registryUrl) { + this.registryUrl = registryUrl; + this.credential = null; + this.avroSpecificReader = false; + this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + } + + /** + * + * @param credential TokenCredential to be used for authenticating with Azure Schema Registry Service + * @return updated {@link SchemaRegistryAvroDeserializerBuilder} instance + */ + public SchemaRegistryAvroDeserializerBuilder credential(TokenCredential credential) { + this.credential = credential; + return this; + } + + /** + * Specifies if objects should be deserialized into Avro SpecificRecords via Avro SpecificDatumReader + * @param avroSpecificReader specific reader flag + * @return updated {@link SchemaRegistryAvroDeserializerBuilder} instance + */ + public SchemaRegistryAvroDeserializerBuilder avroSpecificReader(boolean avroSpecificReader) { + this.avroSpecificReader = avroSpecificReader; + return this; + } + + /** + * Specifies maximum schema object cache size for underlying CachedSchemaRegistryClient. If specified cache + * size is exceeded, all caches are recycled. + * + * @param maxSchemaMapSize maximum number of schemas per cache + * @return updated {@link SchemaRegistryAvroDeserializerBuilder} instance + */ + public SchemaRegistryAvroDeserializerBuilder maxSchemaMapSize(int maxSchemaMapSize) { + this.maxSchemaMapSize = maxSchemaMapSize; + return this; + } + + /** + * Construct instance of {@link SchemaRegistryAvroAsyncDeserializer} + * + * @return {@link SchemaRegistryAvroAsyncDeserializer} instance + * + * @throws NullPointerException if parameters are incorrectly set. + * @throws IllegalArgumentException if credential is not set. + */ + public SchemaRegistryAvroAsyncDeserializer buildAsyncClient() { + return new SchemaRegistryAvroAsyncDeserializer(this.buildSyncClient()); + } + + /** + * Construct instance of {@link SchemaRegistryAvroDeserializer} + * + * @return {@link SchemaRegistryAvroDeserializer} instance + * + * @throws NullPointerException if parameters are incorrectly set. + * @throws IllegalArgumentException if credential is not set. + */ + public SchemaRegistryAvroDeserializer buildSyncClient() { + return new SchemaRegistryAvroDeserializer( + this.registryUrl, + this.credential, + this.avroSpecificReader, + this.maxSchemaMapSize); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java new file mode 100644 index 000000000000..abcd81c3b557 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.schemaregistry.avro; + +import com.azure.core.credential.TokenCredential; +import com.azure.schemaregistry.AbstractDataSerializer; +import com.azure.schemaregistry.SerializationException; +import com.azure.schemaregistry.client.CachedSchemaRegistryClientBuilder; + +/** + * A serializer implementation capable of serializing objects and automatedly storing serialization schemas + * in the Azure Schema Registry store. + * + * SchemaRegistryAvroSerializer instances should be built using the static Builder class. + * + * Pluggable with the core Azure SDK Serializer interface. + * + * @see AbstractDataSerializer See AbstractDataSerializer for internal serialization implementation + */ +public class SchemaRegistryAvroSerializer extends AbstractDataSerializer { + SchemaRegistryAvroSerializer(String registryUrl, + TokenCredential credential, + String schemaGroup, + boolean autoRegisterSchemas, + int maxSchemaMapSize) { + super(new CachedSchemaRegistryClientBuilder(registryUrl) + .credential(credential) + .maxSchemaMapSize(maxSchemaMapSize) + .buildClient()); + + setByteEncoder(new AvroByteEncoder()); + + this.autoRegisterSchemas = autoRegisterSchemas; + this.schemaGroup = schemaGroup; + } + + /** + * Serializes object into byte array payload using the configured byte encoder. + * @param object target of serialization + * @return byte array containing GUID reference to schema, then the object serialized into bytes + * @throws SerializationException Throws on serialization failure. + * Exception may contain inner exceptions detailing failure condition. + */ + public byte[] serializeSync(Object object) throws SerializationException { + if (object == null) { + return null; + } + return serializeImpl(object); + } +} + diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java new file mode 100644 index 000000000000..746b1ca3322c --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.schemaregistry.avro; + +import com.azure.core.credential.TokenCredential; +import com.azure.schemaregistry.AbstractDataSerializer; +import com.azure.schemaregistry.client.CachedSchemaRegistryClient; + +/** + * Builder implemenation for building {@link SchemaRegistryAvroSerializer} and {@link SchemaRegistryAvroAsyncSerializer} + */ +public final class SchemaRegistryAvroSerializerBuilder { + private final String registryUrl; + private TokenCredential credential; + private boolean autoRegisterSchemas; + private String schemaGroup; + private int maxSchemaMapSize; + + /** + * Instantiates instance of Builder class. + * Supplies client defaults. + * + * @param registryUrl base schema registry URL for storing and fetching schemas + */ + private SchemaRegistryAvroSerializerBuilder(String registryUrl) { + this.registryUrl = registryUrl; + this.credential = null; + this.autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; + this.schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; + this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + } + + /** + * Specifies schema group for interacting with Azure Schema Registry service. + * + * If auto-registering schemas, schema will be stored under this group. + * If not auto-registering, serializer will request schema ID for matching data schema under specified group. + * + * @param schemaGroup Azure Schema Registry schema group + * @return updated {@link SchemaRegistryAvroSerializerBuilder} instance + */ + public SchemaRegistryAvroSerializerBuilder schemaGroup(String schemaGroup) { + this.schemaGroup = schemaGroup; + return this; + } + + /** + * Specifies authentication behavior with Azure Schema Registry + * @param credential TokenCredential to be used to authenticate with Azure Schema Registry service + * @return updated {@link SchemaRegistryAvroSerializerBuilder} instance + */ + public SchemaRegistryAvroSerializerBuilder credential(TokenCredential credential) { + this.credential = credential; + return this; + } + + /** + * If specified true, serializer will register schemas against Azure Schema Registry service under the specified + * group. See Azure Schema Registry documentation for a description of schema registration behavior. + * + * If specified false, serializer will simply query the service for an existing ID given schema content. + * Serialization will fail if the schema has not been pre-created. + * + * Auto-registration is **NOT RECOMMENDED** for production scenarios. + * + * @param autoRegisterSchemas flag for schema auto-registration + * @return updated {@link SchemaRegistryAvroSerializerBuilder} instance + */ + public SchemaRegistryAvroSerializerBuilder autoRegisterSchema(boolean autoRegisterSchemas) { + this.autoRegisterSchemas = autoRegisterSchemas; + return this; + } + + /** + * Specifies maximum schema object cache size for underlying CachedSchemaRegistryClient. If specified cache + * size is exceeded, all caches are recycled. + * + * @param maxSchemaMapSize maximum number of schemas per cache + * @return updated {@link SchemaRegistryAvroSerializerBuilder} instance + */ + public SchemaRegistryAvroSerializerBuilder maxSchemaMapSize(int maxSchemaMapSize) { + this.maxSchemaMapSize = maxSchemaMapSize; + return this; + } + + /** + * Instantiates SchemaRegistry + * @return {@link SchemaRegistryAvroAsyncSerializer} instance + * + * @throws NullPointerException if parameters are incorrectly set. + * @throws IllegalArgumentException if credential is not set. + */ + public SchemaRegistryAvroAsyncSerializer buildAsyncClient() { + return new SchemaRegistryAvroAsyncSerializer(this.buildSyncClient()); + } + + /** + * Instantiates {@link SchemaRegistryAvroSerializer} + * @return {@link SchemaRegistryAvroSerializer} instance + * + * @throws NullPointerException if parameters are incorrectly set. + * @throws IllegalArgumentException if credential is not set. + */ + public SchemaRegistryAvroSerializer buildSyncClient() { + return new SchemaRegistryAvroSerializer( + this.registryUrl, + this.credential, + this.schemaGroup, + this.autoRegisterSchemas, + this.maxSchemaMapSize); + } +} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncDeserializer.java deleted file mode 100644 index 646acc7a1540..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncDeserializer.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry.avro; - -import com.azure.schemaregistry.AbstractDataDeserializer; -import com.azure.schemaregistry.SerializationException; -import com.azure.schemaregistry.client.CachedSchemaRegistryClient; - -/** - * A deserializer implementation capable of automatedly deserializing encoded byte array payloads into Java objects by - * fetching payload-specified schemas from the Azure Schema Registry store. - * - * SchemaRegistryAvroSyncDeserializer instances should be built using the static Builder class. - * - * Pluggable with the core Azure SDK Deserializer interface. - * - * @see AbstractDataDeserializer See AbstractDataDeserializer for internal deserialization implementation - * @see SchemaRegistryAvroSyncDeserializer.Builder See Builder for documentation on builder parameters - */ -public class SchemaRegistryAvroSyncDeserializer extends AbstractDataDeserializer { - private SchemaRegistryAvroSyncDeserializer(Builder builder) { - super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) - .credential() - .maxSchemaMapSize(builder.maxSchemaMapSize) - .build()); - - loadByteDecoder(new AvroByteDecoder.Builder() - .avroSpecificReader(builder.avroSpecificReader) - .build()); - } - - /** - * Deserializes byte array into Java object using payload-specified schema. - * - * @param data Byte array containing serialized bytes - * @return Java object. - * - * Object type is testable with instanceof operator. Return value can be casted in the caller layer. - * - * @throws SerializationException Throws on deserialization failure. - * Exception may contain inner exceptions detailing failure condition. - */ - public Object deserializeSync(byte[] data) throws SerializationException { - return super.deserialize(data); - - } - - public static class Builder { - private final String registryUrl; - private int maxSchemaMapSize; - private String credential; - private boolean avroSpecificReader; - - public Builder(String registryUrl) { - this.registryUrl = registryUrl; - this.credential = null; - this.avroSpecificReader = false; - this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; - } - - public SchemaRegistryAvroSyncDeserializer build() { - return new SchemaRegistryAvroSyncDeserializer(this); - } - - public Builder credential(String credential) { - this.credential = credential; - return this; - } - - public Builder avroSpecificReader(boolean avroSpecificReader) { - this.avroSpecificReader = avroSpecificReader; - return this; - } - - public Builder maxSchemaMapSize(int maxSchemaMapSize) { - this.maxSchemaMapSize = maxSchemaMapSize; - return this; - } - } -} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncSerializer.java deleted file mode 100644 index a9922d5dd469..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSyncSerializer.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -package com.azure.schemaregistry.avro; - -import com.azure.schemaregistry.AbstractDataSerializer; -import com.azure.schemaregistry.SerializationException; -import com.azure.schemaregistry.client.CachedSchemaRegistryClient; - -/** - * A serializer implementation capable of serializing objects and automatedly storing serialization schemas - * in the Azure Schema Registry store. - * - * SchemaRegistryAvroSyncSerializer instances should be built using the static Builder class. - * - * Pluggable with the core Azure SDK Serializer interface. - * - * @see AbstractDataSerializer See AbstractDataSerializer for internal serialization implementation - * @see SchemaRegistryAvroSyncSerializer.Builder See Builder for documentation on required parameters - */ -public class SchemaRegistryAvroSyncSerializer extends AbstractDataSerializer { - private SchemaRegistryAvroSyncSerializer(Builder builder) { - super(new CachedSchemaRegistryClient.Builder(builder.registryUrl) - .maxSchemaMapSize(builder.maxSchemaMapSize) - .build()); - - setByteEncoder(new AvroByteEncoder.Builder().build()); - this.serializationFormat = this.byteEncoder.serializationFormat(); - this.autoRegisterSchemas = builder.autoRegisterSchemas; - this.schemaGroup = builder.schemaGroup; - } - - /** - * Serializes object into byte array payload using the configured byte encoder. - * @param object target of serialization - * @return byte array containing GUID reference to schema, then the object serialized into bytes - * @throws SerializationException Throws on serialization failure. - * Exception may contain inner exceptions detailing failure condition. - */ - public byte[] serializeSync(Object object) throws SerializationException { - if (object == null) { - return null; - } - return serializeImpl(object); - } - - public static class Builder { - private final String registryUrl; - private boolean autoRegisterSchemas; - private String credential; - private int maxSchemaMapSize; - private String schemaGroup; - - public Builder(String registryUrl) { - this.registryUrl = registryUrl; - this.credential = null; - this.autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; - this.schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; - this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; - } - - public SchemaRegistryAvroSyncSerializer build() { - return new SchemaRegistryAvroSyncSerializer(this); - } - - public Builder schemaGroup(String schemaGroup) { - this.schemaGroup = schemaGroup; - return this; - } - - public Builder credential(String credential) { - this.credential = credential; - return this; - } - - public Builder autoRegisterSchema(boolean autoRegisterSchemas) { - this.autoRegisterSchemas = autoRegisterSchemas; - return this; - } - - public Builder maxSchemaMapSize(int maxSchemaMapSize) { - this.maxSchemaMapSize = maxSchemaMapSize; - return this; - } - } -} - diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/package-info.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/package-info.java new file mode 100644 index 000000000000..190a1761edda --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/package-info.java @@ -0,0 +1,5 @@ +/** + * Package containing Avro-specific serializer and deserializer implementations. + * Also contains the Avro codec utility classes required for all serde operations. + */ +package com.azure.schemaregistry.avro; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java index 7f7fc42db326..19695d87eca5 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java @@ -1,31 +1,15 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.avro; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; -public class AvroByteDecoderTest extends TestCase { - public AvroByteDecoderTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(AvroByteDecoderTest.class); - } - - protected void setUp() { - } - - protected void tearDown() { - } +import static org.junit.jupiter.api.Assertions.assertTrue; - public void testShouldAnswerWithTrue() - { - assertTrue( true ); +public class AvroByteDecoderTest { + @Test + public void testShouldAnswerWithTrue() { + assertTrue(true); } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java index f9f8b5cb9284..7faada8a2ce5 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java @@ -1,38 +1,22 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.schemaregistry.avro; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; -public class AvroByteEncoderTest extends TestCase { - private static final String MOCK_AVRO_SCHEMA_STRING = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; - private static final Character namespaceDelimiter = '/'; - - public AvroByteEncoderTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(AvroByteEncoderTest.class); - } +import static org.junit.jupiter.api.Assertions.assertTrue; - protected void setUp() { - } - - protected void tearDown() { - } +public class AvroByteEncoderTest { + private static final String MOCK_AVRO_SCHEMA_STRING = "{\"namespace\":\"example2.avro\",\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\": [\"int\", \"null\"]}]}"; + @Test public void testPlaceholder() { getEncoder(); assertTrue(true); } private AvroByteEncoder getEncoder() { - return new AvroByteEncoder.Builder().build(); + return new AvroByteEncoder(); } } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java index 70a4240bdff8..8d4a4c237c3c 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java @@ -49,6 +49,7 @@ protected void setByteEncoder(ByteEncoder byteEncoder) { new IllegalArgumentException("Setting multiple encoders on serializer not permitted")); } this.byteEncoder = byteEncoder; + this.serializationFormat = byteEncoder.serializationFormat(); this.schemaRegistryClient.loadSchemaParser(byteEncoder.serializationFormat(), byteEncoder::parseSchemaString); } From 07fcff11aa494af2aaad61c7d67e4d701eb69acc Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 17:18:48 -0700 Subject: [PATCH 13/43] spotbugs override for serializing null value --- .../src/main/resources/spotbugs/spotbugs-exclude.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index d0a77f3a4f04..5873a175f954 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -1897,6 +1897,14 @@ + + + + + + + From 16ec23e54235c372cba9295cb98394f30da15d2a Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 17:33:48 -0700 Subject: [PATCH 14/43] add service client annotation --- .../schemaregistry/client/CachedSchemaRegistryClient.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index 5c7b144cbb40..2bf301ae6577 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -3,6 +3,7 @@ package com.azure.schemaregistry.client; +import com.azure.core.annotation.ServiceClient; import com.azure.core.credential.TokenCredential; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpPipeline; @@ -35,6 +36,9 @@ * @see SchemaRegistryClient Implements SchemaRegistryClient interface to allow for testing with mock * @see CachedSchemaRegistryClientBuilder Follows builder pattern for object instantiation */ +@ServiceClient( + builder = CachedSchemaRegistryClientBuilder.class, + serviceInterfaces = AzureSchemaRegistryRestService.class) public class CachedSchemaRegistryClient implements SchemaRegistryClient { private final ClientLogger logger = new ClientLogger(CachedSchemaRegistryClient.class); From a6b56a8ea6815d7797f6e4f7719aa8308a6b0f9b Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 17:41:53 -0700 Subject: [PATCH 15/43] service client style --- .../client/CachedSchemaRegistryClient.java | 56 ++++++++++--------- .../CachedSchemaRegistryClientBuilder.java | 1 - 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index 2bf301ae6577..eb1da09b8abe 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -4,7 +4,6 @@ package com.azure.schemaregistry.client; import com.azure.core.annotation.ServiceClient; -import com.azure.core.credential.TokenCredential; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpPipeline; import com.azure.core.util.logging.ClientLogger; @@ -23,14 +22,14 @@ /** * HTTP-based client that interacts with Azure Schema Registry service to store and retrieve schemas on demand. - * + *

* Utilizes in-memory HashMap caching to minimize network I/O. - * + *

* Max HashMap size can be configured when instantiating. * Two maps are maintained - * - SchemaRegistryObject cache by GUID - stores GUIDs previously seen in payloads * - SchemaRegistryObject cache by schema string - minimizes HTTP calls when sending payloads of same schema - * + *

* TODO: implement max age for schema maps? or will schemas always be immutable? * * @see SchemaRegistryClient Implements SchemaRegistryClient interface to allow for testing with mock @@ -43,30 +42,35 @@ public class CachedSchemaRegistryClient implements SchemaRegistryClient { private final ClientLogger logger = new ClientLogger(CachedSchemaRegistryClient.class); public static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; - public static final int MAX_SCHEMA_MAP_SIZE_MINIMUM = 10; public static final Charset SCHEMA_REGISTRY_SERVICE_ENCODING = StandardCharsets.UTF_8; + static final int MAX_SCHEMA_MAP_SIZE_MINIMUM = 10; - private final int maxSchemaMapSize; private final AzureSchemaRegistryRestService restService; + private final int maxSchemaMapSize; private final HashMap> typeParserDictionary; - - private HashMap guidCache; - private HashMap schemaStringCache; + private final HashMap guidCache; + private final HashMap schemaStringCache; CachedSchemaRegistryClient( - String registryUrl, - HttpPipeline pipeline, - TokenCredential credential, - int maxSchemaMapSize, - HashMap> typeParserDictionary) { + String registryUrl, + HttpPipeline pipeline, + int maxSchemaMapSize, + HashMap> typeParserDictionary) { if (registryUrl == null || registryUrl.isEmpty()) { - throw new IllegalArgumentException("Schema Registry URL cannot be null or empty."); + throw logger.logExceptionAsError( + new IllegalArgumentException("Schema Registry URL cannot be null or empty.")); + } + + if (maxSchemaMapSize < MAX_SCHEMA_MAP_SIZE_MINIMUM) { + throw logger.logExceptionAsError( + new IllegalArgumentException( + String.format("Max schema map size must be greater than %d schemas", MAX_SCHEMA_MAP_SIZE_MINIMUM))); } this.restService = new AzureSchemaRegistryRestServiceClientBuilder() - .host(registryUrl) - .pipeline(pipeline) - .buildClient(); + .host(registryUrl) + .pipeline(pipeline) + .buildClient(); this.maxSchemaMapSize = maxSchemaMapSize; this.typeParserDictionary = typeParserDictionary; @@ -98,7 +102,6 @@ public Charset getEncoding() { /** * @param schemaType tag used by schema registry store to identify schema serialization type, e.g. "avro" * @param parseMethod function to parse string into usable schema object - * * @throws IllegalArgumentException on bad schema type or if parser for schema type has already been registered */ public synchronized void loadSchemaParser(String schemaType, Function parseMethod) { @@ -118,7 +121,7 @@ public synchronized void loadSchemaParser(String schemaType, Function deleteSchema(String schemaGroup, String schemaName) - throws SchemaRegistryClientException { + throws SchemaRegistryClientException { // return this.restService.deleteSchema(); // remove from cache return null; @@ -250,18 +253,17 @@ public synchronized void reset() { * Checks if caches should be reinitialized to satisfy initial configuration */ private synchronized void resetIfNeeded() { - // don't call clear, just re-instantiate and let gc collect - // don't clear parser dictionary if (guidCache.size() > this.maxSchemaMapSize) { - guidCache = new HashMap<>(); + guidCache.clear(); } if (schemaStringCache.size() > this.maxSchemaMapSize) { - schemaStringCache = new HashMap<>(); + schemaStringCache.clear(); } } /** * Return stored parse function for parsing schema payloads of specified schema type + * * @param schemaType schema type of payload to be deserialized * @return parse method for deserializing schema string */ diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index 8eb2f5de998b..a4f542822630 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -278,7 +278,6 @@ public CachedSchemaRegistryClient buildClient() { return new CachedSchemaRegistryClient( schemaRegistryUrl, pipeline, - credential, maxSchemaMapSize, typeParserDictionary); } From 309b0bb4ef849caa33c85527eb138e4a9487517e Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 19:06:29 -0700 Subject: [PATCH 16/43] fix dep management tags --- eng/versioning/external_dependencies.txt | 1 - .../azure-schemaregistry-client/pom.xml | 9 +++--- .../azure-schemaregistry-serde-avro/pom.xml | 9 +++--- .../azure-schemaregistry-serde-common/pom.xml | 30 +++++++++++++++---- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/eng/versioning/external_dependencies.txt b/eng/versioning/external_dependencies.txt index c1320a4f1370..89cfbd7f7aad 100644 --- a/eng/versioning/external_dependencies.txt +++ b/eng/versioning/external_dependencies.txt @@ -122,7 +122,6 @@ org.openjdk.jmh:jmh-generator-annprocess;1.22 org.spockframework:spock-core;1.3-groovy-2.5 org.testng:testng;6.14.3 uk.org.lidalia:slf4j-test;1.2.0 -org.apache.avro:avro;1.9.2 ## Maven Tools versions com.azure:sdk-build-tools;1.0.0 diff --git a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml index 3f34a214af52..018be97b4920 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml @@ -14,9 +14,10 @@ ../../parents/azure-client-sdk-parent + com.azure azure-schemaregistry-client jar - 1.0.0-beta.1 + 1.0.0-beta.1 Microsoft Azure Schema Registry - REST Client REST client implementation for Azure Schema Registry @@ -53,19 +54,19 @@ org.junit.jupiter junit-jupiter-api - 5.4.2 + 5.6.2 test org.junit.jupiter junit-jupiter-engine - 5.4.2 + 5.6.2 test org.junit.jupiter junit-jupiter-params - 5.4.2 + 5.6.2 test diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml index 09ee3410a3b8..c917d04898c5 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml @@ -18,7 +18,7 @@ com.azure azure-schemaregistry-serde-avro - 1.0.0-beta.1 + 1.0.0-beta.1 Microsoft Azure Schema Registry - Avro-specific package for client library Avro-specific package for Azure Schema Registry client library @@ -55,24 +55,23 @@ compile - org.junit.jupiter junit-jupiter-api - 5.4.2 + 5.6.2 test org.junit.jupiter junit-jupiter-engine - 5.4.2 + 5.6.2 test org.junit.jupiter junit-jupiter-params - 5.4.2 + 5.6.2 test diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml index 6cc8028bee45..41fb1fc5c221 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml @@ -14,9 +14,10 @@ ../../parents/azure-client-sdk-parent + com.azure azure-schemaregistry-serde-common jar - 1.0.0-beta.1 + 1.0.0-beta.1 Microsoft Azure Schema Registry - Common SerDe Package for client library Common SerDe Package containing base serialization/deserialization implementation for Azure Schema Registry client library @@ -48,26 +49,26 @@ com.azure azure-schemaregistry-client - 1.0.0-beta.1 + 1.0.0-beta.1 org.junit.jupiter junit-jupiter-api - 5.4.2 + 5.6.2 test org.junit.jupiter junit-jupiter-engine - 5.4.2 + 5.6.2 test org.junit.jupiter junit-jupiter-params - 5.4.2 + 5.6.2 test @@ -77,4 +78,23 @@ test + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + + com.azure:* + + + + + + + From 51db740b3fdc1a7be446361a547ed187b2fcdc0e Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 22:00:19 -0700 Subject: [PATCH 17/43] add module-info and initial readme --- .../azure-schemaregistry-client/README.md | 0 .../src/main/module-info.java | 14 ++++++++++++++ .../azure-schemaregistry-serde-avro/README.md | 0 .../src/main/module-info.java | 8 ++++++++ .../azure-schemaregistry-serde-common/README.md | 0 .../src/main/module-info.java | 10 ++++++++++ 6 files changed, 32 insertions(+) create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/README.md create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-common/README.md create mode 100644 sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/README.md b/sdk/schemaregistry/azure-schemaregistry-client/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java new file mode 100644 index 000000000000..7feee6499759 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +module com.azure.schemaregistry.client { + requires transitive com.azure.core; + + exports com.azure.schemaregistry.client; + exports com.azure.schemaregistry.client.rest; + exports com.azure.schemaregistry.client.rest.models; + + opens com.azure.schemaregistry.client to com.fasterxml.jackson.databind; + opens com.azure.schemaregistry.client.rest to com.fasterxml.jackson.databind, com.azure.core; + opens com.azure.schemaregistry.client.models to com.fasterxml.jackson.databind, com.azure.core; +} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md b/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java new file mode 100644 index 000000000000..47ca5f0e40a7 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +module com.azure.schemaregistry.serde.avro { + requires transitive com.azure.core; + + exports com.azure.schemaregistry.serde.avro; +} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md b/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java new file mode 100644 index 000000000000..061031d4d0b0 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +module com.azure.schemaregistry.serde.common { + requires com.azure.core; + + exports com.azure.schemaregistry; + + opens com.azure.schemaregistry to com.fasterxml.jackson.databind, com.azure.core; +} From 7492f737a61d0151097267692e9e7aeee62b4ab9 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 22:36:45 -0700 Subject: [PATCH 18/43] add readme sections --- .../azure-schemaregistry-client/README.md | 13 +++++++++++++ .../azure-schemaregistry-serde-avro/README.md | 13 +++++++++++++ .../azure-schemaregistry-serde-common/README.md | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/README.md b/sdk/schemaregistry/azure-schemaregistry-client/README.md index e69de29bb2d1..a9c5e9ccc9fa 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/README.md +++ b/sdk/schemaregistry/azure-schemaregistry-client/README.md @@ -0,0 +1,13 @@ +# Azure Schema Registry client library for Java + +## Getting Started + +## Key Concepts + +## Examples + +## Troubleshooting + +## Next Steps + +## Contributing diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md b/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md index e69de29bb2d1..32bbbfa323f6 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md @@ -0,0 +1,13 @@ +# Azure Schema Registry Avro Serializer/Deserializer client library for Java + +## Getting Started + +## Key Concepts + +## Examples + +## Troubleshooting + +## Next Steps + +## Contributing diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md b/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md index e69de29bb2d1..5fcbbc211ac4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md @@ -0,0 +1,13 @@ +# Azure Schema Registry shared library for Java + +## Getting Started + +## Key Concepts + +## Examples + +## Troubleshooting + +## Next Steps + +## Contributing From c1ac6c6a8cebe93b9ceca251c19d925b3c1fdd5d Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 21 May 2020 22:44:34 -0700 Subject: [PATCH 19/43] fix readme section case --- sdk/schemaregistry/azure-schemaregistry-client/README.md | 6 +++--- .../azure-schemaregistry-serde-avro/README.md | 6 +++--- .../azure-schemaregistry-serde-common/README.md | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/README.md b/sdk/schemaregistry/azure-schemaregistry-client/README.md index a9c5e9ccc9fa..c9c59e6f4c56 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/README.md +++ b/sdk/schemaregistry/azure-schemaregistry-client/README.md @@ -1,13 +1,13 @@ # Azure Schema Registry client library for Java -## Getting Started +## Getting started -## Key Concepts +## Key concepts ## Examples ## Troubleshooting -## Next Steps +## Next steps ## Contributing diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md b/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md index 32bbbfa323f6..46dfc90fa76e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md @@ -1,13 +1,13 @@ # Azure Schema Registry Avro Serializer/Deserializer client library for Java -## Getting Started +## Getting started -## Key Concepts +## Key concepts ## Examples ## Troubleshooting -## Next Steps +## Next steps ## Contributing diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md b/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md index 5fcbbc211ac4..a35b09cc5829 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md @@ -1,13 +1,13 @@ # Azure Schema Registry shared library for Java -## Getting Started +## Getting started -## Key Concepts +## Key concepts ## Examples ## Troubleshooting -## Next Steps +## Next steps ## Contributing From 47dba954784ff3b90784ed5e7aee231ca36c26c9 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Fri, 22 May 2020 12:15:27 -0700 Subject: [PATCH 20/43] add src clients to jacoco --- eng/jacoco-test-coverage/pom.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/eng/jacoco-test-coverage/pom.xml b/eng/jacoco-test-coverage/pom.xml index c9b4f0734ed9..c9990697794f 100644 --- a/eng/jacoco-test-coverage/pom.xml +++ b/eng/jacoco-test-coverage/pom.xml @@ -187,6 +187,21 @@ azure-sdk-template 1.0.4-beta.20 + + com.azure + azure-schemaregistry-client + 1.0.0-beta.1 + + + com.azure + azure-schemaregistry-serde-avro + 1.0.0-beta.1 + + + com.azure + azure-schemaregistry-serde-common + 1.0.0-beta.1 + From 198a0304094ecdabffc951af5763ee30c6539d11 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Fri, 22 May 2020 12:33:01 -0700 Subject: [PATCH 21/43] add latest swagger --- .../azure-schemaregistry-client/swagger.yaml | 378 ++++++++++++++++++ 1 file changed, 378 insertions(+) create mode 100644 sdk/schemaregistry/azure-schemaregistry-client/swagger.yaml diff --git a/sdk/schemaregistry/azure-schemaregistry-client/swagger.yaml b/sdk/schemaregistry/azure-schemaregistry-client/swagger.yaml new file mode 100644 index 000000000000..bf924360babc --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-client/swagger.yaml @@ -0,0 +1,378 @@ +openapi: 3.0.0 +info: + title: Azure Schema Registry Rest Service + version: 1.0.0-beta +paths: + /$schemagroups: + get: + summary: 'Get list of schema groups' + description: 'Get all schema groups in namespace.' + operationId: getGroups + responses: + '200': + description: OK + content: + application/json: + schema: + type: array + items: + type: string + tags: + - 'groups' + /$schemagroups/getSchemaById/{schema-id}: + get: + summary: Get schema by schema ID + description: Get schema by schema ID. + operationId: getSchemaById + parameters: + - name: schema-id + in: path + description: schema ID referencing specific schema in registry namespace + required: true + schema: + type: string + format: uuid + responses: + '200': + $ref: '#/components/responses/SchemaBytePayloadResponse' + '404': + description: Schema with matching ID not found + tags: + - 'runtime' + /$schemagroups/{group-name}: + parameters: + - name: group-name + in: path + description: schema group + required: true + schema: + type: string + get: + summary: Get schema group + description: Get schema group description in registry namespace. + operationId: getGroup + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/SchemaGroup' + '404': + description: Specified group not found + tags: + - 'groups' + put: + summary: Create schema group + description: Create schema group with specified schema type in registry namespace. + operationId: createGroup + requestBody: + description: schema group description + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/SchemaGroup' + responses: + '201': + description: Created + headers: + Location: + schema: + type: string + '409': + description: Schema group already exists + tags: + - 'groups' + delete: + summary: Delete schema group + description: Delete schema group in schema registry namespace. + operationId: deleteGroup + responses: + '204': + description: OK no content + '404': + description: Specified group not found + tags: + - 'groups' + /$schemagroups/{group-name}/schemas: + parameters: + - name: group-name + in: path + description: schema group + required: true + schema: + type: string + get: + tags: + - 'groups' + summary: Get schemas for group name + description: Returns schema by group name. + operationId: getSchemasByGroup + responses: + '200': + description: OK + headers: + X-Schema-Type: + schema: + type: string + content: + application/json: + schema: + type: array + items: + type: string + '404': + description: Group not found + delete: + tags: + - 'groups' + summary: Deletes all schemas in group + description: Deletes all schemas under specified group name. + operationId: deleteSchemasByGroup + responses: + '204': + description: OK no content + '404': + description: Group not found + /$schemagroups/{group-name}/schemas/{schema-name}: + parameters: + - name: group-name + in: path + description: schema group + required: true + schema: + type: string + - name: schema-name + in: path + description: schema name + required: true + schema: + type: string + post: + summary: Get schema ID by schema content + description: Get ID for schema with matching byte content and schema type. + operationId: getIdBySchemaContent + parameters: + - in: header + name: X-Schema-Type + schema: + type: string + required: true + requestBody: + description: schema content + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/SchemaBytePayload' + responses: + '200': + $ref: '#/components/responses/SchemaIdResponse' + '404': + description: Matching schema not found + tags: + - 'runtime' + put: + summary: Register schema + description: > + Register schema. + If schema of specified name does not exist in specified group, schema is created at version 1. + If schema of specified name exists already in specified group, schema is created at latest version + 1. + If schema with identical content already exists, existing schema's ID is returned. + operationId: createSchema + parameters: + - in: header + name: X-Schema-Type + schema: + type: string + required: true + requestBody: + description: schema content + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/SchemaBytePayload' + responses: + '200': + $ref: '#/components/responses/SchemaIdResponse' + '400': + description: Invalid request + tags: + - 'runtime' + get: + summary: Get latest version of schema + description: Get latest version of schema. + operationId: getLatestSchema + responses: + '200': + $ref: '#/components/responses/SchemaBytePayloadResponse' + tags: + - 'schemas' + delete: + summary: Delete schema + operationId: deleteSchema + responses: + '204': + description: OK no content + '404': + description: Matching schema not found + tags: + - 'schemas' + /$schemagroups/{group-name}/schemas/{schema-name}/versions: + parameters: + - name: group-name + in: path + description: schema group + required: true + schema: + type: string + - name: schema-name + in: path + description: schema name + required: true + schema: + type: string + get: + summary: Get list of versions + description: Get list of versions for specified schema + operationId: getSchemaVersions + responses: + '200': + description: OK + headers: + X-Schema-Type: + schema: + type: string + content: + application/json: + schema: + type: array + items: + type: integer + tags: + - 'schemas' + /$schemagroups/{group-name}/schemas/{schema-name}/versions/{version-number}: + parameters: + - name: group-name + in: path + description: schema group + required: true + schema: + type: string + - name: schema-name + in: path + description: schema name + required: true + schema: + type: string + - name: version-number + in: path + description: version number + required: true + schema: + type: integer + get: + summary: Get specified version of schema + operationId: getSchemaVersion + responses: + '200': + $ref: '#/components/responses/SchemaBytePayloadResponse' + '404': + description: Specified schema not found + tags: + - 'schemas' + delete: + summary: Delete specified version of schema + operationId: deleteSchemaVersion + responses: + '204': + description: OK no content + tags: + - 'schemas' + +components: + schemas: + SchemaId: + type: object + properties: + id: + type: string + SchemaBytePayload: + type: string + SchemaGroup: + type: object + properties: + name: + type: string + createdTimeUtc: + type: string + format: date-time + updatedTimeUtc: + type: string + format: date-time + schemaType: + type: string + schemaCompatibility: + type: integer + description: schema compatibility mode enum, defined by supported schema type + groupProperties: + type: object + additionalProperties: + type: string + responses: + SchemaIdResponse: + description: OK + headers: + Location: + schema: + type: string + X-Schema-Type: + schema: + type: string + X-Schema-Id: + schema: + type: string + format: uuid + description: unique schema identifier + X-Schema-Id-Location: + schema: + type: string + format: url + description: location of schema resource + X-Schema-Version: + schema: + type: integer + description: version of returned schema + content: + application/json: + schema: + $ref: '#/components/schemas/SchemaId' + SchemaBytePayloadResponse: + description: OK + headers: + Location: + schema: + type: string + X-Schema-Type: + schema: + type: string + X-Schema-Id: + schema: + type: string + format: uuid + description: unique schema identifier + X-Schema-Id-Location: + schema: + type: string + format: url + description: location of schema resource + X-Schema-Version: + schema: + type: integer + description: version of returned schema + content: + application/json: + schema: + $ref: '#/components/schemas/SchemaBytePayload' \ No newline at end of file From 24381c0ddcfa41338502bf12181deb5c33688d42 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Fri, 22 May 2020 15:59:15 -0700 Subject: [PATCH 22/43] add basic readme intros --- sdk/schemaregistry/azure-schemaregistry-client/README.md | 4 ++++ .../azure-schemaregistry-serde-avro/README.md | 4 ++++ .../azure-schemaregistry-serde-common/README.md | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/README.md b/sdk/schemaregistry/azure-schemaregistry-client/README.md index c9c59e6f4c56..dff2149e5509 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/README.md +++ b/sdk/schemaregistry/azure-schemaregistry-client/README.md @@ -1,5 +1,9 @@ # Azure Schema Registry client library for Java +This library contains a client implementation for sending, receiving, and managing Azure Schema Registry resources. + +A Swagger API definition of the service can be found at the base level of the repository. + ## Getting started ## Key concepts diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md b/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md index 46dfc90fa76e..2eefe88c09be 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md @@ -1,5 +1,9 @@ # 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 diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md b/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md index a35b09cc5829..19eaf0f2e8e4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md @@ -1,9 +1,15 @@ # Azure Schema Registry shared library for Java +This library contains common implementations for Azure Schema Registry-backed serializers and deserializers. + ## Getting started ## Key concepts +Using registry-backed serializers and deserializers allows schema information such as names and types of fields to be held externally in schema documents, allowing serialization and deserialization frameworks to produce very compact on-wire representations of structured data (e.g. payload of events and messages). To democratize schema handling for all clients, all parties who need to serialize or deserialize event or message payloads require consistent access to the same schema store. + +The serialization and deserialization implementations in this library utilize the `CachedSchemaRegistryClient` class to register and fetch schemas in Azure Schema Registry. + ## Examples ## Troubleshooting From 09d2745466c27375d3d238f4b19fad94a14b2257 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson <30675661+arerlend@users.noreply.github.com> Date: Tue, 26 May 2020 16:34:29 -0700 Subject: [PATCH 23/43] Update sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java Co-authored-by: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> --- .../client/CachedSchemaRegistryClient.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index eb1da09b8abe..680105179ab7 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -23,12 +23,13 @@ /** * HTTP-based client that interacts with Azure Schema Registry service to store and retrieve schemas on demand. *

- * Utilizes in-memory HashMap caching to minimize network I/O. + * Utilizes in-memory {@link Map} caching to minimize network I/O. Max size can be configured when instantiating by using {@link CachedSchemaRegistryClientBuilder#maxSchemaMapSize}, otherwise {@code 1000} will be used as the default. *

- * Max HashMap size can be configured when instantiating. - * Two maps are maintained - - * - SchemaRegistryObject cache by GUID - stores GUIDs previously seen in payloads - * - SchemaRegistryObject cache by schema string - minimizes HTTP calls when sending payloads of same schema + * Two maps are maintained. + *

    + *
  • SchemaRegistryObject cache by GUID - stores GUIDs previously seen in payloads.
  • + *
  • SchemaRegistryObject cache by schema string - minimizes HTTP calls when sending payloads of same schema.
  • + *
*

* TODO: implement max age for schema maps? or will schemas always be immutable? * From 866fe7f70ef19f0ab65169cbdcb411c44f1068c9 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Tue, 26 May 2020 16:36:24 -0700 Subject: [PATCH 24/43] fix comments --- .../client/CachedSchemaRegistryClient.java | 11 +++-------- .../client/CachedSchemaRegistryClientBuilder.java | 1 + .../java/com/azure/schemaregistry/ByteEncoder.java | 5 ++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index eb1da09b8abe..07874c33b901 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -30,7 +30,6 @@ * - SchemaRegistryObject cache by GUID - stores GUIDs previously seen in payloads * - SchemaRegistryObject cache by schema string - minimizes HTTP calls when sending payloads of same schema *

- * TODO: implement max age for schema maps? or will schemas always be immutable? * * @see SchemaRegistryClient Implements SchemaRegistryClient interface to allow for testing with mock * @see CachedSchemaRegistryClientBuilder Follows builder pattern for object instantiation @@ -41,8 +40,9 @@ public class CachedSchemaRegistryClient implements SchemaRegistryClient { private final ClientLogger logger = new ClientLogger(CachedSchemaRegistryClient.class); - public static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; public static final Charset SCHEMA_REGISTRY_SERVICE_ENCODING = StandardCharsets.UTF_8; + + static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; static final int MAX_SCHEMA_MAP_SIZE_MINIMUM = 10; private final AzureSchemaRegistryRestService restService; @@ -61,12 +61,6 @@ public class CachedSchemaRegistryClient implements SchemaRegistryClient { new IllegalArgumentException("Schema Registry URL cannot be null or empty.")); } - if (maxSchemaMapSize < MAX_SCHEMA_MAP_SIZE_MINIMUM) { - throw logger.logExceptionAsError( - new IllegalArgumentException( - String.format("Max schema map size must be greater than %d schemas", MAX_SCHEMA_MAP_SIZE_MINIMUM))); - } - this.restService = new AzureSchemaRegistryRestServiceClientBuilder() .host(registryUrl) .pipeline(pipeline) @@ -249,6 +243,7 @@ public synchronized void reset() { typeParserDictionary.clear(); } + // TODO: max age for schema maps? or will schemas always be immutable? /** * Checks if caches should be reinitialized to satisfy initial configuration */ diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index a4f542822630..16ba032da37e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -113,6 +113,7 @@ public CachedSchemaRegistryClientBuilder maxSchemaMapSize(int maxSchemaMapSize) String.format("Schema map size must be greater than %s entries", CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM))); } + this.maxSchemaMapSize = maxSchemaMapSize; return this; } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java index 10e6eab6a81b..aba4ef428a1e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java @@ -28,14 +28,13 @@ public interface ByteEncoder extends Codec { */ String getSchemaString(Object object) throws SerializationException; + // TODO: Method does not currently require schema object to be passed since schemas can be derived from + // Avro objects. JSON implementation would be the same. /** * Converts object into stream containing the encoded representation of the object. * @param object Object to be encoded into byte stream * @return output stream containing byte representation of object * @throws SerializationException if generating byte representation of object fails - * - * TODO: Method does not currently require schema object to be passed since schemas can be derived from - * Avro objects. JSON implementation would be the same. */ ByteArrayOutputStream encode(Object object) throws SerializationException; } From d4e534007a19fe5f9198e31acc5c152b8b05b4f1 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson <30675661+arerlend@users.noreply.github.com> Date: Tue, 26 May 2020 16:40:23 -0700 Subject: [PATCH 25/43] Update sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java Co-authored-by: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> --- .../azure/schemaregistry/client/CachedSchemaRegistryClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index b8572c1039f1..a1fc7b665d21 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -110,7 +110,7 @@ public synchronized void loadSchemaParser(String schemaType, Function Date: Tue, 26 May 2020 16:57:41 -0700 Subject: [PATCH 26/43] default retry policy on null --- .../client/CachedSchemaRegistryClientBuilder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index 16ba032da37e..b59d2c94b86a 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -46,6 +46,8 @@ public class CachedSchemaRegistryClientBuilder { private static final String CLIENT_PROPERTIES = "azure-schemaregistry-client.properties"; private static final String NAME = "name"; private static final String VERSION = "version"; + private static final RetryPolicy DEFAULT_RETRY_POLICY = + new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS); private final String schemaRegistryUrl; private final HashMap> typeParserDictionary; @@ -252,7 +254,8 @@ public CachedSchemaRegistryClient buildClient() { HttpPolicyProviders.addBeforeRetryPolicies(policies); - policies.add(retryPolicy); + + policies.add(retryPolicy == null ? DEFAULT_RETRY_POLICY : retryPolicy); policies.add(new AddDatePolicy()); // Authentications From 2a216c3617d1b1c31c749c7db1556ec0ef6bec07 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Tue, 26 May 2020 17:04:28 -0700 Subject: [PATCH 27/43] remove unused headers policy --- .../CachedSchemaRegistryClientBuilder.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index b59d2c94b86a..6ef047649941 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -54,7 +54,6 @@ public class CachedSchemaRegistryClientBuilder { private final List policies; private final String clientName; private final String clientVersion; - private final HttpHeaders headers; private HttpClient httpClient; private int maxSchemaMapSize; @@ -98,8 +97,6 @@ public CachedSchemaRegistryClientBuilder(String schemaRegistryUrl) { Map properties = CoreUtils.getProperties(CLIENT_PROPERTIES); clientName = properties.getOrDefault(NAME, "UnknownName"); clientVersion = properties.getOrDefault(VERSION, "UnknownVersion"); - - this.headers = new HttpHeaders(); } /** @@ -241,6 +238,13 @@ public CachedSchemaRegistryClientBuilder loadSchemaParser( * @throws IllegalArgumentException if credential is not set. */ public CachedSchemaRegistryClient buildClient() { + // Authentications + if (credential == null) { + // Throw exception that credential and tokenCredential cannot be null + throw logger.logExceptionAsError( + new IllegalArgumentException("Missing credential information while building a client.")); + } + HttpPipeline pipeline = this.httpPipeline; // Create a default Pipeline if it is not given if (pipeline == null) { @@ -250,7 +254,6 @@ public CachedSchemaRegistryClient buildClient() { policies.add(new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, Configuration.getGlobalConfiguration().clone())); policies.add(new RequestIdPolicy()); - policies.add(new AddHeadersPolicy(this.headers)); HttpPolicyProviders.addBeforeRetryPolicies(policies); @@ -258,15 +261,8 @@ public CachedSchemaRegistryClient buildClient() { policies.add(retryPolicy == null ? DEFAULT_RETRY_POLICY : retryPolicy); policies.add(new AddDatePolicy()); - // Authentications - if (credential != null) { - // User token based policy - policies.add(new BearerTokenAuthenticationPolicy(credential, DEFAULT_SCOPE)); - } else { - // Throw exception that credential and tokenCredential cannot be null - throw logger.logExceptionAsError( - new IllegalArgumentException("Missing credential information while building a client.")); - } + + policies.add(new BearerTokenAuthenticationPolicy(credential, DEFAULT_SCOPE)); policies.addAll(this.policies); HttpPolicyProviders.addAfterRetryPolicies(policies); From d25047fd1cfd114aec2b106aae454e1237d841ed Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 27 May 2020 08:36:49 -0700 Subject: [PATCH 28/43] netty dep --- sdk/schemaregistry/azure-schemaregistry-client/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml index 018be97b4920..7ee09d33f956 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml @@ -49,6 +49,11 @@ azure-core 1.5.0 + + com.azure + azure-core-http-netty + 1.5.1 + From 9cd191ebe22a464348914279d96db3cf321871ea Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 27 May 2020 08:38:52 -0700 Subject: [PATCH 29/43] hashmap to concurrent hashmap, slf4j format pattern --- .../client/CachedSchemaRegistryClient.java | 102 +++++++++--------- 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index a1fc7b665d21..bd9b15d417ac 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -6,6 +6,7 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpPipeline; +import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestService; import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestServiceClientBuilder; @@ -14,16 +15,18 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; /** * HTTP-based client that interacts with Azure Schema Registry service to store and retrieve schemas on demand. *

- * Utilizes in-memory {@link Map} caching to minimize network I/O. Max size can be configured when instantiating by using {@link CachedSchemaRegistryClientBuilder#maxSchemaMapSize}, otherwise {@code 1000} will be used as the default. + * Utilizes in-memory {@link Map} caching to minimize network I/O. Max size can be configured when instantiating by + * using {@link CachedSchemaRegistryClientBuilder#maxSchemaMapSize}, otherwise {@code 1000} will be used as the default. *

* Two maps are maintained. *

    @@ -48,16 +51,16 @@ public class CachedSchemaRegistryClient implements SchemaRegistryClient { private final AzureSchemaRegistryRestService restService; private final int maxSchemaMapSize; - private final HashMap> typeParserDictionary; - private final HashMap guidCache; - private final HashMap schemaStringCache; + private final Map> typeParserMap; + private final Map guidCache; + private final Map schemaStringCache; CachedSchemaRegistryClient( String registryUrl, HttpPipeline pipeline, int maxSchemaMapSize, - HashMap> typeParserDictionary) { - if (registryUrl == null || registryUrl.isEmpty()) { + Map> typeParserMap) { + if (CoreUtils.isNullOrEmpty(registryUrl)) { throw logger.logExceptionAsError( new IllegalArgumentException("Schema Registry URL cannot be null or empty.")); } @@ -68,21 +71,21 @@ public class CachedSchemaRegistryClient implements SchemaRegistryClient { .buildClient(); this.maxSchemaMapSize = maxSchemaMapSize; - this.typeParserDictionary = typeParserDictionary; - this.guidCache = new HashMap<>(); - this.schemaStringCache = new HashMap<>(); + this.typeParserMap = typeParserMap; + this.guidCache = new ConcurrentHashMap<>(); + this.schemaStringCache = new ConcurrentHashMap<>(); } - // testing + // testing - todo remove constructor and replace with mock CachedSchemaRegistryClient( AzureSchemaRegistryRestService restService, - HashMap guidCache, - HashMap schemaStringCache, - HashMap> typeParserDictionary) { + Map guidCache, + Map schemaStringCache, + Map> typeParserMap) { this.restService = restService; // mockable this.guidCache = guidCache; this.schemaStringCache = schemaStringCache; - this.typeParserDictionary = typeParserDictionary; + this.typeParserMap = typeParserMap; this.maxSchemaMapSize = MAX_SCHEMA_MAP_SIZE_DEFAULT; } @@ -95,39 +98,37 @@ public Charset getEncoding() { } /** - * @param schemaType tag used by schema registry store to identify schema serialization type, e.g. "avro" + * @param schemaType case-insensitive tag used by schema registry store to identify schema type, e.g. "avro" * @param parseMethod function to parse string into usable schema object * @throws IllegalArgumentException on bad schema type or if parser for schema type has already been registered */ - public synchronized void loadSchemaParser(String schemaType, Function parseMethod) { - if (schemaType == null || schemaType.isEmpty()) { + public void loadSchemaParser(String schemaType, Function parseMethod) { + if (CoreUtils.isNullOrEmpty(schemaType)) { throw logger.logExceptionAsError( new IllegalArgumentException("Serialization type cannot be null or empty.")); } - if (this.typeParserDictionary.containsKey(schemaType.toLowerCase(Locale.ENGLISH))) { + if (this.typeParserMap.containsKey(schemaType.toLowerCase(Locale.ROOT))) { throw logger.logExceptionAsError( new IllegalArgumentException("Multiple parse methods for single serialization type may not be added.")); } - this.typeParserDictionary.put(schemaType.toLowerCase(Locale.ENGLISH), parseMethod); + this.typeParserMap.putIfAbsent(schemaType.toLowerCase(Locale.ROOT), parseMethod); logger.verbose( - "Loaded parser for '{}' serialization format.", schemaType.toLowerCase(Locale.ENGLISH)); + "Loaded parser for '{}' serialization format.", schemaType.toLowerCase(Locale.ROOT)); } @Override - public synchronized SchemaRegistryObject register( - String schemaGroup, String schemaName, String schemaString, String serializationType) - throws SchemaRegistryClientException { + public SchemaRegistryObject register( + String schemaGroup, String schemaName, String schemaString, String serializationType) { if (schemaStringCache.containsKey(schemaString)) { logger.verbose( - String.format( - "Cache hit schema string. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", - schemaGroup, schemaName, serializationType, schemaString)); + "Cache hit schema string. Group: '{}', name: '{}', serialization type: '{}', payload: '{}'", + schemaGroup, schemaName, serializationType, schemaString); return schemaStringCache.get(schemaString); } logger.verbose( - String.format("Registering schema. Group: '%s', name: '%s', serialization type: '%s', payload: '%s'", - schemaGroup, schemaName, serializationType, schemaString)); + "Registering schema. Group: '{}', name: '{}', serialization type: '{}', payload: '{}'", + schemaGroup, schemaName, serializationType, schemaString); SchemaId schemaId; try { @@ -142,16 +143,15 @@ public synchronized SchemaRegistryObject register( getParseFunc(serializationType)); resetIfNeeded(); - schemaStringCache.put(schemaString, registered); - logger.verbose(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + schemaStringCache.putIfAbsent(schemaString, registered); + logger.verbose("Cached schema string. Group: '{}', name: '{}'", schemaGroup, schemaName); return registered; } @Override - public synchronized SchemaRegistryObject getSchemaByGuid(String schemaId) - throws SchemaRegistryClientException { + public SchemaRegistryObject getSchemaByGuid(String schemaId) { if (guidCache.containsKey(schemaId)) { - logger.verbose(String.format("Cache hit for schema id '%s'", schemaId)); + logger.verbose("Cache hit for schema id '{}'", schemaId); return guidCache.get(schemaId); } @@ -175,17 +175,16 @@ public synchronized SchemaRegistryObject getSchemaByGuid(String schemaId) getParseFunc(schemaType)); resetIfNeeded(); - guidCache.put(schemaId, schemaObject); - logger.verbose(String.format("Cached schema object. Path: '%s'", schemaId)); + guidCache.putIfAbsent(schemaId, schemaObject); + logger.verbose("Cached schema object. Path: '{}'", schemaId); return schemaObject; } @Override - public synchronized String getSchemaId( - String schemaGroup, String schemaName, String schemaString, String schemaType) - throws SchemaRegistryClientException { + public String getSchemaId( + String schemaGroup, String schemaName, String schemaString, String schemaType) { if (schemaStringCache.containsKey(schemaString)) { - logger.verbose(String.format("Cache hit schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + logger.verbose("Cache hit schema string. Group: '{}', name: '{}'", schemaGroup, schemaName); return schemaStringCache.get(schemaString).getSchemaId(); } @@ -200,36 +199,33 @@ public synchronized String getSchemaId( } resetIfNeeded(); - schemaStringCache.put( + schemaStringCache.putIfAbsent( schemaString, new SchemaRegistryObject( schemaId.getId(), schemaType, schemaString.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING), getParseFunc(schemaType))); - logger.verbose(String.format("Cached schema string. Group: '%s', name: '%s'", schemaGroup, schemaName)); + logger.verbose("Cached schema string. Group: '{}', name: '{}'", schemaGroup, schemaName); return schemaId.getId(); } @Override - public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) - throws SchemaRegistryClientException { + public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) { // return this.restService.deleteSchemaVersion(schemaName, version); // remove from cache return null; } @Override - public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) - throws SchemaRegistryClientException { + public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) { // return this.restService.deleteSchemaVersion(schemaName, null); // remove from cache return null; } @Override - public List deleteSchema(String schemaGroup, String schemaName) - throws SchemaRegistryClientException { + public List deleteSchema(String schemaGroup, String schemaName) { // return this.restService.deleteSchema(); // remove from cache return null; @@ -238,17 +234,17 @@ public List deleteSchema(String schemaGroup, String schemaName) /** * Explicit call to clear all caches. */ - public synchronized void reset() { + public void reset() { guidCache.clear(); schemaStringCache.clear(); - typeParserDictionary.clear(); + typeParserMap.clear(); } // TODO: max age for schema maps? or will schemas always be immutable? /** * Checks if caches should be reinitialized to satisfy initial configuration */ - private synchronized void resetIfNeeded() { + private void resetIfNeeded() { if (guidCache.size() > this.maxSchemaMapSize) { guidCache.clear(); } @@ -264,13 +260,13 @@ private synchronized void resetIfNeeded() { * @return parse method for deserializing schema string */ private Function getParseFunc(String schemaType) { - Function parseFunc = typeParserDictionary.get(schemaType.toLowerCase(Locale.ENGLISH)); + Function parseFunc = typeParserMap.get(schemaType.toLowerCase(Locale.ROOT)); if (parseFunc == null) { throw logger.logExceptionAsError(new SchemaRegistryClientException( String.format("Unexpected serialization type '%s' received. Currently loaded parsers: %s", schemaType, - typeParserDictionary.keySet().toString()))); + typeParserMap.keySet().toString()))); } return parseFunc; } From 59d8f9d2fd1c4ea421a774ed95c98a9a85d73a06 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 27 May 2020 08:39:37 -0700 Subject: [PATCH 30/43] builder cleanup --- .../client/CachedSchemaRegistryClientBuilder.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index 6ef047649941..90573f0ae378 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -6,11 +6,9 @@ import com.azure.core.annotation.ServiceClientBuilder; import com.azure.core.credential.TokenCredential; import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.AddDatePolicy; -import com.azure.core.http.policy.AddHeadersPolicy; import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; @@ -28,11 +26,11 @@ import java.net.URL; import java.time.temporal.ChronoUnit; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; /** @@ -50,7 +48,7 @@ public class CachedSchemaRegistryClientBuilder { new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS); private final String schemaRegistryUrl; - private final HashMap> typeParserDictionary; + private final ConcurrentHashMap> typeParserMap; private final List policies; private final String clientName; private final String clientVersion; @@ -89,7 +87,7 @@ public CachedSchemaRegistryClientBuilder(String schemaRegistryUrl) { this.policies = new ArrayList<>(); this.httpLogOptions = new HttpLogOptions(); this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; - this.typeParserDictionary = new HashMap<>(); + this.typeParserMap = new ConcurrentHashMap<>(); this.httpClient = null; this.credential = null; this.retryPolicy = new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS); @@ -218,11 +216,11 @@ public CachedSchemaRegistryClientBuilder loadSchemaParser( throw logger.logExceptionAsError( new IllegalArgumentException("Serialization type cannot be null or empty.")); } - if (this.typeParserDictionary.containsKey(schemaType.toLowerCase(Locale.ENGLISH))) { + if (this.typeParserMap.containsKey(schemaType.toLowerCase(Locale.ROOT))) { throw logger.logExceptionAsError( new IllegalArgumentException("Multiple parse methods for single serialization type may not be added.")); } - this.typeParserDictionary.put(schemaType.toLowerCase(Locale.ENGLISH), parseMethod); + this.typeParserMap.put(schemaType.toLowerCase(Locale.ROOT), parseMethod); return this; } @@ -279,6 +277,6 @@ public CachedSchemaRegistryClient buildClient() { schemaRegistryUrl, pipeline, maxSchemaMapSize, - typeParserDictionary); + typeParserMap); } } From a04c3835260f66214ce8618ec632e7e8774e03eb Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 27 May 2020 08:40:01 -0700 Subject: [PATCH 31/43] remove runtime error from method signature --- .../client/SchemaRegistryClient.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java index 8b36bfca299f..33dc12b5a694 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java @@ -38,8 +38,7 @@ public interface SchemaRegistryClient { * @return SchemaRegistryObject containing information regarding registered schema. * @throws SchemaRegistryClientException if registration operation fails */ - SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) - throws SchemaRegistryClientException; + SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType); /** * Fetches schema specified by the GUID. @@ -50,7 +49,7 @@ SchemaRegistryObject register(String schemaGroup, String schemaName, String sche * @return SchemaRegistryObject containing information regarding matching schema. * @throws SchemaRegistryClientException if fetch operation fails */ - SchemaRegistryObject getSchemaByGuid(String schemaGuid) throws SchemaRegistryClientException; + SchemaRegistryObject getSchemaByGuid(String schemaGuid); /** * Fetches schema GUID given schema group, name, string representation, and serialization type @@ -62,8 +61,7 @@ SchemaRegistryObject register(String schemaGroup, String schemaName, String sche * @return SchemaRegistryObject containing information regarding requested schema. * @throws SchemaRegistryClientException if fetch operation fails */ - String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType) - throws SchemaRegistryClientException; + String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType); /** * Not currently implemented. @@ -74,8 +72,7 @@ String getSchemaId(String schemaGroup, String schemaName, String schemaString, S * @return GUID of delete schema * @throws SchemaRegistryClientException deletion operation failed */ - String deleteSchemaVersion(String schemaGroup, String schemaName, int version) - throws SchemaRegistryClientException; + String deleteSchemaVersion(String schemaGroup, String schemaName, int version); /** * Not currently implemented. @@ -85,7 +82,7 @@ String deleteSchemaVersion(String schemaGroup, String schemaName, int version) * @return GUID of deleted schema * @throws SchemaRegistryClientException deletion operation failed */ - String deleteLatestSchemaVersion(String schemaGroup, String schemaName) throws SchemaRegistryClientException; + String deleteLatestSchemaVersion(String schemaGroup, String schemaName); /** * Not currently implemented. @@ -95,5 +92,5 @@ String deleteSchemaVersion(String schemaGroup, String schemaName, int version) * @return list of GUID references to deleted schemas * @throws SchemaRegistryClientException deletion operation failed */ - List deleteSchema(String schemaGroup, String schemaName) throws SchemaRegistryClientException; + List deleteSchema(String schemaGroup, String schemaName); } From 1656da90030e3ca9f610132ba3b4537dfa049910 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 27 May 2020 13:56:46 -0700 Subject: [PATCH 32/43] comments --- .../client/CachedSchemaRegistryClient.java | 15 ++++++------- .../client/SchemaRegistryClient.java | 3 ++- .../client/SchemaRegistryClientException.java | 4 +++- .../client/SchemaRegistryObject.java | 16 +++++++------- .../AzureSchemaRegistryRestService.java | 22 +++++++++---------- ...chemaRegistryRestServiceClientBuilder.java | 2 +- .../models/CreateGroupHeaders.java | 2 +- .../models/CreateGroupResponse.java | 2 +- .../models/CreateSchemaHeaders.java | 2 +- .../models/CreateSchemaResponse.java | 2 +- .../models/GetIdBySchemaContentHeaders.java | 2 +- .../models/GetIdBySchemaContentResponse.java | 2 +- .../models/GetLatestSchemaHeaders.java | 2 +- .../models/GetLatestSchemaResponse.java | 2 +- .../models/GetSchemaByIdHeaders.java | 2 +- .../models/GetSchemaByIdResponse.java | 2 +- .../models/GetSchemaVersionHeaders.java | 2 +- .../models/GetSchemaVersionResponse.java | 2 +- .../models/GetSchemaVersionsHeaders.java | 2 +- .../models/GetSchemaVersionsResponse.java | 2 +- .../models/GetSchemasByGroupHeaders.java | 2 +- .../models/GetSchemasByGroupResponse.java | 2 +- .../models/SchemaGroup.java | 2 +- .../models/SchemaId.java | 2 +- .../models/package-info.java | 2 +- .../package-info.java | 0 .../{ => swagger}/swagger.yaml | 0 27 files changed, 51 insertions(+), 49 deletions(-) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/AzureSchemaRegistryRestService.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/AzureSchemaRegistryRestServiceClientBuilder.java (97%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/CreateGroupHeaders.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/CreateGroupResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/CreateSchemaHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/CreateSchemaResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetIdBySchemaContentHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetIdBySchemaContentResponse.java (95%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetLatestSchemaHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetLatestSchemaResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetSchemaByIdHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetSchemaByIdResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetSchemaVersionHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetSchemaVersionResponse.java (95%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetSchemaVersionsHeaders.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetSchemaVersionsResponse.java (95%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetSchemasByGroupHeaders.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/GetSchemasByGroupResponse.java (95%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/SchemaGroup.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/SchemaId.java (93%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/models/package-info.java (57%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/{rest => implementation}/package-info.java (100%) rename sdk/schemaregistry/azure-schemaregistry-client/{ => swagger}/swagger.yaml (100%) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java index bd9b15d417ac..a55178e32d3f 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java @@ -8,10 +8,10 @@ import com.azure.core.http.HttpPipeline; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; -import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestService; -import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestServiceClientBuilder; -import com.azure.schemaregistry.client.rest.models.GetSchemaByIdResponse; -import com.azure.schemaregistry.client.rest.models.SchemaId; +import com.azure.schemaregistry.client.implementation.AzureSchemaRegistryRestService; +import com.azure.schemaregistry.client.implementation.AzureSchemaRegistryRestServiceClientBuilder; +import com.azure.schemaregistry.client.implementation.models.GetSchemaByIdResponse; +import com.azure.schemaregistry.client.implementation.models.SchemaId; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -41,7 +41,7 @@ @ServiceClient( builder = CachedSchemaRegistryClientBuilder.class, serviceInterfaces = AzureSchemaRegistryRestService.class) -public class CachedSchemaRegistryClient implements SchemaRegistryClient { +public final class CachedSchemaRegistryClient implements SchemaRegistryClient { private final ClientLogger logger = new ClientLogger(CachedSchemaRegistryClient.class); public static final Charset SCHEMA_REGISTRY_SERVICE_ENCODING = StandardCharsets.UTF_8; @@ -212,9 +212,7 @@ public String getSchemaId( @Override public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) { - // return this.restService.deleteSchemaVersion(schemaName, version); - // remove from cache - return null; + throw new UnsupportedOperationException(); } @Override @@ -245,6 +243,7 @@ public void reset() { * Checks if caches should be reinitialized to satisfy initial configuration */ private void resetIfNeeded() { + // todo add verbose log if (guidCache.size() > this.maxSchemaMapSize) { guidCache.clear(); } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java index 33dc12b5a694..28493a9a61fd 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java @@ -24,7 +24,8 @@ public interface SchemaRegistryClient { * usable schema object. * * @param serializationType tag used by schema registry store to identify schema serialization type, e.g. "avro" - * @param parseMethod function to parse string into usable schema object + * @param parseMethod *idempotent* function to parse string into usable schema object. May be called more than once + * per schema */ void loadSchemaParser(String serializationType, Function parseMethod); diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java index 3dd6d00dbcb4..30ae8f01e97e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java @@ -3,10 +3,12 @@ package com.azure.schemaregistry.client; +import com.azure.core.exception.AzureException; + /** * Runtime exception to be returned from SchemaRegistryClient implementations. */ -public class SchemaRegistryClientException extends RuntimeException { +public class SchemaRegistryClientException extends AzureException { /** * @param s error message returned from schema registry client */ diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java index f90901f50867..38e68766a1e9 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java @@ -15,7 +15,7 @@ public class SchemaRegistryObject { private final String schemaId; private final String schemaType; private final Function parseMethod; - private final byte[] schemaByteArray; + private final byte[] schemaBytes; private Object deserialized; @@ -34,7 +34,7 @@ public SchemaRegistryObject( Function parseMethod) { this.schemaId = schemaId; this.schemaType = schemaType; - this.schemaByteArray = schemaByteArray.clone(); + this.schemaBytes = schemaByteArray.clone(); this.deserialized = null; this.parseMethod = parseMethod; } @@ -67,12 +67,12 @@ public Object deserialize() { } if (this.deserialized == null) { - logger.verbose( - String.format("Deserializing schema, id: %s, schema string %s", - this.schemaId, - new String(this.schemaByteArray, CachedSchemaRegistryClient.SCHEMA_REGISTRY_SERVICE_ENCODING))); - this.deserialized = parseMethod.apply( - new String(this.schemaByteArray, CachedSchemaRegistryClient.SCHEMA_REGISTRY_SERVICE_ENCODING)); + String schemaString = new String( + this.schemaBytes, CachedSchemaRegistryClient.SCHEMA_REGISTRY_SERVICE_ENCODING); + + logger.verbose("Deserializing schema, id: '{}', schema string '{}'", this.schemaId, schemaString); + + this.deserialized = parseMethod.apply(schemaString); } return deserialized; } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java index 9059e387e5d5..be95bbf34d67 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestService.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest; +package com.azure.schemaregistry.client.implementation; import com.azure.core.annotation.BodyParam; import com.azure.core.annotation.Delete; @@ -28,16 +28,16 @@ import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; -import com.azure.schemaregistry.client.rest.models.CreateGroupResponse; -import com.azure.schemaregistry.client.rest.models.CreateSchemaResponse; -import com.azure.schemaregistry.client.rest.models.GetIdBySchemaContentResponse; -import com.azure.schemaregistry.client.rest.models.GetLatestSchemaResponse; -import com.azure.schemaregistry.client.rest.models.GetSchemaByIdResponse; -import com.azure.schemaregistry.client.rest.models.GetSchemaVersionResponse; -import com.azure.schemaregistry.client.rest.models.GetSchemaVersionsResponse; -import com.azure.schemaregistry.client.rest.models.GetSchemasByGroupResponse; -import com.azure.schemaregistry.client.rest.models.SchemaGroup; -import com.azure.schemaregistry.client.rest.models.SchemaId; +import com.azure.schemaregistry.client.implementation.models.CreateGroupResponse; +import com.azure.schemaregistry.client.implementation.models.CreateSchemaResponse; +import com.azure.schemaregistry.client.implementation.models.GetIdBySchemaContentResponse; +import com.azure.schemaregistry.client.implementation.models.GetLatestSchemaResponse; +import com.azure.schemaregistry.client.implementation.models.GetSchemaByIdResponse; +import com.azure.schemaregistry.client.implementation.models.GetSchemaVersionResponse; +import com.azure.schemaregistry.client.implementation.models.GetSchemaVersionsResponse; +import com.azure.schemaregistry.client.implementation.models.GetSchemasByGroupResponse; +import com.azure.schemaregistry.client.implementation.models.SchemaGroup; +import com.azure.schemaregistry.client.implementation.models.SchemaId; import reactor.core.publisher.Mono; import java.util.List; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java similarity index 97% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceClientBuilder.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java index a1643a217ba8..145f91e30e22 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/AzureSchemaRegistryRestServiceClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest; +package com.azure.schemaregistry.client.implementation; import com.azure.core.annotation.ServiceClientBuilder; import com.azure.core.http.HttpPipeline; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupHeaders.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupHeaders.java index 8f50fa5babe8..c1eb5f7b3fa4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupResponse.java index b62e9399f2f5..1c49cdf7c6f6 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateGroupResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaHeaders.java index e57cb556630c..451f96f2ff69 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaResponse.java index 1dec3c2aa724..bd2b0ca2ca19 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/CreateSchemaResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java index dc77686dff43..3b8dd56c0b11 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java similarity index 95% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java index e26af9943bd6..1cfa578edae1 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetIdBySchemaContentResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java index 9cdf385e0924..0769486318df 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java index 8dfcf1f9ec9e..88c43929cb76 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetLatestSchemaResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java index a6027973f53a..0ab743c97a68 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java index 8d80b74e1d70..a6e0f156fd5c 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaByIdResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java index c16879dac958..5a697d12158b 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java similarity index 95% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java index e310d36ec8d0..8828783c35ed 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java index 03a25659f2eb..e10b7fd782ab 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java similarity index 95% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java index 0875be91a464..ed44dd9dd7f9 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemaVersionsResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java index 1142e85b8e86..af20a8b9765f 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java similarity index 95% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java index e80e83544847..f2423081e837 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/GetSchemasByGroupResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaGroup.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaGroup.java index b0285509e5af..be96fbb3e6b2 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaGroup.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaGroup.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaId.java similarity index 93% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaId.java index 4afc4840d571..358eb330dcc4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/SchemaId.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaId.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/package-info.java similarity index 57% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/package-info.java index ff2eadc27b1d..9f561b8f770d 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/models/package-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/package-info.java @@ -1,3 +1,3 @@ /** Package containing the data models for AzureSchemaRegistryRestService. null. */ -package com.azure.schemaregistry.client.rest.models; +package com.azure.schemaregistry.client.implementation.models; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/rest/package-info.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/package-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/swagger.yaml b/sdk/schemaregistry/azure-schemaregistry-client/swagger/swagger.yaml similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/swagger.yaml rename to sdk/schemaregistry/azure-schemaregistry-client/swagger/swagger.yaml From 81682bcf0e27294f75d434f047e63ed5eda9e110 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 27 May 2020 17:33:25 -0700 Subject: [PATCH 33/43] change group name --- .../azure-schemaregistry-client/pom.xml | 2 +- .../client/CachedSchemaRegistryClient.java | 62 ++++++++++--------- .../CachedSchemaRegistryClientBuilder.java | 58 +++++++++-------- .../client/SchemaRegistryClient.java | 2 +- .../client/SchemaRegistryClientException.java | 2 +- .../client/SchemaRegistryObject.java | 8 +-- .../AzureSchemaRegistryRestService.java | 22 +++---- ...chemaRegistryRestServiceClientBuilder.java | 2 +- .../models/CreateGroupHeaders.java | 2 +- .../models/CreateGroupResponse.java | 2 +- .../models/CreateSchemaHeaders.java | 2 +- .../models/CreateSchemaResponse.java | 2 +- .../models/GetIdBySchemaContentHeaders.java | 2 +- .../models/GetIdBySchemaContentResponse.java | 2 +- .../models/GetLatestSchemaHeaders.java | 2 +- .../models/GetLatestSchemaResponse.java | 2 +- .../models/GetSchemaByIdHeaders.java | 2 +- .../models/GetSchemaByIdResponse.java | 2 +- .../models/GetSchemaVersionHeaders.java | 2 +- .../models/GetSchemaVersionResponse.java | 2 +- .../models/GetSchemaVersionsHeaders.java | 2 +- .../models/GetSchemaVersionsResponse.java | 2 +- .../models/GetSchemasByGroupHeaders.java | 2 +- .../models/GetSchemasByGroupResponse.java | 2 +- .../implementation/models/SchemaGroup.java | 2 +- .../implementation/models/SchemaId.java | 2 +- .../implementation/models/package-info.java | 2 +- .../client/implementation/package-info.java | 2 +- .../schemaregistry/client/package-info.java | 2 +- .../src/main/module-info.java | 12 ++-- .../CachedSchemaRegistryClientTest.java | 15 ++--- .../azure-schemaregistry-serde-avro/pom.xml | 6 +- .../schemaregistry/avro/AvroByteDecoder.java | 6 +- .../schemaregistry/avro/AvroByteEncoder.java | 6 +- .../schemaregistry/avro/AvroCodec.java | 4 +- .../schemaregistry/avro/AvroSchemaUtils.java | 2 +- .../SchemaRegistryAvroAsyncDeserializer.java | 4 +- .../SchemaRegistryAvroAsyncSerializer.java | 6 +- .../avro/SchemaRegistryAvroDeserializer.java | 17 ++--- ...SchemaRegistryAvroDeserializerBuilder.java | 4 +- .../avro/SchemaRegistryAvroSerializer.java | 11 ++-- .../SchemaRegistryAvroSerializerBuilder.java | 6 +- .../schemaregistry/avro/package-info.java | 2 +- .../src/main/module-info.java | 4 +- .../avro/AvroByteDecoderTest.java | 2 +- .../avro/AvroByteEncoderTest.java | 2 +- .../azure-schemaregistry-serde-common/pom.xml | 4 +- .../AbstractDataDeserializer.java | 13 ++-- .../schemaregistry/AbstractDataSerDe.java | 4 +- .../AbstractDataSerializer.java | 6 +- .../schemaregistry/ByteDecoder.java | 2 +- .../schemaregistry/ByteEncoder.java | 2 +- .../{ => data}/schemaregistry/Codec.java | 2 +- .../SerializationException.java | 2 +- .../schemaregistry/package-info.java | 2 +- .../src/main/module-info.java | 6 +- .../AbstractDataDeserializerTest.java | 6 +- .../AbstractDataSerializerTest.java | 4 +- .../MockSchemaRegistryClient.java | 8 +-- .../schemaregistry/SampleByteDecoder.java | 2 +- .../schemaregistry/SampleByteEncoder.java | 2 +- .../schemaregistry/TestDummyDeserializer.java | 4 +- .../schemaregistry/TestDummySerializer.java | 4 +- sdk/schemaregistry/ci.yml | 12 ++-- 64 files changed, 199 insertions(+), 195 deletions(-) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/CachedSchemaRegistryClient.java (84%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/CachedSchemaRegistryClientBuilder.java (90%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/SchemaRegistryClient.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/SchemaRegistryClientException.java (93%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/SchemaRegistryObject.java (88%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java (97%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/CreateGroupHeaders.java (93%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/CreateGroupResponse.java (93%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/CreateSchemaHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/CreateSchemaResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java (94%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/SchemaGroup.java (98%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/SchemaId.java (93%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/models/package-info.java (55%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/implementation/package-info.java (56%) rename sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/{ => data}/schemaregistry/client/package-info.java (76%) rename sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/{ => data}/schemaregistry/client/CachedSchemaRegistryClientTest.java (89%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/AvroByteDecoder.java (95%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/AvroByteEncoder.java (95%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/AvroCodec.java (86%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/AvroSchemaUtils.java (98%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java (93%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java (89%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/SchemaRegistryAvroDeserializer.java (78%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java (96%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/SchemaRegistryAvroSerializer.java (84%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java (96%) rename sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/{ => data}/schemaregistry/avro/package-info.java (79%) rename sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/{ => data}/schemaregistry/AbstractDataDeserializer.java (92%) rename sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/{ => data}/schemaregistry/AbstractDataSerDe.java (92%) rename sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/{ => data}/schemaregistry/AbstractDataSerializer.java (96%) rename sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/{ => data}/schemaregistry/ByteDecoder.java (94%) rename sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/{ => data}/schemaregistry/ByteEncoder.java (97%) rename sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/{ => data}/schemaregistry/Codec.java (94%) rename sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/{ => data}/schemaregistry/SerializationException.java (94%) rename sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/{ => data}/schemaregistry/package-info.java (74%) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml index 7ee09d33f956..50397517a8e5 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-client/pom.xml @@ -15,7 +15,7 @@ com.azure - azure-schemaregistry-client + azure-data-schemaregistry-client jar 1.0.0-beta.1 diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java similarity index 84% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java index a55178e32d3f..3e43c77941d1 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java @@ -1,25 +1,27 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client; +package com.azure.data.schemaregistry.client; import com.azure.core.annotation.ServiceClient; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpPipeline; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; -import com.azure.schemaregistry.client.implementation.AzureSchemaRegistryRestService; -import com.azure.schemaregistry.client.implementation.AzureSchemaRegistryRestServiceClientBuilder; -import com.azure.schemaregistry.client.implementation.models.GetSchemaByIdResponse; -import com.azure.schemaregistry.client.implementation.models.SchemaId; +import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestService; +import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestServiceClientBuilder; +import com.azure.data.schemaregistry.client.implementation.models.GetSchemaByIdResponse; +import com.azure.data.schemaregistry.client.implementation.models.SchemaId; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.function.Function; /** @@ -46,20 +48,20 @@ public final class CachedSchemaRegistryClient implements SchemaRegistryClient { public static final Charset SCHEMA_REGISTRY_SERVICE_ENCODING = StandardCharsets.UTF_8; - static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; + public static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; static final int MAX_SCHEMA_MAP_SIZE_MINIMUM = 10; private final AzureSchemaRegistryRestService restService; private final int maxSchemaMapSize; - private final Map> typeParserMap; - private final Map guidCache; + private final ConcurrentSkipListMap> typeParserMap; + private final Map idCache; private final Map schemaStringCache; CachedSchemaRegistryClient( String registryUrl, HttpPipeline pipeline, int maxSchemaMapSize, - Map> typeParserMap) { + ConcurrentSkipListMap> typeParserMap) { if (CoreUtils.isNullOrEmpty(registryUrl)) { throw logger.logExceptionAsError( new IllegalArgumentException("Schema Registry URL cannot be null or empty.")); @@ -72,18 +74,18 @@ public final class CachedSchemaRegistryClient implements SchemaRegistryClient { this.maxSchemaMapSize = maxSchemaMapSize; this.typeParserMap = typeParserMap; - this.guidCache = new ConcurrentHashMap<>(); + this.idCache = new ConcurrentHashMap<>(); this.schemaStringCache = new ConcurrentHashMap<>(); } // testing - todo remove constructor and replace with mock CachedSchemaRegistryClient( AzureSchemaRegistryRestService restService, - Map guidCache, + Map idCache, Map schemaStringCache, - Map> typeParserMap) { + ConcurrentSkipListMap> typeParserMap) { this.restService = restService; // mockable - this.guidCache = guidCache; + this.idCache = idCache; this.schemaStringCache = schemaStringCache; this.typeParserMap = typeParserMap; this.maxSchemaMapSize = MAX_SCHEMA_MAP_SIZE_DEFAULT; @@ -107,11 +109,11 @@ public void loadSchemaParser(String schemaType, Function parseMe throw logger.logExceptionAsError( new IllegalArgumentException("Serialization type cannot be null or empty.")); } - if (this.typeParserMap.containsKey(schemaType.toLowerCase(Locale.ROOT))) { + if (this.typeParserMap.containsKey(schemaType)) { throw logger.logExceptionAsError( new IllegalArgumentException("Multiple parse methods for single serialization type may not be added.")); } - this.typeParserMap.putIfAbsent(schemaType.toLowerCase(Locale.ROOT), parseMethod); + this.typeParserMap.putIfAbsent(schemaType, parseMethod); logger.verbose( "Loaded parser for '{}' serialization format.", schemaType.toLowerCase(Locale.ROOT)); } @@ -150,9 +152,11 @@ public SchemaRegistryObject register( @Override public SchemaRegistryObject getSchemaByGuid(String schemaId) { - if (guidCache.containsKey(schemaId)) { + Objects.requireNonNull(schemaId, "'schemaId' should not be null"); + + if (idCache.containsKey(schemaId)) { logger.verbose("Cache hit for schema id '{}'", schemaId); - return guidCache.get(schemaId); + return idCache.get(schemaId); } GetSchemaByIdResponse response; @@ -175,7 +179,7 @@ public SchemaRegistryObject getSchemaByGuid(String schemaId) { getParseFunc(schemaType)); resetIfNeeded(); - guidCache.putIfAbsent(schemaId, schemaObject); + idCache.putIfAbsent(schemaId, schemaObject); logger.verbose("Cached schema object. Path: '{}'", schemaId); return schemaObject; } @@ -183,6 +187,8 @@ public SchemaRegistryObject getSchemaByGuid(String schemaId) { @Override public String getSchemaId( String schemaGroup, String schemaName, String schemaString, String schemaType) { + + if (schemaStringCache.containsKey(schemaString)) { logger.verbose("Cache hit schema string. Group: '{}', name: '{}'", schemaGroup, schemaName); return schemaStringCache.get(schemaString).getSchemaId(); @@ -212,28 +218,24 @@ public String getSchemaId( @Override public String deleteSchemaVersion(String schemaGroup, String schemaName, int version) { - throw new UnsupportedOperationException(); + throw logger.logExceptionAsError(new UnsupportedOperationException()); } @Override public String deleteLatestSchemaVersion(String schemaGroup, String schemaName) { - // return this.restService.deleteSchemaVersion(schemaName, null); - // remove from cache - return null; + throw logger.logExceptionAsError(new UnsupportedOperationException()); } @Override public List deleteSchema(String schemaGroup, String schemaName) { - // return this.restService.deleteSchema(); - // remove from cache - return null; + throw logger.logExceptionAsError(new UnsupportedOperationException()); } /** * Explicit call to clear all caches. */ public void reset() { - guidCache.clear(); + idCache.clear(); schemaStringCache.clear(); typeParserMap.clear(); } @@ -244,11 +246,13 @@ public void reset() { */ private void resetIfNeeded() { // todo add verbose log - if (guidCache.size() > this.maxSchemaMapSize) { - guidCache.clear(); + if (idCache.size() > this.maxSchemaMapSize) { + idCache.clear(); + logger.verbose("Cleared schema ID cache."); } if (schemaStringCache.size() > this.maxSchemaMapSize) { schemaStringCache.clear(); + logger.verbose("Cleared schema string cache."); } } @@ -259,7 +263,7 @@ private void resetIfNeeded() { * @return parse method for deserializing schema string */ private Function getParseFunc(String schemaType) { - Function parseFunc = typeParserMap.get(schemaType.toLowerCase(Locale.ROOT)); + Function parseFunc = typeParserMap.get(schemaType); if (parseFunc == null) { throw logger.logExceptionAsError(new SchemaRegistryClientException( diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java similarity index 90% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index 90573f0ae378..0edbb7c4f330 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client; +package com.azure.data.schemaregistry.client; import com.azure.core.annotation.ServiceClientBuilder; import com.azure.core.credential.TokenCredential; @@ -27,10 +27,9 @@ import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.function.Function; /** @@ -47,12 +46,12 @@ public class CachedSchemaRegistryClientBuilder { private static final RetryPolicy DEFAULT_RETRY_POLICY = new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS); - private final String schemaRegistryUrl; - private final ConcurrentHashMap> typeParserMap; + private final ConcurrentSkipListMap> typeParserMap; private final List policies; private final String clientName; private final String clientVersion; + private String schemaRegistryUrl; private HttpClient httpClient; private int maxSchemaMapSize; private TokenCredential credential; @@ -60,22 +59,38 @@ public class CachedSchemaRegistryClientBuilder { private HttpPipeline httpPipeline; private RetryPolicy retryPolicy; + /** + * Constructor for CachedSchemaRegistryClientBuilder. Supplies client defaults. + */ + public CachedSchemaRegistryClientBuilder() { + this.policies = new ArrayList<>(); + this.httpLogOptions = new HttpLogOptions(); + this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + this.typeParserMap = new ConcurrentSkipListMap<>(String.CASE_INSENSITIVE_ORDER); + this.httpClient = null; + this.credential = null; + this.retryPolicy = new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS); + + Map properties = CoreUtils.getProperties(CLIENT_PROPERTIES); + clientName = properties.getOrDefault(NAME, "UnknownName"); + clientVersion = properties.getOrDefault(VERSION, "UnknownVersion"); + } + /** * Sets the service endpoint for the Azure Schema Registry instance. - * Supplies client defaults. * + * @return The updated {@link CachedSchemaRegistryClientBuilder} object. * @param schemaRegistryUrl The URL of the Azure Schema Registry instance * @throws NullPointerException if {@code schemaRegistryUrl} is null - * @throws IllegalArgumentException if {@code schemaRegistryUrl} cannot be parsed into a valid URL. + * @throws IllegalArgumentException if {@code schemaRegistryUrl} cannot be parsed into a valid URL */ - public CachedSchemaRegistryClientBuilder(String schemaRegistryUrl) { - Objects.requireNonNull(schemaRegistryUrl, "'schemaRegistryUrl' cannot be null."); + public CachedSchemaRegistryClientBuilder host(String schemaRegistryUrl) { + Objects.requireNonNull(schemaRegistryUrl, "'endpoint' cannot be null."); try { new URL(schemaRegistryUrl); } catch (MalformedURLException ex) { - throw logger.logExceptionAsWarning( - new IllegalArgumentException("'schemaRegistryUrl' must be a valid URL.", ex)); + throw logger.logExceptionAsWarning(new IllegalArgumentException("'endpoint' must be a valid URL.", ex)); } if (schemaRegistryUrl.endsWith("/")) { @@ -84,17 +99,7 @@ public CachedSchemaRegistryClientBuilder(String schemaRegistryUrl) { this.schemaRegistryUrl = schemaRegistryUrl; } - this.policies = new ArrayList<>(); - this.httpLogOptions = new HttpLogOptions(); - this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; - this.typeParserMap = new ConcurrentHashMap<>(); - this.httpClient = null; - this.credential = null; - this.retryPolicy = new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS); - - Map properties = CoreUtils.getProperties(CLIENT_PROPERTIES); - clientName = properties.getOrDefault(NAME, "UnknownName"); - clientVersion = properties.getOrDefault(VERSION, "UnknownVersion"); + return this; } /** @@ -199,7 +204,7 @@ public CachedSchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { * Loads a parser method Function object used to convert schema strings returned from the Schema Registry * service into useable schema objects. * - * Any com.azure.schemaregistry.ByteEncoder or com.azure.schemaregistry.ByteDecoder class will implement + * Any com.azure.data.schemaregistry.ByteEncoder or com.azure.data.schemaregistry.ByteDecoder class will implement * - serializationFormat(), which specifies schema type, and * - parseSchemaString(), which parses schemas of the specified schema type from String to Object. * This method can be used by passing in a method reference, e.g. ByteEncoder::parseSchemaString. @@ -212,15 +217,15 @@ public CachedSchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { */ public CachedSchemaRegistryClientBuilder loadSchemaParser( String schemaType, Function parseMethod) { - if (schemaType == null || schemaType.isEmpty()) { + if (CoreUtils.isNullOrEmpty(schemaType)) { throw logger.logExceptionAsError( new IllegalArgumentException("Serialization type cannot be null or empty.")); } - if (this.typeParserMap.containsKey(schemaType.toLowerCase(Locale.ROOT))) { + if (this.typeParserMap.containsKey(schemaType)) { throw logger.logExceptionAsError( new IllegalArgumentException("Multiple parse methods for single serialization type may not be added.")); } - this.typeParserMap.put(schemaType.toLowerCase(Locale.ROOT), parseMethod); + this.typeParserMap.put(schemaType, parseMethod); return this; } @@ -255,7 +260,6 @@ public CachedSchemaRegistryClient buildClient() { HttpPolicyProviders.addBeforeRetryPolicies(policies); - policies.add(retryPolicy == null ? DEFAULT_RETRY_POLICY : retryPolicy); policies.add(new AddDatePolicy()); diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java index 28493a9a61fd..ee3f58b80160 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client; +package com.azure.data.schemaregistry.client; import java.nio.charset.Charset; import java.util.List; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java similarity index 93% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java index 30ae8f01e97e..5d40f72d5701 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryClientException.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client; +package com.azure.data.schemaregistry.client; import com.azure.core.exception.AzureException; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java similarity index 88% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java index 38e68766a1e9..7f593da1e945 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/SchemaRegistryObject.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client; +package com.azure.data.schemaregistry.client; import com.azure.core.util.logging.ClientLogger; import java.util.function.Function; @@ -60,12 +60,6 @@ public String getSchemaType() { * @return schema object, deserialized using stored schema parser method. */ public Object deserialize() { - if (parseMethod == null) { - throw logger.logExceptionAsError(new SchemaRegistryClientException( - String.format("No loaded parser for %s format. Schema guid: %s", - this.schemaType, this.schemaId))); - } - if (this.deserialized == null) { String schemaString = new String( this.schemaBytes, CachedSchemaRegistryClient.SCHEMA_REGISTRY_SERVICE_ENCODING); diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java index be95bbf34d67..f69a532755e3 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation; +package com.azure.data.schemaregistry.client.implementation; import com.azure.core.annotation.BodyParam; import com.azure.core.annotation.Delete; @@ -28,16 +28,16 @@ import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; -import com.azure.schemaregistry.client.implementation.models.CreateGroupResponse; -import com.azure.schemaregistry.client.implementation.models.CreateSchemaResponse; -import com.azure.schemaregistry.client.implementation.models.GetIdBySchemaContentResponse; -import com.azure.schemaregistry.client.implementation.models.GetLatestSchemaResponse; -import com.azure.schemaregistry.client.implementation.models.GetSchemaByIdResponse; -import com.azure.schemaregistry.client.implementation.models.GetSchemaVersionResponse; -import com.azure.schemaregistry.client.implementation.models.GetSchemaVersionsResponse; -import com.azure.schemaregistry.client.implementation.models.GetSchemasByGroupResponse; -import com.azure.schemaregistry.client.implementation.models.SchemaGroup; -import com.azure.schemaregistry.client.implementation.models.SchemaId; +import com.azure.data.schemaregistry.client.implementation.models.CreateGroupResponse; +import com.azure.data.schemaregistry.client.implementation.models.CreateSchemaResponse; +import com.azure.data.schemaregistry.client.implementation.models.GetIdBySchemaContentResponse; +import com.azure.data.schemaregistry.client.implementation.models.GetLatestSchemaResponse; +import com.azure.data.schemaregistry.client.implementation.models.GetSchemaByIdResponse; +import com.azure.data.schemaregistry.client.implementation.models.GetSchemaVersionResponse; +import com.azure.data.schemaregistry.client.implementation.models.GetSchemaVersionsResponse; +import com.azure.data.schemaregistry.client.implementation.models.GetSchemasByGroupResponse; +import com.azure.data.schemaregistry.client.implementation.models.SchemaGroup; +import com.azure.data.schemaregistry.client.implementation.models.SchemaId; import reactor.core.publisher.Mono; import java.util.List; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java similarity index 97% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java index 145f91e30e22..4dbf94d09ca5 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation; +package com.azure.data.schemaregistry.client.implementation; import com.azure.core.annotation.ServiceClientBuilder; import com.azure.core.http.HttpPipeline; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java similarity index 93% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java index c1eb5f7b3fa4..ba373f71b19d 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java similarity index 93% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java index 1c49cdf7c6f6..7f6b958bbd68 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateGroupResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java index 451f96f2ff69..be000bba9f56 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java index bd2b0ca2ca19..5612686cb87f 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/CreateSchemaResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java index 3b8dd56c0b11..e8b967ee584b 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java index 1cfa578edae1..4061fd93f937 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java index 0769486318df..bc155966690e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java index 88c43929cb76..b1aec099e868 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java index 0ab743c97a68..4facf3327dbe 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java index a6e0f156fd5c..9f5f8392a987 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java index 5a697d12158b..ebdce5e0585e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java index 8828783c35ed..4b4f3bfbc24c 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java index e10b7fd782ab..db011b690a66 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java index ed44dd9dd7f9..67afbfed471b 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java index af20a8b9765f..a8162e0af75a 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java index f2423081e837..796219fe422d 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaGroup.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaGroup.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java index be96fbb3e6b2..98d2e8e3ca71 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaGroup.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaId.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java similarity index 93% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaId.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java index 358eb330dcc4..6fa7927c4cc4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/SchemaId.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java similarity index 55% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/package-info.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java index 9f561b8f770d..a8f6474a639a 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/models/package-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java @@ -1,3 +1,3 @@ /** Package containing the data models for AzureSchemaRegistryRestService. null. */ -package com.azure.schemaregistry.client.implementation.models; +package com.azure.data.schemaregistry.client.implementation.models; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java similarity index 56% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/package-info.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java index 3f07bf1c49c9..b9afd3e65bc9 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/implementation/package-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java @@ -1,2 +1,2 @@ /** Package containing the classes for AzureSchemaRegistryRestService. null. */ -package com.azure.schemaregistry.client.rest; +package com.azure.data.schemaregistry.client.implementation; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/package-info.java similarity index 76% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/package-info.java index fbd8c34c6a4d..f6da76235f3a 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/schemaregistry/client/package-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/package-info.java @@ -4,4 +4,4 @@ * - CachedSchemaRegistryClient * - AzureSchemaRegistryRestService. */ -package com.azure.schemaregistry.client; +package com.azure.data.schemaregistry.client; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java index 7feee6499759..88867172521b 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java @@ -1,14 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -module com.azure.schemaregistry.client { +module com.azure.data.schemaregistry.client { requires transitive com.azure.core; - exports com.azure.schemaregistry.client; - exports com.azure.schemaregistry.client.rest; - exports com.azure.schemaregistry.client.rest.models; + exports com.azure.data.schemaregistry.client; - opens com.azure.schemaregistry.client to com.fasterxml.jackson.databind; - opens com.azure.schemaregistry.client.rest to com.fasterxml.jackson.databind, com.azure.core; - opens com.azure.schemaregistry.client.models to com.fasterxml.jackson.databind, com.azure.core; + opens com.azure.data.schemaregistry.client to com.fasterxml.jackson.databind; + opens com.azure.data.schemaregistry.client.rest to com.fasterxml.jackson.databind, com.azure.core; + opens com.azure.data.schemaregistry.client.models to com.fasterxml.jackson.databind, com.azure.core; } diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java similarity index 89% rename from sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java rename to sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java index c6a96f56d91e..a0c34758c930 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/schemaregistry/client/CachedSchemaRegistryClientTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.client; +package com.azure.data.schemaregistry.client; -import com.azure.schemaregistry.client.rest.AzureSchemaRegistryRestService; -import com.azure.schemaregistry.client.rest.models.GetSchemaByIdHeaders; -import com.azure.schemaregistry.client.rest.models.GetSchemaByIdResponse; -import com.azure.schemaregistry.client.rest.models.SchemaId; +import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestService; +import com.azure.data.schemaregistry.client.implementation.models.GetSchemaByIdHeaders; +import com.azure.data.schemaregistry.client.implementation.models.GetSchemaByIdResponse; +import com.azure.data.schemaregistry.client.implementation.models.SchemaId; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.UUID; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.function.Function; import static org.mockito.Mockito.*; @@ -33,14 +34,14 @@ public class CachedSchemaRegistryClientTest { private AzureSchemaRegistryRestService restService; private HashMap guidCache; private HashMap schemaStringCache; - private HashMap> typeParserDictionary; + private ConcurrentSkipListMap> typeParserDictionary; @BeforeEach protected void setUp() { this.guidCache = new HashMap(); this.schemaStringCache = new HashMap(); - this.typeParserDictionary = new HashMap>(); + this.typeParserDictionary = new ConcurrentSkipListMap<>(String.CASE_INSENSITIVE_ORDER); this.typeParserDictionary.put(MOCK_SERIALIZATION, (s) -> s); this.restService = mock(AzureSchemaRegistryRestService.class); diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml index c917d04898c5..b8272ee04ef4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml @@ -17,11 +17,11 @@ com.azure - azure-schemaregistry-serde-avro + azure-data-schemaregistry-serde-avro 1.0.0-beta.1 Microsoft Azure Schema Registry - Avro-specific package for client library - Avro-specific package for Azure Schema Registry client library + Avro-specih,fic package for Azure Schema Registry client library https://github.com/Azure/azure-sdk-for-java @@ -44,7 +44,7 @@ com.azure - azure-schemaregistry-serde-common + azure-data-schemaregistry-serde-common 1.0.0-beta.1 compile diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java similarity index 95% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java index 2dde25396263..d91e45106f15 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteDecoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; import com.azure.core.util.logging.ClientLogger; -import com.azure.schemaregistry.ByteDecoder; -import com.azure.schemaregistry.SerializationException; +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; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java similarity index 95% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java index 20f9cf8566d8..f0e9693be0fc 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroByteEncoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; import com.azure.core.util.logging.ClientLogger; -import com.azure.schemaregistry.ByteEncoder; -import com.azure.schemaregistry.SerializationException; +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; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java similarity index 86% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java index 1ad70cc478b4..27865e57bfb1 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroCodec.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; -import com.azure.schemaregistry.Codec; +import com.azure.data.schemaregistry.Codec; import org.apache.avro.Schema; /** diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java index 9449591d1d2e..5bfed3df0278 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/AvroSchemaUtils.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; import com.azure.core.util.logging.ClientLogger; import org.apache.avro.Schema; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java similarity index 93% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java index 11e670633d01..c364c2962cc2 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; -import com.azure.schemaregistry.SerializationException; +import com.azure.data.schemaregistry.SerializationException; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; import reactor.core.scheduler.Schedulers; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java similarity index 89% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java index a9e6458bec9b..05624146404c 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; -import com.azure.schemaregistry.AbstractDataSerializer; -import com.azure.schemaregistry.SerializationException; +import com.azure.data.schemaregistry.AbstractDataSerializer; +import com.azure.data.schemaregistry.SerializationException; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; import reactor.core.scheduler.Schedulers; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java similarity index 78% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java index c4b117af0ce3..267b7aa21ffa 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; import com.azure.core.credential.TokenCredential; -import com.azure.schemaregistry.AbstractDataDeserializer; -import com.azure.schemaregistry.SerializationException; -import com.azure.schemaregistry.client.CachedSchemaRegistryClientBuilder; +import com.azure.data.schemaregistry.AbstractDataDeserializer; +import com.azure.data.schemaregistry.SerializationException; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClientBuilder; /** * A deserializer implementation capable of automatedly deserializing encoded byte array payloads into Java objects by @@ -23,10 +23,11 @@ public class SchemaRegistryAvroDeserializer extends AbstractDataDeserializer { TokenCredential credential, boolean avroSpecificReader, int maxSchemaMapSize) { - super(new CachedSchemaRegistryClientBuilder(registryUrl) - .credential(credential) - .maxSchemaMapSize(maxSchemaMapSize) - .buildClient()); + super(new CachedSchemaRegistryClientBuilder() + .host(registryUrl) + .credential(credential) + .maxSchemaMapSize(maxSchemaMapSize) + .buildClient()); loadByteDecoder(new AvroByteDecoder(avroSpecificReader)); } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java similarity index 96% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java index bcce9ba0cd6e..906eefae2e81 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; import com.azure.core.credential.TokenCredential; -import com.azure.schemaregistry.client.CachedSchemaRegistryClient; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClient; /** * Builder class for constructing {@link SchemaRegistryAvroDeserializer} and {@link SchemaRegistryAvroAsyncDeserializer} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java similarity index 84% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java index abcd81c3b557..af412ed394c2 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; import com.azure.core.credential.TokenCredential; -import com.azure.schemaregistry.AbstractDataSerializer; -import com.azure.schemaregistry.SerializationException; -import com.azure.schemaregistry.client.CachedSchemaRegistryClientBuilder; +import com.azure.data.schemaregistry.AbstractDataSerializer; +import com.azure.data.schemaregistry.SerializationException; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClientBuilder; /** * A serializer implementation capable of serializing objects and automatedly storing serialization schemas @@ -24,7 +24,8 @@ public class SchemaRegistryAvroSerializer extends AbstractDataSerializer { String schemaGroup, boolean autoRegisterSchemas, int maxSchemaMapSize) { - super(new CachedSchemaRegistryClientBuilder(registryUrl) + super(new CachedSchemaRegistryClientBuilder() + .host(registryUrl) .credential(credential) .maxSchemaMapSize(maxSchemaMapSize) .buildClient()); diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java similarity index 96% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java index 746b1ca3322c..22baf9bb3758 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; import com.azure.core.credential.TokenCredential; -import com.azure.schemaregistry.AbstractDataSerializer; -import com.azure.schemaregistry.client.CachedSchemaRegistryClient; +import com.azure.data.schemaregistry.AbstractDataSerializer; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClient; /** * Builder implemenation for building {@link SchemaRegistryAvroSerializer} and {@link SchemaRegistryAvroAsyncSerializer} diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/package-info.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java similarity index 79% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/package-info.java rename to sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java index 190a1761edda..815a7707a645 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/schemaregistry/avro/package-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java @@ -2,4 +2,4 @@ * Package containing Avro-specific serializer and deserializer implementations. * Also contains the Avro codec utility classes required for all serde operations. */ -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java index 47ca5f0e40a7..2418ccc22285 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -module com.azure.schemaregistry.serde.avro { +module com.azure.data.schemaregistry.serde.avro { requires transitive com.azure.core; - exports com.azure.schemaregistry.serde.avro; + exports com.azure.data.schemaregistry.serde.avro; } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java index 19695d87eca5..6732085e8911 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; import org.junit.jupiter.api.Test; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java index 7faada8a2ce5..2f3188989917 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry.avro; +package com.azure.data.schemaregistry.avro; import org.junit.jupiter.api.Test; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml index 41fb1fc5c221..4f46693c2ed4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml @@ -15,7 +15,7 @@ com.azure - azure-schemaregistry-serde-common + azure-data-schemaregistry-serde-common jar 1.0.0-beta.1 @@ -48,7 +48,7 @@ com.azure - azure-schemaregistry-client + azure-data-schemaregistry-client 1.0.0-beta.1 diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java similarity index 92% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java index 6bb9e074606c..88c830d10776 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; import com.azure.core.util.logging.ClientLogger; -import com.azure.schemaregistry.client.SchemaRegistryObject; -import com.azure.schemaregistry.client.SchemaRegistryClient; -import com.azure.schemaregistry.client.SchemaRegistryClientException; +import com.azure.data.schemaregistry.client.SchemaRegistryObject; +import com.azure.data.schemaregistry.client.SchemaRegistryClient; +import com.azure.data.schemaregistry.client.SchemaRegistryClientException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; @@ -58,7 +58,7 @@ protected Object deserialize(byte[] payload) throws SerializationException { payloadSchema = registryObject.deserialize(); } catch (SchemaRegistryClientException e) { throw logger.logExceptionAsError( - new SerializationException(String.format("Failed to retrieve schema for id ", schemaGuid), e)); + new SerializationException(String.format("Failed to retrieve schema for id %s", schemaGuid), e)); } // TODO: how to handle unknown formats @@ -90,7 +90,8 @@ private ByteDecoder getByteDecoder(SchemaRegistryObject registryObject) throws S if (decoder == null) { throw logger.logExceptionAsError( new SerializationException( - String.format("No decoder class found for serialization type ", registryObject.getSchemaType()))); + String.format("No decoder class found for serialization type '%s'", registryObject.getSchemaType()) + )); } return decoder; } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java similarity index 92% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java index c02412a4e8e7..b2bc450371b6 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerDe.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; import com.azure.core.util.logging.ClientLogger; -import com.azure.schemaregistry.client.SchemaRegistryClient; +import com.azure.data.schemaregistry.client.SchemaRegistryClient; /** * Common fields and helper methods for both the serializer and the deserializer. diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java similarity index 96% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java index 8d4a4c237c3c..9164d3fdeea0 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/AbstractDataSerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; import com.azure.core.util.logging.ClientLogger; -import com.azure.schemaregistry.client.SchemaRegistryClient; -import com.azure.schemaregistry.client.SchemaRegistryClientException; +import com.azure.data.schemaregistry.client.SchemaRegistryClient; +import com.azure.data.schemaregistry.client.SchemaRegistryClientException; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteDecoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java index 41f3273106c1..70a06f339afb 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteDecoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; /** * An interface defining operations required for registry deserializer to convert encoded bytes to Java object. diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java similarity index 97% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java index aba4ef428a1e..734b154c162a 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/ByteEncoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; import java.io.ByteArrayOutputStream; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/Codec.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/Codec.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java index 5e13b747659e..c1c035ebdcb1 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/Codec.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; /** * Base interface for all ByteEncoder and ByteDecoder interfaces diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/SerializationException.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/SerializationException.java similarity index 94% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/SerializationException.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/SerializationException.java index 6ca1c8d69e6e..b22134563c12 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/SerializationException.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/SerializationException.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; /** * Exception thrown by Schema Registry serializer/deserializer implementations for runtime error cases. diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/package-info.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/package-info.java similarity index 74% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/package-info.java rename to sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/package-info.java index 5e674e17640f..f04c2e22d1ed 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/schemaregistry/package-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/package-info.java @@ -1,4 +1,4 @@ /** * Package containing core serialization and deserialization implementations for Azure Schema Registry SDK. */ -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java index 061031d4d0b0..1c5128fd6722 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -module com.azure.schemaregistry.serde.common { +module com.azure.data.schemaregistry.serde.common { requires com.azure.core; - exports com.azure.schemaregistry; + exports com.azure.data.schemaregistry; - opens com.azure.schemaregistry to com.fasterxml.jackson.databind, com.azure.core; + opens com.azure.data.schemaregistry to com.fasterxml.jackson.databind, com.azure.core; } diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java index 4b2c25e7c275..b2ee94f5338e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; -import com.azure.schemaregistry.client.SchemaRegistryObject; -import com.azure.schemaregistry.client.SchemaRegistryClientException; +import com.azure.data.schemaregistry.client.SchemaRegistryObject; +import com.azure.data.schemaregistry.client.SchemaRegistryClientException; import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericDatumWriter; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java index 7166624fc616..b47d4448c8ea 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; -import com.azure.schemaregistry.client.SchemaRegistryObject; +import com.azure.data.schemaregistry.client.SchemaRegistryObject; import org.junit.jupiter.api.Test; import java.nio.BufferUnderflowException; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java index 426c6dad5613..17f485032572 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; -import com.azure.schemaregistry.client.SchemaRegistryClient; -import com.azure.schemaregistry.client.SchemaRegistryClientException; -import com.azure.schemaregistry.client.SchemaRegistryObject; +import com.azure.data.schemaregistry.client.SchemaRegistryClient; +import com.azure.data.schemaregistry.client.SchemaRegistryClientException; +import com.azure.data.schemaregistry.client.SchemaRegistryObject; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java index a7bf175749c1..3a22e4ff42e8 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; import org.apache.avro.Schema; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java index 5d7b686fe480..442727488ab8 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java index 9c2027e4bcf1..e47528f4ae2f 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; -import com.azure.schemaregistry.client.SchemaRegistryClient; +import com.azure.data.schemaregistry.client.SchemaRegistryClient; public class TestDummyDeserializer extends AbstractDataDeserializer { TestDummyDeserializer(SchemaRegistryClient mockClient) { diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java index a48cb3ac9f86..9844b9caaaad 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java +++ b/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.schemaregistry; +package com.azure.data.schemaregistry; -import com.azure.schemaregistry.client.SchemaRegistryClient; +import com.azure.data.schemaregistry.client.SchemaRegistryClient; public class TestDummySerializer extends AbstractDataSerializer { TestDummySerializer( diff --git a/sdk/schemaregistry/ci.yml b/sdk/schemaregistry/ci.yml index 0fcdb17e44ff..703e22a66a05 100644 --- a/sdk/schemaregistry/ci.yml +++ b/sdk/schemaregistry/ci.yml @@ -37,12 +37,12 @@ stages: parameters: ServiceDirectory: schemaregistry Artifacts: - - name: azure-schemaregistry-client + - name: azure-data-schemaregistry-client groupId: com.azure - safeName: azureschemaregistryclient - - name: azure-schemaregistry-serde-common + safeName: azuredataschemaregistryclient + - name: azure-data-schemaregistry-serde-common groupId: com.azure - safeName: azureschemaregistryserdecommon - - name: azure-schemaregistry-serde-avro + safeName: azuredataschemaregistryserdecommon + - name: azure-data-schemaregistry-serde-avro groupId: com.azure - safeName: azureschemaregistryserde-avro + safeName: azuredataschemaregistryserde-avro From b855cd00761662d2d845a68ea753ef0a5e96d29e Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 27 May 2020 17:42:18 -0700 Subject: [PATCH 34/43] move rest service builder --- .../client/CachedSchemaRegistryClient.java | 15 ++------------- .../client/CachedSchemaRegistryClientBuilder.java | 13 ++++++++----- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java index 3e43c77941d1..cff79d32ed5b 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java @@ -9,7 +9,6 @@ import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestService; -import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestServiceClientBuilder; import com.azure.data.schemaregistry.client.implementation.models.GetSchemaByIdResponse; import com.azure.data.schemaregistry.client.implementation.models.SchemaId; @@ -58,20 +57,10 @@ public final class CachedSchemaRegistryClient implements SchemaRegistryClient { private final Map schemaStringCache; CachedSchemaRegistryClient( - String registryUrl, - HttpPipeline pipeline, + AzureSchemaRegistryRestService restService, int maxSchemaMapSize, ConcurrentSkipListMap> typeParserMap) { - if (CoreUtils.isNullOrEmpty(registryUrl)) { - throw logger.logExceptionAsError( - new IllegalArgumentException("Schema Registry URL cannot be null or empty.")); - } - - this.restService = new AzureSchemaRegistryRestServiceClientBuilder() - .host(registryUrl) - .pipeline(pipeline) - .buildClient(); - + this.restService = restService; this.maxSchemaMapSize = maxSchemaMapSize; this.typeParserMap = typeParserMap; this.idCache = new ConcurrentHashMap<>(); diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index 0edbb7c4f330..986c4115a197 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -21,6 +21,8 @@ import com.azure.core.util.Configuration; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; +import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestService; +import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestServiceClientBuilder; import java.net.MalformedURLException; import java.net.URL; @@ -277,10 +279,11 @@ public CachedSchemaRegistryClient buildClient() { .build(); } - return new CachedSchemaRegistryClient( - schemaRegistryUrl, - pipeline, - maxSchemaMapSize, - typeParserMap); + AzureSchemaRegistryRestService restService = new AzureSchemaRegistryRestServiceClientBuilder() + .host(this.schemaRegistryUrl) + .pipeline(pipeline) + .buildClient(); + + return new CachedSchemaRegistryClient(restService, maxSchemaMapSize, typeParserMap); } } From 850201a2c0e6907248dd8ff0ff2b9d5234c87150 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Wed, 27 May 2020 17:47:26 -0700 Subject: [PATCH 35/43] update dirs and repo files --- .../src/main/resources/spotbugs/spotbugs-exclude.xml | 2 +- eng/jacoco-test-coverage/pom.xml | 12 ++++++------ eng/versioning/version_client.txt | 6 +++--- .../README.md | 0 .../pom.xml | 2 +- .../resources/azure-schemaregistry-client.properties | 0 .../client/CachedSchemaRegistryClient.java | 1 - .../client/CachedSchemaRegistryClientBuilder.java | 0 .../schemaregistry/client/SchemaRegistryClient.java | 0 .../client/SchemaRegistryClientException.java | 0 .../schemaregistry/client/SchemaRegistryObject.java | 0 .../AzureSchemaRegistryRestService.java | 0 .../AzureSchemaRegistryRestServiceClientBuilder.java | 0 .../implementation/models/CreateGroupHeaders.java | 0 .../implementation/models/CreateGroupResponse.java | 0 .../implementation/models/CreateSchemaHeaders.java | 0 .../implementation/models/CreateSchemaResponse.java | 0 .../models/GetIdBySchemaContentHeaders.java | 0 .../models/GetIdBySchemaContentResponse.java | 0 .../models/GetLatestSchemaHeaders.java | 0 .../models/GetLatestSchemaResponse.java | 0 .../implementation/models/GetSchemaByIdHeaders.java | 0 .../implementation/models/GetSchemaByIdResponse.java | 0 .../models/GetSchemaVersionHeaders.java | 0 .../models/GetSchemaVersionResponse.java | 0 .../models/GetSchemaVersionsHeaders.java | 0 .../models/GetSchemaVersionsResponse.java | 0 .../models/GetSchemasByGroupHeaders.java | 0 .../models/GetSchemasByGroupResponse.java | 0 .../client/implementation/models/SchemaGroup.java | 0 .../client/implementation/models/SchemaId.java | 0 .../client/implementation/models/package-info.java | 0 .../client/implementation/package-info.java | 0 .../data/schemaregistry/client/package-info.java | 0 .../src/main/module-info.java | 0 .../client/CachedSchemaRegistryClientTest.java | 0 .../mockito-extensions/org.mockito.plugins.MockMaker | 0 .../swagger/swagger.yaml | 0 .../README.md | 0 .../pom.xml | 4 ++-- .../data/schemaregistry/avro/AvroByteDecoder.java | 0 .../data/schemaregistry/avro/AvroByteEncoder.java | 0 .../azure/data/schemaregistry/avro/AvroCodec.java | 0 .../data/schemaregistry/avro/AvroSchemaUtils.java | 0 .../avro/SchemaRegistryAvroAsyncDeserializer.java | 0 .../avro/SchemaRegistryAvroAsyncSerializer.java | 0 .../avro/SchemaRegistryAvroDeserializer.java | 0 .../avro/SchemaRegistryAvroDeserializerBuilder.java | 0 .../avro/SchemaRegistryAvroSerializer.java | 0 .../avro/SchemaRegistryAvroSerializerBuilder.java | 0 .../azure/data/schemaregistry/avro/package-info.java | 0 .../src/main/module-info.java | 0 .../schemaregistry/avro/AvroByteDecoderTest.java | 0 .../schemaregistry/avro/AvroByteEncoderTest.java | 0 .../README.md | 0 .../pom.xml | 4 ++-- .../schemaregistry/AbstractDataDeserializer.java | 0 .../azure/data/schemaregistry/AbstractDataSerDe.java | 0 .../data/schemaregistry/AbstractDataSerializer.java | 0 .../com/azure/data/schemaregistry/ByteDecoder.java | 0 .../com/azure/data/schemaregistry/ByteEncoder.java | 0 .../java/com/azure/data/schemaregistry/Codec.java | 0 .../data/schemaregistry/SerializationException.java | 0 .../com/azure/data/schemaregistry/package-info.java | 0 .../src/main/module-info.java | 0 .../schemaregistry/AbstractDataDeserializerTest.java | 0 .../schemaregistry/AbstractDataSerializerTest.java | 0 .../schemaregistry/MockSchemaRegistryClient.java | 0 .../com/azure/schemaregistry/SampleByteDecoder.java | 0 .../com/azure/schemaregistry/SampleByteEncoder.java | 0 .../azure/schemaregistry/TestDummyDeserializer.java | 0 .../azure/schemaregistry/TestDummySerializer.java | 0 sdk/schemaregistry/pom.xml | 10 +++++----- 73 files changed, 20 insertions(+), 21 deletions(-) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/README.md (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/pom.xml (98%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/resources/azure-schemaregistry-client.properties (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java (99%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/java/com/azure/data/schemaregistry/client/package-info.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/main/module-info.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker (100%) rename sdk/schemaregistry/{azure-schemaregistry-client => azure-data-schemaregistry-client}/swagger/swagger.yaml (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/README.md (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/pom.xml (96%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/java/com/azure/data/schemaregistry/avro/package-info.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/main/module-info.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-avro => azure-data-schemaregistry-serde-avro}/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/README.md (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/pom.xml (97%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/main/java/com/azure/data/schemaregistry/Codec.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/main/java/com/azure/data/schemaregistry/SerializationException.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/main/java/com/azure/data/schemaregistry/package-info.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/main/module-info.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java (100%) rename sdk/schemaregistry/{azure-schemaregistry-serde-common => azure-data-schemaregistry-serde-common}/src/test/java/com/azure/schemaregistry/TestDummySerializer.java (100%) diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index 5873a175f954..b1887cf0e539 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -1900,7 +1900,7 @@ - + diff --git a/eng/jacoco-test-coverage/pom.xml b/eng/jacoco-test-coverage/pom.xml index db4e490c103c..cc45f0248593 100644 --- a/eng/jacoco-test-coverage/pom.xml +++ b/eng/jacoco-test-coverage/pom.xml @@ -189,18 +189,18 @@ com.azure - azure-schemaregistry-client - 1.0.0-beta.1 + azure-data-schemaregistry-client + 1.0.0-beta.1 com.azure - azure-schemaregistry-serde-avro - 1.0.0-beta.1 + azure-data-schemaregistry-serde-avro + 1.0.0-beta.1 com.azure - azure-schemaregistry-serde-common - 1.0.0-beta.1 + azure-data-schemaregistry-serde-common + 1.0.0-beta.1 com.microsoft.azure diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index 466125dc2dd0..1bb425a7f801 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -26,9 +26,9 @@ com.azure:azure-identity-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-messaging-eventhubs;5.1.0;5.2.0-beta.1 com.azure:azure-messaging-eventhubs-checkpointstore-blob;1.1.0;1.2.0-beta.1 com.azure:azure-messaging-servicebus;7.0.0-beta.2;7.0.0-beta.3 -com.azure:azure-schemaregistry-client;1.0.0-beta.1;1.0.0-beta.1 -com.azure:azure-schemaregistry-serde-common;1.0.0-beta.1;1.0.0-beta.1 -com.azure:azure-schemaregistry-serde-avro;1.0.0-beta.1;1.0.0-beta.1 +com.azure:azure-data-schemaregistry-client;1.0.0-beta.1;1.0.0-beta.1 +com.azure:azure-data-schemaregistry-serde-common;1.0.0-beta.1;1.0.0-beta.1 +com.azure:azure-data-schemaregistry-serde-avro;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-search-documents;1.0.0-beta.3;1.0.0-beta.4 com.azure:azure-security-keyvault-certificates;4.1.0-beta.2;4.1.0-beta.3 com.azure:azure-security-keyvault-keys;4.2.0-beta.3;4.2.0-beta.4 diff --git a/sdk/schemaregistry/azure-schemaregistry-client/README.md b/sdk/schemaregistry/azure-data-schemaregistry-client/README.md similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/README.md rename to sdk/schemaregistry/azure-data-schemaregistry-client/README.md diff --git a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry-client/pom.xml similarity index 98% rename from sdk/schemaregistry/azure-schemaregistry-client/pom.xml rename to sdk/schemaregistry/azure-data-schemaregistry-client/pom.xml index 50397517a8e5..7fda107e4ce8 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry-client/pom.xml @@ -17,7 +17,7 @@ com.azure azure-data-schemaregistry-client jar - 1.0.0-beta.1 + 1.0.0-beta.1 Microsoft Azure Schema Registry - REST Client REST client implementation for Azure Schema Registry diff --git a/sdk/schemaregistry/azure-schemaregistry-client/resources/azure-schemaregistry-client.properties b/sdk/schemaregistry/azure-data-schemaregistry-client/resources/azure-schemaregistry-client.properties similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/resources/azure-schemaregistry-client.properties rename to sdk/schemaregistry/azure-data-schemaregistry-client/resources/azure-schemaregistry-client.properties diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java similarity index 99% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java index cff79d32ed5b..3899f9f5a43d 100644 --- a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java @@ -5,7 +5,6 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.exception.HttpResponseException; -import com.azure.core.http.HttpPipeline; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestService; diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/package-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/module-info.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/main/module-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/main/module-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java diff --git a/sdk/schemaregistry/azure-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/sdk/schemaregistry/azure-data-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker rename to sdk/schemaregistry/azure-data-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/sdk/schemaregistry/azure-schemaregistry-client/swagger/swagger.yaml b/sdk/schemaregistry/azure-data-schemaregistry-client/swagger/swagger.yaml similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-client/swagger/swagger.yaml rename to sdk/schemaregistry/azure-data-schemaregistry-client/swagger/swagger.yaml diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/README.md similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/README.md rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/README.md diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/pom.xml similarity index 96% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/pom.xml index b8272ee04ef4..7d12bf329597 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-avro/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/pom.xml @@ -18,7 +18,7 @@ com.azure azure-data-schemaregistry-serde-avro - 1.0.0-beta.1 + 1.0.0-beta.1 Microsoft Azure Schema Registry - Avro-specific package for client library Avro-specih,fic package for Azure Schema Registry client library @@ -45,7 +45,7 @@ com.azure azure-data-schemaregistry-serde-common - 1.0.0-beta.1 + 1.0.0-beta.1 compile diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/module-info.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/main/module-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/module-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/README.md b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/README.md similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/README.md rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/README.md diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/pom.xml similarity index 97% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/pom.xml index 4f46693c2ed4..4dd43529c5aa 100644 --- a/sdk/schemaregistry/azure-schemaregistry-serde-common/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/pom.xml @@ -17,7 +17,7 @@ com.azure azure-data-schemaregistry-serde-common jar - 1.0.0-beta.1 + 1.0.0-beta.1 Microsoft Azure Schema Registry - Common SerDe Package for client library Common SerDe Package containing base serialization/deserialization implementation for Azure Schema Registry client library @@ -49,7 +49,7 @@ com.azure azure-data-schemaregistry-client - 1.0.0-beta.1 + 1.0.0-beta.1 diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/SerializationException.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/SerializationException.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/SerializationException.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/SerializationException.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/package-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/module-info.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/main/module-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/module-info.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java diff --git a/sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java b/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java similarity index 100% rename from sdk/schemaregistry/azure-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java diff --git a/sdk/schemaregistry/pom.xml b/sdk/schemaregistry/pom.xml index e82b93970121..b059fc462945 100644 --- a/sdk/schemaregistry/pom.xml +++ b/sdk/schemaregistry/pom.xml @@ -8,12 +8,12 @@ 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"> 4.0.0 com.azure - azure-schemaregistry + azure-data-schemaregistry pom 1.0.0 - azure-schemaregistry-client - azure-schemaregistry-serde-common - azure-schemaregistry-serde-avro + azure-data-schemaregistry-client + azure-data-schemaregistry-serde-common + azure-data-schemaregistry-serde-avro - \ No newline at end of file + From 6b1ee4e13efcd0ec118bdafc4d273b01874131ab Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 28 May 2020 12:46:17 -0700 Subject: [PATCH 36/43] update package structure --- .../README.md | 0 .../pom.xml | 8 +- .../schemaregistry/avro/AvroByteDecoder.java | 0 .../schemaregistry/avro/AvroByteEncoder.java | 0 .../data/schemaregistry/avro/AvroCodec.java | 2 +- .../schemaregistry/avro/AvroSchemaUtils.java | 0 .../SchemaRegistryAvroAsyncDeserializer.java | 0 .../SchemaRegistryAvroAsyncSerializer.java | 0 .../avro/SchemaRegistryAvroDeserializer.java | 4 +- ...SchemaRegistryAvroDeserializerBuilder.java | 5 +- .../avro/SchemaRegistryAvroSerializer.java | 4 +- .../SchemaRegistryAvroSerializerBuilder.java | 5 +- .../schemaregistry/avro/package-info.java | 0 .../src/main/module-info.java | 0 .../avro/AvroByteDecoderTest.java | 0 .../avro/AvroByteEncoderTest.java | 0 .../README.md | 17 ---- .../azure-data-schemaregistry-client/pom.xml | 84 ------------------- .../src/main/module-info.java | 12 --- .../README.md | 0 .../pom.xml | 20 +++-- ...ure-data-schemaregistry-client.properties} | 0 .../AbstractDataDeserializer.java | 8 +- .../schemaregistry/AbstractDataSerDe.java | 0 .../AbstractDataSerializer.java | 12 +-- .../data/schemaregistry/ByteDecoder.java | 0 .../data/schemaregistry/ByteEncoder.java | 0 .../com/azure/data/schemaregistry/Codec.java | 6 +- .../SerializationException.java | 0 .../client/CachedSchemaRegistryClient.java | 35 ++++---- .../CachedSchemaRegistryClientBuilder.java | 30 +++---- .../client/SchemaRegistryClient.java | 23 ++--- .../client/SchemaRegistryClientException.java | 0 .../client/SchemaRegistryObject.java | 0 .../AzureSchemaRegistryRestService.java | 0 ...chemaRegistryRestServiceClientBuilder.java | 0 .../models/CreateGroupHeaders.java | 0 .../models/CreateGroupResponse.java | 0 .../models/CreateSchemaHeaders.java | 0 .../models/CreateSchemaResponse.java | 0 .../models/GetIdBySchemaContentHeaders.java | 0 .../models/GetIdBySchemaContentResponse.java | 0 .../models/GetLatestSchemaHeaders.java | 0 .../models/GetLatestSchemaResponse.java | 0 .../models/GetSchemaByIdHeaders.java | 0 .../models/GetSchemaByIdResponse.java | 0 .../models/GetSchemaVersionHeaders.java | 0 .../models/GetSchemaVersionResponse.java | 0 .../models/GetSchemaVersionsHeaders.java | 0 .../models/GetSchemaVersionsResponse.java | 0 .../models/GetSchemasByGroupHeaders.java | 0 .../models/GetSchemasByGroupResponse.java | 0 .../implementation/models/SchemaGroup.java | 0 .../implementation/models/SchemaId.java | 0 .../implementation/models/package-info.java | 0 .../client/implementation/package-info.java | 0 .../schemaregistry/client/package-info.java | 0 .../data/schemaregistry/package-info.java | 0 .../src/main/module-info.java | 1 + .../AbstractDataDeserializerTest.java | 2 +- .../AbstractDataSerializerTest.java | 2 +- .../MockSchemaRegistryClient.java | 6 +- .../schemaregistry/SampleByteDecoder.java | 2 +- .../schemaregistry/SampleByteEncoder.java | 2 +- .../schemaregistry/TestDummyDeserializer.java | 2 +- .../schemaregistry/TestDummySerializer.java | 0 .../CachedSchemaRegistryClientTest.java | 0 .../org.mockito.plugins.MockMaker | 0 .../swagger/swagger.yaml | 0 sdk/schemaregistry/ci.yml | 11 +-- sdk/schemaregistry/pom.xml | 7 +- 71 files changed, 101 insertions(+), 209 deletions(-) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/README.md (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/pom.xml (93%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java (93%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java (95%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java (94%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java (95%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java (95%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/java/com/azure/data/schemaregistry/avro/package-info.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/main/module-info.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-avro => azure-data-schemaregistry-avro}/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java (100%) delete mode 100644 sdk/schemaregistry/azure-data-schemaregistry-client/README.md delete mode 100644 sdk/schemaregistry/azure-data-schemaregistry-client/pom.xml delete mode 100644 sdk/schemaregistry/azure-data-schemaregistry-client/src/main/module-info.java rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/README.md (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/pom.xml (82%) rename sdk/schemaregistry/{azure-data-schemaregistry-client/resources/azure-schemaregistry-client.properties => azure-data-schemaregistry/resources/azure-data-schemaregistry-client.properties} (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java (92%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java (93%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/Codec.java (77%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/SerializationException.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java (90%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java (92%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java (80%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/client/package-info.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/src/main/java/com/azure/data/schemaregistry/package-info.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common => azure-data-schemaregistry}/src/main/module-info.java (86%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common/src/test/java/com/azure => azure-data-schemaregistry/src/test/java/com/azure/data}/schemaregistry/AbstractDataDeserializerTest.java (99%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common/src/test/java/com/azure => azure-data-schemaregistry/src/test/java/com/azure/data}/schemaregistry/AbstractDataSerializerTest.java (98%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common/src/test/java/com/azure => azure-data-schemaregistry/src/test/java/com/azure/data}/schemaregistry/MockSchemaRegistryClient.java (93%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common/src/test/java/com/azure => azure-data-schemaregistry/src/test/java/com/azure/data}/schemaregistry/SampleByteDecoder.java (93%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common/src/test/java/com/azure => azure-data-schemaregistry/src/test/java/com/azure/data}/schemaregistry/SampleByteEncoder.java (96%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common/src/test/java/com/azure => azure-data-schemaregistry/src/test/java/com/azure/data}/schemaregistry/TestDummyDeserializer.java (83%) rename sdk/schemaregistry/{azure-data-schemaregistry-serde-common/src/test/java/com/azure => azure-data-schemaregistry/src/test/java/com/azure/data}/schemaregistry/TestDummySerializer.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker (100%) rename sdk/schemaregistry/{azure-data-schemaregistry-client => azure-data-schemaregistry}/swagger/swagger.yaml (100%) diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/README.md b/sdk/schemaregistry/azure-data-schemaregistry-avro/README.md similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/README.md rename to sdk/schemaregistry/azure-data-schemaregistry-avro/README.md diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml similarity index 93% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/pom.xml rename to sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml index 7d12bf329597..552daf8eec4f 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml @@ -17,8 +17,8 @@ com.azure - azure-data-schemaregistry-serde-avro - 1.0.0-beta.1 + azure-data-schemaregistry-avro + 1.0.0-beta.1 Microsoft Azure Schema Registry - Avro-specific package for client library Avro-specih,fic package for Azure Schema Registry client library @@ -44,8 +44,8 @@ com.azure - azure-data-schemaregistry-serde-common - 1.0.0-beta.1 + azure-data-schemaregistry + 1.0.0-beta.1 compile diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java similarity index 93% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java index 27865e57bfb1..29b9524b8141 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java @@ -10,7 +10,7 @@ * Base Codec class for Avro encoder and decoder implementations */ abstract class AvroCodec implements Codec { - public String serializationFormat() { + public String schemaType() { return "avro"; } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java similarity index 95% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java index 267b7aa21ffa..fd749f413273 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java @@ -22,9 +22,9 @@ public class SchemaRegistryAvroDeserializer extends AbstractDataDeserializer { SchemaRegistryAvroDeserializer(String registryUrl, TokenCredential credential, boolean avroSpecificReader, - int maxSchemaMapSize) { + Integer maxSchemaMapSize) { super(new CachedSchemaRegistryClientBuilder() - .host(registryUrl) + .endpoint(registryUrl) .credential(credential) .maxSchemaMapSize(maxSchemaMapSize) .buildClient()); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java similarity index 94% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java index 906eefae2e81..cf67c6400455 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java @@ -4,7 +4,6 @@ package com.azure.data.schemaregistry.avro; import com.azure.core.credential.TokenCredential; -import com.azure.data.schemaregistry.client.CachedSchemaRegistryClient; /** * Builder class for constructing {@link SchemaRegistryAvroDeserializer} and {@link SchemaRegistryAvroAsyncDeserializer} @@ -14,7 +13,7 @@ public class SchemaRegistryAvroDeserializerBuilder { private final String registryUrl; private TokenCredential credential; private boolean avroSpecificReader; - private int maxSchemaMapSize; + private Integer maxSchemaMapSize; /** * Instantiates instance of Builder class. @@ -26,7 +25,7 @@ public SchemaRegistryAvroDeserializerBuilder(String registryUrl) { this.registryUrl = registryUrl; this.credential = null; this.avroSpecificReader = false; - this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + this.maxSchemaMapSize = null; } /** diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java similarity index 95% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java index af412ed394c2..2ea74915c75e 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java @@ -23,9 +23,9 @@ public class SchemaRegistryAvroSerializer extends AbstractDataSerializer { TokenCredential credential, String schemaGroup, boolean autoRegisterSchemas, - int maxSchemaMapSize) { + Integer maxSchemaMapSize) { super(new CachedSchemaRegistryClientBuilder() - .host(registryUrl) + .endpoint(registryUrl) .credential(credential) .maxSchemaMapSize(maxSchemaMapSize) .buildClient()); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java similarity index 95% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java index 22baf9bb3758..ec37817d3dfe 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java @@ -5,7 +5,6 @@ import com.azure.core.credential.TokenCredential; import com.azure.data.schemaregistry.AbstractDataSerializer; -import com.azure.data.schemaregistry.client.CachedSchemaRegistryClient; /** * Builder implemenation for building {@link SchemaRegistryAvroSerializer} and {@link SchemaRegistryAvroAsyncSerializer} @@ -15,7 +14,7 @@ public final class SchemaRegistryAvroSerializerBuilder { private TokenCredential credential; private boolean autoRegisterSchemas; private String schemaGroup; - private int maxSchemaMapSize; + private Integer maxSchemaMapSize; /** * Instantiates instance of Builder class. @@ -28,7 +27,7 @@ private SchemaRegistryAvroSerializerBuilder(String registryUrl) { this.credential = null; this.autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; this.schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; - this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + this.maxSchemaMapSize = null; } /** diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/package-info.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/module-info.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/module-info.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/main/module-info.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/module-info.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/README.md b/sdk/schemaregistry/azure-data-schemaregistry-client/README.md deleted file mode 100644 index dff2149e5509..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry-client/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Azure Schema Registry client library for Java - -This library contains a client implementation for sending, receiving, and managing Azure Schema Registry resources. - -A Swagger API definition of the service can be found at the base level of the repository. - -## Getting started - -## Key concepts - -## Examples - -## Troubleshooting - -## Next steps - -## Contributing diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry-client/pom.xml deleted file mode 100644 index 7fda107e4ce8..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry-client/pom.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - 4.0.0 - - - com.azure - azure-client-sdk-parent - 1.7.0 - ../../parents/azure-client-sdk-parent - - - com.azure - azure-data-schemaregistry-client - jar - 1.0.0-beta.1 - - Microsoft Azure Schema Registry - REST Client - REST client implementation for Azure Schema Registry - https://github.com/Azure/azure-sdk-for-java - - - - azure-java-build-docs - ${site.url}/site/${project.artifactId} - - - - - scm:git:https://github.com/Azure/azure-sdk-for-java - scm:git:git@github.com:Azure/azure-sdk-for-java.git - HEAD - - - - - - 0.10 - 0.01 - - - - - com.azure - azure-core - 1.5.0 - - - com.azure - azure-core-http-netty - 1.5.1 - - - - - org.junit.jupiter - junit-jupiter-api - 5.6.2 - test - - - org.junit.jupiter - junit-jupiter-engine - 5.6.2 - test - - - org.junit.jupiter - junit-jupiter-params - 5.6.2 - test - - - org.mockito - mockito-core - 3.0.0 - test - - - diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/module-info.java b/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/module-info.java deleted file mode 100644 index 88867172521b..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/module-info.java +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -module com.azure.data.schemaregistry.client { - requires transitive com.azure.core; - - exports com.azure.data.schemaregistry.client; - - opens com.azure.data.schemaregistry.client to com.fasterxml.jackson.databind; - opens com.azure.data.schemaregistry.client.rest to com.fasterxml.jackson.databind, com.azure.core; - opens com.azure.data.schemaregistry.client.models to com.fasterxml.jackson.databind, com.azure.core; -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/README.md b/sdk/schemaregistry/azure-data-schemaregistry/README.md similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/README.md rename to sdk/schemaregistry/azure-data-schemaregistry/README.md diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry/pom.xml similarity index 82% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/pom.xml rename to sdk/schemaregistry/azure-data-schemaregistry/pom.xml index 4dd43529c5aa..645584002738 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry/pom.xml @@ -15,12 +15,14 @@ com.azure - azure-data-schemaregistry-serde-common + azure-data-schemaregistry jar - 1.0.0-beta.1 + 1.0.0-beta.1 - Microsoft Azure Schema Registry - Common SerDe Package for client library - Common SerDe Package containing base serialization/deserialization implementation for Azure Schema Registry client library + Microsoft Azure Schema Registry - Common Client/SerDe Package for client library + + Common SerDe Package containing client and base serialization/deserialization implementation for Azure Schema Registry client library + https://github.com/Azure/azure-sdk-for-java @@ -48,8 +50,8 @@ com.azure - azure-data-schemaregistry-client - 1.0.0-beta.1 + azure-core-http-netty + 1.5.1 @@ -71,6 +73,12 @@ 5.6.2 test + + org.mockito + mockito-core + 3.0.0 + test + org.apache.avro avro diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/resources/azure-schemaregistry-client.properties b/sdk/schemaregistry/azure-data-schemaregistry/resources/azure-data-schemaregistry-client.properties similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/resources/azure-schemaregistry-client.properties rename to sdk/schemaregistry/azure-data-schemaregistry/resources/azure-data-schemaregistry-client.properties diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java similarity index 92% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java index 88c830d10776..91eb8208f940 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java @@ -90,7 +90,7 @@ private ByteDecoder getByteDecoder(SchemaRegistryObject registryObject) throws S if (decoder == null) { throw logger.logExceptionAsError( new SerializationException( - String.format("No decoder class found for serialization type '%s'", registryObject.getSchemaType()) + String.format("No decoder class found for schema type '%s'", registryObject.getSchemaType()) )); } return decoder; @@ -113,7 +113,7 @@ private String getSchemaGuidFromPayload(ByteBuffer buffer) throws SerializationE } /** - * Loads a ByteDecoder to be used for deserializing payloads of specified serialization format. + * Loads a ByteDecoder to be used for decoding message payloads of specified schema type. * @param decoder ByteDecoder class instance to be loaded */ protected void loadByteDecoder(ByteDecoder decoder) { @@ -121,7 +121,7 @@ protected void loadByteDecoder(ByteDecoder decoder) { throw logger.logExceptionAsError(new SerializationException("ByteDecoder cannot be null")); } - this.byteDecoderMap.put(decoder.serializationFormat(), decoder); - this.schemaRegistryClient.loadSchemaParser(decoder.serializationFormat(), decoder::parseSchemaString); + this.byteDecoderMap.put(decoder.schemaType(), decoder); + this.schemaRegistryClient.addSchemaParser(decoder); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataSerDe.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java similarity index 93% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java index 9164d3fdeea0..74784e54e37d 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataSerializer.java @@ -22,7 +22,7 @@ public abstract class AbstractDataSerializer extends AbstractDataSerDe { public static final String SCHEMA_GROUP_DEFAULT = "$default"; protected ByteEncoder byteEncoder = null; - protected String serializationFormat; + protected String schemaType; protected Boolean autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; protected String schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; @@ -49,8 +49,8 @@ protected void setByteEncoder(ByteEncoder byteEncoder) { new IllegalArgumentException("Setting multiple encoders on serializer not permitted")); } this.byteEncoder = byteEncoder; - this.serializationFormat = byteEncoder.serializationFormat(); - this.schemaRegistryClient.loadSchemaParser(byteEncoder.serializationFormat(), byteEncoder::parseSchemaString); + this.schemaType = byteEncoder.schemaType(); + this.schemaRegistryClient.addSchemaParser(byteEncoder); } /** @@ -73,8 +73,8 @@ protected byte[] serializeImpl(Object object) { new SerializationException("Byte encoder null, serializer must be initialized with a byte encoder.")); } - if (serializationFormat == null) { - serializationFormat = byteEncoder.serializationFormat(); + if (schemaType == null) { + schemaType = byteEncoder.schemaType(); } String schemaString = byteEncoder.getSchemaString(object); @@ -82,7 +82,7 @@ protected byte[] serializeImpl(Object object) { try { String schemaGuid = maybeRegisterSchema( - this.schemaGroup, schemaName, schemaString, this.serializationFormat); + this.schemaGroup, schemaName, schemaString, this.schemaType); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteBuffer guidBuffer = ByteBuffer.allocate(AbstractDataSerDe.SCHEMA_ID_SIZE) .put(schemaGuid.getBytes(StandardCharsets.UTF_8)); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/ByteDecoder.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/Codec.java similarity index 77% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/Codec.java index c1c035ebdcb1..cf99962f9ff6 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/Codec.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/Codec.java @@ -8,12 +8,12 @@ */ public interface Codec { /** - * @return String representation of serialization format type, e.g. "avro" or "json". + * @return String representation of schema type, e.g. "avro" or "json". * * Utilized by schema registry store and client as non-case-sensitive tags for - * schemas of specific serialization format. + * schemas of a specific type. */ - String serializationFormat(); + String schemaType(); /** * Parses string representation of schema into schema Object diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/SerializationException.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SerializationException.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/SerializationException.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SerializationException.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java similarity index 90% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java index 3899f9f5a43d..7202cd2752dc 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClient.java @@ -7,6 +7,7 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; +import com.azure.data.schemaregistry.Codec; import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestService; import com.azure.data.schemaregistry.client.implementation.models.GetSchemaByIdResponse; import com.azure.data.schemaregistry.client.implementation.models.SchemaId; @@ -45,12 +46,11 @@ public final class CachedSchemaRegistryClient implements SchemaRegistryClient { private final ClientLogger logger = new ClientLogger(CachedSchemaRegistryClient.class); public static final Charset SCHEMA_REGISTRY_SERVICE_ENCODING = StandardCharsets.UTF_8; - - public static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; + static final int MAX_SCHEMA_MAP_SIZE_DEFAULT = 1000; static final int MAX_SCHEMA_MAP_SIZE_MINIMUM = 10; private final AzureSchemaRegistryRestService restService; - private final int maxSchemaMapSize; + private final Integer maxSchemaMapSize; private final ConcurrentSkipListMap> typeParserMap; private final Map idCache; private final Map schemaStringCache; @@ -88,49 +88,48 @@ public Charset getEncoding() { } /** - * @param schemaType case-insensitive tag used by schema registry store to identify schema type, e.g. "avro" - * @param parseMethod function to parse string into usable schema object + * @param codec Codec class implementation * @throws IllegalArgumentException on bad schema type or if parser for schema type has already been registered */ - public void loadSchemaParser(String schemaType, Function parseMethod) { - if (CoreUtils.isNullOrEmpty(schemaType)) { + public void addSchemaParser(Codec codec) { + if (CoreUtils.isNullOrEmpty(codec.schemaType())) { throw logger.logExceptionAsError( new IllegalArgumentException("Serialization type cannot be null or empty.")); } - if (this.typeParserMap.containsKey(schemaType)) { + if (this.typeParserMap.containsKey(codec.schemaType())) { throw logger.logExceptionAsError( new IllegalArgumentException("Multiple parse methods for single serialization type may not be added.")); } - this.typeParserMap.putIfAbsent(schemaType, parseMethod); + this.typeParserMap.putIfAbsent(codec.schemaType(), codec::parseSchemaString); logger.verbose( - "Loaded parser for '{}' serialization format.", schemaType.toLowerCase(Locale.ROOT)); + "Loaded parser for '{}' serialization format.", codec.schemaType().toLowerCase(Locale.ROOT)); } @Override public SchemaRegistryObject register( - String schemaGroup, String schemaName, String schemaString, String serializationType) { + String schemaGroup, String schemaName, String schemaString, String schemaType) { if (schemaStringCache.containsKey(schemaString)) { logger.verbose( - "Cache hit schema string. Group: '{}', name: '{}', serialization type: '{}', payload: '{}'", - schemaGroup, schemaName, serializationType, schemaString); + "Cache hit schema string. Group: '{}', name: '{}', schema type: '{}', payload: '{}'", + schemaGroup, schemaName, schemaType, schemaString); return schemaStringCache.get(schemaString); } logger.verbose( "Registering schema. Group: '{}', name: '{}', serialization type: '{}', payload: '{}'", - schemaGroup, schemaName, serializationType, schemaString); + schemaGroup, schemaName, schemaType, schemaString); SchemaId schemaId; try { - schemaId = this.restService.createSchema(schemaGroup, schemaName, schemaString, serializationType); + schemaId = this.restService.createSchema(schemaGroup, schemaName, schemaString, schemaType); } catch (HttpResponseException e) { throw logger.logExceptionAsError(new SchemaRegistryClientException("Register operation failed.", e)); } SchemaRegistryObject registered = new SchemaRegistryObject(schemaId.getId(), - serializationType, + schemaType, schemaString.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING), - getParseFunc(serializationType)); + getParseFunc(schemaType)); resetIfNeeded(); schemaStringCache.putIfAbsent(schemaString, registered); @@ -175,8 +174,6 @@ public SchemaRegistryObject getSchemaByGuid(String schemaId) { @Override public String getSchemaId( String schemaGroup, String schemaName, String schemaString, String schemaType) { - - if (schemaStringCache.containsKey(schemaString)) { logger.verbose("Cache hit schema string. Group: '{}', name: '{}'", schemaGroup, schemaName); return schemaStringCache.get(schemaString).getSchemaId(); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java similarity index 92% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index 986c4115a197..3fb25a73d14b 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -21,6 +21,7 @@ import com.azure.core.util.Configuration; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; +import com.azure.data.schemaregistry.Codec; import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestService; import com.azure.data.schemaregistry.client.implementation.AzureSchemaRegistryRestServiceClientBuilder; @@ -42,7 +43,7 @@ public class CachedSchemaRegistryClientBuilder { private final ClientLogger logger = new ClientLogger(CachedSchemaRegistryClientBuilder.class); private static final String DEFAULT_SCOPE = "https://eventhubs.azure.com/.default"; - private static final String CLIENT_PROPERTIES = "azure-schemaregistry-client.properties"; + private static final String CLIENT_PROPERTIES = "azure-data-schemaregistry-client.properties"; private static final String NAME = "name"; private static final String VERSION = "version"; private static final RetryPolicy DEFAULT_RETRY_POLICY = @@ -55,7 +56,7 @@ public class CachedSchemaRegistryClientBuilder { private String schemaRegistryUrl; private HttpClient httpClient; - private int maxSchemaMapSize; + private Integer maxSchemaMapSize; private TokenCredential credential; private HttpLogOptions httpLogOptions; private HttpPipeline httpPipeline; @@ -67,7 +68,7 @@ public class CachedSchemaRegistryClientBuilder { public CachedSchemaRegistryClientBuilder() { this.policies = new ArrayList<>(); this.httpLogOptions = new HttpLogOptions(); - this.maxSchemaMapSize = CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + this.maxSchemaMapSize = null; this.typeParserMap = new ConcurrentSkipListMap<>(String.CASE_INSENSITIVE_ORDER); this.httpClient = null; this.credential = null; @@ -86,7 +87,7 @@ public CachedSchemaRegistryClientBuilder() { * @throws NullPointerException if {@code schemaRegistryUrl} is null * @throws IllegalArgumentException if {@code schemaRegistryUrl} cannot be parsed into a valid URL */ - public CachedSchemaRegistryClientBuilder host(String schemaRegistryUrl) { + public CachedSchemaRegistryClientBuilder endpoint(String schemaRegistryUrl) { Objects.requireNonNull(schemaRegistryUrl, "'endpoint' cannot be null."); try { @@ -111,7 +112,7 @@ public CachedSchemaRegistryClientBuilder host(String schemaRegistryUrl) { * @return The updated {@link CachedSchemaRegistryClientBuilder} object. * @throws IllegalArgumentException on invalid maxSchemaMapSize value */ - public CachedSchemaRegistryClientBuilder maxSchemaMapSize(int maxSchemaMapSize) throws IllegalArgumentException { + public CachedSchemaRegistryClientBuilder maxSchemaMapSize(int maxSchemaMapSize) { if (maxSchemaMapSize < CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_MINIMUM) { throw logger.logExceptionAsError(new IllegalArgumentException( String.format("Schema map size must be greater than %s entries", @@ -207,27 +208,24 @@ public CachedSchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { * service into useable schema objects. * * Any com.azure.data.schemaregistry.ByteEncoder or com.azure.data.schemaregistry.ByteDecoder class will implement - * - serializationFormat(), which specifies schema type, and + * - schemaType(), which specifies schema type, and * - parseSchemaString(), which parses schemas of the specified schema type from String to Object. - * This method can be used by passing in a method reference, e.g. ByteEncoder::parseSchemaString. * * The parseMethod argument should be a stateless, idempotent function. * - * @param schemaType schema type for which the parse method should be applied. - * @param parseMethod function for deserializing registry-stored schema strings to Java Objects + * @param codec Codec class implementation * @return The updated {@link CachedSchemaRegistryClientBuilder} object. */ - public CachedSchemaRegistryClientBuilder loadSchemaParser( - String schemaType, Function parseMethod) { - if (CoreUtils.isNullOrEmpty(schemaType)) { + public CachedSchemaRegistryClientBuilder addSchemaParser(Codec codec) { + if (CoreUtils.isNullOrEmpty(codec.schemaType())) { throw logger.logExceptionAsError( new IllegalArgumentException("Serialization type cannot be null or empty.")); } - if (this.typeParserMap.containsKey(schemaType)) { + if (this.typeParserMap.containsKey(codec.schemaType())) { throw logger.logExceptionAsError( new IllegalArgumentException("Multiple parse methods for single serialization type may not be added.")); } - this.typeParserMap.put(schemaType, parseMethod); + this.typeParserMap.put(codec.schemaType(), codec::parseSchemaString); return this; } @@ -284,6 +282,10 @@ public CachedSchemaRegistryClient buildClient() { .pipeline(pipeline) .buildClient(); + this.maxSchemaMapSize = this.maxSchemaMapSize != null + ? this.maxSchemaMapSize + : CachedSchemaRegistryClient.MAX_SCHEMA_MAP_SIZE_DEFAULT; + return new CachedSchemaRegistryClient(restService, maxSchemaMapSize, typeParserMap); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java similarity index 80% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java index ee3f58b80160..5443ded21196 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClient.java @@ -3,9 +3,10 @@ package com.azure.data.schemaregistry.client; +import com.azure.data.schemaregistry.Codec; + import java.nio.charset.Charset; import java.util.List; -import java.util.function.Function; /** * Interface that defines operation for registering and fetching schemas and schema information to and from a @@ -20,14 +21,16 @@ public interface SchemaRegistryClient { Charset getEncoding(); /** - * Loads function for a given serialization format that can parse the registry-stored schema string into + * Loads function for a given schema type that can parse the registry-stored schema string into * usable schema object. * - * @param serializationType tag used by schema registry store to identify schema serialization type, e.g. "avro" - * @param parseMethod *idempotent* function to parse string into usable schema object. May be called more than once - * per schema + * Any com.azure.data.schemaregistry.ByteEncoder or com.azure.data.schemaregistry.ByteDecoder class will implement + * - schemaType(), which specifies schema type, and + * - parseSchemaString(), which parses schemas of the specified schema type from String to Object. + * + * @param codec Codec class implementation */ - void loadSchemaParser(String serializationType, Function parseMethod); + void addSchemaParser(Codec codec); /** * Registers a schema against backing schema registry store. @@ -35,11 +38,11 @@ public interface SchemaRegistryClient { * @param schemaGroup schema group name * @param schemaName schema name * @param schemaString string representation of schema - * @param serializationType string representation of serialization format type + * @param schemaType string representation of schema type * @return SchemaRegistryObject containing information regarding registered schema. * @throws SchemaRegistryClientException if registration operation fails */ - SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType); + SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String schemaType); /** * Fetches schema specified by the GUID. @@ -58,11 +61,11 @@ public interface SchemaRegistryClient { * @param schemaGroup schema group name * @param schemaName schema name * @param schemaString String representation of schema - * @param serializationType String representation of serialization format type + * @param schemaType String representation of schema type * @return SchemaRegistryObject containing information regarding requested schema. * @throws SchemaRegistryClientException if fetch operation fails */ - String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType); + String getSchemaId(String schemaGroup, String schemaName, String schemaString, String schemaType); /** * Not currently implemented. diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryClientException.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestService.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/AzureSchemaRegistryRestServiceClientBuilder.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupHeaders.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateGroupResponse.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaHeaders.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/CreateSchemaResponse.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentHeaders.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetIdBySchemaContentResponse.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaHeaders.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetLatestSchemaResponse.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdHeaders.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaByIdResponse.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionHeaders.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionResponse.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsHeaders.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemaVersionsResponse.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupHeaders.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/GetSchemasByGroupResponse.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaGroup.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/SchemaId.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/models/package-info.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/implementation/package-info.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/main/java/com/azure/data/schemaregistry/client/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/package-info.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/package-info.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/java/com/azure/data/schemaregistry/package-info.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/package-info.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/module-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/module-info.java similarity index 86% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/module-info.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/main/module-info.java index 1c5128fd6722..5c6d7383fdba 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/main/module-info.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/module-info.java @@ -5,6 +5,7 @@ requires com.azure.core; exports com.azure.data.schemaregistry; + exports com.azure.data.schemaregistry.client; opens com.azure.data.schemaregistry to com.fasterxml.jackson.databind, com.azure.core; } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/AbstractDataDeserializerTest.java similarity index 99% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/AbstractDataDeserializerTest.java index b2ee94f5338e..310d3abe0039 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataDeserializerTest.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/AbstractDataDeserializerTest.java @@ -34,7 +34,7 @@ public void testLoadDecoder() throws IOException, SchemaRegistryClientException, // manually add SchemaRegistryObject to cache SchemaRegistryObject registered = new SchemaRegistryObject(MOCK_GUID, - decoder.serializationFormat(), + decoder.schemaType(), MOCK_AVRO_SCHEMA_STRING.getBytes(), decoder::parseSchemaString); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/AbstractDataSerializerTest.java similarity index 98% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/AbstractDataSerializerTest.java index b47d4448c8ea..ec8494935b94 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/AbstractDataSerializerTest.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/AbstractDataSerializerTest.java @@ -20,7 +20,7 @@ public void testRegistryGuidPrefixedToPayload() { // manually add SchemaRegistryObject into mock registry client cache SampleByteEncoder encoder = new SampleByteEncoder(); SchemaRegistryObject registered = new SchemaRegistryObject(MOCK_GUID, - encoder.serializationFormat(), + encoder.schemaType(), encoder.getSchemaString(null).getBytes(), // always returns same schema string encoder::parseSchemaString); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/MockSchemaRegistryClient.java similarity index 93% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/MockSchemaRegistryClient.java index 17f485032572..54fb22667bba 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/MockSchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/MockSchemaRegistryClient.java @@ -30,10 +30,10 @@ public Charset getEncoding() { return StandardCharsets.UTF_8; } - public void loadSchemaParser(String serializationFormat, Function f) { } + public void addSchemaParser(Codec codec) { } @Override - public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String serializationType) + public SchemaRegistryObject register(String schemaGroup, String schemaName, String schemaString, String schemaType) throws SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { return schemaStringCache.get(schemaString); @@ -52,7 +52,7 @@ public SchemaRegistryObject getSchemaByGuid(String schemaGuid) } @Override - public String getSchemaId(String schemaGroup, String schemaName, String schemaString, String serializationType) + public String getSchemaId(String schemaGroup, String schemaName, String schemaString, String schemaType) throws SchemaRegistryClientException { if (schemaStringCache.containsKey(schemaString)) { return schemaStringCache.get(schemaString).getSchemaId(); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SampleByteDecoder.java similarity index 93% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SampleByteDecoder.java index 3a22e4ff42e8..8b4cba7c8215 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteDecoder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SampleByteDecoder.java @@ -9,7 +9,7 @@ public class SampleByteDecoder implements ByteDecoder { public SampleByteDecoder() { } @Override - public String serializationFormat() { + public String schemaType() { return "sample"; } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SampleByteEncoder.java similarity index 96% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SampleByteEncoder.java index 442727488ab8..768f7fbac496 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/SampleByteEncoder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SampleByteEncoder.java @@ -35,7 +35,7 @@ public ByteArrayOutputStream encode(Object object) throws SerializationException } @Override - public String serializationFormat() { + public String schemaType() { return "test"; } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/TestDummyDeserializer.java similarity index 83% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/TestDummyDeserializer.java index e47528f4ae2f..4a99d814af9c 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummyDeserializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/TestDummyDeserializer.java @@ -9,6 +9,6 @@ public class TestDummyDeserializer extends AbstractDataDeserializer { TestDummyDeserializer(SchemaRegistryClient mockClient) { super(mockClient); ByteDecoder sampleDecoder = new SampleByteDecoder(); - this.byteDecoderMap.put(sampleDecoder.serializationFormat(), sampleDecoder); + this.byteDecoderMap.put(sampleDecoder.schemaType(), sampleDecoder); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/TestDummySerializer.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-serde-common/src/test/java/com/azure/schemaregistry/TestDummySerializer.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/TestDummySerializer.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java rename to sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientTest.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/sdk/schemaregistry/azure-data-schemaregistry/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker rename to sdk/schemaregistry/azure-data-schemaregistry/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/sdk/schemaregistry/azure-data-schemaregistry-client/swagger/swagger.yaml b/sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.yaml similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-client/swagger/swagger.yaml rename to sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.yaml diff --git a/sdk/schemaregistry/ci.yml b/sdk/schemaregistry/ci.yml index 703e22a66a05..81019698dc2b 100644 --- a/sdk/schemaregistry/ci.yml +++ b/sdk/schemaregistry/ci.yml @@ -37,12 +37,9 @@ stages: parameters: ServiceDirectory: schemaregistry Artifacts: - - name: azure-data-schemaregistry-client + - name: azure-data-schemaregistry groupId: com.azure - safeName: azuredataschemaregistryclient - - name: azure-data-schemaregistry-serde-common + safeName: azuredataschemaregistry + - name: azure-data-schemaregistry-avro groupId: com.azure - safeName: azuredataschemaregistryserdecommon - - name: azure-data-schemaregistry-serde-avro - groupId: com.azure - safeName: azuredataschemaregistryserde-avro + safeName: azuredataschemaregistryavro diff --git a/sdk/schemaregistry/pom.xml b/sdk/schemaregistry/pom.xml index b059fc462945..b4913ee4eddd 100644 --- a/sdk/schemaregistry/pom.xml +++ b/sdk/schemaregistry/pom.xml @@ -8,12 +8,11 @@ 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"> 4.0.0 com.azure - azure-data-schemaregistry + azure-data-schemaregistry-service pom 1.0.0 - azure-data-schemaregistry-client - azure-data-schemaregistry-serde-common - azure-data-schemaregistry-serde-avro + azure-data-schemaregistry + azure-data-schemaregistry-avro From d6e0941bd0ecbd4918935608d447047be7fe7795 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 28 May 2020 12:46:42 -0700 Subject: [PATCH 37/43] update versioning --- eng/versioning/version_client.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index 1bb425a7f801..fed16ebd1c71 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -26,9 +26,8 @@ com.azure:azure-identity-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-messaging-eventhubs;5.1.0;5.2.0-beta.1 com.azure:azure-messaging-eventhubs-checkpointstore-blob;1.1.0;1.2.0-beta.1 com.azure:azure-messaging-servicebus;7.0.0-beta.2;7.0.0-beta.3 -com.azure:azure-data-schemaregistry-client;1.0.0-beta.1;1.0.0-beta.1 -com.azure:azure-data-schemaregistry-serde-common;1.0.0-beta.1;1.0.0-beta.1 -com.azure:azure-data-schemaregistry-serde-avro;1.0.0-beta.1;1.0.0-beta.1 +com.azure:azure-data-schemaregistry;1.0.0-beta.1;1.0.0-beta.1 +com.azure:azure-data-schemaregistry-avro;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-search-documents;1.0.0-beta.3;1.0.0-beta.4 com.azure:azure-security-keyvault-certificates;4.1.0-beta.2;4.1.0-beta.3 com.azure:azure-security-keyvault-keys;4.2.0-beta.3;4.2.0-beta.4 From c1f71999dfc723f4022f3ce221f2e82aeaf1f1ec Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Thu, 28 May 2020 13:05:03 -0700 Subject: [PATCH 38/43] fix jacoco test pom --- eng/jacoco-test-coverage/pom.xml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/eng/jacoco-test-coverage/pom.xml b/eng/jacoco-test-coverage/pom.xml index cc45f0248593..f7d026cebb78 100644 --- a/eng/jacoco-test-coverage/pom.xml +++ b/eng/jacoco-test-coverage/pom.xml @@ -189,18 +189,13 @@ com.azure - azure-data-schemaregistry-client - 1.0.0-beta.1 + azure-data-schemaregistry + 1.0.0-beta.1 com.azure - azure-data-schemaregistry-serde-avro - 1.0.0-beta.1 - - - com.azure - azure-data-schemaregistry-serde-common - 1.0.0-beta.1 + azure-data-schemaregistry-avro + 1.0.0-beta.1 com.microsoft.azure From 93defa9bdfacb71789c231eb2cb9980f80c0ea01 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Fri, 29 May 2020 09:15:06 -0700 Subject: [PATCH 39/43] fix eng system comments --- eng/versioning/version_client.txt | 4 ++-- .../azure-data-schemaregistry-avro/pom.xml | 1 + .../azure-data-schemaregistry/pom.xml | 20 +------------------ 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index fed16ebd1c71..254c47c2f508 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -20,14 +20,14 @@ com.azure:azure-cosmos;4.0.1-beta.3;4.0.1-beta.4 com.azure:azure-cosmos-examples;4.0.1-beta.1;4.0.1-beta.1 com.azure:azure-cosmos-benchmark;4.0.1-beta.1;4.0.1-beta.1 com.azure:azure-data-appconfiguration;1.1.1;1.2.0-beta.1 +com.azure:azure-data-schemaregistry;1.0.0-beta.1;1.0.0-beta.1 +com.azure:azure-data-schemaregistry-avro;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-e2e;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-identity;1.0.6;1.1.0-beta.5 com.azure:azure-identity-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-messaging-eventhubs;5.1.0;5.2.0-beta.1 com.azure:azure-messaging-eventhubs-checkpointstore-blob;1.1.0;1.2.0-beta.1 com.azure:azure-messaging-servicebus;7.0.0-beta.2;7.0.0-beta.3 -com.azure:azure-data-schemaregistry;1.0.0-beta.1;1.0.0-beta.1 -com.azure:azure-data-schemaregistry-avro;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-search-documents;1.0.0-beta.3;1.0.0-beta.4 com.azure:azure-security-keyvault-certificates;4.1.0-beta.2;4.1.0-beta.3 com.azure:azure-security-keyvault-keys;4.2.0-beta.3;4.2.0-beta.4 diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml index 552daf8eec4f..df4a44a24788 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml @@ -38,6 +38,7 @@ + true diff --git a/sdk/schemaregistry/azure-data-schemaregistry/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry/pom.xml index 645584002738..a1da5396df35 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry/pom.xml @@ -39,6 +39,7 @@ + true @@ -86,23 +87,4 @@ test - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M3 - - - - - com.azure:* - - - - - - - From cea60ee4b0f1327bbcd6ed5231f8a23ac3faef83 Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson <30675661+arerlend@users.noreply.github.com> Date: Fri, 29 May 2020 10:47:34 -0700 Subject: [PATCH 40/43] Update sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml Co-authored-by: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> --- sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml index df4a44a24788..58f07f12a73b 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml @@ -21,7 +21,7 @@ 1.0.0-beta.1 Microsoft Azure Schema Registry - Avro-specific package for client library - Avro-specih,fic package for Azure Schema Registry client library + Avro-specific package for Azure Schema Registry client library https://github.com/Azure/azure-sdk-for-java From 6ffe75968536564b10be6f66ec76e925c9679c6c Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson <30675661+arerlend@users.noreply.github.com> Date: Fri, 29 May 2020 11:30:29 -0700 Subject: [PATCH 41/43] Update sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java Co-authored-by: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> --- .../schemaregistry/avro/SchemaRegistryAvroDeserializer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java index fd749f413273..83dbc169864e 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java @@ -11,9 +11,9 @@ /** * A deserializer implementation capable of automatedly deserializing encoded byte array payloads into Java objects by * fetching payload-specified schemas from the Azure Schema Registry store. - * + *

    * SchemaRegistryAvroDeserializer instances should be built using the static Builder class. - * + *

    * Pluggable with the core Azure SDK Deserializer interface. * * @see AbstractDataDeserializer See AbstractDataDeserializer for internal deserialization implementation From e5c40b1d74f2ba4462e9ec347998c876458c017a Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Fri, 29 May 2020 13:49:46 -0700 Subject: [PATCH 42/43] fix comments --- .../azure-data-schemaregistry-avro/pom.xml | 2 - .../schemaregistry/avro/AvroByteDecoder.java | 15 +- .../schemaregistry/avro/AvroByteEncoder.java | 17 +- .../data/schemaregistry/avro/AvroCodec.java | 2 + .../schemaregistry/avro/AvroSchemaUtils.java | 3 +- .../SchemaRegistryAvroAsyncDeserializer.java | 4 +- .../SchemaRegistryAvroAsyncSerializer.java | 4 +- .../avro/SchemaRegistryAvroDeserializer.java | 20 +- ...SchemaRegistryAvroDeserializerBuilder.java | 37 +- .../avro/SchemaRegistryAvroSerializer.java | 18 +- .../SchemaRegistryAvroSerializerBuilder.java | 38 +- .../src/main/module-info.java | 4 +- .../avro/AvroByteDecoderTest.java | 0 .../avro/AvroByteEncoderTest.java | 0 .../AbstractDataDeserializer.java | 7 +- .../data/schemaregistry/ByteEncoder.java | 4 +- .../SerializationException.java | 4 +- .../CachedSchemaRegistryClientBuilder.java | 6 +- .../client/SchemaRegistryObject.java | 7 +- .../src/main/module-info.java | 4 +- .../schemaregistry/TestDummyDeserializer.java | 2 +- .../swagger/swagger.json | 576 ++++++++++++++++++ .../swagger/swagger.yaml | 378 ------------ 23 files changed, 687 insertions(+), 465 deletions(-) rename sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/{ => data}/schemaregistry/avro/AvroByteDecoderTest.java (100%) rename sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/{ => data}/schemaregistry/avro/AvroByteEncoderTest.java (100%) create mode 100644 sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.json delete mode 100644 sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.yaml diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml index 58f07f12a73b..1f9920fee584 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/pom.xml @@ -47,13 +47,11 @@ com.azure azure-data-schemaregistry 1.0.0-beta.1 - compile org.apache.avro avro 1.9.2 - compile diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java index d91e45106f15..9b3893583771 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteDecoder.java @@ -13,22 +13,23 @@ import org.apache.avro.specific.SpecificDatumReader; import java.io.IOException; +import java.util.Objects; /** - * ByteDecoder implementation with all Avro-specific functionality required to deserialize byte arrays + * Apache Avro ByteDecoder implementation with all Avro-specific functionality required to deserialize byte arrays * given an Avro schema. */ public class AvroByteDecoder extends AvroCodec implements ByteDecoder { private final ClientLogger logger = new ClientLogger(AvroByteDecoder.class); - private final DecoderFactory decoderFactory = DecoderFactory.get(); + 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) { + public AvroByteDecoder(boolean avroSpecificReader) { this.avroSpecificReader = avroSpecificReader; } @@ -38,10 +39,12 @@ public AvroByteDecoder(Boolean avroSpecificReader) { * @return deserialized object * @throws SerializationException upon deserialization failure */ - public Object decodeBytes(byte[] b, Object object) throws SerializationException { + public Object decodeBytes(byte[] b, Object object) { + Objects.requireNonNull(object, "Schema must not be null."); + if (!(object instanceof Schema)) { throw logger.logExceptionAsError( - new SerializationException("Attempted to decode with non-Avro schema object in AvroByteDecoder")); + new SerializationException("Object must be an Avro schema.")); } Schema schema = (Schema) object; @@ -52,7 +55,7 @@ public Object decodeBytes(byte[] b, Object object) throws SerializationException DatumReader reader = getDatumReader(schema); try { - Object result = reader.read(null, decoderFactory.binaryDecoder(b, null)); + Object result = reader.read(null, DECODER_FACTORY.binaryDecoder(b, null)); if (schema.getType().equals(Schema.Type.STRING)) { return result.toString(); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java index f0e9693be0fc..266d7cd840ca 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroByteEncoder.java @@ -23,18 +23,14 @@ public class AvroByteEncoder extends AvroCodec implements ByteEncoder { private final ClientLogger logger = new ClientLogger(AvroByteEncoder.class); - private final EncoderFactory encoderFactory = EncoderFactory.get(); - - /** - * Instantiates AvroByteEncoder instance. - */ - public AvroByteEncoder() { } + 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(); @@ -46,6 +42,7 @@ public String getSchemaString(Object object) { * @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(); } @@ -56,15 +53,16 @@ public String getSchemaName(Object object) { * @return closed ByteArrayOutputStream * @throws SerializationException wraps runtime exceptions */ - public ByteArrayOutputStream encode(Object object) throws SerializationException { + @Override + public ByteArrayOutputStream encode(Object object) { Schema schema = AvroSchemaUtils.getSchema(object); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (object instanceof byte[]) { - out.write((byte[]) object); + out.write((byte[]) object); // todo: real avro byte arrays require writing array size to buffer } else { - BinaryEncoder encoder = encoderFactory.directBinaryEncoder(out, null); + BinaryEncoder encoder = ENCODER_FACTORY.directBinaryEncoder(out, null); DatumWriter writer; if (object instanceof SpecificRecord) { writer = new SpecificDatumWriter<>(schema); @@ -74,7 +72,6 @@ public ByteArrayOutputStream encode(Object object) throws SerializationException writer.write(object, encoder); encoder.flush(); } - out.close(); return out; } catch (IOException | RuntimeException e) { // Avro serialization can throw AvroRuntimeException, NullPointerException, ClassCastException, etc diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java index 29b9524b8141..bbf70f18342c 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroCodec.java @@ -10,6 +10,7 @@ * Base Codec class for Avro encoder and decoder implementations */ abstract class AvroCodec implements Codec { + @Override public String schemaType() { return "avro"; } @@ -18,6 +19,7 @@ public String schemaType() { * @param schemaString string representation of schema * @return avro schema */ + @Override public Schema parseSchemaString(String schemaString) { return (new Schema.Parser()).parse(schemaString); } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java index 5bfed3df0278..fbdf3fd90336 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/AvroSchemaUtils.java @@ -7,6 +7,7 @@ import org.apache.avro.Schema; import org.apache.avro.generic.GenericContainer; +import java.nio.ByteBuffer; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -72,7 +73,7 @@ public static Schema getSchema(Object object) throws IllegalArgumentException { return PRIMITIVE_SCHEMAS.get("Double"); } else if (object instanceof CharSequence) { return PRIMITIVE_SCHEMAS.get("String"); - } else if (object instanceof byte[]) { + } else if (object instanceof byte[] || object instanceof ByteBuffer) { return PRIMITIVE_SCHEMAS.get("Bytes"); } else if (object instanceof GenericContainer) { return ((GenericContainer) object).getSchema(); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java index c364c2962cc2..e43ab1de10f5 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncDeserializer.java @@ -35,9 +35,9 @@ public class SchemaRegistryAvroAsyncDeserializer { * @return Mono wrapper around deserialized object * @throws SerializationException if deserialization operation fails */ - public Mono deserializeAsync(byte[] data) throws SerializationException { + public Mono deserialize(byte[] data) throws SerializationException { return Mono - .fromCallable(() -> this.deserializer.deserializeSync(data)) + .fromCallable(() -> this.deserializer.deserialize(data)) .subscribeOn(scheduler); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java index 05624146404c..7d8edfb020ba 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroAsyncSerializer.java @@ -35,13 +35,13 @@ public class SchemaRegistryAvroAsyncSerializer extends AbstractDataSerializer { * @return Avro byte representation of object * @throws SerializationException upon serialization operation failure */ - public Mono serializeAsync(Object object) throws SerializationException { + public Mono serialize(Object object) throws SerializationException { if (object == null) { return Mono.empty(); } return Mono - .fromCallable(() -> this.serializer.serializeSync(object)) + .fromCallable(() -> this.serializer.serialize(object)) .subscribeOn(scheduler); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java index 83dbc169864e..c683ebc2ec9d 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializer.java @@ -3,10 +3,9 @@ package com.azure.data.schemaregistry.avro; -import com.azure.core.credential.TokenCredential; import com.azure.data.schemaregistry.AbstractDataDeserializer; import com.azure.data.schemaregistry.SerializationException; -import com.azure.data.schemaregistry.client.CachedSchemaRegistryClientBuilder; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClient; /** * A deserializer implementation capable of automatedly deserializing encoded byte array payloads into Java objects by @@ -19,15 +18,8 @@ * @see AbstractDataDeserializer See AbstractDataDeserializer for internal deserialization implementation */ public class SchemaRegistryAvroDeserializer extends AbstractDataDeserializer { - SchemaRegistryAvroDeserializer(String registryUrl, - TokenCredential credential, - boolean avroSpecificReader, - Integer maxSchemaMapSize) { - super(new CachedSchemaRegistryClientBuilder() - .endpoint(registryUrl) - .credential(credential) - .maxSchemaMapSize(maxSchemaMapSize) - .buildClient()); + SchemaRegistryAvroDeserializer(CachedSchemaRegistryClient registryClient, boolean avroSpecificReader) { + super(registryClient); loadByteDecoder(new AvroByteDecoder(avroSpecificReader)); } @@ -36,14 +28,12 @@ public class SchemaRegistryAvroDeserializer extends AbstractDataDeserializer { * Deserializes byte array into Java object using payload-specified schema. * * @param data Byte array containing serialized bytes - * @return Java object. - * - * Object type is testable with instanceof operator. Return value can be casted in the caller layer. + * @return decoded Java object * * @throws SerializationException Throws on deserialization failure. * Exception may contain inner exceptions detailing failure condition. */ - public Object deserializeSync(byte[] data) throws SerializationException { + public Object deserialize(byte[] data) throws SerializationException { return super.deserialize(data); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java index cf67c6400455..f661ee5d7b3f 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserializerBuilder.java @@ -4,30 +4,46 @@ package com.azure.data.schemaregistry.avro; import com.azure.core.credential.TokenCredential; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClient; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClientBuilder; + +import java.util.Objects; /** * Builder class for constructing {@link SchemaRegistryAvroDeserializer} and {@link SchemaRegistryAvroAsyncDeserializer} */ public class SchemaRegistryAvroDeserializerBuilder { - private final String registryUrl; + private String registryUrl; private TokenCredential credential; private boolean avroSpecificReader; private Integer maxSchemaMapSize; /** * Instantiates instance of Builder class. - * Supplies client defaults. + * Supplies default avro.specific.reader value. * - * @param registryUrl base schema registry URL for storing and fetching schemas */ - public SchemaRegistryAvroDeserializerBuilder(String registryUrl) { - this.registryUrl = registryUrl; + public SchemaRegistryAvroDeserializerBuilder() { + this.registryUrl = null; this.credential = null; this.avroSpecificReader = false; this.maxSchemaMapSize = null; } + /** + * Sets the service endpoint for the Azure Schema Registry instance. + * + * @return The updated {@link SchemaRegistryAvroDeserializerBuilder} object. + * @param schemaRegistryUrl The URL of the Azure Schema Registry instance + * @throws NullPointerException if {@code schemaRegistryUrl} is null + */ + public SchemaRegistryAvroDeserializerBuilder schemaRegistryUrl(String schemaRegistryUrl) { + Objects.requireNonNull(schemaRegistryUrl, "'schemaRegistryUrl' cannot be null."); + this.registryUrl = schemaRegistryUrl; + return this; + } + /** * * @param credential TokenCredential to be used for authenticating with Azure Schema Registry Service @@ -81,10 +97,11 @@ public SchemaRegistryAvroAsyncDeserializer buildAsyncClient() { * @throws IllegalArgumentException if credential is not set. */ public SchemaRegistryAvroDeserializer buildSyncClient() { - return new SchemaRegistryAvroDeserializer( - this.registryUrl, - this.credential, - this.avroSpecificReader, - this.maxSchemaMapSize); + CachedSchemaRegistryClient client = new CachedSchemaRegistryClientBuilder() + .endpoint(registryUrl) + .credential(credential) + .maxSchemaMapSize(maxSchemaMapSize) + .buildClient(); + return new SchemaRegistryAvroDeserializer(client, this.avroSpecificReader); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java index 2ea74915c75e..03791b6ba264 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java @@ -3,10 +3,9 @@ package com.azure.data.schemaregistry.avro; -import com.azure.core.credential.TokenCredential; import com.azure.data.schemaregistry.AbstractDataSerializer; import com.azure.data.schemaregistry.SerializationException; -import com.azure.data.schemaregistry.client.CachedSchemaRegistryClientBuilder; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClient; /** * A serializer implementation capable of serializing objects and automatedly storing serialization schemas @@ -19,16 +18,10 @@ * @see AbstractDataSerializer See AbstractDataSerializer for internal serialization implementation */ public class SchemaRegistryAvroSerializer extends AbstractDataSerializer { - SchemaRegistryAvroSerializer(String registryUrl, - TokenCredential credential, + SchemaRegistryAvroSerializer(CachedSchemaRegistryClient registryClient, String schemaGroup, - boolean autoRegisterSchemas, - Integer maxSchemaMapSize) { - super(new CachedSchemaRegistryClientBuilder() - .endpoint(registryUrl) - .credential(credential) - .maxSchemaMapSize(maxSchemaMapSize) - .buildClient()); + boolean autoRegisterSchemas) { + super(registryClient); setByteEncoder(new AvroByteEncoder()); @@ -41,9 +34,8 @@ public class SchemaRegistryAvroSerializer extends AbstractDataSerializer { * @param object target of serialization * @return byte array containing GUID reference to schema, then the object serialized into bytes * @throws SerializationException Throws on serialization failure. - * Exception may contain inner exceptions detailing failure condition. */ - public byte[] serializeSync(Object object) throws SerializationException { + public byte[] serialize(Object object) throws SerializationException { if (object == null) { return null; } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java index ec37817d3dfe..50145d43b37c 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerBuilder.java @@ -5,12 +5,16 @@ import com.azure.core.credential.TokenCredential; import com.azure.data.schemaregistry.AbstractDataSerializer; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClient; +import com.azure.data.schemaregistry.client.CachedSchemaRegistryClientBuilder; + +import java.util.Objects; /** * Builder implemenation for building {@link SchemaRegistryAvroSerializer} and {@link SchemaRegistryAvroAsyncSerializer} */ public final class SchemaRegistryAvroSerializerBuilder { - private final String registryUrl; + private String registryUrl; private TokenCredential credential; private boolean autoRegisterSchemas; private String schemaGroup; @@ -19,17 +23,28 @@ public final class SchemaRegistryAvroSerializerBuilder { /** * Instantiates instance of Builder class. * Supplies client defaults. - * - * @param registryUrl base schema registry URL for storing and fetching schemas */ - private SchemaRegistryAvroSerializerBuilder(String registryUrl) { - this.registryUrl = registryUrl; + private SchemaRegistryAvroSerializerBuilder() { + this.registryUrl = null; this.credential = null; this.autoRegisterSchemas = AbstractDataSerializer.AUTO_REGISTER_SCHEMAS_DEFAULT; this.schemaGroup = AbstractDataSerializer.SCHEMA_GROUP_DEFAULT; this.maxSchemaMapSize = null; } + /** + * Sets the service endpoint for the Azure Schema Registry instance. + * + * @return The updated {@link SchemaRegistryAvroSerializerBuilder} object. + * @param schemaRegistryUrl The URL of the Azure Schema Registry instance + * @throws NullPointerException if {@code schemaRegistryUrl} is null + */ + public SchemaRegistryAvroSerializerBuilder schemaRegistryUrl(String schemaRegistryUrl) { + Objects.requireNonNull(schemaRegistryUrl, "'schemaRegistryUrl' cannot be null."); + this.registryUrl = schemaRegistryUrl; + return this; + } + /** * Specifies schema group for interacting with Azure Schema Registry service. * @@ -102,11 +117,12 @@ public SchemaRegistryAvroAsyncSerializer buildAsyncClient() { * @throws IllegalArgumentException if credential is not set. */ public SchemaRegistryAvroSerializer buildSyncClient() { - return new SchemaRegistryAvroSerializer( - this.registryUrl, - this.credential, - this.schemaGroup, - this.autoRegisterSchemas, - this.maxSchemaMapSize); + CachedSchemaRegistryClient client = new CachedSchemaRegistryClientBuilder() + .endpoint(registryUrl) + .credential(credential) + .maxSchemaMapSize(maxSchemaMapSize) + .buildClient(); + + return new SchemaRegistryAvroSerializer(client, this.schemaGroup, this.autoRegisterSchemas); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/module-info.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/module-info.java index 2418ccc22285..69127c51a063 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/module-info.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/module-info.java @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -module com.azure.data.schemaregistry.serde.avro { +module com.azure.data.schemaregistry.avro { requires transitive com.azure.core; - exports com.azure.data.schemaregistry.serde.avro; + exports com.azure.data.schemaregistry.avro; } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/data/schemaregistry/avro/AvroByteDecoderTest.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteDecoderTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/data/schemaregistry/avro/AvroByteDecoderTest.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java b/sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/data/schemaregistry/avro/AvroByteEncoderTest.java similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/schemaregistry/avro/AvroByteEncoderTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/data/schemaregistry/avro/AvroByteEncoderTest.java diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java index 91eb8208f940..436a73a2b937 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/AbstractDataDeserializer.java @@ -20,7 +20,7 @@ public abstract class AbstractDataDeserializer extends AbstractDataSerDe { private final ClientLogger logger = new ClientLogger(AbstractDataDeserializer.class); - protected final Map byteDecoderMap = new ConcurrentHashMap<>(); + private final Map byteDecoderMap = new ConcurrentHashMap<>(); /** * Constructor called by all concrete implementation constructors. @@ -61,12 +61,11 @@ protected Object deserialize(byte[] payload) throws SerializationException { new SerializationException(String.format("Failed to retrieve schema for id %s", schemaGuid), e)); } - // TODO: how to handle unknown formats if (payloadSchema == null) { throw logger.logExceptionAsError( new SerializationException( - String.format("Cast failure for REST object from registry. Object type: %s", - registryObject.deserialize().getClass().getName()))); + String.format("Payload schema returned as null. Schema type: %s, Schema ID: %s", + registryObject.getSchemaType(), registryObject.getSchemaId()))); } int start = buffer.position() + buffer.arrayOffset(); diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java index 734b154c162a..65116e772250 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/ByteEncoder.java @@ -26,7 +26,7 @@ public interface ByteEncoder extends Codec { * @return String representation of schema object parameter * @throws SerializationException if generating string representation of schema fails */ - String getSchemaString(Object object) throws SerializationException; + String getSchemaString(Object object); // TODO: Method does not currently require schema object to be passed since schemas can be derived from // Avro objects. JSON implementation would be the same. @@ -36,5 +36,5 @@ public interface ByteEncoder extends Codec { * @return output stream containing byte representation of object * @throws SerializationException if generating byte representation of object fails */ - ByteArrayOutputStream encode(Object object) throws SerializationException; + ByteArrayOutputStream encode(Object object); } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SerializationException.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SerializationException.java index b22134563c12..a4f6b5f6065e 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SerializationException.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SerializationException.java @@ -3,10 +3,12 @@ package com.azure.data.schemaregistry; +import com.azure.core.exception.AzureException; + /** * Exception thrown by Schema Registry serializer/deserializer implementations for runtime error cases. */ -public class SerializationException extends RuntimeException { +public class SerializationException extends AzureException { /** * @param s error message explaining serde operation failure */ diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java index 3fb25a73d14b..6f1da7c4a6cd 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/CachedSchemaRegistryClientBuilder.java @@ -88,12 +88,13 @@ public CachedSchemaRegistryClientBuilder() { * @throws IllegalArgumentException if {@code schemaRegistryUrl} cannot be parsed into a valid URL */ public CachedSchemaRegistryClientBuilder endpoint(String schemaRegistryUrl) { - Objects.requireNonNull(schemaRegistryUrl, "'endpoint' cannot be null."); + Objects.requireNonNull(schemaRegistryUrl, "'schemaRegistryUrl' cannot be null."); try { new URL(schemaRegistryUrl); } catch (MalformedURLException ex) { - throw logger.logExceptionAsWarning(new IllegalArgumentException("'endpoint' must be a valid URL.", ex)); + throw logger.logExceptionAsWarning( + new IllegalArgumentException("'schemaRegistryUrl' must be a valid URL.", ex)); } if (schemaRegistryUrl.endsWith("/")) { @@ -217,6 +218,7 @@ public CachedSchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { * @return The updated {@link CachedSchemaRegistryClientBuilder} object. */ public CachedSchemaRegistryClientBuilder addSchemaParser(Codec codec) { + Objects.requireNonNull(codec, "'codec' cannot be null."); if (CoreUtils.isNullOrEmpty(codec.schemaType())) { throw logger.logExceptionAsError( new IllegalArgumentException("Serialization type cannot be null or empty.")); diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java index 7f593da1e945..2af1d810d07b 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/client/SchemaRegistryObject.java @@ -66,7 +66,12 @@ public Object deserialize() { logger.verbose("Deserializing schema, id: '{}', schema string '{}'", this.schemaId, schemaString); - this.deserialized = parseMethod.apply(schemaString); + try { + this.deserialized = parseMethod.apply(schemaString); + } catch (Exception e) { + logger.logExceptionAsError(new SchemaRegistryClientException("Failed to deserialize schema", e)); + } + } return deserialized; } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/module-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/module-info.java index 5c6d7383fdba..1858b02d6f17 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/module-info.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/module-info.java @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -module com.azure.data.schemaregistry.serde.common { - requires com.azure.core; +module com.azure.data.schemaregistry { + requires transitive com.azure.core; exports com.azure.data.schemaregistry; exports com.azure.data.schemaregistry.client; diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/TestDummyDeserializer.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/TestDummyDeserializer.java index 4a99d814af9c..591ffd95f172 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/TestDummyDeserializer.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/TestDummyDeserializer.java @@ -9,6 +9,6 @@ public class TestDummyDeserializer extends AbstractDataDeserializer { TestDummyDeserializer(SchemaRegistryClient mockClient) { super(mockClient); ByteDecoder sampleDecoder = new SampleByteDecoder(); - this.byteDecoderMap.put(sampleDecoder.schemaType(), sampleDecoder); + this.loadByteDecoder(sampleDecoder); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.json b/sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.json new file mode 100644 index 000000000000..3a6f605d3aa7 --- /dev/null +++ b/sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.json @@ -0,0 +1,576 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Azure Schema Registry Rest Service", + "version": "1.0.0-beta" + }, + "paths": { + "/$schemagroups": { + "get": { + "summary": "Get list of schema groups", + "description": "Get all schema groups in namespace.", + "operationId": "getGroups", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + }, + "tags": [ + "groups" + ] + } + }, + "/$schemagroups/getSchemaById/{schema-id}": { + "get": { + "summary": "Get schema by schema ID", + "description": "Get schema by schema ID.", + "operationId": "getSchemaById", + "parameters": [ + { + "name": "schema-id", + "in": "path", + "description": "schema ID referencing specific schema in registry namespace", + "required": true, + "schema": { + "type": "string", + "format": "uuid" + } + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/SchemaBytePayloadResponse" + }, + "404": { + "description": "Schema with matching ID not found" + } + }, + "tags": [ + "runtime" + ] + } + }, + "/$schemagroups/{group-name}": { + "parameters": [ + { + "name": "group-name", + "in": "path", + "description": "schema group", + "required": true, + "schema": { + "type": "string" + } + } + ], + "get": { + "summary": "Get schema group", + "description": "Get schema group description in registry namespace.", + "operationId": "getGroup", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SchemaGroup" + } + } + } + }, + "404": { + "description": "Specified group not found" + } + }, + "tags": [ + "groups" + ] + }, + "put": { + "summary": "Create schema group", + "description": "Create schema group with specified schema type in registry namespace.", + "operationId": "createGroup", + "requestBody": { + "description": "schema group description", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SchemaGroup" + } + } + } + }, + "responses": { + "201": { + "description": "Created", + "headers": { + "Location": { + "schema": { + "type": "string" + } + } + } + }, + "409": { + "description": "Schema group already exists" + } + }, + "tags": [ + "groups" + ] + }, + "delete": { + "summary": "Delete schema group", + "description": "Delete schema group in schema registry namespace.", + "operationId": "deleteGroup", + "responses": { + "204": { + "description": "OK no content" + }, + "404": { + "description": "Specified group not found" + } + }, + "tags": [ + "groups" + ] + } + }, + "/$schemagroups/{group-name}/schemas": { + "parameters": [ + { + "name": "group-name", + "in": "path", + "description": "schema group", + "required": true, + "schema": { + "type": "string" + } + } + ], + "get": { + "tags": [ + "groups" + ], + "summary": "Get schemas for group name", + "description": "Returns schema by group name.", + "operationId": "getSchemasByGroup", + "responses": { + "200": { + "description": "OK", + "headers": { + "X-Schema-Type": { + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + "404": { + "description": "Group not found" + } + } + }, + "delete": { + "tags": [ + "groups" + ], + "summary": "Deletes all schemas in group", + "description": "Deletes all schemas under specified group name.", + "operationId": "deleteSchemasByGroup", + "responses": { + "204": { + "description": "OK no content" + }, + "404": { + "description": "Group not found" + } + } + } + }, + "/$schemagroups/{group-name}/schemas/{schema-name}": { + "parameters": [ + { + "name": "group-name", + "in": "path", + "description": "schema group", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "schema-name", + "in": "path", + "description": "schema name", + "required": true, + "schema": { + "type": "string" + } + } + ], + "post": { + "summary": "Get schema ID by schema content", + "description": "Get ID for schema with matching byte content and schema type.", + "operationId": "getIdBySchemaContent", + "parameters": [ + { + "in": "header", + "name": "X-Schema-Type", + "schema": { + "type": "string" + }, + "required": true + } + ], + "requestBody": { + "description": "schema content", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SchemaBytePayload" + } + } + } + }, + "responses": { + "200": { + "$ref": "#/components/responses/SchemaIdResponse" + }, + "404": { + "description": "Matching schema not found" + } + }, + "tags": [ + "runtime" + ] + }, + "put": { + "summary": "Register schema", + "description": "Register schema. If schema of specified name does not exist in specified group, schema is created at version 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. If schema with identical content already exists, existing schema's ID is returned. \n", + "operationId": "createSchema", + "parameters": [ + { + "in": "header", + "name": "X-Schema-Type", + "schema": { + "type": "string" + }, + "required": true + } + ], + "requestBody": { + "description": "schema content", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SchemaBytePayload" + } + } + } + }, + "responses": { + "200": { + "$ref": "#/components/responses/SchemaIdResponse" + }, + "400": { + "description": "Invalid request" + } + }, + "tags": [ + "runtime" + ] + }, + "get": { + "summary": "Get latest version of schema", + "description": "Get latest version of schema.", + "operationId": "getLatestSchema", + "responses": { + "200": { + "$ref": "#/components/responses/SchemaBytePayloadResponse" + } + }, + "tags": [ + "schemas" + ] + }, + "delete": { + "summary": "Delete schema", + "operationId": "deleteSchema", + "responses": { + "204": { + "description": "OK no content" + }, + "404": { + "description": "Matching schema not found" + } + }, + "tags": [ + "schemas" + ] + } + }, + "/$schemagroups/{group-name}/schemas/{schema-name}/versions": { + "parameters": [ + { + "name": "group-name", + "in": "path", + "description": "schema group", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "schema-name", + "in": "path", + "description": "schema name", + "required": true, + "schema": { + "type": "string" + } + } + ], + "get": { + "summary": "Get list of versions", + "description": "Get list of versions for specified schema", + "operationId": "getSchemaVersions", + "responses": { + "200": { + "description": "OK", + "headers": { + "X-Schema-Type": { + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "integer" + } + } + } + } + } + }, + "tags": [ + "schemas" + ] + } + }, + "/$schemagroups/{group-name}/schemas/{schema-name}/versions/{version-number}": { + "parameters": [ + { + "name": "group-name", + "in": "path", + "description": "schema group", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "schema-name", + "in": "path", + "description": "schema name", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "version-number", + "in": "path", + "description": "version number", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "get": { + "summary": "Get specified version of schema", + "operationId": "getSchemaVersion", + "responses": { + "200": { + "$ref": "#/components/responses/SchemaBytePayloadResponse" + }, + "404": { + "description": "Specified schema not found" + } + }, + "tags": [ + "schemas" + ] + }, + "delete": { + "summary": "Delete specified version of schema", + "operationId": "deleteSchemaVersion", + "responses": { + "204": { + "description": "OK no content" + } + }, + "tags": [ + "schemas" + ] + } + } + }, + "components": { + "schemas": { + "SchemaId": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + } + }, + "SchemaBytePayload": { + "type": "string" + }, + "SchemaGroup": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "createdTimeUtc": { + "type": "string", + "format": "date-time" + }, + "updatedTimeUtc": { + "type": "string", + "format": "date-time" + }, + "schemaType": { + "type": "string" + }, + "schemaCompatibility": { + "type": "integer", + "description": "schema compatibility mode enum, defined by supported schema type" + }, + "groupProperties": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "responses": { + "SchemaIdResponse": { + "description": "OK", + "headers": { + "Location": { + "schema": { + "type": "string" + } + }, + "X-Schema-Type": { + "schema": { + "type": "string" + } + }, + "X-Schema-Id": { + "schema": { + "type": "string", + "format": "uuid" + }, + "description": "unique schema identifier" + }, + "X-Schema-Id-Location": { + "schema": { + "type": "string", + "format": "url" + }, + "description": "location of schema resource" + }, + "X-Schema-Version": { + "schema": { + "type": "integer" + }, + "description": "version of returned schema" + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SchemaId" + } + } + } + }, + "SchemaBytePayloadResponse": { + "description": "OK", + "headers": { + "Location": { + "schema": { + "type": "string" + } + }, + "X-Schema-Type": { + "schema": { + "type": "string" + } + }, + "X-Schema-Id": { + "schema": { + "type": "string", + "format": "uuid" + }, + "description": "unique schema identifier" + }, + "X-Schema-Id-Location": { + "schema": { + "type": "string", + "format": "url" + }, + "description": "location of schema resource" + }, + "X-Schema-Version": { + "schema": { + "type": "integer" + }, + "description": "version of returned schema" + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SchemaBytePayload" + } + } + } + } + } + } + } \ No newline at end of file diff --git a/sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.yaml b/sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.yaml deleted file mode 100644 index bf924360babc..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.yaml +++ /dev/null @@ -1,378 +0,0 @@ -openapi: 3.0.0 -info: - title: Azure Schema Registry Rest Service - version: 1.0.0-beta -paths: - /$schemagroups: - get: - summary: 'Get list of schema groups' - description: 'Get all schema groups in namespace.' - operationId: getGroups - responses: - '200': - description: OK - content: - application/json: - schema: - type: array - items: - type: string - tags: - - 'groups' - /$schemagroups/getSchemaById/{schema-id}: - get: - summary: Get schema by schema ID - description: Get schema by schema ID. - operationId: getSchemaById - parameters: - - name: schema-id - in: path - description: schema ID referencing specific schema in registry namespace - required: true - schema: - type: string - format: uuid - responses: - '200': - $ref: '#/components/responses/SchemaBytePayloadResponse' - '404': - description: Schema with matching ID not found - tags: - - 'runtime' - /$schemagroups/{group-name}: - parameters: - - name: group-name - in: path - description: schema group - required: true - schema: - type: string - get: - summary: Get schema group - description: Get schema group description in registry namespace. - operationId: getGroup - responses: - '200': - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/SchemaGroup' - '404': - description: Specified group not found - tags: - - 'groups' - put: - summary: Create schema group - description: Create schema group with specified schema type in registry namespace. - operationId: createGroup - requestBody: - description: schema group description - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/SchemaGroup' - responses: - '201': - description: Created - headers: - Location: - schema: - type: string - '409': - description: Schema group already exists - tags: - - 'groups' - delete: - summary: Delete schema group - description: Delete schema group in schema registry namespace. - operationId: deleteGroup - responses: - '204': - description: OK no content - '404': - description: Specified group not found - tags: - - 'groups' - /$schemagroups/{group-name}/schemas: - parameters: - - name: group-name - in: path - description: schema group - required: true - schema: - type: string - get: - tags: - - 'groups' - summary: Get schemas for group name - description: Returns schema by group name. - operationId: getSchemasByGroup - responses: - '200': - description: OK - headers: - X-Schema-Type: - schema: - type: string - content: - application/json: - schema: - type: array - items: - type: string - '404': - description: Group not found - delete: - tags: - - 'groups' - summary: Deletes all schemas in group - description: Deletes all schemas under specified group name. - operationId: deleteSchemasByGroup - responses: - '204': - description: OK no content - '404': - description: Group not found - /$schemagroups/{group-name}/schemas/{schema-name}: - parameters: - - name: group-name - in: path - description: schema group - required: true - schema: - type: string - - name: schema-name - in: path - description: schema name - required: true - schema: - type: string - post: - summary: Get schema ID by schema content - description: Get ID for schema with matching byte content and schema type. - operationId: getIdBySchemaContent - parameters: - - in: header - name: X-Schema-Type - schema: - type: string - required: true - requestBody: - description: schema content - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/SchemaBytePayload' - responses: - '200': - $ref: '#/components/responses/SchemaIdResponse' - '404': - description: Matching schema not found - tags: - - 'runtime' - put: - summary: Register schema - description: > - Register schema. - If schema of specified name does not exist in specified group, schema is created at version 1. - If schema of specified name exists already in specified group, schema is created at latest version + 1. - If schema with identical content already exists, existing schema's ID is returned. - operationId: createSchema - parameters: - - in: header - name: X-Schema-Type - schema: - type: string - required: true - requestBody: - description: schema content - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/SchemaBytePayload' - responses: - '200': - $ref: '#/components/responses/SchemaIdResponse' - '400': - description: Invalid request - tags: - - 'runtime' - get: - summary: Get latest version of schema - description: Get latest version of schema. - operationId: getLatestSchema - responses: - '200': - $ref: '#/components/responses/SchemaBytePayloadResponse' - tags: - - 'schemas' - delete: - summary: Delete schema - operationId: deleteSchema - responses: - '204': - description: OK no content - '404': - description: Matching schema not found - tags: - - 'schemas' - /$schemagroups/{group-name}/schemas/{schema-name}/versions: - parameters: - - name: group-name - in: path - description: schema group - required: true - schema: - type: string - - name: schema-name - in: path - description: schema name - required: true - schema: - type: string - get: - summary: Get list of versions - description: Get list of versions for specified schema - operationId: getSchemaVersions - responses: - '200': - description: OK - headers: - X-Schema-Type: - schema: - type: string - content: - application/json: - schema: - type: array - items: - type: integer - tags: - - 'schemas' - /$schemagroups/{group-name}/schemas/{schema-name}/versions/{version-number}: - parameters: - - name: group-name - in: path - description: schema group - required: true - schema: - type: string - - name: schema-name - in: path - description: schema name - required: true - schema: - type: string - - name: version-number - in: path - description: version number - required: true - schema: - type: integer - get: - summary: Get specified version of schema - operationId: getSchemaVersion - responses: - '200': - $ref: '#/components/responses/SchemaBytePayloadResponse' - '404': - description: Specified schema not found - tags: - - 'schemas' - delete: - summary: Delete specified version of schema - operationId: deleteSchemaVersion - responses: - '204': - description: OK no content - tags: - - 'schemas' - -components: - schemas: - SchemaId: - type: object - properties: - id: - type: string - SchemaBytePayload: - type: string - SchemaGroup: - type: object - properties: - name: - type: string - createdTimeUtc: - type: string - format: date-time - updatedTimeUtc: - type: string - format: date-time - schemaType: - type: string - schemaCompatibility: - type: integer - description: schema compatibility mode enum, defined by supported schema type - groupProperties: - type: object - additionalProperties: - type: string - responses: - SchemaIdResponse: - description: OK - headers: - Location: - schema: - type: string - X-Schema-Type: - schema: - type: string - X-Schema-Id: - schema: - type: string - format: uuid - description: unique schema identifier - X-Schema-Id-Location: - schema: - type: string - format: url - description: location of schema resource - X-Schema-Version: - schema: - type: integer - description: version of returned schema - content: - application/json: - schema: - $ref: '#/components/schemas/SchemaId' - SchemaBytePayloadResponse: - description: OK - headers: - Location: - schema: - type: string - X-Schema-Type: - schema: - type: string - X-Schema-Id: - schema: - type: string - format: uuid - description: unique schema identifier - X-Schema-Id-Location: - schema: - type: string - format: url - description: location of schema resource - X-Schema-Version: - schema: - type: integer - description: version of returned schema - content: - application/json: - schema: - $ref: '#/components/schemas/SchemaBytePayload' \ No newline at end of file From 101aeebbd0ab2198e58b83c5deeddcd80660ef4b Mon Sep 17 00:00:00 2001 From: Arthur Erlendsson Date: Fri, 29 May 2020 13:49:58 -0700 Subject: [PATCH 43/43] spotbugs update --- .../src/main/resources/spotbugs/spotbugs-exclude.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index b1887cf0e539..fa11a5a2e4ec 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -1901,7 +1901,7 @@ consistently instead of injecting null payload behavior from the payload. --> - +