diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/IRuntimeInfoProvider.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/IRuntimeInfoProvider.cs index 4c52c29cbb..4e4017434c 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/IRuntimeInfoProvider.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/IRuntimeInfoProvider.cs @@ -10,7 +10,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Core /// /// 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. /// 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; } } } diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerEnvironment.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerEnvironment.cs index 7aa0a828fb..a5c39887d2 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerEnvironment.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerEnvironment.cs @@ -15,7 +15,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker /// /// 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. /// public class DockerEnvironment : IEnvironment { @@ -23,6 +23,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker readonly IEntityStore 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 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 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); } diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerEnvironmentProvider.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerEnvironmentProvider.cs index 224aa5d30a..03344fce14 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerEnvironmentProvider.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerEnvironmentProvider.cs @@ -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 store, IRestartPolicyManager restartPolicyManager, string operatingSystemType, string architecture) + DockerEnvironmentProvider( + IRuntimeInfoProvider runtimeInfoProvider, + IEntityStore 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); } } diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerPlatformInfo.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerPlatformInfo.cs index 466fcbc008..f2db4ea8ff 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerPlatformInfo.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerPlatformInfo.cs @@ -9,10 +9,11 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker public class DockerPlatformInfo : IEquatable { [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.Default.GetHashCode(this.OperatingSystemType); hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(this.Architecture); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(this.Version); return hashCode; } diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/RuntimeInfoProvider.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/RuntimeInfoProvider.cs index 658a685759..5f8a5cb029 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/RuntimeInfoProvider.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/RuntimeInfoProvider.cs @@ -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 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> GetModules(CancellationToken ctsToken) @@ -171,7 +173,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker return status; } - public Task GetSystemInfo() => Task.FromResult(new SystemInfo(this.operatingSystemType, this.architecture)); + public Task GetSystemInfo() => Task.FromResult(new SystemInfo(this.operatingSystemType, this.architecture, this.version)); static class Events { diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/RuntimeInfoProvider.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/RuntimeInfoProvider.cs index 3e4f23304b..f15fe631ef 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/RuntimeInfoProvider.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/RuntimeInfoProvider.cs @@ -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 GetModuleRuntimeInfo(ModuleDetails moduleDetails) { @@ -46,7 +46,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet Option exitTime = exitStatus == null ? Option.None() : Option.Some(exitStatus.ExitTime); Option startTime = !moduleDetails.Status.StartTime.HasValue ? Option.None() : 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; } diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/generatedCode/EdgeletHttpClient.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/generatedCode/EdgeletHttpClient.cs index 42e611a3c0..722834b6e0 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/generatedCode/EdgeletHttpClient.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/generatedCode/EdgeletHttpClient.cs @@ -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((System.Array) value); + var array = System.Linq.Enumerable.OfType((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); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/DockerEnvironmentProviderTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/DockerEnvironmentProviderTest.cs index a516dc3974..7701724381 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/DockerEnvironmentProviderTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/DockerEnvironmentProviderTest.cs @@ -18,7 +18,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker public async Task CreateEnvironmentTest() { // Arrange - var runtimeInfoProvider = Mock.Of(m => m.GetSystemInfo() == Task.FromResult(new SystemInfo("linux", "x64"))); + var runtimeInfoProvider = Mock.Of(m => m.GetSystemInfo() == Task.FromResult(new SystemInfo("linux", "x64", "17.11.0-ce"))); var entityStore = Mock.Of>(); var restartPolicyManager = Mock.Of(); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/DockerEnvironmentTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/DockerEnvironmentTest.cs index 6fdd43d47c..b91d26b48d 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/DockerEnvironmentTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/DockerEnvironmentTest.cs @@ -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>(); var restartPolicyManager = Mock.Of(); @@ -43,7 +44,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test new SystemModules(Option.None(), Option.None()), new Dictionary()); - 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(); var moduleStateStore = Mock.Of>(); var restartPolicyManager = Mock.Of(); - 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(); restartPolicyManager.Setup( r => r.ComputeModuleStatusFromRestartPolicy( @@ -159,12 +156,12 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test new SystemModules(edgeAgentModule, edgeHubModule), new Dictionary { [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)); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/RuntimeInfoProviderTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/RuntimeInfoProviderTest.cs index 2c580e260a..809298d6c7 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/RuntimeInfoProviderTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.Test/RuntimeInfoProviderTest.cs @@ -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); } } diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test/reporters/IoTHubReporterTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test/reporters/IoTHubReporterTest.cs index e4664c3c11..7525ee4dac 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test/reporters/IoTHubReporterTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.IoTHub.Test/reporters/IoTHubReporterTest.cs @@ -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>(); @@ -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 diff --git a/edgelet/api/management.yaml b/edgelet/api/management.yaml index 397b0bd8fd..c8317804ea 100644 --- a/edgelet/api/management.yaml +++ b/edgelet/api/management.yaml @@ -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" diff --git a/edgelet/edgelet-core/src/module.rs b/edgelet/edgelet-core/src/module.rs index e0e4028c7c..53c031f902 100644 --- a/edgelet/edgelet-core/src/module.rs +++ b/edgelet/edgelet-core/src/module.rs @@ -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 { diff --git a/edgelet/edgelet-http-mgmt/src/server/system_info/get.rs b/edgelet/edgelet-http-mgmt/src/server/system_info/get.rs index 2864226956..bcb1f7cc94 100644 --- a/edgelet/edgelet-http-mgmt/src/server/system_info/get.rs +++ b/edgelet/edgelet-http-mgmt/src/server/system_info/get.rs @@ -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(()) }) diff --git a/edgelet/management/src/models/system_info.rs b/edgelet/management/src/models/system_info.rs index 9ed735d727..431f682245 100644 --- a/edgelet/management/src/models/system_info.rs +++ b/edgelet/management/src/models/system_info.rs @@ -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 + } } diff --git a/versionInfo.json b/versionInfo.json index bc9c7594d8..d1b5078740 100644 --- a/versionInfo.json +++ b/versionInfo.json @@ -1,5 +1,5 @@ { - "version" : "1.0.1-dev", - "build" : "BUILDNUMBER", - "commit" : "COMMITID" + "version": "1.0.1-dev", + "build": "BUILDNUMBER", + "commit": "COMMITID" }