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

Feature/rename gateway to iot edge #281

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace AzureIoTHub.Portal.Server.Tests.Controllers.V10
{
[TestFixture]
public class GatewaysControllerTests
public class EdgeDevicesControllerTests
{
private MockRepository mockRepository;

Expand All @@ -38,7 +38,7 @@ public void SetUp()
this.mockDeviceService = this.mockRepository.Create<IDeviceService>();
}

private EdgeDevicesController CreateGatewaysController()
private EdgeDevicesController CreateEdgeDevicesController()
{
return new EdgeDevicesController(
this.mockConfiguration.Object,
Expand All @@ -64,10 +64,10 @@ public async Task Get_StateUnderTest_ExpectedBehavior()
this.mockDeviceService.Setup(x => x.GetDeviceTwin(It.Is<string>(c => c == twin.DeviceId)))
.ReturnsAsync(twin);

var gatewaysController = this.CreateGatewaysController();
var edgeDevicesController = this.CreateEdgeDevicesController();

// Act
var result = await gatewaysController.Get();
var result = await edgeDevicesController.Get();

// Assert
Assert.IsNotNull(result);
Expand All @@ -77,8 +77,8 @@ public async Task Get_StateUnderTest_ExpectedBehavior()
Assert.IsNotNull(okObjectResult);
Assert.AreEqual(200, okObjectResult.StatusCode);
Assert.IsNotNull(okObjectResult.Value);
Assert.IsAssignableFrom<List<GatewayListItem>>(okObjectResult.Value);
var gatewayList = okObjectResult.Value as List<GatewayListItem>;
Assert.IsAssignableFrom<List<IoTEdgeListItem>>(okObjectResult.Value);
var gatewayList = okObjectResult.Value as List<IoTEdgeListItem>;
Assert.IsNotNull(gatewayList);
Assert.AreEqual(1, gatewayList.Count);
var gateway = gatewayList[0];
Expand All @@ -94,12 +94,12 @@ public async Task Get_StateUnderTest_ExpectedBehavior()
public async Task GetSymmetricKey_StateUnderTest_ExpectedBehavior()
{
// Arrange
var gatewaysController = this.CreateGatewaysController();
var edgeDevicesController = this.CreateEdgeDevicesController();
this.mockConnectionStringManager.Setup(c => c.GetSymmetricKey("aaa", "bbb"))
.ReturnsAsync("dfhjkfdgh");

// Act
var result = await gatewaysController.GetSymmetricKey("aaa", "bbb");
var result = await edgeDevicesController.GetSymmetricKey("aaa", "bbb");

// Assert
Assert.IsNotNull(result);
Expand All @@ -119,8 +119,8 @@ public async Task GetSymmetricKey_StateUnderTest_ExpectedBehavior()
public async Task CreateGatewayAsync_StateUnderTest_ExpectedBehavior()
{
// Arrange
var gatewaysController = this.CreateGatewaysController();
var gateway = new Gateway()
var edgeDevicesController = this.CreateEdgeDevicesController();
var gateway = new IoTEdgeDevice()
{
DeviceId = "aaa",
Type = "lora"
Expand All @@ -140,7 +140,7 @@ public async Task CreateGatewayAsync_StateUnderTest_ExpectedBehavior()
this.mockLogger.Setup(x => x.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), It.IsAny<Func<It.IsAnyType, Exception, string>>()));

// Act
var result = await gatewaysController.CreateGatewayAsync(gateway);
var result = await edgeDevicesController.CreateGatewayAsync(gateway);

// Assert
Assert.IsNotNull(result);
Expand All @@ -157,8 +157,8 @@ public async Task CreateGatewayAsync_StateUnderTest_ExpectedBehavior()
public async Task UpdateDeviceAsync_StateUnderTest_ExpectedBehavior()
{
// Arrange
var gatewaysController = this.CreateGatewaysController();
var gateway = new Gateway()
var edgeDevicesController = this.CreateEdgeDevicesController();
var gateway = new IoTEdgeDevice()
{
DeviceId = "aaa",
Type = "lora",
Expand Down Expand Up @@ -195,7 +195,7 @@ public async Task UpdateDeviceAsync_StateUnderTest_ExpectedBehavior()
this.mockLogger.Setup(x => x.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), It.IsAny<Func<It.IsAnyType, Exception, string>>()));

// Act
var result = await gatewaysController.UpdateDeviceAsync(gateway);
var result = await edgeDevicesController.UpdateDeviceAsync(gateway);

// Assert
Assert.IsNotNull(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
/// </summary>
/// <param name="module">Selected module</param>
/// <returns></returns>
public async Task ShowModuleDetail(GatewayModule module)
public async Task ShowModuleDetail(IoTEdgeModule module)
{
var parameters = new DialogParameters();
parameters.Add("module", module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
[CascadingParameter]
MudDialogInstance MudDialog { get; set; }
[Parameter]
public GatewayModule Module { get; set; }
public IoTEdgeModule Module { get; set; }

void Cancel() => MudDialog.Cancel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
@code {
[CascadingParameter] MudDialogInstance MudDialog { get; set; }

private Gateway gateway = new Gateway();
private IoTEdgeDevice gateway = new IoTEdgeDevice();

void Cancel() => MudDialog.Cancel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,17 @@
private bool processingUpdate = false;
private bool processingDelete = false;

private Gateway Gateway;
private IoTEdgeDevice Gateway;

protected override async Task OnInitializedAsync()
{
Gateway = new Gateway();
Gateway = new IoTEdgeDevice();
await LoadDevice();
}

public async Task LoadDevice()
{
Gateway = await Http.GetFromJsonAsync<Gateway>($"api/edge/device/{deviceId}");
Gateway = await Http.GetFromJsonAsync<IoTEdgeDevice>($"api/edge/device/{deviceId}");

if (Gateway.ConnectionState == "Disconnected")
{
Expand All @@ -213,7 +213,7 @@
processingUpdate = false;
}

public async Task OnMethod(GatewayModule module, string methodName)
public async Task OnMethod(IoTEdgeModule module, string methodName)
{
var result = await Http.PostAsJsonAsync($"api/edge/device/{Gateway.DeviceId}/{module.ModuleName}/{methodName}", module);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
else
{
<MudItem xs="12">
<MudTable Items="@result" Dense=true Breakpoint="Breakpoint.Sm" Hover=true Bordered=true Striped=true Filter="new Func<GatewayListItem, bool>(FilterFunc)">
<MudTable Items="@result" Dense=true Breakpoint="Breakpoint.Sm" Hover=true Bordered=true Striped=true Filter="new Func<IoTEdgeListItem, bool>(FilterFunc)">
<ColGroup>
<col style="width: 40%;" />
<col style="width: 10%;" />
Expand Down Expand Up @@ -122,7 +122,7 @@
</MudGrid>

@code {
private List<GatewayListItem> result;
private List<IoTEdgeListItem> result;
private List<string> typeList = new List<string>() { "LoRa", "Other" };
private SearchModel searchModel = new SearchModel(null, "");

Expand All @@ -138,15 +138,15 @@
{
try
{
result = await Http.GetFromJsonAsync<List<GatewayListItem>>("api/edge/device");
result = await Http.GetFromJsonAsync<List<IoTEdgeListItem>>("api/edge/device");
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
}

private bool FilterFunc(GatewayListItem element)
private bool FilterFunc(IoTEdgeListItem element)
{
if (element.Type == null)
{
Expand Down Expand Up @@ -186,10 +186,10 @@
await LoadGatewaysList();
}

public async Task ShowDeleteDialog(GatewayListItem gateway)
public async Task ShowDeleteDialog(IoTEdgeListItem gateway)
{
var parameters = new DialogParameters();
parameters.Add(nameof(Gateway.DeviceId), gateway.DeviceId);
parameters.Add(nameof(IoTEdgeDevice.DeviceId), gateway.DeviceId);
var result = await DialogService.Show<EdgeDeviceDeleteConfirmationDialog>("Confirm Deletion", parameters).Result;

if (result.Cancelled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public async Task<IEnumerable<ConfigListItem>> Get()
// Azure Configurations may have different types: "Configuration", "Deployment" or "LayeredDeployment"
foreach (Configuration config in configList)
{
var moduleList = new List<GatewayModule>();
var moduleList = new List<IoTEdgeModule>();

// Only deployments have modules. If it doesn't, it's a configuration and we don't want to keep it.
if (config.Content.ModulesContent != null)
{
moduleList.AddRange(config.Content.ModulesContent.Select(x => new GatewayModule
moduleList.AddRange(config.Content.ModulesContent.Select(x => new IoTEdgeModule
{
ModuleName = x.Key
}));
Expand All @@ -73,7 +73,7 @@ public async Task<IEnumerable<ConfigListItem>> Get()
public async Task<ConfigListItem> Get(string configurationID)
{
var config = await this.configService.GetConfigItem(configurationID);
var moduleList = new List<GatewayModule>();
var moduleList = new List<IoTEdgeModule>();

// Details of every modules are stored within the EdgeAgent module data
if (config.Content.ModulesContent != null
Expand All @@ -93,7 +93,7 @@ public async Task<ConfigListItem> Get(string configurationID)
{
foreach (var m in modules.Values<JProperty>())
{
GatewayModule newModule = ConfigHelper.CreateGatewayModule(config, m);
IoTEdgeModule newModule = ConfigHelper.CreateGatewayModule(config, m);
moduleList.Add(newModule);
}
}
Expand All @@ -103,7 +103,7 @@ public async Task<ConfigListItem> Get(string configurationID)
{
foreach (var sm in systemModulesToken.Values<JProperty>())
{
GatewayModule newModule = ConfigHelper.CreateGatewayModule(config, sm);
IoTEdgeModule newModule = ConfigHelper.CreateGatewayModule(config, sm);
moduleList.Add(newModule);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ public EdgeDevicesController(
/// </summary>
/// <returns></returns>
[HttpGet(Name = "GET IoT Edge devices")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<GatewayListItem>))]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<IoTEdgeListItem>))]
public async Task<IActionResult> Get()
{
// don't contain tags
IEnumerable<Twin> edgeDevices = await this.devicesService.GetAllEdgeDevice();

List<GatewayListItem> newGatewayList = new();
List<IoTEdgeListItem> newGatewayList = new();

foreach (Twin deviceTwin in edgeDevices)
{
var twin = this.devicesService.GetDeviceTwin(deviceTwin.DeviceId).Result;

if (twin != null)
{
GatewayListItem gateway = new()
IoTEdgeListItem gateway = new()
{
DeviceId = deviceTwin.DeviceId,
Status = twin.Status?.ToString(),
Expand All @@ -114,15 +114,15 @@ public async Task<IActionResult> Get()
/// <param name="deviceId">The device identifier.</param>
/// <returns></returns>
[HttpGet("{deviceId}", Name = "GET IoT Edge device")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(Gateway))]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IoTEdgeDevice))]
public async Task<IActionResult> Get(string deviceId)
{
try
{
Twin deviceTwin = await this.devicesService.GetDeviceTwin(deviceId);
Twin deviceWithModules = await this.devicesService.GetDeviceTwinWithModule(deviceId);

Gateway gateway = new()
IoTEdgeDevice gateway = new()
{
DeviceId = deviceTwin.DeviceId,
Status = deviceTwin.Status?.ToString(),
Expand Down Expand Up @@ -171,7 +171,7 @@ public async Task<IActionResult> GetSymmetricKey(string deviceId, string deviceT
[HttpPost(Name = "POST Create IoT Edge")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> CreateGatewayAsync(Gateway gateway)
public async Task<IActionResult> CreateGatewayAsync(IoTEdgeDevice gateway)
{
try
{
Expand Down Expand Up @@ -199,7 +199,7 @@ public async Task<IActionResult> CreateGatewayAsync(Gateway gateway)
/// <returns></returns>
[HttpPut(Name = "PUT Update IoT Edge")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> UpdateDeviceAsync(Gateway gateway)
public async Task<IActionResult> UpdateDeviceAsync(IoTEdgeDevice gateway)
{
Device device = await this.devicesService.GetDevice(gateway.DeviceId);

Expand Down Expand Up @@ -241,7 +241,7 @@ public async Task<IActionResult> DeleteDeviceAsync(string deviceId)
/// <param name="methodName">Name of the method.</param>
/// <returns></returns>
[HttpPost("{deviceId}/{moduleId}/{methodName}", Name = "POST Execute module command")]
public async Task<C2Dresult> ExecuteMethode(GatewayModule module, string deviceId, string methodName)
public async Task<C2Dresult> ExecuteMethode(IoTEdgeModule module, string deviceId, string methodName)
{
CloudToDeviceMethod method = new(methodName);
string payload = string.Empty;
Expand Down
6 changes: 3 additions & 3 deletions src/AzureIoTHub.Portal/Server/Helpers/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static long RetrieveMetricValue(Configuration item, string metricName)
/// <param name="config">Configuration object from Azure IoT Hub.</param>
/// <param name="moduleList">List of modules related to this configuration.</param>
/// <returns>A configuration converted to a ConfigListItem.</returns>
public static ConfigListItem CreateConfigListItem(Configuration config, List<GatewayModule> moduleList)
public static ConfigListItem CreateConfigListItem(Configuration config, List<IoTEdgeModule> moduleList)
{
return new ConfigListItem
{
Expand All @@ -56,9 +56,9 @@ public static ConfigListItem CreateConfigListItem(Configuration config, List<Gat
/// <param name="config">Configuration object from Azure IoT Hub.</param>
/// <param name="module">Dictionnary containing the module's name and its properties.</param>
/// <returns>A module with all its details as a GatewayModule object.</returns>
public static GatewayModule CreateGatewayModule(Configuration config, JProperty module)
public static IoTEdgeModule CreateGatewayModule(Configuration config, JProperty module)
{
return new GatewayModule
return new IoTEdgeModule
{
ModuleName = module.Name,
Version = module.Value["settings"]["image"]?.Value<string>(),
Expand Down
6 changes: 3 additions & 3 deletions src/AzureIoTHub.Portal/Server/Helpers/DeviceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ public static string RetrieveRuntimeResponse(Twin twin, string deviceId)
/// <param name="twin">the twin of the device we want.</param>
/// <param name="moduleCount">the module count.</param>
/// <returns> List of GatewayModule.</returns>
public static List<GatewayModule> RetrieveModuleList(Twin twin, int moduleCount)
public static List<IoTEdgeModule> RetrieveModuleList(Twin twin, int moduleCount)
{
var list = new List<GatewayModule>();
var list = new List<IoTEdgeModule>();

if (twin.Properties.Reported.Contains("modules") && moduleCount > 0)
{
foreach (var element in twin.Properties.Reported["modules"])
{
var module = new GatewayModule()
var module = new IoTEdgeModule()
{
ModuleName = element.Key
};
Expand Down
4 changes: 2 additions & 2 deletions src/AzureIoTHub.Portal/Shared/Models/v1.0/ConfigListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ConfigListItem
/// </summary>
public ConfigListItem()
{
this.Modules = new List<GatewayModule>();
this.Modules = new List<IoTEdgeModule>();
}

/// <summary>
Expand Down Expand Up @@ -59,6 +59,6 @@ public ConfigListItem()
///<summary>
/// The IoT Edge modules configuration.
/// </summary>
public List<GatewayModule> Modules { get; set; }
public List<IoTEdgeModule> Modules { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AzureIoTHub.Portal.Shared.Models.V10
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

public class Gateway
public class IoTEdgeDevice
{
/// <summary>
/// The IoT Edge identifier.
Expand Down Expand Up @@ -73,14 +73,14 @@ public class Gateway
/// <summary>
/// The IoT Edge modules.
/// </summary>
public List<GatewayModule> Modules { get; set; }
public List<IoTEdgeModule> Modules { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="Gateway"/> class.
/// Initializes a new instance of the <see cref="IoTEdgeDevice"/> class.
/// </summary>
public Gateway()
public IoTEdgeDevice()
{
this.Modules = new List<GatewayModule>();
this.Modules = new List<IoTEdgeModule>();
this.LastDeployment = new ConfigItem();
}
}
Expand Down
Loading