예제 #1
0
        public void LauncherTest()
        {
            var config        = ConfigurationFactory.ParseString(File.ReadAllText("./TempData/config.hocon"));
            var configuration =
                JsonConvert.DeserializeObject <NodeStartUpConfiguration>(File.ReadAllText("./TempData/fallBackConfiguration.json"));
            var nugetUrl   = "http://nuget/";
            var serviceDir = Path.Combine(".", "service");

            if (Directory.Exists(serviceDir))
            {
                Directory.Delete(serviceDir, true);
            }

            Directory.CreateDirectory(serviceDir);

            var repository = new RemotePackageRepository(nugetUrl);

            repository.CreateServiceAsync(
                configuration.Packages.Select(p => new PackageIdentity(p.Id, NuGetVersion.Parse(p.Version))),
                "win7-x64",
                PackageRepositoryExtensions.CurrentRuntime,
                serviceDir,
                "KlusterKite.Core.Service",
                this.output.WriteLine).GetAwaiter().GetResult();
        }
예제 #2
0
        /// <summary>
        /// Creates the runnable service from installed packages
        /// </summary>
        /// <param name="configuration">Current node configuration</param>
        private void CreateService(NodeStartUpConfiguration configuration)
        {
            Console.WriteLine(@"Creating service");
            var serviceDir = Path.Combine(this.WorkingDirectory, "service");

            Directory.CreateDirectory(serviceDir);

            var repository = new RemotePackageRepository(configuration.PackageSource);

            repository.CreateServiceAsync(
                configuration.Packages.Select(p => new PackageIdentity(p.Id, NuGetVersion.Parse(p.Version))),
                this.Runtime,
                PackageRepositoryExtensions.CurrentRuntime,
                serviceDir,
                "KlusterKite.Core.Service",
                Console.WriteLine).GetAwaiter().GetResult();

            File.WriteAllText(Path.Combine(serviceDir, "akka.hocon"), configuration.Configuration);
            Console.WriteLine($@"General configuration: \n {configuration.Configuration}");

            // cluster self-join is not welcomed
            var    seeds       = configuration.Seeds?.ToList() ?? new List <string>();
            string startConfig = $@"{{
                KlusterKite.NodeManager.ConfigurationId = {configuration.ConfigurationId}
                KlusterKite.NodeManager.NodeTemplate = {configuration.NodeTemplate}
                KlusterKite.NodeManager.ContainerType = {this.ContainerType}
                KlusterKite.NodeManager.Runtime = ""{this.Runtime.Replace("\"", "\\\"")}""
                KlusterKite.NodeManager.NodeId = {this.Uid}
                akka.cluster.seed-nodes = [{string.Join(", ", seeds.Select(s => $"\"{s}\""))}]
            }}";

            File.WriteAllText(Path.Combine(serviceDir, "start.hocon"), startConfig);
            Console.WriteLine($@"Start configuration: 
                                {startConfig}");
        }
예제 #3
0
        /// <summary>
        /// Runs seeder configuration
        /// </summary>
        /// <param name="configuration">The global configuration</param>
        /// <param name="seederConfiguration">The seeder configuration</param>
        private static void RunSeederConfiguration(Configuration configuration, SeederConfiguration seederConfiguration)
        {
            var executionDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            Directory.CreateDirectory(executionDir);

            try
            {
                while (true)
                {
                    try
                    {
                        var repository = new RemotePackageRepository(configuration.Nuget);
                        var packages   = GetPackagesToInstall(repository, seederConfiguration).GetAwaiter()
                                         .GetResult();

                        repository.CreateServiceAsync(
                            packages,
                            configuration.Runtime,
                            PackageRepositoryExtensions.CurrentRuntime,
                            executionDir,
                            "KlusterKite.NodeManager.Seeder",
                            Console.WriteLine).GetAwaiter().GetResult();

                        Console.WriteLine("Packages installed");
                    }
                    catch (PackageNotFoundException packageNotFoundException)
                    {
                        Console.WriteLine($"Package {packageNotFoundException.Message} was not found");
                        Thread.Sleep(configuration.NugetCheckPeriod);
                        continue;
                    }
                    catch (AggregateException exception)
                    {
                        var e = exception.InnerExceptions?.FirstOrDefault() ?? exception;
                        Console.WriteLine(e.Message);
                        Console.WriteLine(e.StackTrace);
                        Thread.Sleep(configuration.NugetCheckPeriod);
                        continue;
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.Message);
                        Console.WriteLine(exception.StackTrace);
                        Thread.Sleep(configuration.NugetCheckPeriod);
                        continue;
                    }

                    try
                    {
                        File.Copy(configuration.ConfigFile, Path.Combine(executionDir, "seeder.hocon"), true);

                        // todo: move to CreateServiceAsync
                        // ConfigurationUtils.FixAssemblyVersions(Path.Combine(executionDir, "KlusterKite.NodeManager.Seeder.exe.config"));
                        Console.WriteLine($"Seeder prepared in {executionDir}");
#if APPDOMAIN
                        var process = new Process
                        {
                            StartInfo =
                            {
                                UseShellExecute  = false,
                                WorkingDirectory = executionDir,
                                FileName         = "KlusterKite.NodeManager.Seeder.exe",
                                Arguments        = seederConfiguration.Name
                            }
                        };
#elif CORECLR
                        var process = new Process
                        {
                            StartInfo =
                            {
                                UseShellExecute  = false,
                                WorkingDirectory = executionDir,
                                FileName         = "dotnet",
                                Arguments        = $"KlusterKite.NodeManager.Seeder.dll {seederConfiguration.Name}"
                            }
                        };
#endif
                        process.Start();
                        process.WaitForExit();
                        process.Dispose();
                        Console.WriteLine("Seeder stopped");
                        break;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine(e.StackTrace);
                        Console.ReadLine();
                        break;
                    }
                }
            }
            finally
            {
                try
                {
                    Directory.Delete(executionDir, true);
                }
                catch
                {
                    Console.WriteLine("Failed to remove execution directory");
                }
            }
        }