Beispiel #1
0
        public async Task TestThatClusterPropertiesAreUsedToMatchDeployments()
        {
            UploadDeploymentConfig("DeploymentConfigWithProperties.json");
            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                                                   _applicationsInstallPath).SetShowApplicationProcessWindow(false)
                             .AddClusterProperty("NodeType", "Test")
                             .AddClusterProperty("Region", "East").Build();

            AppInstallConfig appInstallConfig = null;
            var applicationInstallerStub      = new StubIApplicationInstaller().Install(
                (config) =>
            {
                Assert.Null(appInstallConfig);
                appInstallConfig = config;
                return(Task.CompletedTask);
            });

            ContainerBuilder builder = InitializeContainerBuilder(yamsConfig);

            builder.RegisterInstance <IApplicationInstaller>(applicationInstallerStub);
            InitializeYamsService(builder.Build());

            IApplicationUpdateManager applicationUpdateManager = _yamsDiModule.Container.Resolve <IApplicationUpdateManager>();
            await applicationUpdateManager.CheckForUpdates();

            Assert.Equal(new AppIdentity("test.app1", new SemVersion(1, 0, 0)), appInstallConfig.AppIdentity);
            Assert.True(appInstallConfig.Properties.ContainsKey("NodeType"));
            Assert.Equal("Test", appInstallConfig.Properties["NodeType"]);
            Assert.True(appInstallConfig.Properties.ContainsKey("Region"));
            Assert.Equal("East", appInstallConfig.Properties["Region"]);
        }
Beispiel #2
0
        public async Task TestThatUpdateSessionIsEndedFollowingASuccessfulUpdate()
        {
            IEnumerable <AppIdentity> appsToDeploy = new[] { app1v2 };
            IEnumerable <string>      clusters     = new[] { "clusterId1" };

            IApplicationPool applicationPool = new ApplicationPoolStub();
            string           path            = Path.GetTempPath();
            await applicationPool.AddApplication(new ApplicationStub(app1v1, path));

            bool updateSessionEnded = false;
            IUpdateSessionManager updateSessionManagerStub = new StubIUpdateSessionManager()
                                                             .TryStartUpdateSession(() => Task.FromResult(true))
                                                             .EndUpdateSession(() =>
            {
                updateSessionEnded = true;
                return(Task.CompletedTask);
            });

            IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory()
                                                                             .FetchDeployments(() => Task.FromResult(appsToDeploy.Select(identity => new AppDeploymentConfig(identity, clusters))));

            var applicationInstallerStub = new StubIApplicationInstaller()
                                           .Install((config) => throw new Exception("Failed to install application"));
            const string             ClusterId  = "clusterId";
            const string             InstanceId = "instanceId";
            ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager(ClusterId, InstanceId,
                                                                                             applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstallerStub,
                                                                                             deploymentStatusWriterStub, updateSessionManagerStub);
            await applicationUpdateManager.CheckForUpdates();

            Assert.False(updateSessionEnded);
        }
Beispiel #3
0
        public async Task TestThatClusterPropertiesAreUsedToMatchDeployments()
        {
            UploadDeploymentConfig("DeploymentConfigWithProperties.json");
            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                                                   _applicationsInstallPath).SetUseShellExecute(false)
                             .AddClusterProperty("NodeType", "Test")
                             .AddClusterProperty("Region", "East").Build();

            var installedApps            = new List <AppInstallConfig>();
            var applicationInstallerStub = new StubIApplicationInstaller().Install(
                (config) =>
            {
                installedApps.Add(config);
                return(Task.CompletedTask);
            });

            ContainerBuilder builder = InitializeContainerBuilder(yamsConfig);

            builder.RegisterInstance <IApplicationInstaller>(applicationInstallerStub);
            InitializeYamsService(builder.Build());

            IApplicationUpdateManager applicationUpdateManager = _yamsDiModule.Container.Resolve <IApplicationUpdateManager>();
            await applicationUpdateManager.CheckForUpdates();

            Assert.Equal(2, installedApps.Count);
            Assert.True(installedApps.Any(config => config.AppIdentity == new AppIdentity("test.app1", "1.0.0")));
            Assert.True(installedApps.Any(config => config.AppIdentity == new AppIdentity("test.app2", "2.0.0-beta")));

            AppInstallConfig appInstallConfig = installedApps.Find(config => config.AppIdentity.Id == "test.app1");

            Assert.Equal(new AppIdentity("test.app1", new SemVersion(1, 0, 0)), appInstallConfig.AppIdentity);
            Assert.True(appInstallConfig.Properties.ContainsKey("NodeType"));
            Assert.Equal("Test", appInstallConfig.Properties["NodeType"]);
            Assert.True(appInstallConfig.Properties.ContainsKey("Region"));
            Assert.Equal("East", appInstallConfig.Properties["Region"]);
        }
        public async Task TestMultipleUpdates()
        {
            string id1 = "appId1";
            var v1 = SemVersion.Parse("1.0.0");
            var v2 = SemVersion.Parse("2.0.0");
            var v3 = SemVersion.Parse("3.0.0");
            var v4 = SemVersion.Parse("4.0.0");
            var v5 = SemVersion.Parse("5.0.0");

            AppIdentity app1v1 = new AppIdentity(id1, v1);
            AppIdentity app1v2 = new AppIdentity(id1, v2);
            AppIdentity app1v3 = new AppIdentity(id1, v3);
            AppIdentity app1v4 = new AppIdentity(id1, v4);
            AppIdentity app1v5 = new AppIdentity(id1, v5);

            IEnumerable<AppIdentity> appsToDeploy = new[] {app1v3, app1v4, app1v5};
            IEnumerable<string> clusters = new[] {"clusterId1"};

	        IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory()
		        .FetchDeployments(() => Task.FromResult(appsToDeploy.Select(identity => new AppDeploymentConfig(identity, clusters))));

            IApplicationPool applicationPool = new ApplicationPoolStub();
            string path = Path.GetTempPath();
            await applicationPool.AddApplication(new ApplicationStub(app1v1, path));
            await applicationPool.AddApplication(new ApplicationStub(app1v2, path));
            await applicationPool.AddApplication(new ApplicationStub(app1v3, path));

            var downloadedApps = new List<AppIdentity>();
            IApplicationDownloader applicationDownloader = new StubIApplicationDownloader()
                .DownloadApplication(appIdentity =>
                {
                    downloadedApps.Add(appIdentity);
                    return Task.FromResult(true);
                }
            );

            var installedApps = new List<AppIdentity>();
            var uninstalledApps = new List<AppIdentity>();
            string updatedAppId = null;
            IEnumerable<SemVersion> versionsRemoved = null;
            IEnumerable<SemVersion> versionsAdded = null;
            IApplicationInstaller applicationInstaller = new StubIApplicationInstaller()
                .Install(config => 
                {
                    installedApps.Add(config.AppIdentity);
                    return Task.FromResult(true);
                })
                .UnInstall(appIdentity =>
                {
                    uninstalledApps.Add(appIdentity);
                    return Task.FromResult(true);
                })
                .Update((applicationsToRemove, applicationsToInstall) => 
                {
	                updatedAppId = applicationsToInstall.First().AppIdentity.Id;
	                versionsRemoved = applicationsToRemove.Select(identity => identity.Version);
	                versionsAdded = applicationsToInstall.Select(config => config.AppIdentity.Version);
	                return Task.FromResult(true);
                }
            );

            ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager("clusterId", applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstaller);
            await applicationUpdateManager.CheckForUpdates();

            Assert.Equal(2, downloadedApps.Count);
            Assert.True(downloadedApps.Contains(app1v4));
            Assert.True(downloadedApps.Contains(app1v5));

            Assert.False(installedApps.Any());
            Assert.False(uninstalledApps.Any());

            Assert.Equal(id1, updatedAppId);
            Assert.Equal(new [] { v1, v2 }, versionsRemoved.ToList());
            Assert.Equal(new[] { v4, v5 }, versionsAdded.ToList());
        }
Beispiel #5
0
        public async Task TestMultipleUpdates()
        {
            string id1 = "appId1";
            var    v1  = SemVersion.Parse("1.0.0");
            var    v2  = SemVersion.Parse("2.0.0");
            var    v3  = SemVersion.Parse("3.0.0");
            var    v4  = SemVersion.Parse("4.0.0");
            var    v5  = SemVersion.Parse("5.0.0");

            AppIdentity app1v1 = new AppIdentity(id1, v1);
            AppIdentity app1v2 = new AppIdentity(id1, v2);
            AppIdentity app1v3 = new AppIdentity(id1, v3);
            AppIdentity app1v4 = new AppIdentity(id1, v4);
            AppIdentity app1v5 = new AppIdentity(id1, v5);

            IEnumerable <AppIdentity> appsToDeploy = new[] { app1v3, app1v4, app1v5 };
            IEnumerable <string>      clusters     = new[] { "clusterId1" };

            IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory()
                                                                             .FetchDeployments(() => Task.FromResult(appsToDeploy.Select(identity => new AppDeploymentConfig(identity, clusters))));

            IApplicationPool applicationPool = new ApplicationPoolStub();
            string           path            = Path.GetTempPath();
            await applicationPool.AddApplication(new ApplicationStub(app1v1, path));

            await applicationPool.AddApplication(new ApplicationStub(app1v2, path));

            await applicationPool.AddApplication(new ApplicationStub(app1v3, path));

            var downloadedApps = new List <AppIdentity>();
            IApplicationDownloader applicationDownloader = new StubIApplicationDownloader()
                                                           .DownloadApplication(appIdentity =>
            {
                downloadedApps.Add(appIdentity);
                return(Task.FromResult(true));
            }
                                                                                );

            var    installedApps   = new List <AppIdentity>();
            var    uninstalledApps = new List <AppIdentity>();
            string updatedAppId    = null;
            IEnumerable <SemVersion> versionsRemoved      = null;
            IEnumerable <SemVersion> versionsAdded        = null;
            IApplicationInstaller    applicationInstaller = new StubIApplicationInstaller()
                                                            .Install(config =>
            {
                installedApps.Add(config.AppIdentity);
                return(Task.FromResult(true));
            })
                                                            .UnInstall(appIdentity =>
            {
                uninstalledApps.Add(appIdentity);
                return(Task.FromResult(true));
            })
                                                            .Update((applicationsToRemove, applicationsToInstall) =>
            {
                updatedAppId    = applicationsToInstall.First().AppIdentity.Id;
                versionsRemoved = applicationsToRemove.Select(identity => identity.Version);
                versionsAdded   = applicationsToInstall.Select(config => config.AppIdentity.Version);
                return(Task.FromResult(true));
            }
                                                                    );

            ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager("clusterId", applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstaller);
            await applicationUpdateManager.CheckForUpdates();

            Assert.Equal(2, downloadedApps.Count);
            Assert.True(downloadedApps.Contains(app1v4));
            Assert.True(downloadedApps.Contains(app1v5));

            Assert.False(installedApps.Any());
            Assert.False(uninstalledApps.Any());

            Assert.Equal(id1, updatedAppId);
            Assert.Equal(new [] { v1, v2 }, versionsRemoved.ToList());
            Assert.Equal(new[] { v4, v5 }, versionsAdded.ToList());
        }
        public async Task TestMultipleUpdates()
        {
            string id1 = "appId1";
            var    v1  = SemVersion.Parse("1.0.0");
            var    v2  = SemVersion.Parse("2.0.0");
            var    v3  = SemVersion.Parse("3.0.0");
            var    v4  = SemVersion.Parse("4.0.0");
            var    v5  = SemVersion.Parse("5.0.0");

            AppIdentity app1v1 = new AppIdentity(id1, v1);
            AppIdentity app1v2 = new AppIdentity(id1, v2);
            AppIdentity app1v3 = new AppIdentity(id1, v3);
            AppIdentity app1v4 = new AppIdentity(id1, v4);
            AppIdentity app1v5 = new AppIdentity(id1, v5);

            IEnumerable <AppIdentity> appsToDeploy = new[] { app1v3, app1v4, app1v5 };
            IEnumerable <string>      clusters     = new[] { "clusterId1" };

            IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory()
                                                                             .FetchDeployments(() => Task.FromResult(appsToDeploy.Select(identity => new AppDeploymentConfig(identity, clusters))));

            IApplicationPool applicationPool = new ApplicationPoolStub();
            string           path            = Path.GetTempPath();
            await applicationPool.AddApplication(new ApplicationStub(app1v1, path));

            await applicationPool.AddApplication(new ApplicationStub(app1v2, path));

            await applicationPool.AddApplication(new ApplicationStub(app1v3, path));

            var downloadedApps = new List <AppIdentity>();
            IApplicationDownloader applicationDownloader = new StubIApplicationDownloader()
                                                           .DownloadApplication(appIdentity =>
            {
                downloadedApps.Add(appIdentity);
                return(Task.FromResult(true));
            }
                                                                                );

            IApplicationInstaller applicationInstaller = new StubIApplicationInstaller()
                                                         .Install(config =>
            {
                applicationPool.AddApplication(new ApplicationStub(config.AppIdentity, "path"));
                return(Task.FromResult(true));
            })
                                                         .UnInstall(appIdentity =>
            {
                applicationPool.RemoveApplication(appIdentity);
                return(Task.FromResult(true));
            })
                                                         .Update((applicationsToRemove, applicationsToInstall) =>
            {
                foreach (var appIdentity in applicationsToRemove)
                {
                    applicationPool.RemoveApplication(appIdentity);
                }
                foreach (var appInstallConfig in applicationsToInstall)
                {
                    applicationPool.AddApplication(new ApplicationStub(appInstallConfig.AppIdentity, "path"));
                }
                return(Task.FromResult(true));
            }
                                                                 );

            var instanceDeploymentStatus = new InstanceDeploymentStatus();
            IDeploymentStatusWriter deploymentStatusWriterStub = new StubIDeploymentStatusWriter()
                                                                 .PublishInstanceDeploymentStatus((clusterId, instanceId, status) =>
            {
                instanceDeploymentStatus = status;
                return(Task.CompletedTask);
            });

            const string             ClusterId  = "clusterId";
            const string             InstanceId = "instanceId";
            ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager(ClusterId, InstanceId,
                                                                                             applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstaller,
                                                                                             deploymentStatusWriterStub);
            await applicationUpdateManager.CheckForUpdates();

            Assert.Equal(3, applicationPool.Applications.Count());
            Assert.True(applicationPool.HasApplication(app1v3));
            Assert.True(applicationPool.HasApplication(app1v4));
            Assert.True(applicationPool.HasApplication(app1v5));

            Assert.Equal(3, instanceDeploymentStatus.Applications.Count());
            VerifyThatDeploymentStatusHasBeenUpdated(instanceDeploymentStatus, app1v3, ClusterId, InstanceId);
            VerifyThatDeploymentStatusHasBeenUpdated(instanceDeploymentStatus, app1v4, ClusterId, InstanceId);
            VerifyThatDeploymentStatusHasBeenUpdated(instanceDeploymentStatus, app1v5, ClusterId, InstanceId);
        }
Beispiel #7
0
        public async Task TestMultipleUpdates()
        {
            string id1 = "appId1";
            var    v1  = new Version("1.0.0");
            var    v2  = new Version("2.0.0");
            var    v3  = new Version("3.0.0");
            var    v4  = new Version("4.0.0");
            var    v5  = new Version("5.0.0");

            AppIdentity app1v1 = new AppIdentity(id1, v1);
            AppIdentity app1v2 = new AppIdentity(id1, v2);
            AppIdentity app1v3 = new AppIdentity(id1, v3);
            AppIdentity app1v4 = new AppIdentity(id1, v4);
            AppIdentity app1v5 = new AppIdentity(id1, v5);

            IEnumerable <AppIdentity> appsToDeploy = new[] { app1v3, app1v4, app1v5 };

            IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory
            {
                FetchDeployments_String = (deploymentId) => Task.FromResult(appsToDeploy)
            };

            IApplicationPool applicationPool = new ApplicationPoolStub();
            string           path            = Path.GetTempPath();
            await applicationPool.AddApplication(new ApplicationStub(app1v1, path));

            await applicationPool.AddApplication(new ApplicationStub(app1v2, path));

            await applicationPool.AddApplication(new ApplicationStub(app1v3, path));

            var downloadedApps = new List <AppIdentity>();
            IApplicationDownloader applicationDownloader = new StubIApplicationDownloader
            {
                DownloadApplication_AppIdentity = (appIdentity) =>
                {
                    downloadedApps.Add(appIdentity);
                    return(Task.FromResult(true));
                }
            };

            var    installedApps   = new List <AppIdentity>();
            var    uninstalledApps = new List <AppIdentity>();
            string updatedAppId    = null;
            IEnumerable <Version> versionsRemoved      = null;
            IEnumerable <Version> versionsAdded        = null;
            IApplicationInstaller applicationInstaller = new StubIApplicationInstaller
            {
                Install_AppIdentity = (appIdentity) =>
                {
                    installedApps.Add(appIdentity);
                    return(Task.FromResult(true));
                },
                UnInstall_AppIdentity = (appIdentity) =>
                {
                    uninstalledApps.Add(appIdentity);
                    return(Task.FromResult(true));
                },
                Update_String_IEnumerableOfVersion_IEnumerableOfVersion = (appId, versionsToRemove, versionToDeploy) =>
                {
                    updatedAppId    = appId;
                    versionsRemoved = versionsToRemove;
                    versionsAdded   = versionToDeploy;
                    return(Task.FromResult(true));
                }
            };

            ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager("deploymentId", applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstaller);
            await applicationUpdateManager.CheckForUpdates();

            Assert.Equal(2, downloadedApps.Count);
            Assert.True(downloadedApps.Contains(app1v4));
            Assert.True(downloadedApps.Contains(app1v5));

            Assert.False(installedApps.Any());
            Assert.False(uninstalledApps.Any());

            Assert.Equal(id1, updatedAppId);
            Assert.Equal(new [] { v1, v2 }, versionsRemoved.ToList());
            Assert.Equal(new[] { v4, v5 }, versionsAdded.ToList());
        }
        public async Task TestMultipleUpdates()
        {
            string id1 = "appId1";
            var v1 = new Version("1.0.0");
            var v2 = new Version("2.0.0");
            var v3 = new Version("3.0.0");
            var v4 = new Version("4.0.0");
            var v5 = new Version("5.0.0");

            AppIdentity app1v1 = new AppIdentity(id1, v1);
            AppIdentity app1v2 = new AppIdentity(id1, v2);
            AppIdentity app1v3 = new AppIdentity(id1, v3);
            AppIdentity app1v4 = new AppIdentity(id1, v4);
            AppIdentity app1v5 = new AppIdentity(id1, v5);

            IEnumerable<AppIdentity> appsToDeploy = new[] {app1v3, app1v4, app1v5};

            IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory
            {
                FetchDeploymentsString = (deploymentId) => Task.FromResult(appsToDeploy)
            };

            IApplicationPool applicationPool = new ApplicationPoolStub();
            string path = Path.GetTempPath();
            await applicationPool.AddApplication(new ApplicationStub(app1v1, path));
            await applicationPool.AddApplication(new ApplicationStub(app1v2, path));
            await applicationPool.AddApplication(new ApplicationStub(app1v3, path));

            var downloadedApps = new List<AppIdentity>();
            IApplicationDownloader applicationDownloader = new StubIApplicationDownloader
            {
                DownloadApplicationAppIdentity = (appIdentity) =>
                {
                    downloadedApps.Add(appIdentity);
                    return Task.FromResult(true);
                }
            };

            var installedApps = new List<AppIdentity>();
            var uninstalledApps = new List<AppIdentity>();
            string updatedAppId = null;
            IEnumerable<Version> versionsRemoved = null;
            IEnumerable<Version> versionsAdded = null;
            IApplicationInstaller applicationInstaller = new StubIApplicationInstaller
            {
                InstallAppIdentity = (appIdentity) =>
                {
                    installedApps.Add(appIdentity);
                    return Task.FromResult(true);
                },
                UnInstallAppIdentity = (appIdentity) =>
                {
                    uninstalledApps.Add(appIdentity);
                    return Task.FromResult(true);
                },
                UpdateStringIEnumerableOfVersionIEnumerableOfVersion = (appId, versionsToRemove, versionToDeploy) =>
                {
                    updatedAppId = appId;
                    versionsRemoved = versionsToRemove;
                    versionsAdded = versionToDeploy;
                    return Task.FromResult(true);
                }
            };

            ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager("deploymentId", applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstaller);
            await applicationUpdateManager.CheckForUpdates();

            Assert.AreEqual(2, downloadedApps.Count);
            Assert.IsTrue(downloadedApps.Contains(app1v4));
            Assert.IsTrue(downloadedApps.Contains(app1v5));

            Assert.IsFalse(installedApps.Any());
            Assert.IsFalse(uninstalledApps.Any());

            Assert.AreEqual(id1, updatedAppId);
            CollectionAssert.AreEqual(new []{ v1, v2 }, versionsRemoved.ToList());
            CollectionAssert.AreEqual(new[] { v4, v5 }, versionsAdded.ToList());
        }