Skip to content

Commit

Permalink
Get AWS iot Edge Device
Browse files Browse the repository at this point in the history
  • Loading branch information
ssgueye2 committed May 31, 2023
1 parent b720dc4 commit ee26f45
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Task<PaginationResult<Twin>> GetAllEdgeDevice(

Task<DeviceCredentials> GetEdgeDeviceCredentials(IoTEdgeDevice device);

Task<ConfigItem> RetrieveLastConfiguration(Twin twin);
Task<ConfigItem> RetrieveLastConfiguration(IoTEdgeDevice ioTEdgeDevice);

Task<Twin> CreateNewTwinFromDeviceId(string deviceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,19 @@ public async Task<DeviceCredentials> GetDeviceCredentials(string deviceId)
}
}

public Task<ConfigItem> RetrieveLastConfiguration(Twin twin)
public async Task<ConfigItem> RetrieveLastConfiguration(IoTEdgeDevice ioTEdgeDevice)
{
throw new NotImplementedException();
var coreDevice = await this.greengrass.GetCoreDeviceAsync(new GetCoreDeviceRequest
{
CoreDeviceThingName = ioTEdgeDevice.DeviceName
});

return new ConfigItem
{
Name = coreDevice.CoreDeviceThingName,
DateCreation = coreDevice.LastStatusUpdateTimestamp,
Status = coreDevice.Status
};
}

public Task<Device> UpdateDevice(Device device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public async Task<IoTEdgeDevice> GetEdgeDevice(string edgeDeviceId)
var deviceDto = await base.GetEdgeDevice(edgeDeviceId);

// TODO

deviceDto.LastDeployment = await this.externalDeviceService.RetrieveLastConfiguration(deviceDto);
deviceDto.Status = deviceDto.LastDeployment.Status;
deviceDto.Modules = null;
return deviceDto;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public async Task<IoTEdgeDevice> GetEdgeDevice(string edgeDeviceId)

var deviceTwinWithModules = await this.externalDevicesService.GetDeviceTwinWithModule(edgeDeviceId);

deviceDto.LastDeployment = await this.externalDevicesService.RetrieveLastConfiguration(deviceTwinWithModules);
deviceDto.LastDeployment = await this.externalDevicesService.RetrieveLastConfiguration(deviceDto);

deviceDto.Modules = DeviceHelper.RetrieveModuleList(deviceTwinWithModules);
deviceDto.RuntimeResponse = DeviceHelper.RetrieveRuntimeResponse(deviceTwinWithModules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,9 @@ public async Task<DeviceCredentials> GetEdgeDeviceCredentials(IoTEdgeDevice devi
/// Retrieves the last configuration of the IoT Edge.
/// </summary>
/// <param name="twin">The twin.</param>
public async Task<ConfigItem> RetrieveLastConfiguration(Twin twin)
public async Task<ConfigItem> RetrieveLastConfiguration(IoTEdgeDevice ioTEdgeDevice)
{
var twin = await this.registryManager.GetTwinAsync(ioTEdgeDevice.DeviceId);
var item = new ConfigItem();

if (twin.Configurations?.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,10 @@ public async Task GetEdgeDevicesCountShouldThrowNotImplementedException()
public async Task RetrieveLastConfigurationShouldThrowNotImplementedException()
{
// Act
var act = () => this.externalDeviceService.RetrieveLastConfiguration(Fixture.Create<Twin>());
var act = () => this.externalDeviceService.RetrieveLastConfiguration(Fixture.Create<IoTEdgeDevice>());

// Assert
_ = await act.Should().ThrowAsync<NotImplementedException>();

}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public async Task GetEdgeDeviceShouldReturnValue()
.ReturnsAsync(new Twin(expectedEdgeDevice.Id));

_ = this.mockDeviceService
.Setup(x => x.RetrieveLastConfiguration(It.IsAny<Twin>()))
.Setup(x => x.RetrieveLastConfiguration(It.IsAny<IoTEdgeDevice>()))
.ReturnsAsync(new ConfigItem());

_ = this.mockDeviceModelImageManager.Setup(manager => manager.ComputeImageUri(It.IsAny<string>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2094,10 +2094,10 @@ public async Task RetrieveLastConfigurationTwinHasNoConfigurationShouldReturnNul
{
// Arrange
var service = CreateService();
var mockTwin = new Twin("aaa");

var mockDevice = Fixture.Create<IoTEdgeDevice>();
_ = this.mockRegistryManager.Setup(c => c.GetTwinAsync(mockDevice.DeviceId)).ReturnsAsync(Fixture.Create<Twin>());
// Act
var result = await service.RetrieveLastConfiguration(mockTwin);
var result = await service.RetrieveLastConfiguration(mockDevice);

// Assert
Assert.IsNull(result);
Expand Down

0 comments on commit ee26f45

Please sign in to comment.