Merged PR 949052: Report iotedged version

Report iotedged version
This commit is contained in:
Raj Vengalil 2018-07-10 06:46:34 +00:00
Родитель ffb942ba1b
Коммит 91c5612e0e
16 изменённых файлов: 141 добавлений и 55 удалений

Просмотреть файл

@ -10,7 +10,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Core
/// <summary>
/// This interface provides the module runtime information.
/// TODO: Consider replacing this with IEnvironment and the decorator pattern.
/// However, that would require IModule implementations to be made generic.
/// However, that would require IModule implementations to be made generic.
/// </summary>
public interface IRuntimeInfoProvider
{
@ -21,17 +21,20 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Core
public class SystemInfo
{
static SystemInfo Empty { get; } = new SystemInfo(string.Empty, string.Empty);
static SystemInfo Empty { get; } = new SystemInfo(string.Empty, string.Empty, string.Empty);
[JsonConstructor]
public SystemInfo(string operatingSystemType, string architecture)
public SystemInfo(string operatingSystemType, string architecture, string version)
{
this.OperatingSystemType = operatingSystemType;
this.Architecture = architecture;
this.Version = version;
}
public string OperatingSystemType { get; }
public string Architecture { get; }
public string Version { get; }
}
}

Просмотреть файл

@ -15,7 +15,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
/// <summary>
/// This implementation gets the module runtime information from IRuntimeInfoProvider and
/// the configuration information from the deploymentConfig.
/// TODO: This could be made generic (not docker specific) and moved to Core.
/// TODO: This could be made generic (not docker specific) and moved to Core.
/// </summary>
public class DockerEnvironment : IEnvironment
{
@ -23,6 +23,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
readonly IEntityStore<string, ModuleState> moduleStateStore;
readonly string operatingSystemType;
readonly string architecture;
readonly string version;
readonly DeploymentConfig deploymentConfig;
readonly IRestartPolicyManager restartManager;
@ -31,7 +32,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
IEntityStore<string, ModuleState> moduleStateStore,
IRestartPolicyManager restartManager,
string operatingSystemType,
string architecture)
string architecture,
string version)
{
this.moduleStatusProvider = moduleStatusProvider;
this.deploymentConfig = deploymentConfig;
@ -39,6 +41,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
this.restartManager = restartManager;
this.operatingSystemType = operatingSystemType;
this.architecture = architecture;
this.version = version;
}
public async Task<ModuleSet> GetModulesAsync(CancellationToken token)
@ -103,13 +106,13 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
IRuntimeInfo runtimeInfo = this.deploymentConfig.Runtime;
if (runtimeInfo?.Type == "docker")
{
var platform = new DockerPlatformInfo(this.operatingSystemType, this.architecture);
var platform = new DockerPlatformInfo(this.operatingSystemType, this.architecture, this.version);
DockerRuntimeConfig config = (runtimeInfo as DockerRuntimeInfo)?.Config;
runtimeInfo = new DockerReportedRuntimeInfo(runtimeInfo.Type, config, platform);
}
else if (runtimeInfo == null || runtimeInfo is UnknownRuntimeInfo)
{
var platform = new DockerPlatformInfo(this.operatingSystemType, this.architecture);
var platform = new DockerPlatformInfo(this.operatingSystemType, this.architecture, this.version);
runtimeInfo = new DockerReportedUnknownRuntimeInfo(platform);
}

Просмотреть файл

@ -14,13 +14,21 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
readonly IRestartPolicyManager restartPolicyManager;
readonly string operatingSystemType;
readonly string architecture;
readonly string version;
DockerEnvironmentProvider(IRuntimeInfoProvider runtimeInfoProvider, IEntityStore<string, ModuleState> store, IRestartPolicyManager restartPolicyManager, string operatingSystemType, string architecture)
DockerEnvironmentProvider(
IRuntimeInfoProvider runtimeInfoProvider,
IEntityStore<string, ModuleState> store,
IRestartPolicyManager restartPolicyManager,
string operatingSystemType,
string architecture,
string version)
{
this.moduleStatusProvider = runtimeInfoProvider;
this.store = Preconditions.CheckNotNull(store, nameof(store));
this.operatingSystemType = operatingSystemType;
this.architecture = architecture;
this.version = version;
this.restartPolicyManager = Preconditions.CheckNotNull(restartPolicyManager, nameof(restartPolicyManager));
}
@ -28,10 +36,16 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
IRestartPolicyManager restartPolicyManager)
{
SystemInfo systemInfo = await Preconditions.CheckNotNull(runtimeInfoProvider, nameof(runtimeInfoProvider)).GetSystemInfo();
return new DockerEnvironmentProvider(runtimeInfoProvider, store, restartPolicyManager, systemInfo.OperatingSystemType, systemInfo.Architecture);
return new DockerEnvironmentProvider(
runtimeInfoProvider, store, restartPolicyManager,
systemInfo.OperatingSystemType, systemInfo.Architecture,
systemInfo.Version);
}
public IEnvironment Create(DeploymentConfig deploymentConfig) =>
new DockerEnvironment(this.moduleStatusProvider, deploymentConfig, this.store, this.restartPolicyManager, this.operatingSystemType, this.architecture);
new DockerEnvironment(
this.moduleStatusProvider, deploymentConfig, this.store,
this.restartPolicyManager, this.operatingSystemType,
this.architecture, this.version);
}
}

Просмотреть файл

@ -9,10 +9,11 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
public class DockerPlatformInfo : IEquatable<DockerPlatformInfo>
{
[JsonConstructor]
public DockerPlatformInfo(string operatingSystemType, string architecture)
public DockerPlatformInfo(string operatingSystemType, string architecture, string version)
{
this.OperatingSystemType = operatingSystemType ?? string.Empty;
this.Architecture = architecture ?? string.Empty;
this.Version = version ?? string.Empty;
}
[JsonProperty("os")]
@ -21,16 +22,23 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
[JsonProperty("architecture")]
public string Architecture { get; }
[JsonProperty("version")]
public string Version { get; }
public override bool Equals(object obj) => this.Equals(obj as DockerPlatformInfo);
public bool Equals(DockerPlatformInfo other) =>
other != null && this.OperatingSystemType == other.OperatingSystemType && this.Architecture == other.Architecture;
other != null &&
this.OperatingSystemType == other.OperatingSystemType &&
this.Architecture == other.Architecture &&
this.Version == other.Version;
public override int GetHashCode()
{
int hashCode = 577840947;
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.OperatingSystemType);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.Architecture);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.Version);
return hashCode;
}

Просмотреть файл

@ -25,13 +25,15 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
readonly IDockerClient client;
readonly string operatingSystemType;
readonly string architecture;
readonly string version;
RuntimeInfoProvider(IDockerClient client, string operatingSystemType, string architecture)
RuntimeInfoProvider(IDockerClient client, string operatingSystemType, string architecture, string version)
{
this.client = Preconditions.CheckNotNull(client, nameof(client));
this.operatingSystemType = string.IsNullOrWhiteSpace(operatingSystemType) ? CoreConstants.Unknown : operatingSystemType;
this.architecture = string.IsNullOrWhiteSpace(architecture) ? CoreConstants.Unknown : architecture;
this.version = string.IsNullOrWhiteSpace(version) ? CoreConstants.Unknown : version;
}
public async static Task<RuntimeInfoProvider> CreateAsync(IDockerClient client)
@ -41,7 +43,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
// get system information from docker
SystemInfoResponse info = await client.System.GetSystemInfoAsync();
return new RuntimeInfoProvider(client, info.OSType, info.Architecture);
return new RuntimeInfoProvider(client, info.OSType, info.Architecture, info.ServerVersion);
}
public async Task<IEnumerable<ModuleRuntimeInfo>> GetModules(CancellationToken ctsToken)
@ -171,7 +173,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
return status;
}
public Task<SystemInfo> GetSystemInfo() => Task.FromResult(new SystemInfo(this.operatingSystemType, this.architecture));
public Task<SystemInfo> GetSystemInfo() => Task.FromResult(new SystemInfo(this.operatingSystemType, this.architecture, this.version));
static class Events
{

Просмотреть файл

@ -32,8 +32,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet
{
GeneratedCode.SystemInfo systemInfo = await this.moduleManager.GetSystemInfoAsync();
return new Core.SystemInfo(systemInfo.OsType, systemInfo.Architecture);
}
return new Core.SystemInfo(systemInfo.OsType, systemInfo.Architecture, systemInfo.Version);
}
internal static ModuleRuntimeInfo<T> GetModuleRuntimeInfo(ModuleDetails moduleDetails)
{
@ -46,7 +46,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet
Option<DateTime> exitTime = exitStatus == null ? Option.None<DateTime>() : Option.Some(exitStatus.ExitTime);
Option<DateTime> startTime = !moduleDetails.Status.StartTime.HasValue ? Option.None<DateTime>() : Option.Some(moduleDetails.Status.StartTime.Value);
if (!Enum.TryParse(moduleDetails.Status.RuntimeStatus.Status, true, out ModuleStatus status))
if (!Enum.TryParse(moduleDetails.Status.RuntimeStatus.Status, true, out ModuleStatus status))
{
status = ModuleStatus.Unknown;
}

Просмотреть файл

@ -7,7 +7,7 @@
namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet.GeneratedCode
{
#pragma warning disable // Disable all warnings
#pragma warning disable // Disable all warnings
[System.CodeDom.Compiler.GeneratedCode("NSwag", "11.17.12.0 (NJsonSchema v9.10.50.0 (Newtonsoft.Json v9.0.0.0))")]
public partial class EdgeletHttpClient
@ -1403,11 +1403,11 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet.GeneratedCode
}
else if (value is byte[])
{
return System.Convert.ToBase64String((byte[]) value);
return System.Convert.ToBase64String((byte[])value);
}
else if (value.GetType().IsArray)
{
var array = System.Linq.Enumerable.OfType<object>((System.Array) value);
var array = System.Linq.Enumerable.OfType<object>((System.Array)value);
return string.Join(",", System.Linq.Enumerable.Select(array, o => ConvertToString(o, cultureInfo)));
}
@ -1420,6 +1420,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet.GeneratedCode
{
private string _osType;
private string _architecture;
private string _version;
[Newtonsoft.Json.JsonProperty("osType", Required = Newtonsoft.Json.Required.Always)]
public string OsType
@ -1449,6 +1450,20 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet.GeneratedCode
}
}
[Newtonsoft.Json.JsonProperty("version", Required = Newtonsoft.Json.Required.Always)]
public string Version
{
get { return _version; }
set
{
if (_version != value)
{
_version = value;
RaisePropertyChanged();
}
}
}
public string ToJson()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);

Просмотреть файл

@ -18,7 +18,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
public async Task CreateEnvironmentTest()
{
// Arrange
var runtimeInfoProvider = Mock.Of<IRuntimeInfoProvider>(m => m.GetSystemInfo() == Task.FromResult(new SystemInfo("linux", "x64")));
var runtimeInfoProvider = Mock.Of<IRuntimeInfoProvider>(m => m.GetSystemInfo() == Task.FromResult(new SystemInfo("linux", "x64", "17.11.0-ce")));
var entityStore = Mock.Of<IEntityStore<string, ModuleState>>();
var restartPolicyManager = Mock.Of<IRestartPolicyManager>();

Просмотреть файл

@ -22,13 +22,14 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test
{
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
[Fact]
[Unit]
public async Task GetRuntimeInfoTest()
{
// Arrange
var systemInfo = new SystemInfo(OperatingSystemType, Architecture);
var systemInfo = new SystemInfo(OperatingSystemType, Architecture, Version);
var store = Mock.Of<IEntityStore<string, ModuleState>>();
var restartPolicyManager = Mock.Of<IRestartPolicyManager>();
@ -43,7 +44,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test
new SystemModules(Option.None<IEdgeAgentModule>(), Option.None<IEdgeHubModule>()),
new Dictionary<string, IModule>());
var environment = new DockerEnvironment(runtimeInfoProvider, deploymentConfig, moduleStateStore, restartPolicyManager, systemInfo.OperatingSystemType, systemInfo.Architecture);
var environment = new DockerEnvironment(runtimeInfoProvider, deploymentConfig, moduleStateStore, restartPolicyManager, systemInfo.OperatingSystemType, systemInfo.Architecture, systemInfo.Version);
// act
IRuntimeInfo reportedRuntimeInfo = await environment.GetRuntimeInfoAsync();
@ -53,6 +54,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test
var dockerReported = reportedRuntimeInfo as DockerReportedRuntimeInfo;
Assert.Equal(OperatingSystemType, dockerReported.Platform.OperatingSystemType);
Assert.Equal(Architecture, dockerReported.Platform.Architecture);
Assert.Equal(Version, dockerReported.Platform.Version);
Assert.Equal(minDockerVersion, dockerReported.Config.MinDockerVersion);
Assert.Equal(dockerLoggingOptions, dockerReported.Config.LoggingOptions);
}
@ -62,17 +64,11 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test
public async Task GetUnknownRuntimeInfoTest()
{
// Arrange
var systemInfoResponse = new SystemInfoResponse
{
OSType = OperatingSystemType,
Architecture = Architecture
};
var runtimeInfoProvider = Mock.Of<IRuntimeInfoProvider>();
var moduleStateStore = Mock.Of<IEntityStore<string, ModuleState>>();
var restartPolicyManager = Mock.Of<IRestartPolicyManager>();
var environment = new DockerEnvironment(runtimeInfoProvider, DeploymentConfig.Empty, moduleStateStore, restartPolicyManager, OperatingSystemType, Architecture);
var environment = new DockerEnvironment(runtimeInfoProvider, DeploymentConfig.Empty, moduleStateStore, restartPolicyManager, OperatingSystemType, Architecture, Version);
// act
IRuntimeInfo reportedRuntimeInfo = await environment.GetRuntimeInfoAsync();
@ -82,13 +78,14 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test
var dockerReported = reportedRuntimeInfo as DockerReportedUnknownRuntimeInfo;
Assert.Equal(OperatingSystemType, dockerReported.Platform.OperatingSystemType);
Assert.Equal(Architecture, dockerReported.Platform.Architecture);
Assert.Equal(Version, dockerReported.Platform.Version);
}
[Fact]
[Unit]
public async Task GetModulesTest()
{
// Arrange
// Arrange
var restartPolicyManager = new Mock<IRestartPolicyManager>();
restartPolicyManager.Setup(
r => r.ComputeModuleStatusFromRestartPolicy(
@ -159,12 +156,12 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test
new SystemModules(edgeAgentModule, edgeHubModule),
new Dictionary<string, IModule> { [module1.Name] = module1, [module2.Name] = module2 });
var environment = new DockerEnvironment(runtimeInfoProvider, deploymentConfig, moduleStateStore.Object, restartPolicyManager.Object, OperatingSystemType, Architecture);
var environment = new DockerEnvironment(runtimeInfoProvider, deploymentConfig, moduleStateStore.Object, restartPolicyManager.Object, OperatingSystemType, Architecture, Version);
// act
// Act
ModuleSet moduleSet = await environment.GetModulesAsync(CancellationToken.None);
//. assert
// Assert
Assert.NotNull(moduleSet);
Assert.True(moduleSet.Modules.TryGetValue("module1", out IModule receivedModule1));
Assert.True(moduleSet.Modules.TryGetValue("module2", out IModule receivedModule2));

Просмотреть файл

@ -56,6 +56,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test
// Assert
Assert.Equal(systemInfo.OSType, recivedSystemInfo.OperatingSystemType);
Assert.Equal(systemInfo.Architecture, recivedSystemInfo.Architecture);
Assert.Equal(systemInfo.ServerVersion, recivedSystemInfo.Version);
}
}

Просмотреть файл

@ -81,6 +81,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
const string LoggingOptions = "logging options";
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
var versionInfo = new VersionInfo("v1", "b1", "c1");
// Mock IEdgeAgentConnection
@ -128,7 +129,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
IRuntimeInfo runtimeInfo = new DockerReportedRuntimeInfo(
RuntimeType,
(deploymentConfigInfo.DeploymentConfig.Runtime as DockerRuntimeInfo)?.Config,
new DockerPlatformInfo(OperatingSystemType, Architecture));
new DockerPlatformInfo(OperatingSystemType, Architecture, Version));
// Mock AgentStateSerDe
var agentStateSerde = new Mock<ISerde<AgentState>>();
@ -190,7 +191,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
platform = new
{
os = OperatingSystemType,
architecture = Architecture
architecture = Architecture,
version = Version
}
},
systemModules = new
@ -228,6 +230,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
const string LoggingOptions = "logging options";
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
var versionInfo = new VersionInfo("v1", "b1", "c1");
// prepare IEdgeAgentConnection mock
@ -275,7 +278,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
IRuntimeInfo runtimeInfo = new DockerReportedRuntimeInfo(
RuntimeType,
(deploymentConfigInfo.DeploymentConfig.Runtime as DockerRuntimeInfo)?.Config,
new DockerPlatformInfo(OperatingSystemType, Architecture));
new DockerPlatformInfo(OperatingSystemType, Architecture, Version));
IEdgeAgentModule edgeAgentModule = this.CreateMockEdgeAgentModule();
// build current module set
@ -325,7 +328,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
platform = new
{
os = OperatingSystemType,
architecture = Architecture
architecture = Architecture,
version = Version
}
},
systemModules = new
@ -371,6 +375,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
const string LoggingOptions = "logging options";
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
var versionInfo = new VersionInfo("v1", "b1", "c1");
// prepare IEdgeAgentConnection mock
@ -418,7 +423,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
IRuntimeInfo runtimeInfo = new DockerReportedRuntimeInfo(
RuntimeType,
(deploymentConfigInfo.DeploymentConfig.Runtime as DockerRuntimeInfo)?.Config,
new DockerPlatformInfo(OperatingSystemType, Architecture));
new DockerPlatformInfo(OperatingSystemType, Architecture, Version));
IEdgeAgentModule edgeAgentModule = this.CreateMockEdgeAgentModule();
// build current module set
@ -468,7 +473,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
platform = new
{
os = OperatingSystemType,
architecture = Architecture
architecture = Architecture,
version = Version
}
},
systemModules = new
@ -523,6 +529,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
const string LoggingOptions = "logging options";
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
var versionInfo = new VersionInfo("v1", "b1", "c1");
// prepare IEdgeAgentConnection mock
@ -575,7 +582,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
IRuntimeInfo runtimeInfo = new DockerReportedRuntimeInfo(
RuntimeType,
(deploymentConfigInfo.DeploymentConfig.Runtime as DockerRuntimeInfo)?.Config,
new DockerPlatformInfo(OperatingSystemType, Architecture));
new DockerPlatformInfo(OperatingSystemType, Architecture, Version));
// build current module set
ModuleSet currentModuleSet = ModuleSet.Create(
@ -624,7 +631,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
platform = new
{
os = OperatingSystemType,
architecture = Architecture
architecture = Architecture,
version = Version
}
},
systemModules = new
@ -669,6 +677,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
const string LoggingOptions = "logging options";
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
var versionInfo = new VersionInfo("v1", "b1", "c1");
// prepare IEdgeAgentConnection mock
@ -714,7 +723,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
IRuntimeInfo runtimeInfo = new DockerReportedRuntimeInfo(
RuntimeType,
(deploymentConfigInfo.DeploymentConfig.Runtime as DockerRuntimeInfo)?.Config,
new DockerPlatformInfo(OperatingSystemType, Architecture));
new DockerPlatformInfo(OperatingSystemType, Architecture, Version));
// build current module set
ModuleSet currentModuleSet = ModuleSet.Create(
@ -793,6 +802,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
const string LoggingOptions = "logging options";
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
var versionInfo = new VersionInfo("v1", "b1", "c1");
// prepare IEdgeAgentConnection mock
@ -834,7 +844,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
IRuntimeInfo runtimeInfo = new DockerReportedRuntimeInfo(
RuntimeType,
(deploymentConfigInfo.DeploymentConfig.Runtime as DockerRuntimeInfo)?.Config,
new DockerPlatformInfo(OperatingSystemType, Architecture));
new DockerPlatformInfo(OperatingSystemType, Architecture, Version));
// build current module set
ModuleSet currentModuleSet = ModuleSet.Create(
@ -882,6 +892,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
const string LoggingOptions = "logging options";
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
var versionInfo = new VersionInfo("v1", "b1", "c1");
// prepare IEdgeAgentConnection mock
@ -921,7 +932,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
IRuntimeInfo runtimeInfo = new DockerReportedRuntimeInfo(
RuntimeType,
(deploymentConfigInfo.DeploymentConfig.Runtime as DockerRuntimeInfo)?.Config,
new DockerPlatformInfo(OperatingSystemType, Architecture));
new DockerPlatformInfo(OperatingSystemType, Architecture, Version));
// build current module set
DateTime lastStartTimeUtc = DateTime.Parse(
@ -987,7 +998,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
platform = new
{
os = OperatingSystemType,
architecture = Architecture
architecture = Architecture,
version = Version
}
},
systemModules = new
@ -1107,6 +1119,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
const string LoggingOptions = "logging options";
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
var versionInfo = new VersionInfo("v1", "b1", "c1");
DateTime lastStartTimeUtc = DateTime.Parse("2017-11-13T23:44:35.127381Z", null, DateTimeStyles.RoundtripKind);
@ -1145,7 +1158,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
IRuntimeInfo runtimeInfo = new DockerReportedRuntimeInfo(
RuntimeType,
(deploymentConfigInfo.DeploymentConfig.Runtime as DockerRuntimeInfo)?.Config,
new DockerPlatformInfo(OperatingSystemType, Architecture));
new DockerPlatformInfo(OperatingSystemType, Architecture, Version));
// build current module set
ModuleSet currentModuleSet = ModuleSet.Create(
@ -1228,6 +1241,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
const string LoggingOptions = "";
const string OperatingSystemType = "linux";
const string Architecture = "x86_x64";
const string Version = "17.11.0-ce";
var versionInfo = new VersionInfo("v1", "b1", "c1");
// prepare IEdgeAgentConnection mock
@ -1280,7 +1294,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
IRuntimeInfo runtimeInfo = new DockerReportedRuntimeInfo(
RuntimeType,
(deploymentConfigInfo.DeploymentConfig.Runtime as DockerRuntimeInfo)?.Config,
new DockerPlatformInfo(OperatingSystemType, Architecture));
new DockerPlatformInfo(OperatingSystemType, Architecture, Version));
IEdgeAgentModule edgeAgentModule = this.CreateMockEdgeAgentModule();
// build current module set
@ -1344,7 +1358,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test.Reporters
platform = new
{
os = OperatingSystemType,
architecture = Architecture
architecture = Architecture,
version = Version
}
},
systemModules = new

Просмотреть файл

@ -525,9 +525,12 @@ definitions:
type: string
architecture:
type: string
version:
type: string
required:
- osType
- architecture
- version
example:
osType: "linux/windows"
architecture: "arm/amd64/x86"

Просмотреть файл

@ -317,6 +317,8 @@ pub struct SystemInfo {
os_type: String,
/// Hardware architecture of the host. Example of value expected: arm32, x86, amd64
architecture: String,
/// iotedge version string
version: &'static str,
}
impl SystemInfo {
@ -324,6 +326,7 @@ impl SystemInfo {
SystemInfo {
os_type,
architecture,
version: super::version(),
}
}
@ -334,6 +337,10 @@ impl SystemInfo {
pub fn architecture(&self) -> &str {
&self.architecture
}
pub fn version(&self) -> &str {
self.version
}
}
pub trait ModuleRuntime {

Просмотреть файл

@ -52,6 +52,7 @@ where
let body = SystemInfo::new(
systeminfo.os_type().to_string(),
systeminfo.architecture().to_string(),
systeminfo.version().to_string(),
);
let response = serde_json::to_string(&body)
.context(ErrorKind::Serde)
@ -74,7 +75,7 @@ where
#[cfg(test)]
mod tests {
use edgelet_core::ModuleRuntimeState;
use edgelet_core::{self, ModuleRuntimeState};
use edgelet_http::route::Parameters;
use edgelet_test_utils::module::*;
use futures::Stream;
@ -110,6 +111,7 @@ mod tests {
assert_eq!("os_type_sample", os_type);
assert_eq!("architecture_sample", architecture);
assert_eq!(edgelet_core::version(), system_info.version());
Ok(())
})

Просмотреть файл

@ -17,13 +17,16 @@ pub struct SystemInfo {
os_type: String,
#[serde(rename = "architecture")]
architecture: String,
#[serde(rename = "version")]
version: String,
}
impl SystemInfo {
pub fn new(os_type: String, architecture: String) -> SystemInfo {
pub fn new(os_type: String, architecture: String, version: String) -> SystemInfo {
SystemInfo {
os_type,
architecture,
version,
}
}
@ -52,4 +55,17 @@ impl SystemInfo {
pub fn architecture(&self) -> &String {
&self.architecture
}
pub fn set_version(&mut self, version: String) {
self.version = version;
}
pub fn with_version(mut self, version: String) -> SystemInfo {
self.version = version;
self
}
pub fn version(&self) -> &String {
&self.version
}
}

Просмотреть файл

@ -1,5 +1,5 @@
{
"version" : "1.0.1-dev",
"build" : "BUILDNUMBER",
"commit" : "COMMITID"
"version": "1.0.1-dev",
"build": "BUILDNUMBER",
"commit": "COMMITID"
}