예제 #1
0
파일: WorkerRole.cs 프로젝트: ca-ta/Yams
        public async Task RunAsync()
        {
            WorkerRoleConfig config = new WorkerRoleConfig();
            YamsConfig yamsConfig = new YamsConfigBuilder(
                // mandatory configs
                config.StorageDataConnectionString,
                DeploymentIdUtils.CloudServiceDeploymentId,
                RoleEnvironment.CurrentRoleInstance.UpdateDomain.ToString(),
                RoleEnvironment.CurrentRoleInstance.Id,
                config.CurrentRoleInstanceLocalStoreDirectory)
                // optional configs
                .SetCheckForUpdatesPeriodInSeconds(config.UpdateFrequencyInSeconds)
                .SetApplicationRestartCount(config.ApplicationRestartCount)
                .Build();
            _yamsEntryPoint = new YamsEntryPoint(yamsConfig);

            try
            {
                Trace.TraceInformation("Yams is starting");
                await _yamsEntryPoint.Start();
                Trace.TraceInformation("Yams has started");
                while (true)
                {
                    await Task.Delay(1000);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
예제 #2
0
        public async Task TestMultipleUpdates()
        {
            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                                                   _applicationsInstallPath).SetShowApplicationProcessWindow(false).Build();

            InitializeYamsService(yamsConfig);

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

            AssertThatApplicationIsRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 0)), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app2", new SemVersion(1, 1, 0)), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app2", new SemVersion(2, 0, 0, "beta")), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app3", new SemVersion(1, 1, 0)), "TestProcess");

            UploadDeploymentConfig("DeploymentConfigUpdate.json");

            await applicationUpdateManager.CheckForUpdates();

            AssertThatApplicationIsNotRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 0)));
            AssertThatApplicationIsNotRunning(new AppIdentity("test.app2", new SemVersion(1, 1, 0)));

            AssertThatApplicationIsRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 1)), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app2", new SemVersion(2, 0, 0, "beta")), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app3", new SemVersion(1, 0, 0)), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app3", new SemVersion(1, 1, 0)), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app4", new SemVersion(1, 0, 0)), "TestProcess");

            AssertThatNumberOfApplicationsRunningIs(5);
        }
예제 #3
0
        public async Task RunAsync()
        {
            WorkerRoleConfig config = new WorkerRoleConfig();
            YamsConfig yamsConfig = new YamsConfigBuilder(
                // mandatory configs
                DeploymentIdUtils.GetYamsClusterId(this.IsSingleClusterDeployment),
                RoleEnvironment.CurrentRoleInstance.UpdateDomain.ToString(),
                RoleEnvironment.CurrentRoleInstance.Id,
                config.CurrentRoleInstanceLocalStoreDirectory)
                // optional configs
                .SetCheckForUpdatesPeriodInSeconds(config.UpdateFrequencyInSeconds)
                .SetApplicationRestartCount(config.ApplicationRestartCount)
                .Build();
            _yamsService = YamsServiceFactory.Create(yamsConfig,
                deploymentRepositoryStorageConnectionString: config.StorageDataConnectionString,
                updateSessionStorageConnectionString: config.StorageDataConnectionString);

            try
            {
                Trace.TraceInformation("Yams is starting");
                await _yamsService.Start();
                Trace.TraceInformation("Yams has started. Looking for apps with deploymentId:" + yamsConfig.ClusterDeploymentId);
                while (true)
                {
                    await Task.Delay(1000);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
예제 #4
0
        public async Task RunAsync()
        {
            WorkerRoleConfig config     = new WorkerRoleConfig();
            YamsConfig       yamsConfig = new YamsConfigBuilder(
                // mandatory configs
                config.StorageDataConnectionString,
                DeploymentIdUtils.CloudServiceDeploymentId,
                RoleEnvironment.CurrentRoleInstance.UpdateDomain.ToString(),
                RoleEnvironment.CurrentRoleInstance.Id,
                config.CurrentRoleInstanceLocalStoreDirectory)
                                          // optional configs
                                          .SetCheckForUpdatesPeriodInSeconds(config.UpdateFrequencyInSeconds)
                                          .SetApplicationRestartCount(config.ApplicationRestartCount)
                                          .Build();

            _yamsEntryPoint = new YamsEntryPoint(yamsConfig);

            try
            {
                Trace.TraceInformation("Yams is starting");
                await _yamsEntryPoint.Start();

                Trace.TraceInformation("Yams has started");
                while (true)
                {
                    await Task.Delay(1000);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
예제 #5
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"]);
        }
예제 #6
0
        public ApplicationPoolTestFixture()
        {
            var dataRootPath = Path.Combine(Directory.GetCurrentDirectory(), "Data", "ApplicationPool");
            var testDirPath  = Path.Combine(Directory.GetCurrentDirectory(), "ApplicationPoolTest");

            ApplicationsRootPath = Path.Combine(testDirPath, "Applications");

            FileUtils.CopyDir(dataRootPath, ApplicationsRootPath, overwrite: true).Wait();

            const string exeName = "TestProcess.exe";

            string[] testAppsRelPath =
            {
                Path.Combine("test.myapp", "1.0.0"),
                Path.Combine("test.myapp", "1.0.1"),
            };

            foreach (string testAppRelPath in testAppsRelPath)
            {
                TestUtils.CopyExe(exeName, Path.Combine(ApplicationsRootPath, testAppRelPath));
            }

            YamsConfig config = new YamsConfigBuilder("clusterId", "1", "instanceId", "C:\\")
                                .SetShowApplicationProcessWindow(false).SetApplicationRestartCount(0).Build();

            ApplicationFactory =
                new ConfigurableApplicationFactory(new ApplicationConfigParser(
                                                       new ApplicationConfigSymbolResolver(ClusterId, InstanceId), new JsonSerializer(new DiagnosticsTraceWriter())),
                                                   new ProcessFactory(config), new ProcessStopper(0));
        }
예제 #7
0
파일: WorkerRole.cs 프로젝트: zhonli/Yams
        public async Task RunAsync()
        {
            WorkerRoleConfig config     = new WorkerRoleConfig();
            YamsConfig       yamsConfig = new YamsConfigBuilder(
                // mandatory configs
                DeploymentIdUtils.GetYamsClusterId(this.IsSingleClusterDeployment),
                RoleEnvironment.CurrentRoleInstance.UpdateDomain.ToString(),
                RoleEnvironment.CurrentRoleInstance.Id,
                config.CurrentRoleInstanceLocalStoreDirectory)
                                          // optional configs
                                          .SetCheckForUpdatesPeriodInSeconds(config.UpdateFrequencyInSeconds)
                                          .SetApplicationRestartCount(config.ApplicationRestartCount)
                                          .Build();

            _yamsService = YamsServiceFactory.Create(yamsConfig,
                                                     deploymentRepositoryStorageConnectionString: config.StorageDataConnectionString,
                                                     updateSessionStorageConnectionString: config.StorageDataConnectionString);

            try
            {
                Trace.TraceInformation("Yams is starting");
                await _yamsService.Start();

                Trace.TraceInformation("Yams has started. Looking for apps with deploymentId:" + yamsConfig.ClusterDeploymentId);
                while (true)
                {
                    await Task.Delay(1000);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
예제 #8
0
파일: Program.cs 프로젝트: Microsoft/Yams
        static void Main(string[] args)
        {
            ServicePointManager.DefaultConnectionLimit = 1000;

            HostFactory.Run(x =>
            {
                x.AddCommandLineDefinition("deploymentId", did => _deploymentId = did);
                x.AddCommandLineDefinition("updateDomain", upd => _updateDomain = upd);
                x.AddCommandLineDefinition("storageAccount", sacc => _storageAccount = sacc);
                x.AddCommandLineDefinition("storageKey", skey => _storageKey = skey);
                x.AddCommandLineDefinition("updateFrequency", uf => _updateFrequencyInSeconds = Convert.ToInt32(uf));
                x.AddCommandLineDefinition("applicationRestartCount", arc => _applicationRestartCount = Convert.ToInt32(arc));

                x.ApplyCommandLine();

                x.Service<IYamsService>(s =>
                {
                    s.ConstructUsing(name =>
                    {
                        if (string.IsNullOrWhiteSpace(_storageKey))
                            throw new ArgumentNullException(nameof(_storageKey));

                        if (string.IsNullOrWhiteSpace(_storageAccount))
                            throw new ArgumentNullException(nameof(_storageAccount));

                        if (string.IsNullOrWhiteSpace(_deploymentId))
                            throw new ArgumentNullException(nameof(_deploymentId));

                        if (string.IsNullOrWhiteSpace(_updateDomain))
                            throw new ArgumentNullException(nameof(_updateDomain));

                        string blobStorageConnectionString = $"DefaultEndpointsProtocol=https;AccountName={_storageAccount};AccountKey={_storageKey}";
                        YamsConfig yamsConfig = new YamsConfigBuilder(
                            // mandatory configs
                            _deploymentId,
                            _updateDomain,
                            Environment.MachineName,
                            Environment.CurrentDirectory + "\\LocalStore")
                            // optional configs
                            .SetCheckForUpdatesPeriodInSeconds(_updateFrequencyInSeconds)
                            .SetApplicationRestartCount(_applicationRestartCount)
                            .Build();

                        return YamsServiceFactory.Create(yamsConfig,
                            deploymentRepositoryStorageConnectionString: blobStorageConnectionString,
                            updateSessionStorageConnectionString: blobStorageConnectionString);
                    });
                    s.WhenStarted(yep => yep.Start().Wait());
                    s.WhenStopped(yep => yep.Stop().Wait());
                });
                x.RunAsLocalSystem();

                x.SetDescription("Yams Service Host");
                x.SetDisplayName("Yams Service");
                x.SetServiceName("Yams");
                x.StartAutomatically();
            });
        }
예제 #9
0
파일: Program.cs 프로젝트: zhonli/Yams
        public static YamsConfigBuilder AddClusterProperties(this YamsConfigBuilder yamsConfigBuilder,
                                                             IDictionary <string, string> properties)
        {
            foreach (var property in properties)
            {
                yamsConfigBuilder.AddClusterProperty(property.Key, property.Value);
            }

            return(yamsConfigBuilder);
        }
예제 #10
0
        //---------------------------------------------------------------------
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            // TODO: Replace the following with your own logic.
            //while (!cancellationToken.IsCancellationRequested)
            //{
            //    Trace.TraceInformation("Working");
            //    await Task.Delay(1000);
            //}

            WorkerRoleConfig config     = new WorkerRoleConfig();
            YamsConfig       yamsConfig = new YamsConfigBuilder(
                // mandatory configs
                DeploymentIdUtils.CloudServiceDeploymentId,
                RoleEnvironment.CurrentRoleInstance.UpdateDomain.ToString(),
                RoleEnvironment.CurrentRoleInstance.Id,
                config.CurrentRoleInstanceLocalStoreDirectory)
                                          // optional configs
                                          .SetCheckForUpdatesPeriodInSeconds(config.UpdateFrequencyInSeconds)
                                          .SetApplicationRestartCount(config.ApplicationRestartCount)
                                          .Build();

            this.yamsService = YamsServiceFactory.Create(yamsConfig,
                                                         deploymentRepositoryStorageConnectionString: config.StorageDataConnectionString,
                                                         updateSessionStorageConnectionString: config.StorageDataConnectionString);

            try
            {
                Trace.TraceInformation("Yams is starting");

                await this.yamsService.Start();

                Trace.TraceInformation("Yams has started. Looking for apps with deploymentId:" + yamsConfig.ClusterDeploymentId);

                //while (true)
                //{
                //    await Task.Delay(1000);
                //}

                while (!cancellationToken.IsCancellationRequested)
                {
                    //Trace.TraceInformation("Working");
                    await Task.Delay(1000);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
예제 #11
0
        public async Task TestMultipleUpdates()
        {
            const string ClusterId  = "clusterId1";
            const string InstanceId = "instanceId";
            var          yamsConfig = new YamsConfigBuilder(ClusterId, "1", InstanceId,
                                                            _applicationsInstallPath).SetUseShellExecute(false).Build();

            InitializeYamsService(yamsConfig);

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

            AssertThatApplicationIsRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 0)), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app2", new SemVersion(1, 1, 0)), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app2", new SemVersion(2, 0, 0, "beta")), "TestProcess");
            AssertThatApplicationIsRunning(new AppIdentity("test.app3", new SemVersion(1, 1, 0)), "TestProcess");

            UploadDeploymentConfig("DeploymentConfigUpdate.json");

            await applicationUpdateManager.CheckForUpdates();

            AssertThatApplicationIsNotRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 0)));
            AssertThatApplicationIsNotRunning(new AppIdentity("test.app2", new SemVersion(1, 1, 0)));

            AppIdentity app1v101     = new AppIdentity("test.app1", new SemVersion(1, 0, 1));
            AppIdentity app2v200beta = new AppIdentity("test.app2", new SemVersion(2, 0, 0, "beta"));
            AppIdentity app3v100     = new AppIdentity("test.app3", new SemVersion(1, 0, 0));
            AppIdentity app3v110     = new AppIdentity("test.app3", new SemVersion(1, 1, 0));
            AppIdentity app4v100     = new AppIdentity("test.app4", new SemVersion(1, 0, 0));

            AssertThatApplicationIsRunning(app1v101, "TestProcess");
            AssertThatApplicationIsRunning(app2v200beta, "TestProcess");
            AssertThatApplicationIsRunning(app3v100, "TestProcess");
            AssertThatApplicationIsRunning(app3v110, "TestProcess");
            AssertThatApplicationIsRunning(app4v100, "TestProcess");

            AssertThatNumberOfApplicationsRunningIs(5);

            InstanceDeploymentStatus deploymentStatus = await _deploymentRepository.FetchInstanceDeploymentStatus(ClusterId, InstanceId);

            VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app1v101, ClusterId, InstanceId);
            VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app2v200beta, ClusterId, InstanceId);
            VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app3v100, ClusterId, InstanceId);
            VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app3v110, ClusterId, InstanceId);
            VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app4v100, ClusterId, InstanceId);
        }
예제 #12
0
        public async Task TestApplicationWithMonitoredInitializationTimeout()
        {
            await CopyAppBinariesToAppDeploymentDir("MonitorInitApp", "MonitorInitProcess", "1.0.0");

            UploadDeploymentConfig("DeploymentConfigMonitorInitApp.json");

            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                                                   _applicationsInstallPath).SetAppInitTimeout(TimeSpan.FromSeconds(1))
                             .SetShowApplicationProcessWindow(false).Build();

            InitializeYamsService(yamsConfig);

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

            AssertThatApplicationIsNotRunning(new AppIdentity("MonitorInitApp", new SemVersion(1, 0, 0)));
        }
예제 #13
0
        private static void Main(string[] args)
        {
            ServicePointManager.DefaultConnectionLimit = 10000;
            HostFactory.Run(host =>
            {
                var configurationDirectory = ApplicationPath.CurrentDirectory;
                host.AddCommandLineDefinition("config", x => configurationDirectory = x);
                host.ApplyCommandLine();
                var configuration = YamsServiceConfiguration.Load(configurationDirectory);
                var logger        = new LoggerConfiguration()
                                    .WriteTo.RollingFile(Path.Combine(ApplicationPath.CurrentDirectory, "logs", "yams-{Date}.log"))
                                    .MinimumLevel.Is(LogEventLevel.Debug)
                                    .CreateLogger();
                Trace.Listeners.Add(new SerilogTraceListener.SerilogTraceListener(logger));

                host.Service <IYamsService>(service =>
                {
                    service.ConstructUsing(name =>
                    {
                        var builder = new YamsConfigBuilder(
                            configuration.ClusterId,
                            configuration.InstanceUpdateDomain,
                            configuration.InstanceUpdateDomain,
                            configuration.ApplicationInstallDirectory);
                        var yamsConfig = builder
                                         .SetCheckForUpdatesPeriodInSeconds(configuration.UpdatePeriodInSeconds)
                                         .SetApplicationRestartCount(configuration.RestartCount)
                                         .Build();
                        return(YamsServiceFactory.Create(
                                   yamsConfig,
                                   configuration.AzureStorageConnectionString,
                                   configuration.AzureStorageConnectionString));
                    });
                    service.WhenStarted(x => x.Start().Wait());
                    service.WhenStopped(x => x.Stop().Wait());
                });

                host.RunAsLocalSystem();
                host.SetDescription("Yams Service Host");
                host.SetDisplayName("Yams Service");
                host.SetServiceName("Yams");
                host.StartAutomatically();
            });
        }
예제 #14
0
        public async Task TestThatApplicationsAreLoadedAtStartup()
        {
            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                _applicationsInstallPath).SetShowApplicationProcessWindow(false).Build();

            InitializeYamsService(yamsConfig);

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

            AssertThatApplicationIsRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 0)));
            AssertThatApplicationIsRunning(new AppIdentity("test.app2", new SemVersion(1, 1, 0)));
            AssertThatApplicationIsRunning(new AppIdentity("test.app2", new SemVersion(2, 0, 0,"beta")));
            AssertThatApplicationIsRunning(new AppIdentity("test.app3", new SemVersion(1, 1, 0)));

            AssertThatApplicationIsNotRunning(new AppIdentity("test.app4", new SemVersion(1, 0, 0)));

            AssertThatNumberOfApplicationsRunningIs(4);
        }
예제 #15
0
        public EndToEndTest()
        {
            _dataRootPath            = Path.Combine(Directory.GetCurrentDirectory(), "Data", "EndToEndTest");
            _testDirPath             = Path.Combine(Directory.GetCurrentDirectory(), "EndToEndTest");
            _deploymentDirPath       = Path.Combine(_testDirPath, "Deployments");
            _applicationsInstallPath = Path.Combine(_testDirPath, "applications");

            FileUtils.CopyDir(_dataRootPath, _deploymentDirPath, overwrite: true).Wait();

            CopyTestProcessExeToTestApps();

            var yamsConfig = new YamsConfigBuilder("deploymentId1", "1", "instanceId",
                                                   _applicationsInstallPath).SetShowApplicationProcessWindow(false).Build();

            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager()
                                                         .TryStartUpdateSession(applicationId => Task.FromResult(true))
                                                         .EndUpdateSession(applicationId => Task.FromResult(true));

            _yamsDiModule = new YamsDiModule(yamsConfig, new LocalDeploymentRepository(_deploymentDirPath), updateSessionManager);
            _yamsService  = _yamsDiModule.YamsService;
        }
예제 #16
0
        static async Task MainAsync(string[] args)
        {
            string clusterId      = "testClusterId";
            string superClusterId = "testSuperClusterId";

            YamsConfig yamsConfig = new YamsConfigBuilder(
                // mandatory configs
                clusterId: clusterId,
                instanceUpdateDomain: "0",
                instanceId: "instance_0",
                applicationInstallDirectory: Directory.GetCurrentDirectory())
                                    // optional configs
                                    .SetSuperClusterId(superClusterId)
                                    .SetCheckForUpdatesPeriodInSeconds(5)
                                    .SetApplicationRestartCount(int.MaxValue)
                                    .Build();

            string storageConnectionString = "UseDevelopmentStorage=true";
            var    yamsService             = YamsServiceFactory.Create(yamsConfig,
                                                                       deploymentRepositoryStorageConnectionString: storageConnectionString,
                                                                       updateSessionStorageConnectionString: storageConnectionString);

            try
            {
                Trace.TraceInformation("Yams is starting");
                await yamsService.Start();

                Trace.TraceInformation($"Yams has started. Looking for apps with clusterId: {clusterId}");
            }
            catch (Exception e)
            {
                Trace.TraceError($"Failed to start the Yams cluster {clusterId}", e);
                return;
            }

            while (true)
            {
                await Task.Delay(1000);
            }
        }
예제 #17
0
        private async Task RunGracefulShutdownTest(TimeSpan gracefulShutdownTimeout)
        {
            await CopyAppBinariesToAppDeploymentDir("GracefulShutdownApp", "GracefullShutdownProcess", "1.0.0");

            UploadDeploymentConfig("DeploymentConfigGracefulShutdownApp.json");

            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                                                   _applicationsInstallPath).SetAppGracefulShutdownTimeout(gracefulShutdownTimeout)
                             .SetShowApplicationProcessWindow(false).Build();

            InitializeYamsService(yamsConfig);

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

            AssertThatApplicationIsRunning(new AppIdentity("GracefulShutdownApp", new SemVersion(1, 0, 0)));

            UploadDeploymentConfig("DeploymentConfigNoApps.json");
            await applicationUpdateManager.CheckForUpdates();

            AssertThatApplicationIsNotRunning(new AppIdentity("GracefulShutdownApp", new SemVersion(1, 0, 0)));
        }
예제 #18
0
        private async Task RunHeartBeatTest(TimeSpan heartBeatTimeout)
        {
            await CopyAppBinariesToAppDeploymentDir("HeartBeatApp", "HeartBeatProcess", "1.0.0");

            UploadDeploymentConfig("DeploymentConfigHeartBeatApp.json");

            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                                                   _applicationsInstallPath)
                             .SetAppHeartBeatTimeout(heartBeatTimeout)
                             .SetShowApplicationProcessWindow(false).Build();

            InitializeYamsService(yamsConfig);

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

            AssertThatApplicationIsRunning(new AppIdentity("HeartBeatApp", new SemVersion(1, 0, 0)));
            // wait for a bit to make sure heart beat messages are not failing
            await Task.Delay(1000);

            AssertThatApplicationIsRunning(new AppIdentity("HeartBeatApp", new SemVersion(1, 0, 0)));
        }
예제 #19
0
        public async Task TestThatClusterPropertiesAreUsedToMatchDeployments()
        {
            File.Copy(Path.Combine(_dataRootPath, "DeploymentConfigWithProperties.json"), Path.Combine(_deploymentDirPath, "DeploymentConfig.json"), overwrite: true);
            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                                                   _applicationsInstallPath).SetShowApplicationProcessWindow(false)
                             .AddClusterProperty("NodeType", "Test")
                             .AddClusterProperty("Region", "East").Build();

            InitializeYamsService(yamsConfig);

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

            AssertThatApplicationIsRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 0)));

            AssertThatApplicationIsNotRunning(new AppIdentity("test.app2", new SemVersion(1, 1, 0)));
            AssertThatApplicationIsNotRunning(new AppIdentity("test.app2", new SemVersion(2, 0, 0, "beta")));
            AssertThatApplicationIsNotRunning(new AppIdentity("test.app3", new SemVersion(1, 1, 0)));
            AssertThatApplicationIsNotRunning(new AppIdentity("test.app4", new SemVersion(1, 0, 0)));

            AssertThatNumberOfApplicationsRunningIs(1);
        }
예제 #20
0
        public async Task TestFullIpcApp()
        {
            await CopyAppBinariesToAppDeploymentDir("FullIpcApp", "FullIpcProcess", "1.0.0");

            UploadDeploymentConfig("DeploymentConfigFullIpcApp.json");

            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                                                   _applicationsInstallPath).SetShowApplicationProcessWindow(false).Build();

            InitializeYamsService(yamsConfig);

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

            AssertThatApplicationIsRunning(new AppIdentity("FullIpcApp", new SemVersion(1, 0, 0)));

            await Task.Delay(5000);

            UploadDeploymentConfig("DeploymentConfigNoApps.json");
            await applicationUpdateManager.CheckForUpdates();

            AssertThatApplicationIsNotRunning(new AppIdentity("FullIpcApp", new SemVersion(1, 0, 0)));
        }
        public async Task TestThatExitedEventIsNotFiredOnGracefulShutdown()
        {
            var            yamsConfig = new YamsConfigBuilder("clusterId", "1", "instanceId", "C:\\Foo").Build();
            var            process    = new StubIProcess().HasExited_Get(() => true);
            IIpcConnection connection = new StubIIpcConnection()
                                        .SendMessage(message =>
            {
                process.Exited_Raise(process, new ProcessExitedArgs(process, ""));
                return(Task.CompletedTask);
            })
                                        .Disconnect(() => Task.CompletedTask);
            GracefulShutdownProcessDecorator decorator = new GracefulShutdownProcessDecorator(yamsConfig, process, connection);
            bool hasExitedFired = false;

            decorator.Exited += (sender, args) =>
            {
                hasExitedFired = true;
            };

            await decorator.Close();

            Assert.False(hasExitedFired);
        }
예제 #22
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"]);
        }
예제 #23
0
파일: Program.cs 프로젝트: youscan/Yams
        static void Main(string[] args)
        {
            ServicePointManager.DefaultConnectionLimit = 1000;

            HostFactory.Run(x =>
            {
                x.AddCommandLineDefinition("deploymentId", did => _deploymentId                       = did);
                x.AddCommandLineDefinition("updateDomain", upd => _updateDomain                       = upd);
                x.AddCommandLineDefinition("storageAccount", sacc => _storageAccount                  = sacc);
                x.AddCommandLineDefinition("storageKey", skey => _storageKey                          = skey);
                x.AddCommandLineDefinition("updateFrequency", uf => _updateFrequencyInSeconds         = Convert.ToInt32(uf));
                x.AddCommandLineDefinition("applicationRestartCount", arc => _applicationRestartCount = Convert.ToInt32(arc));

                x.ApplyCommandLine();

                x.Service <IYamsService>(s =>
                {
                    s.ConstructUsing(name =>
                    {
                        if (string.IsNullOrWhiteSpace(_storageKey))
                        {
                            throw new ArgumentNullException(nameof(_storageKey));
                        }

                        if (string.IsNullOrWhiteSpace(_storageAccount))
                        {
                            throw new ArgumentNullException(nameof(_storageAccount));
                        }

                        if (string.IsNullOrWhiteSpace(_deploymentId))
                        {
                            throw new ArgumentNullException(nameof(_deploymentId));
                        }

                        if (string.IsNullOrWhiteSpace(_updateDomain))
                        {
                            throw new ArgumentNullException(nameof(_updateDomain));
                        }

                        string blobStorageConnectionString = $"DefaultEndpointsProtocol=https;AccountName={_storageAccount};AccountKey={_storageKey}";
                        YamsConfig yamsConfig = new YamsConfigBuilder(
                            // mandatory configs
                            _deploymentId,
                            _updateDomain,
                            Environment.MachineName,
                            Environment.CurrentDirectory + "\\LocalStore")
                                                // optional configs
                                                .SetCheckForUpdatesPeriodInSeconds(_updateFrequencyInSeconds)
                                                .SetApplicationRestartCount(_applicationRestartCount)
                                                .Build();

                        return(YamsServiceFactory.Create(yamsConfig,
                                                         deploymentRepositoryStorageConnectionString: blobStorageConnectionString,
                                                         updateSessionStorageConnectionString: blobStorageConnectionString));
                    });
                    s.WhenStarted(yep => yep.Start().Wait());
                    s.WhenStopped(yep => yep.Stop().Wait());
                });
                x.RunAsLocalSystem();

                x.SetDescription("Yams Service Host");
                x.SetDisplayName("Yams Service");
                x.SetServiceName("Yams");
                x.StartAutomatically();
            });
        }
예제 #24
0
파일: Program.cs 프로젝트: zhonli/Yams
        static void Main(string[] args)
        {
            ServicePointManager.DefaultConnectionLimit = 1000;

            HostFactory.Run(x =>
            {
                x.AddCommandLineDefinition("clusterId", cid => _clusterId       = cid);
                x.AddCommandLineDefinition("updateDomain", upd => _updateDomain = upd);
                x.AddCommandLineDefinition("deploymentRepositoryStorageConnectionString", drscs => _deploymentRepositoryStorageConnectionString = drscs);
                x.AddCommandLineDefinition("updateSessionStorageConnectionString", upscs => _updateSessionStorageConnectionString = upscs);
                x.AddCommandLineDefinition("updateFrequency", uf => _updateFrequencyInSeconds         = Convert.ToInt32(uf));
                x.AddCommandLineDefinition("applicationRestartCount", arc => _applicationRestartCount = Convert.ToInt32(arc));
                x.AddCommandLineDefinition("clusterProperties", cp => _clusterProperties = cp.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(item => item.Split('=')).ToDictionary(s => s[0], s => s[1]));

                x.ApplyCommandLine();

                x.Service <IYamsService>(s =>
                {
                    s.ConstructUsing(name =>
                    {
                        if (string.IsNullOrWhiteSpace(_updateSessionStorageConnectionString))
                        {
                            throw new ArgumentNullException(nameof(_updateSessionStorageConnectionString));
                        }

                        if (string.IsNullOrWhiteSpace(_deploymentRepositoryStorageConnectionString))
                        {
                            throw new ArgumentNullException(nameof(_deploymentRepositoryStorageConnectionString));
                        }

                        if (string.IsNullOrWhiteSpace(_clusterId))
                        {
                            throw new ArgumentNullException(nameof(_clusterId));
                        }

                        if (string.IsNullOrWhiteSpace(_updateDomain))
                        {
                            throw new ArgumentNullException(nameof(_updateDomain));
                        }

                        // mandatory configs
                        YamsConfigBuilder yamsConfigBuilder = new YamsConfigBuilder(
                            _clusterId,
                            _updateDomain,
                            Environment.MachineName,
                            Environment.CurrentDirectory + "\\LocalStore");

                        // optional configs;
                        if (_updateFrequencyInSeconds.HasValue)
                        {
                            yamsConfigBuilder.SetCheckForUpdatesPeriodInSeconds(_updateFrequencyInSeconds.Value);
                        }

                        if (_applicationRestartCount.HasValue)
                        {
                            yamsConfigBuilder.SetApplicationRestartCount(_applicationRestartCount.Value);
                        }

                        if (_clusterProperties != null)
                        {
                            yamsConfigBuilder.AddClusterProperties(_clusterProperties);
                        }

                        var yamsConfig = yamsConfigBuilder.Build();

                        return(YamsServiceFactory.Create(yamsConfig,
                                                         deploymentRepositoryStorageConnectionString: _deploymentRepositoryStorageConnectionString,
                                                         updateSessionStorageConnectionString: _updateSessionStorageConnectionString));
                    });
                    s.WhenStarted(yep => yep.Start().Wait());
                    s.WhenStopped(yep => yep.Stop().Wait());
                });
                x.RunAsLocalSystem();
                x.AddCommandLineArgumentsToStartupParameters();

                x.SetDescription("Yams Service Host");
                x.SetDisplayName($"Yams Service [{_clusterId} - {_updateDomain}]");
                x.SetServiceName("Yams");

                x.EnableServiceRecovery(configurator =>
                {
                    configurator.OnCrashOnly();
                    configurator.RestartService(0);
                });
                x.StartAutomatically();
            });
        }
예제 #25
0
        public async Task TestThatClusterPropertiesAreUsedToMatchDeployments()
        {
            File.Copy(Path.Combine(_dataRootPath, "DeploymentConfigWithProperties.json"), Path.Combine(_deploymentDirPath, "DeploymentConfig.json"), overwrite: true);
            var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId",
                _applicationsInstallPath).SetShowApplicationProcessWindow(false)
                .AddClusterProperty("NodeType", "Test")
                .AddClusterProperty("Region", "East").Build();

            InitializeYamsService(yamsConfig);

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

            AssertThatApplicationIsRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 0)));

            AssertThatApplicationIsNotRunning(new AppIdentity("test.app2", new SemVersion(1, 1, 0)));
            AssertThatApplicationIsNotRunning(new AppIdentity("test.app2", new SemVersion(2, 0, 0, "beta")));
            AssertThatApplicationIsNotRunning(new AppIdentity("test.app3", new SemVersion(1, 1, 0)));
            AssertThatApplicationIsNotRunning(new AppIdentity("test.app4", new SemVersion(1, 0, 0)));

            AssertThatNumberOfApplicationsRunningIs(1);
        }