Skip to content

Commit

Permalink
Fix/1416 - Enable setting container create options on system modules …
Browse files Browse the repository at this point in the history
…in edge models (#1418)

* resolve #1416

* fix unit test

Co-authored-by: ben salim <salim.benahben@cgi.com>
  • Loading branch information
kbeaugrand and Sben65 authored Oct 26, 2022
1 parent 3db396a commit b44a21f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,13 @@
<MudTable Items="Model.SystemModules" Dense=true Hover=true Bordered=true Striped=true Elevation=0>
<ColGroup>
<col style="width: 15%;" />
<col style="width: 40%;" />
<col style="width: 15%;" />
<col style="width: 50%;" />
<col style="width: 10%;" />
</ColGroup>

<HeaderContent>
<MudTh Style="text-align: center">Module name</MudTh>
<MudTh Style="text-align: center">Image URI</MudTh>
<MudTh Style="text-align: center">Version</MudTh>
<MudTh Style="text-align: center">Detail</MudTh>
</HeaderContent>

Expand All @@ -91,9 +89,6 @@
<MudTd DataLabel="System module Image URI" Style="word-break: break-all;">
<MudTextField id=@nameof(EdgeModelSystemModule.ImageUri) @bind-Value="@sysModule.ImageUri" Margin="Margin.Dense" Label="Image URI" For="@(() => sysModule.ImageUri )" Variant="Variant.Outlined" />
</MudTd>
<MudTd DataLabel="System module version" Style="word-break: break-all;">
<MudTextField id=@nameof(EdgeModelSystemModule.SchemaVersion) @bind-Value="@sysModule.SchemaVersion" Margin="Margin.Dense" Label="Version" For="@(() => sysModule.SchemaVersion )" Variant="Variant.Outlined" />
</MudTd>
<MudTd DataLabel="See detail" Style="text-align: center;">
<MudButton Variant="Variant.Filled" id="@("editSystModuleButton_"+sysModule.Name)" OnClick="@(async () => await ShowSystemModuleDetail(sysModule))">Detail</MudButton>
</MudTd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Label="Module name"
Variant="Variant.Outlined"
For="@(()=> Module.Name)"
Required="true" />
Required="true" Disabled/>
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="@currentImageUri"
Expand All @@ -19,6 +19,16 @@
For="@(()=> Module.ImageUri)"
Required="true" />
</MudItem>
<MudItem xs="12">
<MudTextField @bind-Value="@currentContainerCreateOptions"
id=@nameof(EdgeModelSystemModule.ContainerCreateOptions)
Label="Container Create Options"
Variant="Variant.Outlined"
For="@(()=> Module.ContainerCreateOptions)" Lines="8" />
</MudItem>
<MudItem xs="12">
<MudAlert Severity="Severity.Info"><MudLink Href="https://learn.microsoft.com/en-us/azure/iot-edge/how-to-use-create-options" Target="_blank ">How to configure container create options for IoT Edge modules</MudLink></MudAlert>
</MudItem>
</MudGrid>

<MudTabs Elevation="1" Class="mt-10" Rounded="true" PanelClass="mt-6 scrollable-tab-content">
Expand Down Expand Up @@ -55,6 +65,7 @@

currentModuleName = Module.Name;
currentImageUri = Module.ImageUri;
currentContainerCreateOptions = Module.ContainerCreateOptions;
currentEnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>(Module.EnvironmentVariables.ToArray());
await Task.Delay(0);
IsLoading = false;
Expand All @@ -64,6 +75,7 @@
{
Module.Name = currentModuleName;
Module.ImageUri = currentImageUri;
Module.ContainerCreateOptions = currentContainerCreateOptions;
Module.EnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>(currentEnvironmentVariables.ToArray());
MudDialog.Close(DialogResult.Ok(true));
}
Expand Down
13 changes: 7 additions & 6 deletions src/AzureIoTHub.Portal.Server/Helpers/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,25 +227,26 @@ public static Dictionary<string, IDictionary<string, object>> GenerateModulesCon
{
var edgeAgentPropertiesDesired = new EdgeAgentPropertiesDesired();

if (string.IsNullOrEmpty(edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").ImageUri))
if (!string.IsNullOrEmpty(edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").ImageUri))
{
edgeAgentPropertiesDesired.SystemModules.EdgeAgent.Settings.Image = edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").ImageUri;
}

if (string.IsNullOrEmpty(edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").SchemaVersion))
if (!string.IsNullOrEmpty(edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").ContainerCreateOptions))
{
edgeAgentPropertiesDesired.SchemaVersion = edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").SchemaVersion;
edgeAgentPropertiesDesired.SystemModules.EdgeAgent.Settings.CreateOptions = edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").ContainerCreateOptions;
}

if (string.IsNullOrEmpty(edgeModel.SystemModules.Single(x => x.Name == "edgeHub").ImageUri))
if (!string.IsNullOrEmpty(edgeModel.SystemModules.Single(x => x.Name == "edgeHub").ImageUri))
{
edgeAgentPropertiesDesired.SystemModules.EdgeHub.Settings.Image = edgeModel.SystemModules.Single(x => x.Name == "edgeHub").ImageUri;
}

var edgeHubPropertiesDesired = GenerateRoutesContent(edgeModel.EdgeRoutes);
if (!string.IsNullOrEmpty(edgeModel.SystemModules.Single(x => x.Name == "edgeHub").SchemaVersion))

if (!string.IsNullOrEmpty(edgeModel.SystemModules.Single(x => x.Name == "edgeHub").ContainerCreateOptions))
{
edgeHubPropertiesDesired.SchemaVersion = edgeModel.SystemModules.Single(x => x.Name == "edgeHub").SchemaVersion;
edgeAgentPropertiesDesired.SystemModules.EdgeHub.Settings.CreateOptions = edgeModel.SystemModules.Single(x => x.Name == "edgeHub").ContainerCreateOptions;
}

foreach (var item in edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").EnvironmentVariables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class EdgeModelSystemModule

public string ImageUri { get; set; }

public string SchemaVersion { get; set; }
public string ContainerCreateOptions { get; set; }

public List<IoTEdgeModuleEnvironmentVariable> EnvironmentVariables { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task SystemModuleDialogMustCloseOnCLickOnCloseButton()
Value = Fixture.Create<string>()
}
},
SchemaVersion = "1.0"
ContainerCreateOptions = Fixture.Create<string>(),
};

var cut = RenderComponent<MudDialogProvider>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void GenerateModulesContentShouldReturnValue()
new EdgeModelSystemModule("edgeAgent")
{
ImageUri = "image",
SchemaVersion = "1.0",
ContainerCreateOptions = Guid.NewGuid().ToString(),
EnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>()
{
new IoTEdgeModuleEnvironmentVariable(){ Name ="test", Value = "test" }
Expand All @@ -193,7 +193,7 @@ public void GenerateModulesContentShouldReturnValue()
new EdgeModelSystemModule("edgeHub")
{
ImageUri = "image",
SchemaVersion = "1.0",
ContainerCreateOptions = Guid.NewGuid().ToString(),
EnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>()
{
new IoTEdgeModuleEnvironmentVariable(){ Name ="test", Value = "test" }
Expand Down

0 comments on commit b44a21f

Please sign in to comment.