-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from JMayrbaeurl/aasximport
Added AASX command line tool
- Loading branch information
Showing
37 changed files
with
13,180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Asset Administration Shell - Tools for Azure services | ||
|
||
The following tools are provided to manage the lifecycle of the AAS Digital twin graph: | ||
|
||
| Tool | Description | | ||
| --- | --- | | ||
| [AASX Command line](aasx%20command%20line.md) | Imports the contents of an AASX package into an Azure Digital Twin instance | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Asset Administration Shell - AASX Command line tool | ||
|
||
A tool to work with Asset Administration Shell package files. E.g. importing contents of the files into an [Azure | ||
Digital Twin](https://docs.microsoft.com/en-us/azure/digital-twins/overview) instance using the | ||
[AAS DTDLv2 ontology](https://github.com/JMayrbaeurl/opendigitaltwins-assetadminstrationshell). | ||
|
||
**Basic usage** | ||
``` | ||
aasxcli subcommand [options] | ||
``` | ||
|
||
Available subcommands are: `import` and `list-all` | ||
|
||
| Command line syntax | Description | | ||
| --- | --- | | ||
| `aasxcli import` | Imports the contents of an AASX package into an Azure Digital Twin instance | | ||
| `aasxcli list-all` | Lists the contents of an AASX package file | | ||
|
||
**Global Parameters** | ||
|
||
`--url -u` | ||
|
||
Url of the Azure Digital Twins instance. E.g. `https://[Your ADT instance name].api.weu.digitaltwins.azure.net` | ||
|
||
`--file -f` | ||
|
||
File path to the [AASX package file](https://github.com/admin-shell-io/aas-specs). | ||
Currently Version 1.0 and [Version 2.0](https://github.com/admin-shell-io/aasx-package-explorer/tree/master/src/AasxCsharpLibrary/Resources/schemaV201) | ||
of the AASX package file format are supported. | ||
|
||
### aasxcli import | ||
|
||
Imports the contents of the AASX package file into an Azure Digital Twin instance | ||
|
||
``` | ||
aasxcli import --file --url [--ignoreConceptDescriptions] [--DeleteShellsBeforeImport] | ||
``` | ||
**Examples** | ||
|
||
Import the '01 Festo' sample shells into ADT replacing existing nodes | ||
``` | ||
aasxcli import -f ".\AASX Samples\01_Festo.aasx" --u "https://[Your ADT instance name].api.weu.digitaltwins.azure.net" | ||
``` | ||
|
||
Import the '01 Festo' sample shells into ADT and delete the existing shell first | ||
``` | ||
aasxcli import --DeleteShellsBeforeImport -f ".\AASX Samples\01_Festo.aasx" --u "https://[Your ADT instance name].api.weu.digitaltwins.azure.net" | ||
``` | ||
**Required Parameters** | ||
|
||
None | ||
|
||
**Optional Parameters** | ||
|
||
`--ignoreConceptDescriptions` | ||
|
||
Ignore the Concept Description entries in the AASX package file | ||
|
||
`--DeleteShellsBeforeImport` | ||
|
||
Delete the existing shell twins in the Azure Digital Twins instance before importing the new one | ||
|
||
### aasxcli list-all | ||
|
||
Lists the contents of an AASX package file | ||
|
||
``` | ||
aasxcli list-all --file --url | ||
``` | ||
**Examples** | ||
|
||
List all contents of the '01 Festo' sample | ||
``` | ||
aasxcli list-all -f ".\AASX Samples\01_Festo.aasx" --u "https://[Your ADT instance name].api.weu.digitaltwins.azure.net" | ||
``` | ||
|
||
```json | ||
{ | ||
"Shells": [ | ||
{ | ||
"IdType": "IRI", | ||
"Id": "smart.festo.com/demo/aas/1/1/454576463545648365874", | ||
"IdShort": "Festo_3S7PM0CP4BD" | ||
} | ||
], | ||
"Submodels": [ | ||
{ | ||
"IdType": "IRI", | ||
"Id": "www.company.com/ids/sm/4343_5072_7091_3242", | ||
"IdShort": "Nameplate" | ||
}, | ||
{ | ||
"IdType": "IRI", | ||
"Id": "www.company.com/ids/sm/2543_5072_7091_2660", | ||
"IdShort": "Document" | ||
}, | ||
{ | ||
"IdType": "IRI", | ||
"Id": "www.company.com/ids/sm/6053_5072_7091_5102", | ||
"IdShort": "Service" | ||
}, | ||
{ | ||
"IdType": "IRI", | ||
"Id": "www.company.com/ids/sm/6563_5072_7091_4267", | ||
"IdShort": "Identification" | ||
}, | ||
{ | ||
"IdType": "IRI", | ||
"Id": "smart.festo.com/demo/sm/instance/1/1/13B7CCD9BF7A3F24", | ||
"IdShort": "DeviceDescriptionFiles" | ||
} | ||
], | ||
"Assets": [ | ||
{ | ||
"IdType": "IRI", | ||
"Id": "HTTP://PK.FESTO.COM/3S7PM0CP4BD", | ||
"IdShort": "FPK_3s7plfdrs35" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
**Required Parameters** | ||
|
||
--url is currently required but ignored | ||
|
||
**Optional Parameters** | ||
|
||
None |
29 changes: 29 additions & 0 deletions
29
tools/aasx-cmdline-tests/AASX Package Command line Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<RootNamespace>AAS.AASX.CmdLine.Test</RootNamespace> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\aasx-cmdline\AASX Package Command line.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="appsettings.tests.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using Azure.Core.Pipeline; | ||
using Azure.DigitalTwins.Core; | ||
using Azure.Identity; | ||
using Microsoft.Extensions.Azure; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Net.Http; | ||
using static AdminShellNS.AdminShellV20; | ||
|
||
namespace AAS.AASX.CmdLine.Test | ||
{ | ||
[TestClass] | ||
public class ADTAASRepoTests | ||
{ | ||
private IAASRepo aasRepo; | ||
|
||
[TestMethod] | ||
public void TestFindTwinFor01_FestoAAS() | ||
{ | ||
var AASRef = new Reference(new Key(Key.AAS, true, Identification.IRI, "smart.festo.com/demo/aas/1/1/454576463545648365874")); | ||
Assert.IsFalse(String.IsNullOrEmpty(this.aasRepo.FindTwinForReference(AASRef).GetAwaiter().GetResult())); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFindTwinForNameplateOf01_FestoAAS() | ||
{ | ||
var NameplateRef = new Reference( | ||
new Key(Key.AAS, true, Identification.IRI, "smart.festo.com/demo/aas/1/1/454576463545648365874")); | ||
NameplateRef.Keys.Add(new Key(Key.Submodel, true, Identification.IdShort, "Nameplate")); | ||
|
||
Assert.AreEqual<string>("Submodel_27f89173-0ef5-486b-98f9-fa388395523a", | ||
this.aasRepo.FindTwinForReference(NameplateRef).GetAwaiter().GetResult()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFindTwinForPropertyOf01_FestoAAS() | ||
{ | ||
var propRef = new Reference( | ||
new Key(Key.AAS, true, Identification.IRI, "smart.festo.com/demo/aas/1/1/454576463545648365874")); | ||
propRef.Keys.Add(new Key(Key.Submodel, true, Identification.IdShort, "Nameplate")); | ||
propRef.Keys.Add(new Key("SubmodelElementCollection", true, Identification.IdShort, "Marking_RCM")); | ||
propRef.Keys.Add(new Key("Property", true, Identification.IdShort, "RCMLabelingPresent")); | ||
|
||
Assert.AreEqual<string>("Property_c31b62cf-5e8c-4917-be7e-467ca9fc6218", | ||
this.aasRepo.FindTwinForReference(propRef).GetAwaiter().GetResult()); | ||
} | ||
|
||
[TestInitialize] | ||
public void Setup() | ||
{ | ||
using IHost host = Host.CreateDefaultBuilder() | ||
.ConfigureServices((_, services) => | ||
{ | ||
ConfigureBasicServices(services, "https://aasadtdevjm.api.weu.digitaltwins.azure.net"); | ||
|
||
services.AddSingleton<IAASRepo, ADTAASRepo>(); | ||
}) | ||
.Build(); | ||
|
||
using IServiceScope serviceScope = host.Services.CreateScope(); | ||
IServiceProvider provider = serviceScope.ServiceProvider; | ||
|
||
this.aasRepo = provider.GetRequiredService<IAASRepo>(); | ||
} | ||
|
||
private static void ConfigureBasicServices(IServiceCollection services, string adtInstanceUrl) | ||
{ | ||
services.Configure<DigitalTwinsClientOptions>(options => options.ADTEndpoint = new Uri(adtInstanceUrl)); | ||
|
||
services.AddAzureClients(builder => | ||
{ | ||
builder.AddClient<DigitalTwinsClient, DigitalTwinsClientOptions>((options, provider) => | ||
{ | ||
var appOptions = provider.GetService<IOptions<DigitalTwinsClientOptions>>(); | ||
|
||
var credentials = new DefaultAzureCredential(); | ||
DigitalTwinsClient client = new DigitalTwinsClient(appOptions.Value.ADTEndpoint, | ||
credentials, new Azure.DigitalTwins.Core.DigitalTwinsClientOptions { Transport = new HttpClientTransport(new HttpClient()) }); | ||
return client; | ||
}); | ||
|
||
// First use DefaultAzureCredentials and second EnvironmentCredential to enable local docker execution | ||
builder.UseCredential(new ChainedTokenCredential(new DefaultAzureCredential(), new EnvironmentCredential())); | ||
}); | ||
} | ||
|
||
public class DigitalTwinsClientOptions | ||
{ | ||
public Uri ADTEndpoint { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Azure.Core.Pipeline; | ||
using Azure.DigitalTwins.Core; | ||
using Azure.Identity; | ||
using Microsoft.Extensions.Azure; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Options; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Text; | ||
|
||
namespace AAS.AASX.CmdLine.Test | ||
{ | ||
public abstract class AbstractTestSupport | ||
{ | ||
protected IConfiguration configuration; | ||
|
||
protected AbstractTestSupport() | ||
{ | ||
configuration = new ConfigurationBuilder().AddJsonFile("appsettings.tests.json").Build(); | ||
} | ||
|
||
protected static void ConfigureBasicServices(IServiceCollection services, string adtInstanceUrl) | ||
{ | ||
services.Configure<DigitalTwinsClientOptions>(options => options.ADTEndpoint = new Uri(adtInstanceUrl)); | ||
|
||
services.AddAzureClients(builder => | ||
{ | ||
builder.AddClient<DigitalTwinsClient, DigitalTwinsClientOptions>((options, provider) => | ||
{ | ||
var appOptions = provider.GetService<IOptions<DigitalTwinsClientOptions>>(); | ||
|
||
var credentials = new DefaultAzureCredential(); | ||
DigitalTwinsClient client = new DigitalTwinsClient(appOptions.Value.ADTEndpoint, | ||
credentials, new Azure.DigitalTwins.Core.DigitalTwinsClientOptions { Transport = new HttpClientTransport(new HttpClient()) }); | ||
return client; | ||
}); | ||
|
||
// First use DefaultAzureCredentials and second EnvironmentCredential to enable local docker execution | ||
builder.UseCredential(new ChainedTokenCredential(new DefaultAzureCredential(), new EnvironmentCredential())); | ||
}); | ||
} | ||
} | ||
|
||
public class DigitalTwinsClientOptions | ||
{ | ||
public Uri ADTEndpoint { get; set; } | ||
} | ||
} |
Oops, something went wrong.