Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(modelsRepo): Initial commit: Azure.Iot.ModelsRepository #18998

Merged
merged 22 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
01e199e
Initial Commit - Bring ModelRepository Project to the mono repo (#18706)
azabbasi Feb 12, 2021
1df6709
Use resx file and update formattings.
azabbasi Feb 16, 2021
0f86217
Add client diagnostics - Add sync APIs to RemoteFetcher and LocalFetc…
azabbasi Feb 16, 2021
b1de661
Add async methods to the ResolverClient (#18814)
azabbasi Feb 17, 2021
9a96df7
Add support for recorded tests. (#18836)
azabbasi Feb 18, 2021
b2d52a1
Refactor RepositoryHandler and ResolverClient (#18857)
azabbasi Feb 18, 2021
aa993b6
Refactor ModelQuery (#18843)
digimaun Feb 18, 2021
c4c4eb4
Rename Client to ModelsRepoClient (#18862)
azabbasi Feb 18, 2021
40896b9
Remove ResolverException in favor of RequestFailedException (#18874)
digimaun Feb 19, 2021
f784e78
Rename Repo to Repository and minor changes / Import samples project …
azabbasi Feb 24, 2021
39be362
Format changes/Remove resx file.
azabbasi Feb 24, 2021
6ee38a4
Add first draft of readme. Add comment for dtmi validation. (#18987)
digimaun Feb 24, 2021
b8fd02b
Merge branch 'feature/modelsRepo' of https://github.com/Azure/azure-s…
azabbasi Feb 24, 2021
4181b9c
Fix service directory spelling.
azabbasi Feb 24, 2021
829dfed
Update CHANGELOG.md
azabbasi Feb 24, 2021
1de46e1
Update CODEOWNERS
azabbasi Feb 24, 2021
a2059fd
Update CHANGELOG.md
azabbasi Feb 24, 2021
7e1e267
Use fluent assertion
azabbasi Feb 24, 2021
0e6ee79
CR comments
azabbasi Feb 24, 2021
34bdbcb
fix issues with build
azabbasi Feb 24, 2021
f88c4ab
Use playback as default
azabbasi Feb 24, 2021
f00448c
fix Links and root service directory casing
azabbasi Feb 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@
# ServiceLabel: %Digital Twins %Service Attention
/sdk/digitaltwins/ @drwill-ms @timtay-microsoft @abhipsaMisra @vinagesh @azabbasi @bikamani @barustum @jamdavi

# PRLabel: %IoT Model Repository
azabbasi marked this conversation as resolved.
Show resolved Hide resolved
# ServiceLabel: %IoT Model Repository %Service Attention
/sdk/modelrepository/ @drwill-ms @timtay-microsoft @abhipsaMisra @vinagesh @azabbasi @bikamani @barustum @jamdavi @digimaun

# PRLabel: %TimeSeriesInsights
# ServiceLabel: %TimeSeriesInsights %Service Attention
/sdk/timeseriesinsights/ @drwill-ms @timtay-microsoft @abhipsaMisra @vinagesh @azabbasi @bikamani @barustum @jamdavi @yeskarthik @rasidhan @dmdenmsft
Expand Down
1 change: 1 addition & 0 deletions sdk/modelsrepository/Azure.Iot.ModelsRepository/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Iot.ModelsRepository", "src\Azure.Iot.ModelsRepository.csproj", "{5E11A377-0D20-49F8-952B-50390196EF4B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Iot.ModelsRepository.Tests", "tests\Azure.Iot.ModelsRepository.Tests.csproj", "{092E6CE2-9998-428C-A801-2BAB4E14A577}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelsRepositoryClientSamples", "samples\ModelsRepositoryClientSamples\ModelsRepositoryClientSamples.csproj", "{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5E11A377-0D20-49F8-952B-50390196EF4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E11A377-0D20-49F8-952B-50390196EF4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E11A377-0D20-49F8-952B-50390196EF4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E11A377-0D20-49F8-952B-50390196EF4B}.Release|Any CPU.Build.0 = Release|Any CPU
{092E6CE2-9998-428C-A801-2BAB4E14A577}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{092E6CE2-9998-428C-A801-2BAB4E14A577}.Debug|Any CPU.Build.0 = Debug|Any CPU
{092E6CE2-9998-428C-A801-2BAB4E14A577}.Release|Any CPU.ActiveCfg = Release|Any CPU
{092E6CE2-9998-428C-A801-2BAB4E14A577}.Release|Any CPU.Build.0 = Release|Any CPU
{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}.Release|Any CPU.Build.0 = Release|Any CPU
{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {671D1EFB-2BB9-4846-91EF-A3FB1FF9DDA6}
EndGlobalSection
EndGlobal
19 changes: 19 additions & 0 deletions sdk/modelsrepository/Azure.Iot.ModelsRepository/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Release History

## 1.0.0-preview.1 (Unreleased)

### New features

- Initial preview of Azure.IoT.ModelsRepository SDK
azabbasi marked this conversation as resolved.
Show resolved Hide resolved

### Breaking changes

- N/A

### Added

- N/A

### Fixes and improvements

- N/A
41 changes: 41 additions & 0 deletions sdk/modelsrepository/Azure.Iot.ModelsRepository/CodeMaid.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="SteveCadwallader.CodeMaid.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<userSettings>
<SteveCadwallader.CodeMaid.Properties.Settings>
<setting name="Cleaning_AutoCleanupOnFileSave" serializeAs="String">
<value>True</value>
</setting>
<setting name="Formatting_CommentXmlSpaceSingleTags" serializeAs="String">
<value>True</value>
</setting>
<setting name="Cleaning_InsertEndOfFileTrailingNewLine" serializeAs="String">
<value>True</value>
</setting>
<setting name="Formatting_CommentWrapColumn" serializeAs="String">
<value>120</value>
</setting>
<setting name="Formatting_CommentRunDuringCleanup" serializeAs="String">
<value>False</value>
</setting>
<setting name="Cleaning_UpdateFileHeaderCSharp" serializeAs="String">
<value>// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
</value>
</setting>
<setting name="Reorganizing_PrimaryOrderByAccessLevel" serializeAs="String">
<value>True</value>
</setting>
<setting name="Cleaning_PerformPartialCleanupOnExternal" serializeAs="String">
<value>1</value>
</setting>
<setting name="Progressing_ShowBuildProgressOnBuildStart" serializeAs="String">
<value>False</value>
</setting>
</SteveCadwallader.CodeMaid.Properties.Settings>
</userSettings>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Add any shared properties you want for the projects under this package directory that need to be set before the auto imported Directory.Build.props
-->
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
</Project>
96 changes: 96 additions & 0 deletions sdk/modelsrepository/Azure.Iot.ModelsRepository/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Azure IoT Models Repository client library for .NET

This library provides functionality for interacting with the [Azure IoT Models Repository][modelsrepository_iot_endpoint]. It also aims to provide a consistent experience working with digital twin model repositories following Azure IoT conventions.

[Source code][source] | [Package (nuget)][package]

## Getting started

The complete Microsoft Azure SDK can be downloaded from the [Microsoft Azure downloads][microsoft_sdk_download] page, and it ships with support for building deployment packages, integrating with tooling, rich command-line tooling, and more.

For the best development experience, developers should use the official Microsoft NuGet packages for libraries. NuGet packages are regularly updated with new functionality and bug fixes.

### Install the package

Install the Azure IoT Models Repository client library for .NET with [NuGet][nuget]:

```PowerShell
Install-Package Azure.Iot.ModelsRepository
```

View the package details at [nuget.org][modelsrepository_nuget].

### Prerequisites

- A models repository following [Azure IoT conventions][modelsrepository_conventions]
- The models repository can be located on the local filesystem or hosted on a webserver.
- Azure IoT hosts the global [Azure IoT Models Repository][modelsrepository_iot_endpoint] which the client will point to by default if no URI is provided.

### Authenticate the client

Currently no authentication mechanisms are supported in the client. The global endpoint is not tied to an Azure subscription and does not support auth. All models published are meant for anonymous public consumption.

## Key concepts

The Azure IoT Models Repository enables builders to manage and share digital twin models. The models are [JSON-LD][json_ld_reference] documents defined using the Digital Twins Definition Language ([DTDL][dtdlv2_reference]).

The repository defines a pattern to store DTDL interfaces in a directory structure based on the Digital Twin Model Identifier (DTMI). You can locate an interface in the repository by converting the DTMI to a relative path. For example, the DTMI "`dtmi:com:example:Thermostat;1`" translates to `/dtmi/com/example/thermostat-1.json`.

### Thread safety

We guarantee that all client instance methods are thread-safe and independent of each other. See thread safety [guideline][thread_safety_guideline]. This ensures that the recommendation of reusing client instances is always safe, even across threads.

### Additional concepts

<!-- CLIENT COMMON BAR -->
[Client options](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#configuring-service-clients-using-clientoptions) |
[Accessing the response](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#accessing-http-response-details-using-responset) |
[Long-running operations](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#consuming-long-running-operations-using-operationt) |
[Handling failures](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#reporting-errors-requestfailedexception) |
[Diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md) |
[Mocking](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#mocking) |
[Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/)
<!-- CLIENT COMMON BAR -->

## Examples

You can familiarize yourself with the client using [samples for IoT Models Repository][modelsrepository_samples].

## Troubleshooting

All service operations will throw RequestFailedException on failure, with helpful error codes and other information. The client also produces diagnostic events and logging which can be listened to with an [EventListener][eventsourcelistener_reference].

## Next steps

See implementation examples with our [code samples][modelsrepository_samples].

## Contributing

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 <https://cla.microsoft.com.>

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 [email protected] with any additional questions or comments.

<!-- LINKS -->
[microsoft_sdk_download]: https://azure.microsoft.com/downloads/?sdk=net
[azure_sdk_target_frameworks]: https://github.com/azure/azure-sdk-for-net#target-frameworks
[source]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/modelsrepository/Azure.Iot.ModelsRepository/src
[package]: https://www.nuget.org/packages/Azure.Iot.ModelsRepository
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[code_of_conduct_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[nuget]: https://www.nuget.org/
[azure_core_library]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/core/Azure.Core
[modelsrepository_nuget]: https://www.nuget.org/packages/Azure.Iot.ModelsRepository
[modelsrepository_conventions]: https://github.com/Azure/iot-plugandplay-models-tools/wiki
[modelsrepository_iot_endpoint]: https://devicemodels.azure.com/
[modelsrepository_samples]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/modelsrepository/Azure.Iot.ModelsRepository/samples
[thread_safety_guideline]: https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety
[json_ld_reference]: https://json-ld.org
[dtdlv2_reference]: https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v2/dtdlv2.md
[eventsourcelistener_reference]: https://docs.microsoft.com/en-us/dotnet/api/azure.core.diagnostics.azureeventsourcelistener?view=azure-dotnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1;net5.0</TargetFramework>
<RootNamespace>Azure.Iot.ModelsRepository.Samples</RootNamespace>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\readme.md" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Azure.Iot.ModelsRepository.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Core.Diagnostics;
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Net;
using System.Threading.Tasks;

namespace Azure.Iot.ModelsRepository.Samples
{
public class Program
{
public static async Task Main(string[] args)
{
// Forward all the events written to the console output with a specific format.
using AzureEventSourceListener listener = new AzureEventSourceListener(
(e, message) =>
Console.WriteLine("[{0:HH:mm:ss:fff}][{1}] {2}", DateTimeOffset.Now, e.Level, message),
level: EventLevel.Verbose);

await ResolveExistingAsync();
await TryResolveButNotFoundAsync();
}

private static async Task ResolveExistingAsync()
{
var dtmi = "dtmi:com:example:TemperatureController;1";
azabbasi marked this conversation as resolved.
Show resolved Hide resolved
var client = new ModelsRepositoryClient();

IDictionary<string, string> models = await client.ResolveAsync(dtmi).ConfigureAwait(false);

Console.WriteLine($"{dtmi} resolved in {models.Count} interfaces.");
}

private static async Task TryResolveButNotFoundAsync()
{
var dtmi = "dtmi:com:example:NotFound;1";
var client = new ModelsRepositoryClient();

try
{
IDictionary<string, string> models = await client.ResolveAsync(dtmi).ConfigureAwait(false);
Console.WriteLine($"{dtmi} resolved in {models.Count} interfaces.");
}
catch (RequestFailedException ex) when (ex.Status == (int)HttpStatusCode.NotFound)
{
Console.WriteLine($"{dtmi} was not found in the default public models repository: {ex.Message}");
}
}
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyTitle>Azure IoT Models Repository SDK</AssemblyTitle>
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<!-- Nuget properties -->
<PropertyGroup>
<PackageTags>IoT;ModelsRepository;Pnp;DigitalTwins$(PackageCommonTags)</PackageTags>
<Description>SDK for the Azure IoT Models Repository</Description>
<Version>1.0.0-preview.1</Version>
digimaun marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>


<ItemGroup>
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<!-- Common source from Azure.Core -->
<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)ArrayBufferWriter.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
<Compile Include="$(AzureCoreSharedSources)ClientDiagnostics.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
<Compile Include="$(AzureCoreSharedSources)ContentTypeUtilities.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
<Compile Include="$(AzureCoreSharedSources)DiagnosticScope.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
<Compile Include="$(AzureCoreSharedSources)DiagnosticScopeFactory.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
<Compile Include="$(AzureCoreSharedSources)HttpMessageSanitizer.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
<Compile Include="$(AzureCoreSharedSources)TaskExtensions.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
<Compile Include="$(AzureCoreSharedSources)OperationHelpers.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
<Compile Include="$(AzureCoreSharedSources)Argument.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs">
<LinkBase>Shared\Azure.Core</LinkBase>
</Compile>
</ItemGroup>

<Import Project="$(RepoRoot)\sdk\core\Azure.Core\src\Azure.Core.props" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.Iot.ModelsRepository
{
/// <summary>
/// The dependency processing options.
/// </summary>
public enum DependencyResolutionOption
{
/// <summary>
/// Do not process external dependencies.
/// </summary>
Disabled,

/// <summary>
/// Enable external dependencies.
/// </summary>
Enabled,

/// <summary>
/// Try to get external dependencies using .expanded.json.
/// </summary>
TryFromExpanded
}
}
Loading