Esempio n. 1
0
        public async Task RunAsync()
        {
            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();

            _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());
            }
        }
Esempio n. 2
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());
            }
        }
Esempio n. 3
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();
            });
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        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();
            });
        }
Esempio n. 6
0
        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();
            });
        }