diff --git a/src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs b/src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs index 9aacd5ef4..043ec8c48 100644 --- a/src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs +++ b/src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs @@ -194,6 +194,9 @@ public async Task DeleteConfiguration(string modelId) { var modules = await GetConfigModuleList(modelId); + //Deprecate Deployment Thing type + await DeprecateDeploymentThingType(modelId); + foreach (var module in modules.Where(c => string.IsNullOrEmpty(c.Id))) { var deletedComponentResponse = await this.greengrass.DeleteComponentAsync(new DeleteComponentRequest @@ -228,9 +231,31 @@ public async Task DeleteConfiguration(string modelId) { throw new InternalServerErrorException("The deletion of the deployment failed due to an error in the Amazon IoT API."); } + } } + private async Task DeprecateDeploymentThingType(string modelId) + { + try + { + var deployment = await this.greengrass.GetDeploymentAsync(new GetDeploymentRequest + { + DeploymentId = modelId + }); + + var deploymentThingType = await this.iotClient.DeprecateThingTypeAsync(new DeprecateThingTypeRequest + { + ThingTypeName = deployment.DeploymentName + }); + + } + catch (Amazon.GreengrassV2.Model.ResourceNotFoundException) + { + throw new InternalServerErrorException("The deployment is not found"); + + } + } public async Task GetFailedDeploymentsCount() { var failedDeploymentCount = 0; diff --git a/src/IoTHub.Portal.Tests.Unit/Infrastructure/Services/AWS_Tests/AwsConfigTests.cs b/src/IoTHub.Portal.Tests.Unit/Infrastructure/Services/AWS_Tests/AwsConfigTests.cs index 853dbe2cc..c28364709 100644 --- a/src/IoTHub.Portal.Tests.Unit/Infrastructure/Services/AWS_Tests/AwsConfigTests.cs +++ b/src/IoTHub.Portal.Tests.Unit/Infrastructure/Services/AWS_Tests/AwsConfigTests.cs @@ -246,7 +246,7 @@ public async Task GetAllDeploymentComponentsShouldRetreiveImageUriAndEnvironment } [Test] - public async Task DeleteDeploymentShouldDeleteTheDeploymentVersionAndAllItsComponentsVersions() + public async Task DeleteDeploymentShouldDeleteTheDeploymentVersionAndAllItsComponentsVersionsAndDeprecateItsThingType() { //Act var edge = Fixture.Create(); @@ -266,6 +266,12 @@ public async Task DeleteDeploymentShouldDeleteTheDeploymentVersionAndAllItsCompo } }); + _ = this.mockIotClient.Setup(s3 => s3.DeprecateThingTypeAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(new DeprecateThingTypeResponse + { + HttpStatusCode = HttpStatusCode.OK + }); + _ = this.mockGreengrasClient.Setup(s3 => s3.GetComponentAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(new GetComponentResponse {