Skip to content

Commit

Permalink
#3023 startupOrder not supported in Edge Device Model schema
Browse files Browse the repository at this point in the history
  • Loading branch information
E068097 committed Dec 3, 2024
1 parent f9eb5ab commit 31c5063
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 12 deletions.
14 changes: 13 additions & 1 deletion src/IoTHub.Portal.Application/Helpers/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public static IoTEdgeModule CreateGatewayModule(Configuration config, JProperty
ModuleName = module.Name,
Image = module.Value["settings"]?["image"]?.Value<string>(),
ContainerCreateOptions = module.Value["settings"]?["createOptions"]?.Value<string>(),
StartupOrder = module.Value["settings"]?["startupOrder"]?.Value<int>() ?? 0,
Status = module.Value["status"]?.Value<string>(),
};

Expand Down Expand Up @@ -229,6 +230,11 @@ public static Dictionary<string, IDictionary<string, object>> GenerateModulesCon
edgeAgentPropertiesDesired.SystemModules.EdgeAgent.Settings.CreateOptions = edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").ContainerCreateOptions;
}

if (edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").StartupOrder > 0)
{
edgeAgentPropertiesDesired.SystemModules.EdgeAgent.Settings.StartupOrder = edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").StartupOrder;
}

if (!string.IsNullOrEmpty(edgeModel.SystemModules.Single(x => x.Name == "edgeHub").Image))
{
edgeAgentPropertiesDesired.SystemModules.EdgeHub.Settings.Image = edgeModel.SystemModules.Single(x => x.Name == "edgeHub").Image;
Expand All @@ -241,6 +247,11 @@ public static Dictionary<string, IDictionary<string, object>> GenerateModulesCon
edgeAgentPropertiesDesired.SystemModules.EdgeHub.Settings.CreateOptions = edgeModel.SystemModules.Single(x => x.Name == "edgeHub").ContainerCreateOptions;
}

if (edgeModel.SystemModules.Single(x => x.Name == "edgeHub").StartupOrder > 0)
{
edgeAgentPropertiesDesired.SystemModules.EdgeHub.Settings.StartupOrder = edgeModel.SystemModules.Single(x => x.Name == "edgeHub").StartupOrder;
}

foreach (var item in edgeModel.SystemModules.Single(x => x.Name == "edgeAgent").EnvironmentVariables)
{
edgeAgentPropertiesDesired.SystemModules.EdgeAgent.EnvironmentVariables?.Add(item.Name, new EnvironmentVariable() { EnvValue = item.Value });
Expand All @@ -262,7 +273,8 @@ public static Dictionary<string, IDictionary<string, object>> GenerateModulesCon
Settings = new ModuleSettings()
{
Image = module.Image,
CreateOptions = module.ContainerCreateOptions
CreateOptions = module.ContainerCreateOptions,
StartupOrder = module.StartupOrder,
},
RestartPolicy = "always",
EnvironmentVariables = new Dictionary<string, EnvironmentVariable>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
<DialogContent>
<MudContainer Style="max-height: 600px; overflow-y: scroll">
<MudGrid>
<MudItem xs="12" md="6">
<MudItem xs="12" md="4">
<MudTextField @bind-Value="@currentModuleName"
id=@nameof(IoTEdgeModule.ModuleName)
Label="Module name"
Variant="Variant.Outlined"
For="@(() => Module.ModuleName)"
Required="true"/>
</MudItem>
<MudItem xs="12" md="2">
<MudTextField @bind-Value="@currentStartupOrder"
id=@nameof(IoTEdgeModule.StartupOrder)
Label="Startup Order"
Variant="Variant.Outlined"
For="@(() => Module.StartupOrder)"
Required="false" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="@currentImage"
id=@nameof(IoTEdgeModule.Image)
Expand Down Expand Up @@ -87,6 +95,7 @@
private string currentImage = default!;
private string currentContainerCreateOptions = default!;
private string currentNumVersion = "1.0.0";
private int currentStartupOrder;

private List<IoTEdgeModuleEnvironmentVariable> currentEnvironmentVariables = new();
private List<IoTEdgeModuleTwinSetting> currentModuleIdentityTwinSettings = new();
Expand All @@ -103,6 +112,7 @@
currentImage = Module.Image;
currentContainerCreateOptions = Module.ContainerCreateOptions;
currentNumVersion = Module.Version;
currentStartupOrder = Module.StartupOrder;
currentEnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>(Module.EnvironmentVariables.ToArray());
currentModuleIdentityTwinSettings = new List<IoTEdgeModuleTwinSetting>(Module.ModuleIdentityTwinSettings.ToArray());
currentCommands = new List<IoTEdgeModuleCommand>(Module.Commands.ToArray());
Expand All @@ -115,6 +125,7 @@
Module.ModuleName = currentModuleName;
Module.Image = currentImage;
Module.ContainerCreateOptions = currentContainerCreateOptions;
Module.StartupOrder = currentStartupOrder;

if (Portal.CloudProvider.Equals(CloudProviders.Azure)) { Module.Version = " "; }
else { Module.Version = currentNumVersion; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
<DialogContent>
<MudContainer Style="max-height: 600px; overflow-y: scroll">
<MudGrid>
<MudItem xs="12" md="6">
<MudItem xs="12" md="4">
<MudTextField @bind-Value="@currentModuleName"
id=@nameof(EdgeModelSystemModule.Name)
Label="Module name"
Variant="Variant.Outlined"
For="@(()=> Module.Name)"
Required="true" Disabled/>
</MudItem>
<MudItem xs="12" md="2">
<MudTextField @bind-Value="@currentStartupOrder"
id=@nameof(EdgeModelSystemModule.StartupOrder)
Label="Startup Order"
Variant="Variant.Outlined"
For="@(() => Module.StartupOrder)"
Required="false" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="@currentImage"
id=@nameof(EdgeModelSystemModule.Image)
Expand Down Expand Up @@ -45,7 +53,7 @@
</DialogActions>
</MudDialog>

@code {
@code {
[CascadingParameter]
MudDialogInstance MudDialog { get; set; } = default!;

Expand All @@ -55,6 +63,7 @@
private string currentModuleName = default!;
private string currentImage = default!;
private string currentContainerCreateOptions = default!;
private int currentStartupOrder;

private List<IoTEdgeModuleEnvironmentVariable> currentEnvironmentVariables = new();

Expand All @@ -67,6 +76,7 @@
currentModuleName = Module.Name;
currentImage = Module.Image;
currentContainerCreateOptions = Module.ContainerCreateOptions;
currentStartupOrder = Module.StartupOrder;
currentEnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>(Module.EnvironmentVariables.ToArray());
await Task.Delay(0);
IsLoading = false;
Expand All @@ -77,6 +87,7 @@
Module.Name = currentModuleName;
Module.Image = currentImage;
Module.ContainerCreateOptions = currentContainerCreateOptions;
Module.StartupOrder = currentStartupOrder;
Module.EnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>(currentEnvironmentVariables.ToArray());
MudDialog.Close(DialogResult.Ok(true));
}
Expand Down
1 change: 1 addition & 0 deletions src/IoTHub.Portal.Server/Services/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public async Task<List<EdgeModelSystemModule>> GetModelSystemModule(string model
Image = newModule.Image,
EnvironmentVariables = newModule.EnvironmentVariables,
ContainerCreateOptions = newModule.ContainerCreateOptions,
StartupOrder = newModule.StartupOrder
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/IoTHub.Portal.Shared/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
global using IoTHub.Portal.Shared.Constants;
global using IoTHub.Portal.Shared.Models;
global using IoTHub.Portal.Shared.Models.v10;
global using Newtonsoft.Json;
2 changes: 1 addition & 1 deletion src/IoTHub.Portal.Shared/Models/DevicePropertyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace IoTHub.Portal.Models
/// <summary>
/// Device property type.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))]
public enum DevicePropertyType
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/IoTHub.Portal.Shared/Models/v1.0/EdgeModelSystemModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class EdgeModelSystemModule

public string ContainerCreateOptions { get; set; } = default!;

public int StartupOrder { get; set; }

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

public EdgeModelSystemModule(string name)
Expand Down
2 changes: 2 additions & 0 deletions src/IoTHub.Portal.Shared/Models/v1.0/IoTEdgeModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class IoTEdgeModule

public string ContainerCreateOptions { get; set; } = default!;

public int StartupOrder { get; set; }

/// <summary>
/// The module status.
/// </summary>
Expand Down
19 changes: 15 additions & 4 deletions src/IoTHub.Portal.Shared/Models/v1.0/IoTEdgeModule/ConfigModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ namespace IoTHub.Portal.Shared.Models.v10.IoTEdgeModule
public class ConfigModule
{
[JsonPropertyName("settings")]
[JsonProperty(PropertyName = "settings")]
public ModuleSettings Settings { get; set; }

[JsonPropertyName("type")]
[JsonProperty(PropertyName = "type")]
public string Type { get; set; } = default!;

[JsonPropertyName("env")]
//, NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty(PropertyName = "env", NullValueHandling = NullValueHandling.Ignore)]
public IDictionary<string, EnvironmentVariable>? EnvironmentVariables { get; set; }

[JsonPropertyName("status")]/*, NullValueHandling = NullValueHandling.Ignore)]*/
[JsonPropertyName("status")]
[JsonProperty(PropertyName = "status", NullValueHandling = NullValueHandling.Ignore)]
public string? Status { get; set; }

[JsonPropertyName("restartPolicy")]/*, NullValueHandling = NullValueHandling.Ignore)]*/
[JsonPropertyName("restartPolicy")]
[JsonProperty(PropertyName = "restartPolicy", NullValueHandling = NullValueHandling.Ignore)]
public string? RestartPolicy { get; set; }

public ConfigModule()
Expand All @@ -32,15 +36,22 @@ public ConfigModule()
public class ModuleSettings
{
[JsonPropertyName("image")]
[JsonProperty(PropertyName = "image")]
public string Image { get; set; } = default!;

[JsonPropertyName("createOptions")]/*, NullValueHandling = NullValueHandling.Ignore)]*/
[JsonPropertyName("createOptions")]
[JsonProperty(PropertyName = "createOptions", NullValueHandling = NullValueHandling.Ignore)]
public string CreateOptions { get; set; } = default!;

[JsonPropertyName("startupOrder")]
[JsonProperty(PropertyName = "startupOrder", NullValueHandling = NullValueHandling.Ignore)]
public int StartupOrder { get; set; } = 0;
}

public class EnvironmentVariable
{
[JsonPropertyName("value")]
[JsonProperty(PropertyName = "value")]
public string EnvValue { get; set; } = default!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ namespace IoTHub.Portal.Shared.Models.v10.IoTEdgeModule
public class EdgeAgentPropertiesDesired
{
[JsonPropertyName("modules")]
[JsonProperty(PropertyName = "modules")]
public IDictionary<string, ConfigModule> Modules { get; set; }

[JsonPropertyName("runtime")]
[JsonProperty(PropertyName = "runtime")]
public Runtime Runtime { get; set; }

[JsonPropertyName("schemaVersion")]
[JsonProperty(PropertyName = "schemaVersion")]
public string SchemaVersion { get; set; }

[JsonPropertyName("systemModules")]
[JsonProperty(PropertyName = "systemModules")]
public SystemModules SystemModules { get; set; }

public EdgeAgentPropertiesDesired()
Expand All @@ -29,9 +33,11 @@ public EdgeAgentPropertiesDesired()
public class Runtime
{
[JsonPropertyName("settings")]
[JsonProperty(PropertyName = "settings")]
public RuntimeSettings Settings { get; set; }

[JsonPropertyName("type")]
[JsonProperty(PropertyName = "type")]
public string Type { get; set; }

public Runtime()
Expand All @@ -44,6 +50,7 @@ public Runtime()
public class RuntimeSettings
{
[JsonPropertyName("minDockerVersion")]
[JsonProperty(PropertyName = "minDockerVersion")]
public string MinDockerVersion { get; set; }

public RuntimeSettings()
Expand All @@ -55,9 +62,11 @@ public RuntimeSettings()
public class SystemModules
{
[JsonPropertyName("edgeAgent")]
[JsonProperty(PropertyName = "edgeAgent")]
public ConfigModule EdgeAgent { get; set; }

[JsonPropertyName("edgeHub")]
[JsonProperty(PropertyName = "edgeHub")]
public ConfigModule EdgeHub { get; set; }

public SystemModules()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ namespace IoTHub.Portal.Shared.Models.v10.IoTEdgeModule
public class EdgeHubPropertiesDesired
{
[JsonPropertyName("routes")]
[JsonProperty(PropertyName = "routes")]
public IDictionary<string, object> Routes { get; set; }

[JsonPropertyName("schemaVersion")]
[JsonProperty(PropertyName = "schemaVersion")]
public string SchemaVersion { get; set; }

[JsonPropertyName("storeAndForwardConfiguration")]
[JsonProperty(PropertyName = "storeAndForwardConfiguration")]
public StoreAndForwardConfiguration StoreAndForwardConfiguration { get; set; }

public EdgeHubPropertiesDesired()
Expand All @@ -25,6 +28,7 @@ public EdgeHubPropertiesDesired()
public class StoreAndForwardConfiguration
{
[JsonPropertyName("timeToLiveSecs")]
[JsonProperty(PropertyName = "timeToLiveSecs")]
public int TimeToLiveSecs { get; set; }

public StoreAndForwardConfiguration()
Expand Down
6 changes: 6 additions & 0 deletions src/IoTHub.Portal.Shared/Models/v1.0/LoRaWAN/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,42 @@ public class Channel
/// A value indicating whether the channel is enabled.
/// </summary>
[JsonPropertyName("enable")]
[JsonProperty("enable")]
public bool? Enable { get; set; }

/// <summary>
/// The frequency.
/// </summary>
[JsonPropertyName("freq")]
[JsonProperty("freq")]
public int Freq { get; set; }

/// <summary>
/// The radio.
/// </summary>
[JsonPropertyName("radio")]
[JsonProperty("radio")]
public int Radio { get; set; }

/// <summary>
/// The interface.
/// </summary>
[JsonPropertyName("if")]
[JsonProperty("if")]
public int If { get; set; }

/// <summary>
/// The bandwidth.
/// </summary>
[JsonPropertyName("bandwidth")]
[JsonProperty("bandwidth")]
public int Bandwidth { get; set; }

/// <summary>
/// The spread factor.
/// </summary>
[JsonPropertyName("spread_factor")]
[JsonProperty("spread_factor")]
public int SpreadFactor { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/IoTHub.Portal.Shared/Models/v1.0/LoRaWAN/ClassType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace IoTHub.Portal.Models.v10.LoRaWAN
/// <summary>
/// LoRaWAN Device Class.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))]
public enum ClassType
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace IoTHub.Portal.Models.v10.LoRaWAN
/// <summary>
/// LoRaWAN Deduplication strategy.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))]
public enum DeduplicationMode
{
/// <summary>
Expand Down
Loading

0 comments on commit 31c5063

Please sign in to comment.