From 24e37d0ec88befb8254abdaeb5718849840c1689 Mon Sep 17 00:00:00 2001 From: ssgueye2 <127868584+ssgueye2@users.noreply.github.com> Date: Mon, 12 Jun 2023 12:36:07 +0200 Subject: [PATCH] #2191 remove edge model should remove its thing type (#2199) * Hide certificates when getting the magic ommand * Deleting a deployment will deprecate its thing type --------- Co-authored-by: Kevin BEAUGRAND --- .../Services/AWS/AwsConfigService.cs | 25 +++++++++++++++++++ .../Services/AWS_Tests/AwsConfigTests.cs | 8 +++++- 2 files changed, 32 insertions(+), 1 deletion(-) 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 {