Skip to content

Commit

Permalink
Change IdProvider to ExternalIdentifier + Delete Deployment (DONE)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssgueye2 committed May 26, 2023
1 parent d6f8a1d commit 187437d
Show file tree
Hide file tree
Showing 12 changed files with 771 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
Required="true"/>
</MudItem>
<MudItem xs="12">
<MudAlert Severity="Severity.Warning">The Version should be incremented when updating the component</MudAlert>
<MudAlert Severity="Severity.Warning">The Version Number should be incremented when updating the component</MudAlert>
</MudItem>
}

Expand Down Expand Up @@ -120,7 +120,10 @@
Module.ModuleName = currentModuleName;
Module.ImageURI = currentImageUri;
Module.ContainerCreateOptions = currentContainerCreateOptions;
Module.Version = currentNumVersion;

if (Portal.CloudProvider.Equals(CloudProviders.Azure)) { Module.Version = " "; }
else { Module.Version = currentNumVersion; }

Module.EnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>(currentEnvironmentVariables.ToArray());
Module.ModuleIdentityTwinSettings = new List<IoTEdgeModuleTwinSetting>(currentModuleIdentityTwinSettings.ToArray());
Module.Commands = new List<IoTEdgeModuleCommand>(currentCommands.ToArray());
Expand Down
2 changes: 1 addition & 1 deletion src/AzureIoTHub.Portal.Domain/Entities/EdgeDeviceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class EdgeDeviceModel : EntityBase
public string Name { get; set; } = default!;

public string? Description { get; set; }
public string? IdProvider { get; set; }
public string? ExternalIdentifier { get; set; }

/// <summary>
/// Labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task RollOutEdgeModelConfiguration(IoTEdgeModel edgeModel)
}
else
{
edgeModel!.IdProvider = createDeploymentResponse.DeploymentId;
edgeModel!.ExternalIdentifier = createDeploymentResponse.DeploymentId;

_ = this.mapper.Map(edgeModel, edgeModelEntity);

Expand Down Expand Up @@ -240,9 +240,45 @@ public Task<Configuration> GetConfigItem(string id)
throw new NotImplementedException();
}

public Task DeleteConfiguration(string configId)
public async Task DeleteConfiguration(string modelId)
{
throw new NotImplementedException();
var modules = await GetConfigModuleList(modelId);
foreach (var module in modules)
{
var deletedComponentResponse = await this.greengras.DeleteComponentAsync(new DeleteComponentRequest
{
Arn = $"arn:aws:greengrass:{config.AWSRegion}:{config.AWSAccountId}:components:{module.ModuleName}:versions:{module.Version}"
});

if (deletedComponentResponse.HttpStatusCode != HttpStatusCode.NoContent)
{
throw new InternalServerErrorException("The deletion of the component failed due to an error in the Amazon IoT API.");

}
}

var cancelDeploymentResponse = await this.greengras.CancelDeploymentAsync(new CancelDeploymentRequest
{
DeploymentId = modelId
});
if (cancelDeploymentResponse.HttpStatusCode != HttpStatusCode.OK)
{
throw new InternalServerErrorException("The cancellation of the deployment failed due to an error in the Amazon IoT API.");

}
else
{
var deleteDeploymentResponse = await this.greengras.DeleteDeploymentAsync(new DeleteDeploymentRequest
{
DeploymentId = modelId
});

if (deleteDeploymentResponse.HttpStatusCode != HttpStatusCode.NoContent)
{
throw new InternalServerErrorException("The deletion of the deployment failed due to an error in the Amazon IoT API.");
}
}

}

public Task<int> GetFailedDeploymentsCount()
Expand Down
25 changes: 16 additions & 9 deletions src/AzureIoTHub.Portal.Infrastructure/Services/EdgeModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private async Task<IoTEdgeModel> GetAzureEdgeModel(EdgeDeviceModel edgeModelEnti

private async Task<IoTEdgeModel> GetAwsEdgeModel(EdgeDeviceModel edgeModelEntity)
{
var modules = await this.configService.GetConfigModuleList(edgeModelEntity.IdProvider!);
var modules = await this.configService.GetConfigModuleList(edgeModelEntity.ExternalIdentifier!);
//TODO : User a mapper
//Previously return this.edgeDeviceModelMapper.CreateEdgeDeviceModel(query.Value, modules, routes, commands);
var result = new IoTEdgeModel
Expand Down Expand Up @@ -282,17 +282,24 @@ public async Task DeleteEdgeModel(string edgeModelId)
return;
}

var config = this.configService.GetIoTEdgeConfigurations().Result.FirstOrDefault(x => x.Id.StartsWith(edgeModelId, StringComparison.Ordinal));

if (config != null)
if (this.config.CloudProvider.Equals(CloudProviders.Azure, StringComparison.Ordinal))
{
await this.configService.DeleteConfiguration(config.Id);
}
var config = this.configService.GetIoTEdgeConfigurations().Result.FirstOrDefault(x => x.Id.StartsWith(edgeModelId, StringComparison.Ordinal));

var existingCommands = this.commandRepository.GetAll().Where(x => x.EdgeDeviceModelId == edgeModelId).ToList();
foreach (var command in existingCommands)
if (config != null)
{
await this.configService.DeleteConfiguration(config.Id);
}

var existingCommands = this.commandRepository.GetAll().Where(x => x.EdgeDeviceModelId == edgeModelId).ToList();
foreach (var command in existingCommands)
{
this.commandRepository.Delete(command.Id);
}
}
else
{
this.commandRepository.Delete(command.Id);
await this.configService.DeleteConfiguration(edgeModelEntity.ExternalIdentifier!);
}

foreach (var labelEntity in edgeModelEntity.Labels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public static IServiceCollection AddAWSInfrastructureLayer(this IServiceCollecti
.ConfigureAWSClient(configuration).Result
.ConfigureAWSServices()
.ConfigureAWSDeviceModelImages()
.ConfigureAWSSyncJobs(configuration)
.ConfigureOtherDependencies();
.ConfigureAWSSyncJobs(configuration);
}
private static async Task<IServiceCollection> ConfigureAWSClient(this IServiceCollection services, ConfigHandler configuration)
{
Expand Down Expand Up @@ -88,10 +87,5 @@ private static IServiceCollection ConfigureAWSSyncJobs(this IServiceCollection s
});
}

private static IServiceCollection ConfigureOtherDependencies(this IServiceCollection services)
{
_ = services.AddSingleton(new PortalSettings());
return services;
}
}
}
Loading

0 comments on commit 187437d

Please sign in to comment.