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

#2191 remove edge model should remove its thing type #2199

Merged
Merged
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
});
Comment on lines +247 to +250

Check warning

Code scanning / CodeQL

Useless assignment to local variable

This assignment to [deploymentThingType](1) is useless, since its value is never read.

}
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