Exemple #1
0
        /// <summary>
        /// Loads <see cref="ClusterConfiguration"/> using <see cref="ClusterConfiguration.StandardLoad"/>.
        /// </summary>
        /// <param name="builder">The host builder.</param>
        /// <returns>The silo builder.</returns>
        public static ISiloHostBuilder LoadClusterConfiguration(this ISiloHostBuilder builder)
        {
            var configuration = new ClusterConfiguration();

            configuration.StandardLoad();
            return(builder.UseConfiguration(configuration));
        }
Exemple #2
0
        internal static void InitSchedulerLogging()
        {
            TraceLogger.UnInitialize();
            //TraceLogger.LogConsumers.Add(new LogWriterToConsole());
            if (!Logger.TelemetryConsumers.OfType <ConsoleTelemetryConsumer>().Any())
            {
                Logger.TelemetryConsumers.Add(new ConsoleTelemetryConsumer());
            }

            var traceLevels = new[]
            {
                Tuple.Create("Scheduler", Severity.Verbose3),
                Tuple.Create("Scheduler.WorkerPoolThread", Severity.Verbose2),
            };

            TraceLogger.SetTraceLevelOverrides(new List <Tuple <string, Severity> >(traceLevels));

            var orleansConfig = new ClusterConfiguration();

            orleansConfig.StandardLoad();
            NodeConfiguration config = orleansConfig.GetOrAddConfigurationForNode("Primary");

            StatisticsCollector.Initialize(config);
            SchedulerStatisticsGroup.Init();
        }
Exemple #3
0
        public static ISiloHost BuildSiloHost()
        {
            var ddd = new MySql.Data.MySqlClient.MySqlCommand();

            var config = new ClusterConfiguration();

            config.StandardLoad();

            var builder = new SiloHostBuilder();

            //builder.LoadClusterConfiguration()
            builder.UseConfiguration(config)
            .ConfigureLogging(logging => logging.AddLog4Net("log4net.config"))
            .ConfigureServices((context, svr) =>
            {
                //同理客户端(ClientBuilder),服务端,也是自己有一个ServiceCollection容器对象
                //此处注入,处理的是针对Grain实现类的依赖注入;
                svr.AddScoped <IMessageService, MessageService>();
            })
            .ConfigureApplicationParts(parts =>
            {
                //此处需要添加Grain实现类程序集
                parts.AddApplicationPart(typeof(DemoService).Assembly).WithReferences();
            })
            .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "my-first-cluster";
                options.ServiceId = "MyAwesomeOrleansService";
            });

            return(builder.Build());
        }
        public override void Run()
        {
            var config = new ClusterConfiguration();
            config.StandardLoad();

            // Configure storage providers

            silo = new AzureSilo();
            bool ok = silo.Start(RoleEnvironment.DeploymentId,
                                 RoleEnvironment.CurrentRoleInstance,
                                 config);

            silo.Run(); // Call will block until silo is shutdown

            Trace.TraceInformation("OrleansAzureSilos is running");

            try
            {
                this.RunAsync(this.cancellationTokenSource.Token).Wait();
            }
            finally
            {
                this.runCompleteEvent.Set();
            }
        }
Exemple #5
0
        public override void Run()
        {
            var config = new ClusterConfiguration();

            config.StandardLoad();

            // Configure storage providers

            silo = new AzureSilo();
            bool ok = silo.Start(RoleEnvironment.DeploymentId,
                                 RoleEnvironment.CurrentRoleInstance,
                                 config);

            silo.Run(); // Call will block until silo is shutdown

            Trace.TraceInformation("OrleansAzureSilos is running");

            try
            {
                this.RunAsync(this.cancellationTokenSource.Token).Wait();
            }
            finally
            {
                this.runCompleteEvent.Set();
            }
        }
Exemple #6
0
 public override void Run() { 
     var config = new ClusterConfiguration();
     config.StandardLoad();
     
     // It is IMPORTANT to start the silo not in OnStart but in Run. 
     // Azure may not have the firewalls open yet (on the remote silos) at the OnStart phase.
     silo = new AzureSilo();
     bool isSiloStarted = silo.Start(config);
     
     silo.Run(); // Call will block until silo is shutdown
 } 
Exemple #7
0
        public void TestInitialize()
        {
            MessagingStatisticsGroup.Init(false);

            var orleansConfig = new ClusterConfiguration();

            orleansConfig.StandardLoad();
            BufferPool.InitGlobalBufferPool(orleansConfig.Globals);

            SerializationManager.InitializeForTesting();
        }
        public MessageSerializerTests(ITestOutputHelper output)
        {
            this.output = output;
            MessagingStatisticsGroup.Init(false);

            var orleansConfig = new ClusterConfiguration();

            orleansConfig.StandardLoad();
            BufferPool.InitGlobalBufferPool(orleansConfig.Globals);

            SerializationManager.InitializeForTesting();
        }
Exemple #9
0
        public override void Run()
        {
            var config = new ClusterConfiguration();

            config.StandardLoad();

            // It is IMPORTANT to start the silo not in OnStart but in Run.
            // Azure may not have the firewalls open yet (on the remote silos) at the OnStart phase.
            silo = new AzureSilo();
            bool isSiloStarted = silo.Start(config);

            silo.Run(); // Call will block until silo is shutdown
        }
        internal static ILoggerFactory InitSchedulerLogging()
        {
            var filters = new LoggerFilterOptions();

            filters.AddFilter("Scheduler", LogLevel.Trace);
            filters.AddFilter("Scheduler.WorkerPoolThread", LogLevel.Trace);
            var orleansConfig = new ClusterConfiguration();

            orleansConfig.StandardLoad();
            NodeConfiguration config = orleansConfig.CreateNodeConfigurationForSilo("Primary");
            var loggerFactory        = TestingUtils.CreateDefaultLoggerFactory(TestingUtils.CreateTraceFileName(config.SiloName, orleansConfig.Globals.ClusterId), filters);

            return(loggerFactory);
        }
Exemple #11
0
        private static async Task <ISiloHost> StartSilo()
        {
            var config = new ClusterConfiguration();

            config.StandardLoad();

            var builder = new SiloHostBuilder()
                          .UseConfiguration(config)
                          .ConfigureApplicationParts(x => x.AddApplicationPart(typeof(UserAccount).Assembly).WithReferences())
                          .ConfigureLogging(logging => logging.AddConsole());

            var host = builder.Build();
            await host.StartAsync();

            return(host);
        }
Exemple #12
0
        public void LogFileName()
        {
            var oc = new ClusterConfiguration();

            oc.StandardLoad();
            NodeConfiguration n     = oc.CreateNodeConfigurationForSilo("Node1");
            string            fname = n.TraceFileName;

            Assert.NotNull(fname);
            Assert.False(fname.Contains(":"), "Log file name should not contain colons.");

            // Check that .NET is happy with the file name
            var f = new FileInfo(fname);

            Assert.NotNull(f.Name);
            Assert.Equal(fname, f.Name);
        }
        internal static void InitSchedulerLogging()
        {
            LogManager.UnInitialize();
            //LogManager.LogConsumers.Add(new LogWriterToConsole());

            var traceLevels = new[]
            {
                Tuple.Create("Scheduler", Severity.Verbose3),
                Tuple.Create("Scheduler.WorkerPoolThread", Severity.Verbose2),
            };

            LogManager.SetTraceLevelOverrides(new List <Tuple <string, Severity> >(traceLevels));

            var orleansConfig = new ClusterConfiguration();

            orleansConfig.StandardLoad();
            NodeConfiguration config = orleansConfig.CreateNodeConfigurationForSilo("Primary");

            StatisticsCollector.Initialize(config);
            SchedulerStatisticsGroup.Init();
        }
        public override void Run()
        {
            Trace.TraceInformation("OrleansWorker is running");

            try
            {
                var config = new ClusterConfiguration();
                config.StandardLoad();
                ConfigureStorageProvider(config);
                _silo = new AzureSilo();
                var isSiloStarted = _silo.Start(config);
                if (isSiloStarted == false)
                {
                    Trace.TraceError("OrleansWorker.Run() -Error in starting silo");
                }
                _silo.Run();
            }
            finally
            {
                this._manualResetEvent.Set();
            }
        }
Exemple #15
0
        public override void Run()
        {
            Trace.WriteLine("OrleansAzureSilos-Run entry point called", "Information");

            Trace.WriteLine("OrleansAzureSilos-OnStart Starting Orleans silo", "Information");

            var config = new ClusterConfiguration();

            config.StandardLoad();

            // First example of how to configure an existing provider
            //ConfigureExistingStorageProvider(config);
            //ConfigureNewStorageProvider(config);
            //ConfigureNewBootstrapProvider(config);

            // It is IMPORTANT to start the silo not in OnStart but in Run.
            // Azure may not have the firewalls open yet (on the remote silos) at the OnStart phase.
            orleansAzureSilo = new AzureSilo();
            bool ok = orleansAzureSilo.Start(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance, config);

            Trace.WriteLine("OrleansAzureSilos-OnStart Orleans silo started ok=" + ok, "Information");

            orleansAzureSilo.Run(); // Call will block until silo is shutdown
        }
Exemple #16
0
        private SiloHandle StartOrleansSilo(Silo.SiloType type, TestingSiloOptions options, int instanceCount, AppDomain shared = null)
        {
            // Load initial config settings, then apply some overrides below.
            ClusterConfiguration config = new ClusterConfiguration();

            if (options.SiloConfigFile == null)
            {
                config.StandardLoad();
            }
            else
            {
                config.LoadFromFile(options.SiloConfigFile.FullName);
            }

            int basePort = options.BasePort < 0 ? BasePort : options.BasePort;


            if (config.Globals.SeedNodes.Count > 0 && options.BasePort < 0)
            {
                config.PrimaryNode = config.Globals.SeedNodes[0];
            }
            else
            {
                config.PrimaryNode = new IPEndPoint(IPAddress.Loopback, basePort);
            }
            config.Globals.SeedNodes.Clear();
            config.Globals.SeedNodes.Add(config.PrimaryNode);

            if (!String.IsNullOrEmpty(DeploymentId))
            {
                config.Globals.DeploymentId = DeploymentId;
            }
            config.Defaults.PropagateActivityId = options.PropagateActivityId;
            if (options.LargeMessageWarningThreshold > 0)
            {
                config.Defaults.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold;
            }

            config.Globals.LivenessType        = options.LivenessType;
            config.Globals.ReminderServiceType = options.ReminderServiceType;
            if (!String.IsNullOrEmpty(options.DataConnectionString))
            {
                config.Globals.DataConnectionString = options.DataConnectionString;
            }

            _livenessStabilizationTime = GetLivenessStabilizationTime(config.Globals);

            string siloName;

            switch (type)
            {
            case Silo.SiloType.Primary:
                siloName = "Primary";
                break;

            default:
                siloName = "Secondary_" + instanceCount.ToString(CultureInfo.InvariantCulture);
                break;
            }

            NodeConfiguration nodeConfig = config.GetConfigurationForNode(siloName);

            nodeConfig.HostNameOrIPAddress = "loopback";
            nodeConfig.Port = basePort + instanceCount;
            nodeConfig.DefaultTraceLevel   = config.Defaults.DefaultTraceLevel;
            nodeConfig.PropagateActivityId = config.Defaults.PropagateActivityId;
            nodeConfig.BulkMessageLimit    = config.Defaults.BulkMessageLimit;

            if (nodeConfig.ProxyGatewayEndpoint != null && nodeConfig.ProxyGatewayEndpoint.Address != null)
            {
                nodeConfig.ProxyGatewayEndpoint = new IPEndPoint(nodeConfig.ProxyGatewayEndpoint.Address, ProxyBasePort + instanceCount);
            }

            config.Globals.ExpectedClusterSize = 2;

            config.Overrides[siloName] = nodeConfig;

            AdjustForTest(config, options);

            WriteLog("Starting a new silo in app domain {0} with config {1}", siloName, config.ToString(siloName));
            AppDomain appDomain;
            Silo      silo = LoadSiloInNewAppDomain(siloName, type, config, out appDomain);

            silo.Start();

            SiloHandle retValue = new SiloHandle
            {
                Name      = siloName,
                Silo      = silo,
                Options   = options,
                Endpoint  = silo.SiloAddress.Endpoint,
                AppDomain = appDomain,
            };

            ImportGeneratedAssemblies(retValue);
            return(retValue);
        }
        private bool ParseArguments(string[] args)
        {
            string siloName = Dns.GetHostName(); // Default to machine name

            int siloPort         = 9800;
            int proxyGatewayPort = 9880;

            int argPos = 1;

            for (int i = 0; i < args.Length; i++)
            {
                string a = args[i];
                if (a.StartsWith("-") || a.StartsWith("/"))
                {
                    switch (a.ToLowerInvariant())
                    {
                    case "/?":
                    case "/help":
                    case "-?":
                    case "-help":
                        // Query usage help
                        return(false);

                    default:
                        Console.WriteLine("Bad command line arguments supplied: " + a);
                        return(false);
                    }
                }
                else if (a.Contains("="))
                {
                    string[] split = a.Split('=');
                    if (String.IsNullOrEmpty(split[1]))
                    {
                        Console.WriteLine("Bad command line arguments supplied: " + a);
                        return(false);
                    }

                    switch (split[0])
                    {
                    case "silo":
                        siloPort = int.Parse(split[1]);
                        break;

                    case "proxy":
                        proxyGatewayPort = int.Parse(split[1]);
                        break;

                    default:
                        Console.WriteLine("Bad command line arguments supplied: " + a);
                        return(false);
                    }
                }
                // unqualified arguments below
                else if (argPos == 1)
                {
                    siloName = a;
                    argPos++;
                }
                else
                {
                    // Too many command line arguments
                    Console.WriteLine("Too many command line arguments supplied: " + a);
                    return(false);
                }
            }

            var config = new ClusterConfiguration();

            config.StandardLoad();
            config.Defaults.Port = siloPort;
            config.Defaults.ProxyGatewayEndpoint = new IPEndPoint(config.Defaults.ProxyGatewayEndpoint.Address,
                                                                  proxyGatewayPort);

            config.Globals.DeploymentId            = "BetLab.Meetup";
            config.Globals.LivenessType            = GlobalConfiguration.LivenessProviderType.Custom;
            config.Globals.MembershipTableAssembly = "OrleansConsulUtils";
            config.Globals.ReminderServiceType     = GlobalConfiguration.ReminderServiceProviderType.Disabled;

            config.Globals.RegisterBootstrapProvider <Dashboard>("Dashboard", new Dictionary <string, string>()
            {
                ["Port"] = "8080"
            });

            config.AddStateStorageBasedLogConsistencyProvider();

            _siloHost = new SiloHost(siloName, config);

            return(true);
        }
Exemple #18
0
        /// <summary>
        /// Start a new silo in the target cluster
        /// </summary>
        /// <param name="host">The target cluster</param>
        /// <param name="type">The type of the silo to deploy</param>
        /// <param name="options">The options to use for the silo</param>
        /// <param name="instanceCount">The instance count of the silo</param>
        /// <param name="shared">The shared AppDomain to use</param>
        /// <returns>A handle to the deployed silo</returns>
        public static SiloHandle StartOrleansSilo(TestingSiloHost host, Silo.SiloType type, TestingSiloOptions options, int instanceCount, AppDomain shared = null)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            // Load initial config settings, then apply some overrides below.
            ClusterConfiguration config = new ClusterConfiguration();

            try
            {
                if (options.SiloConfigFile == null)
                {
                    config.StandardLoad();
                }
                else
                {
                    config.LoadFromFile(options.SiloConfigFile.FullName);
                }
            }
            catch (FileNotFoundException)
            {
                if (options.SiloConfigFile != null &&
                    !string.Equals(options.SiloConfigFile.Name, TestingSiloOptions.DEFAULT_SILO_CONFIG_FILE, StringComparison.InvariantCultureIgnoreCase))
                {
                    // if the user is not using the defaults, then throw because the file was legitimally not found
                    throw;
                }

                config = ClusterConfiguration.LocalhostPrimarySilo();
                config.AddMemoryStorageProvider("Default");
                config.AddMemoryStorageProvider("MemoryStore");
            }

            int basePort = options.BasePort < 0 ? BasePort : options.BasePort;


            if (config.Globals.SeedNodes.Count > 0 && options.BasePort < 0)
            {
                config.PrimaryNode = config.Globals.SeedNodes[0];
            }
            else
            {
                config.PrimaryNode = new IPEndPoint(IPAddress.Loopback, basePort);
            }
            config.Globals.SeedNodes.Clear();
            config.Globals.SeedNodes.Add(config.PrimaryNode);

            if (!String.IsNullOrEmpty(host.DeploymentId))
            {
                config.Globals.DeploymentId = host.DeploymentId;
            }

            config.Defaults.PropagateActivityId = options.PropagateActivityId;
            if (options.LargeMessageWarningThreshold > 0)
            {
                config.Defaults.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold;
            }

            config.Globals.LivenessType        = options.LivenessType;
            config.Globals.ReminderServiceType = options.ReminderServiceType;
            if (!String.IsNullOrEmpty(options.DataConnectionString))
            {
                config.Globals.DataConnectionString = options.DataConnectionString;
            }

            host.Globals = config.Globals;

            string siloName;

            switch (type)
            {
            case Silo.SiloType.Primary:
                siloName = "Primary";
                break;

            default:
                siloName = "Secondary_" + instanceCount.ToString(CultureInfo.InvariantCulture);
                break;
            }

            NodeConfiguration nodeConfig = config.GetOrCreateNodeConfigurationForSilo(siloName);

            nodeConfig.HostNameOrIPAddress = "loopback";
            nodeConfig.Port = basePort + instanceCount;
            nodeConfig.DefaultTraceLevel   = config.Defaults.DefaultTraceLevel;
            nodeConfig.PropagateActivityId = config.Defaults.PropagateActivityId;
            nodeConfig.BulkMessageLimit    = config.Defaults.BulkMessageLimit;

            int?gatewayport = null;

            if (nodeConfig.ProxyGatewayEndpoint != null && nodeConfig.ProxyGatewayEndpoint.Address != null)
            {
                gatewayport = (options.ProxyBasePort < 0 ? ProxyBasePort : options.ProxyBasePort) + instanceCount;
                nodeConfig.ProxyGatewayEndpoint = new IPEndPoint(nodeConfig.ProxyGatewayEndpoint.Address, gatewayport.Value);
            }

            config.Globals.ExpectedClusterSize = 2;

            config.Overrides[siloName] = nodeConfig;

            AdjustForTest(config, options);

            WriteLog("Starting a new silo in app domain {0} with config {1}", siloName, config.ToString(siloName));
            return(AppDomainSiloHandle.Create(siloName, type, config, nodeConfig, host.additionalAssemblies));
        }
Exemple #19
0
        private SiloHandle _StartOrleansSilo(Silo.SiloType type, UnitTestSiloOptions options, AppDomain shared = null)
        {
            // Load initial config settings, then apply some overrides below.
            ClusterConfiguration config = new ClusterConfiguration();

            if (options.SiloConfigFile == null)
            {
                config.StandardLoad();
            }
            else
            {
                config.LoadFromFile(options.SiloConfigFile.FullName);
            }

            int basePort = options.BasePort >= 0 ? options.BasePort : BasePort;

            if (config.Globals.SeedNodes.Count > 0 && options.BasePort < 0)
            {
                config.PrimaryNode = config.Globals.SeedNodes[0];
            }
            else
            {
                config.PrimaryNode = new IPEndPoint(IPAddress.Loopback, basePort);
            }
            config.Globals.SeedNodes.Clear();
            config.Globals.SeedNodes.Add(config.PrimaryNode);

            if (!String.IsNullOrEmpty(DeploymentId))
            {
                config.Globals.DeploymentId = DeploymentId;
            }
            config.Defaults.PropagateActivityId = options.PropagateActivityId;
            if (options.LargeMessageWarningThreshold > 0)
            {
                config.Defaults.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold;
            }

            config.Globals.LivenessType = options.LivenessType;

            globalConfig = config.Globals;

            string siloName;

            switch (type)
            {
            case Silo.SiloType.Primary:
                siloName = "Primary";
                break;

            default:
                siloName = "Secondary_" + InstanceCounter.ToString(CultureInfo.InvariantCulture);
                break;
            }

            NodeConfiguration nodeConfig = config.GetConfigurationForNode(siloName);

            nodeConfig.HostNameOrIPAddress = "loopback";
            nodeConfig.Port = basePort + InstanceCounter;
            nodeConfig.DefaultTraceLevel   = config.Defaults.DefaultTraceLevel;
            nodeConfig.PropagateActivityId = config.Defaults.PropagateActivityId;
            nodeConfig.BulkMessageLimit    = config.Defaults.BulkMessageLimit;

            config.Globals.ExpectedClusterSize = 2;

            config.Overrides[siloName] = nodeConfig;

            InstanceCounter++;

            Console.WriteLine("Starting a new silo in app domain {0} with config {1}", siloName, config.ToString(siloName));
            AppDomain appDomain;
            Silo      silo = _LoadSiloInNewAppDomain(siloName, type, config, out appDomain);

            silo.Start();

            SiloHandle retValue = new SiloHandle
            {
                Name      = siloName,
                Silo      = silo,
                Options   = options,
                Endpoint  = silo.SiloAddress.Endpoint,
                AppDomain = appDomain,
            };

            return(retValue);
        }