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

#2192 remove aws deprecated thing types after 5mns #2200

Merged
merged 11 commits into from
Jun 12, 2023
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
25 changes: 25 additions & 0 deletions src/IoTHub.Portal.Infrastructure/Jobs/AWS/SyncThingTypesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ private async Task SyncThingTypesAsDeviceModels()
await DeleteThingTypes(thingTypes);
}


private async Task<List<DescribeThingTypeResponse>> Remove5mnDeprecatedThingTypes(List<DescribeThingTypeResponse> thingTypes)
{
var awsThingTypes = new List< DescribeThingTypeResponse>();

foreach (var thingType in thingTypes)
{
var diffInMinutes = (DateTime.Now.Subtract(thingType.ThingTypeMetadata.DeprecationDate)).TotalMinutes;
if (thingType.ThingTypeMetadata.Deprecated && diffInMinutes > 5)
{
_ = await this.amazonIoTClient.DeleteThingTypeAsync(new DeleteThingTypeRequest
{
ThingTypeName = thingType.ThingTypeName
});
}
else
{
awsThingTypes.Add(thingType);
}
}

return awsThingTypes;
}
private async Task<List<DescribeThingTypeResponse>> GetAllThingTypes()
{
var thingTypes = new List<DescribeThingTypeResponse>();
Expand Down Expand Up @@ -116,6 +139,8 @@ private async Task<List<DescribeThingTypeResponse>> GetAllThingTypes()
}
while (!string.IsNullOrEmpty(nextToken));

thingTypes = await Remove5mnDeprecatedThingTypes(thingTypes);

return thingTypes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,20 @@ public async Task Execute_SyncNewAndExistingAndDepprecatedThingTypes_DeviceModel
ThingTypeMetadata = new ThingTypeMetadata
{
Deprecated = true,
DeprecationDate = new DateTime(2023, 6, 11, 10, 30, 0)
}
};



_ = this.iaAmazon.Setup(client => client.DescribeThingTypeAsync(It.Is<DescribeThingTypeRequest>(c => c.ThingTypeName == existingThingType.ThingTypeName), It.IsAny<CancellationToken>()))
.ReturnsAsync(existingThingType);
.ReturnsAsync(existingThingType);
_ = this.iaAmazon.Setup(client => client.DescribeThingTypeAsync(It.Is<DescribeThingTypeRequest>(c => c.ThingTypeName == newThingType.ThingTypeName), It.IsAny<CancellationToken>()))
.ReturnsAsync(newThingType);
.ReturnsAsync(newThingType);
_ = this.iaAmazon.Setup(client => client.DescribeThingTypeAsync(It.Is<DescribeThingTypeRequest>(c => c.ThingTypeName == depcrecatedThingType.ThingTypeName), It.IsAny<CancellationToken>()))
.ReturnsAsync(depcrecatedThingType);
_ = this.iaAmazon.Setup(client => client.DeleteThingTypeAsync(It.Is<DeleteThingTypeRequest>(c => c.ThingTypeName == depcrecatedThingType.ThingTypeName), It.IsAny<CancellationToken>()))
.ReturnsAsync(Fixture.Create<DeleteThingTypeResponse>);

_ = this.mockExternalDeviceService.Setup(client => client.IsEdgeDeviceModel(It.IsAny<ExternalDeviceModelDto>()))
.ReturnsAsync(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@

namespace IoTHub.Portal.Tests.Unit.Infrastructure.Services.AWS_Tests
{
using Amazon.GreengrassV2;
using IoTHub.Portal.Application.Managers;
using IoTHub.Portal.Domain.Repositories;
using IoTHub.Portal.Domain;
using IoTHub.Portal.Tests.Unit.UnitTests.Bases;
using NUnit.Framework;
using IoTHub.Portal.Application.Services;
using AutoMapper;
using IoTHub.Portal.Infrastructure.Services.AWS;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using Amazon.GreengrassV2.Model;
using System.Text;
using System.Threading;
using IoTHub.Portal.Models.v10;
using AutoFixture;
using System.Threading.Tasks;
using Amazon.GreengrassV2;
using Amazon.GreengrassV2.Model;
using Amazon.IoT;
using Amazon.IoT.Model;
using AutoFixture;
using AutoMapper;
using FluentAssertions;
using IoTHub.Portal.Application.Managers;
using IoTHub.Portal.Application.Services;
using IoTHub.Portal.Domain;
using IoTHub.Portal.Domain.Entities;
using System.Collections.Generic;
using System.IO;
using System.Text;
using IoTHub.Portal.Domain.Repositories;
using IoTHub.Portal.Infrastructure.Services.AWS;
using IoTHub.Portal.Models.v10;
using IoTHub.Portal.Tests.Unit.UnitTests.Bases;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Newtonsoft.Json.Linq;
using System.Linq;
using FluentAssertions;
using System;
using NUnit.Framework;

[TestFixture]
public class AwsConfigTests : BackendUnitTest
Expand Down