updated
This commit is contained in:
Родитель
b5a7ac4f3d
Коммит
ff46a895da
|
@ -5,7 +5,6 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.Devices;
|
||||
using Microsoft.Azure.IoTSolutions.UIConfig.Services.Diagnostics;
|
||||
using Microsoft.Azure.IoTSolutions.UIConfig.Services.Exceptions;
|
||||
using Microsoft.Azure.IoTSolutions.UIConfig.Services.External;
|
||||
using Microsoft.Azure.IoTSolutions.UIConfig.Services.Helpers.PackageValidation;
|
||||
|
|
|
@ -38,11 +38,6 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers
|
|||
throw new InvalidInputException("Valid package packageType must be provided");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(configType))
|
||||
{
|
||||
throw new InvalidInputException("Valid config packageType must be provided");
|
||||
}
|
||||
|
||||
return new PackageListApiModel(await this.storage.GetPackagesAsync(), packageType, configType);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,14 +18,24 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Models
|
|||
|
||||
public PackageListApiModel(IEnumerable<Package> models, string type, string config)
|
||||
{
|
||||
type = type.ToLower().Trim();
|
||||
config = config.ToLower().Trim();
|
||||
this.Items = models.Select( m => new PackageApiModel(m)).Where(
|
||||
package => (
|
||||
package.ConfigType != null
|
||||
&& package.packageType.ToString().ToLower().Equals(type)
|
||||
&& package.ConfigType.ToString().ToLower().Equals(config)));
|
||||
|
||||
if (string.IsNullOrEmpty(type))
|
||||
{
|
||||
this.Items = models.Select(m => new PackageApiModel(m));
|
||||
}
|
||||
else if (string.IsNullOrEmpty(config))
|
||||
{
|
||||
this.Items = models.Select(m => new PackageApiModel(m)).Where(
|
||||
package => (
|
||||
package.packageType.ToString().ToLower().Equals(type.ToString().ToLower())));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Items = models.Select(m => new PackageApiModel(m)).Where(
|
||||
package => (
|
||||
package.ConfigType != null
|
||||
&& package.packageType.ToString().ToLower().Equals(type)
|
||||
&& package.ConfigType.ToString().ToLower().Equals(config)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -176,34 +176,13 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.Services
|
|||
{
|
||||
DeploymentMetrics =
|
||||
{
|
||||
DeviceMetrics = CalculateDeviceMetrics(deviceStatuses),
|
||||
DeviceMetrics = ConfigurationsHelper.IsEdgeDeployment(deployment) ?
|
||||
CalculateDeviceMetrics(deviceStatuses) : null,
|
||||
DeviceStatuses = includeDeviceStatus ? this.GetDeviceStatuses(deployment) : null
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private IDictionary<DeploymentStatus, long> CalculateDeviceMetrics(IDictionary<string, DeploymentStatus> deviceStatuses)
|
||||
{
|
||||
|
||||
if (deviceStatuses == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
IDictionary<DeploymentStatus, long> deviceMetrics = new Dictionary<DeploymentStatus, long>();
|
||||
|
||||
deviceMetrics[DeploymentStatus.Successful] = deviceStatuses.Where(item =>
|
||||
item.Value == DeploymentStatus.Successful).LongCount();
|
||||
|
||||
deviceMetrics[DeploymentStatus.Failed] = deviceStatuses.Where(item =>
|
||||
item.Value == DeploymentStatus.Failed).LongCount();
|
||||
|
||||
deviceMetrics[DeploymentStatus.Pending] = deviceStatuses.Where(item =>
|
||||
item.Value == DeploymentStatus.Pending).LongCount();
|
||||
|
||||
return deviceMetrics;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a given deployment by id.
|
||||
/// </summary>
|
||||
|
@ -292,5 +271,27 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.Services
|
|||
|
||||
return deviceIds;
|
||||
}
|
||||
|
||||
private IDictionary<DeploymentStatus, long> CalculateDeviceMetrics(IDictionary<string, DeploymentStatus> deviceStatuses)
|
||||
{
|
||||
|
||||
if (deviceStatuses == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
IDictionary<DeploymentStatus, long> deviceMetrics = new Dictionary<DeploymentStatus, long>();
|
||||
|
||||
deviceMetrics[DeploymentStatus.Successful] = deviceStatuses.Where(item =>
|
||||
item.Value == DeploymentStatus.Successful).LongCount();
|
||||
|
||||
deviceMetrics[DeploymentStatus.Failed] = deviceStatuses.Where(item =>
|
||||
item.Value == DeploymentStatus.Failed).LongCount();
|
||||
|
||||
deviceMetrics[DeploymentStatus.Pending] = deviceStatuses.Where(item =>
|
||||
item.Value == DeploymentStatus.Pending).LongCount();
|
||||
|
||||
return deviceMetrics;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -65,9 +65,13 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.Services.Models
|
|||
{
|
||||
this.Type = DeploymentType.DeviceConfiguration;
|
||||
}
|
||||
else if (deployment.Content.ModulesContent != null)
|
||||
{
|
||||
this.Type = DeploymentType.EdgeManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Incorrect deployment type found.");
|
||||
this.Type = DeploymentType.DeviceConfiguration;
|
||||
}
|
||||
|
||||
this.ConfigType = deployment.Labels[ConfigurationsHelper.CONFIG_TYPE_LABEL];
|
||||
|
|
|
@ -25,8 +25,7 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Models
|
|||
public IDictionary<string, DeploymentStatus> DeviceStatuses { get; set; }
|
||||
|
||||
public DeploymentMetricsApiModel()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
public DeploymentMetricsApiModel(DeploymentMetrics metricsServiceModel)
|
||||
{
|
||||
|
@ -34,6 +33,7 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Models
|
|||
|
||||
this.CustomMetrics = metricsServiceModel.CustomMetrics;
|
||||
this.SystemMetrics = metricsServiceModel.SystemMetrics;
|
||||
this.DeviceStatuses = metricsServiceModel.DeviceStatuses;
|
||||
|
||||
if (metricsServiceModel.DeviceMetrics != null)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче