Skip to content

Commit

Permalink
Merge pull request #2 from JMayrbaeurl/aasximport
Browse files Browse the repository at this point in the history
Added AASX command line tool
  • Loading branch information
JMayrbaeurl authored Feb 7, 2022
2 parents ebf7663 + c1bdd6d commit 63a4135
Show file tree
Hide file tree
Showing 37 changed files with 13,180 additions and 1 deletion.
23 changes: 22 additions & 1 deletion AAS API on Azure.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AAS Registry Service", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AAS Registry Service Tests", "src\aas-registry-service-tests\AAS Registry Service Tests.csproj", "{A4F5E0BC-2400-422E-9D38-6B82BB3E1347}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AAS WebApp Registry", "src\aas-api-webapp-registry\AAS WebApp Registry.csproj", "{B3AA9231-9B5E-4A71-AE05-57A687CD9097}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AAS WebApp Registry", "src\aas-api-webapp-registry\AAS WebApp Registry.csproj", "{B3AA9231-9B5E-4A71-AE05-57A687CD9097}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AASX Package Command line", "tools\aasx-cmdline\AASX Package Command line.csproj", "{ECD5A9BE-8210-4BA6-A1FC-F23A3F0C7B84}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AASX Package Command line Tests", "tools\aasx-cmdline-tests\AASX Package Command line Tests.csproj", "{5BBB7304-26FC-4690-BEF4-59782E720A68}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{D3185476-EC73-4773-BA8D-E19147F729AE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AASX Command line", "AASX Command line", "{803CDCDE-B5BD-4EE7-A873-68B352F0A275}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -102,10 +110,23 @@ Global
{B3AA9231-9B5E-4A71-AE05-57A687CD9097}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3AA9231-9B5E-4A71-AE05-57A687CD9097}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3AA9231-9B5E-4A71-AE05-57A687CD9097}.Release|Any CPU.Build.0 = Release|Any CPU
{ECD5A9BE-8210-4BA6-A1FC-F23A3F0C7B84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECD5A9BE-8210-4BA6-A1FC-F23A3F0C7B84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECD5A9BE-8210-4BA6-A1FC-F23A3F0C7B84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECD5A9BE-8210-4BA6-A1FC-F23A3F0C7B84}.Release|Any CPU.Build.0 = Release|Any CPU
{5BBB7304-26FC-4690-BEF4-59782E720A68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BBB7304-26FC-4690-BEF4-59782E720A68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BBB7304-26FC-4690-BEF4-59782E720A68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BBB7304-26FC-4690-BEF4-59782E720A68}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{ECD5A9BE-8210-4BA6-A1FC-F23A3F0C7B84} = {803CDCDE-B5BD-4EE7-A873-68B352F0A275}
{5BBB7304-26FC-4690-BEF4-59782E720A68} = {803CDCDE-B5BD-4EE7-A873-68B352F0A275}
{803CDCDE-B5BD-4EE7-A873-68B352F0A275} = {D3185476-EC73-4773-BA8D-E19147F729AE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3B9D5232-0DAC-44CB-B879-A2E20EC77D59}
EndGlobalSection
Expand Down
8 changes: 8 additions & 0 deletions tools/README.md
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 |

129 changes: 129 additions & 0 deletions tools/aasx command line.md
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 tools/aasx-cmdline-tests/AASX Package Command line Tests.csproj
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>
95 changes: 95 additions & 0 deletions tools/aasx-cmdline-tests/ADTAASRepoTests.cs
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; }
}
}
}
51 changes: 51 additions & 0 deletions tools/aasx-cmdline-tests/AbstractTestSupport.cs
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; }
}
}
Loading

0 comments on commit 63a4135

Please sign in to comment.