From 63045ea1269b20f29d7dc3c496bd2855f856726f Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 22 Jul 2020 16:49:55 -0700 Subject: [PATCH 01/45] Generated the SchemaRegistry SDK. Set up project and custom client. Fixed original swagger and made a separate PR for it. --- .../Azure.Data.SchemaRegistry.sln | 37 + .../Azure.Data.SchemaRegistry/CHANGELOG.md | 46 + .../Directory.Build.props | 6 + .../Azure.Data.SchemaRegistry/README.md | 104 ++ .../api/Azure.Template.netstandard2.0.cs | 32 + .../src/Azure.Data.SchemaRegistry.csproj | 28 + .../Models/SchemaGroup.Serialization.cs | 119 ++ .../src/Generated/Models/SchemaGroup.cs | 57 + .../Models/SchemaId.Serialization.cs | 29 + .../src/Generated/Models/SchemaId.cs | 28 + .../ServiceCreateOrUpdateGroupHeaders.cs | 22 + .../Generated/ServiceCreateSchemaHeaders.cs | 30 + .../ServiceGetIdBySchemaContentHeaders.cs | 30 + .../ServiceGetLatestSchemaHeaders.cs | 30 + .../Generated/ServiceGetSchemaByIdHeaders.cs | 30 + .../ServiceGetSchemaVersionHeaders.cs | 30 + .../ServiceGetSchemaVersionsHeaders.cs | 22 + .../ServiceGetSchemasByGroupHeaders.cs | 22 + .../src/Generated/ServiceRestClient.cs | 1135 +++++++++++++++++ .../src/SchemaRegistryClient.cs | 89 ++ .../src/SchemaRegistryClientOptions.cs | 41 + .../Azure.Data.SchemaRegistry/src/autorest.md | 7 + .../Azure.Data.SchemaRegistry.Tests.csproj | 22 + .../SchemaRegistryClientSamples.HelloWorld.cs | 27 + .../tests/SchemaRegistryClientLiveTest.cs | 36 + .../SchemaRegistryClientTestEnvironment.cs | 16 + .../RecordsGoHere.md | 1 + sdk/schemaregistry/ci.yml | 31 + sdk/schemaregistry/test-resources.json | 81 ++ 29 files changed, 2188 insertions(+) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/Azure.Data.SchemaRegistry.sln create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/Directory.Build.props create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Template.netstandard2.0.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.Serialization.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.Serialization.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateOrUpdateGroupHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateSchemaHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetIdBySchemaContentHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetLatestSchemaHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaByIdHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionsHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemasByGroupHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceRestClient.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Azure.Data.SchemaRegistry.Tests.csproj create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientTestEnvironment.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/RecordsGoHere.md create mode 100644 sdk/schemaregistry/ci.yml create mode 100644 sdk/schemaregistry/test-resources.json diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/Azure.Data.SchemaRegistry.sln b/sdk/schemaregistry/Azure.Data.SchemaRegistry/Azure.Data.SchemaRegistry.sln new file mode 100644 index 0000000000000..5e4abf209e1a6 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/Azure.Data.SchemaRegistry.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry", "src\Azure.Data.SchemaRegistry.csproj", "{E33D09D9-D809-472C-82E6-6A26BDB86FC2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry.Tests", "tests\Azure.Data.SchemaRegistry.Tests.csproj", "{4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{8052009B-2126-44A3-88CD-4F3B17894C64}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.Build.0 = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.Build.0 = Release|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md new file mode 100644 index 0000000000000..c0ee0e516f7a9 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md @@ -0,0 +1,46 @@ +# Release History + +## 1.0.2-preview.15 (2020-06-29) +- Test release pipeline + +## 1.0.2-preview.14 (2020-06-02) +- Test release pipeline + +## 1.0.2-preview.13 (2020-03-23) +- Test release pipeline + +## 1.0.2-preview.12 (2020-03-23) +- Test release pipeline + +## 1.0.2-preview.11 (2020-03-23) +- Test release pipeline + +## 1.0.2-preview.10 (2020-03-23) +- Test release pipeline + +## 1.0.2-preview.9 (2020-03-17) +- Test release pipeline + +## 1.0.2-preview.8 (2020-03-10) +- Testing out release pipeline + +## 1.0.2-preview.7 (2020-03-06) +- Testing out release pipeline + +## 1.0.2-preview.6 (2020-02-24) +### Added +- Testing Changelog added section +- Testing Links [Project Site](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/template/Azure.Template/README.md) +- Test `Highlighted Code` + +## 1.0.2-preview.5 (2020-02-24) +### Added +- Testing Changelog added section +- Testing Links [Project Site](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/template/Azure.Template/README.md) +- Test `Highlighted Code` + +## 1.0.2-preview.4 (2019-12-17) +- Version Bump + +## 1.0.2-preview.3 (2019-12-17) +- Started changelog to capture release notes. \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/Directory.Build.props b/sdk/schemaregistry/Azure.Data.SchemaRegistry/Directory.Build.props new file mode 100644 index 0000000000000..1a9611bd49242 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/Directory.Build.props @@ -0,0 +1,6 @@ + + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md new file mode 100644 index 0000000000000..3411f7736223f --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md @@ -0,0 +1,104 @@ +# README.md template + +Use the guidelines in each section of this template to ensure consistency and readability of your README. The README resides in your package's GitHub repository at the root of its directory within the repo. It's also used as the package distribution page (NuGet, PyPi, npm, etc.) and as a Quickstart on docs.microsoft.com. See [README-EXAMPLE.md](README-EXAMPLE.md) for an example following this template. + +**Title**: The H1 of your README should be in the format: `# [Product Name] client library for [Language]` + +* All headings, including the H1, should use **sentence-style capitalization**. Refer to the [Microsoft Style Guide][style-guide-msft] and [Microsoft Cloud Style Guide][style-guide-cloud] for more information. +* Example: `# Azure Batch client library for Python` + +# Azure Template client library for .NET + +**Introduction**: The introduction appears directly under the title (H1) of your README. + +* **DO NOT** use an "Introduction" or "Overview" heading (H2) for this section. +* First sentence: **Describe the service** briefly. You can usually use the first line of the service's docs landing page for this (Example: [Cosmos DB docs landing page](https://docs.microsoft.com/azure/cosmos-db/)). +* Next, add a **bulleted list** of the **most common tasks** supported by the package or library, prefaced with "Use the client library for [Product Name] to:". Then, provide code snippets for these tasks in the [Examples](#examples) section later in the document. Keep the task list short but include those tasks most developers need to perform with your package. +* Include this single line of links targeting your product's content at the bottom of the introduction, making any adjustments as necessary (for example, NuGet instead of PyPi): + + [Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/azure-batch) | [Package (PyPi)](https://pypi.org/project/azure-batch/) | [API reference documentation](https://docs.microsoft.com/python/api/overview/azure/batch?view=azure-python) | [Product documentation](https://docs.microsoft.com/azure/batch/) + +> TIP: Your README should be as **brief** as possible but **no more brief** than necessary to get a developer new to Azure, the service, or the package up and running quickly. Keep it brief, but include everything a developer needs to make their first API call successfully. + +## Getting started + +This section should include everything a developer needs to do to install and create their first client connection *very quickly*. + +### Install the package + +First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `pip install package-name`, but should enable a developer to successfully install the package from NuGet, pip, npm, Maven, or even cloning a GitHub repository. + +### Prerequisites + +Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB: + +> You must have an [Azure subscription](https://azure.microsoft.com/free/), [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API), and [Python 3.6+](https://www.python.org/downloads/) to use this package. + +### Authenticate the client + +If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating. + +For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object. + +## Key concepts + +The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity. + +## Examples + +Include code snippets and short descriptions for each task you listed in the [Introduction](#introduction) (the bulleted list). Briefly explain each operation, but include enough clarity to explain complex or otherwise tricky operations. + +If possible, use the same example snippets that your in-code documentation uses. For example, use the snippets in your `examples.py` that Sphinx ingests via its [literalinclude](https://www.sphinx-doc.org/en/1.5/markup/code.html?highlight=code%20examples#includes) directive. The `examples.py` file containing the snippets should reside alongside your package's code, and should be tested in an automated fashion. + +Each example in the *Examples* section starts with an H3 that describes the example. At the top of this section, just under the *Examples* H2, add a bulleted list linking to each example H3. Each example should deep-link to the types and/or members used in the example. + +* [Create the thing](#create-the-thing) +* [Get the thing](#get-the-thing) +* [List the things](#list-the-things) + +### Create the thing + +Use the [create_thing](not-valid-link) method to create a Thing reference; this method does not make a network call. To persist the Thing in the service, call [Thing.save](not-valid-link). + +```Python +thing = client.create_thing(id, name) +thing.save() +``` + +### Get the thing + +The [get_thing](not-valid-link) method retrieves a Thing from the service. The `id` parameter is the unique ID of the Thing, not its "name" property. + +```C# Snippet:GetSecret +var client = new MiniSecretClient(new Uri(endpoint), new DefaultAzureCredential()); + +SecretBundle secret = client.GetSecret("TestSecret"); + +Console.WriteLine(secret.Value); +```Python +things = client.list_things() +``` + +## Troubleshooting + +Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery. + +Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API. + +If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code. + +## Next steps + +* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory. +* If appropriate, point users to other packages that might be useful. +* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for. + +## Contributing + +This is a template, but your SDK readme should include details on how to contribute code to the repo/package. + + +[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization +[style-guide-cloud]: https://worldready.cloudapp.net/Styleguide/Read?id=2696&topicid=25357 + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftemplate%2FAzure.Template%2FREADME.png) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Template.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Template.netstandard2.0.cs new file mode 100644 index 0000000000000..4f6ce7887d818 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Template.netstandard2.0.cs @@ -0,0 +1,32 @@ +namespace Azure.Template +{ + public partial class MiniSecretClient + { + protected MiniSecretClient() { } + public MiniSecretClient(System.Uri endpoint, Azure.Core.TokenCredential credential) { } + public MiniSecretClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.Template.MiniSecretClientOptions options) { } + public virtual Azure.Response GetSecret(string secretName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetSecretAsync(string secretName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } + public partial class MiniSecretClientOptions : Azure.Core.ClientOptions + { + public MiniSecretClientOptions(Azure.Template.MiniSecretClientOptions.ServiceVersion version = Azure.Template.MiniSecretClientOptions.ServiceVersion.V7_0) { } + public enum ServiceVersion + { + V7_0 = 1, + } + } +} +namespace Azure.Template.Models +{ + public partial class SecretBundle + { + internal SecretBundle() { } + public string ContentType { get { throw null; } } + public string Id { get { throw null; } } + public string Kid { get { throw null; } } + public bool? Managed { get { throw null; } } + public System.Collections.Generic.IReadOnlyDictionary Tags { get { throw null; } } + public string Value { get { throw null; } } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj new file mode 100644 index 0000000000000..3addbb4dce273 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj @@ -0,0 +1,28 @@ + + + Azure Schema Registry SDK + Azure Schema Registry SDK + 1.0.0-preview.1 + Azure;Schema Registry;SchemaRegistry;.NET;Data;$(PackageCommonTags) + $(RequiredTargetFrameworks) + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.Serialization.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.Serialization.cs new file mode 100644 index 0000000000000..31440eade4715 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.Serialization.cs @@ -0,0 +1,119 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry.Models +{ + public partial class SchemaGroup : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"); + writer.WriteStringValue(Name); + } + if (Optional.IsDefined(CreatedTimeUtc)) + { + writer.WritePropertyName("createdTimeUtc"); + writer.WriteStringValue(CreatedTimeUtc.Value, "O"); + } + if (Optional.IsDefined(UpdatedTimeUtc)) + { + writer.WritePropertyName("updatedTimeUtc"); + writer.WriteStringValue(UpdatedTimeUtc.Value, "O"); + } + if (Optional.IsDefined(SchemaType)) + { + writer.WritePropertyName("schemaType"); + writer.WriteStringValue(SchemaType); + } + if (Optional.IsDefined(Etag)) + { + writer.WritePropertyName("etag"); + writer.WriteStringValue(Etag); + } + if (Optional.IsDefined(SchemaCompatibility)) + { + writer.WritePropertyName("schemaCompatibility"); + writer.WriteNumberValue(SchemaCompatibility.Value); + } + if (Optional.IsCollectionDefined(GroupProperties)) + { + writer.WritePropertyName("groupProperties"); + writer.WriteStartObject(); + foreach (var item in GroupProperties) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + internal static SchemaGroup DeserializeSchemaGroup(JsonElement element) + { + Optional name = default; + Optional createdTimeUtc = default; + Optional updatedTimeUtc = default; + Optional schemaType = default; + Optional etag = default; + Optional schemaCompatibility = default; + Optional> groupProperties = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name")) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("createdTimeUtc")) + { + createdTimeUtc = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("updatedTimeUtc")) + { + updatedTimeUtc = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("schemaType")) + { + schemaType = property.Value.GetString(); + continue; + } + if (property.NameEquals("etag")) + { + etag = property.Value.GetString(); + continue; + } + if (property.NameEquals("schemaCompatibility")) + { + schemaCompatibility = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("groupProperties")) + { + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + groupProperties = dictionary; + continue; + } + } + return new SchemaGroup(name.Value, Optional.ToNullable(createdTimeUtc), Optional.ToNullable(updatedTimeUtc), schemaType.Value, etag.Value, Optional.ToNullable(schemaCompatibility), Optional.ToDictionary(groupProperties)); + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.cs new file mode 100644 index 0000000000000..1ea73db3a6d23 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry.Models +{ + /// The SchemaGroup. + public partial class SchemaGroup + { + /// Initializes a new instance of SchemaGroup. + public SchemaGroup() + { + GroupProperties = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of SchemaGroup. + /// The name of the schema group. + /// The creation time in UTC of the schema group. + /// The update time in UTC of the schema group. + /// The schema type of the schema group. + /// Define an read-only identifier that uniquely describe an instance of the group. This is returned from get call for update purposes. Setting this on create or update has no effect. + /// schema compatibility mode enum, defined by supported schema type. + /// Dictionary of <string>. + internal SchemaGroup(string name, DateTimeOffset? createdTimeUtc, DateTimeOffset? updatedTimeUtc, string schemaType, string etag, int? schemaCompatibility, IDictionary groupProperties) + { + Name = name; + CreatedTimeUtc = createdTimeUtc; + UpdatedTimeUtc = updatedTimeUtc; + SchemaType = schemaType; + Etag = etag; + SchemaCompatibility = schemaCompatibility; + GroupProperties = groupProperties; + } + + /// The name of the schema group. + public string Name { get; set; } + /// The creation time in UTC of the schema group. + public DateTimeOffset? CreatedTimeUtc { get; set; } + /// The update time in UTC of the schema group. + public DateTimeOffset? UpdatedTimeUtc { get; set; } + /// The schema type of the schema group. + public string SchemaType { get; set; } + /// Define an read-only identifier that uniquely describe an instance of the group. This is returned from get call for update purposes. Setting this on create or update has no effect. + public string Etag { get; set; } + /// schema compatibility mode enum, defined by supported schema type. + public int? SchemaCompatibility { get; set; } + /// Dictionary of <string>. + public IDictionary GroupProperties { get; } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.Serialization.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.Serialization.cs new file mode 100644 index 0000000000000..cccb726f4f915 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.Serialization.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry.Models +{ + public partial class SchemaId + { + internal static SchemaId DeserializeSchemaId(JsonElement element) + { + Optional id = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id")) + { + id = property.Value.GetString(); + continue; + } + } + return new SchemaId(id.Value); + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs new file mode 100644 index 0000000000000..22bbb14500851 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Data.SchemaRegistry.Models +{ + /// The SchemaId. + public partial class SchemaId + { + /// Initializes a new instance of SchemaId. + internal SchemaId() + { + } + + /// Initializes a new instance of SchemaId. + /// The id of the schema. + internal SchemaId(string id) + { + Id = id; + } + + /// The id of the schema. + public string Id { get; } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateOrUpdateGroupHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateOrUpdateGroupHeaders.cs new file mode 100644 index 0000000000000..ae053a1917f68 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateOrUpdateGroupHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class ServiceCreateOrUpdateGroupHeaders + { + private readonly Response _response; + public ServiceCreateOrUpdateGroupHeaders(Response response) + { + _response = response; + } + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateSchemaHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateSchemaHeaders.cs new file mode 100644 index 0000000000000..4717e60bc8c63 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateSchemaHeaders.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class ServiceCreateSchemaHeaders + { + private readonly Response _response; + public ServiceCreateSchemaHeaders(Response response) + { + _response = response; + } + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; + /// unique schema identifier. + public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; + /// location of schema resource. + public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; + /// version of returned schema. + public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetIdBySchemaContentHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetIdBySchemaContentHeaders.cs new file mode 100644 index 0000000000000..5ffdbe4ca7ee9 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetIdBySchemaContentHeaders.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class ServiceGetIdBySchemaContentHeaders + { + private readonly Response _response; + public ServiceGetIdBySchemaContentHeaders(Response response) + { + _response = response; + } + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; + /// unique schema identifier. + public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; + /// location of schema resource. + public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; + /// version of returned schema. + public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetLatestSchemaHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetLatestSchemaHeaders.cs new file mode 100644 index 0000000000000..fe5289075589e --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetLatestSchemaHeaders.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class ServiceGetLatestSchemaHeaders + { + private readonly Response _response; + public ServiceGetLatestSchemaHeaders(Response response) + { + _response = response; + } + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; + /// unique schema identifier. + public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; + /// location of schema resource. + public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; + /// version of returned schema. + public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaByIdHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaByIdHeaders.cs new file mode 100644 index 0000000000000..d9fc8a9b0980e --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaByIdHeaders.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class ServiceGetSchemaByIdHeaders + { + private readonly Response _response; + public ServiceGetSchemaByIdHeaders(Response response) + { + _response = response; + } + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; + /// unique schema identifier. + public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; + /// location of schema resource. + public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; + /// version of returned schema. + public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionHeaders.cs new file mode 100644 index 0000000000000..6d9600a9df7ca --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionHeaders.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class ServiceGetSchemaVersionHeaders + { + private readonly Response _response; + public ServiceGetSchemaVersionHeaders(Response response) + { + _response = response; + } + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; + /// unique schema identifier. + public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; + /// location of schema resource. + public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; + /// version of returned schema. + public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionsHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionsHeaders.cs new file mode 100644 index 0000000000000..f3b6fe33a6fd3 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionsHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class ServiceGetSchemaVersionsHeaders + { + private readonly Response _response; + public ServiceGetSchemaVersionsHeaders(Response response) + { + _response = response; + } + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemasByGroupHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemasByGroupHeaders.cs new file mode 100644 index 0000000000000..cf0b811e3d1df --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemasByGroupHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class ServiceGetSchemasByGroupHeaders + { + private readonly Response _response; + public ServiceGetSchemasByGroupHeaders(Response response) + { + _response = response; + } + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceRestClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceRestClient.cs new file mode 100644 index 0000000000000..f861b31260f99 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceRestClient.cs @@ -0,0 +1,1135 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Data.SchemaRegistry.Models; + +namespace Azure.Data.SchemaRegistry +{ + internal partial class ServiceRestClient + { + private Uri endpoint; + private ClientDiagnostics _clientDiagnostics; + private HttpPipeline _pipeline; + + /// Initializes a new instance of ServiceRestClient. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// server parameter. + public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null) + { + endpoint ??= new Uri(""); + + this.endpoint = endpoint; + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + internal HttpMessage CreateGetGroupsRequest() + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups", false); + request.Uri = uri; + return message; + } + + /// Get all schema groups in namespace. + /// The cancellation token to use. + public async Task>> GetGroupsAsync(CancellationToken cancellationToken = default) + { + using var message = CreateGetGroupsRequest(); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetString()); + } + value = array; + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Get all schema groups in namespace. + /// The cancellation token to use. + public Response> GetGroups(CancellationToken cancellationToken = default) + { + using var message = CreateGetGroupsRequest(); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + IReadOnlyList value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetString()); + } + value = array; + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetSchemaByIdRequest(string schemaId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/getSchemaById/", false); + uri.AppendPath(schemaId, true); + request.Uri = uri; + return message; + } + + /// Get schema by schema ID. + /// schema ID referencing specific schema in registry namespace. + /// The cancellation token to use. + public async Task> GetSchemaByIdAsync(string schemaId, CancellationToken cancellationToken = default) + { + if (schemaId == null) + { + throw new ArgumentNullException(nameof(schemaId)); + } + + using var message = CreateGetSchemaByIdRequest(schemaId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceGetSchemaByIdHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = document.RootElement.GetString(); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 404: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Get schema by schema ID. + /// schema ID referencing specific schema in registry namespace. + /// The cancellation token to use. + public ResponseWithHeaders GetSchemaById(string schemaId, CancellationToken cancellationToken = default) + { + if (schemaId == null) + { + throw new ArgumentNullException(nameof(schemaId)); + } + + using var message = CreateGetSchemaByIdRequest(schemaId); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceGetSchemaByIdHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = document.RootElement.GetString(); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 404: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetGroupRequest(string groupName) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + request.Uri = uri; + return message; + } + + /// Get schema group description in registry namespace. + /// schema group. + /// The cancellation token to use. + public async Task> GetGroupAsync(string groupName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + + using var message = CreateGetGroupRequest(groupName); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + SchemaGroup value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = SchemaGroup.DeserializeSchemaGroup(document.RootElement); + return Response.FromValue(value, message.Response); + } + case 404: + return Response.FromValue(null, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Get schema group description in registry namespace. + /// schema group. + /// The cancellation token to use. + public Response GetGroup(string groupName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + + using var message = CreateGetGroupRequest(groupName); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + SchemaGroup value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = SchemaGroup.DeserializeSchemaGroup(document.RootElement); + return Response.FromValue(value, message.Response); + } + case 404: + return Response.FromValue(null, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateCreateOrUpdateGroupRequest(string groupName, SchemaGroup body, string ifMatch) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + request.Uri = uri; + if (ifMatch != null) + { + request.Headers.Add("If-Match", ifMatch); + } + request.Headers.Add("Content-Type", "application/json"); + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(body); + request.Content = content; + return message; + } + + /// Create or update schema group with specified schema type in registry namespace. + /// schema group. + /// schema group description. + /// Specify an ETag value to perform update operation only on schema group with a matching Guid value. If a '*' is supplied then update is performed without ETag check. Supplying empty value will enforce the create-only behavior. + /// The cancellation token to use. + public async Task> CreateOrUpdateGroupAsync(string groupName, SchemaGroup body, string ifMatch = null, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (body == null) + { + throw new ArgumentNullException(nameof(body)); + } + + using var message = CreateCreateOrUpdateGroupRequest(groupName, body, ifMatch); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceCreateOrUpdateGroupHeaders(message.Response); + switch (message.Response.Status) + { + case 201: + case 409: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Create or update schema group with specified schema type in registry namespace. + /// schema group. + /// schema group description. + /// Specify an ETag value to perform update operation only on schema group with a matching Guid value. If a '*' is supplied then update is performed without ETag check. Supplying empty value will enforce the create-only behavior. + /// The cancellation token to use. + public ResponseWithHeaders CreateOrUpdateGroup(string groupName, SchemaGroup body, string ifMatch = null, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (body == null) + { + throw new ArgumentNullException(nameof(body)); + } + + using var message = CreateCreateOrUpdateGroupRequest(groupName, body, ifMatch); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceCreateOrUpdateGroupHeaders(message.Response); + switch (message.Response.Status) + { + case 201: + case 409: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateDeleteGroupRequest(string groupName) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + request.Uri = uri; + return message; + } + + /// Delete schema group in schema registry namespace. + /// schema group. + /// The cancellation token to use. + public async Task DeleteGroupAsync(string groupName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + + using var message = CreateDeleteGroupRequest(groupName); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 204: + case 404: + return message.Response; + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Delete schema group in schema registry namespace. + /// schema group. + /// The cancellation token to use. + public Response DeleteGroup(string groupName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + + using var message = CreateDeleteGroupRequest(groupName); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 204: + case 404: + return message.Response; + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetSchemasByGroupRequest(string groupName) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas", false); + request.Uri = uri; + return message; + } + + /// Returns schema by group name. + /// schema group. + /// The cancellation token to use. + public async Task, ServiceGetSchemasByGroupHeaders>> GetSchemasByGroupAsync(string groupName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + + using var message = CreateGetSchemasByGroupRequest(groupName); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceGetSchemasByGroupHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetString()); + } + value = array; + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 404: + return ResponseWithHeaders.FromValue, ServiceGetSchemasByGroupHeaders>(null, headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Returns schema by group name. + /// schema group. + /// The cancellation token to use. + public ResponseWithHeaders, ServiceGetSchemasByGroupHeaders> GetSchemasByGroup(string groupName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + + using var message = CreateGetSchemasByGroupRequest(groupName); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceGetSchemasByGroupHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + IReadOnlyList value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetString()); + } + value = array; + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 404: + return ResponseWithHeaders.FromValue, ServiceGetSchemasByGroupHeaders>(null, headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateDeleteSchemasByGroupRequest(string groupName) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas", false); + request.Uri = uri; + return message; + } + + /// Deletes all schemas under specified group name. + /// schema group. + /// The cancellation token to use. + public async Task DeleteSchemasByGroupAsync(string groupName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + + using var message = CreateDeleteSchemasByGroupRequest(groupName); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 204: + case 404: + return message.Response; + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Deletes all schemas under specified group name. + /// schema group. + /// The cancellation token to use. + public Response DeleteSchemasByGroup(string groupName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + + using var message = CreateDeleteSchemasByGroupRequest(groupName); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 204: + case 404: + return message.Response; + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetIdBySchemaContentRequest(string groupName, string schemaName, string xSchemaType, string body) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas/", false); + uri.AppendPath(schemaName, true); + request.Uri = uri; + request.Headers.Add("X-Schema-Type", xSchemaType); + request.Headers.Add("Content-Type", "application/json"); + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteStringValue(body); + request.Content = content; + return message; + } + + /// Get ID for schema with matching byte content and schema type. + /// schema group. + /// schema name. + /// The String to use. + /// schema content. + /// The cancellation token to use. + public async Task> GetIdBySchemaContentAsync(string groupName, string schemaName, string xSchemaType, string body, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + if (xSchemaType == null) + { + throw new ArgumentNullException(nameof(xSchemaType)); + } + if (body == null) + { + throw new ArgumentNullException(nameof(body)); + } + + using var message = CreateGetIdBySchemaContentRequest(groupName, schemaName, xSchemaType, body); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceGetIdBySchemaContentHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + SchemaId value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = SchemaId.DeserializeSchemaId(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 404: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Get ID for schema with matching byte content and schema type. + /// schema group. + /// schema name. + /// The String to use. + /// schema content. + /// The cancellation token to use. + public ResponseWithHeaders GetIdBySchemaContent(string groupName, string schemaName, string xSchemaType, string body, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + if (xSchemaType == null) + { + throw new ArgumentNullException(nameof(xSchemaType)); + } + if (body == null) + { + throw new ArgumentNullException(nameof(body)); + } + + using var message = CreateGetIdBySchemaContentRequest(groupName, schemaName, xSchemaType, body); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceGetIdBySchemaContentHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + SchemaId value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = SchemaId.DeserializeSchemaId(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 404: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateCreateSchemaRequest(string groupName, string schemaName, string xSchemaType, string body) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas/", false); + uri.AppendPath(schemaName, true); + request.Uri = uri; + request.Headers.Add("X-Schema-Type", xSchemaType); + request.Headers.Add("Content-Type", "application/json"); + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteStringValue(body); + request.Content = content; + return message; + } + + /// + /// 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. + /// . + /// + /// schema group. + /// schema name. + /// The String to use. + /// schema content. + /// The cancellation token to use. + public async Task> CreateSchemaAsync(string groupName, string schemaName, string xSchemaType, string body, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + if (xSchemaType == null) + { + throw new ArgumentNullException(nameof(xSchemaType)); + } + if (body == null) + { + throw new ArgumentNullException(nameof(body)); + } + + using var message = CreateCreateSchemaRequest(groupName, schemaName, xSchemaType, body); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceCreateSchemaHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + SchemaId value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = SchemaId.DeserializeSchemaId(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 400: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// + /// 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. + /// . + /// + /// schema group. + /// schema name. + /// The String to use. + /// schema content. + /// The cancellation token to use. + public ResponseWithHeaders CreateSchema(string groupName, string schemaName, string xSchemaType, string body, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + if (xSchemaType == null) + { + throw new ArgumentNullException(nameof(xSchemaType)); + } + if (body == null) + { + throw new ArgumentNullException(nameof(body)); + } + + using var message = CreateCreateSchemaRequest(groupName, schemaName, xSchemaType, body); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceCreateSchemaHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + SchemaId value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = SchemaId.DeserializeSchemaId(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 400: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetLatestSchemaRequest(string groupName, string schemaName) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas/", false); + uri.AppendPath(schemaName, true); + request.Uri = uri; + return message; + } + + /// Get latest version of schema. + /// schema group. + /// schema name. + /// The cancellation token to use. + public async Task> GetLatestSchemaAsync(string groupName, string schemaName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateGetLatestSchemaRequest(groupName, schemaName); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceGetLatestSchemaHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = document.RootElement.GetString(); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Get latest version of schema. + /// schema group. + /// schema name. + /// The cancellation token to use. + public ResponseWithHeaders GetLatestSchema(string groupName, string schemaName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateGetLatestSchemaRequest(groupName, schemaName); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceGetLatestSchemaHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = document.RootElement.GetString(); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateDeleteSchemaRequest(string groupName, string schemaName) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas/", false); + uri.AppendPath(schemaName, true); + request.Uri = uri; + return message; + } + + /// Delete schema. + /// schema group. + /// schema name. + /// The cancellation token to use. + public async Task DeleteSchemaAsync(string groupName, string schemaName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateDeleteSchemaRequest(groupName, schemaName); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 204: + case 404: + return message.Response; + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Delete schema. + /// schema group. + /// schema name. + /// The cancellation token to use. + public Response DeleteSchema(string groupName, string schemaName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateDeleteSchemaRequest(groupName, schemaName); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 204: + case 404: + return message.Response; + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetSchemaVersionsRequest(string groupName, string schemaName) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas/", false); + uri.AppendPath(schemaName, true); + uri.AppendPath("/versions", false); + request.Uri = uri; + return message; + } + + /// Get list of versions for specified schema. + /// schema group. + /// schema name. + /// The cancellation token to use. + public async Task, ServiceGetSchemaVersionsHeaders>> GetSchemaVersionsAsync(string groupName, string schemaName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateGetSchemaVersionsRequest(groupName, schemaName); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceGetSchemaVersionsHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetInt32()); + } + value = array; + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Get list of versions for specified schema. + /// schema group. + /// schema name. + /// The cancellation token to use. + public ResponseWithHeaders, ServiceGetSchemaVersionsHeaders> GetSchemaVersions(string groupName, string schemaName, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateGetSchemaVersionsRequest(groupName, schemaName); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceGetSchemaVersionsHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + IReadOnlyList value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetInt32()); + } + value = array; + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetSchemaVersionRequest(string groupName, string schemaName, int versionNumber) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas/", false); + uri.AppendPath(schemaName, true); + uri.AppendPath("/versions/", false); + uri.AppendPath(versionNumber, true); + request.Uri = uri; + return message; + } + + /// Get specified version of schema. + /// schema group. + /// schema name. + /// version number. + /// The cancellation token to use. + public async Task> GetSchemaVersionAsync(string groupName, string schemaName, int versionNumber, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateGetSchemaVersionRequest(groupName, schemaName, versionNumber); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceGetSchemaVersionHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = document.RootElement.GetString(); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 404: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Get specified version of schema. + /// schema group. + /// schema name. + /// version number. + /// The cancellation token to use. + public ResponseWithHeaders GetSchemaVersion(string groupName, string schemaName, int versionNumber, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateGetSchemaVersionRequest(groupName, schemaName, versionNumber); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceGetSchemaVersionHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = document.RootElement.GetString(); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 404: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateDeleteSchemaVersionRequest(string groupName, string schemaName, int versionNumber) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas/", false); + uri.AppendPath(schemaName, true); + uri.AppendPath("/versions/", false); + uri.AppendPath(versionNumber, true); + request.Uri = uri; + return message; + } + + /// Delete specified version of schema. + /// schema group. + /// schema name. + /// version number. + /// The cancellation token to use. + public async Task DeleteSchemaVersionAsync(string groupName, string schemaName, int versionNumber, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateDeleteSchemaVersionRequest(groupName, schemaName, versionNumber); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 204: + return message.Response; + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Delete specified version of schema. + /// schema group. + /// schema name. + /// version number. + /// The cancellation token to use. + public Response DeleteSchemaVersion(string groupName, string schemaName, int versionNumber, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + + using var message = CreateDeleteSchemaVersionRequest(groupName, schemaName, versionNumber); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 204: + return message.Response; + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs new file mode 100644 index 0000000000000..28f8ca5bd7b61 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.Data.SchemaRegistry +{ + /// + /// The Schema Registry client. + /// + public class SchemaRegistryClient + { + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + internal ServiceRestClient RestClient { get; } + + /// + /// Initializes a new instance of the . + /// + public SchemaRegistryClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new SchemaRegistryClientOptions()) + { + } + + /// + /// Initializes a new instance of the . + /// + public SchemaRegistryClient(Uri endpoint, TokenCredential credential, SchemaRegistryClientOptions options) : this( + new ClientDiagnostics(options), + HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, "https://vault.azure.net/.default")), + endpoint.ToString())//, + //options.Version) + { + } + + /// Initializes a new instance of SchemaRegistryClient for mocking. + protected SchemaRegistryClient() + { + } + /// Initializes a new instance of SchemaRegistryClient. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The vault name, for example https://myvault.vault.azure.net. + ///// Api Version. + internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string vaultBaseUrl)//, string apiVersion = "7.0") + { + RestClient = new ServiceRestClient(clientDiagnostics, pipeline, new Uri(vaultBaseUrl)); + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + // /// The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission. + // /// The name of the secret. + // /// The cancellation token to use. + // public virtual async Task> GetSecretAsync(string secretName, CancellationToken cancellationToken = default) + // { + // using var scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSecret"); + // scope.Start(); + // try + // { + // return await RestClient.GetSecretAsync(secretName, cancellationToken).ConfigureAwait(false); + // } + // catch (Exception e) + // { + // scope.Failed(e); + // throw; + // } + // } + + // /// The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission. + // /// The name of the secret. + // /// The cancellation token to use. + // public virtual Response GetSecret(string secretName, CancellationToken cancellationToken = default) + // { + // using var scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSecret"); + // scope.Start(); + // try + // { + // return RestClient.GetSecret(secretName, cancellationToken); + // } + // catch (Exception e) + // { + // scope.Failed(e); + // throw; + // } + // } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs new file mode 100644 index 0000000000000..02e83fb9e05b1 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + /// + /// The options for + /// + public class SchemaRegistryClientOptions : ClientOptions + { + internal string Version { get; } + + /// + /// Initializes a new instance of the . + /// + public SchemaRegistryClientOptions(ServiceVersion version = ServiceVersion.V1_0) + { + Version = version switch + { + ServiceVersion.V1_0 => "1.0", + _ => throw new ArgumentException($"The service version {version} is not supported by this library.", nameof(version)) + }; + } + + /// + /// The Schema Registry service version. + /// + public enum ServiceVersion + { + /// + /// The 1.0 of the Schema Registry service. + /// +#pragma warning disable CA1707 // Remove the underscores from member name + V1_0 = 1 +#pragma warning restore + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md new file mode 100644 index 0000000000000..f8f912fa13787 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md @@ -0,0 +1,7 @@ +# Generated code configuration + +Run `dotnet msbuild /t:GenerateCode` to generate code. + +``` yaml +input-file: https://github.com/MiYanni/azure-sdk-for-java/blob/08e2a148900e23dd015a973721d2b2acb395601f/sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.json +``` diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Azure.Data.SchemaRegistry.Tests.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Azure.Data.SchemaRegistry.Tests.csproj new file mode 100644 index 0000000000000..7834a3986139d --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Azure.Data.SchemaRegistry.Tests.csproj @@ -0,0 +1,22 @@ + + + $(RequiredTargetFrameworks) + + + + + + + + + + + + + + + + + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs new file mode 100644 index 0000000000000..9eb7cae1e3f7a --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core.TestFramework; +using Azure.Identity; +using NUnit.Framework; + +namespace Azure.Data.SchemaRegistry.Tests.Samples +{ + public class SchemaRegistryClientSamples : SamplesBase + { + [Test] + public void GettingASecret() + { + var endpoint = TestEnvironment.KeyVaultUri; + + #region Snippet:GetSecret + var client = new SchemaRegistryClient(new Uri(endpoint), new DefaultAzureCredential()); + + //SecretBundle secret = client.GetSecret("TestSecret"); + + //Console.WriteLine(secret.Value); + #endregion + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs new file mode 100644 index 0000000000000..380183a137e07 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core.TestFramework; + +namespace Azure.Data.SchemaRegistry.Tests +{ + public class SchemaRegistryClientLiveTest : RecordedTestBase + { + public SchemaRegistryClientLiveTest(bool isAsync) : base(isAsync) + { + //TODO: https://github.com/Azure/autorest.csharp/issues/689 + TestDiagnostics = false; + } + + private SchemaRegistryClient CreateClient() + { + return InstrumentClient(new SchemaRegistryClient( + new Uri(TestEnvironment.KeyVaultUri), + TestEnvironment.Credential, + Recording.InstrumentClientOptions(new SchemaRegistryClientOptions()) + )); + } + + //[Test] + //public async Task CanGetSecret() + //{ + // var client = CreateClient(); + + // var secret = await client.GetSecretAsync("TestSecret"); + + // Assert.AreEqual("Very secret value", secret.Value.Value); + //} + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientTestEnvironment.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientTestEnvironment.cs new file mode 100644 index 0000000000000..6bbf530aa5540 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientTestEnvironment.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; + +namespace Azure.Data.SchemaRegistry.Tests +{ + public class SchemaRegistryClientTestEnvironment : TestEnvironment + { + public SchemaRegistryClientTestEnvironment() : base("schemaregistry") + { + } + + public string KeyVaultUri => GetRecordedVariable("KEYVAULT_URL"); + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/RecordsGoHere.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/RecordsGoHere.md new file mode 100644 index 0000000000000..f6e0339af6f3e --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/RecordsGoHere.md @@ -0,0 +1 @@ +Placeholder \ No newline at end of file diff --git a/sdk/schemaregistry/ci.yml b/sdk/schemaregistry/ci.yml new file mode 100644 index 0000000000000..d6e1f89cf0011 --- /dev/null +++ b/sdk/schemaregistry/ci.yml @@ -0,0 +1,31 @@ +# DO NOT EDIT THIS FILE +# This file is generated automatically and any changes will be lost. +trigger: + branches: + include: + - master + - hotfix/* + - release/* + paths: + include: + - sdk/template/ + +pr: + branches: + include: + - master + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/template/ + +extends: + template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: template + ArtifactName: packages + Artifacts: + - name: Azure.Template + safeName: AzureTemplate \ No newline at end of file diff --git a/sdk/schemaregistry/test-resources.json b/sdk/schemaregistry/test-resources.json new file mode 100644 index 0000000000000..46c4dc7699972 --- /dev/null +++ b/sdk/schemaregistry/test-resources.json @@ -0,0 +1,81 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "baseName": { + "type": "string", + "defaultValue": "[resourceGroup().name]", + "metadata": { + "description": "The base resource name." + } + }, + "tenantId": { + "type": "string", + "defaultValue": "72f988bf-86f1-41af-91ab-2d7cd011db47", + "metadata": { + "description": "The tenant ID to which the application and resources belong." + } + }, + "testApplicationOid": { + "type": "string", + "defaultValue": "b3653439-8136-4cd5-aac3-2a9460871ca6", + "metadata": { + "description": "The client OID to grant access to test resources." + } + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]", + "metadata": { + "description": "The location of the resource. By default, this is the same as the resource group." + } + } + }, + "variables": { + "azureKeyVaultUrl": "[format('https://{0}.vault.azure.net', parameters('baseName'))]" + }, + "resources": [ + { + "type": "Microsoft.KeyVault/vaults", + "apiVersion": "2016-10-01", + "name": "[parameters('baseName')]", + "location": "[parameters('location')]", + "properties": { + "sku": { + "family": "A", + "name": "premium" + }, + "tenantId": "[parameters('tenantId')]", + "accessPolicies": [ + { + "tenantId": "[parameters('tenantId')]", + "objectId": "[parameters('testApplicationOid')]", + "permissions": { + "secrets": [ + "get" + ] + } + } + ] + } + }, + { + "type": "Microsoft.KeyVault/vaults/secrets", + "name": "[concat(parameters('baseName'), '/TestSecret')]", + "apiVersion": "2016-10-01", + "location": "[parameters('location')]", + "dependsOn": [ + "[resourceId('Microsoft.KeyVault/vaults', parameters('baseName'))]" + ], + "properties": { + "value": "Very secret value" + } + } + ], + "outputs": { + "KEYVAULT_URL": { + "type": "string", + "value": "[variables('azureKeyVaultUrl')]" + } + } +} From 6b44ba3bf7d9279826d014e75f238eb69ee8e168 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Thu, 30 Jul 2020 17:54:23 -0700 Subject: [PATCH 02/45] Update to latest swagger with description fixes. --- .../Models/SchemaGroup.Serialization.cs | 119 -- .../src/Generated/Models/SchemaGroup.cs | 57 - .../src/Generated/Models/SchemaId.cs | 2 +- .../src/Generated/SchemaGetByIdHeaders.cs | 31 + .../Generated/SchemaGetIdByContentHeaders.cs | 31 + .../src/Generated/SchemaRegisterHeaders.cs | 31 + .../src/Generated/SchemaRestClient.cs | 324 +++++ .../ServiceCreateOrUpdateGroupHeaders.cs | 22 - .../Generated/ServiceCreateSchemaHeaders.cs | 30 - .../ServiceGetIdBySchemaContentHeaders.cs | 30 - .../ServiceGetLatestSchemaHeaders.cs | 30 - .../Generated/ServiceGetSchemaByIdHeaders.cs | 30 - .../ServiceGetSchemaVersionHeaders.cs | 30 - .../ServiceGetSchemaVersionsHeaders.cs | 22 - .../ServiceGetSchemasByGroupHeaders.cs | 22 - .../src/Generated/ServiceRestClient.cs | 1135 ----------------- .../src/SchemaRegistryClient.cs | 4 +- .../Azure.Data.SchemaRegistry/src/autorest.md | 2 +- 18 files changed, 421 insertions(+), 1531 deletions(-) delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.Serialization.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetByIdHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetIdByContentHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRegisterHeaders.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateOrUpdateGroupHeaders.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateSchemaHeaders.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetIdBySchemaContentHeaders.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetLatestSchemaHeaders.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaByIdHeaders.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionHeaders.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionsHeaders.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemasByGroupHeaders.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceRestClient.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.Serialization.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.Serialization.cs deleted file mode 100644 index 31440eade4715..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.Serialization.cs +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Text.Json; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry.Models -{ - public partial class SchemaGroup : IUtf8JsonSerializable - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - if (Optional.IsDefined(Name)) - { - writer.WritePropertyName("name"); - writer.WriteStringValue(Name); - } - if (Optional.IsDefined(CreatedTimeUtc)) - { - writer.WritePropertyName("createdTimeUtc"); - writer.WriteStringValue(CreatedTimeUtc.Value, "O"); - } - if (Optional.IsDefined(UpdatedTimeUtc)) - { - writer.WritePropertyName("updatedTimeUtc"); - writer.WriteStringValue(UpdatedTimeUtc.Value, "O"); - } - if (Optional.IsDefined(SchemaType)) - { - writer.WritePropertyName("schemaType"); - writer.WriteStringValue(SchemaType); - } - if (Optional.IsDefined(Etag)) - { - writer.WritePropertyName("etag"); - writer.WriteStringValue(Etag); - } - if (Optional.IsDefined(SchemaCompatibility)) - { - writer.WritePropertyName("schemaCompatibility"); - writer.WriteNumberValue(SchemaCompatibility.Value); - } - if (Optional.IsCollectionDefined(GroupProperties)) - { - writer.WritePropertyName("groupProperties"); - writer.WriteStartObject(); - foreach (var item in GroupProperties) - { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); - } - writer.WriteEndObject(); - } - writer.WriteEndObject(); - } - - internal static SchemaGroup DeserializeSchemaGroup(JsonElement element) - { - Optional name = default; - Optional createdTimeUtc = default; - Optional updatedTimeUtc = default; - Optional schemaType = default; - Optional etag = default; - Optional schemaCompatibility = default; - Optional> groupProperties = default; - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("name")) - { - name = property.Value.GetString(); - continue; - } - if (property.NameEquals("createdTimeUtc")) - { - createdTimeUtc = property.Value.GetDateTimeOffset("O"); - continue; - } - if (property.NameEquals("updatedTimeUtc")) - { - updatedTimeUtc = property.Value.GetDateTimeOffset("O"); - continue; - } - if (property.NameEquals("schemaType")) - { - schemaType = property.Value.GetString(); - continue; - } - if (property.NameEquals("etag")) - { - etag = property.Value.GetString(); - continue; - } - if (property.NameEquals("schemaCompatibility")) - { - schemaCompatibility = property.Value.GetInt32(); - continue; - } - if (property.NameEquals("groupProperties")) - { - Dictionary dictionary = new Dictionary(); - foreach (var property0 in property.Value.EnumerateObject()) - { - dictionary.Add(property0.Name, property0.Value.GetString()); - } - groupProperties = dictionary; - continue; - } - } - return new SchemaGroup(name.Value, Optional.ToNullable(createdTimeUtc), Optional.ToNullable(updatedTimeUtc), schemaType.Value, etag.Value, Optional.ToNullable(schemaCompatibility), Optional.ToDictionary(groupProperties)); - } - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.cs deleted file mode 100644 index 1ea73db3a6d23..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaGroup.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry.Models -{ - /// The SchemaGroup. - public partial class SchemaGroup - { - /// Initializes a new instance of SchemaGroup. - public SchemaGroup() - { - GroupProperties = new ChangeTrackingDictionary(); - } - - /// Initializes a new instance of SchemaGroup. - /// The name of the schema group. - /// The creation time in UTC of the schema group. - /// The update time in UTC of the schema group. - /// The schema type of the schema group. - /// Define an read-only identifier that uniquely describe an instance of the group. This is returned from get call for update purposes. Setting this on create or update has no effect. - /// schema compatibility mode enum, defined by supported schema type. - /// Dictionary of <string>. - internal SchemaGroup(string name, DateTimeOffset? createdTimeUtc, DateTimeOffset? updatedTimeUtc, string schemaType, string etag, int? schemaCompatibility, IDictionary groupProperties) - { - Name = name; - CreatedTimeUtc = createdTimeUtc; - UpdatedTimeUtc = updatedTimeUtc; - SchemaType = schemaType; - Etag = etag; - SchemaCompatibility = schemaCompatibility; - GroupProperties = groupProperties; - } - - /// The name of the schema group. - public string Name { get; set; } - /// The creation time in UTC of the schema group. - public DateTimeOffset? CreatedTimeUtc { get; set; } - /// The update time in UTC of the schema group. - public DateTimeOffset? UpdatedTimeUtc { get; set; } - /// The schema type of the schema group. - public string SchemaType { get; set; } - /// Define an read-only identifier that uniquely describe an instance of the group. This is returned from get call for update purposes. Setting this on create or update has no effect. - public string Etag { get; set; } - /// schema compatibility mode enum, defined by supported schema type. - public int? SchemaCompatibility { get; set; } - /// Dictionary of <string>. - public IDictionary GroupProperties { get; } - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs index 22bbb14500851..c50ab3c41dd11 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs @@ -7,7 +7,7 @@ namespace Azure.Data.SchemaRegistry.Models { - /// The SchemaId. + /// The id of a Schema Registry schema. public partial class SchemaId { /// Initializes a new instance of SchemaId. diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetByIdHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetByIdHeaders.cs new file mode 100644 index 0000000000000..e7343abe81fb9 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetByIdHeaders.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class SchemaGetByIdHeaders + { + private readonly Response _response; + public SchemaGetByIdHeaders(Response response) + { + _response = response; + } + /// URL location of schema, identified by schema group, schema name, and version. + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + /// Serialization type for the schema being stored. + public string XSerialization => _response.Headers.TryGetValue("X-Serialization", out string value) ? value : null; + /// References specific schema in registry namespace. + public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; + /// URL location of schema, identified by schema ID. + public string XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out string value) ? value : null; + /// Version of the returned schema. + public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetIdByContentHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetIdByContentHeaders.cs new file mode 100644 index 0000000000000..8478af4459c47 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetIdByContentHeaders.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class SchemaGetIdByContentHeaders + { + private readonly Response _response; + public SchemaGetIdByContentHeaders(Response response) + { + _response = response; + } + /// URL location of schema, identified by schema group, schema name, and version. + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + /// Serialization type for the schema being stored. + public string XSerialization => _response.Headers.TryGetValue("X-Serialization", out string value) ? value : null; + /// References specific schema in registry namespace. + public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; + /// URL location of schema, identified by schema ID. + public string XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out string value) ? value : null; + /// Version of the returned schema. + public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRegisterHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRegisterHeaders.cs new file mode 100644 index 0000000000000..c494aa7d84c93 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRegisterHeaders.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + internal class SchemaRegisterHeaders + { + private readonly Response _response; + public SchemaRegisterHeaders(Response response) + { + _response = response; + } + /// URL location of schema, identified by schema group, schema name, and version. + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + /// Serialization type for the schema being registered. + public string XSerialization => _response.Headers.TryGetValue("X-Serialization", out string value) ? value : null; + /// References specific schema in registry namespace. + public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; + /// URL location of schema, identified by schema ID. + public string XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out string value) ? value : null; + /// Version of the returned schema. + public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs new file mode 100644 index 0000000000000..38f502e1fc13f --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs @@ -0,0 +1,324 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Data.SchemaRegistry.Models; + +namespace Azure.Data.SchemaRegistry +{ + internal partial class SchemaRestClient + { + private Uri endpoint; + private ClientDiagnostics _clientDiagnostics; + private HttpPipeline _pipeline; + + /// Initializes a new instance of SchemaRestClient. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// server parameter. + public SchemaRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null) + { + endpoint ??= new Uri(""); + + this.endpoint = endpoint; + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + internal HttpMessage CreateGetByIdRequest(string schemaId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/getSchemaById/", false); + uri.AppendPath(schemaId, true); + request.Uri = uri; + return message; + } + + /// Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. + /// References specific schema in registry namespace. + /// The cancellation token to use. + /// is null. + public async Task> GetByIdAsync(string schemaId, CancellationToken cancellationToken = default) + { + if (schemaId == null) + { + throw new ArgumentNullException(nameof(schemaId)); + } + + using var message = CreateGetByIdRequest(schemaId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new SchemaGetByIdHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = document.RootElement.GetString(); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. + /// References specific schema in registry namespace. + /// The cancellation token to use. + /// is null. + public ResponseWithHeaders GetById(string schemaId, CancellationToken cancellationToken = default) + { + if (schemaId == null) + { + throw new ArgumentNullException(nameof(schemaId)); + } + + using var message = CreateGetByIdRequest(schemaId); + _pipeline.Send(message, cancellationToken); + var headers = new SchemaGetByIdHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = document.RootElement.GetString(); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetIdByContentRequest(string groupName, string schemaName, string serializationType, string schemaContent) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas/", false); + uri.AppendPath(schemaName, true); + request.Uri = uri; + request.Headers.Add("serialization-type", serializationType); + request.Headers.Add("Content-Type", "application/json"); + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteStringValue(schemaContent); + request.Content = content; + return message; + } + + /// Gets the ID referencing an existing schema within the specified schema group, as matched by schema content comparison. + /// Schema group under which schema is registered. Group's serialization type should match the serialization type specified in the request. + /// Name of the registered schema. + /// Serialization type of the registered schema. Must match serialization type of the specified schema group. + /// String representation of the registered schema. + /// The cancellation token to use. + /// , , , or is null. + public async Task> GetIdByContentAsync(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + if (serializationType == null) + { + throw new ArgumentNullException(nameof(serializationType)); + } + if (schemaContent == null) + { + throw new ArgumentNullException(nameof(schemaContent)); + } + + using var message = CreateGetIdByContentRequest(groupName, schemaName, serializationType, schemaContent); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new SchemaGetIdByContentHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + SchemaId value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = SchemaId.DeserializeSchemaId(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Gets the ID referencing an existing schema within the specified schema group, as matched by schema content comparison. + /// Schema group under which schema is registered. Group's serialization type should match the serialization type specified in the request. + /// Name of the registered schema. + /// Serialization type of the registered schema. Must match serialization type of the specified schema group. + /// String representation of the registered schema. + /// The cancellation token to use. + /// , , , or is null. + public ResponseWithHeaders GetIdByContent(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + if (serializationType == null) + { + throw new ArgumentNullException(nameof(serializationType)); + } + if (schemaContent == null) + { + throw new ArgumentNullException(nameof(schemaContent)); + } + + using var message = CreateGetIdByContentRequest(groupName, schemaName, serializationType, schemaContent); + _pipeline.Send(message, cancellationToken); + var headers = new SchemaGetIdByContentHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + SchemaId value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = SchemaId.DeserializeSchemaId(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, string serializationType, string schemaContent) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/$schemagroups/", false); + uri.AppendPath(groupName, true); + uri.AppendPath("/schemas/", false); + uri.AppendPath(schemaName, true); + request.Uri = uri; + request.Headers.Add("serialization-type", serializationType); + request.Headers.Add("Content-Type", "application/json"); + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteStringValue(schemaContent); + request.Content = content; + return message; + } + + /// + /// Register new 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. + /// . + /// + /// Schema group under which schema should be registered. Group's serialization type should match the serialization type specified in the request. + /// Name of schema being registered. + /// Serialization type for the schema being registered. Must match serialization type of the specified schema group. + /// String representation of the schema being registered. + /// The cancellation token to use. + /// , , , or is null. + public async Task> RegisterAsync(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + if (serializationType == null) + { + throw new ArgumentNullException(nameof(serializationType)); + } + if (schemaContent == null) + { + throw new ArgumentNullException(nameof(schemaContent)); + } + + using var message = CreateRegisterRequest(groupName, schemaName, serializationType, schemaContent); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new SchemaRegisterHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + SchemaId value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = SchemaId.DeserializeSchemaId(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// + /// Register new 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. + /// . + /// + /// Schema group under which schema should be registered. Group's serialization type should match the serialization type specified in the request. + /// Name of schema being registered. + /// Serialization type for the schema being registered. Must match serialization type of the specified schema group. + /// String representation of the schema being registered. + /// The cancellation token to use. + /// , , , or is null. + public ResponseWithHeaders Register(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + { + if (groupName == null) + { + throw new ArgumentNullException(nameof(groupName)); + } + if (schemaName == null) + { + throw new ArgumentNullException(nameof(schemaName)); + } + if (serializationType == null) + { + throw new ArgumentNullException(nameof(serializationType)); + } + if (schemaContent == null) + { + throw new ArgumentNullException(nameof(schemaContent)); + } + + using var message = CreateRegisterRequest(groupName, schemaName, serializationType, schemaContent); + _pipeline.Send(message, cancellationToken); + var headers = new SchemaRegisterHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + SchemaId value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = SchemaId.DeserializeSchemaId(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateOrUpdateGroupHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateOrUpdateGroupHeaders.cs deleted file mode 100644 index ae053a1917f68..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateOrUpdateGroupHeaders.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using Azure; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry -{ - internal class ServiceCreateOrUpdateGroupHeaders - { - private readonly Response _response; - public ServiceCreateOrUpdateGroupHeaders(Response response) - { - _response = response; - } - public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateSchemaHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateSchemaHeaders.cs deleted file mode 100644 index 4717e60bc8c63..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceCreateSchemaHeaders.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using Azure; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry -{ - internal class ServiceCreateSchemaHeaders - { - private readonly Response _response; - public ServiceCreateSchemaHeaders(Response response) - { - _response = response; - } - public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; - public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; - /// unique schema identifier. - public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; - /// location of schema resource. - public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; - /// version of returned schema. - public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetIdBySchemaContentHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetIdBySchemaContentHeaders.cs deleted file mode 100644 index 5ffdbe4ca7ee9..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetIdBySchemaContentHeaders.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using Azure; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry -{ - internal class ServiceGetIdBySchemaContentHeaders - { - private readonly Response _response; - public ServiceGetIdBySchemaContentHeaders(Response response) - { - _response = response; - } - public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; - public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; - /// unique schema identifier. - public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; - /// location of schema resource. - public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; - /// version of returned schema. - public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetLatestSchemaHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetLatestSchemaHeaders.cs deleted file mode 100644 index fe5289075589e..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetLatestSchemaHeaders.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using Azure; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry -{ - internal class ServiceGetLatestSchemaHeaders - { - private readonly Response _response; - public ServiceGetLatestSchemaHeaders(Response response) - { - _response = response; - } - public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; - public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; - /// unique schema identifier. - public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; - /// location of schema resource. - public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; - /// version of returned schema. - public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaByIdHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaByIdHeaders.cs deleted file mode 100644 index d9fc8a9b0980e..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaByIdHeaders.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using Azure; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry -{ - internal class ServiceGetSchemaByIdHeaders - { - private readonly Response _response; - public ServiceGetSchemaByIdHeaders(Response response) - { - _response = response; - } - public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; - public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; - /// unique schema identifier. - public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; - /// location of schema resource. - public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; - /// version of returned schema. - public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionHeaders.cs deleted file mode 100644 index 6d9600a9df7ca..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionHeaders.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using Azure; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry -{ - internal class ServiceGetSchemaVersionHeaders - { - private readonly Response _response; - public ServiceGetSchemaVersionHeaders(Response response) - { - _response = response; - } - public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; - public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; - /// unique schema identifier. - public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; - /// location of schema resource. - public Uri XSchemaIdLocation => _response.Headers.TryGetValue("X-Schema-Id-Location", out Uri value) ? value : null; - /// version of returned schema. - public int? XSchemaVersion => _response.Headers.TryGetValue("X-Schema-Version", out int? value) ? value : null; - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionsHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionsHeaders.cs deleted file mode 100644 index f3b6fe33a6fd3..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemaVersionsHeaders.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using Azure; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry -{ - internal class ServiceGetSchemaVersionsHeaders - { - private readonly Response _response; - public ServiceGetSchemaVersionsHeaders(Response response) - { - _response = response; - } - public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemasByGroupHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemasByGroupHeaders.cs deleted file mode 100644 index cf0b811e3d1df..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceGetSchemasByGroupHeaders.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using Azure; -using Azure.Core; - -namespace Azure.Data.SchemaRegistry -{ - internal class ServiceGetSchemasByGroupHeaders - { - private readonly Response _response; - public ServiceGetSchemasByGroupHeaders(Response response) - { - _response = response; - } - public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceRestClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceRestClient.cs deleted file mode 100644 index f861b31260f99..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/ServiceRestClient.cs +++ /dev/null @@ -1,1135 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.Pipeline; -using Azure.Data.SchemaRegistry.Models; - -namespace Azure.Data.SchemaRegistry -{ - internal partial class ServiceRestClient - { - private Uri endpoint; - private ClientDiagnostics _clientDiagnostics; - private HttpPipeline _pipeline; - - /// Initializes a new instance of ServiceRestClient. - /// The handler for diagnostic messaging in the client. - /// The HTTP pipeline for sending and receiving REST requests and responses. - /// server parameter. - public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null) - { - endpoint ??= new Uri(""); - - this.endpoint = endpoint; - _clientDiagnostics = clientDiagnostics; - _pipeline = pipeline; - } - - internal HttpMessage CreateGetGroupsRequest() - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups", false); - request.Uri = uri; - return message; - } - - /// Get all schema groups in namespace. - /// The cancellation token to use. - public async Task>> GetGroupsAsync(CancellationToken cancellationToken = default) - { - using var message = CreateGetGroupsRequest(); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 200: - { - IReadOnlyList value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - List array = new List(); - foreach (var item in document.RootElement.EnumerateArray()) - { - array.Add(item.GetString()); - } - value = array; - return Response.FromValue(value, message.Response); - } - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Get all schema groups in namespace. - /// The cancellation token to use. - public Response> GetGroups(CancellationToken cancellationToken = default) - { - using var message = CreateGetGroupsRequest(); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 200: - { - IReadOnlyList value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - List array = new List(); - foreach (var item in document.RootElement.EnumerateArray()) - { - array.Add(item.GetString()); - } - value = array; - return Response.FromValue(value, message.Response); - } - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateGetSchemaByIdRequest(string schemaId) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/getSchemaById/", false); - uri.AppendPath(schemaId, true); - request.Uri = uri; - return message; - } - - /// Get schema by schema ID. - /// schema ID referencing specific schema in registry namespace. - /// The cancellation token to use. - public async Task> GetSchemaByIdAsync(string schemaId, CancellationToken cancellationToken = default) - { - if (schemaId == null) - { - throw new ArgumentNullException(nameof(schemaId)); - } - - using var message = CreateGetSchemaByIdRequest(schemaId); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new ServiceGetSchemaByIdHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - string value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = document.RootElement.GetString(); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 404: - return ResponseWithHeaders.FromValue(null, headers, message.Response); - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Get schema by schema ID. - /// schema ID referencing specific schema in registry namespace. - /// The cancellation token to use. - public ResponseWithHeaders GetSchemaById(string schemaId, CancellationToken cancellationToken = default) - { - if (schemaId == null) - { - throw new ArgumentNullException(nameof(schemaId)); - } - - using var message = CreateGetSchemaByIdRequest(schemaId); - _pipeline.Send(message, cancellationToken); - var headers = new ServiceGetSchemaByIdHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - string value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = document.RootElement.GetString(); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 404: - return ResponseWithHeaders.FromValue(null, headers, message.Response); - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateGetGroupRequest(string groupName) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - request.Uri = uri; - return message; - } - - /// Get schema group description in registry namespace. - /// schema group. - /// The cancellation token to use. - public async Task> GetGroupAsync(string groupName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - - using var message = CreateGetGroupRequest(groupName); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 200: - { - SchemaGroup value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = SchemaGroup.DeserializeSchemaGroup(document.RootElement); - return Response.FromValue(value, message.Response); - } - case 404: - return Response.FromValue(null, message.Response); - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Get schema group description in registry namespace. - /// schema group. - /// The cancellation token to use. - public Response GetGroup(string groupName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - - using var message = CreateGetGroupRequest(groupName); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 200: - { - SchemaGroup value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = SchemaGroup.DeserializeSchemaGroup(document.RootElement); - return Response.FromValue(value, message.Response); - } - case 404: - return Response.FromValue(null, message.Response); - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateCreateOrUpdateGroupRequest(string groupName, SchemaGroup body, string ifMatch) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Put; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - request.Uri = uri; - if (ifMatch != null) - { - request.Headers.Add("If-Match", ifMatch); - } - request.Headers.Add("Content-Type", "application/json"); - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(body); - request.Content = content; - return message; - } - - /// Create or update schema group with specified schema type in registry namespace. - /// schema group. - /// schema group description. - /// Specify an ETag value to perform update operation only on schema group with a matching Guid value. If a '*' is supplied then update is performed without ETag check. Supplying empty value will enforce the create-only behavior. - /// The cancellation token to use. - public async Task> CreateOrUpdateGroupAsync(string groupName, SchemaGroup body, string ifMatch = null, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (body == null) - { - throw new ArgumentNullException(nameof(body)); - } - - using var message = CreateCreateOrUpdateGroupRequest(groupName, body, ifMatch); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new ServiceCreateOrUpdateGroupHeaders(message.Response); - switch (message.Response.Status) - { - case 201: - case 409: - return ResponseWithHeaders.FromValue(headers, message.Response); - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Create or update schema group with specified schema type in registry namespace. - /// schema group. - /// schema group description. - /// Specify an ETag value to perform update operation only on schema group with a matching Guid value. If a '*' is supplied then update is performed without ETag check. Supplying empty value will enforce the create-only behavior. - /// The cancellation token to use. - public ResponseWithHeaders CreateOrUpdateGroup(string groupName, SchemaGroup body, string ifMatch = null, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (body == null) - { - throw new ArgumentNullException(nameof(body)); - } - - using var message = CreateCreateOrUpdateGroupRequest(groupName, body, ifMatch); - _pipeline.Send(message, cancellationToken); - var headers = new ServiceCreateOrUpdateGroupHeaders(message.Response); - switch (message.Response.Status) - { - case 201: - case 409: - return ResponseWithHeaders.FromValue(headers, message.Response); - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateDeleteGroupRequest(string groupName) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Delete; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - request.Uri = uri; - return message; - } - - /// Delete schema group in schema registry namespace. - /// schema group. - /// The cancellation token to use. - public async Task DeleteGroupAsync(string groupName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - - using var message = CreateDeleteGroupRequest(groupName); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 204: - case 404: - return message.Response; - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Delete schema group in schema registry namespace. - /// schema group. - /// The cancellation token to use. - public Response DeleteGroup(string groupName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - - using var message = CreateDeleteGroupRequest(groupName); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 204: - case 404: - return message.Response; - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateGetSchemasByGroupRequest(string groupName) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - uri.AppendPath("/schemas", false); - request.Uri = uri; - return message; - } - - /// Returns schema by group name. - /// schema group. - /// The cancellation token to use. - public async Task, ServiceGetSchemasByGroupHeaders>> GetSchemasByGroupAsync(string groupName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - - using var message = CreateGetSchemasByGroupRequest(groupName); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new ServiceGetSchemasByGroupHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - IReadOnlyList value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - List array = new List(); - foreach (var item in document.RootElement.EnumerateArray()) - { - array.Add(item.GetString()); - } - value = array; - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 404: - return ResponseWithHeaders.FromValue, ServiceGetSchemasByGroupHeaders>(null, headers, message.Response); - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Returns schema by group name. - /// schema group. - /// The cancellation token to use. - public ResponseWithHeaders, ServiceGetSchemasByGroupHeaders> GetSchemasByGroup(string groupName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - - using var message = CreateGetSchemasByGroupRequest(groupName); - _pipeline.Send(message, cancellationToken); - var headers = new ServiceGetSchemasByGroupHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - IReadOnlyList value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - List array = new List(); - foreach (var item in document.RootElement.EnumerateArray()) - { - array.Add(item.GetString()); - } - value = array; - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 404: - return ResponseWithHeaders.FromValue, ServiceGetSchemasByGroupHeaders>(null, headers, message.Response); - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateDeleteSchemasByGroupRequest(string groupName) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Delete; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - uri.AppendPath("/schemas", false); - request.Uri = uri; - return message; - } - - /// Deletes all schemas under specified group name. - /// schema group. - /// The cancellation token to use. - public async Task DeleteSchemasByGroupAsync(string groupName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - - using var message = CreateDeleteSchemasByGroupRequest(groupName); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 204: - case 404: - return message.Response; - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Deletes all schemas under specified group name. - /// schema group. - /// The cancellation token to use. - public Response DeleteSchemasByGroup(string groupName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - - using var message = CreateDeleteSchemasByGroupRequest(groupName); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 204: - case 404: - return message.Response; - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateGetIdBySchemaContentRequest(string groupName, string schemaName, string xSchemaType, string body) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - uri.AppendPath("/schemas/", false); - uri.AppendPath(schemaName, true); - request.Uri = uri; - request.Headers.Add("X-Schema-Type", xSchemaType); - request.Headers.Add("Content-Type", "application/json"); - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteStringValue(body); - request.Content = content; - return message; - } - - /// Get ID for schema with matching byte content and schema type. - /// schema group. - /// schema name. - /// The String to use. - /// schema content. - /// The cancellation token to use. - public async Task> GetIdBySchemaContentAsync(string groupName, string schemaName, string xSchemaType, string body, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - if (xSchemaType == null) - { - throw new ArgumentNullException(nameof(xSchemaType)); - } - if (body == null) - { - throw new ArgumentNullException(nameof(body)); - } - - using var message = CreateGetIdBySchemaContentRequest(groupName, schemaName, xSchemaType, body); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new ServiceGetIdBySchemaContentHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - SchemaId value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = SchemaId.DeserializeSchemaId(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 404: - return ResponseWithHeaders.FromValue(null, headers, message.Response); - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Get ID for schema with matching byte content and schema type. - /// schema group. - /// schema name. - /// The String to use. - /// schema content. - /// The cancellation token to use. - public ResponseWithHeaders GetIdBySchemaContent(string groupName, string schemaName, string xSchemaType, string body, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - if (xSchemaType == null) - { - throw new ArgumentNullException(nameof(xSchemaType)); - } - if (body == null) - { - throw new ArgumentNullException(nameof(body)); - } - - using var message = CreateGetIdBySchemaContentRequest(groupName, schemaName, xSchemaType, body); - _pipeline.Send(message, cancellationToken); - var headers = new ServiceGetIdBySchemaContentHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - SchemaId value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = SchemaId.DeserializeSchemaId(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 404: - return ResponseWithHeaders.FromValue(null, headers, message.Response); - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateCreateSchemaRequest(string groupName, string schemaName, string xSchemaType, string body) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Put; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - uri.AppendPath("/schemas/", false); - uri.AppendPath(schemaName, true); - request.Uri = uri; - request.Headers.Add("X-Schema-Type", xSchemaType); - request.Headers.Add("Content-Type", "application/json"); - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteStringValue(body); - request.Content = content; - return message; - } - - /// - /// 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. - /// . - /// - /// schema group. - /// schema name. - /// The String to use. - /// schema content. - /// The cancellation token to use. - public async Task> CreateSchemaAsync(string groupName, string schemaName, string xSchemaType, string body, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - if (xSchemaType == null) - { - throw new ArgumentNullException(nameof(xSchemaType)); - } - if (body == null) - { - throw new ArgumentNullException(nameof(body)); - } - - using var message = CreateCreateSchemaRequest(groupName, schemaName, xSchemaType, body); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new ServiceCreateSchemaHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - SchemaId value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = SchemaId.DeserializeSchemaId(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 400: - return ResponseWithHeaders.FromValue(null, headers, message.Response); - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// - /// 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. - /// . - /// - /// schema group. - /// schema name. - /// The String to use. - /// schema content. - /// The cancellation token to use. - public ResponseWithHeaders CreateSchema(string groupName, string schemaName, string xSchemaType, string body, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - if (xSchemaType == null) - { - throw new ArgumentNullException(nameof(xSchemaType)); - } - if (body == null) - { - throw new ArgumentNullException(nameof(body)); - } - - using var message = CreateCreateSchemaRequest(groupName, schemaName, xSchemaType, body); - _pipeline.Send(message, cancellationToken); - var headers = new ServiceCreateSchemaHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - SchemaId value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = SchemaId.DeserializeSchemaId(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 400: - return ResponseWithHeaders.FromValue(null, headers, message.Response); - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateGetLatestSchemaRequest(string groupName, string schemaName) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - uri.AppendPath("/schemas/", false); - uri.AppendPath(schemaName, true); - request.Uri = uri; - return message; - } - - /// Get latest version of schema. - /// schema group. - /// schema name. - /// The cancellation token to use. - public async Task> GetLatestSchemaAsync(string groupName, string schemaName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateGetLatestSchemaRequest(groupName, schemaName); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new ServiceGetLatestSchemaHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - string value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = document.RootElement.GetString(); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Get latest version of schema. - /// schema group. - /// schema name. - /// The cancellation token to use. - public ResponseWithHeaders GetLatestSchema(string groupName, string schemaName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateGetLatestSchemaRequest(groupName, schemaName); - _pipeline.Send(message, cancellationToken); - var headers = new ServiceGetLatestSchemaHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - string value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = document.RootElement.GetString(); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateDeleteSchemaRequest(string groupName, string schemaName) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Delete; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - uri.AppendPath("/schemas/", false); - uri.AppendPath(schemaName, true); - request.Uri = uri; - return message; - } - - /// Delete schema. - /// schema group. - /// schema name. - /// The cancellation token to use. - public async Task DeleteSchemaAsync(string groupName, string schemaName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateDeleteSchemaRequest(groupName, schemaName); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 204: - case 404: - return message.Response; - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Delete schema. - /// schema group. - /// schema name. - /// The cancellation token to use. - public Response DeleteSchema(string groupName, string schemaName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateDeleteSchemaRequest(groupName, schemaName); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 204: - case 404: - return message.Response; - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateGetSchemaVersionsRequest(string groupName, string schemaName) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - uri.AppendPath("/schemas/", false); - uri.AppendPath(schemaName, true); - uri.AppendPath("/versions", false); - request.Uri = uri; - return message; - } - - /// Get list of versions for specified schema. - /// schema group. - /// schema name. - /// The cancellation token to use. - public async Task, ServiceGetSchemaVersionsHeaders>> GetSchemaVersionsAsync(string groupName, string schemaName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateGetSchemaVersionsRequest(groupName, schemaName); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new ServiceGetSchemaVersionsHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - IReadOnlyList value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - List array = new List(); - foreach (var item in document.RootElement.EnumerateArray()) - { - array.Add(item.GetInt32()); - } - value = array; - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Get list of versions for specified schema. - /// schema group. - /// schema name. - /// The cancellation token to use. - public ResponseWithHeaders, ServiceGetSchemaVersionsHeaders> GetSchemaVersions(string groupName, string schemaName, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateGetSchemaVersionsRequest(groupName, schemaName); - _pipeline.Send(message, cancellationToken); - var headers = new ServiceGetSchemaVersionsHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - IReadOnlyList value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - List array = new List(); - foreach (var item in document.RootElement.EnumerateArray()) - { - array.Add(item.GetInt32()); - } - value = array; - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateGetSchemaVersionRequest(string groupName, string schemaName, int versionNumber) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - uri.AppendPath("/schemas/", false); - uri.AppendPath(schemaName, true); - uri.AppendPath("/versions/", false); - uri.AppendPath(versionNumber, true); - request.Uri = uri; - return message; - } - - /// Get specified version of schema. - /// schema group. - /// schema name. - /// version number. - /// The cancellation token to use. - public async Task> GetSchemaVersionAsync(string groupName, string schemaName, int versionNumber, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateGetSchemaVersionRequest(groupName, schemaName, versionNumber); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new ServiceGetSchemaVersionHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - string value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = document.RootElement.GetString(); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 404: - return ResponseWithHeaders.FromValue(null, headers, message.Response); - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Get specified version of schema. - /// schema group. - /// schema name. - /// version number. - /// The cancellation token to use. - public ResponseWithHeaders GetSchemaVersion(string groupName, string schemaName, int versionNumber, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateGetSchemaVersionRequest(groupName, schemaName, versionNumber); - _pipeline.Send(message, cancellationToken); - var headers = new ServiceGetSchemaVersionHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - string value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = document.RootElement.GetString(); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 404: - return ResponseWithHeaders.FromValue(null, headers, message.Response); - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - - internal HttpMessage CreateDeleteSchemaVersionRequest(string groupName, string schemaName, int versionNumber) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Delete; - var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); - uri.AppendPath(groupName, true); - uri.AppendPath("/schemas/", false); - uri.AppendPath(schemaName, true); - uri.AppendPath("/versions/", false); - uri.AppendPath(versionNumber, true); - request.Uri = uri; - return message; - } - - /// Delete specified version of schema. - /// schema group. - /// schema name. - /// version number. - /// The cancellation token to use. - public async Task DeleteSchemaVersionAsync(string groupName, string schemaName, int versionNumber, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateDeleteSchemaVersionRequest(groupName, schemaName, versionNumber); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 204: - return message.Response; - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Delete specified version of schema. - /// schema group. - /// schema name. - /// version number. - /// The cancellation token to use. - public Response DeleteSchemaVersion(string groupName, string schemaName, int versionNumber, CancellationToken cancellationToken = default) - { - if (groupName == null) - { - throw new ArgumentNullException(nameof(groupName)); - } - if (schemaName == null) - { - throw new ArgumentNullException(nameof(schemaName)); - } - - using var message = CreateDeleteSchemaVersionRequest(groupName, schemaName, versionNumber); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 204: - return message.Response; - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index 28f8ca5bd7b61..d0bada073b9be 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -14,7 +14,7 @@ public class SchemaRegistryClient { private readonly ClientDiagnostics _clientDiagnostics; private readonly HttpPipeline _pipeline; - internal ServiceRestClient RestClient { get; } + internal SchemaRestClient RestClient { get; } /// /// Initializes a new instance of the . @@ -45,7 +45,7 @@ protected SchemaRegistryClient() ///// Api Version. internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string vaultBaseUrl)//, string apiVersion = "7.0") { - RestClient = new ServiceRestClient(clientDiagnostics, pipeline, new Uri(vaultBaseUrl)); + RestClient = new SchemaRestClient(clientDiagnostics, pipeline, new Uri(vaultBaseUrl)); _clientDiagnostics = clientDiagnostics; _pipeline = pipeline; } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md index f8f912fa13787..ade18ffe58bfa 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md @@ -3,5 +3,5 @@ Run `dotnet msbuild /t:GenerateCode` to generate code. ``` yaml -input-file: https://github.com/MiYanni/azure-sdk-for-java/blob/08e2a148900e23dd015a973721d2b2acb395601f/sdk/schemaregistry/azure-data-schemaregistry/swagger/swagger.json +require: https://github.com/MiYanni/azure-rest-api-specs/blob/55814eadcf5428280923bf5c80bb63d4fcf8910a/specification/schemaregistry/data-plane/readme.md ``` From 4c7a288795d0a158a42552eca3c61c242ed90882 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 5 Aug 2020 14:38:01 -0700 Subject: [PATCH 03/45] Fixed changlog. Regen surface. --- .../Azure.Data.SchemaRegistry/CHANGELOG.md | 44 +------------------ ...zure.Data.SchemaRegistry.netstandard2.0.cs | 25 +++++++++++ .../api/Azure.Template.netstandard2.0.cs | 32 -------------- 3 files changed, 26 insertions(+), 75 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Template.netstandard2.0.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md index c0ee0e516f7a9..36ac757b66df9 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md @@ -1,46 +1,4 @@ # Release History -## 1.0.2-preview.15 (2020-06-29) -- Test release pipeline - -## 1.0.2-preview.14 (2020-06-02) -- Test release pipeline - -## 1.0.2-preview.13 (2020-03-23) -- Test release pipeline - -## 1.0.2-preview.12 (2020-03-23) -- Test release pipeline - -## 1.0.2-preview.11 (2020-03-23) -- Test release pipeline - -## 1.0.2-preview.10 (2020-03-23) -- Test release pipeline - -## 1.0.2-preview.9 (2020-03-17) -- Test release pipeline - -## 1.0.2-preview.8 (2020-03-10) -- Testing out release pipeline - -## 1.0.2-preview.7 (2020-03-06) -- Testing out release pipeline - -## 1.0.2-preview.6 (2020-02-24) -### Added -- Testing Changelog added section -- Testing Links [Project Site](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/template/Azure.Template/README.md) -- Test `Highlighted Code` - -## 1.0.2-preview.5 (2020-02-24) -### Added -- Testing Changelog added section -- Testing Links [Project Site](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/template/Azure.Template/README.md) -- Test `Highlighted Code` - -## 1.0.2-preview.4 (2019-12-17) -- Version Bump - -## 1.0.2-preview.3 (2019-12-17) +## 1.0.0-preview.1 (2020-08-05) - Started changelog to capture release notes. \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs new file mode 100644 index 0000000000000..93782e5bac425 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs @@ -0,0 +1,25 @@ +namespace Azure.Data.SchemaRegistry +{ + public partial class SchemaRegistryClient + { + protected SchemaRegistryClient() { } + public SchemaRegistryClient(System.Uri endpoint, Azure.Core.TokenCredential credential) { } + public SchemaRegistryClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.Data.SchemaRegistry.SchemaRegistryClientOptions options) { } + } + public partial class SchemaRegistryClientOptions : Azure.Core.ClientOptions + { + public SchemaRegistryClientOptions(Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion version = Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion.V1_0) { } + public enum ServiceVersion + { + V1_0 = 1, + } + } +} +namespace Azure.Data.SchemaRegistry.Models +{ + public partial class SchemaId + { + internal SchemaId() { } + public string Id { get { throw null; } } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Template.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Template.netstandard2.0.cs deleted file mode 100644 index 4f6ce7887d818..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Template.netstandard2.0.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Azure.Template -{ - public partial class MiniSecretClient - { - protected MiniSecretClient() { } - public MiniSecretClient(System.Uri endpoint, Azure.Core.TokenCredential credential) { } - public MiniSecretClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.Template.MiniSecretClientOptions options) { } - public virtual Azure.Response GetSecret(string secretName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> GetSecretAsync(string secretName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - } - public partial class MiniSecretClientOptions : Azure.Core.ClientOptions - { - public MiniSecretClientOptions(Azure.Template.MiniSecretClientOptions.ServiceVersion version = Azure.Template.MiniSecretClientOptions.ServiceVersion.V7_0) { } - public enum ServiceVersion - { - V7_0 = 1, - } - } -} -namespace Azure.Template.Models -{ - public partial class SecretBundle - { - internal SecretBundle() { } - public string ContentType { get { throw null; } } - public string Id { get { throw null; } } - public string Kid { get { throw null; } } - public bool? Managed { get { throw null; } } - public System.Collections.Generic.IReadOnlyDictionary Tags { get { throw null; } } - public string Value { get { throw null; } } - } -} From 202090a7ac4bc9471f1b7e12496d4726a91f16c2 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 5 Aug 2020 14:54:32 -0700 Subject: [PATCH 04/45] Regen with correct swagger. --- .../src/Generated/Models/SchemaId.cs | 6 ++-- .../src/Generated/SchemaRestClient.cs | 30 ++++++++++++------- .../src/SchemaRegistryClient.cs | 2 +- .../Azure.Data.SchemaRegistry/src/autorest.md | 2 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs index c50ab3c41dd11..9d9fc65ca2d26 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs @@ -7,7 +7,7 @@ namespace Azure.Data.SchemaRegistry.Models { - /// The id of a Schema Registry schema. + /// JSON Object received from the registry containing schema identifiers. public partial class SchemaId { /// Initializes a new instance of SchemaId. @@ -16,13 +16,13 @@ internal SchemaId() } /// Initializes a new instance of SchemaId. - /// The id of the schema. + /// Schema ID that uniquely identifies a schema in the registry namespace. internal SchemaId(string id) { Id = id; } - /// The id of the schema. + /// Schema ID that uniquely identifies a schema in the registry namespace. public string Id { get; } } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs index 38f502e1fc13f..9164b6c8fe814 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs @@ -17,17 +17,21 @@ namespace Azure.Data.SchemaRegistry { internal partial class SchemaRestClient { - private Uri endpoint; + private string endpoint; private ClientDiagnostics _clientDiagnostics; private HttpPipeline _pipeline; /// Initializes a new instance of SchemaRestClient. /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. - /// server parameter. - public SchemaRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null) + /// The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net. + /// is null. + public SchemaRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) { - endpoint ??= new Uri(""); + if (endpoint == null) + { + throw new ArgumentNullException(nameof(endpoint)); + } this.endpoint = endpoint; _clientDiagnostics = clientDiagnostics; @@ -40,8 +44,10 @@ internal HttpMessage CreateGetByIdRequest(string schemaId) var request = message.Request; request.Method = RequestMethod.Get; var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/getSchemaById/", false); + uri.AppendRaw("https://", false); + uri.AppendRaw(endpoint, false); + uri.AppendRaw("/$schemagroups", false); + uri.AppendPath("/getSchemaById/", false); uri.AppendPath(schemaId, true); request.Uri = uri; return message; @@ -109,8 +115,10 @@ internal HttpMessage CreateGetIdByContentRequest(string groupName, string schema var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); + uri.AppendRaw("https://", false); + uri.AppendRaw(endpoint, false); + uri.AppendRaw("/$schemagroups", false); + uri.AppendPath("/", false); uri.AppendPath(groupName, true); uri.AppendPath("/schemas/", false); uri.AppendPath(schemaName, true); @@ -215,8 +223,10 @@ internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, var request = message.Request; request.Method = RequestMethod.Put; var uri = new RawRequestUriBuilder(); - uri.Reset(endpoint); - uri.AppendPath("/$schemagroups/", false); + uri.AppendRaw("https://", false); + uri.AppendRaw(endpoint, false); + uri.AppendRaw("/$schemagroups", false); + uri.AppendPath("/", false); uri.AppendPath(groupName, true); uri.AppendPath("/schemas/", false); uri.AppendPath(schemaName, true); diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index d0bada073b9be..8c02b4788f050 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -45,7 +45,7 @@ protected SchemaRegistryClient() ///// Api Version. internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string vaultBaseUrl)//, string apiVersion = "7.0") { - RestClient = new SchemaRestClient(clientDiagnostics, pipeline, new Uri(vaultBaseUrl)); + RestClient = new SchemaRestClient(clientDiagnostics, pipeline, vaultBaseUrl); _clientDiagnostics = clientDiagnostics; _pipeline = pipeline; } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md index ade18ffe58bfa..f07087ff4a635 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md @@ -3,5 +3,5 @@ Run `dotnet msbuild /t:GenerateCode` to generate code. ``` yaml -require: https://github.com/MiYanni/azure-rest-api-specs/blob/55814eadcf5428280923bf5c80bb63d4fcf8910a/specification/schemaregistry/data-plane/readme.md +require: https://github.com/Azure/azure-rest-api-specs/blob/dc7937d9de990e0e56f9e2d7cdd226f6e210631c/specification/schemaregistry/data-plane/readme.md ``` From 96e42d31c5d15931c8a3819bb06917217abb8570 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Thu, 6 Aug 2020 15:49:24 -0700 Subject: [PATCH 05/45] Started adding client methods. --- .../src/SchemaProperties.cs | 45 ++++++ .../src/SchemaRegistryClient.cs | 136 +++++++++++++++++- 2 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs new file mode 100644 index 0000000000000..ddf62e3bbd3ed --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Data.SchemaRegistry +{ + /// + /// Properties for a SchemaRegistry schema. + /// + public class SchemaProperties + { + internal SchemaProperties(string location, string xSerialization, string xSchemaId, int? xSchemaVersion) + { + Id = xSchemaId; + Name = location; //TODO: Parse name from location + GroupName = null; //TODO: Parse group name from location + Type = xSerialization; + Version = xSchemaVersion; + } + + /// + /// The schema ID that uniquely identifies a schema in the registry namespace. + /// + public string Id { get; } + + /// + /// The name of the schema. + /// + public string Name { get; } + + /// + /// The group name of the schema. + /// + public string GroupName { get; } + + /// + /// Serialization type for the schema being stored. + /// + public string Type { get; } + + /// + /// Version of the schema. + /// + public int? Version { get; } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index 8c02b4788f050..ac0d5b56a80f6 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -2,6 +2,8 @@ // Licensed under the MIT License. using System; +using System.Threading; +using System.Threading.Tasks; using Azure.Core; using Azure.Core.Pipeline; @@ -38,14 +40,14 @@ public SchemaRegistryClient(Uri endpoint, TokenCredential credential, SchemaRegi protected SchemaRegistryClient() { } + /// Initializes a new instance of SchemaRegistryClient. /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. - /// The vault name, for example https://myvault.vault.azure.net. - ///// Api Version. - internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string vaultBaseUrl)//, string apiVersion = "7.0") + /// The vault name, for example https://myvault.vault.azure.net. + internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) { - RestClient = new SchemaRestClient(clientDiagnostics, pipeline, vaultBaseUrl); + RestClient = new SchemaRestClient(clientDiagnostics, pipeline, endpoint); _clientDiagnostics = clientDiagnostics; _pipeline = pipeline; } @@ -85,5 +87,131 @@ internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline // throw; // } // } + + /// + /// TODO. (Create OR Get). (Register/Create). + /// + public virtual async Task> RegisterSchemaAsync(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); + scope.Start(); + try + { + var response = await RestClient.RegisterAsync(groupName, schemaName, serializationType, schemaContent, cancellationToken).ConfigureAwait(false); + return Response.FromValue( + new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + response); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// TODO. (Create OR Get). (Register/Create). + /// + public virtual Response RegisterSchema(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); + scope.Start(); + try + { + var response = RestClient.Register(groupName, schemaName, serializationType, schemaContent, cancellationToken); + return Response.FromValue( + new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + response); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// TODO. (Opposite of TryGet) (Find/Query/Get). + /// + public virtual async Task> GetSchemaAsync(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); + scope.Start(); + try + { + var response = await RestClient.GetIdByContentAsync(groupName, schemaName, serializationType, schemaContent, cancellationToken).ConfigureAwait(false); + return Response.FromValue( + new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + response); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// TODO. (Opposite of TryGet) (Find/Query/Get). + /// + public virtual Response GetSchema(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); + scope.Start(); + try + { + var response = RestClient.GetIdByContent(groupName, schemaName, serializationType, schemaContent, cancellationToken); + return Response.FromValue( + new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + response); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// TODO. (Opposite of TryGet) (Find/Query/Get). + /// + public virtual async Task> GetSchemaAsync(string schemaId, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); + scope.Start(); + try + { + var response = await RestClient.GetByIdAsync(schemaId, cancellationToken).ConfigureAwait(false); + return Response.FromValue( + new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + response); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// TODO. (Opposite of TryGet) (Find/Query/Get). + /// + public virtual Response GetSchema(string schemaId, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); + scope.Start(); + try + { + var response = RestClient.GetById(schemaId, cancellationToken); + return Response.FromValue( + new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + response); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } } } From 66a4426522f78860c99e1cbcb5dededdba0847c6 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 7 Aug 2020 10:33:40 -0700 Subject: [PATCH 06/45] Update SchemaId to be struct. Regen api. --- ...zure.Data.SchemaRegistry.netstandard2.0.cs | 23 +++++++----- .../Models/SchemaId.Serialization.cs | 2 +- .../src/Generated/Models/SchemaId.cs | 15 ++++---- .../Azure.Data.SchemaRegistry/src/SchemaId.cs | 15 ++++++++ .../src/SchemaRegistryClient.cs | 36 ------------------- 5 files changed, 40 insertions(+), 51 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaId.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs index 93782e5bac425..67637eac31160 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs @@ -1,10 +1,25 @@ namespace Azure.Data.SchemaRegistry { + public partial class SchemaProperties + { + internal SchemaProperties() { } + public string GroupName { get { throw null; } } + public string Id { get { throw null; } } + public string Name { get { throw null; } } + public string Type { get { throw null; } } + public int? Version { get { throw null; } } + } public partial class SchemaRegistryClient { protected SchemaRegistryClient() { } public SchemaRegistryClient(System.Uri endpoint, Azure.Core.TokenCredential credential) { } public SchemaRegistryClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.Data.SchemaRegistry.SchemaRegistryClientOptions options) { } + public virtual Azure.Response GetSchema(string groupName, string schemaName, string serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetSchema(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetSchemaAsync(string groupName, string schemaName, string serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetSchemaAsync(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RegisterSchema(string groupName, string schemaName, string serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, string serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public partial class SchemaRegistryClientOptions : Azure.Core.ClientOptions { @@ -15,11 +30,3 @@ public enum ServiceVersion } } } -namespace Azure.Data.SchemaRegistry.Models -{ - public partial class SchemaId - { - internal SchemaId() { } - public string Id { get { throw null; } } - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.Serialization.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.Serialization.cs index cccb726f4f915..0e24121aba695 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.Serialization.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.Data.SchemaRegistry.Models { - public partial class SchemaId + internal partial struct SchemaId { internal static SchemaId DeserializeSchemaId(JsonElement element) { diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs index 9d9fc65ca2d26..b1ab4b861c031 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SchemaId.cs @@ -5,20 +5,23 @@ #nullable disable +using System; + namespace Azure.Data.SchemaRegistry.Models { /// JSON Object received from the registry containing schema identifiers. - public partial class SchemaId + internal readonly partial struct SchemaId { - /// Initializes a new instance of SchemaId. - internal SchemaId() - { - } - /// Initializes a new instance of SchemaId. /// Schema ID that uniquely identifies a schema in the registry namespace. + /// is null. internal SchemaId(string id) { + if (id == null) + { + throw new ArgumentNullException(nameof(id)); + } + Id = id; } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaId.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaId.cs new file mode 100644 index 0000000000000..049bbee7f9f17 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaId.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Data.SchemaRegistry.Models +{ + /// + /// JSON Object received from the registry containing schema identifiers. + /// + [CodeGenModel("SchemaId")] + internal readonly partial struct SchemaId + { + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index ac0d5b56a80f6..cb22fcacb583b 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -52,42 +52,6 @@ internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline _pipeline = pipeline; } - // /// The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission. - // /// The name of the secret. - // /// The cancellation token to use. - // public virtual async Task> GetSecretAsync(string secretName, CancellationToken cancellationToken = default) - // { - // using var scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSecret"); - // scope.Start(); - // try - // { - // return await RestClient.GetSecretAsync(secretName, cancellationToken).ConfigureAwait(false); - // } - // catch (Exception e) - // { - // scope.Failed(e); - // throw; - // } - // } - - // /// The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission. - // /// The name of the secret. - // /// The cancellation token to use. - // public virtual Response GetSecret(string secretName, CancellationToken cancellationToken = default) - // { - // using var scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSecret"); - // scope.Start(); - // try - // { - // return RestClient.GetSecret(secretName, cancellationToken); - // } - // catch (Exception e) - // { - // scope.Failed(e); - // throw; - // } - // } - /// /// TODO. (Create OR Get). (Register/Create). /// From 86932ac7f9855e9699c89457f19dd7444b9eb26a Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 12 Aug 2020 15:11:24 -0700 Subject: [PATCH 07/45] Initial attempt of serializer. --- .../src/AvroObjectSerializer.cs | 163 ++++++++++++++++++ .../src/Azure.Data.SchemaRegistry.csproj | 1 + 2 files changed, 164 insertions(+) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/AvroObjectSerializer.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/AvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/AvroObjectSerializer.cs new file mode 100644 index 0000000000000..4ae91f1666925 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/AvroObjectSerializer.cs @@ -0,0 +1,163 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Avro; +using Avro.File; +using Avro.Generic; +using Azure.Core.Serialization; + +namespace Azure.Data.SchemaRegistry +{ + /// + /// A implementation that uses to for serialization/deserialization. + /// + public class AvroObjectSerializer : ObjectSerializer//, IMemberNameConverter + { + //private readonly ConcurrentDictionary _cache; + //private readonly JsonSerializerOptions _options; + + private readonly RecordSchema _schema; + + /// + /// Initializes new instance of . + /// + public AvroObjectSerializer(string schema) //: this(new JsonSerializerOptions()) + { + _schema = (RecordSchema)Schema.Parse(schema); + } + + ///// + ///// Initializes new instance of . + ///// + ///// The instance to use when serializing/deserializing. + ///// is null. + //public AvroObjectSerializer(JsonSerializerOptions options) + //{ + // //_options = options ?? throw new ArgumentNullException(nameof(options)); + + // //// TODO: Consider using WeakReference cache to allow the GC to collect if the JsonObjectSerialized is held for a long duration. + // //_cache = new ConcurrentDictionary(); + //} + + /// + public override void Serialize(Stream stream, object value, Type inputType, CancellationToken cancellationToken) + { + if (!(value is IEnumerable records)) + { + throw new ArgumentException("Wrong value type."); + } + var datumWriter = new GenericDatumWriter(_schema); + using var writer = DataFileWriter.OpenWriter(datumWriter, stream); + foreach (var record in records) + { + writer.Append(record); + } + + //var buffer = JsonSerializer.SerializeToUtf8Bytes(value, inputType, _options); + //stream.Write(buffer, 0, buffer.Length); + } + + /// + public override async ValueTask SerializeAsync(Stream stream, object value, Type inputType, CancellationToken cancellationToken) + { + await Task.Run(() => Serialize(stream, value, inputType, cancellationToken), cancellationToken).ConfigureAwait(false); + //await JsonSerializer.SerializeAsync(stream, value, inputType, _options, cancellationToken).ConfigureAwait(false); + } + + /// + public override object Deserialize(Stream stream, Type returnType, CancellationToken cancellationToken) + { + //using var memoryStream = new MemoryStream(); + //stream.CopyTo(memoryStream); + //return JsonSerializer.Deserialize(memoryStream.ToArray(), returnType, _options); + var records = new List(); + using var reader = DataFileReader.OpenReader(stream); + while (reader.HasNext()) + { + records.Add(reader.Next()); + } + + return records; + } + + /// + public override async ValueTask DeserializeAsync(Stream stream, Type returnType, CancellationToken cancellationToken) + { + return await Task.Run(() => Deserialize(stream, returnType, cancellationToken), cancellationToken).ConfigureAwait(false); + //return await JsonSerializer.DeserializeAsync(stream, returnType, _options, cancellationToken).ConfigureAwait(false); + } + + ///// + //string? IMemberNameConverter.ConvertMemberName(MemberInfo member) + //{ + // Argument.AssertNotNull(member, nameof(member)); + + // return _cache.GetOrAdd(member, m => + // { + // // Mimics property enumeration based on: + // // * https://github.com/dotnet/corefx/blob/v3.1.0/src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs#L130-L191 + // // * TODO: Add support for fields when .NET 5 GAs (https://github.com/Azure/azure-sdk-for-net/issues/13627) + + // if (m is PropertyInfo propertyInfo) + // { + // // Ignore indexers. + // if (propertyInfo.GetIndexParameters().Length > 0) + // { + // return null; + // } + + // // Only support public getters and/or setters. + // if (propertyInfo.GetMethod?.IsPublic == true || + // propertyInfo.SetMethod?.IsPublic == true) + // { + // if (propertyInfo.GetCustomAttribute() != null) + // { + // return null; + // } + + // // Ignore - but do not assert correctness - for JsonExtensionDataAttribute based on + // // https://github.com/dotnet/corefx/blob/v3.1.0/src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs#L244-L261 + // if (propertyInfo.GetCustomAttribute() != null) + // { + // return null; + // } + + // // No need to validate collisions since they are based on the serialized name. + // return GetPropertyName(propertyInfo); + // } + // } + + // // The member is unsupported or ignored. + // return null; + // }); + //} + + //private string GetPropertyName(MemberInfo memberInfo) + //{ + // // Mimics property name determination based on + // // https://github.com/dotnet/runtime/blob/dc8b6f90/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfo.cs#L53-L90 + + // JsonPropertyNameAttribute nameAttribute = memberInfo.GetCustomAttribute(false); + // if (nameAttribute != null) + // { + // return nameAttribute.Name + // ?? throw new InvalidOperationException($"The JSON property name for '{memberInfo.DeclaringType}.{memberInfo.Name}' cannot be null."); + // } + // else if (_options.PropertyNamingPolicy != null) + // { + // return _options.PropertyNamingPolicy.ConvertName(memberInfo.Name) + // ?? throw new InvalidOperationException($"The JSON property name for '{memberInfo.DeclaringType}.{memberInfo.Name}' cannot be null."); + // } + // else + // { + // return memberInfo.Name; + // } + //} + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj index 3addbb4dce273..9b6bd4f268ebd 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj @@ -8,6 +8,7 @@ + From 7ff033c468d921492b27feea607cda7a1d31f9ba Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 12 Aug 2020 17:33:13 -0700 Subject: [PATCH 08/45] Update swagger version. Regenerate rest client. Update public surface. Created first working test. --- ...zure.Data.SchemaRegistry.netstandard2.0.cs | 42 +++++++-- .../src/Generated/Models/SerializationType.cs | 48 ++++++++++ .../src/Generated/SchemaGetByIdHeaders.cs | 2 +- ...rs.cs => SchemaQueryIdByContentHeaders.cs} | 6 +- .../src/Generated/SchemaRegisterHeaders.cs | 2 +- .../src/Generated/SchemaRestClient.cs | 89 +++++++++---------- .../src/SchemaProperties.cs | 18 ++-- .../src/SchemaRegistryClient.cs | 42 ++++----- .../Azure.Data.SchemaRegistry/src/autorest.md | 2 +- .../Azure.Data.SchemaRegistry.Tests.csproj | 3 + .../SchemaRegistryClientSamples.HelloWorld.cs | 5 +- .../tests/SchemaRegistryClientLiveTest.cs | 32 ++++++- .../SchemaRegistryClientTestEnvironment.cs | 2 +- 13 files changed, 204 insertions(+), 89 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SerializationType.cs rename sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/{SchemaGetIdByContentHeaders.cs => SchemaQueryIdByContentHeaders.cs} (84%) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs index 67637eac31160..2684fdbd27ec1 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs @@ -1,25 +1,33 @@ namespace Azure.Data.SchemaRegistry { + public partial class AvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer + { + public AvroObjectSerializer(string schema) { } + public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } + public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } + } public partial class SchemaProperties { internal SchemaProperties() { } public string GroupName { get { throw null; } } public string Id { get { throw null; } } public string Name { get { throw null; } } - public string Type { get { throw null; } } + public Azure.Data.SchemaRegistry.Models.SerializationType Type { get { throw null; } } public int? Version { get { throw null; } } } public partial class SchemaRegistryClient { protected SchemaRegistryClient() { } - public SchemaRegistryClient(System.Uri endpoint, Azure.Core.TokenCredential credential) { } - public SchemaRegistryClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.Data.SchemaRegistry.SchemaRegistryClientOptions options) { } - public virtual Azure.Response GetSchema(string groupName, string schemaName, string serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential) { } + public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential, Azure.Data.SchemaRegistry.SchemaRegistryClientOptions options) { } + public virtual Azure.Response GetSchema(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetSchema(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> GetSchemaAsync(string groupName, string schemaName, string serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetSchemaAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSchemaAsync(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RegisterSchema(string groupName, string schemaName, string serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, string serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RegisterSchema(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public partial class SchemaRegistryClientOptions : Azure.Core.ClientOptions { @@ -30,3 +38,23 @@ public enum ServiceVersion } } } +namespace Azure.Data.SchemaRegistry.Models +{ + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct SerializationType : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public SerializationType(string value) { throw null; } + public static Azure.Data.SchemaRegistry.Models.SerializationType Avro { get { throw null; } } + public bool Equals(Azure.Data.SchemaRegistry.Models.SerializationType other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.Data.SchemaRegistry.Models.SerializationType left, Azure.Data.SchemaRegistry.Models.SerializationType right) { throw null; } + public static implicit operator Azure.Data.SchemaRegistry.Models.SerializationType (string value) { throw null; } + public static bool operator !=(Azure.Data.SchemaRegistry.Models.SerializationType left, Azure.Data.SchemaRegistry.Models.SerializationType right) { throw null; } + public override string ToString() { throw null; } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SerializationType.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SerializationType.cs new file mode 100644 index 0000000000000..8b3ccc12d7951 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SerializationType.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Data.SchemaRegistry.Models +{ + /// The SerializationType. + public readonly partial struct SerializationType : IEquatable + { + private readonly string _value; + + /// Determines if two values are the same. + /// is null. + public SerializationType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AvroValue = "avro"; + + /// Avro Serialization schema type. + public static SerializationType Avro { get; } = new SerializationType(AvroValue); + /// Determines if two values are the same. + public static bool operator ==(SerializationType left, SerializationType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(SerializationType left, SerializationType right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator SerializationType(string value) => new SerializationType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is SerializationType other && Equals(other); + /// + public bool Equals(SerializationType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetByIdHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetByIdHeaders.cs index e7343abe81fb9..d24948fc47737 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetByIdHeaders.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetByIdHeaders.cs @@ -20,7 +20,7 @@ public SchemaGetByIdHeaders(Response response) /// URL location of schema, identified by schema group, schema name, and version. public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; /// Serialization type for the schema being stored. - public string XSerialization => _response.Headers.TryGetValue("X-Serialization", out string value) ? value : null; + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; /// References specific schema in registry namespace. public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; /// URL location of schema, identified by schema ID. diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetIdByContentHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaQueryIdByContentHeaders.cs similarity index 84% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetIdByContentHeaders.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaQueryIdByContentHeaders.cs index 8478af4459c47..bdbd563efc2e3 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaGetIdByContentHeaders.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaQueryIdByContentHeaders.cs @@ -10,17 +10,17 @@ namespace Azure.Data.SchemaRegistry { - internal class SchemaGetIdByContentHeaders + internal class SchemaQueryIdByContentHeaders { private readonly Response _response; - public SchemaGetIdByContentHeaders(Response response) + public SchemaQueryIdByContentHeaders(Response response) { _response = response; } /// URL location of schema, identified by schema group, schema name, and version. public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; /// Serialization type for the schema being stored. - public string XSerialization => _response.Headers.TryGetValue("X-Serialization", out string value) ? value : null; + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; /// References specific schema in registry namespace. public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; /// URL location of schema, identified by schema ID. diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRegisterHeaders.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRegisterHeaders.cs index c494aa7d84c93..09b9ca0a957dd 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRegisterHeaders.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRegisterHeaders.cs @@ -20,7 +20,7 @@ public SchemaRegisterHeaders(Response response) /// URL location of schema, identified by schema group, schema name, and version. public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; /// Serialization type for the schema being registered. - public string XSerialization => _response.Headers.TryGetValue("X-Serialization", out string value) ? value : null; + public string XSchemaType => _response.Headers.TryGetValue("X-Schema-Type", out string value) ? value : null; /// References specific schema in registry namespace. public string XSchemaId => _response.Headers.TryGetValue("X-Schema-Id", out string value) ? value : null; /// URL location of schema, identified by schema ID. diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs index 9164b6c8fe814..6164b202424e2 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs @@ -18,6 +18,7 @@ namespace Azure.Data.SchemaRegistry internal partial class SchemaRestClient { private string endpoint; + private string apiVersion; private ClientDiagnostics _clientDiagnostics; private HttpPipeline _pipeline; @@ -25,15 +26,21 @@ internal partial class SchemaRestClient /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. /// The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net. - /// is null. - public SchemaRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) + /// Api Version. + /// or is null. + public SchemaRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, string apiVersion = "2018-01-01-preview") { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } + if (apiVersion == null) + { + throw new ArgumentNullException(nameof(apiVersion)); + } this.endpoint = endpoint; + this.apiVersion = apiVersion; _clientDiagnostics = clientDiagnostics; _pipeline = pipeline; } @@ -46,9 +53,9 @@ internal HttpMessage CreateGetByIdRequest(string schemaId) var uri = new RawRequestUriBuilder(); uri.AppendRaw("https://", false); uri.AppendRaw(endpoint, false); - uri.AppendRaw("/$schemagroups", false); - uri.AppendPath("/getSchemaById/", false); + uri.AppendPath("/$schemagroups/getSchemaById/", false); uri.AppendPath(schemaId, true); + uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; return message; } @@ -109,7 +116,7 @@ public ResponseWithHeaders GetById(string schemaId } } - internal HttpMessage CreateGetIdByContentRequest(string groupName, string schemaName, string serializationType, string schemaContent) + internal HttpMessage CreateQueryIdByContentRequest(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -117,13 +124,16 @@ internal HttpMessage CreateGetIdByContentRequest(string groupName, string schema var uri = new RawRequestUriBuilder(); uri.AppendRaw("https://", false); uri.AppendRaw(endpoint, false); - uri.AppendRaw("/$schemagroups", false); - uri.AppendPath("/", false); + uri.AppendPath("/$schemagroups/", false); uri.AppendPath(groupName, true); uri.AppendPath("/schemas/", false); uri.AppendPath(schemaName, true); + uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; - request.Headers.Add("serialization-type", serializationType); + if (xSchemaType != null) + { + request.Headers.Add("X-Schema-Type", xSchemaType.Value.ToString()); + } request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteStringValue(schemaContent); @@ -134,11 +144,11 @@ internal HttpMessage CreateGetIdByContentRequest(string groupName, string schema /// Gets the ID referencing an existing schema within the specified schema group, as matched by schema content comparison. /// Schema group under which schema is registered. Group's serialization type should match the serialization type specified in the request. /// Name of the registered schema. - /// Serialization type of the registered schema. Must match serialization type of the specified schema group. /// String representation of the registered schema. + /// Serialization type for the schema being registered. /// The cancellation token to use. - /// , , , or is null. - public async Task> GetIdByContentAsync(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + /// , , or is null. + public async Task> QueryIdByContentAsync(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType = null, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -148,18 +158,14 @@ public async Task> Ge { throw new ArgumentNullException(nameof(schemaName)); } - if (serializationType == null) - { - throw new ArgumentNullException(nameof(serializationType)); - } if (schemaContent == null) { throw new ArgumentNullException(nameof(schemaContent)); } - using var message = CreateGetIdByContentRequest(groupName, schemaName, serializationType, schemaContent); + using var message = CreateQueryIdByContentRequest(groupName, schemaName, schemaContent, xSchemaType); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new SchemaGetIdByContentHeaders(message.Response); + var headers = new SchemaQueryIdByContentHeaders(message.Response); switch (message.Response.Status) { case 200: @@ -177,11 +183,11 @@ public async Task> Ge /// Gets the ID referencing an existing schema within the specified schema group, as matched by schema content comparison. /// Schema group under which schema is registered. Group's serialization type should match the serialization type specified in the request. /// Name of the registered schema. - /// Serialization type of the registered schema. Must match serialization type of the specified schema group. /// String representation of the registered schema. + /// Serialization type for the schema being registered. /// The cancellation token to use. - /// , , , or is null. - public ResponseWithHeaders GetIdByContent(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + /// , , or is null. + public ResponseWithHeaders QueryIdByContent(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType = null, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -191,18 +197,14 @@ public ResponseWithHeaders GetIdByContent { throw new ArgumentNullException(nameof(schemaName)); } - if (serializationType == null) - { - throw new ArgumentNullException(nameof(serializationType)); - } if (schemaContent == null) { throw new ArgumentNullException(nameof(schemaContent)); } - using var message = CreateGetIdByContentRequest(groupName, schemaName, serializationType, schemaContent); + using var message = CreateQueryIdByContentRequest(groupName, schemaName, schemaContent, xSchemaType); _pipeline.Send(message, cancellationToken); - var headers = new SchemaGetIdByContentHeaders(message.Response); + var headers = new SchemaQueryIdByContentHeaders(message.Response); switch (message.Response.Status) { case 200: @@ -217,7 +219,7 @@ public ResponseWithHeaders GetIdByContent } } - internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, string serializationType, string schemaContent) + internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -225,13 +227,16 @@ internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, var uri = new RawRequestUriBuilder(); uri.AppendRaw("https://", false); uri.AppendRaw(endpoint, false); - uri.AppendRaw("/$schemagroups", false); - uri.AppendPath("/", false); + uri.AppendPath("/$schemagroups/", false); uri.AppendPath(groupName, true); uri.AppendPath("/schemas/", false); uri.AppendPath(schemaName, true); + uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; - request.Headers.Add("serialization-type", serializationType); + if (xSchemaType != null) + { + request.Headers.Add("X-Schema-Type", xSchemaType.Value.ToString()); + } request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteStringValue(schemaContent); @@ -245,11 +250,11 @@ internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, /// /// Schema group under which schema should be registered. Group's serialization type should match the serialization type specified in the request. /// Name of schema being registered. - /// Serialization type for the schema being registered. Must match serialization type of the specified schema group. /// String representation of the schema being registered. + /// Serialization type for the schema being registered. /// The cancellation token to use. - /// , , , or is null. - public async Task> RegisterAsync(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + /// , , or is null. + public async Task> RegisterAsync(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType = null, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -259,16 +264,12 @@ public async Task> Register { throw new ArgumentNullException(nameof(schemaName)); } - if (serializationType == null) - { - throw new ArgumentNullException(nameof(serializationType)); - } if (schemaContent == null) { throw new ArgumentNullException(nameof(schemaContent)); } - using var message = CreateRegisterRequest(groupName, schemaName, serializationType, schemaContent); + using var message = CreateRegisterRequest(groupName, schemaName, schemaContent, xSchemaType); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); var headers = new SchemaRegisterHeaders(message.Response); switch (message.Response.Status) @@ -291,11 +292,11 @@ public async Task> Register /// /// Schema group under which schema should be registered. Group's serialization type should match the serialization type specified in the request. /// Name of schema being registered. - /// Serialization type for the schema being registered. Must match serialization type of the specified schema group. /// String representation of the schema being registered. + /// Serialization type for the schema being registered. /// The cancellation token to use. - /// , , , or is null. - public ResponseWithHeaders Register(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + /// , , or is null. + public ResponseWithHeaders Register(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType = null, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -305,16 +306,12 @@ public ResponseWithHeaders Register(string grou { throw new ArgumentNullException(nameof(schemaName)); } - if (serializationType == null) - { - throw new ArgumentNullException(nameof(serializationType)); - } if (schemaContent == null) { throw new ArgumentNullException(nameof(schemaContent)); } - using var message = CreateRegisterRequest(groupName, schemaName, serializationType, schemaContent); + using var message = CreateRegisterRequest(groupName, schemaName, schemaContent, xSchemaType); _pipeline.Send(message, cancellationToken); var headers = new SchemaRegisterHeaders(message.Response); switch (message.Response.Status) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs index ddf62e3bbd3ed..954c6c1871a83 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; +using Azure.Data.SchemaRegistry.Models; + namespace Azure.Data.SchemaRegistry { /// @@ -8,12 +11,17 @@ namespace Azure.Data.SchemaRegistry /// public class SchemaProperties { - internal SchemaProperties(string location, string xSerialization, string xSchemaId, int? xSchemaVersion) + private const char Slash = '/'; + private static readonly string[] s_groupSplitter = { "/$schemagroups/" }; + + internal SchemaProperties(string location, SerializationType xSchemaType, string xSchemaId, int? xSchemaVersion) { Id = xSchemaId; - Name = location; //TODO: Parse name from location - GroupName = null; //TODO: Parse group name from location - Type = xSerialization; + var groupSplit = location.Split(s_groupSplitter, StringSplitOptions.None)[1]; + var slashSplit = groupSplit.Split(Slash); + Name = slashSplit[2]; + GroupName = slashSplit[0]; + Type = xSchemaType; Version = xSchemaVersion; } @@ -35,7 +43,7 @@ internal SchemaProperties(string location, string xSerialization, string xSchema /// /// Serialization type for the schema being stored. /// - public string Type { get; } + public SerializationType Type { get; } /// /// Version of the schema. diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index cb22fcacb583b..1c6347b1b8250 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Azure.Core; using Azure.Core.Pipeline; +using Azure.Data.SchemaRegistry.Models; namespace Azure.Data.SchemaRegistry { @@ -21,18 +22,18 @@ public class SchemaRegistryClient /// /// Initializes a new instance of the . /// - public SchemaRegistryClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new SchemaRegistryClientOptions()) + public SchemaRegistryClient(string endpoint, TokenCredential credential) : this(endpoint, credential, new SchemaRegistryClientOptions()) { } /// /// Initializes a new instance of the . /// - public SchemaRegistryClient(Uri endpoint, TokenCredential credential, SchemaRegistryClientOptions options) : this( + public SchemaRegistryClient(string endpoint, TokenCredential credential, SchemaRegistryClientOptions options) : this( new ClientDiagnostics(options), - HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, "https://vault.azure.net/.default")), - endpoint.ToString())//, - //options.Version) + HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, "https://eventhubs.azure.net/.default")), + endpoint)//, + //options.Version) { } @@ -47,7 +48,8 @@ protected SchemaRegistryClient() /// The vault name, for example https://myvault.vault.azure.net. internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) { - RestClient = new SchemaRestClient(clientDiagnostics, pipeline, endpoint); + //TODO: Hardcoded API version. + RestClient = new SchemaRestClient(clientDiagnostics, pipeline, endpoint, "2017-04"); _clientDiagnostics = clientDiagnostics; _pipeline = pipeline; } @@ -55,15 +57,15 @@ internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline /// /// TODO. (Create OR Get). (Register/Create). /// - public virtual async Task> RegisterSchemaAsync(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + public virtual async Task> RegisterSchemaAsync(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); scope.Start(); try { - var response = await RestClient.RegisterAsync(groupName, schemaName, serializationType, schemaContent, cancellationToken).ConfigureAwait(false); + var response = await RestClient.RegisterAsync(groupName, schemaName, schemaContent, serializationType, cancellationToken).ConfigureAwait(false); return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), response); } catch (Exception e) @@ -76,15 +78,15 @@ public virtual async Task> RegisterSchemaAsync(string /// /// TODO. (Create OR Get). (Register/Create). /// - public virtual Response RegisterSchema(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + public virtual Response RegisterSchema(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); scope.Start(); try { - var response = RestClient.Register(groupName, schemaName, serializationType, schemaContent, cancellationToken); + var response = RestClient.Register(groupName, schemaName, schemaContent, serializationType, cancellationToken); return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), response); } catch (Exception e) @@ -97,15 +99,15 @@ public virtual Response RegisterSchema(string groupName, strin /// /// TODO. (Opposite of TryGet) (Find/Query/Get). /// - public virtual async Task> GetSchemaAsync(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + public virtual async Task> GetSchemaAsync(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); scope.Start(); try { - var response = await RestClient.GetIdByContentAsync(groupName, schemaName, serializationType, schemaContent, cancellationToken).ConfigureAwait(false); + var response = await RestClient.QueryIdByContentAsync(groupName, schemaName, schemaContent, serializationType, cancellationToken).ConfigureAwait(false); return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), response); } catch (Exception e) @@ -118,15 +120,15 @@ public virtual async Task> GetSchemaAsync(string grou /// /// TODO. (Opposite of TryGet) (Find/Query/Get). /// - public virtual Response GetSchema(string groupName, string schemaName, string serializationType, string schemaContent, CancellationToken cancellationToken = default) + public virtual Response GetSchema(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); scope.Start(); try { - var response = RestClient.GetIdByContent(groupName, schemaName, serializationType, schemaContent, cancellationToken); + var response = RestClient.QueryIdByContent(groupName, schemaName, schemaContent, serializationType, cancellationToken); return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), response); } catch (Exception e) @@ -147,7 +149,7 @@ public virtual async Task> GetSchemaAsync(string sche { var response = await RestClient.GetByIdAsync(schemaId, cancellationToken).ConfigureAwait(false); return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), response); } catch (Exception e) @@ -168,7 +170,7 @@ public virtual Response GetSchema(string schemaId, Cancellatio { var response = RestClient.GetById(schemaId, cancellationToken); return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSerialization, response.Headers.XSchemaId, response.Headers.XSchemaVersion), + new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), response); } catch (Exception e) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md index f07087ff4a635..7f1f55cd04ad4 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md @@ -3,5 +3,5 @@ Run `dotnet msbuild /t:GenerateCode` to generate code. ``` yaml -require: https://github.com/Azure/azure-rest-api-specs/blob/dc7937d9de990e0e56f9e2d7cdd226f6e210631c/specification/schemaregistry/data-plane/readme.md +require: https://github.com/Azure/azure-rest-api-specs/blob/b4e233b74adf6d6c586c48dd07df0797db4a6a27/specification/schemaregistry/data-plane/readme.md ``` diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Azure.Data.SchemaRegistry.Tests.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Azure.Data.SchemaRegistry.Tests.csproj index 7834a3986139d..b909dca159694 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Azure.Data.SchemaRegistry.Tests.csproj +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Azure.Data.SchemaRegistry.Tests.csproj @@ -2,6 +2,9 @@ $(RequiredTargetFrameworks) + + TRACE + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs index 9eb7cae1e3f7a..ec6b1efb48469 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Azure.Core.TestFramework; using Azure.Identity; using NUnit.Framework; @@ -13,10 +12,10 @@ public class SchemaRegistryClientSamples : SamplesBase GetRecordedVariable("KEYVAULT_URL"); + public string SchemaRegistryUri => GetRecordedVariable("SCHEMAREGISTRY_URL"); } } From ba0addd2fea41edb5dec4691ac5af529a09a65b9 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Thu, 13 Aug 2020 15:18:02 -0700 Subject: [PATCH 09/45] Added happy path tests for each client method. Added recordings. --- .../tests/SchemaRegistryClientLiveTest.cs | 80 +++++++++++++++---- .../CanGetSchemaViaContent.json | 76 ++++++++++++++++++ .../CanGetSchemaViaContentAsync.json | 76 ++++++++++++++++++ .../CanGetSchemaViaId.json | 71 ++++++++++++++++ .../CanGetSchemaViaIdAsync.json | 71 ++++++++++++++++ .../CanRegisterSchema.json | 43 ++++++++++ .../CanRegisterSchemaAsync.json | 43 ++++++++++ .../RecordsGoHere.md | 1 - 8 files changed, 446 insertions(+), 15 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchema.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchemaAsync.json delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/RecordsGoHere.md diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs index 418bcc9120bf3..7eae880df44f1 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs @@ -13,7 +13,6 @@ public class SchemaRegistryClientLiveTest : RecordedTestBase Date: Thu, 20 Aug 2020 17:11:22 -0700 Subject: [PATCH 10/45] Move serialization stuff into the Azure.Data.SchemaRegistry.Avro project. Created project, test project, and tool (to test Avro). --- .../Azure.Data.SchemaRegistry.Avro.sln | 43 +++++++ .../CHANGELOG.md | 4 + .../Directory.Build.props | 6 + .../Azure.Data.SchemaRegistry.Avro/README.md | 104 ++++++++++++++++ ...zure.Data.SchemaRegistry.netstandard2.0.cs | 60 +++++++++ .../src/AvroObjectSerializer.cs | 8 +- .../src/Azure.Data.SchemaRegistry.Avro.csproj | 25 ++++ ...zure.Data.SchemaRegistry.Avro.Tests.csproj | 25 ++++ .../SchemaRegistryClientSamples.HelloWorld.cs | 25 ++++ .../tests/SchemaRegistryClientLiveTest.cs | 114 ++++++++++++++++++ .../SchemaRegistryClientTestEnvironment.cs | 16 +++ .../CanGetSchemaViaContent.json | 76 ++++++++++++ .../CanGetSchemaViaContentAsync.json | 76 ++++++++++++ .../CanGetSchemaViaId.json | 71 +++++++++++ .../CanGetSchemaViaIdAsync.json | 71 +++++++++++ .../CanRegisterSchema.json | 43 +++++++ .../CanRegisterSchemaAsync.json | 43 +++++++ .../tool/ApacheAvroTestTool.csproj | 18 +++ .../tool/Employee.cs | 70 +++++++++++ .../tool/Example.avro | 9 ++ .../tool/Program.cs | 22 ++++ .../Azure.Data.SchemaRegistry.sln | 2 +- 22 files changed, 929 insertions(+), 2 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/CHANGELOG.md create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Directory.Build.props create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/README.md create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.netstandard2.0.cs rename sdk/schemaregistry/{Azure.Data.SchemaRegistry => Azure.Data.SchemaRegistry.Avro}/src/AvroObjectSerializer.cs (97%) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Azure.Data.SchemaRegistry.Avro.Tests.csproj create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientLiveTest.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientTestEnvironment.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchema.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchemaAsync.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Employee.cs create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avro create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln new file mode 100644 index 0000000000000..fc7d1f637981b --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry.Avro", "src\Azure.Data.SchemaRegistry.Avro.csproj", "{E33D09D9-D809-472C-82E6-6A26BDB86FC2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry.Avro.Tests", "tests\Azure.Data.SchemaRegistry.Avro.Tests.csproj", "{4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{8052009B-2126-44A3-88CD-4F3B17894C64}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApacheAvroTestTool", "tool\ApacheAvroTestTool.csproj", "{D995E097-476D-48C6-87D9-0E01FA890AC4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.Build.0 = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.Build.0 = Release|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.Build.0 = Release|Any CPU + {D995E097-476D-48C6-87D9-0E01FA890AC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D995E097-476D-48C6-87D9-0E01FA890AC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D995E097-476D-48C6-87D9-0E01FA890AC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D995E097-476D-48C6-87D9-0E01FA890AC4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/CHANGELOG.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/CHANGELOG.md new file mode 100644 index 0000000000000..36ac757b66df9 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/CHANGELOG.md @@ -0,0 +1,4 @@ +# Release History + +## 1.0.0-preview.1 (2020-08-05) +- Started changelog to capture release notes. \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Directory.Build.props b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Directory.Build.props new file mode 100644 index 0000000000000..1a9611bd49242 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Directory.Build.props @@ -0,0 +1,6 @@ + + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/README.md new file mode 100644 index 0000000000000..3411f7736223f --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/README.md @@ -0,0 +1,104 @@ +# README.md template + +Use the guidelines in each section of this template to ensure consistency and readability of your README. The README resides in your package's GitHub repository at the root of its directory within the repo. It's also used as the package distribution page (NuGet, PyPi, npm, etc.) and as a Quickstart on docs.microsoft.com. See [README-EXAMPLE.md](README-EXAMPLE.md) for an example following this template. + +**Title**: The H1 of your README should be in the format: `# [Product Name] client library for [Language]` + +* All headings, including the H1, should use **sentence-style capitalization**. Refer to the [Microsoft Style Guide][style-guide-msft] and [Microsoft Cloud Style Guide][style-guide-cloud] for more information. +* Example: `# Azure Batch client library for Python` + +# Azure Template client library for .NET + +**Introduction**: The introduction appears directly under the title (H1) of your README. + +* **DO NOT** use an "Introduction" or "Overview" heading (H2) for this section. +* First sentence: **Describe the service** briefly. You can usually use the first line of the service's docs landing page for this (Example: [Cosmos DB docs landing page](https://docs.microsoft.com/azure/cosmos-db/)). +* Next, add a **bulleted list** of the **most common tasks** supported by the package or library, prefaced with "Use the client library for [Product Name] to:". Then, provide code snippets for these tasks in the [Examples](#examples) section later in the document. Keep the task list short but include those tasks most developers need to perform with your package. +* Include this single line of links targeting your product's content at the bottom of the introduction, making any adjustments as necessary (for example, NuGet instead of PyPi): + + [Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/azure-batch) | [Package (PyPi)](https://pypi.org/project/azure-batch/) | [API reference documentation](https://docs.microsoft.com/python/api/overview/azure/batch?view=azure-python) | [Product documentation](https://docs.microsoft.com/azure/batch/) + +> TIP: Your README should be as **brief** as possible but **no more brief** than necessary to get a developer new to Azure, the service, or the package up and running quickly. Keep it brief, but include everything a developer needs to make their first API call successfully. + +## Getting started + +This section should include everything a developer needs to do to install and create their first client connection *very quickly*. + +### Install the package + +First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `pip install package-name`, but should enable a developer to successfully install the package from NuGet, pip, npm, Maven, or even cloning a GitHub repository. + +### Prerequisites + +Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB: + +> You must have an [Azure subscription](https://azure.microsoft.com/free/), [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API), and [Python 3.6+](https://www.python.org/downloads/) to use this package. + +### Authenticate the client + +If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating. + +For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object. + +## Key concepts + +The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity. + +## Examples + +Include code snippets and short descriptions for each task you listed in the [Introduction](#introduction) (the bulleted list). Briefly explain each operation, but include enough clarity to explain complex or otherwise tricky operations. + +If possible, use the same example snippets that your in-code documentation uses. For example, use the snippets in your `examples.py` that Sphinx ingests via its [literalinclude](https://www.sphinx-doc.org/en/1.5/markup/code.html?highlight=code%20examples#includes) directive. The `examples.py` file containing the snippets should reside alongside your package's code, and should be tested in an automated fashion. + +Each example in the *Examples* section starts with an H3 that describes the example. At the top of this section, just under the *Examples* H2, add a bulleted list linking to each example H3. Each example should deep-link to the types and/or members used in the example. + +* [Create the thing](#create-the-thing) +* [Get the thing](#get-the-thing) +* [List the things](#list-the-things) + +### Create the thing + +Use the [create_thing](not-valid-link) method to create a Thing reference; this method does not make a network call. To persist the Thing in the service, call [Thing.save](not-valid-link). + +```Python +thing = client.create_thing(id, name) +thing.save() +``` + +### Get the thing + +The [get_thing](not-valid-link) method retrieves a Thing from the service. The `id` parameter is the unique ID of the Thing, not its "name" property. + +```C# Snippet:GetSecret +var client = new MiniSecretClient(new Uri(endpoint), new DefaultAzureCredential()); + +SecretBundle secret = client.GetSecret("TestSecret"); + +Console.WriteLine(secret.Value); +```Python +things = client.list_things() +``` + +## Troubleshooting + +Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery. + +Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API. + +If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code. + +## Next steps + +* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory. +* If appropriate, point users to other packages that might be useful. +* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for. + +## Contributing + +This is a template, but your SDK readme should include details on how to contribute code to the repo/package. + + +[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization +[style-guide-cloud]: https://worldready.cloudapp.net/Styleguide/Read?id=2696&topicid=25357 + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftemplate%2FAzure.Template%2FREADME.png) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.netstandard2.0.cs new file mode 100644 index 0000000000000..2684fdbd27ec1 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.netstandard2.0.cs @@ -0,0 +1,60 @@ +namespace Azure.Data.SchemaRegistry +{ + public partial class AvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer + { + public AvroObjectSerializer(string schema) { } + public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } + public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } + } + public partial class SchemaProperties + { + internal SchemaProperties() { } + public string GroupName { get { throw null; } } + public string Id { get { throw null; } } + public string Name { get { throw null; } } + public Azure.Data.SchemaRegistry.Models.SerializationType Type { get { throw null; } } + public int? Version { get { throw null; } } + } + public partial class SchemaRegistryClient + { + protected SchemaRegistryClient() { } + public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential) { } + public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential, Azure.Data.SchemaRegistry.SchemaRegistryClientOptions options) { } + public virtual Azure.Response GetSchema(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetSchema(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetSchemaAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetSchemaAsync(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RegisterSchema(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } + public partial class SchemaRegistryClientOptions : Azure.Core.ClientOptions + { + public SchemaRegistryClientOptions(Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion version = Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion.V1_0) { } + public enum ServiceVersion + { + V1_0 = 1, + } + } +} +namespace Azure.Data.SchemaRegistry.Models +{ + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct SerializationType : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public SerializationType(string value) { throw null; } + public static Azure.Data.SchemaRegistry.Models.SerializationType Avro { get { throw null; } } + public bool Equals(Azure.Data.SchemaRegistry.Models.SerializationType other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.Data.SchemaRegistry.Models.SerializationType left, Azure.Data.SchemaRegistry.Models.SerializationType right) { throw null; } + public static implicit operator Azure.Data.SchemaRegistry.Models.SerializationType (string value) { throw null; } + public static bool operator !=(Azure.Data.SchemaRegistry.Models.SerializationType left, Azure.Data.SchemaRegistry.Models.SerializationType right) { throw null; } + public override string ToString() { throw null; } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/AvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs similarity index 97% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/src/AvroObjectSerializer.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs index 4ae91f1666925..d4464d84770aa 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/AvroObjectSerializer.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs @@ -12,7 +12,7 @@ using Avro.Generic; using Azure.Core.Serialization; -namespace Azure.Data.SchemaRegistry +namespace Azure.Data.SchemaRegistry.Avro { /// /// A implementation that uses to for serialization/deserialization. @@ -45,6 +45,12 @@ public AvroObjectSerializer(string schema) //: this(new JsonSerializerOptions()) // //_cache = new ConcurrentDictionary(); //} + + //private void Map(object value) + //{ + // if (value is Schema.Type.Array) + //} + /// public override void Serialize(Stream stream, object value, Type inputType, CancellationToken cancellationToken) { diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj new file mode 100644 index 0000000000000..54cfd2d9d5ad5 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj @@ -0,0 +1,25 @@ + + + Azure Schema Registry SDK + Azure Schema Registry SDK + 1.0.0-preview.1 + Azure;Schema Registry;SchemaRegistry;.NET;Data;$(PackageCommonTags) + $(RequiredTargetFrameworks) + + + + + + + + + + + + + + + + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Azure.Data.SchemaRegistry.Avro.Tests.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Azure.Data.SchemaRegistry.Avro.Tests.csproj new file mode 100644 index 0000000000000..b887cd41890e6 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Azure.Data.SchemaRegistry.Avro.Tests.csproj @@ -0,0 +1,25 @@ + + + $(RequiredTargetFrameworks) + + + TRACE + + + + + + + + + + + + + + + + + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs new file mode 100644 index 0000000000000..ba7a37fbc6676 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.Data.SchemaRegistry.Tests.Samples +{ + public class SchemaRegistryClientSamples : SamplesBase + { + [Test] + public void GettingASecret() + { + var endpoint = TestEnvironment.SchemaRegistryUri; + + #region Snippet:GetSecret + //var client = new SchemaRegistryClient(endpoint, new DefaultAzureCredential()); + + //SecretBundle secret = client.GetSecret("TestSecret"); + + //Console.WriteLine(secret.Value); + #endregion + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientLiveTest.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientLiveTest.cs new file mode 100644 index 0000000000000..2189dadcfdeef --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientLiveTest.cs @@ -0,0 +1,114 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; + +namespace Azure.Data.SchemaRegistry.Tests +{ + public class SchemaRegistryClientLiveTest : RecordedTestBase + { + public SchemaRegistryClientLiveTest(bool isAsync) : base(isAsync) + { + TestDiagnostics = false; + } + + // private SchemaRegistryClient CreateClient() + // { + // return InstrumentClient(new SchemaRegistryClient( + // TestEnvironment.SchemaRegistryUri, + // TestEnvironment.Credential, + // Recording.InstrumentClientOptions(new SchemaRegistryClientOptions()) + // )); + // } + + // [Test] + // public async Task CanRegisterSchema() + // { + // var client = CreateClient(); + // var schemaName = "test1"; + // var groupName = "miyanni_srgroup"; + // var schemaType = SerializationType.Avro; + // var schema = @" + //{ + // ""type"" : ""record"", + // ""namespace"" : ""TestSchema"", + // ""name"" : ""Employee"", + // ""fields"" : [ + // { ""name"" : ""Name"" , ""type"" : ""string"" }, + // { ""name"" : ""Age"", ""type"" : ""int"" } + // ] + //}"; + + // var schemaProperties = await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); + // Assert.IsNotNull(schemaProperties.Value); + // Assert.AreEqual(schemaName, schemaProperties.Value.Name); + // Assert.AreEqual(groupName, schemaProperties.Value.GroupName); + // Assert.AreEqual(schemaType, schemaProperties.Value.Type); + // Assert.IsNotNull(schemaProperties.Value.Version); + // Assert.IsNotNull(schemaProperties.Value.Id); + // Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); + // } + + + // [Test] + // public async Task CanGetSchemaViaContent() + // { + // var client = CreateClient(); + // var schemaName = "test1"; + // var groupName = "miyanni_srgroup"; + // var schemaType = SerializationType.Avro; + // var schema = @" + //{ + // ""type"" : ""record"", + // ""namespace"" : ""TestSchema"", + // ""name"" : ""Employee"", + // ""fields"" : [ + // { ""name"" : ""Name"" , ""type"" : ""string"" }, + // { ""name"" : ""Age"", ""type"" : ""int"" } + // ] + //}"; + + // await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); + // var schemaProperties = await client.GetSchemaAsync(groupName, schemaName, schema, schemaType); + // Assert.IsNotNull(schemaProperties.Value); + // Assert.AreEqual(schemaName, schemaProperties.Value.Name); + // Assert.AreEqual(groupName, schemaProperties.Value.GroupName); + // Assert.AreEqual(schemaType, schemaProperties.Value.Type); + // Assert.IsNotNull(schemaProperties.Value.Version); + // Assert.IsNotNull(schemaProperties.Value.Id); + // Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); + // } + + // [Test] + // public async Task CanGetSchemaViaId() + // { + // var client = CreateClient(); + // var schemaName = "test1"; + // var groupName = "miyanni_srgroup"; + // var schemaType = SerializationType.Avro; + // var schema = @" + //{ + // ""type"" : ""record"", + // ""namespace"" : ""TestSchema"", + // ""name"" : ""Employee"", + // ""fields"" : [ + // { ""name"" : ""Name"" , ""type"" : ""string"" }, + // { ""name"" : ""Age"", ""type"" : ""int"" } + // ] + //}"; + + // var registerProperties = await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); + // Assert.IsNotNull(registerProperties.Value.Id); + // Assert.IsTrue(Guid.TryParse(registerProperties.Value.Id, out Guid _)); + + // var schemaProperties = await client.GetSchemaAsync(registerProperties.Value.Id); + // Assert.IsNotNull(schemaProperties.Value); + // Assert.AreEqual(schemaName, schemaProperties.Value.Name); + // Assert.AreEqual(groupName, schemaProperties.Value.GroupName); + // Assert.AreEqual(schemaType, schemaProperties.Value.Type); + // Assert.IsNotNull(schemaProperties.Value.Version); + // Assert.IsNotNull(schemaProperties.Value.Id); + // Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); + // } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientTestEnvironment.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientTestEnvironment.cs new file mode 100644 index 0000000000000..99fe105a5bac4 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientTestEnvironment.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; + +namespace Azure.Data.SchemaRegistry.Tests +{ + public class SchemaRegistryClientTestEnvironment : TestEnvironment + { + public SchemaRegistryClientTestEnvironment() : base("schemaregistry") + { + } + + public string SchemaRegistryUri => GetRecordedVariable("SCHEMAREGISTRY_URL"); + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json new file mode 100644 index 0000000000000..fbd3739e79200 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json @@ -0,0 +1,76 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Authorization": "Sanitized", + "Content-Length": "369", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "c014706a785fa3324fba957094d50996", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 22:02:33 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "0e30eb5c747e496cbedd94918fe36fd6" + } + }, + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", + "RequestMethod": "POST", + "RequestHeaders": { + "Authorization": "Sanitized", + "Content-Length": "369", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "9e692bad203bc270f771785f7ee81e0f", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 22:02:33 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "0e30eb5c747e496cbedd94918fe36fd6" + } + } + ], + "Variables": { + "RandomSeed": "832707302", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json new file mode 100644 index 0000000000000..cbdda14f71d88 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json @@ -0,0 +1,76 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Authorization": "Sanitized", + "Content-Length": "369", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "dbdc903e75e4d835f5c2b0d825d4952c", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 22:02:34 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "0e30eb5c747e496cbedd94918fe36fd6" + } + }, + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", + "RequestMethod": "POST", + "RequestHeaders": { + "Authorization": "Sanitized", + "Content-Length": "369", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "f34efb219df07ec84fbf07079dbc1a65", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 22:02:34 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "0e30eb5c747e496cbedd94918fe36fd6" + } + } + ], + "Variables": { + "RandomSeed": "1001910995", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json new file mode 100644 index 0000000000000..ff12639ba0f53 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json @@ -0,0 +1,71 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Authorization": "Sanitized", + "Content-Length": "369", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "37c4dee38bfbbddaff13db42bcf62e30", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 22:13:03 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "0e30eb5c747e496cbedd94918fe36fd6" + } + }, + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/getSchemaById/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "RequestMethod": "GET", + "RequestHeaders": { + "Authorization": "Sanitized", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "0f9628224eac8802528daf4c0e092689", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 22:13:03 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": "\u0022\\u000d\\u000a{\\u000d\\u000a \\\u0022type\\\u0022 : \\\u0022record\\\u0022,\\u000d\\u000a \\\u0022namespace\\\u0022 : \\\u0022TestSchema\\\u0022,\\u000d\\u000a \\\u0022name\\\u0022 : \\\u0022Employee\\\u0022,\\u000d\\u000a \\\u0022fields\\\u0022 : [\\u000d\\u000a { \\\u0022name\\\u0022 : \\\u0022Name\\\u0022 , \\\u0022type\\\u0022 : \\\u0022string\\\u0022 },\\u000d\\u000a { \\\u0022name\\\u0022 : \\\u0022Age\\\u0022, \\\u0022type\\\u0022 : \\\u0022int\\\u0022 }\\u000d\\u000a ]\\u000d\\u000a}\u0022" + } + ], + "Variables": { + "RandomSeed": "1249738123", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json new file mode 100644 index 0000000000000..a228505c9807d --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json @@ -0,0 +1,71 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Authorization": "Sanitized", + "Content-Length": "369", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "53a34a59141d18e9bc7b41ec2c64192a", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 22:13:05 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "0e30eb5c747e496cbedd94918fe36fd6" + } + }, + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/getSchemaById/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "RequestMethod": "GET", + "RequestHeaders": { + "Authorization": "Sanitized", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "e7b659080697259a761a460a935b3d23", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 22:13:05 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": "\u0022\\u000d\\u000a{\\u000d\\u000a \\\u0022type\\\u0022 : \\\u0022record\\\u0022,\\u000d\\u000a \\\u0022namespace\\\u0022 : \\\u0022TestSchema\\\u0022,\\u000d\\u000a \\\u0022name\\\u0022 : \\\u0022Employee\\\u0022,\\u000d\\u000a \\\u0022fields\\\u0022 : [\\u000d\\u000a { \\\u0022name\\\u0022 : \\\u0022Name\\\u0022 , \\\u0022type\\\u0022 : \\\u0022string\\\u0022 },\\u000d\\u000a { \\\u0022name\\\u0022 : \\\u0022Age\\\u0022, \\\u0022type\\\u0022 : \\\u0022int\\\u0022 }\\u000d\\u000a ]\\u000d\\u000a}\u0022" + } + ], + "Variables": { + "RandomSeed": "1336917832", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchema.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchema.json new file mode 100644 index 0000000000000..13ec03a47cfe2 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchema.json @@ -0,0 +1,43 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Authorization": "Sanitized", + "Content-Length": "369", + "Content-Type": "application/json", + "Request-Id": "|fae22771-4509d094581d363d.", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200812.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "06149688c0d107fba9beaa6650213cc6", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 00:24:21 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "0e30eb5c747e496cbedd94918fe36fd6" + } + } + ], + "Variables": { + "RandomSeed": "2024185609", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchemaAsync.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchemaAsync.json new file mode 100644 index 0000000000000..7f58562b02554 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchemaAsync.json @@ -0,0 +1,43 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Authorization": "Sanitized", + "Content-Length": "369", + "Content-Type": "application/json", + "Request-Id": "|fae22773-4509d094581d363d.", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200812.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "10d841304c76af44a9857366d3cdcece", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 13 Aug 2020 00:24:41 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "0e30eb5c747e496cbedd94918fe36fd6" + } + } + ], + "Variables": { + "RandomSeed": "341051900", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj new file mode 100644 index 0000000000000..b4606b3fb316b --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj @@ -0,0 +1,18 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + Always + + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Employee.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Employee.cs new file mode 100644 index 0000000000000..1294eca5c59b7 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Employee.cs @@ -0,0 +1,70 @@ +// ------------------------------------------------------------------------------ +// +// Generated by ApacheAvroTestTool, version 1.10.0.0 +// Changes to this file may cause incorrect behavior and will be lost if code +// is regenerated +// +// ------------------------------------------------------------------------------ +namespace TestSchema +{ + using System; + using System.Collections.Generic; + using System.Text; + using Avro; + using Avro.Specific; + + public partial class Employee : ISpecificRecord + { + public static Schema _SCHEMA = Avro.Schema.Parse("{\"type\":\"record\",\"name\":\"Employee\",\"namespace\":\"TestSchema\",\"fields\":[{\"name\":\"Na" + + "me\",\"type\":\"string\"},{\"name\":\"Age\",\"type\":\"int\"}]}"); + private string _Name; + private int _Age; + public virtual Schema Schema + { + get + { + return Employee._SCHEMA; + } + } + public string Name + { + get + { + return this._Name; + } + set + { + this._Name = value; + } + } + public int Age + { + get + { + return this._Age; + } + set + { + this._Age = value; + } + } + public virtual object Get(int fieldPos) + { + switch (fieldPos) + { + case 0: return this.Name; + case 1: return this.Age; + default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Get()"); + }; + } + public virtual void Put(int fieldPos, object fieldValue) + { + switch (fieldPos) + { + case 0: this.Name = (System.String)fieldValue; break; + case 1: this.Age = (System.Int32)fieldValue; break; + default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Put()"); + }; + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avro b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avro new file mode 100644 index 0000000000000..00d7101aeac62 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avro @@ -0,0 +1,9 @@ +{ + "type" : "record", + "namespace" : "TestSchema", + "name" : "Employee", + "fields" : [ + { "name" : "Name" , "type" : "string" }, + { "name" : "Age", "type" : "int" } + ] +} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs new file mode 100644 index 0000000000000..76157fdd8bd4e --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs @@ -0,0 +1,22 @@ +using System.IO; +using Avro; + +namespace ApacheAvroTestTool +{ + class Program + { + static void Main(string[] args) + { + var currentDirectory = Directory.GetCurrentDirectory(); + var examplePath = Path.Combine(currentDirectory, "Example.avro"); + var schema = Schema.Parse(File.ReadAllText(examplePath)); + var codeGen = new CodeGen(); + codeGen.AddSchema(schema); + var compileUnit = codeGen.GenerateCode(); + //compileUnit. ?????????????? + codeGen.WriteTypes(currentDirectory); + + //Schema.GetTypeString(typeof(Employee)); + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/Azure.Data.SchemaRegistry.sln b/sdk/schemaregistry/Azure.Data.SchemaRegistry/Azure.Data.SchemaRegistry.sln index 5e4abf209e1a6..1925de98e9a47 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/Azure.Data.SchemaRegistry.sln +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/Azure.Data.SchemaRegistry.sln @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry.Tests", "tests\Azure.Data.SchemaRegistry.Tests.csproj", "{4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{8052009B-2126-44A3-88CD-4F3B17894C64}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{8052009B-2126-44A3-88CD-4F3B17894C64}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 38531149b16416c036bf5429e2c0217f344eae52 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Thu, 20 Aug 2020 18:09:46 -0700 Subject: [PATCH 11/45] Modify SchemaProperties to have smaller set of properties. Rerun and rename tests. Update api. --- ...Data.SchemaRegistry.Avro.netstandard2.0.cs | 11 ++++ ...zure.Data.SchemaRegistry.netstandard2.0.cs | 60 ------------------- ...zure.Data.SchemaRegistry.netstandard2.0.cs | 16 +---- .../src/SchemaProperties.cs | 14 +++-- .../src/SchemaRegistryClient.cs | 34 +++++------ .../tests/SchemaRegistryClientLiveTest.cs | 27 +++++---- ...chemaViaIdAsync.json => CanGetSchema.json} | 14 ++--- ...chemaViaId.json => CanGetSchemaAsync.json} | 14 ++--- ...emaViaContent.json => CanGetSchemaId.json} | 14 ++--- ...entAsync.json => CanGetSchemaIdAsync.json} | 14 ++--- 10 files changed, 81 insertions(+), 137 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.netstandard2.0.cs rename sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/{CanGetSchemaViaIdAsync.json => CanGetSchema.json} (90%) rename sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/{CanGetSchemaViaId.json => CanGetSchemaAsync.json} (90%) rename sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/{CanGetSchemaViaContent.json => CanGetSchemaId.json} (90%) rename sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/{CanGetSchemaViaContentAsync.json => CanGetSchemaIdAsync.json} (90%) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs new file mode 100644 index 0000000000000..6eefe1b0b4c76 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs @@ -0,0 +1,11 @@ +namespace Azure.Data.SchemaRegistry.Avro +{ + public partial class AvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer + { + public AvroObjectSerializer(string schema) { } + public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } + public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.netstandard2.0.cs deleted file mode 100644 index 2684fdbd27ec1..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.netstandard2.0.cs +++ /dev/null @@ -1,60 +0,0 @@ -namespace Azure.Data.SchemaRegistry -{ - public partial class AvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer - { - public AvroObjectSerializer(string schema) { } - public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } - public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } - public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } - public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } - } - public partial class SchemaProperties - { - internal SchemaProperties() { } - public string GroupName { get { throw null; } } - public string Id { get { throw null; } } - public string Name { get { throw null; } } - public Azure.Data.SchemaRegistry.Models.SerializationType Type { get { throw null; } } - public int? Version { get { throw null; } } - } - public partial class SchemaRegistryClient - { - protected SchemaRegistryClient() { } - public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential) { } - public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential, Azure.Data.SchemaRegistry.SchemaRegistryClientOptions options) { } - public virtual Azure.Response GetSchema(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response GetSchema(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> GetSchemaAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> GetSchemaAsync(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RegisterSchema(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - } - public partial class SchemaRegistryClientOptions : Azure.Core.ClientOptions - { - public SchemaRegistryClientOptions(Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion version = Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion.V1_0) { } - public enum ServiceVersion - { - V1_0 = 1, - } - } -} -namespace Azure.Data.SchemaRegistry.Models -{ - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct SerializationType : System.IEquatable - { - private readonly object _dummy; - private readonly int _dummyPrimitive; - public SerializationType(string value) { throw null; } - public static Azure.Data.SchemaRegistry.Models.SerializationType Avro { get { throw null; } } - public bool Equals(Azure.Data.SchemaRegistry.Models.SerializationType other) { throw null; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override bool Equals(object obj) { throw null; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override int GetHashCode() { throw null; } - public static bool operator ==(Azure.Data.SchemaRegistry.Models.SerializationType left, Azure.Data.SchemaRegistry.Models.SerializationType right) { throw null; } - public static implicit operator Azure.Data.SchemaRegistry.Models.SerializationType (string value) { throw null; } - public static bool operator !=(Azure.Data.SchemaRegistry.Models.SerializationType left, Azure.Data.SchemaRegistry.Models.SerializationType right) { throw null; } - public override string ToString() { throw null; } - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs index 2684fdbd27ec1..22b84067459c8 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs @@ -1,20 +1,10 @@ namespace Azure.Data.SchemaRegistry { - public partial class AvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer - { - public AvroObjectSerializer(string schema) { } - public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } - public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } - public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } - public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } - } public partial class SchemaProperties { internal SchemaProperties() { } - public string GroupName { get { throw null; } } + public string Content { get { throw null; } } public string Id { get { throw null; } } - public string Name { get { throw null; } } - public Azure.Data.SchemaRegistry.Models.SerializationType Type { get { throw null; } } public int? Version { get { throw null; } } } public partial class SchemaRegistryClient @@ -22,10 +12,10 @@ public partial class SchemaRegistryClient protected SchemaRegistryClient() { } public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential) { } public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential, Azure.Data.SchemaRegistry.SchemaRegistryClientOptions options) { } - public virtual Azure.Response GetSchema(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetSchema(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> GetSchemaAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSchemaAsync(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetSchemaId(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetSchemaIdAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response RegisterSchema(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs index 954c6c1871a83..0ec1821874a66 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs @@ -14,8 +14,9 @@ public class SchemaProperties private const char Slash = '/'; private static readonly string[] s_groupSplitter = { "/$schemagroups/" }; - internal SchemaProperties(string location, SerializationType xSchemaType, string xSchemaId, int? xSchemaVersion) + internal SchemaProperties(string content, string location, SerializationType xSchemaType, string xSchemaId, int? xSchemaVersion) { + Content = content; Id = xSchemaId; var groupSplit = location.Split(s_groupSplitter, StringSplitOptions.None)[1]; var slashSplit = groupSplit.Split(Slash); @@ -30,20 +31,25 @@ internal SchemaProperties(string location, SerializationType xSchemaType, string /// public string Id { get; } + /// + /// The schema content of the SchemaRegistry schema. + /// + public string Content { get; } + /// /// The name of the schema. /// - public string Name { get; } + internal string Name { get; } /// /// The group name of the schema. /// - public string GroupName { get; } + internal string GroupName { get; } /// /// Serialization type for the schema being stored. /// - public SerializationType Type { get; } + internal SerializationType Type { get; } /// /// Version of the schema. diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index 1c6347b1b8250..c5ae19a8a11bc 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -64,9 +64,8 @@ public virtual async Task> RegisterSchemaAsync(string try { var response = await RestClient.RegisterAsync(groupName, schemaName, schemaContent, serializationType, cancellationToken).ConfigureAwait(false); - return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), - response); + var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); + return Response.FromValue(properties, response); } catch (Exception e) { @@ -85,9 +84,8 @@ public virtual Response RegisterSchema(string groupName, strin try { var response = RestClient.Register(groupName, schemaName, schemaContent, serializationType, cancellationToken); - return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), - response); + var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); + return Response.FromValue(properties, response); } catch (Exception e) { @@ -99,16 +97,15 @@ public virtual Response RegisterSchema(string groupName, strin /// /// TODO. (Opposite of TryGet) (Find/Query/Get). /// - public virtual async Task> GetSchemaAsync(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) + public virtual async Task> GetSchemaIdAsync(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); scope.Start(); try { var response = await RestClient.QueryIdByContentAsync(groupName, schemaName, schemaContent, serializationType, cancellationToken).ConfigureAwait(false); - return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), - response); + var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); + return Response.FromValue(properties, response); } catch (Exception e) { @@ -120,16 +117,15 @@ public virtual async Task> GetSchemaAsync(string grou /// /// TODO. (Opposite of TryGet) (Find/Query/Get). /// - public virtual Response GetSchema(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) + public virtual Response GetSchemaId(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); scope.Start(); try { var response = RestClient.QueryIdByContent(groupName, schemaName, schemaContent, serializationType, cancellationToken); - return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), - response); + var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); + return Response.FromValue(properties, response); } catch (Exception e) { @@ -148,9 +144,8 @@ public virtual async Task> GetSchemaAsync(string sche try { var response = await RestClient.GetByIdAsync(schemaId, cancellationToken).ConfigureAwait(false); - return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), - response); + var properties = new SchemaProperties(response.Value, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); + return Response.FromValue(properties, response); } catch (Exception e) { @@ -169,9 +164,8 @@ public virtual Response GetSchema(string schemaId, Cancellatio try { var response = RestClient.GetById(schemaId, cancellationToken); - return Response.FromValue( - new SchemaProperties(response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion), - response); + var properties = new SchemaProperties(response.Value, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); + return Response.FromValue(properties, response); } catch (Exception e) { diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs index 7eae880df44f1..0b55231d787c2 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs @@ -45,17 +45,18 @@ public async Task CanRegisterSchema() var schemaProperties = await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); Assert.IsNotNull(schemaProperties.Value); - Assert.AreEqual(schemaName, schemaProperties.Value.Name); - Assert.AreEqual(groupName, schemaProperties.Value.GroupName); - Assert.AreEqual(schemaType, schemaProperties.Value.Type); + //Assert.AreEqual(schemaName, schemaProperties.Value.Name); + //Assert.AreEqual(groupName, schemaProperties.Value.GroupName); + //Assert.AreEqual(schemaType, schemaProperties.Value.Type); Assert.IsNotNull(schemaProperties.Value.Version); Assert.IsNotNull(schemaProperties.Value.Id); Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); + Assert.AreEqual(schema, schemaProperties.Value.Content); } [Test] - public async Task CanGetSchemaViaContent() + public async Task CanGetSchemaId() { var client = CreateClient(); var schemaName = "test1"; @@ -73,18 +74,19 @@ public async Task CanGetSchemaViaContent() }"; await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); - var schemaProperties = await client.GetSchemaAsync(groupName, schemaName, schema, schemaType); + var schemaProperties = await client.GetSchemaIdAsync(groupName, schemaName, schema, schemaType); Assert.IsNotNull(schemaProperties.Value); - Assert.AreEqual(schemaName, schemaProperties.Value.Name); - Assert.AreEqual(groupName, schemaProperties.Value.GroupName); - Assert.AreEqual(schemaType, schemaProperties.Value.Type); + //Assert.AreEqual(schemaName, schemaProperties.Value.Name); + //Assert.AreEqual(groupName, schemaProperties.Value.GroupName); + //Assert.AreEqual(schemaType, schemaProperties.Value.Type); Assert.IsNotNull(schemaProperties.Value.Version); Assert.IsNotNull(schemaProperties.Value.Id); Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); + Assert.AreEqual(schema, schemaProperties.Value.Content); } [Test] - public async Task CanGetSchemaViaId() + public async Task CanGetSchema() { var client = CreateClient(); var schemaName = "test1"; @@ -107,12 +109,13 @@ public async Task CanGetSchemaViaId() var schemaProperties = await client.GetSchemaAsync(registerProperties.Value.Id); Assert.IsNotNull(schemaProperties.Value); - Assert.AreEqual(schemaName, schemaProperties.Value.Name); - Assert.AreEqual(groupName, schemaProperties.Value.GroupName); - Assert.AreEqual(schemaType, schemaProperties.Value.Type); + //Assert.AreEqual(schemaName, schemaProperties.Value.Name); + //Assert.AreEqual(groupName, schemaProperties.Value.GroupName); + //Assert.AreEqual(schemaType, schemaProperties.Value.Type); Assert.IsNotNull(schemaProperties.Value.Version); Assert.IsNotNull(schemaProperties.Value.Id); Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); + Assert.AreEqual(schema, schemaProperties.Value.Content); } } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchema.json similarity index 90% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchema.json index a228505c9807d..0faa5c8808d14 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchema.json @@ -8,10 +8,10 @@ "Content-Length": "369", "Content-Type": "application/json", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200820.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], - "x-ms-client-request-id": "53a34a59141d18e9bc7b41ec2c64192a", + "x-ms-client-request-id": "a9bb4e4bb92bb7199b81a2fe15c1bf1d", "x-ms-return-client-request-id": "true", "X-Schema-Type": "avro" }, @@ -19,7 +19,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:13:05 GMT", + "Date": "Fri, 21 Aug 2020 01:04:42 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -40,17 +40,17 @@ "RequestHeaders": { "Authorization": "Sanitized", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200820.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], - "x-ms-client-request-id": "e7b659080697259a761a460a935b3d23", + "x-ms-client-request-id": "789557cb0beea63b2b639b6c79b01992", "x-ms-return-client-request-id": "true" }, "RequestBody": null, "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:13:05 GMT", + "Date": "Fri, 21 Aug 2020 01:04:42 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -65,7 +65,7 @@ } ], "Variables": { - "RandomSeed": "1336917832", + "RandomSeed": "1446263238", "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" } } \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaAsync.json similarity index 90% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaAsync.json index ff12639ba0f53..6c2934a6aa698 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaAsync.json @@ -8,10 +8,10 @@ "Content-Length": "369", "Content-Type": "application/json", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200820.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], - "x-ms-client-request-id": "37c4dee38bfbbddaff13db42bcf62e30", + "x-ms-client-request-id": "23519c599ecca90a5a65530717191100", "x-ms-return-client-request-id": "true", "X-Schema-Type": "avro" }, @@ -19,7 +19,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:13:03 GMT", + "Date": "Fri, 21 Aug 2020 01:04:45 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -40,17 +40,17 @@ "RequestHeaders": { "Authorization": "Sanitized", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200820.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], - "x-ms-client-request-id": "0f9628224eac8802528daf4c0e092689", + "x-ms-client-request-id": "fa78deb88eafe71485ee6b337d7d6b2d", "x-ms-return-client-request-id": "true" }, "RequestBody": null, "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:13:03 GMT", + "Date": "Fri, 21 Aug 2020 01:04:46 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -65,7 +65,7 @@ } ], "Variables": { - "RandomSeed": "1249738123", + "RandomSeed": "1311802614", "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" } } \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaId.json similarity index 90% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaId.json index fbd3739e79200..77b7285719fc6 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaId.json @@ -8,10 +8,10 @@ "Content-Length": "369", "Content-Type": "application/json", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200820.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], - "x-ms-client-request-id": "c014706a785fa3324fba957094d50996", + "x-ms-client-request-id": "2c620897d9de14f8847756ca36bfb1dd", "x-ms-return-client-request-id": "true", "X-Schema-Type": "avro" }, @@ -19,7 +19,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:02:33 GMT", + "Date": "Fri, 21 Aug 2020 01:04:43 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -42,10 +42,10 @@ "Content-Length": "369", "Content-Type": "application/json", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200820.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], - "x-ms-client-request-id": "9e692bad203bc270f771785f7ee81e0f", + "x-ms-client-request-id": "f81747feb3bdd74d2da2f268fd8a6e28", "x-ms-return-client-request-id": "true", "X-Schema-Type": "avro" }, @@ -53,7 +53,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:02:33 GMT", + "Date": "Fri, 21 Aug 2020 01:04:43 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -70,7 +70,7 @@ } ], "Variables": { - "RandomSeed": "832707302", + "RandomSeed": "423990645", "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" } } \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaIdAsync.json similarity index 90% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaIdAsync.json index cbdda14f71d88..9595a06551b13 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaIdAsync.json @@ -8,10 +8,10 @@ "Content-Length": "369", "Content-Type": "application/json", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200820.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], - "x-ms-client-request-id": "dbdc903e75e4d835f5c2b0d825d4952c", + "x-ms-client-request-id": "5417cde1a45d14a2ae3731d071449823", "x-ms-return-client-request-id": "true", "X-Schema-Type": "avro" }, @@ -19,7 +19,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:02:34 GMT", + "Date": "Fri, 21 Aug 2020 01:04:46 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -42,10 +42,10 @@ "Content-Length": "369", "Content-Type": "application/json", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200820.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], - "x-ms-client-request-id": "f34efb219df07ec84fbf07079dbc1a65", + "x-ms-client-request-id": "ebf572ccf2140bd54101f2c44b198261", "x-ms-return-client-request-id": "true", "X-Schema-Type": "avro" }, @@ -53,7 +53,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:02:34 GMT", + "Date": "Fri, 21 Aug 2020 01:04:47 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -70,7 +70,7 @@ } ], "Variables": { - "RandomSeed": "1001910995", + "RandomSeed": "1351424262", "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" } } \ No newline at end of file From 1b5999c17ec6baf7c0d714a8e03538c2bc1e2589 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Thu, 27 Aug 2020 13:11:14 -0700 Subject: [PATCH 12/45] Still attempting to get Avro library usable functionality. Some reflection-based usage is working. Unfortunately, we're encoding the avro file incorrectly (it includes schema). --- .../Azure.Data.SchemaRegistry.Avro.sln | 6 + .../src/AvroObjectSerializer.cs | 121 ++++++++++++++++-- .../src/Azure.Data.SchemaRegistry.Avro.csproj | 3 + .../tool/ApacheAvroTestTool.csproj | 3 + .../tool/{Example.avro => Example.avsc} | 0 .../tool/Program.cs | 93 +++++++++++++- 6 files changed, 212 insertions(+), 14 deletions(-) rename sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/{Example.avro => Example.avsc} (100%) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln index fc7d1f637981b..7643b964879c4 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApacheAvroTestTool", "tool\ApacheAvroTestTool.csproj", "{D995E097-476D-48C6-87D9-0E01FA890AC4}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry", "..\Azure.Data.SchemaRegistry\src\Azure.Data.SchemaRegistry.csproj", "{D451EE68-ADE4-4780-A002-2D13DEA888A2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {D995E097-476D-48C6-87D9-0E01FA890AC4}.Debug|Any CPU.Build.0 = Debug|Any CPU {D995E097-476D-48C6-87D9-0E01FA890AC4}.Release|Any CPU.ActiveCfg = Release|Any CPU {D995E097-476D-48C6-87D9-0E01FA890AC4}.Release|Any CPU.Build.0 = Release|Any CPU + {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs index d4464d84770aa..436a850da9070 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs @@ -7,9 +7,9 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Avro; using Avro.File; using Avro.Generic; +using Avro.Specific; using Azure.Core.Serialization; namespace Azure.Data.SchemaRegistry.Avro @@ -22,14 +22,20 @@ public class AvroObjectSerializer : ObjectSerializer//, IMemberNameConverter //private readonly ConcurrentDictionary _cache; //private readonly JsonSerializerOptions _options; - private readonly RecordSchema _schema; + private readonly SchemaRegistryClient _client; + private readonly string _schemaContent; + private readonly string _groupName; + /// /// Initializes new instance of . /// - public AvroObjectSerializer(string schema) //: this(new JsonSerializerOptions()) + public AvroObjectSerializer(SchemaRegistryClient client, string schemaContent, string groupName) //: this(new JsonSerializerOptions()) { - _schema = (RecordSchema)Schema.Parse(schema); + _client = client; + _schemaContent = schemaContent; + _groupName = groupName; + } ///// @@ -51,19 +57,112 @@ public AvroObjectSerializer(string schema) //: this(new JsonSerializerOptions()) // if (value is Schema.Type.Array) //} + //private static Dictionary + + //private class SpecificRecordSerializer + //{ + // private readonly Type _type; + // //private readonly string _schema; + + + + // public SpecificRecordSerializer(Type type) + // { + // if (type == null) + // { + // throw new ArgumentNullException(nameof(type)); + // } + + // _type = type; + // //_schema = schema; + // } + + // public void Serialize(Stream stream, object value) + // { + // ////throw new NotImplementedException(); + // ////https://stackoverflow.com/a/1151470/294804 + // //var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(_type); + // ////https://stackoverflow.com/a/2451341/294804 + // //dynamic writer = Activator.CreateInstance(datumWriterType, schema); + + + // ////https://stackoverflow.com/a/4667999/294804 + // //var writerType = typeof(DataFileWriter<>).MakeGenericType(typeof(Employee)); + // ////var openWriterMethod = writerType.GetMethod("OpenWriter", BindingFlags.Public | BindingFlags.Static); + // //var datumBaseType = typeof(DatumWriter<>).MakeGenericType(typeof(Employee)); + // //var openWriterMethod = writerType.GetMethod("OpenWriter", new[] { datumBaseType, typeof(Stream) }); + // //dynamic fileWriter = openWriterMethod?.Invoke(null, new[] { writer, writeFileStream }); + + // ////var writer = new SpecificDatumWriter(schema); + // ////var fileWriter = DataFileWriter.OpenWriter(writer, employeePath); + + + + + + + + // //fileWriter?.Append(employee); + // //fileWriter?.Close(); + + // } + + // //public ValueTask SerializeAsync(Stream stream, object value, Type inputType, CancellationToken cancellationToken) + // //{ + // // throw new NotImplementedException(); + // //} + + // public object Deserialize(Stream stream) + // { + // throw new NotImplementedException(); + // } + + // //public ValueTask DeserializeAsync(Stream stream, Type returnType, CancellationToken cancellationToken) + // //{ + // // throw new NotImplementedException(); + // //} + //} + /// public override void Serialize(Stream stream, object value, Type inputType, CancellationToken cancellationToken) { - if (!(value is IEnumerable records)) + //if (!(value is IEnumerable records)) + //{ + // throw new ArgumentException("Wrong value type."); + //} + + + + + + if (!(value is ISpecificRecord specificRecord)) { throw new ArgumentException("Wrong value type."); } - var datumWriter = new GenericDatumWriter(_schema); - using var writer = DataFileWriter.OpenWriter(datumWriter, stream); - foreach (var record in records) - { - writer.Append(record); - } + + ////https://stackoverflow.com/a/4667999/294804 + //// Get the generic type definition + //MethodInfo method = inputType.GetMethod("Linq", BindingFlags.Public | BindingFlags.Static); + + //// Build a method with the specific type argument you're interested in + //method = method.MakeGenericMethod(typeOne); + //// The "null" is because it's a static method + //method.Invoke(null, arguments); + + + //var datumWriter = new GenericDatumWriter(_schema); + //using var writer = DataFileWriter.OpenWriter(datumWriter, stream); + //foreach (var record in records) + //{ + // writer.Append(record); + //} + + + + + + + //var buffer = JsonSerializer.SerializeToUtf8Bytes(value, inputType, _options); //stream.Write(buffer, 0, buffer.Length); diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj index 54cfd2d9d5ad5..9996bbff2b0f8 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj @@ -19,6 +19,9 @@ + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj index b4606b3fb316b..a442e82148e1b 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj @@ -13,6 +13,9 @@ Always + + Always + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avro b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avsc similarity index 100% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avro rename to sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avsc diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs index 76157fdd8bd4e..3a0f77d1a6aa9 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs @@ -1,14 +1,20 @@ -using System.IO; +using System; +using System.IO; using Avro; +using Avro.File; +using Avro.Generic; +using Avro.Specific; +using TestSchema; namespace ApacheAvroTestTool { class Program { + static void Main(string[] args) { var currentDirectory = Directory.GetCurrentDirectory(); - var examplePath = Path.Combine(currentDirectory, "Example.avro"); + var examplePath = Path.Combine(currentDirectory, "Example.avsc"); var schema = Schema.Parse(File.ReadAllText(examplePath)); var codeGen = new CodeGen(); codeGen.AddSchema(schema); @@ -16,7 +22,88 @@ static void Main(string[] args) //compileUnit. ?????????????? codeGen.WriteTypes(currentDirectory); - //Schema.GetTypeString(typeof(Employee)); + var employeePath = Path.Combine(currentDirectory, "Employee.avro"); + var employee = new Employee { Age = 42, Name = "Caketown" }; + var writeFileStream = new FileStream(employeePath, FileMode.Create); + + + //var writerType = ; + //https://stackoverflow.com/a/1151470/294804 + var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(typeof(Employee)); + //https://stackoverflow.com/a/2451341/294804 + dynamic writer = Activator.CreateInstance(datumWriterType, schema); + + + //https://stackoverflow.com/a/4667999/294804 + var writerType = typeof(DataFileWriter<>).MakeGenericType(typeof(Employee)); + //var openWriterMethod = writerType.GetMethod("OpenWriter", BindingFlags.Public | BindingFlags.Static); + var datumBaseType = typeof(DatumWriter<>).MakeGenericType(typeof(Employee)); + var openWriterMethod = writerType.GetMethod("OpenWriter", new[] { datumBaseType, typeof(Stream) }); + dynamic fileWriter = openWriterMethod?.Invoke(null, new[] { writer, writeFileStream }); + + //var writer = new SpecificDatumWriter(schema); + //var fileWriter = DataFileWriter.OpenWriter(writer, employeePath); + + + + + + + + fileWriter?.Append(employee); + fileWriter?.Close(); + + + writeFileStream.Close(); + + + + + var readFileStream = new FileStream(employeePath, FileMode.Open); + + + //var reader = new SpecificDatumReader(schema, schema); + //var fileReader = DataFileReader.OpenReader(readFileStream, schema, (ws, rs) => reader); + + //var fileReader = DataFileReader.OpenReader(readFileStream); + + + //https://stackoverflow.com/a/4667999/294804 + var readerType = typeof(DataFileReader<>).MakeGenericType(typeof(Employee)); + var openReaderMethod = readerType.GetMethod("OpenReader", new[] { typeof(Stream) }); + dynamic fileReader = openReaderMethod?.Invoke(null, new object[] { readFileStream }); + + + + + // Not the right solution. Reads schema on the avro data. + var readSchema = fileReader?.GetSchema() as Schema; + + + + + + + + + Employee readEmployee = null; + while (fileReader?.HasNext()) + { + readEmployee = fileReader.Next() as Employee; + break; + } + //Employee readEmployee = fileReader?.NextEntries.First(); + + + Console.WriteLine(readEmployee?.Name); + Console.WriteLine(readEmployee?.Age); + + fileReader?.Dispose(); + readFileStream.Close(); + + + //var classThing = new DotnetClass(typeof(Employee)) + //Schema.p } } } From eaec4d9b6d25d57324a39ed6b4fc3acafbf7ae7a Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 28 Aug 2020 17:43:43 -0700 Subject: [PATCH 13/45] Initial serializer implementation. Only does specific records. --- .../src/AvroObjectSerializer.cs | 207 ++++++++---------- .../src/AvroObjectSerializerOptions.cs | 17 ++ .../tool/ApacheAvroTestTool.csproj | 5 + .../tool/Program.cs | 92 +++++--- 4 files changed, 183 insertions(+), 138 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializerOptions.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs index 436a850da9070..ffaae018e3a16 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs @@ -2,20 +2,23 @@ // Licensed under the MIT License. using System; -using System.Collections.Generic; using System.IO; -using System.Text.Json; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text; using System.Threading; using System.Threading.Tasks; -using Avro.File; -using Avro.Generic; +using Avro; +using Avro.IO; using Avro.Specific; using Azure.Core.Serialization; +using Azure.Data.SchemaRegistry.Models; namespace Azure.Data.SchemaRegistry.Avro { /// - /// A implementation that uses to for serialization/deserialization. + /// A implementation that uses for SpecificRecord serialization/deserialization. /// public class AvroObjectSerializer : ObjectSerializer//, IMemberNameConverter { @@ -23,18 +26,20 @@ public class AvroObjectSerializer : ObjectSerializer//, IMemberNameConverter //private readonly JsonSerializerOptions _options; private readonly SchemaRegistryClient _client; - private readonly string _schemaContent; + //private readonly string _schemaContent; private readonly string _groupName; + private readonly AvroObjectSerializerOptions _options; /// /// Initializes new instance of . /// - public AvroObjectSerializer(SchemaRegistryClient client, string schemaContent, string groupName) //: this(new JsonSerializerOptions()) + public AvroObjectSerializer(SchemaRegistryClient client, string groupName, AvroObjectSerializerOptions options = null) //: this(new JsonSerializerOptions()) { - _client = client; - _schemaContent = schemaContent; - _groupName = groupName; + _client = client ?? throw new ArgumentNullException(nameof(client)); + //_schemaContent = schemaContent; + _groupName = groupName ?? throw new ArgumentNullException(nameof(groupName)); + _options = options; } @@ -105,6 +110,19 @@ public AvroObjectSerializer(SchemaRegistryClient client, string schemaContent, s // //fileWriter?.Append(employee); // //fileWriter?.Close(); + // if (!(value is ISpecificRecord specificRecord)) + // { + // throw new ArgumentException("Wrong value type."); + // } + + // //https://stackoverflow.com/a/1151470/294804 + // var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(_type); + // //https://stackoverflow.com/a/2451341/294804 + // dynamic writer = Activator.CreateInstance(datumWriterType, specificRecord.Schema); + // var binaryEncoder = new BinaryEncoder(stream); + + // writer?.Write(value, binaryEncoder); + // binaryEncoder.Flush(); // } // //public ValueTask SerializeAsync(Stream stream, object value, Type inputType, CancellationToken cancellationToken) @@ -123,6 +141,20 @@ public AvroObjectSerializer(SchemaRegistryClient client, string schemaContent, s // //} //} + private static Schema GetSchemaFromType(Type type) + { + //https://stackoverflow.com/a/5898469/294804 + var schemaField = type.GetField("_SCHEMA", BindingFlags.Public | BindingFlags.Static); + if (!(schemaField?.GetValue(null) is Schema schema)) + { + throw new MissingFieldException($"Field _SCHEMA is missing on type {type.Name}."); + } + + return schema; + } + + private static readonly byte[] s_emptyRecordFormatIndicator = { 0, 0, 0, 0 }; + /// public override void Serialize(Stream stream, object value, Type inputType, CancellationToken cancellationToken) { @@ -131,48 +163,39 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc // throw new ArgumentException("Wrong value type."); //} - - - - - if (!(value is ISpecificRecord specificRecord)) - { - throw new ArgumentException("Wrong value type."); - } - - ////https://stackoverflow.com/a/4667999/294804 - //// Get the generic type definition - //MethodInfo method = inputType.GetMethod("Linq", BindingFlags.Public | BindingFlags.Static); - - //// Build a method with the specific type argument you're interested in - //method = method.MakeGenericMethod(typeOne); - //// The "null" is because it's a static method - //method.Invoke(null, arguments); - - - //var datumWriter = new GenericDatumWriter(_schema); - //using var writer = DataFileWriter.OpenWriter(datumWriter, stream); - //foreach (var record in records) + //if (!(value is ISpecificRecord specificRecord)) //{ - // writer.Append(record); + // throw new ArgumentException("Wrong value type."); //} + var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(inputType); + if (isSpecific) + { + var schema = GetSchemaFromType(inputType); + var schemaProperties = _options.AutoRegisterSchemas + ? _client.RegisterSchema(_groupName, schema.Fullname, schema.ToString(), SerializationType.Avro) + : _client.GetSchemaId(_groupName, schema.Fullname, schema.ToString(), SerializationType.Avro); + //https://stackoverflow.com/a/1151470/294804 + var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(inputType); + //https://stackoverflow.com/a/2451341/294804 + dynamic writer = Activator.CreateInstance(datumWriterType, schema); + stream.Write(s_emptyRecordFormatIndicator, 0, 4); + stream.Write(Encoding.UTF8.GetBytes(schemaProperties.Value.Id), 0, 32); + var binaryEncoder = new BinaryEncoder(stream); + writer?.Write(value, binaryEncoder); + binaryEncoder.Flush(); + } - - - //var buffer = JsonSerializer.SerializeToUtf8Bytes(value, inputType, _options); - //stream.Write(buffer, 0, buffer.Length); } /// public override async ValueTask SerializeAsync(Stream stream, object value, Type inputType, CancellationToken cancellationToken) { await Task.Run(() => Serialize(stream, value, inputType, cancellationToken), cancellationToken).ConfigureAwait(false); - //await JsonSerializer.SerializeAsync(stream, value, inputType, _options, cancellationToken).ConfigureAwait(false); } /// @@ -181,88 +204,50 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT //using var memoryStream = new MemoryStream(); //stream.CopyTo(memoryStream); //return JsonSerializer.Deserialize(memoryStream.ToArray(), returnType, _options); - var records = new List(); - using var reader = DataFileReader.OpenReader(stream); - while (reader.HasNext()) + + + + //var records = new List(); + //using var reader = DataFileReader.OpenReader(stream); + //while (reader.HasNext()) + //{ + // records.Add(reader.Next()); + //} + + //return records; + + var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(returnType); + if (isSpecific) { - records.Add(reader.Next()); + using var memoryStream = new MemoryStream(); + stream.CopyTo(memoryStream); + var message = new Memory(memoryStream.ToArray()); + + var recordFormatIdentifier = message.Slice(0, 4).ToArray(); + if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) + { + throw new InvalidDataContractException("The record format identifier for the message is invalid."); + } + var schemaId = Encoding.UTF8.GetString(message.Slice(3, 32).ToArray()); + var schema = Schema.Parse(_client.GetSchema(schemaId).Value.Content); + var valueStream = new MemoryStream(message.Slice(35, message.Length - 36).ToArray()); + + var binaryDecoder = new BinaryDecoder(valueStream); + //https://stackoverflow.com/a/1151470/294804 + var datumReaderType = typeof(SpecificDatumReader<>).MakeGenericType(returnType); + //https://stackoverflow.com/a/2451341/294804 + dynamic reader = Activator.CreateInstance(datumReaderType, schema, schema); + + return reader?.Read(null, binaryDecoder); } - return records; + return null; } /// public override async ValueTask DeserializeAsync(Stream stream, Type returnType, CancellationToken cancellationToken) { return await Task.Run(() => Deserialize(stream, returnType, cancellationToken), cancellationToken).ConfigureAwait(false); - //return await JsonSerializer.DeserializeAsync(stream, returnType, _options, cancellationToken).ConfigureAwait(false); } - - ///// - //string? IMemberNameConverter.ConvertMemberName(MemberInfo member) - //{ - // Argument.AssertNotNull(member, nameof(member)); - - // return _cache.GetOrAdd(member, m => - // { - // // Mimics property enumeration based on: - // // * https://github.com/dotnet/corefx/blob/v3.1.0/src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs#L130-L191 - // // * TODO: Add support for fields when .NET 5 GAs (https://github.com/Azure/azure-sdk-for-net/issues/13627) - - // if (m is PropertyInfo propertyInfo) - // { - // // Ignore indexers. - // if (propertyInfo.GetIndexParameters().Length > 0) - // { - // return null; - // } - - // // Only support public getters and/or setters. - // if (propertyInfo.GetMethod?.IsPublic == true || - // propertyInfo.SetMethod?.IsPublic == true) - // { - // if (propertyInfo.GetCustomAttribute() != null) - // { - // return null; - // } - - // // Ignore - but do not assert correctness - for JsonExtensionDataAttribute based on - // // https://github.com/dotnet/corefx/blob/v3.1.0/src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs#L244-L261 - // if (propertyInfo.GetCustomAttribute() != null) - // { - // return null; - // } - - // // No need to validate collisions since they are based on the serialized name. - // return GetPropertyName(propertyInfo); - // } - // } - - // // The member is unsupported or ignored. - // return null; - // }); - //} - - //private string GetPropertyName(MemberInfo memberInfo) - //{ - // // Mimics property name determination based on - // // https://github.com/dotnet/runtime/blob/dc8b6f90/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfo.cs#L53-L90 - - // JsonPropertyNameAttribute nameAttribute = memberInfo.GetCustomAttribute(false); - // if (nameAttribute != null) - // { - // return nameAttribute.Name - // ?? throw new InvalidOperationException($"The JSON property name for '{memberInfo.DeclaringType}.{memberInfo.Name}' cannot be null."); - // } - // else if (_options.PropertyNamingPolicy != null) - // { - // return _options.PropertyNamingPolicy.ConvertName(memberInfo.Name) - // ?? throw new InvalidOperationException($"The JSON property name for '{memberInfo.DeclaringType}.{memberInfo.Name}' cannot be null."); - // } - // else - // { - // return memberInfo.Name; - // } - //} } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializerOptions.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializerOptions.cs new file mode 100644 index 0000000000000..6bcb33c97042b --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializerOptions.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Data.SchemaRegistry.Avro +{ + /// + /// Options for . + /// + public class AvroObjectSerializerOptions + { + /// + /// When true, automatically registers the provided value's schema with the SchemaRegistry during serialization. + /// When false, the schema is only acquired from the SchemaRegistry. + /// + public bool AutoRegisterSchemas { get; set; } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj index a442e82148e1b..5620788e8bac4 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj @@ -9,6 +9,11 @@ + + + + + Always diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs index 3a0f77d1a6aa9..b888aea69783e 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs @@ -1,8 +1,8 @@ using System; using System.IO; +using System.Reflection; using Avro; -using Avro.File; -using Avro.Generic; +using Avro.IO; using Avro.Specific; using TestSchema; @@ -12,6 +12,14 @@ class Program { static void Main(string[] args) + { + var employee = new Employee { Age = 42, Name = "Caketown" }; + + + + } + + private static void Testing() { var currentDirectory = Directory.GetCurrentDirectory(); var examplePath = Path.Combine(currentDirectory, "Example.avsc"); @@ -27,19 +35,19 @@ static void Main(string[] args) var writeFileStream = new FileStream(employeePath, FileMode.Create); - //var writerType = ; - //https://stackoverflow.com/a/1151470/294804 - var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(typeof(Employee)); - //https://stackoverflow.com/a/2451341/294804 - dynamic writer = Activator.CreateInstance(datumWriterType, schema); + ////var writerType = ; + ////https://stackoverflow.com/a/1151470/294804 + //var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(typeof(Employee)); + ////https://stackoverflow.com/a/2451341/294804 + //dynamic writer = Activator.CreateInstance(datumWriterType, schema); - //https://stackoverflow.com/a/4667999/294804 - var writerType = typeof(DataFileWriter<>).MakeGenericType(typeof(Employee)); - //var openWriterMethod = writerType.GetMethod("OpenWriter", BindingFlags.Public | BindingFlags.Static); - var datumBaseType = typeof(DatumWriter<>).MakeGenericType(typeof(Employee)); - var openWriterMethod = writerType.GetMethod("OpenWriter", new[] { datumBaseType, typeof(Stream) }); - dynamic fileWriter = openWriterMethod?.Invoke(null, new[] { writer, writeFileStream }); + ////https://stackoverflow.com/a/4667999/294804 + //var writerType = typeof(DataFileWriter<>).MakeGenericType(typeof(Employee)); + ////var openWriterMethod = writerType.GetMethod("OpenWriter", BindingFlags.Public | BindingFlags.Static); + //var datumBaseType = typeof(DatumWriter<>).MakeGenericType(typeof(Employee)); + //var openWriterMethod = writerType.GetMethod("OpenWriter", new[] { datumBaseType, typeof(Stream) }); + //dynamic fileWriter = openWriterMethod?.Invoke(null, new[] { writer, writeFileStream }); //var writer = new SpecificDatumWriter(schema); //var fileWriter = DataFileWriter.OpenWriter(writer, employeePath); @@ -47,11 +55,32 @@ static void Main(string[] args) + //fileWriter?.Append(employee); + //fileWriter?.Close(); + + var employeeType = typeof(Employee); + + var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(employeeType); + + + + //https://stackoverflow.com/a/5898469/294804 + var schemaField = employeeType.GetField("_SCHEMA", BindingFlags.Public | BindingFlags.Static); + var reflectionSchema = schemaField?.GetValue(null) as Schema; + + + //var writer = new SpecificDatumWriter(schema); + //https://stackoverflow.com/a/1151470/294804 + var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(employeeType); + //https://stackoverflow.com/a/2451341/294804 + dynamic writer = Activator.CreateInstance(datumWriterType, reflectionSchema); + var binaryEncoder = new BinaryEncoder(writeFileStream); + + writer?.Write(employee, binaryEncoder); + binaryEncoder.Flush(); - fileWriter?.Append(employee); - fileWriter?.Close(); writeFileStream.Close(); @@ -68,37 +97,46 @@ static void Main(string[] args) //var fileReader = DataFileReader.OpenReader(readFileStream); - //https://stackoverflow.com/a/4667999/294804 - var readerType = typeof(DataFileReader<>).MakeGenericType(typeof(Employee)); - var openReaderMethod = readerType.GetMethod("OpenReader", new[] { typeof(Stream) }); - dynamic fileReader = openReaderMethod?.Invoke(null, new object[] { readFileStream }); + ////https://stackoverflow.com/a/4667999/294804 + //var readerType = typeof(DataFileReader<>).MakeGenericType(typeof(Employee)); + //var openReaderMethod = readerType.GetMethod("OpenReader", new[] { typeof(Stream) }); + //dynamic fileReader = openReaderMethod?.Invoke(null, new object[] { readFileStream }); // Not the right solution. Reads schema on the avro data. - var readSchema = fileReader?.GetSchema() as Schema; + //var readSchema = fileReader?.GetSchema() as Schema; + + + var binaryDecoder = new BinaryDecoder(readFileStream); + //var reader = new SpecificDatumReader(schema, schema); + //https://stackoverflow.com/a/1151470/294804 + var datumReaderType = typeof(SpecificDatumReader<>).MakeGenericType(employeeType); + //https://stackoverflow.com/a/2451341/294804 + dynamic reader = Activator.CreateInstance(datumReaderType, reflectionSchema, reflectionSchema); + var readEmployee = reader?.Read(null, binaryDecoder); - Employee readEmployee = null; - while (fileReader?.HasNext()) - { - readEmployee = fileReader.Next() as Employee; - break; - } + //Employee readEmployee = null; + //while (fileReader?.HasNext()) + //{ + // readEmployee = fileReader.Next() as Employee; + // break; + //} //Employee readEmployee = fileReader?.NextEntries.First(); Console.WriteLine(readEmployee?.Name); Console.WriteLine(readEmployee?.Age); - fileReader?.Dispose(); + //fileReader?.Dispose(); readFileStream.Close(); From af23793bdedf262f2d53bc2f28e1b2e913f27f5b Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Mon, 31 Aug 2020 17:56:55 -0700 Subject: [PATCH 14/45] Fixed issues with specific record schema de/serialization. --- .../src/AvroObjectSerializer.cs | 22 ++++++---- .../tool/ApacheAvroTestTool.csproj | 1 + .../tool/Program.cs | 27 ++++++++++-- .../src/Generated/SchemaRestClient.cs | 41 +++++++++---------- .../src/SchemaProperties.cs | 2 +- .../src/SchemaRegistryClient.cs | 19 ++++----- .../Azure.Data.SchemaRegistry/src/autorest.md | 2 +- .../tests/SchemaRegistryClientLiveTest.cs | 14 +++---- 8 files changed, 77 insertions(+), 51 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs index ffaae018e3a16..dcc9ceb5a7115 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs @@ -14,6 +14,8 @@ using Avro.Specific; using Azure.Core.Serialization; using Azure.Data.SchemaRegistry.Models; +using Decoder = Avro.IO.Decoder; +using Encoder = Avro.IO.Encoder; namespace Azure.Data.SchemaRegistry.Avro { @@ -173,8 +175,8 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc { var schema = GetSchemaFromType(inputType); var schemaProperties = _options.AutoRegisterSchemas - ? _client.RegisterSchema(_groupName, schema.Fullname, schema.ToString(), SerializationType.Avro) - : _client.GetSchemaId(_groupName, schema.Fullname, schema.ToString(), SerializationType.Avro); + ? _client.RegisterSchema(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()) + : _client.GetSchemaId(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()); //https://stackoverflow.com/a/1151470/294804 var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(inputType); @@ -183,10 +185,12 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc stream.Write(s_emptyRecordFormatIndicator, 0, 4); - stream.Write(Encoding.UTF8.GetBytes(schemaProperties.Value.Id), 0, 32); + var schemaId = Encoding.UTF8.GetBytes(schemaProperties.Value.Id); + stream.Write(schemaId, 0, 32); var binaryEncoder = new BinaryEncoder(stream); - writer?.Write(value, binaryEncoder); + var writeMethod = datumWriterType.GetMethod("Write", new[] { inputType, typeof(Encoder) }); + writeMethod?.Invoke(writer, new[] { value, binaryEncoder }); binaryEncoder.Flush(); } @@ -220,6 +224,7 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT if (isSpecific) { using var memoryStream = new MemoryStream(); + stream.Position = 0; stream.CopyTo(memoryStream); var message = new Memory(memoryStream.ToArray()); @@ -228,9 +233,11 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT { throw new InvalidDataContractException("The record format identifier for the message is invalid."); } - var schemaId = Encoding.UTF8.GetString(message.Slice(3, 32).ToArray()); + + var schemaIdBytes = message.Slice(4, 32).ToArray(); + var schemaId = Encoding.UTF8.GetString(schemaIdBytes); var schema = Schema.Parse(_client.GetSchema(schemaId).Value.Content); - var valueStream = new MemoryStream(message.Slice(35, message.Length - 36).ToArray()); + var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); var binaryDecoder = new BinaryDecoder(valueStream); //https://stackoverflow.com/a/1151470/294804 @@ -238,7 +245,8 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT //https://stackoverflow.com/a/2451341/294804 dynamic reader = Activator.CreateInstance(datumReaderType, schema, schema); - return reader?.Read(null, binaryDecoder); + var readMethod = datumReaderType.GetMethod("Read", new[] { returnType, typeof(Decoder) }); + return readMethod?.Invoke(reader, new object[] { null, binaryDecoder }); } return null; diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj index 5620788e8bac4..f82e6576ce6eb 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj @@ -7,6 +7,7 @@ + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs index b888aea69783e..65428b6e8911a 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs @@ -1,9 +1,14 @@ using System; using System.IO; using System.Reflection; +using System.Threading; using Avro; using Avro.IO; using Avro.Specific; +using Azure.Data.SchemaRegistry; +using Azure.Data.SchemaRegistry.Avro; +using Azure.Data.SchemaRegistry.Models; +using Azure.Identity; using TestSchema; namespace ApacheAvroTestTool @@ -13,10 +18,26 @@ class Program static void Main(string[] args) { + //Testing(); var employee = new Employee { Age = 42, Name = "Caketown" }; - - - + var schemaName = "test1"; + var groupName = "miyanni_srgroup"; + var schemaType = SerializationType.Avro; + var endpoint = ""; + var creds = new ClientSecretCredential( + "", + "", + "" + ); + var client = new SchemaRegistryClient(endpoint, creds); + var memoryStream = new MemoryStream(); + + var serializer = new AvroObjectSerializer(client, groupName, new AvroObjectSerializerOptions { AutoRegisterSchemas = true }); + serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); + + var deserializedObject = serializer.Deserialize(memoryStream, typeof(Employee), CancellationToken.None) as Employee; + Console.WriteLine(deserializedObject?.Name); + Console.WriteLine(deserializedObject?.Age); } private static void Testing() diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs index 6164b202424e2..2ef1035ad7884 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/SchemaRestClient.cs @@ -57,6 +57,7 @@ internal HttpMessage CreateGetByIdRequest(string schemaId) uri.AppendPath(schemaId, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -116,7 +117,7 @@ public ResponseWithHeaders GetById(string schemaId } } - internal HttpMessage CreateQueryIdByContentRequest(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType) + internal HttpMessage CreateQueryIdByContentRequest(string groupName, string schemaName, SerializationType xSchemaType, string schemaContent) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -130,11 +131,9 @@ internal HttpMessage CreateQueryIdByContentRequest(string groupName, string sche uri.AppendPath(schemaName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; - if (xSchemaType != null) - { - request.Headers.Add("X-Schema-Type", xSchemaType.Value.ToString()); - } + request.Headers.Add("X-Schema-Type", xSchemaType.ToString()); request.Headers.Add("Content-Type", "application/json"); + request.Headers.Add("Accept", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteStringValue(schemaContent); request.Content = content; @@ -144,11 +143,11 @@ internal HttpMessage CreateQueryIdByContentRequest(string groupName, string sche /// Gets the ID referencing an existing schema within the specified schema group, as matched by schema content comparison. /// Schema group under which schema is registered. Group's serialization type should match the serialization type specified in the request. /// Name of the registered schema. - /// String representation of the registered schema. /// Serialization type for the schema being registered. + /// String representation of the registered schema. /// The cancellation token to use. /// , , or is null. - public async Task> QueryIdByContentAsync(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType = null, CancellationToken cancellationToken = default) + public async Task> QueryIdByContentAsync(string groupName, string schemaName, SerializationType xSchemaType, string schemaContent, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -163,7 +162,7 @@ public async Task> throw new ArgumentNullException(nameof(schemaContent)); } - using var message = CreateQueryIdByContentRequest(groupName, schemaName, schemaContent, xSchemaType); + using var message = CreateQueryIdByContentRequest(groupName, schemaName, xSchemaType, schemaContent); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); var headers = new SchemaQueryIdByContentHeaders(message.Response); switch (message.Response.Status) @@ -183,11 +182,11 @@ public async Task> /// Gets the ID referencing an existing schema within the specified schema group, as matched by schema content comparison. /// Schema group under which schema is registered. Group's serialization type should match the serialization type specified in the request. /// Name of the registered schema. - /// String representation of the registered schema. /// Serialization type for the schema being registered. + /// String representation of the registered schema. /// The cancellation token to use. /// , , or is null. - public ResponseWithHeaders QueryIdByContent(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType = null, CancellationToken cancellationToken = default) + public ResponseWithHeaders QueryIdByContent(string groupName, string schemaName, SerializationType xSchemaType, string schemaContent, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -202,7 +201,7 @@ public ResponseWithHeaders QueryIdByCon throw new ArgumentNullException(nameof(schemaContent)); } - using var message = CreateQueryIdByContentRequest(groupName, schemaName, schemaContent, xSchemaType); + using var message = CreateQueryIdByContentRequest(groupName, schemaName, xSchemaType, schemaContent); _pipeline.Send(message, cancellationToken); var headers = new SchemaQueryIdByContentHeaders(message.Response); switch (message.Response.Status) @@ -219,7 +218,7 @@ public ResponseWithHeaders QueryIdByCon } } - internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType) + internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, SerializationType xSchemaType, string schemaContent) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -233,11 +232,9 @@ internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, uri.AppendPath(schemaName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; - if (xSchemaType != null) - { - request.Headers.Add("X-Schema-Type", xSchemaType.Value.ToString()); - } + request.Headers.Add("X-Schema-Type", xSchemaType.ToString()); request.Headers.Add("Content-Type", "application/json"); + request.Headers.Add("Accept", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteStringValue(schemaContent); request.Content = content; @@ -250,11 +247,11 @@ internal HttpMessage CreateRegisterRequest(string groupName, string schemaName, /// /// Schema group under which schema should be registered. Group's serialization type should match the serialization type specified in the request. /// Name of schema being registered. - /// String representation of the schema being registered. /// Serialization type for the schema being registered. + /// String representation of the schema being registered. /// The cancellation token to use. /// , , or is null. - public async Task> RegisterAsync(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType = null, CancellationToken cancellationToken = default) + public async Task> RegisterAsync(string groupName, string schemaName, SerializationType xSchemaType, string schemaContent, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -269,7 +266,7 @@ public async Task> Register throw new ArgumentNullException(nameof(schemaContent)); } - using var message = CreateRegisterRequest(groupName, schemaName, schemaContent, xSchemaType); + using var message = CreateRegisterRequest(groupName, schemaName, xSchemaType, schemaContent); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); var headers = new SchemaRegisterHeaders(message.Response); switch (message.Response.Status) @@ -292,11 +289,11 @@ public async Task> Register /// /// Schema group under which schema should be registered. Group's serialization type should match the serialization type specified in the request. /// Name of schema being registered. - /// String representation of the schema being registered. /// Serialization type for the schema being registered. + /// String representation of the schema being registered. /// The cancellation token to use. /// , , or is null. - public ResponseWithHeaders Register(string groupName, string schemaName, string schemaContent, SerializationType? xSchemaType = null, CancellationToken cancellationToken = default) + public ResponseWithHeaders Register(string groupName, string schemaName, SerializationType xSchemaType, string schemaContent, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -311,7 +308,7 @@ public ResponseWithHeaders Register(string grou throw new ArgumentNullException(nameof(schemaContent)); } - using var message = CreateRegisterRequest(groupName, schemaName, schemaContent, xSchemaType); + using var message = CreateRegisterRequest(groupName, schemaName, xSchemaType, schemaContent); _pipeline.Send(message, cancellationToken); var headers = new SchemaRegisterHeaders(message.Response); switch (message.Response.Status) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs index 0ec1821874a66..53bcf2b1a6af6 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs @@ -54,6 +54,6 @@ internal SchemaProperties(string content, string location, SerializationType xSc /// /// Version of the schema. /// - public int? Version { get; } + internal int? Version { get; } } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index c5ae19a8a11bc..712228d402187 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -32,8 +32,7 @@ public class SchemaRegistryClient public SchemaRegistryClient(string endpoint, TokenCredential credential, SchemaRegistryClientOptions options) : this( new ClientDiagnostics(options), HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, "https://eventhubs.azure.net/.default")), - endpoint)//, - //options.Version) + endpoint) { } @@ -57,13 +56,13 @@ internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline /// /// TODO. (Create OR Get). (Register/Create). /// - public virtual async Task> RegisterSchemaAsync(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) + public virtual async Task> RegisterSchemaAsync(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); scope.Start(); try { - var response = await RestClient.RegisterAsync(groupName, schemaName, schemaContent, serializationType, cancellationToken).ConfigureAwait(false); + var response = await RestClient.RegisterAsync(groupName, schemaName, serializationType, schemaContent, cancellationToken).ConfigureAwait(false); var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); return Response.FromValue(properties, response); } @@ -77,13 +76,13 @@ public virtual async Task> RegisterSchemaAsync(string /// /// TODO. (Create OR Get). (Register/Create). /// - public virtual Response RegisterSchema(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) + public virtual Response RegisterSchema(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); scope.Start(); try { - var response = RestClient.Register(groupName, schemaName, schemaContent, serializationType, cancellationToken); + var response = RestClient.Register(groupName, schemaName, serializationType, schemaContent, cancellationToken); var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); return Response.FromValue(properties, response); } @@ -97,13 +96,13 @@ public virtual Response RegisterSchema(string groupName, strin /// /// TODO. (Opposite of TryGet) (Find/Query/Get). /// - public virtual async Task> GetSchemaIdAsync(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) + public virtual async Task> GetSchemaIdAsync(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); scope.Start(); try { - var response = await RestClient.QueryIdByContentAsync(groupName, schemaName, schemaContent, serializationType, cancellationToken).ConfigureAwait(false); + var response = await RestClient.QueryIdByContentAsync(groupName, schemaName, serializationType, schemaContent, cancellationToken).ConfigureAwait(false); var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); return Response.FromValue(properties, response); } @@ -117,13 +116,13 @@ public virtual async Task> GetSchemaIdAsync(string gr /// /// TODO. (Opposite of TryGet) (Find/Query/Get). /// - public virtual Response GetSchemaId(string groupName, string schemaName, string schemaContent, SerializationType? serializationType = null, CancellationToken cancellationToken = default) + public virtual Response GetSchemaId(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); scope.Start(); try { - var response = RestClient.QueryIdByContent(groupName, schemaName, schemaContent, serializationType, cancellationToken); + var response = RestClient.QueryIdByContent(groupName, schemaName, serializationType, schemaContent, cancellationToken); var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); return Response.FromValue(properties, response); } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md index 7f1f55cd04ad4..fa978170ca675 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/autorest.md @@ -3,5 +3,5 @@ Run `dotnet msbuild /t:GenerateCode` to generate code. ``` yaml -require: https://github.com/Azure/azure-rest-api-specs/blob/b4e233b74adf6d6c586c48dd07df0797db4a6a27/specification/schemaregistry/data-plane/readme.md +require: https://github.com/Azure/azure-rest-api-specs/blob/a90b9146e543d3eec11381bd52d3b6ff271b1b78/specification/schemaregistry/data-plane/readme.md ``` diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs index 0b55231d787c2..83d33513cfd21 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs @@ -43,12 +43,12 @@ public async Task CanRegisterSchema() ] }"; - var schemaProperties = await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); + var schemaProperties = await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); Assert.IsNotNull(schemaProperties.Value); //Assert.AreEqual(schemaName, schemaProperties.Value.Name); //Assert.AreEqual(groupName, schemaProperties.Value.GroupName); //Assert.AreEqual(schemaType, schemaProperties.Value.Type); - Assert.IsNotNull(schemaProperties.Value.Version); + //Assert.IsNotNull(schemaProperties.Value.Version); Assert.IsNotNull(schemaProperties.Value.Id); Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); Assert.AreEqual(schema, schemaProperties.Value.Content); @@ -73,13 +73,13 @@ public async Task CanGetSchemaId() ] }"; - await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); - var schemaProperties = await client.GetSchemaIdAsync(groupName, schemaName, schema, schemaType); + await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); + var schemaProperties = await client.GetSchemaIdAsync(groupName, schemaName, schemaType, schema); Assert.IsNotNull(schemaProperties.Value); //Assert.AreEqual(schemaName, schemaProperties.Value.Name); //Assert.AreEqual(groupName, schemaProperties.Value.GroupName); //Assert.AreEqual(schemaType, schemaProperties.Value.Type); - Assert.IsNotNull(schemaProperties.Value.Version); + //Assert.IsNotNull(schemaProperties.Value.Version); Assert.IsNotNull(schemaProperties.Value.Id); Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); Assert.AreEqual(schema, schemaProperties.Value.Content); @@ -103,7 +103,7 @@ public async Task CanGetSchema() ] }"; - var registerProperties = await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); + var registerProperties = await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); Assert.IsNotNull(registerProperties.Value.Id); Assert.IsTrue(Guid.TryParse(registerProperties.Value.Id, out Guid _)); @@ -112,7 +112,7 @@ public async Task CanGetSchema() //Assert.AreEqual(schemaName, schemaProperties.Value.Name); //Assert.AreEqual(groupName, schemaProperties.Value.GroupName); //Assert.AreEqual(schemaType, schemaProperties.Value.Type); - Assert.IsNotNull(schemaProperties.Value.Version); + //Assert.IsNotNull(schemaProperties.Value.Version); Assert.IsNotNull(schemaProperties.Value.Id); Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); Assert.AreEqual(schema, schemaProperties.Value.Content); From 8d04053ca61f4e2f3e0be7502bf4bad31a00eebd Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Mon, 31 Aug 2020 20:03:52 -0700 Subject: [PATCH 15/45] Got GenericRecord working. Needs cleanup. --- .../src/AvroObjectSerializer.cs | 115 ++++++++++++++++-- .../tool/Program.cs | 41 ++++++- 2 files changed, 140 insertions(+), 16 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs index dcc9ceb5a7115..1680094a9d389 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs @@ -10,12 +10,11 @@ using System.Threading; using System.Threading.Tasks; using Avro; +using Avro.Generic; using Avro.IO; using Avro.Specific; using Azure.Core.Serialization; using Azure.Data.SchemaRegistry.Models; -using Decoder = Avro.IO.Decoder; -using Encoder = Avro.IO.Encoder; namespace Azure.Data.SchemaRegistry.Avro { @@ -155,6 +154,18 @@ private static Schema GetSchemaFromType(Type type) return schema; } + //private static Schema GetSchemaFromValue(object value) + //{ + // //https://stackoverflow.com/a/5898469/294804 + // var schemaField = type.GetField("_SCHEMA", BindingFlags.Public | BindingFlags.Static); + // if (!(schemaField?.GetValue(null) is Schema schema)) + // { + // throw new MissingFieldException($"Field _SCHEMA is missing on type {type.Name}."); + // } + + // return schema; + //} + private static readonly byte[] s_emptyRecordFormatIndicator = { 0, 0, 0, 0 }; /// @@ -173,15 +184,32 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(inputType); if (isSpecific) { - var schema = GetSchemaFromType(inputType); + //var schema = GetSchemaFromType(inputType); + var schema = ((ISpecificRecord)value).Schema; var schemaProperties = _options.AutoRegisterSchemas ? _client.RegisterSchema(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()) : _client.GetSchemaId(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()); + ////https://stackoverflow.com/a/1151470/294804 + //var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(inputType); + ////https://stackoverflow.com/a/2451341/294804 + //dynamic writer = Activator.CreateInstance(datumWriterType, schema); + + + //stream.Write(s_emptyRecordFormatIndicator, 0, 4); + //var schemaId = Encoding.UTF8.GetBytes(schemaProperties.Value.Id); + //stream.Write(schemaId, 0, 32); + + //var binaryEncoder = new BinaryEncoder(stream); + //var writeMethod = datumWriterType.GetMethod("Write", new[] { inputType, typeof(Encoder) }); + //writeMethod?.Invoke(writer, new[] { value, binaryEncoder }); + //binaryEncoder.Flush(); + + //https://stackoverflow.com/a/1151470/294804 - var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(inputType); + //var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(inputType); //https://stackoverflow.com/a/2451341/294804 - dynamic writer = Activator.CreateInstance(datumWriterType, schema); + var writer = new SpecificDatumWriter(schema); stream.Write(s_emptyRecordFormatIndicator, 0, 4); @@ -189,11 +217,45 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc stream.Write(schemaId, 0, 32); var binaryEncoder = new BinaryEncoder(stream); - var writeMethod = datumWriterType.GetMethod("Write", new[] { inputType, typeof(Encoder) }); - writeMethod?.Invoke(writer, new[] { value, binaryEncoder }); + writer.Write(value, binaryEncoder); + //var writeMethod = datumWriterType.GetMethod("Write", new[] { inputType, typeof(Encoder) }); + //writeMethod?.Invoke(writer, new[] { value, binaryEncoder }); binaryEncoder.Flush(); + return; } + var isGeneric = typeof(GenericRecord).IsAssignableFrom(inputType); + if (isGeneric) + { + var schema = ((GenericRecord)value).Schema; + var schemaProperties = _options.AutoRegisterSchemas + ? _client.RegisterSchema(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()) + : _client.GetSchemaId(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()); + + var writer = new GenericDatumWriter(schema); + stream.Write(s_emptyRecordFormatIndicator, 0, 4); + var schemaId = Encoding.UTF8.GetBytes(schemaProperties.Value.Id); + stream.Write(schemaId, 0, 32); + + var binaryEncoder = new BinaryEncoder(stream); + writer.Write(value, binaryEncoder); + binaryEncoder.Flush(); + return; + } + //var genericWriter = new GenericDatumWriter(null); + + + + //stream.Write(s_emptyRecordFormatIndicator, 0, 4); + //var schemaId = Encoding.UTF8.GetBytes(schemaProperties.Value.Id); + //stream.Write(schemaId, 0, 32); + + //var binaryEncoder = new BinaryEncoder(stream); + //writer.Write(value, binaryEncoder); + ////var writeMethod = datumWriterType.GetMethod("Write", new[] { inputType, typeof(Encoder) }); + ////writeMethod?.Invoke(writer, new[] { value, binaryEncoder }); + //binaryEncoder.Flush(); + } /// @@ -240,15 +302,42 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); var binaryDecoder = new BinaryDecoder(valueStream); - //https://stackoverflow.com/a/1151470/294804 - var datumReaderType = typeof(SpecificDatumReader<>).MakeGenericType(returnType); - //https://stackoverflow.com/a/2451341/294804 - dynamic reader = Activator.CreateInstance(datumReaderType, schema, schema); + ////https://stackoverflow.com/a/1151470/294804 + //var datumReaderType = typeof(SpecificDatumReader<>).MakeGenericType(returnType); + ////https://stackoverflow.com/a/2451341/294804 + //dynamic reader = Activator.CreateInstance(datumReaderType, schema, schema); + + //var readMethod = datumReaderType.GetMethod("Read", new[] { returnType, typeof(Decoder) }); + //return readMethod?.Invoke(reader, new object[] { null, binaryDecoder }); + var reader = new SpecificDatumReader(schema, schema); + return reader.Read(null, binaryDecoder); + } - var readMethod = datumReaderType.GetMethod("Read", new[] { returnType, typeof(Decoder) }); - return readMethod?.Invoke(reader, new object[] { null, binaryDecoder }); + var isGeneric = typeof(GenericRecord).IsAssignableFrom(returnType); + if (isGeneric) + { + using var memoryStream = new MemoryStream(); + stream.Position = 0; + stream.CopyTo(memoryStream); + var message = new Memory(memoryStream.ToArray()); + + var recordFormatIdentifier = message.Slice(0, 4).ToArray(); + if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) + { + throw new InvalidDataContractException("The record format identifier for the message is invalid."); + } + + var schemaIdBytes = message.Slice(4, 32).ToArray(); + var schemaId = Encoding.UTF8.GetString(schemaIdBytes); + var schema = Schema.Parse(_client.GetSchema(schemaId).Value.Content); + var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); + + var binaryDecoder = new BinaryDecoder(valueStream); + var reader = new GenericDatumReader(schema, schema); + return reader.Read(null, binaryDecoder); } + return null; } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs index 65428b6e8911a..4193a291775b2 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs @@ -3,6 +3,7 @@ using System.Reflection; using System.Threading; using Avro; +using Avro.Generic; using Avro.IO; using Avro.Specific; using Azure.Data.SchemaRegistry; @@ -35,9 +36,43 @@ static void Main(string[] args) var serializer = new AvroObjectSerializer(client, groupName, new AvroObjectSerializerOptions { AutoRegisterSchemas = true }); serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); - var deserializedObject = serializer.Deserialize(memoryStream, typeof(Employee), CancellationToken.None) as Employee; - Console.WriteLine(deserializedObject?.Name); - Console.WriteLine(deserializedObject?.Age); + var deserializedObject = serializer.Deserialize(memoryStream, typeof(Employee), CancellationToken.None); + var readEmployee = deserializedObject as Employee; + Console.WriteLine(readEmployee?.Name); + Console.WriteLine(readEmployee?.Age); + + + + + var record = new GenericRecord((RecordSchema)Employee._SCHEMA); + record.Add("Name", "Yanni"); + record.Add("Age", 33); + + var currentDirectory = Directory.GetCurrentDirectory(); + var employeePath = Path.Combine(currentDirectory, "GenericEmployee.avro"); + var writeFileStream = new FileStream(employeePath, FileMode.Create); + + //memoryStream = new MemoryStream(); + serializer = new AvroObjectSerializer(client, groupName, new AvroObjectSerializerOptions { AutoRegisterSchemas = true }); + serializer.Serialize(writeFileStream, record, typeof(GenericRecord), CancellationToken.None); + writeFileStream.Close(); + + + var readFileStream = new FileStream(employeePath, FileMode.Open); + deserializedObject = serializer.Deserialize(readFileStream, typeof(GenericRecord), CancellationToken.None); + var readRecord = deserializedObject as GenericRecord; + Console.WriteLine(readRecord?.GetValue(0)); + Console.WriteLine(readRecord?.GetValue(1)); + + readFileStream.Close(); + + //int + //serializer = new AvroObjectSerializer(client, groupName, new AvroObjectSerializerOptions { AutoRegisterSchemas = true }); + //serializer.Serialize(memoryStream, 42, typeof(int), CancellationToken.None); + + //deserializedObject = serializer.Deserialize(memoryStream, typeof(int), CancellationToken.None); + //var readInt = (int)deserializedObject; + //Console.WriteLine(readInt); } private static void Testing() From 306fa4ff3fa1d196ac9c07d08aaaf0e0f22e3e73 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Tue, 1 Sep 2020 16:17:42 -0700 Subject: [PATCH 16/45] Code cleanup begins! --- ...Data.SchemaRegistry.Avro.netstandard2.0.cs | 7 +- .../src/AvroObjectSerializer.cs | 193 +----------------- ...zure.Data.SchemaRegistry.netstandard2.0.cs | 9 +- 3 files changed, 15 insertions(+), 194 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs index 6eefe1b0b4c76..a1bc05acd6767 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs @@ -2,10 +2,15 @@ namespace Azure.Data.SchemaRegistry.Avro { public partial class AvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer { - public AvroObjectSerializer(string schema) { } + public AvroObjectSerializer(Azure.Data.SchemaRegistry.SchemaRegistryClient client, string groupName, Azure.Data.SchemaRegistry.Avro.AvroObjectSerializerOptions options = null) { } public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } } + public partial class AvroObjectSerializerOptions + { + public AvroObjectSerializerOptions() { } + public bool AutoRegisterSchemas { get { throw null; } set { } } + } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs index 1680094a9d389..349ed1830127b 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs @@ -21,126 +21,27 @@ namespace Azure.Data.SchemaRegistry.Avro /// /// A implementation that uses for SpecificRecord serialization/deserialization. /// - public class AvroObjectSerializer : ObjectSerializer//, IMemberNameConverter + public class AvroObjectSerializer : ObjectSerializer { - //private readonly ConcurrentDictionary _cache; - //private readonly JsonSerializerOptions _options; - private readonly SchemaRegistryClient _client; //private readonly string _schemaContent; private readonly string _groupName; private readonly AvroObjectSerializerOptions _options; - /// /// Initializes new instance of . /// - public AvroObjectSerializer(SchemaRegistryClient client, string groupName, AvroObjectSerializerOptions options = null) //: this(new JsonSerializerOptions()) + public AvroObjectSerializer(SchemaRegistryClient client, string groupName, AvroObjectSerializerOptions options = null) { _client = client ?? throw new ArgumentNullException(nameof(client)); //_schemaContent = schemaContent; _groupName = groupName ?? throw new ArgumentNullException(nameof(groupName)); _options = options; - } - ///// - ///// Initializes new instance of . - ///// - ///// The instance to use when serializing/deserializing. - ///// is null. - //public AvroObjectSerializer(JsonSerializerOptions options) - //{ - // //_options = options ?? throw new ArgumentNullException(nameof(options)); - - // //// TODO: Consider using WeakReference cache to allow the GC to collect if the JsonObjectSerialized is held for a long duration. - // //_cache = new ConcurrentDictionary(); - //} - - - //private void Map(object value) - //{ - // if (value is Schema.Type.Array) - //} - - //private static Dictionary - - //private class SpecificRecordSerializer - //{ - // private readonly Type _type; - // //private readonly string _schema; - - - - // public SpecificRecordSerializer(Type type) - // { - // if (type == null) - // { - // throw new ArgumentNullException(nameof(type)); - // } - - // _type = type; - // //_schema = schema; - // } - - // public void Serialize(Stream stream, object value) - // { - // ////throw new NotImplementedException(); - // ////https://stackoverflow.com/a/1151470/294804 - // //var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(_type); - // ////https://stackoverflow.com/a/2451341/294804 - // //dynamic writer = Activator.CreateInstance(datumWriterType, schema); - - - // ////https://stackoverflow.com/a/4667999/294804 - // //var writerType = typeof(DataFileWriter<>).MakeGenericType(typeof(Employee)); - // ////var openWriterMethod = writerType.GetMethod("OpenWriter", BindingFlags.Public | BindingFlags.Static); - // //var datumBaseType = typeof(DatumWriter<>).MakeGenericType(typeof(Employee)); - // //var openWriterMethod = writerType.GetMethod("OpenWriter", new[] { datumBaseType, typeof(Stream) }); - // //dynamic fileWriter = openWriterMethod?.Invoke(null, new[] { writer, writeFileStream }); - - // ////var writer = new SpecificDatumWriter(schema); - // ////var fileWriter = DataFileWriter.OpenWriter(writer, employeePath); - - - - - - - - // //fileWriter?.Append(employee); - // //fileWriter?.Close(); - - // if (!(value is ISpecificRecord specificRecord)) - // { - // throw new ArgumentException("Wrong value type."); - // } - - // //https://stackoverflow.com/a/1151470/294804 - // var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(_type); - // //https://stackoverflow.com/a/2451341/294804 - // dynamic writer = Activator.CreateInstance(datumWriterType, specificRecord.Schema); - // var binaryEncoder = new BinaryEncoder(stream); - - // writer?.Write(value, binaryEncoder); - // binaryEncoder.Flush(); - // } - - // //public ValueTask SerializeAsync(Stream stream, object value, Type inputType, CancellationToken cancellationToken) - // //{ - // // throw new NotImplementedException(); - // //} - - // public object Deserialize(Stream stream) - // { - // throw new NotImplementedException(); - // } + private static readonly byte[] s_emptyRecordFormatIndicator = { 0, 0, 0, 0 }; - // //public ValueTask DeserializeAsync(Stream stream, Type returnType, CancellationToken cancellationToken) - // //{ - // // throw new NotImplementedException(); - // //} - //} + //private Dictionary _cachedSchemas = new Dictionary(); private static Schema GetSchemaFromType(Type type) { @@ -154,33 +55,9 @@ private static Schema GetSchemaFromType(Type type) return schema; } - //private static Schema GetSchemaFromValue(object value) - //{ - // //https://stackoverflow.com/a/5898469/294804 - // var schemaField = type.GetField("_SCHEMA", BindingFlags.Public | BindingFlags.Static); - // if (!(schemaField?.GetValue(null) is Schema schema)) - // { - // throw new MissingFieldException($"Field _SCHEMA is missing on type {type.Name}."); - // } - - // return schema; - //} - - private static readonly byte[] s_emptyRecordFormatIndicator = { 0, 0, 0, 0 }; - /// public override void Serialize(Stream stream, object value, Type inputType, CancellationToken cancellationToken) { - //if (!(value is IEnumerable records)) - //{ - // throw new ArgumentException("Wrong value type."); - //} - - //if (!(value is ISpecificRecord specificRecord)) - //{ - // throw new ArgumentException("Wrong value type."); - //} - var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(inputType); if (isSpecific) { @@ -190,36 +67,13 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc ? _client.RegisterSchema(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()) : _client.GetSchemaId(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()); - ////https://stackoverflow.com/a/1151470/294804 - //var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(inputType); - ////https://stackoverflow.com/a/2451341/294804 - //dynamic writer = Activator.CreateInstance(datumWriterType, schema); - - - //stream.Write(s_emptyRecordFormatIndicator, 0, 4); - //var schemaId = Encoding.UTF8.GetBytes(schemaProperties.Value.Id); - //stream.Write(schemaId, 0, 32); - - //var binaryEncoder = new BinaryEncoder(stream); - //var writeMethod = datumWriterType.GetMethod("Write", new[] { inputType, typeof(Encoder) }); - //writeMethod?.Invoke(writer, new[] { value, binaryEncoder }); - //binaryEncoder.Flush(); - - - //https://stackoverflow.com/a/1151470/294804 - //var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(inputType); - //https://stackoverflow.com/a/2451341/294804 var writer = new SpecificDatumWriter(schema); - - stream.Write(s_emptyRecordFormatIndicator, 0, 4); var schemaId = Encoding.UTF8.GetBytes(schemaProperties.Value.Id); stream.Write(schemaId, 0, 32); var binaryEncoder = new BinaryEncoder(stream); writer.Write(value, binaryEncoder); - //var writeMethod = datumWriterType.GetMethod("Write", new[] { inputType, typeof(Encoder) }); - //writeMethod?.Invoke(writer, new[] { value, binaryEncoder }); binaryEncoder.Flush(); return; } @@ -242,20 +96,6 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc binaryEncoder.Flush(); return; } - //var genericWriter = new GenericDatumWriter(null); - - - - //stream.Write(s_emptyRecordFormatIndicator, 0, 4); - //var schemaId = Encoding.UTF8.GetBytes(schemaProperties.Value.Id); - //stream.Write(schemaId, 0, 32); - - //var binaryEncoder = new BinaryEncoder(stream); - //writer.Write(value, binaryEncoder); - ////var writeMethod = datumWriterType.GetMethod("Write", new[] { inputType, typeof(Encoder) }); - ////writeMethod?.Invoke(writer, new[] { value, binaryEncoder }); - //binaryEncoder.Flush(); - } /// @@ -267,21 +107,6 @@ public override async ValueTask SerializeAsync(Stream stream, object value, Type /// public override object Deserialize(Stream stream, Type returnType, CancellationToken cancellationToken) { - //using var memoryStream = new MemoryStream(); - //stream.CopyTo(memoryStream); - //return JsonSerializer.Deserialize(memoryStream.ToArray(), returnType, _options); - - - - //var records = new List(); - //using var reader = DataFileReader.OpenReader(stream); - //while (reader.HasNext()) - //{ - // records.Add(reader.Next()); - //} - - //return records; - var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(returnType); if (isSpecific) { @@ -302,13 +127,6 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); var binaryDecoder = new BinaryDecoder(valueStream); - ////https://stackoverflow.com/a/1151470/294804 - //var datumReaderType = typeof(SpecificDatumReader<>).MakeGenericType(returnType); - ////https://stackoverflow.com/a/2451341/294804 - //dynamic reader = Activator.CreateInstance(datumReaderType, schema, schema); - - //var readMethod = datumReaderType.GetMethod("Read", new[] { returnType, typeof(Decoder) }); - //return readMethod?.Invoke(reader, new object[] { null, binaryDecoder }); var reader = new SpecificDatumReader(schema, schema); return reader.Read(null, binaryDecoder); } @@ -319,7 +137,7 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT using var memoryStream = new MemoryStream(); stream.Position = 0; stream.CopyTo(memoryStream); - var message = new Memory(memoryStream.ToArray()); + var message = new ReadOnlyMemory(memoryStream.ToArray()); var recordFormatIdentifier = message.Slice(0, 4).ToArray(); if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) @@ -337,7 +155,6 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT return reader.Read(null, binaryDecoder); } - return null; } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs index 22b84067459c8..7b654694138b4 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs @@ -5,7 +5,6 @@ public partial class SchemaProperties internal SchemaProperties() { } public string Content { get { throw null; } } public string Id { get { throw null; } } - public int? Version { get { throw null; } } } public partial class SchemaRegistryClient { @@ -14,10 +13,10 @@ public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credenti public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential, Azure.Data.SchemaRegistry.SchemaRegistryClientOptions options) { } public virtual Azure.Response GetSchema(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSchemaAsync(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response GetSchemaId(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> GetSchemaIdAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RegisterSchema(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, string schemaContent, Azure.Data.SchemaRegistry.Models.SerializationType? serializationType = default(Azure.Data.SchemaRegistry.Models.SerializationType?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetSchemaId(string groupName, string schemaName, Azure.Data.SchemaRegistry.Models.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetSchemaIdAsync(string groupName, string schemaName, Azure.Data.SchemaRegistry.Models.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RegisterSchema(string groupName, string schemaName, Azure.Data.SchemaRegistry.Models.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, Azure.Data.SchemaRegistry.Models.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public partial class SchemaRegistryClientOptions : Azure.Core.ClientOptions { From d65d746e5d1fcb9b95c1d38120a7372905ec6cf0 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 2 Sep 2020 15:43:45 -0700 Subject: [PATCH 17/45] :-) Cleaned up code for serializers. Wrote proper async implementation. --- .../src/AvroObjectSerializer.cs | 303 ++++++++++++------ 1 file changed, 209 insertions(+), 94 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs index 349ed1830127b..7907665cedd39 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs @@ -2,9 +2,9 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using System.Text; using System.Threading; @@ -24,7 +24,6 @@ namespace Azure.Data.SchemaRegistry.Avro public class AvroObjectSerializer : ObjectSerializer { private readonly SchemaRegistryClient _client; - //private readonly string _schemaContent; private readonly string _groupName; private readonly AvroObjectSerializerOptions _options; @@ -34,134 +33,250 @@ public class AvroObjectSerializer : ObjectSerializer public AvroObjectSerializer(SchemaRegistryClient client, string groupName, AvroObjectSerializerOptions options = null) { _client = client ?? throw new ArgumentNullException(nameof(client)); - //_schemaContent = schemaContent; _groupName = groupName ?? throw new ArgumentNullException(nameof(groupName)); _options = options; } private static readonly byte[] s_emptyRecordFormatIndicator = { 0, 0, 0, 0 }; - //private Dictionary _cachedSchemas = new Dictionary(); + private readonly Dictionary _cachedSchemas = new Dictionary(); - private static Schema GetSchemaFromType(Type type) + private enum SupportedType { - //https://stackoverflow.com/a/5898469/294804 - var schemaField = type.GetField("_SCHEMA", BindingFlags.Public | BindingFlags.Static); - if (!(schemaField?.GetValue(null) is Schema schema)) + SpecificRecord, + GenericRecord + } + + private static SupportedType GetSupportedTypeOrThrow(Type type) + { + if (typeof(ISpecificRecord).IsAssignableFrom(type)) { - throw new MissingFieldException($"Field _SCHEMA is missing on type {type.Name}."); + return SupportedType.SpecificRecord; } - return schema; + if (typeof(GenericRecord).IsAssignableFrom(type)) + { + return SupportedType.GenericRecord; + } + + throw new ArgumentException($"Type {type.Name} is not supported for serialization operations."); } - /// - public override void Serialize(Stream stream, object value, Type inputType, CancellationToken cancellationToken) + private string GetSchemaId(Schema schema, CancellationToken cancellationToken) { - var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(inputType); - if (isSpecific) - { - //var schema = GetSchemaFromType(inputType); - var schema = ((ISpecificRecord)value).Schema; - var schemaProperties = _options.AutoRegisterSchemas - ? _client.RegisterSchema(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()) - : _client.GetSchemaId(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()); - - var writer = new SpecificDatumWriter(schema); - stream.Write(s_emptyRecordFormatIndicator, 0, 4); - var schemaId = Encoding.UTF8.GetBytes(schemaProperties.Value.Id); - stream.Write(schemaId, 0, 32); - - var binaryEncoder = new BinaryEncoder(stream); - writer.Write(value, binaryEncoder); - binaryEncoder.Flush(); - return; - } + var schemaProperties = _options.AutoRegisterSchemas + ? _client.RegisterSchema(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString(), cancellationToken) + : _client.GetSchemaId(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString(), cancellationToken); + return schemaProperties.Value.Id; + } + + private async Task GetSchemaIdAsync(Schema schema, CancellationToken cancellationToken) + { + var schemaProperties = await (_options.AutoRegisterSchemas + ? _client.RegisterSchemaAsync(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString(), cancellationToken) + : _client.GetSchemaIdAsync(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString(), cancellationToken)) + .ConfigureAwait(false); + return schemaProperties.Value.Id; + } - var isGeneric = typeof(GenericRecord).IsAssignableFrom(inputType); - if (isGeneric) + private static DatumWriter GetWriterAndSchema(object value, SupportedType supportedType, out Schema schema) + { + switch (supportedType) { - var schema = ((GenericRecord)value).Schema; - var schemaProperties = _options.AutoRegisterSchemas - ? _client.RegisterSchema(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()) - : _client.GetSchemaId(_groupName, schema.Fullname, SerializationType.Avro, schema.ToString()); - - var writer = new GenericDatumWriter(schema); - stream.Write(s_emptyRecordFormatIndicator, 0, 4); - var schemaId = Encoding.UTF8.GetBytes(schemaProperties.Value.Id); - stream.Write(schemaId, 0, 32); - - var binaryEncoder = new BinaryEncoder(stream); - writer.Write(value, binaryEncoder); - binaryEncoder.Flush(); - return; + case SupportedType.SpecificRecord: + schema = ((ISpecificRecord)value).Schema; + return new SpecificDatumWriter(schema); + case SupportedType.GenericRecord: + schema = ((GenericRecord)value).Schema; + return new GenericDatumWriter(schema); + default: + throw new ArgumentException($"Invalid supported type value: {supportedType}"); } } /// - public override async ValueTask SerializeAsync(Stream stream, object value, Type inputType, CancellationToken cancellationToken) + public override void Serialize(Stream stream, object value, Type inputType, CancellationToken cancellationToken) { - await Task.Run(() => Serialize(stream, value, inputType, cancellationToken), cancellationToken).ConfigureAwait(false); + //TODO: Null check input + var supportedType = GetSupportedTypeOrThrow(inputType); + var writer = GetWriterAndSchema(value, supportedType, out var schema); + var schemaId = GetSchemaId(schema, cancellationToken); + var binaryEncoder = new BinaryEncoder(stream); + stream.Write(s_emptyRecordFormatIndicator, 0, 4); + stream.Write(Encoding.UTF8.GetBytes(schemaId), 0, 32); + writer.Write(value, binaryEncoder); + binaryEncoder.Flush(); } /// - public override object Deserialize(Stream stream, Type returnType, CancellationToken cancellationToken) + public override async ValueTask SerializeAsync(Stream stream, object value, Type inputType, CancellationToken cancellationToken) + { + //TODO: Null check input + //await Task.Run(() => Serialize(stream, value, inputType, cancellationToken), cancellationToken).ConfigureAwait(false); + var supportedType = GetSupportedTypeOrThrow(inputType); + var writer = GetWriterAndSchema(value, supportedType, out var schema); + var schemaId = await GetSchemaIdAsync(schema, cancellationToken).ConfigureAwait(false); + var binaryEncoder = new BinaryEncoder(stream); + await stream.WriteAsync(s_emptyRecordFormatIndicator, 0, 4, cancellationToken).ConfigureAwait(false); + await stream.WriteAsync(Encoding.UTF8.GetBytes(schemaId), 0, 32, cancellationToken).ConfigureAwait(false); + writer.Write(value, binaryEncoder); + binaryEncoder.Flush(); + } + + private Schema GetSchemaById(string schemaId, CancellationToken cancellationToken) { - var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(returnType); - if (isSpecific) + if (_cachedSchemas.TryGetValue(schemaId, out var cachedSchema)) { - using var memoryStream = new MemoryStream(); - stream.Position = 0; - stream.CopyTo(memoryStream); - var message = new Memory(memoryStream.ToArray()); - - var recordFormatIdentifier = message.Slice(0, 4).ToArray(); - if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) - { - throw new InvalidDataContractException("The record format identifier for the message is invalid."); - } - - var schemaIdBytes = message.Slice(4, 32).ToArray(); - var schemaId = Encoding.UTF8.GetString(schemaIdBytes); - var schema = Schema.Parse(_client.GetSchema(schemaId).Value.Content); - var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); - - var binaryDecoder = new BinaryDecoder(valueStream); - var reader = new SpecificDatumReader(schema, schema); - return reader.Read(null, binaryDecoder); + return cachedSchema; } - var isGeneric = typeof(GenericRecord).IsAssignableFrom(returnType); - if (isGeneric) + var schemaContent = _client.GetSchema(schemaId, cancellationToken).Value.Content; + var schema = Schema.Parse(schemaContent); + _cachedSchemas.Add(schemaId, schema); + return schema; + } + + private async Task GetSchemaByIdAsync(string schemaId, CancellationToken cancellationToken) + { + if (_cachedSchemas.TryGetValue(schemaId, out var cachedSchema)) { - using var memoryStream = new MemoryStream(); - stream.Position = 0; - stream.CopyTo(memoryStream); - var message = new ReadOnlyMemory(memoryStream.ToArray()); - - var recordFormatIdentifier = message.Slice(0, 4).ToArray(); - if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) - { - throw new InvalidDataContractException("The record format identifier for the message is invalid."); - } - - var schemaIdBytes = message.Slice(4, 32).ToArray(); - var schemaId = Encoding.UTF8.GetString(schemaIdBytes); - var schema = Schema.Parse(_client.GetSchema(schemaId).Value.Content); - var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); - - var binaryDecoder = new BinaryDecoder(valueStream); - var reader = new GenericDatumReader(schema, schema); - return reader.Read(null, binaryDecoder); + return cachedSchema; } - return null; + var schemaContent = (await _client.GetSchemaAsync(schemaId, cancellationToken).ConfigureAwait(false)).Value.Content; + var schema = Schema.Parse(schemaContent); + _cachedSchemas.Add(schemaId, schema); + return schema; + } + + private static DatumReader GetReader(Schema schema, SupportedType supportedType) + { + switch (supportedType) + { + case SupportedType.SpecificRecord: + return new SpecificDatumReader(schema, schema); + case SupportedType.GenericRecord: + return new GenericDatumReader(schema, schema); + default: + throw new ArgumentException($"Invalid supported type value: {supportedType}"); + } + } + + private static ReadOnlyMemory CopyToReadOnlyMemory(Stream stream) + { + using var tempMemoryStream = new MemoryStream(); + stream.Position = 0; + stream.CopyTo(tempMemoryStream); + return new ReadOnlyMemory(tempMemoryStream.ToArray()); + } + + private static void ValidateRecordFormatIdentifier(ReadOnlyMemory message) + { + var recordFormatIdentifier = message.Slice(0, 4).ToArray(); + if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) + { + throw new InvalidDataContractException( + $"The record format identifier ({recordFormatIdentifier[0]:X} {recordFormatIdentifier[1]:X} {recordFormatIdentifier[2]:X} {recordFormatIdentifier[3]:X}) for the message is invalid."); + } + } + + private Schema GetSchema(ReadOnlyMemory message, CancellationToken cancellationToken) + { + var schemaIdBytes = message.Slice(4, 32).ToArray(); + var schemaId = Encoding.UTF8.GetString(schemaIdBytes); + var schemaContent = _client.GetSchema(schemaId, cancellationToken).Value.Content; + return Schema.Parse(schemaContent); + } + + private async Task GetSchemaAsync(ReadOnlyMemory message, CancellationToken cancellationToken) + { + var schemaIdBytes = message.Slice(4, 32).ToArray(); + var schemaId = Encoding.UTF8.GetString(schemaIdBytes); + var schemaContent = (await _client.GetSchemaAsync(schemaId, cancellationToken).ConfigureAwait(false)).Value.Content; + return Schema.Parse(schemaContent); + } + + /// + public override object Deserialize(Stream stream, Type returnType, CancellationToken cancellationToken) + { + //TODO: Null check input + var supportedType = GetSupportedTypeOrThrow(returnType); + var message = CopyToReadOnlyMemory(stream); + ValidateRecordFormatIdentifier(message); + var schema = GetSchema(message, cancellationToken); + using var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); + var binaryDecoder = new BinaryDecoder(valueStream); + + var reader = GetReader(schema, supportedType); + return reader.Read(reuse: null, binaryDecoder); + + + + //var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(returnType); + //if (isSpecific) + //{ + // using var memoryStream = new MemoryStream(); + // stream.Position = 0; + // stream.CopyTo(memoryStream); + // var message = new Memory(memoryStream.ToArray()); + + // var recordFormatIdentifier = message.Slice(0, 4).ToArray(); + // if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) + // { + // throw new InvalidDataContractException("The record format identifier for the message is invalid."); + // } + + // var schemaIdBytes = message.Slice(4, 32).ToArray(); + // var schemaId = Encoding.UTF8.GetString(schemaIdBytes); + // var schema = Schema.Parse(_client.GetSchema(schemaId).Value.Content); + // var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); + + // var binaryDecoder = new BinaryDecoder(valueStream); + // var reader = new SpecificDatumReader(schema, schema); + // return reader.Read(null, binaryDecoder); + //} + + //var isGeneric = typeof(GenericRecord).IsAssignableFrom(returnType); + //if (isGeneric) + //{ + // using var memoryStream = new MemoryStream(); + // stream.Position = 0; + // stream.CopyTo(memoryStream); + // var message = new ReadOnlyMemory(memoryStream.ToArray()); + + // var recordFormatIdentifier = message.Slice(0, 4).ToArray(); + // if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) + // { + // throw new InvalidDataContractException("The record format identifier for the message is invalid."); + // } + + // var schemaIdBytes = message.Slice(4, 32).ToArray(); + // var schemaId = Encoding.UTF8.GetString(schemaIdBytes); + // var schema = Schema.Parse(_client.GetSchema(schemaId).Value.Content); + // var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); + + // var binaryDecoder = new BinaryDecoder(valueStream); + // var reader = new GenericDatumReader(schema, schema); + // return reader.Read(null, binaryDecoder); + //} + + //return null; } /// public override async ValueTask DeserializeAsync(Stream stream, Type returnType, CancellationToken cancellationToken) { - return await Task.Run(() => Deserialize(stream, returnType, cancellationToken), cancellationToken).ConfigureAwait(false); + //return await Task.Run(() => Deserialize(stream, returnType, cancellationToken), cancellationToken).ConfigureAwait(false); + //TODO: Null check input + var supportedType = GetSupportedTypeOrThrow(returnType); + var message = CopyToReadOnlyMemory(stream); + ValidateRecordFormatIdentifier(message); + var schema = await GetSchemaAsync(message, cancellationToken).ConfigureAwait(false); + using var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); + var binaryDecoder = new BinaryDecoder(valueStream); + + var reader = GetReader(schema, supportedType); + return reader.Read(reuse: null, binaryDecoder); } } } From 6daf00871d1ea7d0b20a29e4d9f2ece213e3d7b4 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 2 Sep 2020 15:51:58 -0700 Subject: [PATCH 18/45] Renamed classes to be more accurate. Removal of commented code. --- ... => SchemaRegistryAvroObjectSerializer.cs} | 64 ++----------------- ...emaRegistryAvroObjectSerializerOptions.cs} | 6 +- .../tool/Program.cs | 6 +- 3 files changed, 11 insertions(+), 65 deletions(-) rename sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/{AvroObjectSerializer.cs => SchemaRegistryAvroObjectSerializer.cs} (74%) rename sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/{AvroObjectSerializerOptions.cs => SchemaRegistryAvroObjectSerializerOptions.cs} (60%) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializer.cs similarity index 74% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializer.cs index 7907665cedd39..17890ea2a5f21 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializer.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializer.cs @@ -19,18 +19,18 @@ namespace Azure.Data.SchemaRegistry.Avro { /// - /// A implementation that uses for SpecificRecord serialization/deserialization. + /// A implementation that uses for SpecificRecord serialization/deserialization. /// - public class AvroObjectSerializer : ObjectSerializer + public class SchemaRegistryAvroObjectSerializer : ObjectSerializer { private readonly SchemaRegistryClient _client; private readonly string _groupName; - private readonly AvroObjectSerializerOptions _options; + private readonly SchemaRegistryAvroObjectSerializerOptions _options; /// - /// Initializes new instance of . + /// Initializes new instance of . /// - public AvroObjectSerializer(SchemaRegistryClient client, string groupName, AvroObjectSerializerOptions options = null) + public SchemaRegistryAvroObjectSerializer(SchemaRegistryClient client, string groupName, SchemaRegistryAvroObjectSerializerOptions options = null) { _client = client ?? throw new ArgumentNullException(nameof(client)); _groupName = groupName ?? throw new ArgumentNullException(nameof(groupName)); @@ -112,7 +112,6 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc public override async ValueTask SerializeAsync(Stream stream, object value, Type inputType, CancellationToken cancellationToken) { //TODO: Null check input - //await Task.Run(() => Serialize(stream, value, inputType, cancellationToken), cancellationToken).ConfigureAwait(false); var supportedType = GetSupportedTypeOrThrow(inputType); var writer = GetWriterAndSchema(value, supportedType, out var schema); var schemaId = await GetSchemaIdAsync(schema, cancellationToken).ConfigureAwait(false); @@ -209,64 +208,11 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT var reader = GetReader(schema, supportedType); return reader.Read(reuse: null, binaryDecoder); - - - - //var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(returnType); - //if (isSpecific) - //{ - // using var memoryStream = new MemoryStream(); - // stream.Position = 0; - // stream.CopyTo(memoryStream); - // var message = new Memory(memoryStream.ToArray()); - - // var recordFormatIdentifier = message.Slice(0, 4).ToArray(); - // if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) - // { - // throw new InvalidDataContractException("The record format identifier for the message is invalid."); - // } - - // var schemaIdBytes = message.Slice(4, 32).ToArray(); - // var schemaId = Encoding.UTF8.GetString(schemaIdBytes); - // var schema = Schema.Parse(_client.GetSchema(schemaId).Value.Content); - // var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); - - // var binaryDecoder = new BinaryDecoder(valueStream); - // var reader = new SpecificDatumReader(schema, schema); - // return reader.Read(null, binaryDecoder); - //} - - //var isGeneric = typeof(GenericRecord).IsAssignableFrom(returnType); - //if (isGeneric) - //{ - // using var memoryStream = new MemoryStream(); - // stream.Position = 0; - // stream.CopyTo(memoryStream); - // var message = new ReadOnlyMemory(memoryStream.ToArray()); - - // var recordFormatIdentifier = message.Slice(0, 4).ToArray(); - // if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) - // { - // throw new InvalidDataContractException("The record format identifier for the message is invalid."); - // } - - // var schemaIdBytes = message.Slice(4, 32).ToArray(); - // var schemaId = Encoding.UTF8.GetString(schemaIdBytes); - // var schema = Schema.Parse(_client.GetSchema(schemaId).Value.Content); - // var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); - - // var binaryDecoder = new BinaryDecoder(valueStream); - // var reader = new GenericDatumReader(schema, schema); - // return reader.Read(null, binaryDecoder); - //} - - //return null; } /// public override async ValueTask DeserializeAsync(Stream stream, Type returnType, CancellationToken cancellationToken) { - //return await Task.Run(() => Deserialize(stream, returnType, cancellationToken), cancellationToken).ConfigureAwait(false); //TODO: Null check input var supportedType = GetSupportedTypeOrThrow(returnType); var message = CopyToReadOnlyMemory(stream); diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializerOptions.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializerOptions.cs similarity index 60% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializerOptions.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializerOptions.cs index 6bcb33c97042b..8c7dce1ebdbef 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/AvroObjectSerializerOptions.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializerOptions.cs @@ -4,12 +4,12 @@ namespace Azure.Data.SchemaRegistry.Avro { /// - /// Options for . + /// Options for . /// - public class AvroObjectSerializerOptions + public class SchemaRegistryAvroObjectSerializerOptions { /// - /// When true, automatically registers the provided value's schema with the SchemaRegistry during serialization. + /// When true, automatically registers the provided schema with the SchemaRegistry during serialization. /// When false, the schema is only acquired from the SchemaRegistry. /// public bool AutoRegisterSchemas { get; set; } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs index 4193a291775b2..452264ac15617 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs @@ -33,7 +33,7 @@ static void Main(string[] args) var client = new SchemaRegistryClient(endpoint, creds); var memoryStream = new MemoryStream(); - var serializer = new AvroObjectSerializer(client, groupName, new AvroObjectSerializerOptions { AutoRegisterSchemas = true }); + var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); var deserializedObject = serializer.Deserialize(memoryStream, typeof(Employee), CancellationToken.None); @@ -53,7 +53,7 @@ static void Main(string[] args) var writeFileStream = new FileStream(employeePath, FileMode.Create); //memoryStream = new MemoryStream(); - serializer = new AvroObjectSerializer(client, groupName, new AvroObjectSerializerOptions { AutoRegisterSchemas = true }); + serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); serializer.Serialize(writeFileStream, record, typeof(GenericRecord), CancellationToken.None); writeFileStream.Close(); @@ -67,7 +67,7 @@ static void Main(string[] args) readFileStream.Close(); //int - //serializer = new AvroObjectSerializer(client, groupName, new AvroObjectSerializerOptions { AutoRegisterSchemas = true }); + //serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); //serializer.Serialize(memoryStream, 42, typeof(int), CancellationToken.None); //deserializedObject = serializer.Deserialize(memoryStream, typeof(int), CancellationToken.None); From aff9ef73a26881c3bcd47ae0c04356197ca637bf Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 2 Sep 2020 16:54:35 -0700 Subject: [PATCH 19/45] Moved serializer over to main project. Removed other project and solution. --- .../Azure.Data.SchemaRegistry.Avro.sln | 49 ----- .../CHANGELOG.md | 4 - .../Directory.Build.props | 6 - .../Azure.Data.SchemaRegistry.Avro/README.md | 104 --------- ...Data.SchemaRegistry.Avro.netstandard2.0.cs | 16 -- .../src/Azure.Data.SchemaRegistry.Avro.csproj | 28 --- ...zure.Data.SchemaRegistry.Avro.Tests.csproj | 25 --- .../SchemaRegistryClientSamples.HelloWorld.cs | 25 --- .../SchemaRegistryClientTestEnvironment.cs | 16 -- .../CanGetSchemaViaContent.json | 76 ------- .../CanGetSchemaViaContentAsync.json | 76 ------- .../CanGetSchemaViaId.json | 71 ------ .../CanGetSchemaViaIdAsync.json | 71 ------ .../CanRegisterSchema.json | 43 ---- .../CanRegisterSchemaAsync.json | 43 ---- .../tool/ApacheAvroTestTool.csproj | 27 --- .../tool/Example.avsc | 9 - .../tool/Program.cs | 203 ------------------ .../SchemaRegistryAvroObjectSerializer.cs | 25 ++- ...hemaRegistryAvroObjectSerializerOptions.cs | 0 .../src/Azure.Data.SchemaRegistry.csproj | 1 + .../src/SchemaProperties.cs | 4 +- .../src/SchemaRegistryClient.cs | 17 +- .../src/SchemaRegistryClientOptions.cs | 8 +- .../tests}/Employee.cs | 0 ...maRegistryAvroObjectSerializerLiveTest.cs} | 47 ++-- .../tests/SchemaRegistryClientLiveTest.cs | 12 -- 27 files changed, 53 insertions(+), 953 deletions(-) delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/CHANGELOG.md delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Directory.Build.props delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/README.md delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Azure.Data.SchemaRegistry.Avro.Tests.csproj delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientTestEnvironment.cs delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchema.json delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchemaAsync.json delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avsc delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs rename sdk/schemaregistry/{Azure.Data.SchemaRegistry.Avro/src => Azure.Data.SchemaRegistry/src/Avro}/SchemaRegistryAvroObjectSerializer.cs (94%) rename sdk/schemaregistry/{Azure.Data.SchemaRegistry.Avro/src => Azure.Data.SchemaRegistry/src/Avro}/SchemaRegistryAvroObjectSerializerOptions.cs (100%) rename sdk/schemaregistry/{Azure.Data.SchemaRegistry.Avro/tool => Azure.Data.SchemaRegistry/tests}/Employee.cs (100%) rename sdk/schemaregistry/{Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientLiveTest.cs => Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs} (64%) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln deleted file mode 100644 index 7643b964879c4..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Azure.Data.SchemaRegistry.Avro.sln +++ /dev/null @@ -1,49 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29709.97 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry.Avro", "src\Azure.Data.SchemaRegistry.Avro.csproj", "{E33D09D9-D809-472C-82E6-6A26BDB86FC2}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry.Avro.Tests", "tests\Azure.Data.SchemaRegistry.Avro.Tests.csproj", "{4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{8052009B-2126-44A3-88CD-4F3B17894C64}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApacheAvroTestTool", "tool\ApacheAvroTestTool.csproj", "{D995E097-476D-48C6-87D9-0E01FA890AC4}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry", "..\Azure.Data.SchemaRegistry\src\Azure.Data.SchemaRegistry.csproj", "{D451EE68-ADE4-4780-A002-2D13DEA888A2}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.Build.0 = Release|Any CPU - {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.Build.0 = Release|Any CPU - {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.Build.0 = Release|Any CPU - {D995E097-476D-48C6-87D9-0E01FA890AC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D995E097-476D-48C6-87D9-0E01FA890AC4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D995E097-476D-48C6-87D9-0E01FA890AC4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D995E097-476D-48C6-87D9-0E01FA890AC4}.Release|Any CPU.Build.0 = Release|Any CPU - {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} - EndGlobalSection -EndGlobal diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/CHANGELOG.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/CHANGELOG.md deleted file mode 100644 index 36ac757b66df9..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/CHANGELOG.md +++ /dev/null @@ -1,4 +0,0 @@ -# Release History - -## 1.0.0-preview.1 (2020-08-05) -- Started changelog to capture release notes. \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Directory.Build.props b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Directory.Build.props deleted file mode 100644 index 1a9611bd49242..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/Directory.Build.props +++ /dev/null @@ -1,6 +0,0 @@ - - - - diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/README.md deleted file mode 100644 index 3411f7736223f..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/README.md +++ /dev/null @@ -1,104 +0,0 @@ -# README.md template - -Use the guidelines in each section of this template to ensure consistency and readability of your README. The README resides in your package's GitHub repository at the root of its directory within the repo. It's also used as the package distribution page (NuGet, PyPi, npm, etc.) and as a Quickstart on docs.microsoft.com. See [README-EXAMPLE.md](README-EXAMPLE.md) for an example following this template. - -**Title**: The H1 of your README should be in the format: `# [Product Name] client library for [Language]` - -* All headings, including the H1, should use **sentence-style capitalization**. Refer to the [Microsoft Style Guide][style-guide-msft] and [Microsoft Cloud Style Guide][style-guide-cloud] for more information. -* Example: `# Azure Batch client library for Python` - -# Azure Template client library for .NET - -**Introduction**: The introduction appears directly under the title (H1) of your README. - -* **DO NOT** use an "Introduction" or "Overview" heading (H2) for this section. -* First sentence: **Describe the service** briefly. You can usually use the first line of the service's docs landing page for this (Example: [Cosmos DB docs landing page](https://docs.microsoft.com/azure/cosmos-db/)). -* Next, add a **bulleted list** of the **most common tasks** supported by the package or library, prefaced with "Use the client library for [Product Name] to:". Then, provide code snippets for these tasks in the [Examples](#examples) section later in the document. Keep the task list short but include those tasks most developers need to perform with your package. -* Include this single line of links targeting your product's content at the bottom of the introduction, making any adjustments as necessary (for example, NuGet instead of PyPi): - - [Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/azure-batch) | [Package (PyPi)](https://pypi.org/project/azure-batch/) | [API reference documentation](https://docs.microsoft.com/python/api/overview/azure/batch?view=azure-python) | [Product documentation](https://docs.microsoft.com/azure/batch/) - -> TIP: Your README should be as **brief** as possible but **no more brief** than necessary to get a developer new to Azure, the service, or the package up and running quickly. Keep it brief, but include everything a developer needs to make their first API call successfully. - -## Getting started - -This section should include everything a developer needs to do to install and create their first client connection *very quickly*. - -### Install the package - -First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `pip install package-name`, but should enable a developer to successfully install the package from NuGet, pip, npm, Maven, or even cloning a GitHub repository. - -### Prerequisites - -Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB: - -> You must have an [Azure subscription](https://azure.microsoft.com/free/), [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API), and [Python 3.6+](https://www.python.org/downloads/) to use this package. - -### Authenticate the client - -If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating. - -For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object. - -## Key concepts - -The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity. - -## Examples - -Include code snippets and short descriptions for each task you listed in the [Introduction](#introduction) (the bulleted list). Briefly explain each operation, but include enough clarity to explain complex or otherwise tricky operations. - -If possible, use the same example snippets that your in-code documentation uses. For example, use the snippets in your `examples.py` that Sphinx ingests via its [literalinclude](https://www.sphinx-doc.org/en/1.5/markup/code.html?highlight=code%20examples#includes) directive. The `examples.py` file containing the snippets should reside alongside your package's code, and should be tested in an automated fashion. - -Each example in the *Examples* section starts with an H3 that describes the example. At the top of this section, just under the *Examples* H2, add a bulleted list linking to each example H3. Each example should deep-link to the types and/or members used in the example. - -* [Create the thing](#create-the-thing) -* [Get the thing](#get-the-thing) -* [List the things](#list-the-things) - -### Create the thing - -Use the [create_thing](not-valid-link) method to create a Thing reference; this method does not make a network call. To persist the Thing in the service, call [Thing.save](not-valid-link). - -```Python -thing = client.create_thing(id, name) -thing.save() -``` - -### Get the thing - -The [get_thing](not-valid-link) method retrieves a Thing from the service. The `id` parameter is the unique ID of the Thing, not its "name" property. - -```C# Snippet:GetSecret -var client = new MiniSecretClient(new Uri(endpoint), new DefaultAzureCredential()); - -SecretBundle secret = client.GetSecret("TestSecret"); - -Console.WriteLine(secret.Value); -```Python -things = client.list_things() -``` - -## Troubleshooting - -Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery. - -Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API. - -If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code. - -## Next steps - -* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory. -* If appropriate, point users to other packages that might be useful. -* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for. - -## Contributing - -This is a template, but your SDK readme should include details on how to contribute code to the repo/package. - - -[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization -[style-guide-cloud]: https://worldready.cloudapp.net/Styleguide/Read?id=2696&topicid=25357 - -![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftemplate%2FAzure.Template%2FREADME.png) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs deleted file mode 100644 index a1bc05acd6767..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/api/Azure.Data.SchemaRegistry.Avro.netstandard2.0.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Azure.Data.SchemaRegistry.Avro -{ - public partial class AvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer - { - public AvroObjectSerializer(Azure.Data.SchemaRegistry.SchemaRegistryClient client, string groupName, Azure.Data.SchemaRegistry.Avro.AvroObjectSerializerOptions options = null) { } - public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } - public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } - public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } - public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } - } - public partial class AvroObjectSerializerOptions - { - public AvroObjectSerializerOptions() { } - public bool AutoRegisterSchemas { get { throw null; } set { } } - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj deleted file mode 100644 index 9996bbff2b0f8..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/Azure.Data.SchemaRegistry.Avro.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - Azure Schema Registry SDK - Azure Schema Registry SDK - 1.0.0-preview.1 - Azure;Schema Registry;SchemaRegistry;.NET;Data;$(PackageCommonTags) - $(RequiredTargetFrameworks) - - - - - - - - - - - - - - - - - - - - - diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Azure.Data.SchemaRegistry.Avro.Tests.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Azure.Data.SchemaRegistry.Avro.Tests.csproj deleted file mode 100644 index b887cd41890e6..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Azure.Data.SchemaRegistry.Avro.Tests.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - $(RequiredTargetFrameworks) - - - TRACE - - - - - - - - - - - - - - - - - - - diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs deleted file mode 100644 index ba7a37fbc6676..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Azure.Core.TestFramework; -using NUnit.Framework; - -namespace Azure.Data.SchemaRegistry.Tests.Samples -{ - public class SchemaRegistryClientSamples : SamplesBase - { - [Test] - public void GettingASecret() - { - var endpoint = TestEnvironment.SchemaRegistryUri; - - #region Snippet:GetSecret - //var client = new SchemaRegistryClient(endpoint, new DefaultAzureCredential()); - - //SecretBundle secret = client.GetSecret("TestSecret"); - - //Console.WriteLine(secret.Value); - #endregion - } - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientTestEnvironment.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientTestEnvironment.cs deleted file mode 100644 index 99fe105a5bac4..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientTestEnvironment.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Azure.Core.TestFramework; - -namespace Azure.Data.SchemaRegistry.Tests -{ - public class SchemaRegistryClientTestEnvironment : TestEnvironment - { - public SchemaRegistryClientTestEnvironment() : base("schemaregistry") - { - } - - public string SchemaRegistryUri => GetRecordedVariable("SCHEMAREGISTRY_URL"); - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json deleted file mode 100644 index fbd3739e79200..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContent.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "Entries": [ - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", - "RequestMethod": "PUT", - "RequestHeaders": { - "Authorization": "Sanitized", - "Content-Length": "369", - "Content-Type": "application/json", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "c014706a785fa3324fba957094d50996", - "x-ms-return-client-request-id": "true", - "X-Schema-Type": "avro" - }, - "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:02:33 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": { - "id": "0e30eb5c747e496cbedd94918fe36fd6" - } - }, - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", - "RequestMethod": "POST", - "RequestHeaders": { - "Authorization": "Sanitized", - "Content-Length": "369", - "Content-Type": "application/json", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "9e692bad203bc270f771785f7ee81e0f", - "x-ms-return-client-request-id": "true", - "X-Schema-Type": "avro" - }, - "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:02:33 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": { - "id": "0e30eb5c747e496cbedd94918fe36fd6" - } - } - ], - "Variables": { - "RandomSeed": "832707302", - "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json deleted file mode 100644 index cbdda14f71d88..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaContentAsync.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "Entries": [ - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", - "RequestMethod": "PUT", - "RequestHeaders": { - "Authorization": "Sanitized", - "Content-Length": "369", - "Content-Type": "application/json", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "dbdc903e75e4d835f5c2b0d825d4952c", - "x-ms-return-client-request-id": "true", - "X-Schema-Type": "avro" - }, - "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:02:34 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": { - "id": "0e30eb5c747e496cbedd94918fe36fd6" - } - }, - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", - "RequestMethod": "POST", - "RequestHeaders": { - "Authorization": "Sanitized", - "Content-Length": "369", - "Content-Type": "application/json", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "f34efb219df07ec84fbf07079dbc1a65", - "x-ms-return-client-request-id": "true", - "X-Schema-Type": "avro" - }, - "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:02:34 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": { - "id": "0e30eb5c747e496cbedd94918fe36fd6" - } - } - ], - "Variables": { - "RandomSeed": "1001910995", - "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json deleted file mode 100644 index ff12639ba0f53..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaId.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "Entries": [ - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", - "RequestMethod": "PUT", - "RequestHeaders": { - "Authorization": "Sanitized", - "Content-Length": "369", - "Content-Type": "application/json", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "37c4dee38bfbbddaff13db42bcf62e30", - "x-ms-return-client-request-id": "true", - "X-Schema-Type": "avro" - }, - "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:13:03 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": { - "id": "0e30eb5c747e496cbedd94918fe36fd6" - } - }, - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/getSchemaById/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "RequestMethod": "GET", - "RequestHeaders": { - "Authorization": "Sanitized", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "0f9628224eac8802528daf4c0e092689", - "x-ms-return-client-request-id": "true" - }, - "RequestBody": null, - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:13:03 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": "\u0022\\u000d\\u000a{\\u000d\\u000a \\\u0022type\\\u0022 : \\\u0022record\\\u0022,\\u000d\\u000a \\\u0022namespace\\\u0022 : \\\u0022TestSchema\\\u0022,\\u000d\\u000a \\\u0022name\\\u0022 : \\\u0022Employee\\\u0022,\\u000d\\u000a \\\u0022fields\\\u0022 : [\\u000d\\u000a { \\\u0022name\\\u0022 : \\\u0022Name\\\u0022 , \\\u0022type\\\u0022 : \\\u0022string\\\u0022 },\\u000d\\u000a { \\\u0022name\\\u0022 : \\\u0022Age\\\u0022, \\\u0022type\\\u0022 : \\\u0022int\\\u0022 }\\u000d\\u000a ]\\u000d\\u000a}\u0022" - } - ], - "Variables": { - "RandomSeed": "1249738123", - "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json deleted file mode 100644 index a228505c9807d..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanGetSchemaViaIdAsync.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "Entries": [ - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", - "RequestMethod": "PUT", - "RequestHeaders": { - "Authorization": "Sanitized", - "Content-Length": "369", - "Content-Type": "application/json", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "53a34a59141d18e9bc7b41ec2c64192a", - "x-ms-return-client-request-id": "true", - "X-Schema-Type": "avro" - }, - "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:13:05 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": { - "id": "0e30eb5c747e496cbedd94918fe36fd6" - } - }, - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/getSchemaById/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "RequestMethod": "GET", - "RequestHeaders": { - "Authorization": "Sanitized", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200813.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "e7b659080697259a761a460a935b3d23", - "x-ms-return-client-request-id": "true" - }, - "RequestBody": null, - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 22:13:05 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": "\u0022\\u000d\\u000a{\\u000d\\u000a \\\u0022type\\\u0022 : \\\u0022record\\\u0022,\\u000d\\u000a \\\u0022namespace\\\u0022 : \\\u0022TestSchema\\\u0022,\\u000d\\u000a \\\u0022name\\\u0022 : \\\u0022Employee\\\u0022,\\u000d\\u000a \\\u0022fields\\\u0022 : [\\u000d\\u000a { \\\u0022name\\\u0022 : \\\u0022Name\\\u0022 , \\\u0022type\\\u0022 : \\\u0022string\\\u0022 },\\u000d\\u000a { \\\u0022name\\\u0022 : \\\u0022Age\\\u0022, \\\u0022type\\\u0022 : \\\u0022int\\\u0022 }\\u000d\\u000a ]\\u000d\\u000a}\u0022" - } - ], - "Variables": { - "RandomSeed": "1336917832", - "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchema.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchema.json deleted file mode 100644 index 13ec03a47cfe2..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchema.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "Entries": [ - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", - "RequestMethod": "PUT", - "RequestHeaders": { - "Authorization": "Sanitized", - "Content-Length": "369", - "Content-Type": "application/json", - "Request-Id": "|fae22771-4509d094581d363d.", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200812.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "06149688c0d107fba9beaa6650213cc6", - "x-ms-return-client-request-id": "true", - "X-Schema-Type": "avro" - }, - "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 00:24:21 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": { - "id": "0e30eb5c747e496cbedd94918fe36fd6" - } - } - ], - "Variables": { - "RandomSeed": "2024185609", - "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchemaAsync.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchemaAsync.json deleted file mode 100644 index 7f58562b02554..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SessionRecords/SchemaRegistryClientLiveTest/CanRegisterSchemaAsync.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "Entries": [ - { - "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1?api-version=2017-04", - "RequestMethod": "PUT", - "RequestHeaders": { - "Authorization": "Sanitized", - "Content-Length": "369", - "Content-Type": "application/json", - "Request-Id": "|fae22773-4509d094581d363d.", - "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200812.1", - "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" - ], - "x-ms-client-request-id": "10d841304c76af44a9857366d3cdcece", - "x-ms-return-client-request-id": "true", - "X-Schema-Type": "avro" - }, - "RequestBody": "\r\n{\r\n \u0022type\u0022 : \u0022record\u0022,\r\n \u0022namespace\u0022 : \u0022TestSchema\u0022,\r\n \u0022name\u0022 : \u0022Employee\u0022,\r\n \u0022fields\u0022 : [\r\n { \u0022name\u0022 : \u0022Name\u0022 , \u0022type\u0022 : \u0022string\u0022 },\r\n { \u0022name\u0022 : \u0022Age\u0022, \u0022type\u0022 : \u0022int\u0022 }\r\n ]\r\n}", - "StatusCode": 200, - "ResponseHeaders": { - "Content-Type": "application/json", - "Date": "Thu, 13 Aug 2020 00:24:41 GMT", - "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/test1/versions/1?api-version=2017-04", - "Server": "Microsoft-HTTPAPI/2.0", - "Strict-Transport-Security": "max-age=31536000", - "Transfer-Encoding": "chunked", - "X-Schema-Id": "0e30eb5c747e496cbedd94918fe36fd6", - "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/0e30eb5c747e496cbedd94918fe36fd6?api-version=2017-04", - "X-Schema-Type": "Avro", - "X-Schema-Version": "1", - "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/test1/versions?api-version=2017-04" - }, - "ResponseBody": { - "id": "0e30eb5c747e496cbedd94918fe36fd6" - } - } - ], - "Variables": { - "RandomSeed": "341051900", - "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" - } -} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj deleted file mode 100644 index f82e6576ce6eb..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/ApacheAvroTestTool.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - - - - - - - - - - Always - - - Always - - - - diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avsc b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avsc deleted file mode 100644 index 00d7101aeac62..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Example.avsc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type" : "record", - "namespace" : "TestSchema", - "name" : "Employee", - "fields" : [ - { "name" : "Name" , "type" : "string" }, - { "name" : "Age", "type" : "int" } - ] -} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs deleted file mode 100644 index 452264ac15617..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Program.cs +++ /dev/null @@ -1,203 +0,0 @@ -using System; -using System.IO; -using System.Reflection; -using System.Threading; -using Avro; -using Avro.Generic; -using Avro.IO; -using Avro.Specific; -using Azure.Data.SchemaRegistry; -using Azure.Data.SchemaRegistry.Avro; -using Azure.Data.SchemaRegistry.Models; -using Azure.Identity; -using TestSchema; - -namespace ApacheAvroTestTool -{ - class Program - { - - static void Main(string[] args) - { - //Testing(); - var employee = new Employee { Age = 42, Name = "Caketown" }; - var schemaName = "test1"; - var groupName = "miyanni_srgroup"; - var schemaType = SerializationType.Avro; - var endpoint = ""; - var creds = new ClientSecretCredential( - "", - "", - "" - ); - var client = new SchemaRegistryClient(endpoint, creds); - var memoryStream = new MemoryStream(); - - var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); - serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); - - var deserializedObject = serializer.Deserialize(memoryStream, typeof(Employee), CancellationToken.None); - var readEmployee = deserializedObject as Employee; - Console.WriteLine(readEmployee?.Name); - Console.WriteLine(readEmployee?.Age); - - - - - var record = new GenericRecord((RecordSchema)Employee._SCHEMA); - record.Add("Name", "Yanni"); - record.Add("Age", 33); - - var currentDirectory = Directory.GetCurrentDirectory(); - var employeePath = Path.Combine(currentDirectory, "GenericEmployee.avro"); - var writeFileStream = new FileStream(employeePath, FileMode.Create); - - //memoryStream = new MemoryStream(); - serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); - serializer.Serialize(writeFileStream, record, typeof(GenericRecord), CancellationToken.None); - writeFileStream.Close(); - - - var readFileStream = new FileStream(employeePath, FileMode.Open); - deserializedObject = serializer.Deserialize(readFileStream, typeof(GenericRecord), CancellationToken.None); - var readRecord = deserializedObject as GenericRecord; - Console.WriteLine(readRecord?.GetValue(0)); - Console.WriteLine(readRecord?.GetValue(1)); - - readFileStream.Close(); - - //int - //serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); - //serializer.Serialize(memoryStream, 42, typeof(int), CancellationToken.None); - - //deserializedObject = serializer.Deserialize(memoryStream, typeof(int), CancellationToken.None); - //var readInt = (int)deserializedObject; - //Console.WriteLine(readInt); - } - - private static void Testing() - { - var currentDirectory = Directory.GetCurrentDirectory(); - var examplePath = Path.Combine(currentDirectory, "Example.avsc"); - var schema = Schema.Parse(File.ReadAllText(examplePath)); - var codeGen = new CodeGen(); - codeGen.AddSchema(schema); - var compileUnit = codeGen.GenerateCode(); - //compileUnit. ?????????????? - codeGen.WriteTypes(currentDirectory); - - var employeePath = Path.Combine(currentDirectory, "Employee.avro"); - var employee = new Employee { Age = 42, Name = "Caketown" }; - var writeFileStream = new FileStream(employeePath, FileMode.Create); - - - ////var writerType = ; - ////https://stackoverflow.com/a/1151470/294804 - //var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(typeof(Employee)); - ////https://stackoverflow.com/a/2451341/294804 - //dynamic writer = Activator.CreateInstance(datumWriterType, schema); - - - ////https://stackoverflow.com/a/4667999/294804 - //var writerType = typeof(DataFileWriter<>).MakeGenericType(typeof(Employee)); - ////var openWriterMethod = writerType.GetMethod("OpenWriter", BindingFlags.Public | BindingFlags.Static); - //var datumBaseType = typeof(DatumWriter<>).MakeGenericType(typeof(Employee)); - //var openWriterMethod = writerType.GetMethod("OpenWriter", new[] { datumBaseType, typeof(Stream) }); - //dynamic fileWriter = openWriterMethod?.Invoke(null, new[] { writer, writeFileStream }); - - //var writer = new SpecificDatumWriter(schema); - //var fileWriter = DataFileWriter.OpenWriter(writer, employeePath); - - - - - //fileWriter?.Append(employee); - //fileWriter?.Close(); - - - var employeeType = typeof(Employee); - - var isSpecific = typeof(ISpecificRecord).IsAssignableFrom(employeeType); - - - - //https://stackoverflow.com/a/5898469/294804 - var schemaField = employeeType.GetField("_SCHEMA", BindingFlags.Public | BindingFlags.Static); - var reflectionSchema = schemaField?.GetValue(null) as Schema; - - - //var writer = new SpecificDatumWriter(schema); - //https://stackoverflow.com/a/1151470/294804 - var datumWriterType = typeof(SpecificDatumWriter<>).MakeGenericType(employeeType); - //https://stackoverflow.com/a/2451341/294804 - dynamic writer = Activator.CreateInstance(datumWriterType, reflectionSchema); - var binaryEncoder = new BinaryEncoder(writeFileStream); - - writer?.Write(employee, binaryEncoder); - binaryEncoder.Flush(); - - - - - writeFileStream.Close(); - - - - - var readFileStream = new FileStream(employeePath, FileMode.Open); - - - //var reader = new SpecificDatumReader(schema, schema); - //var fileReader = DataFileReader.OpenReader(readFileStream, schema, (ws, rs) => reader); - - //var fileReader = DataFileReader.OpenReader(readFileStream); - - - ////https://stackoverflow.com/a/4667999/294804 - //var readerType = typeof(DataFileReader<>).MakeGenericType(typeof(Employee)); - //var openReaderMethod = readerType.GetMethod("OpenReader", new[] { typeof(Stream) }); - //dynamic fileReader = openReaderMethod?.Invoke(null, new object[] { readFileStream }); - - - - - // Not the right solution. Reads schema on the avro data. - //var readSchema = fileReader?.GetSchema() as Schema; - - - - - - var binaryDecoder = new BinaryDecoder(readFileStream); - - - //var reader = new SpecificDatumReader(schema, schema); - //https://stackoverflow.com/a/1151470/294804 - var datumReaderType = typeof(SpecificDatumReader<>).MakeGenericType(employeeType); - //https://stackoverflow.com/a/2451341/294804 - dynamic reader = Activator.CreateInstance(datumReaderType, reflectionSchema, reflectionSchema); - - var readEmployee = reader?.Read(null, binaryDecoder); - - - //Employee readEmployee = null; - //while (fileReader?.HasNext()) - //{ - // readEmployee = fileReader.Next() as Employee; - // break; - //} - //Employee readEmployee = fileReader?.NextEntries.First(); - - - Console.WriteLine(readEmployee?.Name); - Console.WriteLine(readEmployee?.Age); - - //fileReader?.Dispose(); - readFileStream.Close(); - - - //var classThing = new DotnetClass(typeof(Employee)) - //Schema.p - } - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializer.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializer.cs similarity index 94% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializer.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializer.cs index 17890ea2a5f21..663dc36e050d1 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializer.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializer.cs @@ -13,6 +13,7 @@ using Avro.Generic; using Avro.IO; using Avro.Specific; +using Azure.Core; using Azure.Core.Serialization; using Azure.Data.SchemaRegistry.Models; @@ -97,10 +98,14 @@ private static DatumWriter GetWriterAndSchema(object value, SupportedTyp /// public override void Serialize(Stream stream, object value, Type inputType, CancellationToken cancellationToken) { - //TODO: Null check input + Argument.AssertNotNull(stream, nameof(stream)); + Argument.AssertNotNull(value, nameof(value)); + Argument.AssertNotNull(inputType, nameof(inputType)); + var supportedType = GetSupportedTypeOrThrow(inputType); var writer = GetWriterAndSchema(value, supportedType, out var schema); var schemaId = GetSchemaId(schema, cancellationToken); + var binaryEncoder = new BinaryEncoder(stream); stream.Write(s_emptyRecordFormatIndicator, 0, 4); stream.Write(Encoding.UTF8.GetBytes(schemaId), 0, 32); @@ -111,10 +116,14 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc /// public override async ValueTask SerializeAsync(Stream stream, object value, Type inputType, CancellationToken cancellationToken) { - //TODO: Null check input + Argument.AssertNotNull(stream, nameof(stream)); + Argument.AssertNotNull(value, nameof(value)); + Argument.AssertNotNull(inputType, nameof(inputType)); + var supportedType = GetSupportedTypeOrThrow(inputType); var writer = GetWriterAndSchema(value, supportedType, out var schema); var schemaId = await GetSchemaIdAsync(schema, cancellationToken).ConfigureAwait(false); + var binaryEncoder = new BinaryEncoder(stream); await stream.WriteAsync(s_emptyRecordFormatIndicator, 0, 4, cancellationToken).ConfigureAwait(false); await stream.WriteAsync(Encoding.UTF8.GetBytes(schemaId), 0, 32, cancellationToken).ConfigureAwait(false); @@ -198,14 +207,16 @@ private async Task GetSchemaAsync(ReadOnlyMemory message, Cancella /// public override object Deserialize(Stream stream, Type returnType, CancellationToken cancellationToken) { - //TODO: Null check input + Argument.AssertNotNull(stream, nameof(stream)); + Argument.AssertNotNull(returnType, nameof(returnType)); + var supportedType = GetSupportedTypeOrThrow(returnType); var message = CopyToReadOnlyMemory(stream); ValidateRecordFormatIdentifier(message); var schema = GetSchema(message, cancellationToken); using var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); - var binaryDecoder = new BinaryDecoder(valueStream); + var binaryDecoder = new BinaryDecoder(valueStream); var reader = GetReader(schema, supportedType); return reader.Read(reuse: null, binaryDecoder); } @@ -213,14 +224,16 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT /// public override async ValueTask DeserializeAsync(Stream stream, Type returnType, CancellationToken cancellationToken) { - //TODO: Null check input + Argument.AssertNotNull(stream, nameof(stream)); + Argument.AssertNotNull(returnType, nameof(returnType)); + var supportedType = GetSupportedTypeOrThrow(returnType); var message = CopyToReadOnlyMemory(stream); ValidateRecordFormatIdentifier(message); var schema = await GetSchemaAsync(message, cancellationToken).ConfigureAwait(false); using var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); - var binaryDecoder = new BinaryDecoder(valueStream); + var binaryDecoder = new BinaryDecoder(valueStream); var reader = GetReader(schema, supportedType); return reader.Read(reuse: null, binaryDecoder); } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializerOptions.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializerOptions.cs similarity index 100% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/src/SchemaRegistryAvroObjectSerializerOptions.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializerOptions.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj index 9b6bd4f268ebd..6dc3b4ee046a2 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj @@ -22,6 +22,7 @@ + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs index 53bcf2b1a6af6..e095e2279037f 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs @@ -23,7 +23,7 @@ internal SchemaProperties(string content, string location, SerializationType xSc Name = slashSplit[2]; GroupName = slashSplit[0]; Type = xSchemaType; - Version = xSchemaVersion; + Version = xSchemaVersion ?? 0; } /// @@ -54,6 +54,6 @@ internal SchemaProperties(string content, string location, SerializationType xSc /// /// Version of the schema. /// - internal int? Version { get; } + internal int Version { get; } } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index 712228d402187..45db8c741d674 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -16,7 +16,6 @@ namespace Azure.Data.SchemaRegistry public class SchemaRegistryClient { private readonly ClientDiagnostics _clientDiagnostics; - private readonly HttpPipeline _pipeline; internal SchemaRestClient RestClient { get; } /// @@ -32,25 +31,25 @@ public class SchemaRegistryClient public SchemaRegistryClient(string endpoint, TokenCredential credential, SchemaRegistryClientOptions options) : this( new ClientDiagnostics(options), HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, "https://eventhubs.azure.net/.default")), - endpoint) + endpoint, + options.Version) { } - /// Initializes a new instance of SchemaRegistryClient for mocking. + /// Initializes a new instance of for mocking. protected SchemaRegistryClient() { } - /// Initializes a new instance of SchemaRegistryClient. + /// Initializes a new instance of . /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. - /// The vault name, for example https://myvault.vault.azure.net. - internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) + /// The endpoint URI. For example, myschemaregistry.servicebus.windows.net. + /// The API version of the service. + internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, string apiVersion) { - //TODO: Hardcoded API version. - RestClient = new SchemaRestClient(clientDiagnostics, pipeline, endpoint, "2017-04"); + RestClient = new SchemaRestClient(clientDiagnostics, pipeline, endpoint, apiVersion); _clientDiagnostics = clientDiagnostics; - _pipeline = pipeline; } /// diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs index 02e83fb9e05b1..e8e4b3043c0bb 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs @@ -16,11 +16,11 @@ public class SchemaRegistryClientOptions : ClientOptions /// /// Initializes a new instance of the . /// - public SchemaRegistryClientOptions(ServiceVersion version = ServiceVersion.V1_0) + public SchemaRegistryClientOptions(ServiceVersion version = ServiceVersion.V2017_04) { Version = version switch { - ServiceVersion.V1_0 => "1.0", + ServiceVersion.V2017_04 => "2017-04", _ => throw new ArgumentException($"The service version {version} is not supported by this library.", nameof(version)) }; } @@ -31,10 +31,10 @@ public SchemaRegistryClientOptions(ServiceVersion version = ServiceVersion.V1_0) public enum ServiceVersion { /// - /// The 1.0 of the Schema Registry service. + /// Version 2017-04 of the Schema Registry service. /// #pragma warning disable CA1707 // Remove the underscores from member name - V1_0 = 1 + V2017_04 #pragma warning restore } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Employee.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Employee.cs similarity index 100% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tool/Employee.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Employee.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientLiveTest.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs similarity index 64% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientLiveTest.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs index 2189dadcfdeef..85bf13a14983c 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry.Avro/tests/SchemaRegistryClientLiveTest.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs @@ -5,21 +5,21 @@ namespace Azure.Data.SchemaRegistry.Tests { - public class SchemaRegistryClientLiveTest : RecordedTestBase + public class SchemaRegistryAvroObjectSerializerLiveTest : RecordedTestBase { - public SchemaRegistryClientLiveTest(bool isAsync) : base(isAsync) + public SchemaRegistryAvroObjectSerializerLiveTest(bool isAsync) : base(isAsync) { TestDiagnostics = false; } - // private SchemaRegistryClient CreateClient() - // { - // return InstrumentClient(new SchemaRegistryClient( - // TestEnvironment.SchemaRegistryUri, - // TestEnvironment.Credential, - // Recording.InstrumentClientOptions(new SchemaRegistryClientOptions()) - // )); - // } + private SchemaRegistryClient CreateClient() + { + return InstrumentClient(new SchemaRegistryClient( + TestEnvironment.SchemaRegistryUri, + TestEnvironment.Credential, + Recording.InstrumentClientOptions(new SchemaRegistryClientOptions()) + )); + } // [Test] // public async Task CanRegisterSchema() @@ -39,19 +39,16 @@ public SchemaRegistryClientLiveTest(bool isAsync) : base(isAsync) // ] //}"; - // var schemaProperties = await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); + // var schemaProperties = await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); // Assert.IsNotNull(schemaProperties.Value); - // Assert.AreEqual(schemaName, schemaProperties.Value.Name); - // Assert.AreEqual(groupName, schemaProperties.Value.GroupName); - // Assert.AreEqual(schemaType, schemaProperties.Value.Type); - // Assert.IsNotNull(schemaProperties.Value.Version); // Assert.IsNotNull(schemaProperties.Value.Id); // Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); + // Assert.AreEqual(schema, schemaProperties.Value.Content); // } // [Test] - // public async Task CanGetSchemaViaContent() + // public async Task CanGetSchemaId() // { // var client = CreateClient(); // var schemaName = "test1"; @@ -68,19 +65,16 @@ public SchemaRegistryClientLiveTest(bool isAsync) : base(isAsync) // ] //}"; - // await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); - // var schemaProperties = await client.GetSchemaAsync(groupName, schemaName, schema, schemaType); + // await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); + // var schemaProperties = await client.GetSchemaIdAsync(groupName, schemaName, schemaType, schema); // Assert.IsNotNull(schemaProperties.Value); - // Assert.AreEqual(schemaName, schemaProperties.Value.Name); - // Assert.AreEqual(groupName, schemaProperties.Value.GroupName); - // Assert.AreEqual(schemaType, schemaProperties.Value.Type); - // Assert.IsNotNull(schemaProperties.Value.Version); // Assert.IsNotNull(schemaProperties.Value.Id); // Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); + // Assert.AreEqual(schema, schemaProperties.Value.Content); // } // [Test] - // public async Task CanGetSchemaViaId() + // public async Task CanGetSchema() // { // var client = CreateClient(); // var schemaName = "test1"; @@ -97,18 +91,15 @@ public SchemaRegistryClientLiveTest(bool isAsync) : base(isAsync) // ] //}"; - // var registerProperties = await client.RegisterSchemaAsync(groupName, schemaName, schema, schemaType); + // var registerProperties = await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); // Assert.IsNotNull(registerProperties.Value.Id); // Assert.IsTrue(Guid.TryParse(registerProperties.Value.Id, out Guid _)); // var schemaProperties = await client.GetSchemaAsync(registerProperties.Value.Id); // Assert.IsNotNull(schemaProperties.Value); - // Assert.AreEqual(schemaName, schemaProperties.Value.Name); - // Assert.AreEqual(groupName, schemaProperties.Value.GroupName); - // Assert.AreEqual(schemaType, schemaProperties.Value.Type); - // Assert.IsNotNull(schemaProperties.Value.Version); // Assert.IsNotNull(schemaProperties.Value.Id); // Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); + // Assert.AreEqual(schema, schemaProperties.Value.Content); // } } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs index 83d33513cfd21..b9c669729fe9f 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs @@ -45,10 +45,6 @@ public async Task CanRegisterSchema() var schemaProperties = await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); Assert.IsNotNull(schemaProperties.Value); - //Assert.AreEqual(schemaName, schemaProperties.Value.Name); - //Assert.AreEqual(groupName, schemaProperties.Value.GroupName); - //Assert.AreEqual(schemaType, schemaProperties.Value.Type); - //Assert.IsNotNull(schemaProperties.Value.Version); Assert.IsNotNull(schemaProperties.Value.Id); Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); Assert.AreEqual(schema, schemaProperties.Value.Content); @@ -76,10 +72,6 @@ public async Task CanGetSchemaId() await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); var schemaProperties = await client.GetSchemaIdAsync(groupName, schemaName, schemaType, schema); Assert.IsNotNull(schemaProperties.Value); - //Assert.AreEqual(schemaName, schemaProperties.Value.Name); - //Assert.AreEqual(groupName, schemaProperties.Value.GroupName); - //Assert.AreEqual(schemaType, schemaProperties.Value.Type); - //Assert.IsNotNull(schemaProperties.Value.Version); Assert.IsNotNull(schemaProperties.Value.Id); Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); Assert.AreEqual(schema, schemaProperties.Value.Content); @@ -109,10 +101,6 @@ public async Task CanGetSchema() var schemaProperties = await client.GetSchemaAsync(registerProperties.Value.Id); Assert.IsNotNull(schemaProperties.Value); - //Assert.AreEqual(schemaName, schemaProperties.Value.Name); - //Assert.AreEqual(groupName, schemaProperties.Value.GroupName); - //Assert.AreEqual(schemaType, schemaProperties.Value.Type); - //Assert.IsNotNull(schemaProperties.Value.Version); Assert.IsNotNull(schemaProperties.Value.Id); Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); Assert.AreEqual(schema, schemaProperties.Value.Content); From 52220c923460c7188a8e8fa61ba76a42c514c7a4 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 2 Sep 2020 17:33:23 -0700 Subject: [PATCH 20/45] Added 1 test for the serializer. --- .../tests/{ => Models}/Employee.cs | 0 ...emaRegistryAvroObjectSerializerLiveTest.cs | 103 ++++-------------- .../CanSerializeAndDeserialize.json | 73 +++++++++++++ .../CanSerializeAndDeserializeAsync.json | 73 +++++++++++++ 4 files changed, 169 insertions(+), 80 deletions(-) rename sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/{ => Models}/Employee.cs (100%) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Employee.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Models/Employee.cs similarity index 100% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Employee.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Models/Employee.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs index 85bf13a14983c..050c4fd1540cb 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs @@ -1,7 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System.IO; +using System.Threading; +using System.Threading.Tasks; using Azure.Core.TestFramework; +using Azure.Data.SchemaRegistry.Avro; +using NUnit.Framework; +using TestSchema; namespace Azure.Data.SchemaRegistry.Tests { @@ -21,85 +27,22 @@ private SchemaRegistryClient CreateClient() )); } - // [Test] - // public async Task CanRegisterSchema() - // { - // var client = CreateClient(); - // var schemaName = "test1"; - // var groupName = "miyanni_srgroup"; - // var schemaType = SerializationType.Avro; - // var schema = @" - //{ - // ""type"" : ""record"", - // ""namespace"" : ""TestSchema"", - // ""name"" : ""Employee"", - // ""fields"" : [ - // { ""name"" : ""Name"" , ""type"" : ""string"" }, - // { ""name"" : ""Age"", ""type"" : ""int"" } - // ] - //}"; - - // var schemaProperties = await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); - // Assert.IsNotNull(schemaProperties.Value); - // Assert.IsNotNull(schemaProperties.Value.Id); - // Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); - // Assert.AreEqual(schema, schemaProperties.Value.Content); - // } - - - // [Test] - // public async Task CanGetSchemaId() - // { - // var client = CreateClient(); - // var schemaName = "test1"; - // var groupName = "miyanni_srgroup"; - // var schemaType = SerializationType.Avro; - // var schema = @" - //{ - // ""type"" : ""record"", - // ""namespace"" : ""TestSchema"", - // ""name"" : ""Employee"", - // ""fields"" : [ - // { ""name"" : ""Name"" , ""type"" : ""string"" }, - // { ""name"" : ""Age"", ""type"" : ""int"" } - // ] - //}"; - - // await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); - // var schemaProperties = await client.GetSchemaIdAsync(groupName, schemaName, schemaType, schema); - // Assert.IsNotNull(schemaProperties.Value); - // Assert.IsNotNull(schemaProperties.Value.Id); - // Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); - // Assert.AreEqual(schema, schemaProperties.Value.Content); - // } - - // [Test] - // public async Task CanGetSchema() - // { - // var client = CreateClient(); - // var schemaName = "test1"; - // var groupName = "miyanni_srgroup"; - // var schemaType = SerializationType.Avro; - // var schema = @" - //{ - // ""type"" : ""record"", - // ""namespace"" : ""TestSchema"", - // ""name"" : ""Employee"", - // ""fields"" : [ - // { ""name"" : ""Name"" , ""type"" : ""string"" }, - // { ""name"" : ""Age"", ""type"" : ""int"" } - // ] - //}"; - - // var registerProperties = await client.RegisterSchemaAsync(groupName, schemaName, schemaType, schema); - // Assert.IsNotNull(registerProperties.Value.Id); - // Assert.IsTrue(Guid.TryParse(registerProperties.Value.Id, out Guid _)); - - // var schemaProperties = await client.GetSchemaAsync(registerProperties.Value.Id); - // Assert.IsNotNull(schemaProperties.Value); - // Assert.IsNotNull(schemaProperties.Value.Id); - // Assert.IsTrue(Guid.TryParse(schemaProperties.Value.Id, out Guid _)); - // Assert.AreEqual(schema, schemaProperties.Value.Content); - // } + [Test] + public async Task CanSerializeAndDeserialize() + { + var client = CreateClient(); + var groupName = "miyanni_srgroup"; + var employee = new Employee { Age = 42, Name = "Caketown" }; + + var memoryStream = new MemoryStream(); + var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); + await serializer.SerializeAsync(memoryStream, employee, typeof(Employee), CancellationToken.None); + + var deserializedObject = await serializer.DeserializeAsync(memoryStream, typeof(Employee), CancellationToken.None); + var readEmployee = deserializedObject as Employee; + Assert.IsNotNull(readEmployee); + Assert.AreEqual("Caketown", readEmployee.Name); + Assert.AreEqual(42, readEmployee.Age); + } } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json new file mode 100644 index 0000000000000..8cf679c119013 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json @@ -0,0 +1,73 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "Content-Length": "283", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200902.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "868a705e78e1eacc39ee20f0603590e1", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "{\u0022type\u0022:\u0022record\u0022,\u0022name\u0022:\u0022Employee\u0022,\u0022namespace\u0022:\u0022TestSchema\u0022,\u0022fields\u0022:[{\u0022name\u0022:\u0022Name\u0022,\u0022type\u0022:\u0022string\u0022},{\u0022name\u0022:\u0022Age\u0022,\u0022type\u0022:\u0022int\u0022}]}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 03 Sep 2020 00:25:18 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "34fa96c2ac67489da0df6d4a245265a7", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "34fa96c2ac67489da0df6d4a245265a7" + } + }, + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/getSchemaById/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200902.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "fce63c5a3b2209ffbf3241fcd47809a7", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 03 Sep 2020 00:25:18 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "34fa96c2ac67489da0df6d4a245265a7", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions?api-version=2017-04" + }, + "ResponseBody": "{\u0022type\u0022:\u0022record\u0022,\u0022name\u0022:\u0022Employee\u0022,\u0022namespace\u0022:\u0022TestSchema\u0022,\u0022fields\u0022:[{\u0022name\u0022:\u0022Name\u0022,\u0022type\u0022:\u0022string\u0022},{\u0022name\u0022:\u0022Age\u0022,\u0022type\u0022:\u0022int\u0022}]}" + } + ], + "Variables": { + "RandomSeed": "720748394", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json new file mode 100644 index 0000000000000..0c389ac96e11c --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json @@ -0,0 +1,73 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "Content-Length": "283", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200902.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "9194a80ecb3e28d6d988eee20cb5ed95", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "{\u0022type\u0022:\u0022record\u0022,\u0022name\u0022:\u0022Employee\u0022,\u0022namespace\u0022:\u0022TestSchema\u0022,\u0022fields\u0022:[{\u0022name\u0022:\u0022Name\u0022,\u0022type\u0022:\u0022string\u0022},{\u0022name\u0022:\u0022Age\u0022,\u0022type\u0022:\u0022int\u0022}]}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 03 Sep 2020 00:25:19 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "34fa96c2ac67489da0df6d4a245265a7", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "34fa96c2ac67489da0df6d4a245265a7" + } + }, + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/getSchemaById/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200902.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "bbd7ee0ffba0cfc5c3b161ee35b7e4ec", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Thu, 03 Sep 2020 00:25:19 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "34fa96c2ac67489da0df6d4a245265a7", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions?api-version=2017-04" + }, + "ResponseBody": "{\u0022type\u0022:\u0022record\u0022,\u0022name\u0022:\u0022Employee\u0022,\u0022namespace\u0022:\u0022TestSchema\u0022,\u0022fields\u0022:[{\u0022name\u0022:\u0022Name\u0022,\u0022type\u0022:\u0022string\u0022},{\u0022name\u0022:\u0022Age\u0022,\u0022type\u0022:\u0022int\u0022}]}" + } + ], + "Variables": { + "RandomSeed": "1605448636", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file From 817f11d01a426ef4f1dc2bcf3779f61923eb34ef Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 2 Sep 2020 17:46:20 -0700 Subject: [PATCH 21/45] Update api. --- ...zure.Data.SchemaRegistry.netstandard2.0.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs index 7b654694138b4..0df5ded0e3832 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs @@ -20,13 +20,29 @@ public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credenti } public partial class SchemaRegistryClientOptions : Azure.Core.ClientOptions { - public SchemaRegistryClientOptions(Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion version = Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion.V1_0) { } + public SchemaRegistryClientOptions(Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion version = Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion.V2017_04) { } public enum ServiceVersion { - V1_0 = 1, + V2017_04 = 0, } } } +namespace Azure.Data.SchemaRegistry.Avro +{ + public partial class SchemaRegistryAvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer + { + public SchemaRegistryAvroObjectSerializer(Azure.Data.SchemaRegistry.SchemaRegistryClient client, string groupName, Azure.Data.SchemaRegistry.Avro.SchemaRegistryAvroObjectSerializerOptions options = null) { } + public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } + public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } + } + public partial class SchemaRegistryAvroObjectSerializerOptions + { + public SchemaRegistryAvroObjectSerializerOptions() { } + public bool AutoRegisterSchemas { get { throw null; } set { } } + } +} namespace Azure.Data.SchemaRegistry.Models { [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] From b61cd0e04558c83a0583ec6ca395864c2664b9f4 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Thu, 3 Sep 2020 16:20:44 -0700 Subject: [PATCH 22/45] Added back the separate solution. Named it appropriately. --- ...hemaRegistryAvroObjectSerializerOptions.cs | 17 --- .../src/Azure.Data.SchemaRegistry.csproj | 3 +- .../CHANGELOG.md | 4 + .../Directory.Build.props | 7 ++ ...t.Azure.Data.SchemaRegistry.ApacheAvro.sln | 43 ++++++++ .../README.md | 104 ++++++++++++++++++ ...chemaRegistry.ApacheAvro.netstandard2.0.cs | 16 +++ ...zure.Data.SchemaRegistry.ApacheAvro.csproj | 28 +++++ .../SchemaRegistryAvroObjectSerializer.cs | 19 ++-- ...hemaRegistryAvroObjectSerializerOptions.cs | 19 ++++ ...ata.SchemaRegistry.ApacheAvro.Tests.csproj | 26 +++++ .../tests/Models/Employee.cs | 0 .../SchemaRegistryClientSamples.HelloWorld.cs | 25 +++++ ...emaRegistryAvroObjectSerializerLiveTest.cs | 8 +- .../SchemaRegistryClientTestEnvironment.cs | 16 +++ .../CanSerializeAndDeserialize.json | 0 .../CanSerializeAndDeserializeAsync.json | 0 17 files changed, 304 insertions(+), 31 deletions(-) delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializerOptions.cs create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/Directory.Build.props create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.sln create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.csproj rename sdk/schemaregistry/{Azure.Data.SchemaRegistry/src/Avro => Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src}/SchemaRegistryAvroObjectSerializer.cs (92%) create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.csproj rename sdk/schemaregistry/{Azure.Data.SchemaRegistry => Microsoft.Azure.Data.SchemaRegistry.ApacheAvro}/tests/Models/Employee.cs (100%) create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs rename sdk/schemaregistry/{Azure.Data.SchemaRegistry => Microsoft.Azure.Data.SchemaRegistry.ApacheAvro}/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs (94%) create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryClientTestEnvironment.cs rename sdk/schemaregistry/{Azure.Data.SchemaRegistry => Microsoft.Azure.Data.SchemaRegistry.ApacheAvro}/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json (100%) rename sdk/schemaregistry/{Azure.Data.SchemaRegistry => Microsoft.Azure.Data.SchemaRegistry.ApacheAvro}/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json (100%) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializerOptions.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializerOptions.cs deleted file mode 100644 index 8c7dce1ebdbef..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializerOptions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Azure.Data.SchemaRegistry.Avro -{ - /// - /// Options for . - /// - public class SchemaRegistryAvroObjectSerializerOptions - { - /// - /// When true, automatically registers the provided schema with the SchemaRegistry during serialization. - /// When false, the schema is only acquired from the SchemaRegistry. - /// - public bool AutoRegisterSchemas { get; set; } - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj index 6dc3b4ee046a2..7045689ae6af5 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Azure.Data.SchemaRegistry.csproj @@ -2,14 +2,13 @@ Azure Schema Registry SDK Azure Schema Registry SDK - 1.0.0-preview.1 + 1.0.0-beta.1 Azure;Schema Registry;SchemaRegistry;.NET;Data;$(PackageCommonTags) $(RequiredTargetFrameworks) - diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md new file mode 100644 index 0000000000000..36ac757b66df9 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md @@ -0,0 +1,4 @@ +# Release History + +## 1.0.0-preview.1 (2020-08-05) +- Started changelog to capture release notes. \ No newline at end of file diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/Directory.Build.props b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/Directory.Build.props new file mode 100644 index 0000000000000..cd1ea9e1673a1 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/Directory.Build.props @@ -0,0 +1,7 @@ + + + true + + + + diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.sln b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.sln new file mode 100644 index 0000000000000..afe1df921037d --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Data.SchemaRegistry.ApacheAvro", "src\Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.csproj", "{E33D09D9-D809-472C-82E6-6A26BDB86FC2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests", "tests\Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.csproj", "{4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{8052009B-2126-44A3-88CD-4F3B17894C64}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry", "..\Azure.Data.SchemaRegistry\src\Azure.Data.SchemaRegistry.csproj", "{D451EE68-ADE4-4780-A002-2D13DEA888A2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.Build.0 = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.Build.0 = Release|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.Build.0 = Release|Any CPU + {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D451EE68-ADE4-4780-A002-2D13DEA888A2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md new file mode 100644 index 0000000000000..3411f7736223f --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md @@ -0,0 +1,104 @@ +# README.md template + +Use the guidelines in each section of this template to ensure consistency and readability of your README. The README resides in your package's GitHub repository at the root of its directory within the repo. It's also used as the package distribution page (NuGet, PyPi, npm, etc.) and as a Quickstart on docs.microsoft.com. See [README-EXAMPLE.md](README-EXAMPLE.md) for an example following this template. + +**Title**: The H1 of your README should be in the format: `# [Product Name] client library for [Language]` + +* All headings, including the H1, should use **sentence-style capitalization**. Refer to the [Microsoft Style Guide][style-guide-msft] and [Microsoft Cloud Style Guide][style-guide-cloud] for more information. +* Example: `# Azure Batch client library for Python` + +# Azure Template client library for .NET + +**Introduction**: The introduction appears directly under the title (H1) of your README. + +* **DO NOT** use an "Introduction" or "Overview" heading (H2) for this section. +* First sentence: **Describe the service** briefly. You can usually use the first line of the service's docs landing page for this (Example: [Cosmos DB docs landing page](https://docs.microsoft.com/azure/cosmos-db/)). +* Next, add a **bulleted list** of the **most common tasks** supported by the package or library, prefaced with "Use the client library for [Product Name] to:". Then, provide code snippets for these tasks in the [Examples](#examples) section later in the document. Keep the task list short but include those tasks most developers need to perform with your package. +* Include this single line of links targeting your product's content at the bottom of the introduction, making any adjustments as necessary (for example, NuGet instead of PyPi): + + [Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/azure-batch) | [Package (PyPi)](https://pypi.org/project/azure-batch/) | [API reference documentation](https://docs.microsoft.com/python/api/overview/azure/batch?view=azure-python) | [Product documentation](https://docs.microsoft.com/azure/batch/) + +> TIP: Your README should be as **brief** as possible but **no more brief** than necessary to get a developer new to Azure, the service, or the package up and running quickly. Keep it brief, but include everything a developer needs to make their first API call successfully. + +## Getting started + +This section should include everything a developer needs to do to install and create their first client connection *very quickly*. + +### Install the package + +First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `pip install package-name`, but should enable a developer to successfully install the package from NuGet, pip, npm, Maven, or even cloning a GitHub repository. + +### Prerequisites + +Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB: + +> You must have an [Azure subscription](https://azure.microsoft.com/free/), [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API), and [Python 3.6+](https://www.python.org/downloads/) to use this package. + +### Authenticate the client + +If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating. + +For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object. + +## Key concepts + +The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity. + +## Examples + +Include code snippets and short descriptions for each task you listed in the [Introduction](#introduction) (the bulleted list). Briefly explain each operation, but include enough clarity to explain complex or otherwise tricky operations. + +If possible, use the same example snippets that your in-code documentation uses. For example, use the snippets in your `examples.py` that Sphinx ingests via its [literalinclude](https://www.sphinx-doc.org/en/1.5/markup/code.html?highlight=code%20examples#includes) directive. The `examples.py` file containing the snippets should reside alongside your package's code, and should be tested in an automated fashion. + +Each example in the *Examples* section starts with an H3 that describes the example. At the top of this section, just under the *Examples* H2, add a bulleted list linking to each example H3. Each example should deep-link to the types and/or members used in the example. + +* [Create the thing](#create-the-thing) +* [Get the thing](#get-the-thing) +* [List the things](#list-the-things) + +### Create the thing + +Use the [create_thing](not-valid-link) method to create a Thing reference; this method does not make a network call. To persist the Thing in the service, call [Thing.save](not-valid-link). + +```Python +thing = client.create_thing(id, name) +thing.save() +``` + +### Get the thing + +The [get_thing](not-valid-link) method retrieves a Thing from the service. The `id` parameter is the unique ID of the Thing, not its "name" property. + +```C# Snippet:GetSecret +var client = new MiniSecretClient(new Uri(endpoint), new DefaultAzureCredential()); + +SecretBundle secret = client.GetSecret("TestSecret"); + +Console.WriteLine(secret.Value); +```Python +things = client.list_things() +``` + +## Troubleshooting + +Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery. + +Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API. + +If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code. + +## Next steps + +* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory. +* If appropriate, point users to other packages that might be useful. +* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for. + +## Contributing + +This is a template, but your SDK readme should include details on how to contribute code to the repo/package. + + +[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization +[style-guide-cloud]: https://worldready.cloudapp.net/Styleguide/Read?id=2696&topicid=25357 + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftemplate%2FAzure.Template%2FREADME.png) diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs new file mode 100644 index 0000000000000..a1bc05acd6767 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs @@ -0,0 +1,16 @@ +namespace Azure.Data.SchemaRegistry.Avro +{ + public partial class AvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer + { + public AvroObjectSerializer(Azure.Data.SchemaRegistry.SchemaRegistryClient client, string groupName, Azure.Data.SchemaRegistry.Avro.AvroObjectSerializerOptions options = null) { } + public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } + public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } + public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } + } + public partial class AvroObjectSerializerOptions + { + public AvroObjectSerializerOptions() { } + public bool AutoRegisterSchemas { get { throw null; } set { } } + } +} diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.csproj b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.csproj new file mode 100644 index 0000000000000..1b0d2d333c53f --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.csproj @@ -0,0 +1,28 @@ + + + Microsoft Azure Schema Registry Apache Avro SDK + Microsoft Azure Schema Registry Apache Avro SDK + 1.0.0-beta.1 + Azure;Schema Registry;SchemaRegistry;.NET;Data;Apache;Avro;$(PackageCommonTags) + $(RequiredTargetFrameworks) + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializer.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs similarity index 92% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializer.cs rename to sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs index 663dc36e050d1..d569077a7d8ed 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Avro/SchemaRegistryAvroObjectSerializer.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs @@ -1,6 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Avro; +using Avro.Generic; +using Avro.IO; +using Avro.Specific; +using Azure.Core; +using Azure.Core.Serialization; +using Azure.Data.SchemaRegistry; +using Azure.Data.SchemaRegistry.Models; using System; using System.Collections.Generic; using System.IO; @@ -9,15 +17,10 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using Avro; -using Avro.Generic; -using Avro.IO; -using Avro.Specific; -using Azure.Core; -using Azure.Core.Serialization; -using Azure.Data.SchemaRegistry.Models; -namespace Azure.Data.SchemaRegistry.Avro +#pragma warning disable AZC0001 // Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure +namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro +#pragma warning restore AZC0001 // Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure { /// /// A implementation that uses for SpecificRecord serialization/deserialization. diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs new file mode 100644 index 0000000000000..49e294da4440f --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma warning disable AZC0001 // Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure +namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro +#pragma warning restore AZC0001 // Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure +{ + /// + /// Options for . + /// + public class SchemaRegistryAvroObjectSerializerOptions + { + /// + /// When true, automatically registers the provided schema with the SchemaRegistry during serialization. + /// When false, the schema is only acquired from the SchemaRegistry. + /// + public bool AutoRegisterSchemas { get; set; } + } +} diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.csproj b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.csproj new file mode 100644 index 0000000000000..dd8c8f45a8073 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.csproj @@ -0,0 +1,26 @@ + + + $(RequiredTargetFrameworks) + + + TRACE + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Models/Employee.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Models/Employee.cs similarity index 100% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Models/Employee.cs rename to sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Models/Employee.cs diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs new file mode 100644 index 0000000000000..871969a77f9f3 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.Samples +{ + public class SchemaRegistryClientSamples : SamplesBase + { + [Test] + public void GettingASecret() + { + var endpoint = TestEnvironment.SchemaRegistryUri; + + #region Snippet:GetSecret + //var client = new SchemaRegistryClient(endpoint, new DefaultAzureCredential()); + + //SecretBundle secret = client.GetSecret("TestSecret"); + + //Console.WriteLine(secret.Value); + #endregion + } + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs similarity index 94% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs rename to sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs index 050c4fd1540cb..9ca005382f78b 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Azure.Core.TestFramework; +using Azure.Data.SchemaRegistry; +using NUnit.Framework; using System.IO; using System.Threading; using System.Threading.Tasks; -using Azure.Core.TestFramework; -using Azure.Data.SchemaRegistry.Avro; -using NUnit.Framework; using TestSchema; -namespace Azure.Data.SchemaRegistry.Tests +namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests { public class SchemaRegistryAvroObjectSerializerLiveTest : RecordedTestBase { diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryClientTestEnvironment.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryClientTestEnvironment.cs new file mode 100644 index 0000000000000..fe811ae8ca4fc --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryClientTestEnvironment.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; + +namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests +{ + public class SchemaRegistryClientTestEnvironment : TestEnvironment + { + public SchemaRegistryClientTestEnvironment() : base("schemaregistry") + { + } + + public string SchemaRegistryUri => GetRecordedVariable("SCHEMAREGISTRY_URL"); + } +} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json similarity index 100% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json rename to sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json similarity index 100% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json rename to sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json From 96887b698562b8a95173f8ecf3288842f42e2b5b Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Thu, 3 Sep 2020 17:04:16 -0700 Subject: [PATCH 23/45] Addressing some changes from API view comments. --- ...zure.Data.SchemaRegistry.netstandard2.0.cs | 41 +++++-------------- .../src/Generated/Models/SerializationType.cs | 2 +- .../src/SchemaProperties.cs | 20 ++------- .../src/SchemaRegistryClient.cs | 1 - .../src/SchemaRegistryClientOptions.cs | 2 +- .../src/SerializationType.cs | 15 +++++++ ...chemaRegistry.ApacheAvro.netstandard2.0.cs | 10 ++--- .../src/SchemaRegistryAvroObjectSerializer.cs | 8 ++-- 8 files changed, 40 insertions(+), 59 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SerializationType.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs index 0df5ded0e3832..d85702224c0d0 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/api/Azure.Data.SchemaRegistry.netstandard2.0.cs @@ -13,53 +13,34 @@ public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credenti public SchemaRegistryClient(string endpoint, Azure.Core.TokenCredential credential, Azure.Data.SchemaRegistry.SchemaRegistryClientOptions options) { } public virtual Azure.Response GetSchema(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSchemaAsync(string schemaId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response GetSchemaId(string groupName, string schemaName, Azure.Data.SchemaRegistry.Models.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> GetSchemaIdAsync(string groupName, string schemaName, Azure.Data.SchemaRegistry.Models.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RegisterSchema(string groupName, string schemaName, Azure.Data.SchemaRegistry.Models.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, Azure.Data.SchemaRegistry.Models.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetSchemaId(string groupName, string schemaName, Azure.Data.SchemaRegistry.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetSchemaIdAsync(string groupName, string schemaName, Azure.Data.SchemaRegistry.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RegisterSchema(string groupName, string schemaName, Azure.Data.SchemaRegistry.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RegisterSchemaAsync(string groupName, string schemaName, Azure.Data.SchemaRegistry.SerializationType serializationType, string schemaContent, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public partial class SchemaRegistryClientOptions : Azure.Core.ClientOptions { public SchemaRegistryClientOptions(Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion version = Azure.Data.SchemaRegistry.SchemaRegistryClientOptions.ServiceVersion.V2017_04) { } public enum ServiceVersion { - V2017_04 = 0, + V2017_04 = 1, } } -} -namespace Azure.Data.SchemaRegistry.Avro -{ - public partial class SchemaRegistryAvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer - { - public SchemaRegistryAvroObjectSerializer(Azure.Data.SchemaRegistry.SchemaRegistryClient client, string groupName, Azure.Data.SchemaRegistry.Avro.SchemaRegistryAvroObjectSerializerOptions options = null) { } - public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } - public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } - public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } - public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } - } - public partial class SchemaRegistryAvroObjectSerializerOptions - { - public SchemaRegistryAvroObjectSerializerOptions() { } - public bool AutoRegisterSchemas { get { throw null; } set { } } - } -} -namespace Azure.Data.SchemaRegistry.Models -{ [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct SerializationType : System.IEquatable + public readonly partial struct SerializationType : System.IEquatable { private readonly object _dummy; private readonly int _dummyPrimitive; public SerializationType(string value) { throw null; } - public static Azure.Data.SchemaRegistry.Models.SerializationType Avro { get { throw null; } } - public bool Equals(Azure.Data.SchemaRegistry.Models.SerializationType other) { throw null; } + public static Azure.Data.SchemaRegistry.SerializationType Avro { get { throw null; } } + public bool Equals(Azure.Data.SchemaRegistry.SerializationType other) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override bool Equals(object obj) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } - public static bool operator ==(Azure.Data.SchemaRegistry.Models.SerializationType left, Azure.Data.SchemaRegistry.Models.SerializationType right) { throw null; } - public static implicit operator Azure.Data.SchemaRegistry.Models.SerializationType (string value) { throw null; } - public static bool operator !=(Azure.Data.SchemaRegistry.Models.SerializationType left, Azure.Data.SchemaRegistry.Models.SerializationType right) { throw null; } + public static bool operator ==(Azure.Data.SchemaRegistry.SerializationType left, Azure.Data.SchemaRegistry.SerializationType right) { throw null; } + public static implicit operator Azure.Data.SchemaRegistry.SerializationType (string value) { throw null; } + public static bool operator !=(Azure.Data.SchemaRegistry.SerializationType left, Azure.Data.SchemaRegistry.SerializationType right) { throw null; } public override string ToString() { throw null; } } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SerializationType.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SerializationType.cs index 8b3ccc12d7951..ab887838bd30f 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SerializationType.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/Generated/Models/SerializationType.cs @@ -8,7 +8,7 @@ using System; using System.ComponentModel; -namespace Azure.Data.SchemaRegistry.Models +namespace Azure.Data.SchemaRegistry { /// The SerializationType. public readonly partial struct SerializationType : IEquatable diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs index e095e2279037f..f60a757dafa41 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaProperties.cs @@ -1,9 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using Azure.Data.SchemaRegistry.Models; - namespace Azure.Data.SchemaRegistry { /// @@ -11,17 +8,11 @@ namespace Azure.Data.SchemaRegistry /// public class SchemaProperties { - private const char Slash = '/'; - private static readonly string[] s_groupSplitter = { "/$schemagroups/" }; - internal SchemaProperties(string content, string location, SerializationType xSchemaType, string xSchemaId, int? xSchemaVersion) { Content = content; Id = xSchemaId; - var groupSplit = location.Split(s_groupSplitter, StringSplitOptions.None)[1]; - var slashSplit = groupSplit.Split(Slash); - Name = slashSplit[2]; - GroupName = slashSplit[0]; + Location = location; Type = xSchemaType; Version = xSchemaVersion ?? 0; } @@ -37,14 +28,9 @@ internal SchemaProperties(string content, string location, SerializationType xSc public string Content { get; } /// - /// The name of the schema. - /// - internal string Name { get; } - - /// - /// The group name of the schema. + /// The location of the schema. /// - internal string GroupName { get; } + internal string Location { get; } /// /// Serialization type for the schema being stored. diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index 45db8c741d674..70acecb750dbb 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Azure.Core; using Azure.Core.Pipeline; -using Azure.Data.SchemaRegistry.Models; namespace Azure.Data.SchemaRegistry { diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs index e8e4b3043c0bb..8b685ead1937b 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs @@ -34,7 +34,7 @@ public enum ServiceVersion /// Version 2017-04 of the Schema Registry service. /// #pragma warning disable CA1707 // Remove the underscores from member name - V2017_04 + V2017_04 = 1 #pragma warning restore } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SerializationType.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SerializationType.cs new file mode 100644 index 0000000000000..8f8f7c11c52cb --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SerializationType.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Data.SchemaRegistry +{ + /// + /// The format used when serializing SchemaRegistry messages. + /// + [CodeGenModel("SerializationType")] + public readonly partial struct SerializationType + { + } +} diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs index a1bc05acd6767..338fd2b7eaeb8 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs @@ -1,16 +1,16 @@ -namespace Azure.Data.SchemaRegistry.Avro +namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro { - public partial class AvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer + public partial class SchemaRegistryAvroObjectSerializer : Azure.Core.Serialization.ObjectSerializer { - public AvroObjectSerializer(Azure.Data.SchemaRegistry.SchemaRegistryClient client, string groupName, Azure.Data.SchemaRegistry.Avro.AvroObjectSerializerOptions options = null) { } + public SchemaRegistryAvroObjectSerializer(Azure.Data.SchemaRegistry.SchemaRegistryClient client, string groupName, Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.SchemaRegistryAvroObjectSerializerOptions options = null) { } public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } public override System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; } public override void Serialize(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { } public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; } } - public partial class AvroObjectSerializerOptions + public partial class SchemaRegistryAvroObjectSerializerOptions { - public AvroObjectSerializerOptions() { } + public SchemaRegistryAvroObjectSerializerOptions() { } public bool AutoRegisterSchemas { get { throw null; } set { } } } } diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs index d569077a7d8ed..c47ff571e04c4 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs @@ -41,7 +41,7 @@ public SchemaRegistryAvroObjectSerializer(SchemaRegistryClient client, string gr _options = options; } - private static readonly byte[] s_emptyRecordFormatIndicator = { 0, 0, 0, 0 }; + private static readonly byte[] EmptyRecordFormatIndicator = { 0, 0, 0, 0 }; private readonly Dictionary _cachedSchemas = new Dictionary(); @@ -110,7 +110,7 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc var schemaId = GetSchemaId(schema, cancellationToken); var binaryEncoder = new BinaryEncoder(stream); - stream.Write(s_emptyRecordFormatIndicator, 0, 4); + stream.Write(EmptyRecordFormatIndicator, 0, 4); stream.Write(Encoding.UTF8.GetBytes(schemaId), 0, 32); writer.Write(value, binaryEncoder); binaryEncoder.Flush(); @@ -128,7 +128,7 @@ public override async ValueTask SerializeAsync(Stream stream, object value, Type var schemaId = await GetSchemaIdAsync(schema, cancellationToken).ConfigureAwait(false); var binaryEncoder = new BinaryEncoder(stream); - await stream.WriteAsync(s_emptyRecordFormatIndicator, 0, 4, cancellationToken).ConfigureAwait(false); + await stream.WriteAsync(EmptyRecordFormatIndicator, 0, 4, cancellationToken).ConfigureAwait(false); await stream.WriteAsync(Encoding.UTF8.GetBytes(schemaId), 0, 32, cancellationToken).ConfigureAwait(false); writer.Write(value, binaryEncoder); binaryEncoder.Flush(); @@ -184,7 +184,7 @@ private static ReadOnlyMemory CopyToReadOnlyMemory(Stream stream) private static void ValidateRecordFormatIdentifier(ReadOnlyMemory message) { var recordFormatIdentifier = message.Slice(0, 4).ToArray(); - if (!recordFormatIdentifier.SequenceEqual(s_emptyRecordFormatIndicator)) + if (!recordFormatIdentifier.SequenceEqual(EmptyRecordFormatIndicator)) { throw new InvalidDataContractException( $"The record format identifier ({recordFormatIdentifier[0]:X} {recordFormatIdentifier[1]:X} {recordFormatIdentifier[2]:X} {recordFormatIdentifier[3]:X}) for the message is invalid."); From 7b2599583ad82e5591243696d0e0e7e0deff7971 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Thu, 3 Sep 2020 21:25:53 -0700 Subject: [PATCH 24/45] Added some negative tests. Updated public surface descriptions. --- .../Azure.Data.SchemaRegistry/CHANGELOG.md | 4 +- .../src/SchemaRegistryClient.cs | 54 +++++++++++--- .../src/SchemaRegistryClientOptions.cs | 1 + .../tests/SchemaRegistryClientLiveTest.cs | 7 +- .../CHANGELOG.md | 2 +- .../src/SchemaRegistryAvroObjectSerializer.cs | 27 ++----- ...emaRegistryAvroObjectSerializerLiveTest.cs | 54 +++++++++++++- .../CanSerializeAndDeserialize.json | 8 +- .../CanSerializeAndDeserializeAsync.json | 8 +- ...nSerializeAndDeserializeGenericRecord.json | 73 +++++++++++++++++++ ...alizeAndDeserializeGenericRecordAsync.json | 73 +++++++++++++++++++ .../CannotDeserializeUnsupportedType.json | 7 ++ ...CannotDeserializeUnsupportedTypeAsync.json | 7 ++ .../CannotSerializeUnsupportedType.json | 7 ++ .../CannotSerializeUnsupportedTypeAsync.json | 7 ++ 15 files changed, 287 insertions(+), 52 deletions(-) create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeGenericRecord.json create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeGenericRecordAsync.json create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotDeserializeUnsupportedType.json create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotDeserializeUnsupportedTypeAsync.json create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotSerializeUnsupportedType.json create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotSerializeUnsupportedTypeAsync.json diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md index 36ac757b66df9..b173e0720c9fc 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md @@ -1,4 +1,4 @@ # Release History -## 1.0.0-preview.1 (2020-08-05) -- Started changelog to capture release notes. \ No newline at end of file +## 1.0.0-beta.1 (2020-09-08) +- Started changelog to capture release notes. diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index 70acecb750dbb..11943449a4637 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -35,16 +35,16 @@ public SchemaRegistryClient(string endpoint, TokenCredential credential, SchemaR { } - /// Initializes a new instance of for mocking. + /// Initializes a new instance of for mocking. protected SchemaRegistryClient() { } - /// Initializes a new instance of . - /// The handler for diagnostic messaging in the client. - /// The HTTP pipeline for sending and receiving REST requests and responses. - /// The endpoint URI. For example, myschemaregistry.servicebus.windows.net. - /// The API version of the service. + /// Initializes a new instance of . + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The endpoint URI. For example, myschemaregistry.servicebus.windows.net. + /// The API version of the service. internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, string apiVersion) { RestClient = new SchemaRestClient(clientDiagnostics, pipeline, endpoint, apiVersion); @@ -52,8 +52,14 @@ internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline } /// - /// TODO. (Create OR Get). (Register/Create). + /// Registers a schema with the SchemaRegistry service. /// + /// The name of the SchemaRegistry group. + /// The name of the schema. + /// The serialization format of the schema. + /// The string representation of the schema's content. + /// The cancellation token for the operation. + /// The properties of the schema. public virtual async Task> RegisterSchemaAsync(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); @@ -72,8 +78,14 @@ public virtual async Task> RegisterSchemaAsync(string } /// - /// TODO. (Create OR Get). (Register/Create). + /// Registers a schema with the SchemaRegistry service. /// + /// The name of the SchemaRegistry group. + /// The name of the schema. + /// The serialization format of the schema. + /// The string representation of the schema's content. + /// The cancellation token for the operation. + /// The properties of the schema. public virtual Response RegisterSchema(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); @@ -92,8 +104,14 @@ public virtual Response RegisterSchema(string groupName, strin } /// - /// TODO. (Opposite of TryGet) (Find/Query/Get). + /// Gets the schema ID associated with the schema from the SchemaRegistry service. /// + /// The name of the SchemaRegistry group. + /// The name of the schema. + /// The serialization format of the schema. + /// The string representation of the schema's content. + /// The cancellation token for the operation. + /// The properties of the schema, including the schema ID provided by the service. public virtual async Task> GetSchemaIdAsync(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); @@ -112,8 +130,14 @@ public virtual async Task> GetSchemaIdAsync(string gr } /// - /// TODO. (Opposite of TryGet) (Find/Query/Get). + /// Gets the schema ID associated with the schema from the SchemaRegistry service. /// + /// The name of the SchemaRegistry group. + /// The name of the schema. + /// The serialization format of the schema. + /// The string representation of the schema's content. + /// The cancellation token for the operation. + /// The properties of the schema, including the schema ID provided by the service. public virtual Response GetSchemaId(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); @@ -132,8 +156,11 @@ public virtual Response GetSchemaId(string groupName, string s } /// - /// TODO. (Opposite of TryGet) (Find/Query/Get). + /// Gets the schema content associated with the schema ID from the SchemaRegistry service. /// + /// The schema ID of the the schema from the SchemaRegistry. + /// The cancellation token for the operation. + /// The properties of the schema, including the schema content provided by the service. public virtual async Task> GetSchemaAsync(string schemaId, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); @@ -152,8 +179,11 @@ public virtual async Task> GetSchemaAsync(string sche } /// - /// TODO. (Opposite of TryGet) (Find/Query/Get). + /// Gets the schema content associated with the schema ID from the SchemaRegistry service. /// + /// The schema ID of the the schema from the SchemaRegistry. + /// The cancellation token for the operation. + /// The properties of the schema, including the schema content provided by the service. public virtual Response GetSchema(string schemaId, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs index 8b685ead1937b..092698b010227 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs @@ -34,6 +34,7 @@ public enum ServiceVersion /// Version 2017-04 of the Schema Registry service. /// #pragma warning disable CA1707 // Remove the underscores from member name + // ReSharper disable once InconsistentNaming V2017_04 = 1 #pragma warning restore } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs index b9c669729fe9f..4059852961929 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/SchemaRegistryClientLiveTest.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Azure.Core.TestFramework; -using Azure.Data.SchemaRegistry.Models; using NUnit.Framework; namespace Azure.Data.SchemaRegistry.Tests @@ -16,14 +15,12 @@ public SchemaRegistryClientLiveTest(bool isAsync) : base(isAsync) TestDiagnostics = false; } - private SchemaRegistryClient CreateClient() - { - return InstrumentClient(new SchemaRegistryClient( + private SchemaRegistryClient CreateClient() => + InstrumentClient(new SchemaRegistryClient( TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential, Recording.InstrumentClientOptions(new SchemaRegistryClientOptions()) )); - } [Test] public async Task CanRegisterSchema() diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md index 36ac757b66df9..f8af4602aecc2 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md @@ -1,4 +1,4 @@ # Release History -## 1.0.0-preview.1 (2020-08-05) +## 1.0.0-beta.1 (2020-09-08) - Started changelog to capture release notes. \ No newline at end of file diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs index c47ff571e04c4..5c26e0632f211 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs @@ -8,7 +8,6 @@ using Azure.Core; using Azure.Core.Serialization; using Azure.Data.SchemaRegistry; -using Azure.Data.SchemaRegistry.Models; using System; using System.Collections.Generic; using System.IO; @@ -23,7 +22,7 @@ namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro #pragma warning restore AZC0001 // Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure { /// - /// A implementation that uses for SpecificRecord serialization/deserialization. + /// A implementation that uses for Avro serialization/deserialization. /// public class SchemaRegistryAvroObjectSerializer : ObjectSerializer { @@ -191,22 +190,6 @@ private static void ValidateRecordFormatIdentifier(ReadOnlyMemory message) } } - private Schema GetSchema(ReadOnlyMemory message, CancellationToken cancellationToken) - { - var schemaIdBytes = message.Slice(4, 32).ToArray(); - var schemaId = Encoding.UTF8.GetString(schemaIdBytes); - var schemaContent = _client.GetSchema(schemaId, cancellationToken).Value.Content; - return Schema.Parse(schemaContent); - } - - private async Task GetSchemaAsync(ReadOnlyMemory message, CancellationToken cancellationToken) - { - var schemaIdBytes = message.Slice(4, 32).ToArray(); - var schemaId = Encoding.UTF8.GetString(schemaIdBytes); - var schemaContent = (await _client.GetSchemaAsync(schemaId, cancellationToken).ConfigureAwait(false)).Value.Content; - return Schema.Parse(schemaContent); - } - /// public override object Deserialize(Stream stream, Type returnType, CancellationToken cancellationToken) { @@ -216,7 +199,9 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT var supportedType = GetSupportedTypeOrThrow(returnType); var message = CopyToReadOnlyMemory(stream); ValidateRecordFormatIdentifier(message); - var schema = GetSchema(message, cancellationToken); + var schemaIdBytes = message.Slice(4, 32).ToArray(); + var schemaId = Encoding.UTF8.GetString(schemaIdBytes); + var schema = GetSchemaById(schemaId, cancellationToken); using var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); var binaryDecoder = new BinaryDecoder(valueStream); @@ -233,7 +218,9 @@ public override async ValueTask DeserializeAsync(Stream stream, Type ret var supportedType = GetSupportedTypeOrThrow(returnType); var message = CopyToReadOnlyMemory(stream); ValidateRecordFormatIdentifier(message); - var schema = await GetSchemaAsync(message, cancellationToken).ConfigureAwait(false); + var schemaIdBytes = message.Slice(4, 32).ToArray(); + var schemaId = Encoding.UTF8.GetString(schemaIdBytes); + var schema = await GetSchemaByIdAsync(schemaId, cancellationToken).ConfigureAwait(false); using var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); var binaryDecoder = new BinaryDecoder(valueStream); diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs index 9ca005382f78b..9afdfd28d9b0d 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs @@ -1,9 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Avro; +using Avro.Generic; using Azure.Core.TestFramework; using Azure.Data.SchemaRegistry; using NUnit.Framework; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -18,14 +21,12 @@ public SchemaRegistryAvroObjectSerializerLiveTest(bool isAsync) : base(isAsync) TestDiagnostics = false; } - private SchemaRegistryClient CreateClient() - { - return InstrumentClient(new SchemaRegistryClient( + private SchemaRegistryClient CreateClient() => + InstrumentClient(new SchemaRegistryClient( TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential, Recording.InstrumentClientOptions(new SchemaRegistryClientOptions()) )); - } [Test] public async Task CanSerializeAndDeserialize() @@ -44,5 +45,50 @@ public async Task CanSerializeAndDeserialize() Assert.AreEqual("Caketown", readEmployee.Name); Assert.AreEqual(42, readEmployee.Age); } + + [Test] + public async Task CanSerializeAndDeserializeGenericRecord() + { + var client = CreateClient(); + var groupName = "miyanni_srgroup"; + var record = new GenericRecord((RecordSchema)Employee._SCHEMA); + record.Add("Name", "Caketown"); + record.Add("Age", 42); + + var memoryStream = new MemoryStream(); + var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); + await serializer.SerializeAsync(memoryStream, record, typeof(GenericRecord), CancellationToken.None); + + var deserializedObject = await serializer.DeserializeAsync(memoryStream, typeof(GenericRecord), CancellationToken.None); + var readRecord = deserializedObject as GenericRecord; + Assert.IsNotNull(readRecord); + Assert.AreEqual("Caketown", readRecord.GetValue(0)); + Assert.AreEqual(42, readRecord.GetValue(1)); + } + + [Test] + public async Task CannotSerializeUnsupportedType() + { + var client = CreateClient(); + var groupName = "miyanni_srgroup"; + var timeZoneInfo = TimeZoneInfo.Utc; + + var memoryStream = new MemoryStream(); + var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); + Assert.ThrowsAsync(async () => await serializer.SerializeAsync(memoryStream, timeZoneInfo, typeof(TimeZoneInfo), CancellationToken.None)); + await Task.CompletedTask; + } + + [Test] + public async Task CannotDeserializeUnsupportedType() + { + var client = CreateClient(); + var groupName = "miyanni_srgroup"; + + var memoryStream = new MemoryStream(); + var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); + Assert.ThrowsAsync(async () => await serializer.DeserializeAsync(memoryStream, typeof(TimeZoneInfo), CancellationToken.None)); + await Task.CompletedTask; + } } } diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json index 8cf679c119013..b2bc10d238654 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserialize.json @@ -9,7 +9,7 @@ "Content-Length": "283", "Content-Type": "application/json", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200902.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-alpha.20200903.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], "x-ms-client-request-id": "868a705e78e1eacc39ee20f0603590e1", @@ -20,7 +20,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 03 Sep 2020 00:25:18 GMT", + "Date": "Fri, 04 Sep 2020 04:17:14 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -42,7 +42,7 @@ "Accept": "application/json", "Authorization": "Sanitized", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200902.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-alpha.20200903.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], "x-ms-client-request-id": "fce63c5a3b2209ffbf3241fcd47809a7", @@ -52,7 +52,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 03 Sep 2020 00:25:18 GMT", + "Date": "Fri, 04 Sep 2020 04:17:14 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json index 0c389ac96e11c..ecba1315c80c6 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeAsync.json @@ -9,7 +9,7 @@ "Content-Length": "283", "Content-Type": "application/json", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200902.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-alpha.20200903.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], "x-ms-client-request-id": "9194a80ecb3e28d6d988eee20cb5ed95", @@ -20,7 +20,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 03 Sep 2020 00:25:19 GMT", + "Date": "Fri, 04 Sep 2020 04:17:17 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", @@ -42,7 +42,7 @@ "Accept": "application/json", "Authorization": "Sanitized", "User-Agent": [ - "azsdk-net-Data.SchemaRegistry/1.0.0-dev.20200902.1", + "azsdk-net-Data.SchemaRegistry/1.0.0-alpha.20200903.1", "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" ], "x-ms-client-request-id": "bbd7ee0ffba0cfc5c3b161ee35b7e4ec", @@ -52,7 +52,7 @@ "StatusCode": 200, "ResponseHeaders": { "Content-Type": "application/json", - "Date": "Thu, 03 Sep 2020 00:25:19 GMT", + "Date": "Fri, 04 Sep 2020 04:17:17 GMT", "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", "Server": "Microsoft-HTTPAPI/2.0", "Strict-Transport-Security": "max-age=31536000", diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeGenericRecord.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeGenericRecord.json new file mode 100644 index 0000000000000..b957cf8c672ed --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeGenericRecord.json @@ -0,0 +1,73 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "Content-Length": "283", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-alpha.20200903.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "62af9d4468e15d9ba239fef902b0ae57", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "{\u0022type\u0022:\u0022record\u0022,\u0022name\u0022:\u0022Employee\u0022,\u0022namespace\u0022:\u0022TestSchema\u0022,\u0022fields\u0022:[{\u0022name\u0022:\u0022Name\u0022,\u0022type\u0022:\u0022string\u0022},{\u0022name\u0022:\u0022Age\u0022,\u0022type\u0022:\u0022int\u0022}]}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Fri, 04 Sep 2020 04:17:16 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "34fa96c2ac67489da0df6d4a245265a7", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "34fa96c2ac67489da0df6d4a245265a7" + } + }, + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/getSchemaById/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-alpha.20200903.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "28b59f1d4676f2b691ef41bd27d253ab", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Fri, 04 Sep 2020 04:17:16 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "34fa96c2ac67489da0df6d4a245265a7", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions?api-version=2017-04" + }, + "ResponseBody": "{\u0022type\u0022:\u0022record\u0022,\u0022name\u0022:\u0022Employee\u0022,\u0022namespace\u0022:\u0022TestSchema\u0022,\u0022fields\u0022:[{\u0022name\u0022:\u0022Name\u0022,\u0022type\u0022:\u0022string\u0022},{\u0022name\u0022:\u0022Age\u0022,\u0022type\u0022:\u0022int\u0022}]}" + } + ], + "Variables": { + "RandomSeed": "993263430", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeGenericRecordAsync.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeGenericRecordAsync.json new file mode 100644 index 0000000000000..4976695a20827 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CanSerializeAndDeserializeGenericRecordAsync.json @@ -0,0 +1,73 @@ +{ + "Entries": [ + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee?api-version=2017-04", + "RequestMethod": "PUT", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "Content-Length": "283", + "Content-Type": "application/json", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-alpha.20200903.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "29665161b7b0e47e8e47525f0cf322fd", + "x-ms-return-client-request-id": "true", + "X-Schema-Type": "avro" + }, + "RequestBody": "{\u0022type\u0022:\u0022record\u0022,\u0022name\u0022:\u0022Employee\u0022,\u0022namespace\u0022:\u0022TestSchema\u0022,\u0022fields\u0022:[{\u0022name\u0022:\u0022Name\u0022,\u0022type\u0022:\u0022string\u0022},{\u0022name\u0022:\u0022Age\u0022,\u0022type\u0022:\u0022int\u0022}]}", + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Fri, 04 Sep 2020 04:17:18 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "34fa96c2ac67489da0df6d4a245265a7", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions?api-version=2017-04" + }, + "ResponseBody": { + "id": "34fa96c2ac67489da0df6d4a245265a7" + } + }, + { + "RequestUri": "https://sr-playground.servicebus.windows.net/$schemagroups/getSchemaById/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "User-Agent": [ + "azsdk-net-Data.SchemaRegistry/1.0.0-alpha.20200903.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "6a2d0bdc0bba5cc6479100de284925b6", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/json", + "Date": "Fri, 04 Sep 2020 04:17:18 GMT", + "Location": "https://sr-playground.servicebus.windows.net/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions/1?api-version=2017-04", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000", + "Transfer-Encoding": "chunked", + "X-Schema-Id": "34fa96c2ac67489da0df6d4a245265a7", + "X-Schema-Id-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/getschemabyid/34fa96c2ac67489da0df6d4a245265a7?api-version=2017-04", + "X-Schema-Type": "Avro", + "X-Schema-Version": "1", + "X-Schema-Versions-Location": "https://sr-playground.servicebus.windows.net:443/$schemagroups/miyanni_srgroup/schemas/TestSchema.Employee/versions?api-version=2017-04" + }, + "ResponseBody": "{\u0022type\u0022:\u0022record\u0022,\u0022name\u0022:\u0022Employee\u0022,\u0022namespace\u0022:\u0022TestSchema\u0022,\u0022fields\u0022:[{\u0022name\u0022:\u0022Name\u0022,\u0022type\u0022:\u0022string\u0022},{\u0022name\u0022:\u0022Age\u0022,\u0022type\u0022:\u0022int\u0022}]}" + } + ], + "Variables": { + "RandomSeed": "1337710688", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotDeserializeUnsupportedType.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotDeserializeUnsupportedType.json new file mode 100644 index 0000000000000..d46a3d442f041 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotDeserializeUnsupportedType.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "RandomSeed": "838895729", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotDeserializeUnsupportedTypeAsync.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotDeserializeUnsupportedTypeAsync.json new file mode 100644 index 0000000000000..7f4c2ab72703e --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotDeserializeUnsupportedTypeAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "RandomSeed": "592153647", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotSerializeUnsupportedType.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotSerializeUnsupportedType.json new file mode 100644 index 0000000000000..8686dacebc093 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotSerializeUnsupportedType.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "RandomSeed": "977456895", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotSerializeUnsupportedTypeAsync.json b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotSerializeUnsupportedTypeAsync.json new file mode 100644 index 0000000000000..720db6220d8fc --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SessionRecords/SchemaRegistryAvroObjectSerializerLiveTest/CannotSerializeUnsupportedTypeAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "RandomSeed": "504944443", + "SCHEMAREGISTRY_URL": "sr-playground.servicebus.windows.net" + } +} \ No newline at end of file From 88339c2b81277091829da9e96133b92f537b5173 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Thu, 3 Sep 2020 22:11:25 -0700 Subject: [PATCH 25/45] In progress writing readmes. --- .../Azure.Data.SchemaRegistry/CHANGELOG.md | 5 +- .../Azure.Data.SchemaRegistry/README.md | 59 ++++++++++--------- .../CHANGELOG.md | 6 +- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md index b173e0720c9fc..994786219cf63 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/CHANGELOG.md @@ -1,4 +1,7 @@ # Release History ## 1.0.0-beta.1 (2020-09-08) -- Started changelog to capture release notes. +- Added SchemaRegistryClient with 3 operations: + - RegisterSchema + - GetSchemaId + - GetSchema diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md index 3411f7736223f..3561d37be0b73 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md @@ -1,38 +1,29 @@ -# README.md template +# Azure Schema Registry client library for .NET -Use the guidelines in each section of this template to ensure consistency and readability of your README. The README resides in your package's GitHub repository at the root of its directory within the repo. It's also used as the package distribution page (NuGet, PyPi, npm, etc.) and as a Quickstart on docs.microsoft.com. See [README-EXAMPLE.md](README-EXAMPLE.md) for an example following this template. - -**Title**: The H1 of your README should be in the format: `# [Product Name] client library for [Language]` - -* All headings, including the H1, should use **sentence-style capitalization**. Refer to the [Microsoft Style Guide][style-guide-msft] and [Microsoft Cloud Style Guide][style-guide-cloud] for more information. -* Example: `# Azure Batch client library for Python` - -# Azure Template client library for .NET - -**Introduction**: The introduction appears directly under the title (H1) of your README. - -* **DO NOT** use an "Introduction" or "Overview" heading (H2) for this section. -* First sentence: **Describe the service** briefly. You can usually use the first line of the service's docs landing page for this (Example: [Cosmos DB docs landing page](https://docs.microsoft.com/azure/cosmos-db/)). -* Next, add a **bulleted list** of the **most common tasks** supported by the package or library, prefaced with "Use the client library for [Product Name] to:". Then, provide code snippets for these tasks in the [Examples](#examples) section later in the document. Keep the task list short but include those tasks most developers need to perform with your package. -* Include this single line of links targeting your product's content at the bottom of the introduction, making any adjustments as necessary (for example, NuGet instead of PyPi): - - [Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/azure-batch) | [Package (PyPi)](https://pypi.org/project/azure-batch/) | [API reference documentation](https://docs.microsoft.com/python/api/overview/azure/batch?view=azure-python) | [Product documentation](https://docs.microsoft.com/azure/batch/) - -> TIP: Your README should be as **brief** as possible but **no more brief** than necessary to get a developer new to Azure, the service, or the package up and running quickly. Keep it brief, but include everything a developer needs to make their first API call successfully. +The Azure Schema Registry service allows developers to provide and retrieve data schemas from a centralized repository for use in messaging systems. ## Getting started -This section should include everything a developer needs to do to install and create their first client connection *very quickly*. - ### Install the package -First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `pip install package-name`, but should enable a developer to successfully install the package from NuGet, pip, npm, Maven, or even cloning a GitHub repository. +Install the Azure Schema Registry client library for .NET with [NuGet][nuget]: + +```PowerShell +Install-Package Azure.Data.SchemaRegistry +``` ### Prerequisites -Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB: +* An [Azure subscription][azure_sub]. +* An [Event Hubs namespace][event_hubs_namespace] + +If you need to [create an Event Hubs namespace][create_event_hubs_namespace], you can use the Azure Portal or [Azure PowerShell][azure_powershell]. -> You must have an [Azure subscription](https://azure.microsoft.com/free/), [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API), and [Python 3.6+](https://www.python.org/downloads/) to use this package. +You can use Azure PowerShell to create the Event Hubs namespace with the following command: + +```PowerShell +New-AzEventHubNamespace -ResourceGroupName myResourceGroup -NamespaceName namespace_name -Location eastus +``` ### Authenticate the client @@ -46,6 +37,14 @@ The *Key concepts* section should describe the functionality of the main classes ## Examples + +* [Register a schema][azconfig_setting_concepts] +* [Retrieve a schema ID][azconfig_asof_snapshot] +* [Retrieve a schema][azconfig_asof_snapshot] + + + + Include code snippets and short descriptions for each task you listed in the [Introduction](#introduction) (the bulleted list). Briefly explain each operation, but include enough clarity to explain complex or otherwise tricky operations. If possible, use the same example snippets that your in-code documentation uses. For example, use the snippets in your `examples.py` that Sphinx ingests via its [literalinclude](https://www.sphinx-doc.org/en/1.5/markup/code.html?highlight=code%20examples#includes) directive. The `examples.py` file containing the snippets should reside alongside your package's code, and should be tested in an automated fashion. @@ -97,8 +96,10 @@ If the package or a related package supports it, include tips for logging or ena This is a template, but your SDK readme should include details on how to contribute code to the repo/package. - -[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization -[style-guide-cloud]: https://worldready.cloudapp.net/Styleguide/Read?id=2696&topicid=25357 - ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftemplate%2FAzure.Template%2FREADME.png) + + +[nuget]: https://www.nuget.org/ +[event_hubs_namespace]: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-about +[azure_powershell]: https://docs.microsoft.com/en-us/powershell/azure/ +[create_event_hubs_namespace]: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-quickstart-powershell#create-an-event-hubs-namespace diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md index f8af4602aecc2..e15e131f1e442 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/CHANGELOG.md @@ -1,4 +1,8 @@ # Release History ## 1.0.0-beta.1 (2020-09-08) -- Started changelog to capture release notes. \ No newline at end of file +- Added SchemaRegistryAvroObjectSerializer + - Derives from ObjectSerializer + - Works with 2 Avro types: + - SpecificRecord + - GenericRecord \ No newline at end of file From 51942475931d9f131af878ef154bfc7a5dc09292 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 06:39:49 -0700 Subject: [PATCH 26/45] Fixed position reset in deserialization stream. --- .../src/SchemaRegistryAvroObjectSerializer.cs | 1 - .../tests/SchemaRegistryAvroObjectSerializerLiveTest.cs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs index 5c26e0632f211..1ac2d697632d4 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs @@ -175,7 +175,6 @@ private static DatumReader GetReader(Schema schema, SupportedType suppor private static ReadOnlyMemory CopyToReadOnlyMemory(Stream stream) { using var tempMemoryStream = new MemoryStream(); - stream.Position = 0; stream.CopyTo(tempMemoryStream); return new ReadOnlyMemory(tempMemoryStream.ToArray()); } diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs index 9afdfd28d9b0d..b5fcf00aafdc9 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs @@ -39,6 +39,7 @@ public async Task CanSerializeAndDeserialize() var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); await serializer.SerializeAsync(memoryStream, employee, typeof(Employee), CancellationToken.None); + memoryStream.Position = 0; var deserializedObject = await serializer.DeserializeAsync(memoryStream, typeof(Employee), CancellationToken.None); var readEmployee = deserializedObject as Employee; Assert.IsNotNull(readEmployee); @@ -59,6 +60,7 @@ public async Task CanSerializeAndDeserializeGenericRecord() var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); await serializer.SerializeAsync(memoryStream, record, typeof(GenericRecord), CancellationToken.None); + memoryStream.Position = 0; var deserializedObject = await serializer.DeserializeAsync(memoryStream, typeof(GenericRecord), CancellationToken.None); var readRecord = deserializedObject as GenericRecord; Assert.IsNotNull(readRecord); From 0e1122b50dae6e69d81263cfc92d2f29a2556e34 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 06:56:51 -0700 Subject: [PATCH 27/45] Made constants for wire format lengths/positions. --- .../src/SchemaRegistryAvroObjectSerializer.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs index 1ac2d697632d4..f527547e0e6f5 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs @@ -41,6 +41,9 @@ public SchemaRegistryAvroObjectSerializer(SchemaRegistryClient client, string gr } private static readonly byte[] EmptyRecordFormatIndicator = { 0, 0, 0, 0 }; + private const int RecordFormatIndicatorLength = 4; + private const int SchemaIdLength = 32; + private const int PayloadStartPosition = RecordFormatIndicatorLength + SchemaIdLength; private readonly Dictionary _cachedSchemas = new Dictionary(); @@ -109,8 +112,8 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc var schemaId = GetSchemaId(schema, cancellationToken); var binaryEncoder = new BinaryEncoder(stream); - stream.Write(EmptyRecordFormatIndicator, 0, 4); - stream.Write(Encoding.UTF8.GetBytes(schemaId), 0, 32); + stream.Write(EmptyRecordFormatIndicator, 0, RecordFormatIndicatorLength); + stream.Write(Encoding.UTF8.GetBytes(schemaId), 0, SchemaIdLength); writer.Write(value, binaryEncoder); binaryEncoder.Flush(); } @@ -127,8 +130,8 @@ public override async ValueTask SerializeAsync(Stream stream, object value, Type var schemaId = await GetSchemaIdAsync(schema, cancellationToken).ConfigureAwait(false); var binaryEncoder = new BinaryEncoder(stream); - await stream.WriteAsync(EmptyRecordFormatIndicator, 0, 4, cancellationToken).ConfigureAwait(false); - await stream.WriteAsync(Encoding.UTF8.GetBytes(schemaId), 0, 32, cancellationToken).ConfigureAwait(false); + await stream.WriteAsync(EmptyRecordFormatIndicator, 0, RecordFormatIndicatorLength, cancellationToken).ConfigureAwait(false); + await stream.WriteAsync(Encoding.UTF8.GetBytes(schemaId), 0, SchemaIdLength, cancellationToken).ConfigureAwait(false); writer.Write(value, binaryEncoder); binaryEncoder.Flush(); } @@ -181,7 +184,7 @@ private static ReadOnlyMemory CopyToReadOnlyMemory(Stream stream) private static void ValidateRecordFormatIdentifier(ReadOnlyMemory message) { - var recordFormatIdentifier = message.Slice(0, 4).ToArray(); + var recordFormatIdentifier = message.Slice(0, RecordFormatIndicatorLength).ToArray(); if (!recordFormatIdentifier.SequenceEqual(EmptyRecordFormatIndicator)) { throw new InvalidDataContractException( @@ -198,10 +201,10 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT var supportedType = GetSupportedTypeOrThrow(returnType); var message = CopyToReadOnlyMemory(stream); ValidateRecordFormatIdentifier(message); - var schemaIdBytes = message.Slice(4, 32).ToArray(); + var schemaIdBytes = message.Slice(RecordFormatIndicatorLength, SchemaIdLength).ToArray(); var schemaId = Encoding.UTF8.GetString(schemaIdBytes); var schema = GetSchemaById(schemaId, cancellationToken); - using var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); + using var valueStream = new MemoryStream(message.Slice(PayloadStartPosition, message.Length - PayloadStartPosition).ToArray()); var binaryDecoder = new BinaryDecoder(valueStream); var reader = GetReader(schema, supportedType); @@ -217,10 +220,10 @@ public override async ValueTask DeserializeAsync(Stream stream, Type ret var supportedType = GetSupportedTypeOrThrow(returnType); var message = CopyToReadOnlyMemory(stream); ValidateRecordFormatIdentifier(message); - var schemaIdBytes = message.Slice(4, 32).ToArray(); + var schemaIdBytes = message.Slice(RecordFormatIndicatorLength, SchemaIdLength).ToArray(); var schemaId = Encoding.UTF8.GetString(schemaIdBytes); var schema = await GetSchemaByIdAsync(schemaId, cancellationToken).ConfigureAwait(false); - using var valueStream = new MemoryStream(message.Slice(36, message.Length - 36).ToArray()); + using var valueStream = new MemoryStream(message.Slice(PayloadStartPosition, message.Length - PayloadStartPosition).ToArray()); var binaryDecoder = new BinaryDecoder(valueStream); var reader = GetReader(schema, supportedType); From a46462b6e15815cc4cd2affbf80545dc95d57ef0 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 07:19:33 -0700 Subject: [PATCH 28/45] Updated property description. Made static field for UTF8 encoding. --- .../src/SchemaRegistryAvroObjectSerializer.cs | 11 ++++++----- .../src/SchemaRegistryAvroObjectSerializerOptions.cs | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs index f527547e0e6f5..7744bc2b4f271 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs @@ -41,10 +41,11 @@ public SchemaRegistryAvroObjectSerializer(SchemaRegistryClient client, string gr } private static readonly byte[] EmptyRecordFormatIndicator = { 0, 0, 0, 0 }; + private static readonly Encoding Utf8Encoding = new UTF8Encoding(); + private const int RecordFormatIndicatorLength = 4; private const int SchemaIdLength = 32; private const int PayloadStartPosition = RecordFormatIndicatorLength + SchemaIdLength; - private readonly Dictionary _cachedSchemas = new Dictionary(); private enum SupportedType @@ -113,7 +114,7 @@ public override void Serialize(Stream stream, object value, Type inputType, Canc var binaryEncoder = new BinaryEncoder(stream); stream.Write(EmptyRecordFormatIndicator, 0, RecordFormatIndicatorLength); - stream.Write(Encoding.UTF8.GetBytes(schemaId), 0, SchemaIdLength); + stream.Write(Utf8Encoding.GetBytes(schemaId), 0, SchemaIdLength); writer.Write(value, binaryEncoder); binaryEncoder.Flush(); } @@ -131,7 +132,7 @@ public override async ValueTask SerializeAsync(Stream stream, object value, Type var binaryEncoder = new BinaryEncoder(stream); await stream.WriteAsync(EmptyRecordFormatIndicator, 0, RecordFormatIndicatorLength, cancellationToken).ConfigureAwait(false); - await stream.WriteAsync(Encoding.UTF8.GetBytes(schemaId), 0, SchemaIdLength, cancellationToken).ConfigureAwait(false); + await stream.WriteAsync(Utf8Encoding.GetBytes(schemaId), 0, SchemaIdLength, cancellationToken).ConfigureAwait(false); writer.Write(value, binaryEncoder); binaryEncoder.Flush(); } @@ -202,7 +203,7 @@ public override object Deserialize(Stream stream, Type returnType, CancellationT var message = CopyToReadOnlyMemory(stream); ValidateRecordFormatIdentifier(message); var schemaIdBytes = message.Slice(RecordFormatIndicatorLength, SchemaIdLength).ToArray(); - var schemaId = Encoding.UTF8.GetString(schemaIdBytes); + var schemaId = Utf8Encoding.GetString(schemaIdBytes); var schema = GetSchemaById(schemaId, cancellationToken); using var valueStream = new MemoryStream(message.Slice(PayloadStartPosition, message.Length - PayloadStartPosition).ToArray()); @@ -221,7 +222,7 @@ public override async ValueTask DeserializeAsync(Stream stream, Type ret var message = CopyToReadOnlyMemory(stream); ValidateRecordFormatIdentifier(message); var schemaIdBytes = message.Slice(RecordFormatIndicatorLength, SchemaIdLength).ToArray(); - var schemaId = Encoding.UTF8.GetString(schemaIdBytes); + var schemaId = Utf8Encoding.GetString(schemaIdBytes); var schema = await GetSchemaByIdAsync(schemaId, cancellationToken).ConfigureAwait(false); using var valueStream = new MemoryStream(message.Slice(PayloadStartPosition, message.Length - PayloadStartPosition).ToArray()); diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs index 49e294da4440f..9e134e38a6d6a 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs @@ -11,8 +11,10 @@ namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro public class SchemaRegistryAvroObjectSerializerOptions { /// + /// Gets or sets the automatic registration of schemas flag. /// When true, automatically registers the provided schema with the SchemaRegistry during serialization. /// When false, the schema is only acquired from the SchemaRegistry. + /// The default is false. /// public bool AutoRegisterSchemas { get; set; } } From 2d19b511a5893486647678560a5f7e44d70ee2b7 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 07:27:18 -0700 Subject: [PATCH 29/45] Removed unused Directory.Build.props. --- .../Azure.Data.SchemaRegistry/Directory.Build.props | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/Directory.Build.props diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/Directory.Build.props b/sdk/schemaregistry/Azure.Data.SchemaRegistry/Directory.Build.props deleted file mode 100644 index 1a9611bd49242..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/Directory.Build.props +++ /dev/null @@ -1,6 +0,0 @@ - - - - From 54f3d486673512f1d7fcd58f41ffa8a3939da389 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 07:29:34 -0700 Subject: [PATCH 30/45] Removed unused description. --- sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaId.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaId.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaId.cs index 049bbee7f9f17..154d76331ce70 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaId.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaId.cs @@ -5,9 +5,6 @@ namespace Azure.Data.SchemaRegistry.Models { - /// - /// JSON Object received from the registry containing schema identifiers. - /// [CodeGenModel("SchemaId")] internal readonly partial struct SchemaId { From 88d46a2bcfacdf061b735932912cb658f0b27fe1 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 10:58:51 -0700 Subject: [PATCH 31/45] Continuing readme. Started adding snippets. --- .../Azure.Data.SchemaRegistry/README.md | 42 +++++++++++++++---- .../SchemaRegistryClientSamples.HelloWorld.cs | 22 +++++----- ...emaRegistryClientSamples.ReadmeSnippets.cs | 30 +++++++++++++ .../src/SchemaRegistryAvroObjectSerializer.cs | 2 +- 4 files changed, 76 insertions(+), 20 deletions(-) create mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md index 3561d37be0b73..e9281b6eb75af 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md @@ -27,20 +27,44 @@ New-AzEventHubNamespace -ResourceGroupName myResourceGroup -NamespaceName namesp ### Authenticate the client -If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating. +In order to interact with the Azure Schema Registry service, you'll need to create an instance of the [Schema Registry Client][schema_registry_client] class. To create this client, you'll need Azure resource credentials and the Event Hubs namespace hostname. -For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object. +#### Get credentials + +To acquire authenicated credentials and start interacting with Azure resources, please see the [quickstart guide here][quickstart_guide]. + +#### Get Event Hubs namespace hostname + +The simpliest way is to use the [Azure portal][azure_portal] and navigate to your Event Hubs namespace. From the Overview tab, you'll see `Host name`. Copy the value from this field. + +#### Create SchemaRegistryClient + +Once you have the Azure resource credentials and the Event Hubs namespace hostname, you can create the [SchemaRegistryClient][schema_registry_client]: + +```C# Snippet:CreateSchemaRegistryClient +string connectionString = ""; +var client = new ConfigurationClient(connectionString); +``` ## Key concepts -The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity. +### Schemas -## Examples +A schema has 6 components: +- Group Name +- Schema Name +- Schema ID +- Serialization Type +- Schema Content +- Schema Version +These components play different roles. Some are used as input into the operations and some are outputs. Currently, [SchemaProperties][schema_properties] only exposes those properties that are potential outputs that are used in SchemaRegistry operations. Those exposed properties are `Content` and `Id`. + +## Examples -* [Register a schema][azconfig_setting_concepts] -* [Retrieve a schema ID][azconfig_asof_snapshot] -* [Retrieve a schema][azconfig_asof_snapshot] +* [Register a schema](#create-the-thing) +* [Retrieve a schema ID](#get-the-thing) +* [Retrieve a schema](#list-the-things) @@ -103,3 +127,7 @@ This is a template, but your SDK readme should include details on how to contrib [event_hubs_namespace]: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-about [azure_powershell]: https://docs.microsoft.com/en-us/powershell/azure/ [create_event_hubs_namespace]: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-quickstart-powershell#create-an-event-hubs-namespace +[quickstart_guide]: https://github.com/Azure/azure-sdk-for-net/blob/master/doc/mgmt_preview_quickstart.md +[schema_registry_client]: src/SchemaRegistryClient.cs +[azure_portal]: https://ms.portal.azure.com/ +[schema_properties]: src/SchemaProperties.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs index ec6b1efb48469..2cf37373da4f3 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs @@ -2,25 +2,23 @@ // Licensed under the MIT License. using Azure.Core.TestFramework; -using Azure.Identity; -using NUnit.Framework; namespace Azure.Data.SchemaRegistry.Tests.Samples { public class SchemaRegistryClientSamples : SamplesBase { - [Test] - public void GettingASecret() - { - var endpoint = TestEnvironment.SchemaRegistryUri; + //[Test] + //public void GettingASecret() + //{ + // var endpoint = TestEnvironment.SchemaRegistryUri; - #region Snippet:GetSecret - var client = new SchemaRegistryClient(endpoint, new DefaultAzureCredential()); + // #region Snippet:GetSecret + // var client = new SchemaRegistryClient(endpoint, new DefaultAzureCredential()); - //SecretBundle secret = client.GetSecret("TestSecret"); + // //SecretBundle secret = client.GetSecret("TestSecret"); - //Console.WriteLine(secret.Value); - #endregion - } + // //Console.WriteLine(secret.Value); + // #endregion + //} } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs new file mode 100644 index 0000000000000..7f559ae7ccfb3 --- /dev/null +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.Data.SchemaRegistry.Tests.Samples +{ +#pragma warning disable SA1649 // File name should match first type name + public class SchemaRegistryReadmeSnippets : SamplesBase +#pragma warning restore SA1649 // File name should match first type name + { + [Test] + public void CreateSchemaRegistryClient() + { + var endpoint = TestEnvironment.SchemaRegistryUri; + var credentials = TestEnvironment.Credential; + + #region Snippet:CreateSchemaRegistryClient + //@@ string endpoint = ""; + //@@ var credentials = new ClientSecretCredential( + //@@ "", + //@@ "", + //@@ "" + //@@ ); + var client = new SchemaRegistryClient(endpoint, credentials); + #endregion + } + } +} diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs index 7744bc2b4f271..34999b34c1406 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs @@ -41,7 +41,7 @@ public SchemaRegistryAvroObjectSerializer(SchemaRegistryClient client, string gr } private static readonly byte[] EmptyRecordFormatIndicator = { 0, 0, 0, 0 }; - private static readonly Encoding Utf8Encoding = new UTF8Encoding(); + private static readonly Encoding Utf8Encoding = new UTF8Encoding(false); private const int RecordFormatIndicatorLength = 4; private const int SchemaIdLength = 32; From 7008405c7b5c83551baf5642d747a76594ac57f0 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 15:01:33 -0700 Subject: [PATCH 32/45] First readme completed. --- .../Azure.Data.SchemaRegistry/README.md | 74 +++++++--------- .../SchemaRegistryClientSamples.HelloWorld.cs | 13 --- ...emaRegistryClientSamples.ReadmeSnippets.cs | 84 +++++++++++++++++-- .../SchemaRegistryClientSamples.HelloWorld.cs | 14 ---- 4 files changed, 106 insertions(+), 79 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md index e9281b6eb75af..88ccd4ef72f18 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md @@ -14,7 +14,7 @@ Install-Package Azure.Data.SchemaRegistry ### Prerequisites -* An [Azure subscription][azure_sub]. +* An [Azure subscription][azure_sub] * An [Event Hubs namespace][event_hubs_namespace] If you need to [create an Event Hubs namespace][create_event_hubs_namespace], you can use the Azure Portal or [Azure PowerShell][azure_powershell]. @@ -39,7 +39,7 @@ The simpliest way is to use the [Azure portal][azure_portal] and navigate to you #### Create SchemaRegistryClient -Once you have the Azure resource credentials and the Event Hubs namespace hostname, you can create the [SchemaRegistryClient][schema_registry_client]: +Once you have the Azure resource credentials and the Event Hubs namespace hostname, you can create the [SchemaRegistryClient][schema_registry_client]. You'll also need the [Azure.Identity][azure_identity] package to create the credential. ```C# Snippet:CreateSchemaRegistryClient string connectionString = ""; @@ -62,63 +62,46 @@ These components play different roles. Some are used as input into the operation ## Examples -* [Register a schema](#create-the-thing) -* [Retrieve a schema ID](#get-the-thing) -* [Retrieve a schema](#list-the-things) +The following shows examples of what is available through the SchemaRegistryClient. There are both sync and async methods available for these client operations. +* [Register a schema](#register-a-schema) +* [Retrieve a schema ID](#retrieve-a-schema-id) +* [Retrieve a schema](#retrieve-a-schema) +### Register a schema +Register a schema to be stored in the Azure Schema Registry. -Include code snippets and short descriptions for each task you listed in the [Introduction](#introduction) (the bulleted list). Briefly explain each operation, but include enough clarity to explain complex or otherwise tricky operations. - -If possible, use the same example snippets that your in-code documentation uses. For example, use the snippets in your `examples.py` that Sphinx ingests via its [literalinclude](https://www.sphinx-doc.org/en/1.5/markup/code.html?highlight=code%20examples#includes) directive. The `examples.py` file containing the snippets should reside alongside your package's code, and should be tested in an automated fashion. - -Each example in the *Examples* section starts with an H3 that describes the example. At the top of this section, just under the *Examples* H2, add a bulleted list linking to each example H3. Each example should deep-link to the types and/or members used in the example. - -* [Create the thing](#create-the-thing) -* [Get the thing](#get-the-thing) -* [List the things](#list-the-things) - -### Create the thing - -Use the [create_thing](not-valid-link) method to create a Thing reference; this method does not make a network call. To persist the Thing in the service, call [Thing.save](not-valid-link). - -```Python -thing = client.create_thing(id, name) -thing.save() +```C# Snippet:RegisterSchema +string connectionString = ""; +var client = new ConfigurationClient(connectionString); ``` -### Get the thing - -The [get_thing](not-valid-link) method retrieves a Thing from the service. The `id` parameter is the unique ID of the Thing, not its "name" property. +### Retrieve a schema ID -```C# Snippet:GetSecret -var client = new MiniSecretClient(new Uri(endpoint), new DefaultAzureCredential()); +Retrieve a previously registered schema ID from the Azure Schema Registry. -SecretBundle secret = client.GetSecret("TestSecret"); - -Console.WriteLine(secret.Value); -```Python -things = client.list_things() +```C# Snippet:RetrieveSchemaId +string connectionString = ""; +var client = new ConfigurationClient(connectionString); ``` -## Troubleshooting +### Retrieve a schema -Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery. +Retrieve a previously registered schema's content from the Azure Schema Registry. -Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API. - -If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code. +```C# Snippet:RetrieveSchema +string connectionString = ""; +var client = new ConfigurationClient(connectionString); +``` -## Next steps +## Contributing -* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory. -* If appropriate, point users to other packages that might be useful. -* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for. +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla]. -## Contributing +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. -This is a template, but your SDK readme should include details on how to contribute code to the repo/package. +This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][code_of_conduct_faq] or contact [opencode@microsoft.com][email_opencode] with any additional questions or comments. ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftemplate%2FAzure.Template%2FREADME.png) @@ -131,3 +114,8 @@ This is a template, but your SDK readme should include details on how to contrib [schema_registry_client]: src/SchemaRegistryClient.cs [azure_portal]: https://ms.portal.azure.com/ [schema_properties]: src/SchemaProperties.cs +[azure_identity]: https://www.nuget.org/packages/Azure.Identity +[cla]: https://cla.microsoft.com +[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ +[code_of_conduct_faq]: https://opensource.microsoft.com/codeofconduct/faq/ +[email_opencode]: mailto:opencode@microsoft.com diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs index 2cf37373da4f3..ffa8b5f589297 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs @@ -7,18 +7,5 @@ namespace Azure.Data.SchemaRegistry.Tests.Samples { public class SchemaRegistryClientSamples : SamplesBase { - //[Test] - //public void GettingASecret() - //{ - // var endpoint = TestEnvironment.SchemaRegistryUri; - - // #region Snippet:GetSecret - // var client = new SchemaRegistryClient(endpoint, new DefaultAzureCredential()); - - // //SecretBundle secret = client.GetSecret("TestSecret"); - - // //Console.WriteLine(secret.Value); - // #endregion - //} } } diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs index 7f559ae7ccfb3..b1543aba40ac3 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using Azure.Core.TestFramework; +using Azure.Identity; using NUnit.Framework; namespace Azure.Data.SchemaRegistry.Tests.Samples @@ -10,21 +11,86 @@ namespace Azure.Data.SchemaRegistry.Tests.Samples public class SchemaRegistryReadmeSnippets : SamplesBase #pragma warning restore SA1649 // File name should match first type name { + [Ignore("Only verifying that the sample builds")] [Test] public void CreateSchemaRegistryClient() { - var endpoint = TestEnvironment.SchemaRegistryUri; - var credentials = TestEnvironment.Credential; - #region Snippet:CreateSchemaRegistryClient - //@@ string endpoint = ""; - //@@ var credentials = new ClientSecretCredential( - //@@ "", - //@@ "", - //@@ "" - //@@ ); + string endpoint = ""; + var credentials = new ClientSecretCredential( + "", + "", + "" + ); var client = new SchemaRegistryClient(endpoint, credentials); #endregion } + + [Ignore("Only verifying that the sample builds")] + [Test] + public void RegisterSchema() + { + var client = new SchemaRegistryClient(TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential); + + #region Snippet:RegisterSchema + string schemaName = ""; + string groupName = ""; + SerializationType schemaType = SerializationType.Avro; + // Example schema's content + string schemaContent = @" +{ + ""type"" : ""record"", + ""namespace"" : ""TestSchema"", + ""name"" : ""Employee"", + ""fields"" : [ + { ""name"" : ""Name"" , ""type"" : ""string"" }, + { ""name"" : ""Age"", ""type"" : ""int"" } + ] +}"; + + Response schemaProperties = client.RegisterSchema(groupName, schemaName, schemaType, schemaContent); + #endregion + } + + [Ignore("Only verifying that the sample builds")] + [Test] + public void GetSchemaId() + { + var client = new SchemaRegistryClient(TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential); + + #region Snippet:GetSchemaId + string schemaName = ""; + string groupName = ""; + SerializationType schemaType = SerializationType.Avro; + // Example schema's content + string schemaContent = @" +{ + ""type"" : ""record"", + ""namespace"" : ""TestSchema"", + ""name"" : ""Employee"", + ""fields"" : [ + { ""name"" : ""Name"" , ""type"" : ""string"" }, + { ""name"" : ""Age"", ""type"" : ""int"" } + ] +}"; + + Response schemaProperties = client.GetSchemaId(groupName, schemaName, schemaType, schemaContent); + string schemaId = schemaProperties.Value.Id; + #endregion + } + + [Ignore("Only verifying that the sample builds")] + [Test] + public void GetSchema() + { + var client = new SchemaRegistryClient(TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential); + + #region Snippet:GetSchema + string schemaId = ""; + + Response schemaProperties = client.GetSchema(schemaId); + string schemaContent = schemaProperties.Value.Content; + #endregion + } } } diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs index 871969a77f9f3..1561ca50aa8c5 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs @@ -2,24 +2,10 @@ // Licensed under the MIT License. using Azure.Core.TestFramework; -using NUnit.Framework; namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.Samples { public class SchemaRegistryClientSamples : SamplesBase { - [Test] - public void GettingASecret() - { - var endpoint = TestEnvironment.SchemaRegistryUri; - - #region Snippet:GetSecret - //var client = new SchemaRegistryClient(endpoint, new DefaultAzureCredential()); - - //SecretBundle secret = client.GetSecret("TestSecret"); - - //Console.WriteLine(secret.Value); - #endregion - } } } From 63179361f09bedec7046f082d631fb5d9e1e7d7f Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 16:16:59 -0700 Subject: [PATCH 33/45] Finally! Created readmes and snippets. --- .../Azure.Data.SchemaRegistry/README.md | 52 +++++- .../SchemaRegistryClientSamples.HelloWorld.cs | 11 -- ...ets.cs => SchemaRegistryReadmeSnippets.cs} | 10 +- .../README.md | 160 +++++++++++------- .../SchemaRegistryClientSamples.HelloWorld.cs | 11 -- .../SchemaRegistrySerializerReadmeSnippets.cs | 63 +++++++ 6 files changed, 212 insertions(+), 95 deletions(-) delete mode 100644 sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs rename sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/{SchemaRegistryClientSamples.ReadmeSnippets.cs => SchemaRegistryReadmeSnippets.cs} (91%) delete mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md index 88ccd4ef72f18..8aac79c1ff5ab 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md @@ -42,8 +42,13 @@ The simpliest way is to use the [Azure portal][azure_portal] and navigate to you Once you have the Azure resource credentials and the Event Hubs namespace hostname, you can create the [SchemaRegistryClient][schema_registry_client]. You'll also need the [Azure.Identity][azure_identity] package to create the credential. ```C# Snippet:CreateSchemaRegistryClient -string connectionString = ""; -var client = new ConfigurationClient(connectionString); +string endpoint = ""; +var credentials = new ClientSecretCredential( + "", + "", + "" +); +var client = new SchemaRegistryClient(endpoint, credentials); ``` ## Key concepts @@ -73,8 +78,22 @@ The following shows examples of what is available through the SchemaRegistryClie Register a schema to be stored in the Azure Schema Registry. ```C# Snippet:RegisterSchema -string connectionString = ""; -var client = new ConfigurationClient(connectionString); + string schemaName = ""; + string groupName = ""; + SerializationType schemaType = SerializationType.Avro; + // Example schema's content + string schemaContent = @" +{ + ""type"" : ""record"", + ""namespace"" : ""TestSchema"", + ""name"" : ""Employee"", + ""fields"" : [ + { ""name"" : ""Name"" , ""type"" : ""string"" }, + { ""name"" : ""Age"", ""type"" : ""int"" } + ] +}"; + + Response schemaProperties = client.RegisterSchema(groupName, schemaName, schemaType, schemaContent); ``` ### Retrieve a schema ID @@ -82,8 +101,23 @@ var client = new ConfigurationClient(connectionString); Retrieve a previously registered schema ID from the Azure Schema Registry. ```C# Snippet:RetrieveSchemaId -string connectionString = ""; -var client = new ConfigurationClient(connectionString); + string schemaName = ""; + string groupName = ""; + SerializationType schemaType = SerializationType.Avro; + // Example schema's content + string schemaContent = @" +{ + ""type"" : ""record"", + ""namespace"" : ""TestSchema"", + ""name"" : ""Employee"", + ""fields"" : [ + { ""name"" : ""Name"" , ""type"" : ""string"" }, + { ""name"" : ""Age"", ""type"" : ""int"" } + ] +}"; + + Response schemaProperties = client.GetSchemaId(groupName, schemaName, schemaType, schemaContent); + string schemaId = schemaProperties.Value.Id; ``` ### Retrieve a schema @@ -91,8 +125,10 @@ var client = new ConfigurationClient(connectionString); Retrieve a previously registered schema's content from the Azure Schema Registry. ```C# Snippet:RetrieveSchema -string connectionString = ""; -var client = new ConfigurationClient(connectionString); +string schemaId = ""; + +Response schemaProperties = client.GetSchema(schemaId); +string schemaContent = schemaProperties.Value.Content; ``` ## Contributing diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs deleted file mode 100644 index ffa8b5f589297..0000000000000 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Azure.Core.TestFramework; - -namespace Azure.Data.SchemaRegistry.Tests.Samples -{ - public class SchemaRegistryClientSamples : SamplesBase - { - } -} diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryReadmeSnippets.cs similarity index 91% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryReadmeSnippets.cs index b1543aba40ac3..525c57b7feab0 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryClientSamples.ReadmeSnippets.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryReadmeSnippets.cs @@ -7,9 +7,7 @@ namespace Azure.Data.SchemaRegistry.Tests.Samples { -#pragma warning disable SA1649 // File name should match first type name public class SchemaRegistryReadmeSnippets : SamplesBase -#pragma warning restore SA1649 // File name should match first type name { [Ignore("Only verifying that the sample builds")] [Test] @@ -54,11 +52,11 @@ public void RegisterSchema() [Ignore("Only verifying that the sample builds")] [Test] - public void GetSchemaId() + public void RetrieveSchemaId() { var client = new SchemaRegistryClient(TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential); - #region Snippet:GetSchemaId + #region Snippet:RetrieveSchemaId string schemaName = ""; string groupName = ""; SerializationType schemaType = SerializationType.Avro; @@ -81,11 +79,11 @@ public void GetSchemaId() [Ignore("Only verifying that the sample builds")] [Test] - public void GetSchema() + public void RetrieveSchema() { var client = new SchemaRegistryClient(TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential); - #region Snippet:GetSchema + #region Snippet:RetrieveSchema string schemaId = ""; Response schemaProperties = client.GetSchema(schemaId); diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md index 3411f7736223f..c6208466bffac 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md @@ -1,104 +1,146 @@ -# README.md template +# Azure Schema Registry Apache Avro library for .NET -Use the guidelines in each section of this template to ensure consistency and readability of your README. The README resides in your package's GitHub repository at the root of its directory within the repo. It's also used as the package distribution page (NuGet, PyPi, npm, etc.) and as a Quickstart on docs.microsoft.com. See [README-EXAMPLE.md](README-EXAMPLE.md) for an example following this template. +This library provides an Apache Avro serialization and deserialization API using the Azure Schema Registry service. -**Title**: The H1 of your README should be in the format: `# [Product Name] client library for [Language]` +## Getting started -* All headings, including the H1, should use **sentence-style capitalization**. Refer to the [Microsoft Style Guide][style-guide-msft] and [Microsoft Cloud Style Guide][style-guide-cloud] for more information. -* Example: `# Azure Batch client library for Python` +### Install the package -# Azure Template client library for .NET +Install the Azure Schema Registry Apache Avro library for .NET with [NuGet][nuget]: -**Introduction**: The introduction appears directly under the title (H1) of your README. +```PowerShell +Install-Package Microsoft.Azure.Data.SchemaRegistry.ApacheAvro +``` -* **DO NOT** use an "Introduction" or "Overview" heading (H2) for this section. -* First sentence: **Describe the service** briefly. You can usually use the first line of the service's docs landing page for this (Example: [Cosmos DB docs landing page](https://docs.microsoft.com/azure/cosmos-db/)). -* Next, add a **bulleted list** of the **most common tasks** supported by the package or library, prefaced with "Use the client library for [Product Name] to:". Then, provide code snippets for these tasks in the [Examples](#examples) section later in the document. Keep the task list short but include those tasks most developers need to perform with your package. -* Include this single line of links targeting your product's content at the bottom of the introduction, making any adjustments as necessary (for example, NuGet instead of PyPi): +### Prerequisites - [Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/azure-batch) | [Package (PyPi)](https://pypi.org/project/azure-batch/) | [API reference documentation](https://docs.microsoft.com/python/api/overview/azure/batch?view=azure-python) | [Product documentation](https://docs.microsoft.com/azure/batch/) +* An [Azure subscription][azure_sub] +* An [Event Hubs namespace][event_hubs_namespace] -> TIP: Your README should be as **brief** as possible but **no more brief** than necessary to get a developer new to Azure, the service, or the package up and running quickly. Keep it brief, but include everything a developer needs to make their first API call successfully. +If you need to [create an Event Hubs namespace][create_event_hubs_namespace], you can use the Azure Portal or [Azure PowerShell][azure_powershell]. -## Getting started +You can use Azure PowerShell to create the Event Hubs namespace with the following command: -This section should include everything a developer needs to do to install and create their first client connection *very quickly*. +```PowerShell +New-AzEventHubNamespace -ResourceGroupName myResourceGroup -NamespaceName namespace_name -Location eastus +``` -### Install the package +### Authenticate the client -First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `pip install package-name`, but should enable a developer to successfully install the package from NuGet, pip, npm, Maven, or even cloning a GitHub repository. +In order to interact with the Azure Schema Registry service, you'll need to create an instance of the [Schema Registry Client][schema_registry_client] class. To create this client, you'll need Azure resource credentials and the Event Hubs namespace hostname. -### Prerequisites +#### Get credentials -Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB: +To acquire authenicated credentials and start interacting with Azure resources, please see the [quickstart guide here][quickstart_guide]. -> You must have an [Azure subscription](https://azure.microsoft.com/free/), [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API), and [Python 3.6+](https://www.python.org/downloads/) to use this package. +#### Get Event Hubs namespace hostname -### Authenticate the client +The simpliest way is to use the [Azure portal][azure_portal] and navigate to your Event Hubs namespace. From the Overview tab, you'll see `Host name`. Copy the value from this field. -If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating. +#### Create SchemaRegistryClient -For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object. +Once you have the Azure resource credentials and the Event Hubs namespace hostname, you can create the [SchemaRegistryClient][schema_registry_client]. You'll also need the [Azure.Identity][azure_identity] package to create the credential. -## Key concepts +```C# Snippet:CreateSchemaRegistryClient +string endpoint = ""; +var credentials = new ClientSecretCredential( + "", + "", + "" +); +var client = new SchemaRegistryClient(endpoint, credentials); +``` -The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity. +## Key concepts -## Examples +### ObjectSerializer -Include code snippets and short descriptions for each task you listed in the [Introduction](#introduction) (the bulleted list). Briefly explain each operation, but include enough clarity to explain complex or otherwise tricky operations. +This library provides a serializer, [SchemaRegistryAvroObjectSerializer][schema_registry_avro_serializer], that implements the [ObjectSerializer][object_serializer] abstract class. This allows a developer to use this serializer in any .NET Azure SDKs that utilize ObjectSerializer. The SchemaRegistryAvroObjectSerializer utilitizes a SchemaRegistryClient to construct messages using a wire format containing schema information such as a schema ID. -If possible, use the same example snippets that your in-code documentation uses. For example, use the snippets in your `examples.py` that Sphinx ingests via its [literalinclude](https://www.sphinx-doc.org/en/1.5/markup/code.html?highlight=code%20examples#includes) directive. The `examples.py` file containing the snippets should reside alongside your package's code, and should be tested in an automated fashion. +This serializer requires the [Apache Avro library][apache_avro_library]. The payload types accepted by this serializer include [GenericRecord][generic_record] and [ISpecificRecord][specific_record]. -Each example in the *Examples* section starts with an H3 that describes the example. At the top of this section, just under the *Examples* H2, add a bulleted list linking to each example H3. Each example should deep-link to the types and/or members used in the example. +### Wire Format -* [Create the thing](#create-the-thing) -* [Get the thing](#get-the-thing) -* [List the things](#list-the-things) +The serializer in this library creates messages in a wire format. The format is the following: -### Create the thing +- Bytes [0-3] – record format indicator – currently is \x00\x00\x00\x00 +- Bytes [4-35] – UTF-8 GUID, identifying the schema in a Schema Registry instance +- Bytes [36-end] – serialized payload bytes -Use the [create_thing](not-valid-link) method to create a Thing reference; this method does not make a network call. To persist the Thing in the service, call [Thing.save](not-valid-link). +## Examples -```Python -thing = client.create_thing(id, name) -thing.save() +The following shows examples of what is available through the SchemaRegistryAvroObjectSerializer. There are both sync and async methods available for these operations. These examples use a generated Apache Avro class [Employee.cs][employee] created using this schema: + +```json +{ + "type" : "record", + "namespace" : "TestSchema", + "name" : "Employee", + "fields" : [ + { "name" : "Name" , "type" : "string" }, + { "name" : "Age", "type" : "int" } + ] +} ``` -### Get the thing +Details on generating a class using the Apache Avro library can be found in the [Avro C# Documentation][avro_csharp_documentation]. -The [get_thing](not-valid-link) method retrieves a Thing from the service. The `id` parameter is the unique ID of the Thing, not its "name" property. +* [Serialize](#register-a-schema) +* [Deserialize](#retrieve-a-schema-id) -```C# Snippet:GetSecret -var client = new MiniSecretClient(new Uri(endpoint), new DefaultAzureCredential()); +### Serialize -SecretBundle secret = client.GetSecret("TestSecret"); +Register a schema to be stored in the Azure Schema Registry. -Console.WriteLine(secret.Value); -```Python -things = client.list_things() -``` - -## Troubleshooting +```C# Snippet:Serialize +var employee = new Employee { Age = 42, Name = "John Doe" }; +string groupName = ""; -Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery. +var memoryStream = new MemoryStream(); +var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); +serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); +``` -Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API. +### Deserialize -If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code. +Retrieve a previously registered schema ID from the Azure Schema Registry. -## Next steps +```C# Snippet:Deserialize +string groupName = ""; -* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory. -* If appropriate, point users to other packages that might be useful. -* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for. +var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); +memoryStream.Position = 0; +Employee employee = (Employee)serializer.Deserialize(memoryStream, typeof(Employee), CancellationToken.None); +``` ## Contributing -This is a template, but your SDK readme should include details on how to contribute code to the repo/package. +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla]. - -[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization -[style-guide-cloud]: https://worldready.cloudapp.net/Styleguide/Read?id=2696&topicid=25357 +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][code_of_conduct_faq] or contact [opencode@microsoft.com][email_opencode] with any additional questions or comments. ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftemplate%2FAzure.Template%2FREADME.png) + + +[nuget]: https://www.nuget.org/ +[event_hubs_namespace]: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-about +[azure_powershell]: https://docs.microsoft.com/en-us/powershell/azure/ +[create_event_hubs_namespace]: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-quickstart-powershell#create-an-event-hubs-namespace +[quickstart_guide]: https://github.com/Azure/azure-sdk-for-net/blob/master/doc/mgmt_preview_quickstart.md +[schema_registry_client]: src/SchemaRegistryClient.cs +[azure_portal]: https://ms.portal.azure.com/ +[schema_properties]: src/SchemaProperties.cs +[azure_identity]: https://www.nuget.org/packages/Azure.Identity +[cla]: https://cla.microsoft.com +[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ +[code_of_conduct_faq]: https://opensource.microsoft.com/codeofconduct/faq/ +[email_opencode]: mailto:opencode@microsoft.com +[object_serializer]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/src/Serialization/ObjectSerializer.cs +[schema_registry_avro_serializer]: src/SchemaRegistryAvroObjectSerializer.cs +[employee]: tests\Models\Employee.cs +[avro_csharp_documentation]: https://avro.apache.org/docs/current/api/csharp/html/index.html +[apache_avro_library]: https://www.nuget.org/packages/Apache.Avro/ +[generic_record]: https://avro.apache.org/docs/current/api/csharp/html/classAvro_1_1Generic_1_1GenericRecord.html +[specific_record]: https://avro.apache.org/docs/current/api/csharp/html/interfaceAvro_1_1Specific_1_1ISpecificRecord.html diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs deleted file mode 100644 index 1561ca50aa8c5..0000000000000 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistryClientSamples.HelloWorld.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Azure.Core.TestFramework; - -namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.Samples -{ - public class SchemaRegistryClientSamples : SamplesBase - { - } -} diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs new file mode 100644 index 0000000000000..908c019a1be36 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; +using Azure.Data.SchemaRegistry; +using Azure.Identity; +using NUnit.Framework; +using System.IO; +using System.Threading; +using TestSchema; + +namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.Samples +{ + public class SchemaRegistrySerializerReadmeSnippets : SamplesBase + { + [Ignore("Only verifying that the sample builds")] + [Test] + public void CreateSchemaRegistryClient() + { + #region Snippet:CreateSchemaRegistryClient + string endpoint = ""; + var credentials = new ClientSecretCredential( + "", + "", + "" + ); + var client = new SchemaRegistryClient(endpoint, credentials); + #endregion + } + + [Ignore("Only verifying that the sample builds")] + [Test] + public void Serialize() + { + var client = new SchemaRegistryClient(TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential); + + #region Snippet:Serialize + var employee = new Employee { Age = 42, Name = "John Doe" }; + string groupName = ""; + + var memoryStream = new MemoryStream(); + var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); + serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); + #endregion + } + + [Ignore("Only verifying that the sample builds")] + [Test] + public void Deserialize() + { + var client = new SchemaRegistryClient(TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential); + var memoryStream = new MemoryStream(); + + #region Snippet:Deserialize + string groupName = ""; + + var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); + memoryStream.Position = 0; + Employee employee = (Employee)serializer.Deserialize(memoryStream, typeof(Employee), CancellationToken.None); + #endregion + } + } +} From 713b987781a79740f648eddc06342867c53b9945 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 16:43:43 -0700 Subject: [PATCH 34/45] Put credential scope string into a constant. --- .../Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index 11943449a4637..8db24c474cd31 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -16,6 +16,7 @@ public class SchemaRegistryClient { private readonly ClientDiagnostics _clientDiagnostics; internal SchemaRestClient RestClient { get; } + private const string CredentialScope = "https://eventhubs.azure.net/.default"; /// /// Initializes a new instance of the . @@ -29,7 +30,7 @@ public class SchemaRegistryClient /// public SchemaRegistryClient(string endpoint, TokenCredential credential, SchemaRegistryClientOptions options) : this( new ClientDiagnostics(options), - HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, "https://eventhubs.azure.net/.default")), + HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, CredentialScope)), endpoint, options.Version) { From 09adad46d25a6252c2c8b6f97941e78a0f9394f9 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 16:53:49 -0700 Subject: [PATCH 35/45] Addressing a couple documentation PR comments and removed a code comment. --- .../Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs | 4 +++- .../src/SchemaRegistryClientOptions.cs | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index 8db24c474cd31..a33890e1e832b 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -10,7 +10,7 @@ namespace Azure.Data.SchemaRegistry { /// - /// The Schema Registry client. + /// The Schema Registry client provides operations to interact with the Schema Registry service. /// public class SchemaRegistryClient { @@ -80,6 +80,8 @@ public virtual async Task> RegisterSchemaAsync(string /// /// Registers a schema with the SchemaRegistry service. + /// If the schema did not previously exist in the Schema Registry instance, it is added to the instance and assigned a schema ID. + /// If the schema did previous exist in the Schema Registry instance, a new version of the schema is added to the instance and assigned a new schema ID. /// /// The name of the SchemaRegistry group. /// The name of the schema. diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs index 092698b010227..8b685ead1937b 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClientOptions.cs @@ -34,7 +34,6 @@ public enum ServiceVersion /// Version 2017-04 of the Schema Registry service. /// #pragma warning disable CA1707 // Remove the underscores from member name - // ReSharper disable once InconsistentNaming V2017_04 = 1 #pragma warning restore } From f331a513fcd6825a94cd653877c9563d2631c41e Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 17:01:39 -0700 Subject: [PATCH 36/45] Added global suppressions for namespace name. --- .../src/GlobalSuppressions.cs | 11 +++++++++++ .../src/SchemaRegistryAvroObjectSerializer.cs | 2 -- .../src/SchemaRegistryAvroObjectSerializerOptions.cs | 2 -- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/GlobalSuppressions.cs diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/GlobalSuppressions.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/GlobalSuppressions.cs new file mode 100644 index 0000000000000..46d6862a442c8 --- /dev/null +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/GlobalSuppressions.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Usage", "AZC0001:Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure", Justification = "", Scope = "namespace", Target = "~N:Microsoft.Azure.Data.SchemaRegistry.ApacheAvro")] diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs index 34999b34c1406..45dd707a87840 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializer.cs @@ -17,9 +17,7 @@ using System.Threading; using System.Threading.Tasks; -#pragma warning disable AZC0001 // Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro -#pragma warning restore AZC0001 // Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure { /// /// A implementation that uses for Avro serialization/deserialization. diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs index 9e134e38a6d6a..6942dcaadcbe7 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroObjectSerializerOptions.cs @@ -1,9 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#pragma warning disable AZC0001 // Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro -#pragma warning restore AZC0001 // Use one of the following pre-approved namespace groups (https://azure.github.io/azure-sdk/registered_namespaces.html): Azure.AI, Azure.Analytics, Azure.Data, Azure.DigitalTwins, Azure.Iot, Azure.Learn, Azure.Media, Azure.Management, Azure.Messaging, Azure.Search, Azure.Security, Azure.Storage, Azure.Template, Azure.Identity, Microsoft.Extensions.Azure { /// /// Options for . From 747e336040dc0ea6358630da2cf12e434fdab9ef Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 17:07:10 -0700 Subject: [PATCH 37/45] Forgot using for memory streams in tests and snippets. --- .../README.md | 2 +- .../Samples/SchemaRegistrySerializerReadmeSnippets.cs | 4 ++-- .../tests/SchemaRegistryAvroObjectSerializerLiveTest.cs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md index c6208466bffac..00ad22086ec74 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md @@ -96,7 +96,7 @@ Register a schema to be stored in the Azure Schema Registry. var employee = new Employee { Age = 42, Name = "John Doe" }; string groupName = ""; -var memoryStream = new MemoryStream(); +using var memoryStream = new MemoryStream(); var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); ``` diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs index 908c019a1be36..cee634b88b386 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs @@ -38,7 +38,7 @@ public void Serialize() var employee = new Employee { Age = 42, Name = "John Doe" }; string groupName = ""; - var memoryStream = new MemoryStream(); + using var memoryStream = new MemoryStream(); var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); #endregion @@ -49,7 +49,7 @@ public void Serialize() public void Deserialize() { var client = new SchemaRegistryClient(TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential); - var memoryStream = new MemoryStream(); + using var memoryStream = new MemoryStream(); #region Snippet:Deserialize string groupName = ""; diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs index b5fcf00aafdc9..5007c3947661f 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTest.cs @@ -35,7 +35,7 @@ public async Task CanSerializeAndDeserialize() var groupName = "miyanni_srgroup"; var employee = new Employee { Age = 42, Name = "Caketown" }; - var memoryStream = new MemoryStream(); + using var memoryStream = new MemoryStream(); var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); await serializer.SerializeAsync(memoryStream, employee, typeof(Employee), CancellationToken.None); @@ -56,7 +56,7 @@ public async Task CanSerializeAndDeserializeGenericRecord() record.Add("Name", "Caketown"); record.Add("Age", 42); - var memoryStream = new MemoryStream(); + using var memoryStream = new MemoryStream(); var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); await serializer.SerializeAsync(memoryStream, record, typeof(GenericRecord), CancellationToken.None); @@ -75,7 +75,7 @@ public async Task CannotSerializeUnsupportedType() var groupName = "miyanni_srgroup"; var timeZoneInfo = TimeZoneInfo.Utc; - var memoryStream = new MemoryStream(); + using var memoryStream = new MemoryStream(); var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); Assert.ThrowsAsync(async () => await serializer.SerializeAsync(memoryStream, timeZoneInfo, typeof(TimeZoneInfo), CancellationToken.None)); await Task.CompletedTask; @@ -87,7 +87,7 @@ public async Task CannotDeserializeUnsupportedType() var client = CreateClient(); var groupName = "miyanni_srgroup"; - var memoryStream = new MemoryStream(); + using var memoryStream = new MemoryStream(); var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); Assert.ThrowsAsync(async () => await serializer.DeserializeAsync(memoryStream, typeof(TimeZoneInfo), CancellationToken.None)); await Task.CompletedTask; From 3f1cd015ed67c0730a6a557b0c775fcf68664a78 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 17:15:39 -0700 Subject: [PATCH 38/45] Fixed bugged diagnostic scope names. Put scope names into constants. --- .../src/SchemaRegistryClient.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs index a33890e1e832b..81c75e3c81b40 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaRegistryClient.cs @@ -52,6 +52,10 @@ internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline _clientDiagnostics = clientDiagnostics; } + private const string RegisterSchemaScopeName = "SchemaRegistryClient.RegisterSchema"; + private const string GetSchemaIdScopeName = "SchemaRegistryClient.GetSchemaId"; + private const string GetSchemaScopeName = "SchemaRegistryClient.GetSchema"; + /// /// Registers a schema with the SchemaRegistry service. /// @@ -63,7 +67,7 @@ internal SchemaRegistryClient(ClientDiagnostics clientDiagnostics, HttpPipeline /// The properties of the schema. public virtual async Task> RegisterSchemaAsync(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { - using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); + using DiagnosticScope scope = _clientDiagnostics.CreateScope(RegisterSchemaScopeName); scope.Start(); try { @@ -91,7 +95,7 @@ public virtual async Task> RegisterSchemaAsync(string /// The properties of the schema. public virtual Response RegisterSchema(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { - using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.RegisterSchema"); + using DiagnosticScope scope = _clientDiagnostics.CreateScope(RegisterSchemaScopeName); scope.Start(); try { @@ -117,7 +121,7 @@ public virtual Response RegisterSchema(string groupName, strin /// The properties of the schema, including the schema ID provided by the service. public virtual async Task> GetSchemaIdAsync(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { - using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); + using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaIdScopeName); scope.Start(); try { @@ -143,7 +147,7 @@ public virtual async Task> GetSchemaIdAsync(string gr /// The properties of the schema, including the schema ID provided by the service. public virtual Response GetSchemaId(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { - using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); + using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaIdScopeName); scope.Start(); try { @@ -166,7 +170,7 @@ public virtual Response GetSchemaId(string groupName, string s /// The properties of the schema, including the schema content provided by the service. public virtual async Task> GetSchemaAsync(string schemaId, CancellationToken cancellationToken = default) { - using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); + using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaScopeName); scope.Start(); try { @@ -189,7 +193,7 @@ public virtual async Task> GetSchemaAsync(string sche /// The properties of the schema, including the schema content provided by the service. public virtual Response GetSchema(string schemaId, CancellationToken cancellationToken = default) { - using DiagnosticScope scope = _clientDiagnostics.CreateScope("SchemaRegistryClient.GetSchema"); + using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaScopeName); scope.Start(); try { From c87bb3b93adc2cf97570f624c21cbf4a1b260e5b Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 17:26:34 -0700 Subject: [PATCH 39/45] Updated ci configuration. Removed resources template since resources cannot be provisioned currently. --- sdk/schemaregistry/ci.yml | 14 ++--- sdk/schemaregistry/test-resources.json | 81 -------------------------- sdk/schemaregistry/tests.yml | 6 ++ 3 files changed, 13 insertions(+), 88 deletions(-) delete mode 100644 sdk/schemaregistry/test-resources.json create mode 100644 sdk/schemaregistry/tests.yml diff --git a/sdk/schemaregistry/ci.yml b/sdk/schemaregistry/ci.yml index d6e1f89cf0011..c4d4034627ce4 100644 --- a/sdk/schemaregistry/ci.yml +++ b/sdk/schemaregistry/ci.yml @@ -1,5 +1,4 @@ -# DO NOT EDIT THIS FILE -# This file is generated automatically and any changes will be lost. +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. trigger: branches: include: @@ -8,7 +7,7 @@ trigger: - release/* paths: include: - - sdk/template/ + - sdk/schemaregistry/ pr: branches: @@ -19,13 +18,14 @@ pr: - release/* paths: include: - - sdk/template/ + - sdk/schemaregistry/ + - eng/common/ extends: template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml parameters: - ServiceDirectory: template + ServiceDirectory: schemaregistry ArtifactName: packages Artifacts: - - name: Azure.Template - safeName: AzureTemplate \ No newline at end of file + - name: Azure.Data.SchemaRegistry + safeName: AzureDataSchemaRegistry \ No newline at end of file diff --git a/sdk/schemaregistry/test-resources.json b/sdk/schemaregistry/test-resources.json deleted file mode 100644 index 46c4dc7699972..0000000000000 --- a/sdk/schemaregistry/test-resources.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "baseName": { - "type": "string", - "defaultValue": "[resourceGroup().name]", - "metadata": { - "description": "The base resource name." - } - }, - "tenantId": { - "type": "string", - "defaultValue": "72f988bf-86f1-41af-91ab-2d7cd011db47", - "metadata": { - "description": "The tenant ID to which the application and resources belong." - } - }, - "testApplicationOid": { - "type": "string", - "defaultValue": "b3653439-8136-4cd5-aac3-2a9460871ca6", - "metadata": { - "description": "The client OID to grant access to test resources." - } - }, - "location": { - "type": "string", - "defaultValue": "[resourceGroup().location]", - "metadata": { - "description": "The location of the resource. By default, this is the same as the resource group." - } - } - }, - "variables": { - "azureKeyVaultUrl": "[format('https://{0}.vault.azure.net', parameters('baseName'))]" - }, - "resources": [ - { - "type": "Microsoft.KeyVault/vaults", - "apiVersion": "2016-10-01", - "name": "[parameters('baseName')]", - "location": "[parameters('location')]", - "properties": { - "sku": { - "family": "A", - "name": "premium" - }, - "tenantId": "[parameters('tenantId')]", - "accessPolicies": [ - { - "tenantId": "[parameters('tenantId')]", - "objectId": "[parameters('testApplicationOid')]", - "permissions": { - "secrets": [ - "get" - ] - } - } - ] - } - }, - { - "type": "Microsoft.KeyVault/vaults/secrets", - "name": "[concat(parameters('baseName'), '/TestSecret')]", - "apiVersion": "2016-10-01", - "location": "[parameters('location')]", - "dependsOn": [ - "[resourceId('Microsoft.KeyVault/vaults', parameters('baseName'))]" - ], - "properties": { - "value": "Very secret value" - } - } - ], - "outputs": { - "KEYVAULT_URL": { - "type": "string", - "value": "[variables('azureKeyVaultUrl')]" - } - } -} diff --git a/sdk/schemaregistry/tests.yml b/sdk/schemaregistry/tests.yml new file mode 100644 index 0000000000000..379b7aeb30ba8 --- /dev/null +++ b/sdk/schemaregistry/tests.yml @@ -0,0 +1,6 @@ +trigger: none + +extends: + template: ../../eng/pipelines/templates/jobs/archetype-sdk-tests.yml + parameters: + ServiceDirectory: schemaregistry \ No newline at end of file From e152c57c12cb93709b33fe39dfef31b68052d5af Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 17:33:21 -0700 Subject: [PATCH 40/45] Added the other package to CI. --- sdk/schemaregistry/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/schemaregistry/ci.yml b/sdk/schemaregistry/ci.yml index c4d4034627ce4..5697f59839ad5 100644 --- a/sdk/schemaregistry/ci.yml +++ b/sdk/schemaregistry/ci.yml @@ -28,4 +28,6 @@ extends: ArtifactName: packages Artifacts: - name: Azure.Data.SchemaRegistry - safeName: AzureDataSchemaRegistry \ No newline at end of file + safeName: AzureDataSchemaRegistry + - name: Microsoft.Azure.Data.SchemaRegistry.ApacheAvro + safeName: MicrosoftAzureDataSchemaRegistryApacheAvro \ No newline at end of file From ff50a0c65237ca26c6a01366b970ef6e65be74c2 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 17:40:10 -0700 Subject: [PATCH 41/45] Updated sample file names to match convention. --- ...hemaRegistryReadmeSnippets.cs => Sample01_ReadmeSnippets.cs} | 2 +- ...rySerializerReadmeSnippets.cs => Sample01_ReadmeSnippets.cs} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/{SchemaRegistryReadmeSnippets.cs => Sample01_ReadmeSnippets.cs} (97%) rename sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/{SchemaRegistrySerializerReadmeSnippets.cs => Sample01_ReadmeSnippets.cs} (95%) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryReadmeSnippets.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/Sample01_ReadmeSnippets.cs similarity index 97% rename from sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryReadmeSnippets.cs rename to sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/Sample01_ReadmeSnippets.cs index 525c57b7feab0..35ab0fecce87a 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/SchemaRegistryReadmeSnippets.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/Sample01_ReadmeSnippets.cs @@ -7,7 +7,7 @@ namespace Azure.Data.SchemaRegistry.Tests.Samples { - public class SchemaRegistryReadmeSnippets : SamplesBase + public class Sample01_ReadmeSnippets : SamplesBase { [Ignore("Only verifying that the sample builds")] [Test] diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/Sample01_ReadmeSnippets.cs similarity index 95% rename from sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs rename to sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/Sample01_ReadmeSnippets.cs index cee634b88b386..3daf069bca298 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/SchemaRegistrySerializerReadmeSnippets.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Samples/Sample01_ReadmeSnippets.cs @@ -11,7 +11,7 @@ namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.Tests.Samples { - public class SchemaRegistrySerializerReadmeSnippets : SamplesBase + public class Sample01_ReadmeSnippets : SamplesBase { [Ignore("Only verifying that the sample builds")] [Test] From 87348bef4434124fde829a1b56804ca7f805d9f7 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 17:49:32 -0700 Subject: [PATCH 42/45] Added missing readme links. --- sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md | 1 + .../Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md index 8aac79c1ff5ab..bc45e286d747d 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md @@ -155,3 +155,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ [code_of_conduct_faq]: https://opensource.microsoft.com/codeofconduct/faq/ [email_opencode]: mailto:opencode@microsoft.com +[azure_sub]: https://azure.microsoft.com/free/ diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md index 00ad22086ec74..9443a6b5bf64c 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md @@ -144,3 +144,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [apache_avro_library]: https://www.nuget.org/packages/Apache.Avro/ [generic_record]: https://avro.apache.org/docs/current/api/csharp/html/classAvro_1_1Generic_1_1GenericRecord.html [specific_record]: https://avro.apache.org/docs/current/api/csharp/html/interfaceAvro_1_1Specific_1_1ISpecificRecord.html +[azure_sub]: https://azure.microsoft.com/free/ From aa788616cf50d8dcae3ddcc79dc608fa7817db1c Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 17:56:06 -0700 Subject: [PATCH 43/45] Fixed the readme snippets so they don't format oddly. --- .../Azure.Data.SchemaRegistry/README.md | 26 +++++++------- .../tests/Samples/Sample01_ReadmeSnippets.cs | 36 +++++++++---------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md index bc45e286d747d..3076e13dfbef7 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md @@ -78,11 +78,11 @@ The following shows examples of what is available through the SchemaRegistryClie Register a schema to be stored in the Azure Schema Registry. ```C# Snippet:RegisterSchema - string schemaName = ""; - string groupName = ""; - SerializationType schemaType = SerializationType.Avro; - // Example schema's content - string schemaContent = @" +string schemaName = ""; +string groupName = ""; +SerializationType schemaType = SerializationType.Avro; +// Example schema's content +string schemaContent = @" { ""type"" : ""record"", ""namespace"" : ""TestSchema"", @@ -93,7 +93,7 @@ Register a schema to be stored in the Azure Schema Registry. ] }"; - Response schemaProperties = client.RegisterSchema(groupName, schemaName, schemaType, schemaContent); +Response schemaProperties = client.RegisterSchema(groupName, schemaName, schemaType, schemaContent); ``` ### Retrieve a schema ID @@ -101,11 +101,11 @@ Register a schema to be stored in the Azure Schema Registry. Retrieve a previously registered schema ID from the Azure Schema Registry. ```C# Snippet:RetrieveSchemaId - string schemaName = ""; - string groupName = ""; - SerializationType schemaType = SerializationType.Avro; - // Example schema's content - string schemaContent = @" +string schemaName = ""; +string groupName = ""; +SerializationType schemaType = SerializationType.Avro; +// Example schema's content +string schemaContent = @" { ""type"" : ""record"", ""namespace"" : ""TestSchema"", @@ -116,8 +116,8 @@ Retrieve a previously registered schema ID from the Azure Schema Registry. ] }"; - Response schemaProperties = client.GetSchemaId(groupName, schemaName, schemaType, schemaContent); - string schemaId = schemaProperties.Value.Id; +Response schemaProperties = client.GetSchemaId(groupName, schemaName, schemaType, schemaContent); +string schemaId = schemaProperties.Value.Id; ``` ### Retrieve a schema diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/Sample01_ReadmeSnippets.cs b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/Sample01_ReadmeSnippets.cs index 35ab0fecce87a..3e87ed29da3c0 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/Sample01_ReadmeSnippets.cs +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/tests/Samples/Sample01_ReadmeSnippets.cs @@ -36,15 +36,15 @@ public void RegisterSchema() SerializationType schemaType = SerializationType.Avro; // Example schema's content string schemaContent = @" -{ - ""type"" : ""record"", - ""namespace"" : ""TestSchema"", - ""name"" : ""Employee"", - ""fields"" : [ - { ""name"" : ""Name"" , ""type"" : ""string"" }, - { ""name"" : ""Age"", ""type"" : ""int"" } - ] -}"; + { + ""type"" : ""record"", + ""namespace"" : ""TestSchema"", + ""name"" : ""Employee"", + ""fields"" : [ + { ""name"" : ""Name"" , ""type"" : ""string"" }, + { ""name"" : ""Age"", ""type"" : ""int"" } + ] + }"; Response schemaProperties = client.RegisterSchema(groupName, schemaName, schemaType, schemaContent); #endregion @@ -62,15 +62,15 @@ public void RetrieveSchemaId() SerializationType schemaType = SerializationType.Avro; // Example schema's content string schemaContent = @" -{ - ""type"" : ""record"", - ""namespace"" : ""TestSchema"", - ""name"" : ""Employee"", - ""fields"" : [ - { ""name"" : ""Name"" , ""type"" : ""string"" }, - { ""name"" : ""Age"", ""type"" : ""int"" } - ] -}"; + { + ""type"" : ""record"", + ""namespace"" : ""TestSchema"", + ""name"" : ""Employee"", + ""fields"" : [ + { ""name"" : ""Name"" , ""type"" : ""string"" }, + { ""name"" : ""Age"", ""type"" : ""int"" } + ] + }"; Response schemaProperties = client.GetSchemaId(groupName, schemaName, schemaType, schemaContent); string schemaId = schemaProperties.Value.Id; From 7d9a67fb45a3330df7345f8ec8366d3305451ff1 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 18:04:33 -0700 Subject: [PATCH 44/45] Updated schema components descriptions. --- .../Azure.Data.SchemaRegistry/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md index 3076e13dfbef7..fdb4dbe1c5cd2 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md @@ -56,12 +56,12 @@ var client = new SchemaRegistryClient(endpoint, credentials); ### Schemas A schema has 6 components: -- Group Name -- Schema Name -- Schema ID -- Serialization Type -- Schema Content -- Schema Version +- Group Name: The name of the group of schemas in the Schema Registry instance. +- Schema Name: The name of the schema. +- Schema ID: The ID assigned by the Schema Registry instance for the schema. +- Serialization Type: The format used for serialization of the schema. For example, Avro. +- Schema Content: The string representation of the schema. +- Schema Version: The version assigned to the schema in the Schema Registry instance. These components play different roles. Some are used as input into the operations and some are outputs. Currently, [SchemaProperties][schema_properties] only exposes those properties that are potential outputs that are used in SchemaRegistry operations. Those exposed properties are `Content` and `Id`. From 03d9a62c2fed97c5ac516c2f190baf2e92edf975 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 4 Sep 2020 18:10:48 -0700 Subject: [PATCH 45/45] Fixed command to acquire packages. --- sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md | 4 ++-- .../Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md index fdb4dbe1c5cd2..ada3e75fe4367 100644 --- a/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md +++ b/sdk/schemaregistry/Azure.Data.SchemaRegistry/README.md @@ -8,8 +8,8 @@ The Azure Schema Registry service allows developers to provide and retrieve data Install the Azure Schema Registry client library for .NET with [NuGet][nuget]: -```PowerShell -Install-Package Azure.Data.SchemaRegistry +```bash +dotnet add package Azure.Data.SchemaRegistry --version 1.0.0-beta.1 ``` ### Prerequisites diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md index 9443a6b5bf64c..818fc3000022f 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md @@ -8,8 +8,8 @@ This library provides an Apache Avro serialization and deserialization API using Install the Azure Schema Registry Apache Avro library for .NET with [NuGet][nuget]: -```PowerShell -Install-Package Microsoft.Azure.Data.SchemaRegistry.ApacheAvro +```bash +dotnet add package Microsoft.Azure.Data.SchemaRegistry.ApacheAvro --version 1.0.0-beta.1 ``` ### Prerequisites