Esempio n. 1
0
        public GigyaSiloHost(ILog log, OrleansConfigurationBuilder configBuilder,
                             HttpServiceListener httpServiceListener,
                             IEventPublisher <GrainCallEvent> eventPublisher, Func <LoadShedding> loadSheddingConfig,
                             ISourceBlock <OrleansConfig> orleansConfigSourceBlock, OrleansConfig orleansConfig)
        {
            Log                 = log;
            ConfigBuilder       = configBuilder;
            HttpServiceListener = httpServiceListener;
            EventPublisher      = eventPublisher;
            LoadSheddingConfig  = loadSheddingConfig;


            OrleansConfigSourceBlock = orleansConfigSourceBlock;
            PreviousOrleansConfig    = orleansConfig;
            OrleansConfigSourceBlock.LinkTo(new ActionBlock <OrleansConfig>(config => UpdateOrleansAgeLimitChange(config)));

            if (DelegatingBootstrapProvider.OnInit != null || DelegatingBootstrapProvider.OnClose != null)
            {
                throw new InvalidOperationException("DelegatingBootstrapProvider is already in use.");
            }

            DelegatingBootstrapProvider.OnInit  = BootstrapInit;
            DelegatingBootstrapProvider.OnClose = BootstrapClose;

            EventsDiscarded = Metric.Context("GigyaSiloHost").Counter("GrainCallEvents discarded", Unit.Items);
        }
 public OrleansConfigurationBuilder(OrleansConfig orleansConfig, OrleansCodeConfig commonConfig,
                                    OrleansServiceInterfaceMapper orleansServiceInterfaceMapper,
                                    ClusterIdentity clusterIdentity, IServiceEndPointDefinition endPointDefinition,
                                    ServiceArguments serviceArguments,
                                    CurrentApplicationInfo appInfo)
 {
     _orleansConfig = orleansConfig;
     _commonConfig  = commonConfig;
     _orleansServiceInterfaceMapper = orleansServiceInterfaceMapper;
     _clusterIdentity    = clusterIdentity;
     _endPointDefinition = endPointDefinition;
     _serviceArguments   = serviceArguments;
     _appInfo            = appInfo;
     _siloHostBuilder    = InitBuilder();
 }
Esempio n. 3
0
        public GigyaSiloHost(ILog log, HttpServiceListener httpServiceListener,
                             IOrleansToNinjectBinding serviceProvider, OrleansLogProvider logProvider,
                             OrleansConfigurationBuilder orleansConfigurationBuilder, OrleansConfig orleansConfig,
                             Func <IServiceProvider> factoryServiceProvider
                             )

        {
            _serviceProvider             = serviceProvider;
            _logProvider                 = logProvider;
            _orleansConfigurationBuilder = orleansConfigurationBuilder;
            _orleansConfig               = orleansConfig;
            _factoryServiceProvider      = factoryServiceProvider;

            Log = log;
            HttpServiceListener = httpServiceListener;
        }
Esempio n. 4
0
        private void SetAgeLimits(GlobalConfiguration globals, OrleansConfig orleansConfig, OrleansServiceInterfaceMapper orleansServiceInterfaceMapper)
        {
            globals.Application.SetDefaultCollectionAgeLimit(TimeSpan.FromMinutes(orleansConfig.DefaultGrainAgeLimitInMins));

            if (orleansConfig.GrainAgeLimits != null)
            {
                foreach (var grainAgeLimitConfig in orleansConfig.GrainAgeLimits.Values)
                {
                    try
                    {
                        orleansServiceInterfaceMapper.ServiceClassesTypes.Single(x => x.FullName.Equals(grainAgeLimitConfig.GrainType));
                    }
                    catch (Exception e)
                    {
                        throw new ArgumentException($"Assigning Age Limit on {grainAgeLimitConfig.GrainType} has failed, because {grainAgeLimitConfig.GrainType} is an invalid type\n{e.Message}");
                    }
                    globals.Application.SetCollectionAgeLimit(grainAgeLimitConfig.GrainType, TimeSpan.FromMinutes(grainAgeLimitConfig.GrainAgeLimitInMins));
                }
            }
        }
Esempio n. 5
0
        public void UpdateOrleansAgeLimitChange(OrleansConfig orleanConfig)
        {
            try
            {
                var previousAgeLimits = PreviousOrleansConfig.GrainAgeLimits ?? new Dictionary <string, GrainAgeLimitConfig>();
                var newAgeLimits      = orleanConfig.GrainAgeLimits ?? new Dictionary <string, GrainAgeLimitConfig>();


                foreach (var newGrainAgeLimitConfig in newAgeLimits.Values)
                {
                    var grainAgeLimit = previousAgeLimits.Values.FirstOrDefault(x => x.GrainType.Equals(newGrainAgeLimitConfig.GrainType)) ?? new GrainAgeLimitConfig
                    {
                        GrainType           = newGrainAgeLimitConfig.GrainType,
                        GrainAgeLimitInMins = -1
                    };


                    if (grainAgeLimit.GrainAgeLimitInMins != newGrainAgeLimitConfig.GrainAgeLimitInMins)
                    {
                        ConfigBuilder.ClusterConfiguration.Globals.Application.SetCollectionAgeLimit(newGrainAgeLimitConfig.GrainType, TimeSpan.FromMinutes(newGrainAgeLimitConfig.GrainAgeLimitInMins));
                    }
                }

                foreach (var item in previousAgeLimits.Values)
                {
                    var grainAgeLimit = newAgeLimits.Values.FirstOrDefault(x => x.GrainType.Equals(item.GrainType));

                    if (grainAgeLimit == null) //in case that an configuration was removed! - Restoring to default Age Limit
                    {
                        ConfigBuilder.ClusterConfiguration.Globals.Application.SetCollectionAgeLimit(item.GrainType, TimeSpan.FromMinutes(orleanConfig.DefaultGrainAgeLimitInMins));
                    }
                }

                PreviousOrleansConfig = orleanConfig;
            }
            catch (Exception ex)
            {
                Log.Error("Failed to reload configuration", exception: ex);
            }
        }
Esempio n. 6
0
        public OrleansConfigurationBuilder(OrleansConfig orleansConfig, OrleansCodeConfig commonConfig, OrleansServiceInterfaceMapper orleansServiceInterfaceMapper,
                                           ClusterConfiguration clusterConfiguration, ClusterIdentity clusterIdentity, IServiceEndPointDefinition endPointDefinition,
                                           OrleansLogConsumer orleansLogConsumer, ZooKeeperLogConsumer zooKeeperLogConsumer, ServiceArguments serviceArguments)
        {
            ClusterConfiguration = clusterConfiguration;

            SiloType = Silo.SiloType.Secondary;
            var globals  = ClusterConfiguration.Globals;
            var defaults = ClusterConfiguration.Defaults;

            SetAgeLimits(globals, orleansConfig, orleansServiceInterfaceMapper);

            globals.ExpectedClusterSize = 1; // Minimizes artificial startup delay to a maximum of 0.5 seconds (instead of 10 seconds).
            globals.RegisterBootstrapProvider <DelegatingBootstrapProvider>(nameof(DelegatingBootstrapProvider));
            defaults.ProxyGatewayEndpoint = new IPEndPoint(IPAddress.Loopback, endPointDefinition.SiloGatewayPort);
            defaults.Port = endPointDefinition.SiloNetworkingPort;
            defaults.DefaultConnectionLimit = ServicePointManager.DefaultConnectionLimit;

            if (serviceArguments.ProcessorAffinity != null)
            {
                defaults.MaxActiveThreads = serviceArguments.ProcessorAffinity.Length;
            }

            // Orleans log redirection
            defaults.TraceToConsole   = false;
            defaults.TraceFileName    = null;
            defaults.TraceFilePattern = null;
            LogManager.LogConsumers.Add(orleansLogConsumer);

            // ZooKeeper log redirection
            ZooKeeper.LogToFile         = false;
            ZooKeeper.LogToTrace        = false;
            ZooKeeper.LogLevel          = TraceLevel.Verbose;
            ZooKeeper.CustomLogConsumer = zooKeeperLogConsumer;

            //Setup Statistics
            var metricsProviderType = typeof(MetricsStatisticsPublisher);

            globals.ProviderConfigurations.Add("Statistics", new ProviderCategoryConfiguration("Statistics")
            {
                Providers = new Dictionary <string, IProviderConfiguration>
                {
                    {
                        metricsProviderType.Name,
                        new ProviderConfiguration(new Dictionary <string, string>(), metricsProviderType.FullName, metricsProviderType.Name)
                    }
                }
            });
            defaults.StatisticsProviderName              = metricsProviderType.Name;
            defaults.StatisticsCollectionLevel           = StatisticsLevel.Info;
            defaults.StatisticsLogWriteInterval          = TimeSpan.Parse(orleansConfig.MetricsTableWriteInterval);
            defaults.StatisticsWriteLogStatisticsToTable = true;

            if (commonConfig.ServiceArguments.SiloClusterMode != SiloClusterMode.ZooKeeper)
            {
                defaults.HostNameOrIPAddress = "localhost";
                globals.ReminderServiceType  = commonConfig.UseReminders
                    ? GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain
                    : GlobalConfiguration.ReminderServiceProviderType.Disabled;

                globals.LivenessType = GlobalConfiguration.LivenessProviderType.MembershipTableGrain;

                if (commonConfig.ServiceArguments.SiloClusterMode == SiloClusterMode.PrimaryNode)
                {
                    globals.SeedNodes.Add(new IPEndPoint(IPAddress.Loopback, endPointDefinition.SiloNetworkingPort));
                    SiloType = Silo.SiloType.Primary;
                }
                else
                {
                    globals.SeedNodes.Add(new IPEndPoint(IPAddress.Loopback, endPointDefinition.SiloNetworkingPortOfPrimaryNode));
                }
            }
            else
            {
                globals.DeploymentId         = clusterIdentity.DeploymentId;
                globals.LivenessType         = GlobalConfiguration.LivenessProviderType.ZooKeeper;
                globals.DataConnectionString = orleansConfig.ZooKeeper.ConnectionString;

                if (commonConfig.UseReminders)
                {
                    globals.ServiceId           = clusterIdentity.ServiceId;
                    globals.ReminderServiceType = GlobalConfiguration.ReminderServiceProviderType.SqlServer;
                    globals.DataConnectionStringForReminders = orleansConfig.MySql_v4_0.ConnectionString;
                    globals.AdoInvariantForReminders         = "MySql.Data.MySqlClient";
                }
                else
                {
                    globals.ReminderServiceType = GlobalConfiguration.ReminderServiceProviderType.Disabled;
                }
            }

            if (string.IsNullOrEmpty(commonConfig.StorageProviderTypeFullName) == false)
            {
                //globals.RegisterStorageProvider<MemoryStorage>("OrleansStorage");
                globals.RegisterStorageProvider(commonConfig.StorageProviderTypeFullName, "Default");
                globals.RegisterStorageProvider(commonConfig.StorageProviderTypeFullName, commonConfig.StorageProviderName);
            }
        }