public void TestAddDeploymentForExistingApp() { _deploymentConfig = _deploymentConfig.AddApplication(new AppIdentity("app3", "1.0.13"), "clusterId13"); AssertUtils.ContainsSameElementsInAnyOrder(new[] { "1.0.13", "2.0.0-beta" }, _deploymentConfig.ListVersions("app3")); AssertUtils.ContainsSameElementsInAnyOrder(new[] { "clusterId3", "clusterId13" }, _deploymentConfig.ListClusters("app3")); }
public void GetExecutionPlan_WhereTaskHasDuplicateExplicitHostsProvided_ReturnsOnePlan() { // Arrange var taskblock = typeof(DuplicateExplicitHosts); var host = new Host { Hostname = SomeHostname }; var config = new DeploymentConfig { Hosts = new[] { host } }; var expected = new List<ExecutionPlan> { new ExecutionPlan(host, taskblock.GetObjMethods("Task1")) }; // Act var manager = new DeploymentManager<DuplicateExplicitHosts>(config); var actual = manager.GetExecutionPlans(); // Assert CollectionAssert.AreEqual( expected.OrderBy(p => p.Host.Hostname).ToList(), actual.OrderBy(p => p.Host.Hostname).ToList()); }
public async Task ReportShutdownAsyncConfigTest() { // Arrange var mockConfigSource = new Mock <IConfigSource>(); var mockEnvironment = new Mock <IEnvironment>(); var mockPlanner = new Mock <IPlanner>(); var mockPlanRunner = new Mock <IPlanRunner>(); var mockReporter = new Mock <IReporter>(); var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>(); var configStore = Mock.Of <IEntityStore <string, string> >(); var mockEnvironmentProvider = Mock.Of <IEnvironmentProvider>(m => m.Create(It.IsAny <DeploymentConfig>()) == mockEnvironment.Object); var serde = Mock.Of <ISerde <DeploymentConfigInfo> >(); var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>(); var deploymentConfig = new DeploymentConfig( "1.0", Mock.Of <IRuntimeInfo>(), new SystemModules(null, null), new Dictionary <string, IModule> { { "mod1", new TestModule("mod1", "1.0", "docker", ModuleStatus.Running, new TestConfig("boo"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null) } }); var deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig); var token = default(CancellationToken); mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync()) .ReturnsAsync(deploymentConfigInfo); mockEnvironment.Setup(e => e.GetModulesAsync(token)) .ReturnsAsync(ModuleSet.Empty); var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider, mockPlanner.Object, mockPlanRunner.Object, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider); await agent.ReportShutdownAsync(token); // Assert mockReporter.Verify(r => r.ReportShutdown(It.IsAny <DeploymentStatus>(), token)); }
public void GetExecutionPlan_WhereTaskHasDependencyNotSpecifiedForHost_AddsDependencyToPlan() { // Arrange var taskblock = typeof(InheritDependencies); var host = new Host { Hostname = SomeHostname }; var config = new DeploymentConfig { Hosts = new[] { host } }; var expected = new List<ExecutionPlan> { new ExecutionPlan(host, taskblock.GetObjMethods("Task1", "Task2")) }; // Act var manager = new DeploymentManager<InheritDependencies>(config); var actual = manager.GetExecutionPlans(); // Assert CollectionAssert.AreEqual( expected.OrderBy(p => p.Host.Hostname).ToList(), actual.OrderBy(p => p.Host.Hostname).ToList()); }
public async Task GetRuntimeInfoTest() { // Arrange var systemInfo = new SystemInfo(OperatingSystemType, Architecture, Version); var store = Mock.Of <IEntityStore <string, ModuleState> >(); var restartPolicyManager = Mock.Of <IRestartPolicyManager>(); var runtimeInfoProvider = Mock.Of <IRuntimeInfoProvider>(r => r.GetSystemInfo(CancellationToken.None) == Task.FromResult(systemInfo)); var moduleStateStore = Mock.Of <IEntityStore <string, ModuleState> >(); string minDockerVersion = "20"; string dockerLoggingOptions = "dummy logging options"; var deploymentConfig = new DeploymentConfig( "1.0", new DockerRuntimeInfo("docker", new DockerRuntimeConfig(minDockerVersion, dockerLoggingOptions)), new SystemModules(Option.None <IEdgeAgentModule>(), Option.None <IEdgeHubModule>()), new Dictionary <string, IModule>()); var environment = new DockerEnvironment(runtimeInfoProvider, deploymentConfig, moduleStateStore, restartPolicyManager, systemInfo.OperatingSystemType, systemInfo.Architecture, systemInfo.Version); // act IRuntimeInfo reportedRuntimeInfo = await environment.GetRuntimeInfoAsync(); // assert Assert.True(reportedRuntimeInfo is DockerReportedRuntimeInfo); 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); }
public async void ReconcileAsyncOnSetPlan() { var desiredModule = new TestModule("desired", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null); var currentModule = new TestModule("current", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null); var recordKeeper = Option.Some(new TestPlanRecorder()); var moduleExecutionList = new List <TestRecordType> { new TestRecordType(TestCommandType.TestCreate, desiredModule), new TestRecordType(TestCommandType.TestRemove, currentModule) }; var commandList = new List <ICommand> { new TestCommand(TestCommandType.TestCreate, desiredModule, recordKeeper), new TestCommand(TestCommandType.TestRemove, currentModule, recordKeeper) }; var testPlan = new Plan(commandList); var token = new CancellationToken(); var runtimeInfo = Mock.Of <IRuntimeInfo>(); var deploymentConfig = new DeploymentConfig("1.0", runtimeInfo, new SystemModules(null, null), new Dictionary <string, IModule> { ["desired"] = desiredModule }); var deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig); ModuleSet desiredSet = deploymentConfig.GetModuleSet(); ModuleSet currentSet = ModuleSet.Create(currentModule); var mockConfigSource = new Mock <IConfigSource>(); var mockEnvironment = new Mock <IEnvironment>(); var mockPlanner = new Mock <IPlanner>(); var planRunner = new OrderedPlanRunner(); var mockReporter = new Mock <IReporter>(); var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>(); var configStore = Mock.Of <IEntityStore <string, string> >(); var mockEnvironmentProvider = Mock.Of <IEnvironmentProvider>(m => m.Create(It.IsAny <DeploymentConfig>()) == mockEnvironment.Object); var serde = Mock.Of <ISerde <DeploymentConfigInfo> >(); var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>(); mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync()) .ReturnsAsync(deploymentConfigInfo); mockEnvironment.Setup(env => env.GetModulesAsync(token)) .ReturnsAsync(currentSet); mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(desiredSet, currentSet)) .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty); mockPlanner.Setup(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty)) .Returns(Task.FromResult(testPlan)); mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(It.IsAny <ModuleSet>(), currentSet)) .Returns(Task.FromResult((IImmutableDictionary <string, IModuleIdentity>)ImmutableDictionary <string, IModuleIdentity> .Empty)); mockReporter.Setup(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), Option.Some(DeploymentStatus.Success))) .Returns(Task.CompletedTask); var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider, mockPlanner.Object, planRunner, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider); await agent.ReconcileAsync(token); mockEnvironment.Verify(env => env.GetModulesAsync(token), Times.Exactly(1)); mockPlanner.Verify(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty), Times.Once); mockReporter.VerifyAll(); recordKeeper.ForEach(r => Assert.Equal(moduleExecutionList, r.ExecutionList)); }
public void TestAddDeploymentForExistingVersion() { _deploymentConfig = _deploymentConfig.AddApplication(new AppIdentity("app2", "1.0.0"), "deploymentid13"); AssertUtils.ContainsSameElementsInAnyOrder(new[] { "1.0.0" }, _deploymentConfig.ListVersions("app2")); AssertUtils.ContainsSameElementsInAnyOrder(new[] { "deploymentid1", "deploymentid13" }, _deploymentConfig.ListDeploymentIds("app2")); }
public void BasicTest() { var edgeAgentModule = Mock.Of <IEdgeAgentModule>(m => m.Name == "edgeAgent"); var edgeHubModule = Mock.Of <IEdgeHubModule>(m => m.Name == "edgeHub"); var systemModules = new SystemModules(edgeAgentModule, edgeHubModule); var mod1 = new TestModule(null, string.Empty, "test", ModuleStatus.Running, new TestConfig("mod1"), RestartPolicy.Always, ImagePullPolicy.OnCreate, Constants.DefaultPriority, new ConfigurationInfo(), null); var mod2 = new TestModule(null, string.Empty, "test", ModuleStatus.Running, new TestConfig("mod2"), RestartPolicy.Always, ImagePullPolicy.OnCreate, Constants.DefaultPriority, new ConfigurationInfo(), null); var modules = new Dictionary <string, IModule> { ["mod1"] = mod1, ["mod2"] = mod2 }; var deploymentConfig = new DeploymentConfig("1.0", Mock.Of <IRuntimeInfo>(), systemModules, modules); Assert.Equal("mod1", deploymentConfig.Modules["mod1"].Name); Assert.Equal("mod2", deploymentConfig.Modules["mod2"].Name); ModuleSet moduleSet = deploymentConfig.GetModuleSet(); Assert.NotNull(moduleSet); Assert.Equal(4, moduleSet.Modules.Count); Assert.Equal(edgeHubModule.Name, moduleSet.Modules["edgeHub"].Name); Assert.Equal(edgeAgentModule.Name, moduleSet.Modules["edgeAgent"].Name); Assert.Equal(modules["mod1"].Name, moduleSet.Modules["mod1"].Name); Assert.Equal(modules["mod2"].Name, moduleSet.Modules["mod2"].Name); }
public void BasicTest(string[] signercert, string[] intermediatecacert, string signature, string algo) { var edgeAgentModule = Mock.Of <IEdgeAgentModule>(m => m.Name == "edgeAgent"); var edgeHubModule = Mock.Of <IEdgeHubModule>(m => m.Name == "edgeHub"); var systemModules = new SystemModules(edgeAgentModule, edgeHubModule); var mod1 = new TestModule(null, string.Empty, "test", ModuleStatus.Running, new TestConfig("mod1"), RestartPolicy.Always, ImagePullPolicy.OnCreate, Constants.DefaultStartupOrder, new ConfigurationInfo(), null); var mod2 = new TestModule(null, string.Empty, "test", ModuleStatus.Running, new TestConfig("mod2"), RestartPolicy.Always, ImagePullPolicy.OnCreate, Constants.DefaultStartupOrder, new ConfigurationInfo(), null); var modules = new Dictionary <string, IModule> { ["mod1"] = mod1, ["mod2"] = mod2 }; var deploymentConfig = new DeploymentConfig("1.0", Mock.Of <IRuntimeInfo>(), systemModules, modules, null); ManifestIntegrity integrity = new ManifestIntegrity(new TwinHeader(signercert, intermediatecacert), new TwinSignature(signature, algo)); var deploymentConfigWithTwinIntegrity = new DeploymentConfig("1.0", Mock.Of <IRuntimeInfo>(), systemModules, modules, integrity); Assert.Equal("mod1", deploymentConfig.Modules["mod1"].Name); Assert.Equal("mod2", deploymentConfig.Modules["mod2"].Name); ModuleSet moduleSet = deploymentConfig.GetModuleSet(); Assert.NotNull(moduleSet); Assert.Equal(4, moduleSet.Modules.Count); Assert.Equal(edgeHubModule.Name, moduleSet.Modules["edgeHub"].Name); Assert.Equal(edgeAgentModule.Name, moduleSet.Modules["edgeAgent"].Name); Assert.Equal(modules["mod1"].Name, moduleSet.Modules["mod1"].Name); Assert.Equal(modules["mod2"].Name, moduleSet.Modules["mod2"].Name); Assert.Equal(deploymentConfigWithTwinIntegrity.Integrity, Option.Some(integrity)); }
public async void ReconcileAsyncAbortsWhenEnvironmentSourceThrows() { // Arrange var mockConfigSource = new Mock <IConfigSource>(); var mockEnvironment = new Mock <IEnvironment>(); var mockPlanner = new Mock <IPlanner>(); var mockPlanRunner = new Mock <IPlanRunner>(); var mockReporter = new Mock <IReporter>(); var token = default(CancellationToken); var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>(); var configStore = Mock.Of <IEntityStore <string, string> >(); var mockEnvironmentProvider = Mock.Of <IEnvironmentProvider>(m => m.Create(It.IsAny <DeploymentConfig>()) == mockEnvironment.Object); var serde = Mock.Of <ISerde <DeploymentConfigInfo> >(); var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>(); var deploymentConfig = new DeploymentConfig("1.0", Mock.Of <IRuntimeInfo>(), new SystemModules(null, null), new Dictionary <string, IModule>()); var deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig); mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync()) .ReturnsAsync(deploymentConfigInfo); mockEnvironment.Setup(env => env.GetModulesAsync(token)).Throws <InvalidOperationException>(); mockReporter.Setup(r => r.ReportAsync(token, null, It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), It.Is <DeploymentStatus>(s => s.Code == DeploymentStatusCode.Failed))) .Returns(Task.CompletedTask); var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider, mockPlanner.Object, mockPlanRunner.Object, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider); // Act // Assert await agent.ReconcileAsync(token); mockPlanner.Verify(p => p.PlanAsync(It.IsAny <ModuleSet>(), It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <ImmutableDictionary <string, IModuleIdentity> >()), Times.Never); mockReporter.VerifyAll(); mockPlanRunner.Verify(r => r.ExecuteAsync(1, It.IsAny <Plan>(), token), Times.Never); }
public void TestEqualsAndHashCode() { DeploymentConfig deploymentConfig = _fixture.ParseTestDeploymentConfig(); Assert.Equal(_deploymentConfig, deploymentConfig); Assert.Equal(_deploymentConfig.GetHashCode(), deploymentConfig.GetHashCode()); }
public IEnvironment Create(DeploymentConfig deploymentConfig) => new KubernetesEnvironment( this.moduleStatusProvider, deploymentConfig, this.store, this.operatingSystemType, this.architecture, this.version);
public void EqualityTest(DeploymentConfig config1, DeploymentConfig config2, bool areEqual) { // Act bool result = config1.Equals(config2); // Assert Assert.Equal(areEqual, result); }
public async void ReconcileAsyncReportsFailedWhenEncryptProviderThrows() { var token = default(CancellationToken); var serde = Mock.Of <ISerde <DeploymentConfigInfo> >(); var mockConfigSource = new Mock <IConfigSource>(); var mockEnvironment = new Mock <IEnvironment>(); var mockEnvironmentProvider = new Mock <IEnvironmentProvider>(); var mockPlanner = new Mock <IPlanner>(); var mockPlanRunner = new Mock <IPlanRunner>(); var mockReporter = new Mock <IReporter>(); var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>(); var runtimeInfo = Mock.Of <IRuntimeInfo>(); var configStore = Mock.Of <IEntityStore <string, string> >(); var encryptionDecryptionProvider = new Mock <IEncryptionProvider>(); var availabilityMetric = Mock.Of <IAvailabilityMetric>(); var deploymentConfig = new DeploymentConfig( "1.0", runtimeInfo, new SystemModules(null, null), new Dictionary <string, IModule> { { "mod1", new TestModule("mod1", "1.0", "docker", ModuleStatus.Running, new TestConfig("boo"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null) } }); var desiredModule = new TestModule("desired", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null); var recordKeeper = Option.Some(new TestPlanRecorder()); var deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig); ModuleSet desiredModuleSet = deploymentConfig.GetModuleSet(); ModuleSet currentModuleSet = desiredModuleSet; var commandList = new List <ICommand> { new TestCommand(TestCommandType.TestCreate, desiredModule, recordKeeper) }; var testPlan = new Plan(commandList); mockEnvironmentProvider.Setup(m => m.Create(It.IsAny <DeploymentConfig>())).Returns(mockEnvironment.Object); mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync()) .ReturnsAsync(deploymentConfigInfo); mockEnvironment.Setup(env => env.GetModulesAsync(token)) .ReturnsAsync(currentModuleSet); mockEnvironment.Setup(env => env.GetRuntimeInfoAsync()).ReturnsAsync(runtimeInfo); mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet)) .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty); mockPlanner.Setup(pl => pl.PlanAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty)) .ReturnsAsync(testPlan); encryptionDecryptionProvider.Setup(ep => ep.EncryptAsync(It.IsAny <string>())) .ThrowsAsync(new WorkloadCommunicationException("failed", 404)); var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider.Object, mockPlanner.Object, mockPlanRunner.Object, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider.Object, availabilityMetric); await agent.ReconcileAsync(token); // Assert mockPlanner.Verify(p => p.PlanAsync(It.IsAny <ModuleSet>(), It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <ImmutableDictionary <string, IModuleIdentity> >()), Times.Once); mockReporter.Verify(r => r.ReportAsync(It.IsAny <CancellationToken>(), It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), 0, new DeploymentStatus(DeploymentStatusCode.Failed, "failed"))); mockPlanRunner.Verify(r => r.ExecuteAsync(0, It.IsAny <Plan>(), token), Times.Once); encryptionDecryptionProvider.Verify(ep => ep.EncryptAsync(It.IsAny <string>()), Times.Exactly(2)); }
/// <summary> /// Initializes the control. /// </summary> public void Init(AppData appData, DeploymentConfig deploymentConfig, ProjectInstance projectInstance) { this.appData = appData ?? throw new ArgumentNullException(nameof(appData)); this.deploymentConfig = deploymentConfig ?? throw new ArgumentNullException(nameof(deploymentConfig)); this.projectInstance = projectInstance ?? throw new ArgumentNullException(nameof(projectInstance)); txtInstanceName.Text = projectInstance.Name; FillProfileList(); }
public void TestSerializeRoundTrip() { string serialized = JObject.Parse(_serializer.Serialize(_deploymentConfig)).ToString(); DeploymentConfig deploymentConfig = _serializer.Deserialize(serialized); string roundTripJson = JObject.Parse(_serializer.Serialize(deploymentConfig)).ToString(); Assert.Equal(_deploymentConfig, deploymentConfig); Assert.Equal(serialized, roundTripJson); }
private async void OnRemoveApplication(object sender, RoutedEventArgs e) { StorageAccountConnectionInfo connectionInfo = GetCurrentConnection(); string appId = GetSelectedAppId(); _deploymentConfig = _deploymentConfig.RemoveApplication(appId); SaveLocalDeploymentConfig(connectionInfo); await HandleConnectionSelection(); }
public IEnvironment Create(DeploymentConfig deploymentConfig) => new DockerEnvironment( this.moduleStatusProvider, deploymentConfig, this.store, this.restartPolicyManager, this.operatingSystemType, this.architecture, this.version);
public async Task TestPublishThenFetchDeploymentConfig() { string data = File.ReadAllText(_deploymentConfigFilePath); DeploymentConfig deploymentConfig = _serializer.Deserialize(data); await _deploymentRepository.PublishDeploymentConfig(deploymentConfig); DeploymentConfig newDeploymentConfig = await _deploymentRepository.FetchDeploymentConfig(); Assert.Equal(_serializer.Serialize(deploymentConfig), _serializer.Serialize(newDeploymentConfig)); }
public async Task TestPublishThenFetchDeploymentConfig() { string data = File.ReadAllText(_deploymentConfigFilePath); DeploymentConfig deploymentConfig = new DeploymentConfig(data); await _deploymentRepository.PublishDeploymentConfig(deploymentConfig); DeploymentConfig newDeploymentConfig = await _deploymentRepository.FetchDeploymentConfig(); Assert.Equal(deploymentConfig.RawData(), newDeploymentConfig.RawData()); }
/// <summary> /// Sets the project properties to the defaults. /// </summary> private void SetToDefault() { fileName = ""; Name = DefaultName; Version = ProjectVersion.Default; Description = ""; ConfigDatabase = new ConfigDatabase(); Views = new ProjectViews(); Instances = new List <ProjectInstance>(); DeploymentConfig = new DeploymentConfig(); }
private void OnRemoveDeployment(object sender, RoutedEventArgs e) { StorageAccountConnectionInfo connectionInfo = GetCurrentConnection(); DeploymentInfo deploymendInfo = deploymentIdsListView.SelectedItem as DeploymentInfo; if (deploymendInfo == null) { return; } _deploymentConfig = _deploymentConfig.RemoveApplication(deploymendInfo.AppIdentity, deploymendInfo.DeploymentId); SaveLocalDeploymentConfig(connectionInfo); }
static void Main(string[] args) { var serializer = new XmlSerializer(typeof(Config)); var config = (Config)serializer.Deserialize(XmlReader.Create(args[0])); var deploymentConfig = new DeploymentConfig<Config> { Hosts = config.Hosts }; var manager = new DeploymentManager<Tasks, Config>(deploymentConfig); manager.BeginDeployments(); }
private void OnVersionAddDeployment(object sender, RoutedEventArgs e) { StorageAccountConnectionInfo connectionInfo = GetCurrentConnection(); string appId = GetSelectedAppId(); string version = GetSelectedVersion(); AddNewDeploymentDialog dialog = new AddNewDeploymentDialog(appId, version); if (dialog.ShowDialog() == true) { AppIdentity appIdentity = new AppIdentity(appId, new Version(version)); _deploymentConfig = _deploymentConfig.AddApplication(appIdentity, dialog.DeploymentId); SaveLocalDeploymentConfig(connectionInfo); } }
public DockerEnvironment(IRuntimeInfoProvider moduleStatusProvider, DeploymentConfig deploymentConfig, IEntityStore <string, ModuleState> moduleStateStore, IRestartPolicyManager restartManager, string operatingSystemType, string architecture) { this.moduleStatusProvider = moduleStatusProvider; this.deploymentConfig = deploymentConfig; this.moduleStateStore = moduleStateStore; this.restartManager = restartManager; this.operatingSystemType = operatingSystemType; this.architecture = architecture; }
private async void OnSyncFromBlob(object sender, RoutedEventArgs e) { MessageBoxResult res = MessageBox.Show("This will ovewrite any local changes\n\n Are you sure you want to continue?", "Sync From Blob", MessageBoxButton.YesNo); if (res == MessageBoxResult.Yes) { StorageAccountConnectionInfo connectionInfo = GetCurrentConnection(); IDeploymentRepository connection = _deploymentRepositoryManager.GetRepository(connectionInfo); DeploymentConfig deploymentConfig = await connection.FetchDeploymentConfig(); SaveLocalDeploymentConfig(connectionInfo, deploymentConfig.RawData()); } }
private async Task <DeploymentConfig> FetchDeploymentConfig(StorageAccountConnectionInfo connectionInfo) { string path = GetDeploymentConfigLocalPath(connectionInfo.AccountName); if (File.Exists(path)) { return(new DeploymentConfig(File.ReadAllText(path))); } IDeploymentRepository connection = _deploymentRepositoryManager.GetRepository(connectionInfo); DeploymentConfig deploymentConfig = await connection.FetchDeploymentConfig(); SaveLocalDeploymentConfig(connectionInfo, deploymentConfig.RawData()); return(deploymentConfig); }
public async void GetDeploymentConfigTest2() { // Arrange var runtimeInfo = Mock.Of <IRuntimeInfo>(); var edgeHubModule = Mock.Of <IEdgeHubModule>(m => m.Name == "$edgeHub"); var edgeAgentModule = Mock.Of <IEdgeAgentModule>(m => m.Name == "$edgeAgent"); var systemModules = new SystemModules(edgeAgentModule, edgeHubModule); string customModule1Name = null; string customModule2Name = null; var customModule1 = Mock.Of <IModule>(); var customModule2 = Mock.Of <IModule>(); Mock.Get(customModule1).SetupSet(n => n.Name = It.IsAny <string>()).Callback <string>(n => customModule1Name = n); Mock.Get(customModule2).SetupSet(n => n.Name = It.IsAny <string>()).Callback <string>(n => customModule2Name = n); IDictionary <string, IModule> modules = new Dictionary <string, IModule> { ["module1"] = customModule1, ["module2"] = customModule2 }; var deploymentConfig = new DeploymentConfig("1.0", runtimeInfo, systemModules, modules); var deploymentConfigInfo = new DeploymentConfigInfo(5, deploymentConfig); var edgeAgentConnection = new Mock <IEdgeAgentConnection>(); edgeAgentConnection.Setup(e => e.GetDeploymentConfigInfoAsync()).ReturnsAsync(Option.Some(deploymentConfigInfo)); var configuration = Mock.Of <IConfiguration>(); var twinConfigSource = new TwinConfigSource(edgeAgentConnection.Object, configuration); // Act DeploymentConfigInfo receivedDeploymentConfigInfo = await twinConfigSource.GetDeploymentConfigInfoAsync(); // Assert Assert.NotNull(receivedDeploymentConfigInfo); Assert.NotNull(receivedDeploymentConfigInfo.DeploymentConfig); Assert.Equal(5, receivedDeploymentConfigInfo.Version); DeploymentConfig returnedDeploymentConfig = receivedDeploymentConfigInfo.DeploymentConfig; Assert.Equal(Option.Some(edgeAgentModule), returnedDeploymentConfig.SystemModules.EdgeAgent); Assert.Equal(Option.Some(edgeHubModule), returnedDeploymentConfig.SystemModules.EdgeHub); ModuleSet moduleSet = returnedDeploymentConfig.GetModuleSet(); Assert.Equal(4, returnedDeploymentConfig.GetModuleSet().Modules.Count); Assert.Equal(customModule1.Name, moduleSet.Modules["module1"].Name); Assert.Equal(customModule2.Name, moduleSet.Modules["module2"].Name); Assert.Equal(edgeHubModule.Name, moduleSet.Modules["$edgeHub"].Name); Assert.Equal(edgeAgentModule.Name, moduleSet.Modules["$edgeAgent"].Name); Assert.Equal("module1", customModule1Name); Assert.Equal("module2", customModule2Name); }
public KubernetesEnvironment( IRuntimeInfoProvider moduleStatusProvider, DeploymentConfig deploymentConfig, IEntityStore <string, ModuleState> moduleStateStore, string operatingSystemType, string architecture, string version) { this.moduleStatusProvider = moduleStatusProvider; this.deploymentConfig = deploymentConfig; this.moduleStateStore = moduleStateStore; this.operatingSystemType = operatingSystemType; this.architecture = architecture; this.version = version; }
private async Task AddApplication(AppIdentity appIdentity, string deploymentId, string binariesPath) { StorageAccountConnectionInfo connectionInfo = GetCurrentConnection(); IDeploymentRepository repository = _deploymentRepositoryManager.GetRepository(connectionInfo); BusyWindow busyWindow = new BusyWindow { Message = "Please wait..\n\n" + "The binaries are being uploaded to blob storage" }; busyWindow.Show(); await repository.UploadApplicationBinaries(appIdentity, binariesPath, ConflictResolutionMode.DoNothingIfBinariesExist); busyWindow.Close(); _deploymentConfig = _deploymentConfig.AddApplication(appIdentity, deploymentId); SaveLocalDeploymentConfig(connectionInfo); }
public async void ReconcileAsyncOnEmptyPlan() { var token = default(CancellationToken); var serde = Mock.Of <ISerde <DeploymentConfigInfo> >(); var mockConfigSource = new Mock <IConfigSource>(); var mockEnvironment = new Mock <IEnvironment>(); var mockEnvironmentProvider = new Mock <IEnvironmentProvider>(); var mockPlanner = new Mock <IPlanner>(); var mockPlanRunner = new Mock <IPlanRunner>(); var mockReporter = new Mock <IReporter>(); var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>(); var runtimeInfo = Mock.Of <IRuntimeInfo>(); var configStore = Mock.Of <IEntityStore <string, string> >(); var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>(); var availabilityMetric = Mock.Of <IAvailabilityMetric>(); var deploymentConfig = new DeploymentConfig( "1.0", runtimeInfo, new SystemModules(null, null), new Dictionary <string, IModule> { { "mod1", new TestModule("mod1", "1.0", "docker", ModuleStatus.Running, new TestConfig("boo"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null) } }); var deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig); ModuleSet desiredModuleSet = deploymentConfig.GetModuleSet(); ModuleSet currentModuleSet = desiredModuleSet; mockEnvironmentProvider.Setup(m => m.Create(It.IsAny <DeploymentConfig>())).Returns(mockEnvironment.Object); mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync()) .ReturnsAsync(deploymentConfigInfo); mockEnvironment.Setup(env => env.GetModulesAsync(token)) .ReturnsAsync(currentModuleSet); mockEnvironment.Setup(env => env.GetRuntimeInfoAsync()).ReturnsAsync(runtimeInfo); mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet)) .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty); mockPlanner.Setup(pl => pl.PlanAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty)) .Returns(Task.FromResult(Plan.Empty)); var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider.Object, mockPlanner.Object, mockPlanRunner.Object, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider, availabilityMetric); await agent.ReconcileAsync(token); mockEnvironment.Verify(env => env.GetModulesAsync(token), Times.Once); mockPlanner.Verify(pl => pl.PlanAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty), Times.Once); mockReporter.Verify(r => r.ReportAsync(token, currentModuleSet, runtimeInfo, DeploymentConfigInfo.Empty.Version, DeploymentStatus.Success), Times.Once); mockPlanRunner.Verify(r => r.ExecuteAsync(1, Plan.Empty, token), Times.Never); }
internal static void ValidateSchemaVersion(DeploymentConfig config) { string schemaVersion = config.SchemaVersion; if (string.IsNullOrWhiteSpace(schemaVersion) || !Version.TryParse(schemaVersion, out Version actualSchemaVersion)) { throw new InvalidSchemaVersionException($"Invalid desired properties schema version {schemaVersion}"); } // Check major version and upper bound if (actualSchemaVersion.Major != ExpectedSchemaVersion.Major || actualSchemaVersion > ExpectedSchemaVersion) { throw new InvalidSchemaVersionException($"The desired properties schema version {schemaVersion} is not compatible with the expected version {ExpectedSchemaVersion}"); } }
public async void ReconcileAsyncWithNoDeploymentChange() { var desiredModule = new TestModule("CustomModule", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null); var currentModule = new TestModule("CustomModule", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null); var testPlan = new Plan(new List <ICommand>()); var token = default(CancellationToken); var runtimeInfo = Mock.Of <IRuntimeInfo>(); var deploymentConfig = new DeploymentConfig("1.0", runtimeInfo, new SystemModules(null, null), new Dictionary <string, IModule> { ["CustomModule"] = desiredModule }); var deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig); ModuleSet desiredSet = deploymentConfig.GetModuleSet(); ModuleSet currentSet = ModuleSet.Create(currentModule); var mockConfigSource = new Mock <IConfigSource>(); var mockEnvironment = new Mock <IEnvironment>(); var mockPlanner = new Mock <IPlanner>(); var planRunner = new OrderedPlanRunner(); var mockReporter = new Mock <IReporter>(); var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>(); var configStore = Mock.Of <IEntityStore <string, string> >(); var mockEnvironmentProvider = Mock.Of <IEnvironmentProvider>(m => m.Create(It.IsAny <DeploymentConfig>()) == mockEnvironment.Object); var serde = Mock.Of <ISerde <DeploymentConfigInfo> >(); var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>(); var availabilityMetric = Mock.Of <IAvailabilityMetric>(); mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync()) .ReturnsAsync(deploymentConfigInfo); mockEnvironment.Setup(env => env.GetModulesAsync(token)) .ReturnsAsync(currentSet); mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(desiredSet, currentSet)) .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty); mockPlanner.Setup(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty)) .Returns(Task.FromResult(testPlan)); mockReporter.Setup(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), DeploymentStatus.Success)) .Returns(Task.CompletedTask); var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider, mockPlanner.Object, planRunner, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider, availabilityMetric); await agent.ReconcileAsync(token); mockEnvironment.Verify(env => env.GetModulesAsync(token), Times.Exactly(1)); mockPlanner.Verify(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty), Times.Once); mockReporter.Verify(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), DeploymentStatus.Success), Times.Once); }
public void GetExecutionPlan_WhereTaskHasOneRoleAttributeAndMultipleHostsProvided_ReturnsMultiplePlans() { // Arrange var taskblock = typeof(RoleMultipleHosts); var host = new Host { Hostname = SomeHostname, Roles = new[] { SomeRole } }; var host2 = new Host { Hostname = SomeHostname2, Roles = new[] { SomeRole } }; var config = new DeploymentConfig { Hosts = new[] { host, host2 } }; var expected = new List<ExecutionPlan> { new ExecutionPlan(host, taskblock.GetObjMethods("Task1")), new ExecutionPlan(host2, taskblock.GetObjMethods("Task1")) }; // Act var manager = new DeploymentManager<RoleMultipleHosts>(config); var actual = manager.GetExecutionPlans(); // Assert CollectionAssert.AreEqual( expected.OrderBy(p => p.Host.Hostname).ToList(), actual.OrderBy(p => p.Host.Hostname).ToList()); }
public void GetExecutionPlan_WhereTaskNotIncludedAsDependency_IsNotPresentInPlan() { // Arrange var taskblock = typeof(UnusedTask); var host = new Host { Hostname = SomeHostname }; var config = new DeploymentConfig { Hosts = new[] { host } }; var expected = new List<ExecutionPlan> { new ExecutionPlan(host, taskblock.GetObjMethods("Task2", "Task3")) }; // Act var manager = new DeploymentManager<UnusedTask>(config); var actual = manager.GetExecutionPlans(); // Assert CollectionAssert.AreEqual( expected.OrderBy(p => p.Host.Hostname).ToList(), actual.OrderBy(p => p.Host.Hostname).ToList()); }
public void GetExecutionPlan_WhereTaskHasOneHostAttributeAndAliasProvided_ReturnsOnePlan() { // Arrange var taskblock = typeof(HostAttrs); var host = new Host { Alias = SomeHostname, Hostname = "something else" }; var config = new DeploymentConfig { Hosts = new[] { host } }; var expected = new List<ExecutionPlan> { new ExecutionPlan(host, taskblock.GetObjMethods("Task1")) }; // Act var manager = new DeploymentManager<HostAttrs>(config); var actual = manager.GetExecutionPlans(); // Assert CollectionAssert.AreEqual( expected.OrderBy(p => p.Host.Hostname).ToList(), actual.OrderBy(p => p.Host.Hostname).ToList()); }
public void GetExecutionPlan_WhereTaskHasInitializationAndCleanup_ReturnsInitializationFirstAndCleanupLast() { // Arrange var taskblock = typeof(InitializationAndCleanup); var host = new Host { Hostname = SomeHostname }; var config = new DeploymentConfig { Hosts = new[] { host } }; var expected = new List<ExecutionPlan> { new ExecutionPlan(host, taskblock.GetObjMethods("Init", "Task1", "Cleanup")) }; // Act var manager = new DeploymentManager<InitializationAndCleanup>(config); var actual = manager.GetExecutionPlans(); // Assert CollectionAssert.AreEqual(expected.ToList(), actual.ToList()); }
public void GetExecutionPlan_WhereTaskHasOverlappingHostAndRole_ReturnsOnePlan() { // Arrange var taskblock = typeof(OverlappingHostAndRole); var host = new Host { Hostname = SomeHostname, Roles = new[] { SomeRole } }; var config = new DeploymentConfig { Hosts = new[] { host } }; var expected = new List<ExecutionPlan> { new ExecutionPlan(host, taskblock.GetObjMethods("Task1")) }; // Act var manager = new DeploymentManager<OverlappingHostAndRole>(config); var actual = manager.GetExecutionPlans(); // Assert CollectionAssert.AreEqual( expected.OrderBy(p => p.Host.Hostname).ToList(), actual.OrderBy(p => p.Host.Hostname).ToList()); }