Esempio n. 1
0
        static void Main(string[] args)
        {
            SetupLogging();
            var commandLineApplication = new CommandLineApplication(true);

            commandLineApplication.Name = "Tarzan.Nfx.IgniteServer";
            commandLineApplication.HelpOption("-?|-Help");
            var configFileArgument     = commandLineApplication.Option("-ConfigFile", "XML configuration file. If not file is specified then default configuration is used.", CommandOptionType.SingleValue);
            var offheapArgument        = commandLineApplication.Option("-Offheap", "Size of off-heap memory given in megabytes.", CommandOptionType.SingleValue);
            var onheapArgument         = commandLineApplication.Option("-Onheap", "Size of on-heap memory given in megabytes.", CommandOptionType.SingleValue);
            var leaderNodeArgument     = commandLineApplication.Option("-SetLeader", "Set this node as the leader of the cluster.", CommandOptionType.NoValue);
            var serverPortArgument     = commandLineApplication.Option("-SpiPort", "Specifies port for Discovery Spi.", CommandOptionType.SingleValue);
            var clusterEnpointArgument = commandLineApplication.Option("-Cluster", "Specifies IP address and port of a cluster node. Multiple nodes can be specified.", CommandOptionType.MultipleValue);
            var consistentIdArgument   = commandLineApplication.Option("-ConsistentId", "Specifies as a consistent id of the node. This value is used in topology.", CommandOptionType.SingleValue);
            var persistenceEnabled     = commandLineApplication.Option("-PersistenceEnabled", "If set, it enables persistence mode.", CommandOptionType.NoValue);

            commandLineApplication.OnExecute(async() =>
            {
                var configFile = configFileArgument.HasValue() ? configFileArgument.Value() : null;

                using (var server = new IgniteServerRunner(configFile))
                {
                    if (offheapArgument.HasValue())
                    {
                        server.SetOffHeapMemoryLimit(Int32.Parse(offheapArgument.Value()));
                    }
                    if (onheapArgument.HasValue())
                    {
                        server.SetOnHeapMemoryLimit(Int32.Parse(onheapArgument.Value()));
                    }
                    if (serverPortArgument.HasValue())
                    {
                        server.SetServerPort(Int32.Parse(serverPortArgument.Value()));
                    }
                    if (clusterEnpointArgument.HasValue())
                    {
                        server.SetClusterEnpoints(clusterEnpointArgument.Values);
                    }
                    if (consistentIdArgument.HasValue())
                    {
                        server.SetConsistentId(consistentIdArgument.Value());
                    }
                    if (persistenceEnabled.HasValue())
                    {
                        server.SetPersistence(true);
                    }
                    await server.Run();
                }
                return(0);
            });


            try
            {
                commandLineApplication.Execute(args);
            }
            catch (CommandParsingException e)
            {
                commandLineApplication.Error.WriteLine($"ERROR: {e.Message}");
                commandLineApplication.ShowHelp();
            }
            catch (ArgumentException e)
            {
                commandLineApplication.Error.WriteLine($"ERROR: {e.Message}");
                commandLineApplication.ShowHelp();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            SetupLogging();
            var commandLineApplication = new CommandLineApplication(true);

            commandLineApplication.Name = "Tarzan.Nfx.IgniteServer";
            commandLineApplication.HelpOption("-?|-Help");
            var configFileArgument     = commandLineApplication.Option("-ConfigFile", "XML configuration file. If not file is specified then default configuration is used.", CommandOptionType.SingleValue);
            var offheapArgument        = commandLineApplication.Option("-OffHeap", "Size of off-heap memory given in megabytes.", CommandOptionType.SingleValue);
            var onheapArgument         = commandLineApplication.Option("-OnHeap", "Size of on-heap memory given in megabytes.", CommandOptionType.SingleValue);
            var leaderNodeArgument     = commandLineApplication.Option("-SetLeader", "Set this node as the leader of the cluster.", CommandOptionType.NoValue);
            var serverPortArgument     = commandLineApplication.Option("-SpiPort", "Specifies port for Discovery Spi.", CommandOptionType.SingleValue);
            var clusterEnpointArgument = commandLineApplication.Option("-Cluster", "Specifies IP address and port of a cluster node. Multiple nodes can be specified.", CommandOptionType.MultipleValue);
            var consistentIdArgument   = commandLineApplication.Option("-ConsistentId", "Specifies as a consistent id of the node. This value is used in topology.", CommandOptionType.SingleValue);
            var persistenceEnabled     = commandLineApplication.Option("-PersistenceEnabled", "If set, it enables persistence mode.", CommandOptionType.NoValue);
            var serverInstances        = commandLineApplication.Option("-Instances", "Specifies number of instances creared. Default is 1.", CommandOptionType.SingleValue);

            commandLineApplication.OnExecute(async() =>
            {
                var configFile            = configFileArgument.HasValue() ? configFileArgument.Value() : null;
                var serverInstancesNumber = serverInstances.HasValue() ? Int32.Parse(serverInstances.Value()) : 1;
                if (serverInstancesNumber > 0 && serverInstancesNumber <= 16)
                {
                    var servers     = new IgniteServerRunner[serverInstancesNumber];
                    var serverTasks = new Task[serverInstancesNumber];
                    for (int i = 0; i < serverInstancesNumber; i++)
                    {
                        var server = new IgniteServerRunner(configFile);

                        if (offheapArgument.HasValue())
                        {
                            server.SetOffHeapMemoryLimit(Int32.Parse(offheapArgument.Value()));
                        }
                        if (onheapArgument.HasValue())
                        {
                            server.SetOnHeapMemoryLimit(Int32.Parse(onheapArgument.Value()));
                        }
                        if (serverPortArgument.HasValue())
                        {
                            server.SetServerPort(Int32.Parse(serverPortArgument.Value()));
                        }
                        if (clusterEnpointArgument.HasValue())
                        {
                            server.SetClusterEnpoints(clusterEnpointArgument.Values);
                        }
                        if (consistentIdArgument.HasValue())
                        {
                            server.SetConsistentId(consistentIdArgument.Value());
                        }
                        if (persistenceEnabled.HasValue())
                        {
                            server.SetPersistence(true);
                        }
                        serverTasks[i] = server.Run();
                    }
                    Task.WaitAll(serverTasks);
                    return(0);
                }
                throw new ArgumentOutOfRangeException($"Number of server instances {serverInstancesNumber} is out of bounds. It must be less than or equal to 16.");
            });


            try
            {
                commandLineApplication.Execute(args);
            }
            catch (CommandParsingException e)
            {
                commandLineApplication.Error.WriteLine($"ERROR: {e.Message}");
                commandLineApplication.ShowHelp();
            }
            catch (ArgumentException e)
            {
                commandLineApplication.Error.WriteLine($"ERROR: {e.Message}");
                commandLineApplication.ShowHelp();
            }
        }