Skip to content

Commit

Permalink
#2191 remove edge model should remove its thing type (#2199)
Browse files Browse the repository at this point in the history
* Hide certificates when getting the magic ommand

* Deleting a deployment will deprecate its thing type

---------

Co-authored-by: Kevin BEAUGRAND <contact@kbeaugrand.fr>
  • Loading branch information
ssgueye2 and kbeaugrand committed Jun 23, 2023
1 parent cdd3bb7 commit cfddabc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<int> GetFailedDeploymentsCount()
{
var failedDeploymentCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public async Task GetAllDeploymentComponentsShouldRetreiveImageUriAndEnvironment
}

[Test]
public async Task DeleteDeploymentShouldDeleteTheDeploymentVersionAndAllItsComponentsVersions()
public async Task DeleteDeploymentShouldDeleteTheDeploymentVersionAndAllItsComponentsVersionsAndDeprecateItsThingType()
{
//Act
var edge = Fixture.Create<IoTEdgeModel>();
Expand All @@ -266,6 +266,12 @@ public async Task DeleteDeploymentShouldDeleteTheDeploymentVersionAndAllItsCompo
}
});

_ = this.mockIotClient.Setup(s3 => s3.DeprecateThingTypeAsync(It.IsAny<DeprecateThingTypeRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new DeprecateThingTypeResponse
{
HttpStatusCode = HttpStatusCode.OK
});

_ = this.mockGreengrasClient.Setup(s3 => s3.GetComponentAsync(It.IsAny<GetComponentRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new GetComponentResponse
{
Expand Down

0 comments on commit cfddabc

Please sign in to comment.