Beispiel #1
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();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OrleansCommunicationListener" /> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="configuration">The configuration.</param>
        public OrleansCommunicationListener(ServiceContext context, ClusterConfiguration configuration)
        {
            this.configuration = configuration;
            if (this.configuration == null)
            {
                this.configuration = new ClusterConfiguration();
                this.configuration.StandardLoad();
            }

            this.SiloName = Regex.Replace(context.ServiceName.PathAndQuery.Trim('/'), "[^a-zA-Z0-9_]", "_") + "_" +
                            context.ReplicaOrInstanceId.ToString("X");

            // Gather configuration from Service Fabric.
            var activation = context.CodePackageActivationContext;
            var endpoints = activation.GetEndpoints();
            var siloEndpoint = GetEndpoint(endpoints, "OrleansSiloEndpoint");
            var gatewayEndpoint = GetEndpoint(endpoints, "OrleansProxyEndpoint");

            // Set the endpoints according to Service Fabric configuration.
            var nodeConfig = this.configuration.Defaults;
            if (string.IsNullOrWhiteSpace(nodeConfig.HostNameOrIPAddress))
            {
                nodeConfig.HostNameOrIPAddress = context.NodeContext.IPAddressOrFQDN;
            }

            nodeConfig.Port = siloEndpoint.Port;
            nodeConfig.ProxyGatewayEndpoint = new IPEndPoint(nodeConfig.Endpoint.Address, gatewayEndpoint.Port);
        }
 public OrleansCommunicationListener(
     StatelessServiceContext parameters,
     ClusterConfiguration configuration,
     IServicePartition servicePartition)
 {
     this.parameters = parameters;
     this.configuration = configuration;
     this.partition = servicePartition;
 }
Beispiel #4
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
 } 
        private static void AddLegacyClusterConfigurationSupport(IServiceCollection services, ClusterConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (services.TryGetClusterConfiguration() != null)
            {
                throw new InvalidOperationException("Cannot configure legacy ClusterConfiguration support twice");
            }

            // these will eventually be removed once our code doesn't depend on the old ClientConfiguration
            services.AddSingleton(configuration);
            services.TryAddSingleton <LegacyConfigurationWrapper>();
            services.TryAddSingleton(sp => sp.GetRequiredService <LegacyConfigurationWrapper>().ClusterConfig.Globals);
            services.TryAddTransient(sp => sp.GetRequiredService <LegacyConfigurationWrapper>().NodeConfig);
            services.TryAddSingleton <Factory <NodeConfiguration> >(
                sp =>
            {
                var initializationParams = sp.GetRequiredService <LegacyConfigurationWrapper>();
                return(() => initializationParams.NodeConfig);
            });

            services.Configure <ClusterOptions>(options =>
            {
                if (string.IsNullOrWhiteSpace(options.ClusterId) && !string.IsNullOrWhiteSpace(configuration.Globals.ClusterId))
                {
                    options.ClusterId = configuration.Globals.ClusterId;
                }

                if (string.IsNullOrWhiteSpace(options.ServiceId))
                {
                    options.ServiceId = configuration.Globals.ServiceId.ToString();
                }
            });

            services.Configure <MultiClusterOptions>(options =>
            {
                var globals = configuration.Globals;
                if (globals.HasMultiClusterNetwork)
                {
                    options.HasMultiClusterNetwork            = true;
                    options.BackgroundGossipInterval          = globals.BackgroundGossipInterval;
                    options.DefaultMultiCluster               = globals.DefaultMultiCluster?.ToList();
                    options.GlobalSingleInstanceNumberRetries = globals.GlobalSingleInstanceNumberRetries;
                    options.GlobalSingleInstanceRetryInterval = globals.GlobalSingleInstanceRetryInterval;
                    options.MaxMultiClusterGateways           = globals.MaxMultiClusterGateways;
                    options.UseGlobalSingleInstanceByDefault  = globals.UseGlobalSingleInstanceByDefault;
                    foreach (GlobalConfiguration.GossipChannelConfiguration channelConfig in globals.GossipChannels)
                    {
                        options.GossipChannels.Add(GlobalConfiguration.Remap(channelConfig.ChannelType), channelConfig.ConnectionString);
                    }
                }
            });

            services.TryAddFromExisting <IMessagingConfiguration, GlobalConfiguration>();

            services.AddOptions <StatisticsOptions>()
            .Configure <NodeConfiguration>((options, nodeConfig) => LegacyConfigurationExtensions.CopyStatisticsOptions(nodeConfig, options));

            services.AddOptions <DeploymentLoadPublisherOptions>()
            .Configure <GlobalConfiguration>((options, config) =>
            {
                options.DeploymentLoadPublisherRefreshTime = config.DeploymentLoadPublisherRefreshTime;
            });

            services.AddOptions <LoadSheddingOptions>()
            .Configure <NodeConfiguration>((options, nodeConfig) =>
            {
                options.LoadSheddingEnabled = nodeConfig.LoadSheddingEnabled;
                options.LoadSheddingLimit   = nodeConfig.LoadSheddingLimit;
            });

            // Translate legacy configuration to new Options
            services.AddOptions <SiloMessagingOptions>()
            .Configure <GlobalConfiguration>((options, config) =>
            {
                LegacyConfigurationExtensions.CopyCommonMessagingOptions(config, options);
                options.SiloSenderQueues                = config.SiloSenderQueues;
                options.GatewaySenderQueues             = config.GatewaySenderQueues;
                options.MaxForwardCount                 = config.MaxForwardCount;
                options.ClientDropTimeout               = config.ClientDropTimeout;
                options.ClientRegistrationRefresh       = config.ClientRegistrationRefresh;
                options.MaxRequestProcessingTime        = config.MaxRequestProcessingTime;
                options.AssumeHomogenousSilosForTesting = config.AssumeHomogenousSilosForTesting;
            })
            .Configure <NodeConfiguration>((options, config) =>
            {
                options.PropagateActivityId            = config.PropagateActivityId;
                LimitValue requestLimit                = config.LimitManager.GetLimit(LimitNames.LIMIT_MAX_ENQUEUED_REQUESTS);
                options.MaxEnqueuedRequestsSoftLimit   = requestLimit.SoftLimitThreshold;
                options.MaxEnqueuedRequestsHardLimit   = requestLimit.HardLimitThreshold;
                LimitValue statelessWorkerRequestLimit = config.LimitManager.GetLimit(LimitNames.LIMIT_MAX_ENQUEUED_REQUESTS_STATELESS_WORKER);
                options.MaxEnqueuedRequestsSoftLimit_StatelessWorker = statelessWorkerRequestLimit.SoftLimitThreshold;
                options.MaxEnqueuedRequestsHardLimit_StatelessWorker = statelessWorkerRequestLimit.HardLimitThreshold;
            });

            services.Configure <NetworkingOptions>(options => LegacyConfigurationExtensions.CopyNetworkingOptions(configuration.Globals, options));

            services.AddOptions <EndpointOptions>()
            .Configure <IOptions <SiloOptions> >((options, siloOptions) =>
            {
                var nodeConfig = configuration.GetOrCreateNodeConfigurationForSilo(siloOptions.Value.SiloName);
                if (!string.IsNullOrEmpty(nodeConfig.HostNameOrIPAddress) || nodeConfig.Port != 0)
                {
                    options.AdvertisedIPAddress = nodeConfig.Endpoint.Address;
                    options.SiloPort            = nodeConfig.Endpoint.Port;
                }
            });

            services.Configure <SerializationProviderOptions>(options =>
            {
                options.SerializationProviders        = configuration.Globals.SerializationProviders;
                options.FallbackSerializationProvider = configuration.Globals.FallbackSerializationProvider;
            });

            services.Configure <TelemetryOptions>(options =>
            {
                LegacyConfigurationExtensions.CopyTelemetryOptions(configuration.Defaults.TelemetryConfiguration, services, options);
            });

            services.AddOptions <GrainClassOptions>().Configure <IOptions <SiloOptions> >((options, siloOptions) =>
            {
                var nodeConfig = configuration.GetOrCreateNodeConfigurationForSilo(siloOptions.Value.SiloName);
                options.ExcludedGrainTypes.AddRange(nodeConfig.ExcludedGrainTypes);
            });

            services.AddOptions <SchedulingOptions>()
            .Configure <GlobalConfiguration>((options, config) =>
            {
                options.AllowCallChainReentrancy = config.AllowCallChainReentrancy;
                options.PerformDeadlockDetection = config.PerformDeadlockDetection;
            })
            .Configure <NodeConfiguration>((options, nodeConfig) =>
            {
                options.MaxActiveThreads            = nodeConfig.MaxActiveThreads;
                options.DelayWarningThreshold       = nodeConfig.DelayWarningThreshold;
                options.ActivationSchedulingQuantum = nodeConfig.ActivationSchedulingQuantum;
                options.TurnWarningLengthThreshold  = nodeConfig.TurnWarningLengthThreshold;
                options.EnableWorkerThreadInjection = nodeConfig.EnableWorkerThreadInjection;
                LimitValue itemLimit = nodeConfig.LimitManager.GetLimit(LimitNames.LIMIT_MAX_PENDING_ITEMS);
                options.MaxPendingWorkItemsSoftLimit = itemLimit.SoftLimitThreshold;
                options.MaxPendingWorkItemsHardLimit = itemLimit.HardLimitThreshold;
            });

            services.AddOptions <GrainCollectionOptions>().Configure <GlobalConfiguration>((options, config) =>
            {
                options.CollectionQuantum = config.CollectionQuantum;
                options.CollectionAge     = config.Application.DefaultCollectionAgeLimit;
                foreach (GrainTypeConfiguration grainConfig in config.Application.ClassSpecific)
                {
                    if (grainConfig.CollectionAgeLimit.HasValue)
                    {
                        options.ClassSpecificCollectionAge.Add(grainConfig.FullTypeName, grainConfig.CollectionAgeLimit.Value);
                    }
                }
                ;
            });

            LegacyProviderConfigurator <ISiloLifecycle> .ConfigureServices(configuration.Globals.ProviderConfigurations, services);

            if (!string.IsNullOrWhiteSpace(configuration.Globals.DefaultPlacementStrategy))
            {
                services.AddSingleton(typeof(PlacementStrategy), MapDefaultPlacementStrategy(configuration.Globals.DefaultPlacementStrategy));
            }

            services.AddOptions <ActivationCountBasedPlacementOptions>().Configure <GlobalConfiguration>((options, config) =>
            {
                options.ChooseOutOf = config.ActivationCountBasedPlacementChooseOutOf;
            });

            services.AddOptions <StaticClusterDeploymentOptions>().Configure <ClusterConfiguration>((options, config) =>
            {
                options.SiloNames = config.Overrides.Keys.ToList();
            });

            // add grain service configs as keyed services
            foreach (IGrainServiceConfiguration grainServiceConfiguration in configuration.Globals.GrainServiceConfigurations.GrainServices.Values)
            {
                var type = Type.GetType(grainServiceConfiguration.ServiceType);
                services.AddSingletonKeyedService(type, (sp, k) => grainServiceConfiguration);
            }

            // populate grain service options
            foreach (IGrainServiceConfiguration grainServiceConfiguration in configuration.Globals.GrainServiceConfigurations.GrainServices.Values)
            {
                services.AddGrainService(Type.GetType(grainServiceConfiguration.ServiceType));
            }

            services.AddOptions <ConsistentRingOptions>().Configure <GlobalConfiguration>((options, config) =>
            {
                options.UseVirtualBucketsConsistentRing = config.UseVirtualBucketsConsistentRing;
                options.NumVirtualBucketsConsistentRing = config.NumVirtualBucketsConsistentRing;
            });

            services.AddOptions <ClusterMembershipOptions>()
            .Configure <GlobalConfiguration>((options, config) =>
            {
                options.NumMissedTableIAmAliveLimit = config.NumMissedTableIAmAliveLimit;
                options.LivenessEnabled             = config.LivenessEnabled;
                options.ProbeTimeout                = config.ProbeTimeout;
                options.TableRefreshTimeout         = config.TableRefreshTimeout;
                options.DeathVoteExpirationTimeout  = config.DeathVoteExpirationTimeout;
                options.IAmAliveTablePublishTimeout = config.IAmAliveTablePublishTimeout;
                options.MaxJoinAttemptTime          = config.MaxJoinAttemptTime;
                options.ExpectedClusterSize         = config.ExpectedClusterSize;
                options.ValidateInitialConnectivity = config.ValidateInitialConnectivity;
                options.NumMissedProbesLimit        = config.NumMissedProbesLimit;
                options.UseLivenessGossip           = config.UseLivenessGossip;
                options.NumProbedSilos              = config.NumProbedSilos;
                options.NumVotesForDeathDeclaration = config.NumVotesForDeathDeclaration;
            })
            .Configure <ClusterConfiguration>((options, config) =>
            {
                options.IsRunningAsUnitTest = config.IsRunningAsUnitTest;
            });

            services.AddOptions <GrainVersioningOptions>()
            .Configure <GlobalConfiguration>((options, config) =>
            {
                options.DefaultCompatibilityStrategy   = config.DefaultCompatibilityStrategy?.GetType().Name ?? GrainVersioningOptions.DEFAULT_COMPATABILITY_STRATEGY;
                options.DefaultVersionSelectorStrategy = config.DefaultVersionSelectorStrategy?.GetType().Name ?? GrainVersioningOptions.DEFAULT_VERSION_SELECTOR_STRATEGY;
            });

            services.AddOptions <PerformanceTuningOptions>()
            .Configure <NodeConfiguration>((options, config) =>
            {
                options.DefaultConnectionLimit  = config.DefaultConnectionLimit;
                options.Expect100Continue       = config.Expect100Continue;
                options.UseNagleAlgorithm       = config.UseNagleAlgorithm;
                options.MinDotNetThreadPoolSize = config.MinDotNetThreadPoolSize;
            });

            services.AddOptions <TypeManagementOptions>()
            .Configure <GlobalConfiguration>((options, config) =>
            {
                options.TypeMapRefreshInterval = config.TypeMapRefreshInterval;
            });

            services.AddOptions <GrainDirectoryOptions>()
            .Configure <GlobalConfiguration>((options, config) =>
            {
                options.CachingStrategy         = Remap(config.DirectoryCachingStrategy);
                options.CacheSize               = config.CacheSize;
                options.InitialCacheTTL         = config.InitialCacheTTL;
                options.MaximumCacheTTL         = config.MaximumCacheTTL;
                options.CacheTTLExtensionFactor = config.CacheTTLExtensionFactor;
                options.LazyDeregistrationDelay = config.DirectoryLazyDeregistrationDelay;
            });
        }
 /// <summary>
 /// Specifies the configuration to use for this silo.
 /// </summary>
 /// <param name="builder">The host builder.</param>
 /// <param name="configuration">The configuration.</param>
 /// <remarks>This method may only be called once per builder instance.</remarks>
 /// <returns>The silo builder.</returns>
 public static ISiloHostBuilder UseConfiguration(this ISiloHostBuilder builder, ClusterConfiguration configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     return(builder.AddLegacyClusterConfigurationSupport(configuration));
 }
Beispiel #7
0
 /// <summary>
 /// Set the configuration to edit.  If null a new configuration will be created.
 /// </summary>
 /// <param name="configToEdit">Configuration to edit.</param>
 public void SetConfigToEdit(ClusterConfiguration configToEdit)
 {
     this.config        = configToEdit;
     this.canChangeType = configToEdit == null;
     this.BindProperties();
 }
Beispiel #8
0
        static void Main(string[] args)
        {
            // First, configure and start a local silo
            var siloConfig = ClusterConfiguration.LocalhostPrimarySilo();
            var silo       = new SiloHost("TestSilo", siloConfig);

            silo.InitializeOrleansSilo();
            silo.StartOrleansSilo();

            Console.WriteLine("Silo started.");

            // Then configure and connect a client.
            //var clientConfig = ClientConfiguration.LocalhostSilo();
            //var client = new ClientBuilder().UseConfiguration(clientConfig).Build();
            //client.Connect().Wait();
            GrainClient.Initialize(ClientConfiguration.LocalhostSilo());
            Console.WriteLine("Client connected.");



            var game = new GameController();

            //// mock
            //var nir = game.CreatePlayer("p1", "p1name").Result;
            //nir = game.CreatePlayer("p2", "p2name").Result;
            //nir = game.CreatePlayer("p3", "p3name").Result;
            //nir = game.CreatePlayer("p4", "p4name").Result;
            //game.CreateTeam("t1");
            //nir = game.AddPlayerToTeam("p1", "t1").Result;
            //nir = game.AddPlayerToTeam("p2", "t1").Result;
            //nir = game.AddPlayerToTeam("p3", "t1").Result;
            //var players2 = game.ListPlayers("t1").Result;
            //Console.WriteLine(String.Join(", ", players2));

            while (true)
            {
                var line = double.Parse(Console.ReadLine());
                OperationResults.ServiceCallResult status = OperationResults.ServiceCallResult.ERROR;
                switch (line)
                {
                case 1:     // CreatePlayer
                    Console.WriteLine("CreatePlayer");
                    Console.WriteLine("Enter Player ID:");
                    var id = Console.ReadLine();
                    Console.WriteLine("Enter Player Name:");
                    var name = Console.ReadLine();

                    status = game.CreatePlayer(id, name).Result;
                    if (status == OperationResults.ServiceCallResult.ERROR)
                    {
                        Console.WriteLine("error creating player");
                    }
                    break;

                case 2:     // CreateTeam
                    Console.WriteLine("CreateTeam");
                    Console.WriteLine("Enter Team ID:");
                    game.CreateTeam(Console.ReadLine());
                    status = OperationResults.ServiceCallResult.OK;
                    break;

                case 3:     // AddPlayerToTeam
                    Console.WriteLine("AddPlayerToTeam");
                    Console.WriteLine("Player ID:");
                    var playerId = Console.ReadLine();
                    Console.WriteLine("Team ID:");
                    var teamId = Console.ReadLine();
                    status = game.AddPlayerToTeam(playerId, teamId).Result;
                    if (status == OperationResults.ServiceCallResult.ERROR)
                    {
                        Console.WriteLine("error AddPlayerToTeam");
                    }

                    break;

                case 4:     // RemovePlayerFromTeam
                    Console.WriteLine("RemovePlayerFromTeam");
                    Console.WriteLine("Player ID:");
                    Console.WriteLine("Team ID:");
                    status = game.RemovePlayerFromTeam(Console.ReadLine(), Console.ReadLine()).Result;
                    if (status == OperationResults.ServiceCallResult.ERROR)
                    {
                        Console.WriteLine("error RemovePlayerFromTeam");
                    }

                    break;

                case 5:     // ListPlayers
                    Console.WriteLine("ListPlayers");
                    Console.WriteLine("Enter Team ID:");
                    var players = game.ListPlayers(Console.ReadLine()).Result;
                    Console.WriteLine(String.Join(", ", players));
                    status = OperationResults.ServiceCallResult.OK;
                    break;

                default:
                    Console.WriteLine("no such command");
                    break;
                }
            }


            //// End
            //Console.WriteLine("\nPress Enter to terminate...");
            //Console.ReadLine();

            // Shut down
            //client.Close();
            silo.ShutdownOrleansSilo();
        }
Beispiel #9
0
 /// <summary>
 /// Creates and initializes the silo from the specified config data.
 /// </summary>
 /// <param name="name">Name of this silo.</param>
 /// <param name="siloType">Type of this silo.</param>
 /// <param name="config">Silo config data to be used for this silo.</param>
 public Silo(string name, SiloType siloType, ClusterConfiguration config)
     : this(name, siloType, config, null)
 {
 }
        private bool ParseArguments(string[] args)
        {
            string deploymentId = null;

            string siloName = Dns.GetHostName(); // Default to machine name

            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].ToLowerInvariant())
                    {
                    case "deploymentid":
                        deploymentId = 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 = ClusterConfiguration.LocalhostPrimarySilo();

            config.AddMemoryStorageProvider();
            siloHost = new Orleans.Runtime.Host.SiloHost(siloName, config);

            if (deploymentId != null)
            {
                siloHost.DeploymentId = deploymentId;
            }

            return(true);
        }
Beispiel #11
0
        public OutsideRuntimeClient(ClientConfiguration cfg, GrainFactory grainFactory, bool secondary = false)
        {
            this.grainFactory = grainFactory;
            this.clientId     = GrainId.NewClientId();

            if (cfg == null)
            {
                Console.WriteLine("An attempt to create an OutsideRuntimeClient with null ClientConfiguration object.");
                throw new ArgumentException("OutsideRuntimeClient was attempted to be created with null ClientConfiguration object.", "cfg");
            }

            this.config = cfg;

            if (!TraceLogger.IsInitialized)
            {
                TraceLogger.Initialize(config);
            }
            StatisticsCollector.Initialize(config);
            SerializationManager.Initialize(config.UseStandardSerializer, cfg.SerializationProviders, config.UseJsonFallbackSerializer);
            logger    = TraceLogger.GetLogger("OutsideRuntimeClient", TraceLogger.LoggerType.Runtime);
            appLogger = TraceLogger.GetLogger("Application", TraceLogger.LoggerType.Application);

            try
            {
                LoadAdditionalAssemblies();

                PlacementStrategy.Initialize();

                callbacks    = new ConcurrentDictionary <CorrelationId, CallbackData>();
                localObjects = new ConcurrentDictionary <GuidId, LocalObjectData>();

                if (!secondary)
                {
                    UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnhandledException);
                }
                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

                // Ensure SerializationManager static constructor is called before AssemblyLoad event is invoked
                SerializationManager.GetDeserializer(typeof(String));

                clientProviderRuntime     = new ClientProviderRuntime(grainFactory, new DefaultServiceProvider());
                statisticsProviderManager = new StatisticsProviderManager("Statistics", clientProviderRuntime);
                var statsProviderName = statisticsProviderManager.LoadProvider(config.ProviderConfigurations)
                                        .WaitForResultWithThrow(initTimeout);
                if (statsProviderName != null)
                {
                    config.StatisticsProviderName = statsProviderName;
                }

                responseTimeout = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout;
                BufferPool.InitGlobalBufferPool(config);
                var localAddress = ClusterConfiguration.GetLocalIPAddress(config.PreferredFamily, config.NetInterface);

                // Client init / sign-on message
                logger.Info(ErrorCode.ClientInitializing, string.Format(
                                "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}",
                                BARS, config.DNSHostName, localAddress, clientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}",
                                                BARS, RuntimeVersion.Current, PrintAppDomainDetails());
                startMsg = string.Format("{0} Config= " + Environment.NewLine + " {1}", startMsg, config);
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit");
                }

                config.CheckGatewayProviderSettings();

                var generation          = -SiloAddress.AllocateNewGeneration(); // Client generations are negative
                var gatewayListProvider = GatewayProviderFactory.CreateGatewayListProvider(config)
                                          .WithTimeout(initTimeout).Result;
                transport = new ProxiedMessageCenter(config, localAddress, generation, clientId, gatewayListProvider);

                if (StatisticsCollector.CollectThreadTimeTrackingStats)
                {
                    incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver");
                }
            }
            catch (Exception exc)
            {
                if (logger != null)
                {
                    logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc);
                }
                ConstructorReset();
                throw;
            }
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Silo"/> class.
 /// </summary>
 /// <param name="name">Name of this silo.</param>
 /// <param name="siloType">Type of this silo.</param>
 /// <param name="config">Silo config data to be used for this silo.</param>
 public Silo(string name, SiloType siloType, ClusterConfiguration config)
     : this(new SiloInitializationParameters(name, siloType, config), null)
 {
 }
Beispiel #13
0
 public ElasticsearchCluster(ClusterConfiguration clusterConfiguration) : base(clusterConfiguration)
 {
 }
Beispiel #14
0
        internal Silo(string name, SiloType siloType, ClusterConfiguration config, ILocalDataStore keyStore)
        {
            SystemStatus.Current = SystemStatus.Creating;

            CurrentSilo = this;

            var startTime = DateTime.UtcNow;

            this.siloType = siloType;
            Name          = name;

            siloTerminatedEvent = new ManualResetEvent(false);

            OrleansConfig = config;
            globalConfig  = config.Globals;
            config.OnConfigChange("Defaults", () => nodeConfig = config.GetOrCreateNodeConfigurationForSilo(name));

            if (!LogManager.IsInitialized)
            {
                LogManager.Initialize(nodeConfig);
            }

            config.OnConfigChange("Defaults/Tracing", () => LogManager.Initialize(nodeConfig, true), false);
            MultiClusterRegistrationStrategy.Initialize(config.Globals);
            ActivationData.Init(config, nodeConfig);
            StatisticsCollector.Initialize(nodeConfig);

            SerializationManager.Initialize(globalConfig.SerializationProviders, this.globalConfig.FallbackSerializationProvider);
            initTimeout = globalConfig.MaxJoinAttemptTime;
            if (Debugger.IsAttached)
            {
                initTimeout = StandardExtensions.Max(TimeSpan.FromMinutes(10), globalConfig.MaxJoinAttemptTime);
                stopTimeout = initTimeout;
            }

            IPEndPoint here       = nodeConfig.Endpoint;
            int        generation = nodeConfig.Generation;

            if (generation == 0)
            {
                generation            = SiloAddress.AllocateNewGeneration();
                nodeConfig.Generation = generation;
            }
            LogManager.MyIPEndPoint = here;
            logger = LogManager.GetLogger("Silo", LoggerType.Runtime);

            logger.Info(ErrorCode.SiloGcSetting, "Silo starting with GC settings: ServerGC={0} GCLatencyMode={1}", GCSettings.IsServerGC, Enum.GetName(typeof(GCLatencyMode), GCSettings.LatencyMode));
            if (!GCSettings.IsServerGC || !GCSettings.LatencyMode.Equals(GCLatencyMode.Batch))
            {
                logger.Warn(ErrorCode.SiloGcWarning, "Note: Silo not running with ServerGC turned on or with GCLatencyMode.Batch enabled - recommend checking app config : <configuration>-<runtime>-<gcServer enabled=\"true\"> and <configuration>-<runtime>-<gcConcurrent enabled=\"false\"/>");
                logger.Warn(ErrorCode.SiloGcWarning, "Note: ServerGC only kicks in on multi-core systems (settings enabling ServerGC have no effect on single-core machines).");
            }

            logger.Info(ErrorCode.SiloInitializing, "-------------- Initializing {0} silo on host {1} MachineName {2} at {3}, gen {4} --------------",
                        siloType, nodeConfig.DNSHostName, Environment.MachineName, here, generation);
            logger.Info(ErrorCode.SiloInitConfig, "Starting silo {0} with the following configuration= " + Environment.NewLine + "{1}",
                        name, config.ToString(name));

            if (keyStore != null)
            {
                // Re-establish reference to shared local key store in this app domain
                LocalDataStoreInstance.LocalDataStore = keyStore;
            }

            // Configure DI using Startup type
            bool usingCustomServiceProvider;

            Services = StartupBuilder.ConfigureStartup(nodeConfig.StartupTypeName, out usingCustomServiceProvider);

            healthCheckParticipants = new List <IHealthCheckParticipant>();
            allSiloProviders        = new List <IProvider>();

            BufferPool.InitGlobalBufferPool(globalConfig);
            PlacementStrategy.Initialize(globalConfig);

            UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnobservedExceptionHandler);
            AppDomain.CurrentDomain.UnhandledException +=
                (obj, ev) => DomainUnobservedExceptionHandler(obj, (Exception)ev.ExceptionObject);

            try
            {
                grainFactory = Services.GetRequiredService <GrainFactory>();
            }
            catch (InvalidOperationException exc)
            {
                logger.Error(ErrorCode.SiloStartError, "Exception during Silo.Start, GrainFactory was not registered in Dependency Injection container", exc);
                throw;
            }

            typeManager = new GrainTypeManager(
                here.Address.Equals(IPAddress.Loopback),
                grainFactory,
                new SiloAssemblyLoader(OrleansConfig.Defaults.AdditionalAssemblyDirectories));

            // Performance metrics
            siloStatistics = new SiloStatisticsManager(globalConfig, nodeConfig);
            config.OnConfigChange("Defaults/LoadShedding", () => siloStatistics.MetricsTable.NodeConfig = nodeConfig, false);

            // The scheduler
            scheduler = new OrleansTaskScheduler(globalConfig, nodeConfig);
            healthCheckParticipants.Add(scheduler);

            // Initialize the message center
            var mc = new MessageCenter(here, generation, globalConfig, siloStatistics.MetricsTable);

            if (nodeConfig.IsGatewayNode)
            {
                mc.InstallGateway(nodeConfig.ProxyGatewayEndpoint);
            }

            messageCenter = mc;

            SiloIdentity = SiloAddress.ToLongString();

            // GrainRuntime can be created only here, after messageCenter was created.
            grainRuntime = new GrainRuntime(
                globalConfig.ServiceId,
                SiloIdentity,
                grainFactory,
                new TimerRegistry(),
                new ReminderRegistry(),
                new StreamProviderManager(),
                Services);


            // Now the router/directory service
            // This has to come after the message center //; note that it then gets injected back into the message center.;
            localGrainDirectory = new LocalGrainDirectory(this);

            RegistrarManager.InitializeGrainDirectoryManager(localGrainDirectory, globalConfig.GlobalSingleInstanceNumberRetries);

            // Now the activation directory.
            // This needs to know which router to use so that it can keep the global directory in synch with the local one.
            activationDirectory = new ActivationDirectory();

            // Now the consistent ring provider
            RingProvider = GlobalConfig.UseVirtualBucketsConsistentRing ?
                           (IConsistentRingProvider) new VirtualBucketsRingProvider(SiloAddress, GlobalConfig.NumVirtualBucketsConsistentRing)
                : new ConsistentRingProvider(SiloAddress);

            // to preserve backwards compatibility, only use the service provider to inject grain dependencies if the user supplied his own
            // service provider, meaning that he is explicitly opting into it.
            var grainCreator = new GrainCreator(grainRuntime, usingCustomServiceProvider ? Services : null);

            Action <Dispatcher> setDispatcher;

            catalog = new Catalog(Constants.CatalogId, SiloAddress, Name, LocalGrainDirectory, typeManager, scheduler, activationDirectory, config, grainCreator, out setDispatcher);
            var dispatcher = new Dispatcher(scheduler, messageCenter, catalog, config);

            setDispatcher(dispatcher);

            RuntimeClient.Current = new InsideRuntimeClient(
                dispatcher,
                catalog,
                LocalGrainDirectory,
                SiloAddress,
                config,
                RingProvider,
                typeManager,
                grainFactory);
            messageCenter.RerouteHandler       = InsideRuntimeClient.Current.RerouteMessage;
            messageCenter.SniffIncomingMessage = InsideRuntimeClient.Current.SniffIncomingMessage;

            siloStatistics.MetricsTable.Scheduler           = scheduler;
            siloStatistics.MetricsTable.ActivationDirectory = activationDirectory;
            siloStatistics.MetricsTable.ActivationCollector = catalog.ActivationCollector;
            siloStatistics.MetricsTable.MessageCenter       = messageCenter;

            DeploymentLoadPublisher.CreateDeploymentLoadPublisher(this, globalConfig);
            PlacementDirectorsManager.CreatePlacementDirectorsManager(globalConfig);

            // Now the incoming message agents
            incomingSystemAgent = new IncomingMessageAgent(Message.Categories.System, messageCenter, activationDirectory, scheduler, dispatcher);
            incomingPingAgent   = new IncomingMessageAgent(Message.Categories.Ping, messageCenter, activationDirectory, scheduler, dispatcher);
            incomingAgent       = new IncomingMessageAgent(Message.Categories.Application, messageCenter, activationDirectory, scheduler, dispatcher);

            membershipFactory   = new MembershipFactory();
            multiClusterFactory = new MultiClusterOracleFactory();
            reminderFactory     = new LocalReminderServiceFactory();

            SystemStatus.Current = SystemStatus.Created;

            StringValueStatistic.FindOrCreate(StatisticNames.SILO_START_TIME,
                                              () => LogFormatter.PrintDate(startTime)); // this will help troubleshoot production deployment when looking at MDS logs.

            logger.Info(ErrorCode.SiloInitializingFinished, "-------------- Started silo {0}, ConsistentHashCode {1:X} --------------", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode());
        }
Beispiel #15
0
        /// <summary>
        /// Create stream queue balancer by type requested
        /// </summary>
        /// <param name="balancerType">queue balancer type to create</param>
        /// <param name="strProviderName">name of requesting stream provider</param>
        /// <param name="siloStatusOracle">membership services interface.</param>
        /// <param name="clusterConfiguration">cluster configuration</param>
        /// <param name="runtime">stream provider runtime environment to run in</param>
        /// <param name="queueMapper">queue mapper of requesting stream provider</param>
        /// <param name="siloMaturityPeriod">Maturity Period of a silo for queue rebalancing purposes</param>
        /// <returns>Constructed stream queue balancer</returns>
        public static IStreamQueueBalancer Create(
            StreamQueueBalancerType balancerType,
            string strProviderName,
            ISiloStatusOracle siloStatusOracle,
            ClusterConfiguration clusterConfiguration,
            IStreamProviderRuntime runtime,
            IStreamQueueMapper queueMapper,
            TimeSpan siloMaturityPeriod)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (siloStatusOracle == null)
            {
                throw new ArgumentNullException("siloStatusOracle");
            }
            if (clusterConfiguration == null)
            {
                throw new ArgumentNullException("clusterConfiguration");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }
            if (queueMapper == null)
            {
                throw new ArgumentNullException("queueMapper");
            }
            bool isFixed;

            switch (balancerType)
            {
            case StreamQueueBalancerType.ConsistentRingBalancer:
            {
                // Consider: for now re-use the same ConsistentRingProvider with 1 equally devided range. Remove later.
                IConsistentRingProviderForGrains ringProvider = runtime.GetConsistentRingProvider(0, 1);
                return(new ConsistentRingQueueBalancer(ringProvider, queueMapper));
            }

            case StreamQueueBalancerType.DynamicAzureDeploymentBalancer:
            case StreamQueueBalancerType.StaticAzureDeploymentBalancer:
            {
                Logger logger  = LogManager.GetLogger(typeof(StreamQueueBalancerFactory).Name, LoggerType.Runtime);
                var    wrapper = AssemblyLoader.LoadAndCreateInstance <IDeploymentConfiguration>(Constants.ORLEANS_AZURE_UTILS_DLL, logger, runtime.ServiceProvider);
                isFixed = balancerType == StreamQueueBalancerType.StaticAzureDeploymentBalancer;
                return(new DeploymentBasedQueueBalancer(siloStatusOracle, wrapper, queueMapper, siloMaturityPeriod, isFixed));
            }

            case StreamQueueBalancerType.DynamicClusterConfigDeploymentBalancer:
            case StreamQueueBalancerType.StaticClusterConfigDeploymentBalancer:
            {
                IDeploymentConfiguration deploymentConfiguration = new StaticClusterDeploymentConfiguration(clusterConfiguration);
                isFixed = balancerType == StreamQueueBalancerType.StaticClusterConfigDeploymentBalancer;
                return(new DeploymentBasedQueueBalancer(siloStatusOracle, deploymentConfiguration, queueMapper, siloMaturityPeriod, isFixed));
            }

            default:
            {
                string error = string.Format("Unsupported balancerType for stream provider. BalancerType: {0}, StreamProvider: {1}", balancerType, strProviderName);
                throw new ArgumentOutOfRangeException("balancerType", error);
            }
            }
        }
Beispiel #16
0
 /// <summary>
 /// Configures a localhost silo.
 /// </summary>
 /// <param name="builder">The silo builder.</param>
 /// <param name="siloPort">The silo-to-silo communication port.</param>
 /// <param name="gatewayPort">The client-to-silo communication port.</param>
 /// <returns>The silo builder.</returns>
 public static ISiloBuilder ConfigureLocalHostPrimarySilo(this ISiloBuilder builder, int siloPort = 22222, int gatewayPort = 40000)
 {
     builder.ConfigureSiloName(Silo.PrimarySiloName);
     return(builder.UseConfiguration(ClusterConfiguration.LocalhostPrimarySilo(siloPort, gatewayPort)));
 }
Beispiel #17
0
 /// <summary>
 /// Specifies the configuration to use for this silo.
 /// </summary>
 /// <param name="builder">The silo builder.</param>
 /// <param name="configuration">The configuration.</param>
 /// <remarks>This method may only be called once per builder instance.</remarks>
 /// <returns>The silo builder.</returns>
 public static ISiloBuilder UseConfiguration(this ISiloBuilder builder, ClusterConfiguration configuration)
 {
     return(builder.ConfigureServices(services => services.AddSingleton(configuration)));
 }
Beispiel #18
0
        public static IServiceCollection AddLegacyClusterConfigurationSupport(this IServiceCollection services, ClusterConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (services.Any(service => service.ServiceType == typeof(ClusterConfiguration)))
            {
                throw new InvalidOperationException("Cannot configure legacy ClusterConfiguration support twice");
            }

            // these will eventually be removed once our code doesn't depend on the old ClientConfiguration
            services.AddSingleton(configuration);
            services.TryAddSingleton <SiloInitializationParameters>();
            services.TryAddFromExisting <ILocalSiloDetails, SiloInitializationParameters>();
            services.TryAddSingleton(sp => sp.GetRequiredService <SiloInitializationParameters>().ClusterConfig);
            services.TryAddSingleton(sp => sp.GetRequiredService <SiloInitializationParameters>().ClusterConfig.Globals);
            services.TryAddTransient(sp => sp.GetRequiredService <SiloInitializationParameters>().NodeConfig);
            services.TryAddSingleton <Factory <NodeConfiguration> >(
                sp =>
            {
                var initializationParams = sp.GetRequiredService <SiloInitializationParameters>();
                return(() => initializationParams.NodeConfig);
            });
            services.TryAddFromExisting <IMessagingConfiguration, GlobalConfiguration>();

            // Translate legacy configuration to new Options
            services.Configure <SiloMessagingOptions>(options =>
            {
                LegacyConfigurationExtensions.CopyCommonMessagingOptions(configuration.Globals, options);

                options.SiloSenderQueues    = configuration.Globals.SiloSenderQueues;
                options.GatewaySenderQueues = configuration.Globals.GatewaySenderQueues;
                options.MaxForwardCount     = configuration.Globals.MaxForwardCount;
                options.ClientDropTimeout   = configuration.Globals.ClientDropTimeout;
            });

            services.Configure <SerializationProviderOptions>(options =>
            {
                options.SerializationProviders        = configuration.Globals.SerializationProviders;
                options.FallbackSerializationProvider = configuration.Globals.FallbackSerializationProvider;
            });

            services.Configure <IOptions <SiloIdentityOptions>, GrainClassOptions>((identityOptions, options) =>
            {
                var nodeConfig = configuration.GetOrCreateNodeConfigurationForSilo(identityOptions.Value.SiloName);
                options.ExcludedGrainTypes.AddRange(nodeConfig.ExcludedGrainTypes);
            });

            LegacyMembershipConfigurator.ConfigureServices(configuration.Globals, services);
            return(services);
        }
Beispiel #19
0
 private SiloHandle LoadSiloInNewAppDomain(string siloName, Silo.SiloType type, ClusterConfiguration config, NodeConfiguration nodeConfiguration)
 {
     return(AppDomainSiloHandle.Create(siloName, type, config, nodeConfiguration, this.additionalAssemblies));
 }
Beispiel #20
0
        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;

            if (nodeConfig.ProxyGatewayEndpoint != null && nodeConfig.ProxyGatewayEndpoint.Address != null)
            {
                int proxyBasePort = options.ProxyBasePort < 0 ? ProxyBasePort : options.ProxyBasePort;
                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 = host.LoadSiloInNewAppDomain(siloName, type, config, out appDomain);

            silo.Start();

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

            host.ImportGeneratedAssemblies(retValue);
            return(retValue);
        }
Beispiel #21
0
        internal Silo(SiloInitializationParameters initializationParams, IServiceProvider services)
        {
            string name = initializationParams.Name;
            ClusterConfiguration config = initializationParams.ClusterConfig;

            this.initializationParams = initializationParams;

            this.SystemStatus      = SystemStatus.Creating;
            AsynchAgent.IsStarting = true;

            var startTime = DateTime.UtcNow;

            services?.GetService <TelemetryManager>()?.AddFromConfiguration(services, LocalConfig.TelemetryConfiguration);
            StatisticsCollector.Initialize(LocalConfig.StatisticsCollectionLevel);

            initTimeout = GlobalConfig.MaxJoinAttemptTime;
            if (Debugger.IsAttached)
            {
                initTimeout = StandardExtensions.Max(TimeSpan.FromMinutes(10), GlobalConfig.MaxJoinAttemptTime);
                stopTimeout = initTimeout;
            }

            var localEndpoint = this.initializationParams.SiloAddress.Endpoint;

            // Configure DI using Startup type
            if (services == null)
            {
                var serviceCollection = new ServiceCollection();
                serviceCollection.AddSingleton <Silo>(this);
                serviceCollection.AddSingleton(initializationParams);
                serviceCollection.AddLegacyClusterConfigurationSupport(config);
                serviceCollection.Configure <SiloIdentityOptions>(options => options.SiloName = name);
                var hostContext = new HostBuilderContext(new Dictionary <object, object>());
                DefaultSiloServices.AddDefaultServices(hostContext, serviceCollection);

                var applicationPartManager = hostContext.GetApplicationPartManager();
                applicationPartManager.AddApplicationPartsFromAppDomain();
                applicationPartManager.AddApplicationPartsFromBasePath();

                services = StartupBuilder.ConfigureStartup(this.LocalConfig.StartupTypeName, serviceCollection);
                services.GetService <TelemetryManager>()?.AddFromConfiguration(services, LocalConfig.TelemetryConfiguration);
            }

            services.GetService <SerializationManager>().RegisterSerializers(services.GetService <ApplicationPartManager>());

            this.Services = services;
            this.Services.InitializeSiloUnobservedExceptionsHandler();
            //set PropagateActivityId flag from node cofnig
            RequestContext.PropagateActivityId = this.initializationParams.NodeConfig.PropagateActivityId;
            this.loggerFactory = this.Services.GetRequiredService <ILoggerFactory>();
            logger             = this.loggerFactory.CreateLogger <Silo>();

            logger.Info(ErrorCode.SiloGcSetting, "Silo starting with GC settings: ServerGC={0} GCLatencyMode={1}", GCSettings.IsServerGC, Enum.GetName(typeof(GCLatencyMode), GCSettings.LatencyMode));
            if (!GCSettings.IsServerGC)
            {
                logger.Warn(ErrorCode.SiloGcWarning, "Note: Silo not running with ServerGC turned on - recommend checking app config : <configuration>-<runtime>-<gcServer enabled=\"true\">");
                logger.Warn(ErrorCode.SiloGcWarning, "Note: ServerGC only kicks in on multi-core systems (settings enabling ServerGC have no effect on single-core machines).");
            }

            logger.Info(ErrorCode.SiloInitializing, "-------------- Initializing {0} silo on host {1} MachineName {2} at {3}, gen {4} --------------",
                        this.initializationParams.Type, LocalConfig.DNSHostName, Environment.MachineName, localEndpoint, this.initializationParams.SiloAddress.Generation);
            logger.Info(ErrorCode.SiloInitConfig, "Starting silo {0} with the following configuration= " + Environment.NewLine + "{1}",
                        name, config.ToString(name));

            var siloMessagingOptions = this.Services.GetRequiredService <IOptions <SiloMessagingOptions> >();

            BufferPool.InitGlobalBufferPool(siloMessagingOptions);

            try
            {
                grainFactory = Services.GetRequiredService <GrainFactory>();
            }
            catch (InvalidOperationException exc)
            {
                logger.Error(ErrorCode.SiloStartError, "Exception during Silo.Start, GrainFactory was not registered in Dependency Injection container", exc);
                throw;
            }

            // Performance metrics
            siloStatistics = Services.GetRequiredService <SiloStatisticsManager>();

            // The scheduler
            scheduler = Services.GetRequiredService <OrleansTaskScheduler>();
            healthCheckParticipants.Add(scheduler);

            runtimeClient = Services.GetRequiredService <InsideRuntimeClient>();

            // Initialize the message center
            messageCenter = Services.GetRequiredService <MessageCenter>();
            var dispatcher = this.Services.GetRequiredService <Dispatcher>();

            messageCenter.RerouteHandler       = dispatcher.RerouteMessage;
            messageCenter.SniffIncomingMessage = runtimeClient.SniffIncomingMessage;

            // GrainRuntime can be created only here, after messageCenter was created.
            grainRuntime          = Services.GetRequiredService <IGrainRuntime>();
            StreamProviderManager = Services.GetRequiredService <IStreamProviderManager>();

            // Now the router/directory service
            // This has to come after the message center //; note that it then gets injected back into the message center.;
            localGrainDirectory = Services.GetRequiredService <LocalGrainDirectory>();

            // Now the activation directory.
            activationDirectory = Services.GetRequiredService <ActivationDirectory>();

            // Now the consistent ring provider
            RingProvider = Services.GetRequiredService <IConsistentRingProvider>();

            catalog = Services.GetRequiredService <Catalog>();
            siloStatistics.MetricsTable.Scheduler           = scheduler;
            siloStatistics.MetricsTable.ActivationDirectory = activationDirectory;
            siloStatistics.MetricsTable.ActivationCollector = catalog.ActivationCollector;
            siloStatistics.MetricsTable.MessageCenter       = messageCenter;

            executorService = Services.GetRequiredService <ExecutorService>();

            // Now the incoming message agents
            var messageFactory = this.Services.GetRequiredService <MessageFactory>();

            incomingSystemAgent = new IncomingMessageAgent(Message.Categories.System, messageCenter, activationDirectory, scheduler, catalog.Dispatcher, messageFactory, executorService, this.loggerFactory);
            incomingPingAgent   = new IncomingMessageAgent(Message.Categories.Ping, messageCenter, activationDirectory, scheduler, catalog.Dispatcher, messageFactory, executorService, this.loggerFactory);
            incomingAgent       = new IncomingMessageAgent(Message.Categories.Application, messageCenter, activationDirectory, scheduler, catalog.Dispatcher, messageFactory, executorService, this.loggerFactory);

            membershipOracle = Services.GetRequiredService <IMembershipOracle>();

            if (!this.GlobalConfig.HasMultiClusterNetwork)
            {
                logger.Info("Skip multicluster oracle creation (no multicluster network configured)");
            }
            else
            {
                multiClusterOracle = Services.GetRequiredService <IMultiClusterOracle>();
            }

            this.SystemStatus      = SystemStatus.Created;
            AsynchAgent.IsStarting = false;

            StringValueStatistic.FindOrCreate(StatisticNames.SILO_START_TIME,
                                              () => LogFormatter.PrintDate(startTime)); // this will help troubleshoot production deployment when looking at MDS logs.

            var fullSiloLifecycle = this.Services.GetRequiredService <SiloLifecycle>();

            this.siloLifecycle = fullSiloLifecycle;
            IEnumerable <ILifecycleParticipant <ISiloLifecycle> > lifecyleParticipants = this.Services.GetServices <ILifecycleParticipant <ISiloLifecycle> >();

            foreach (ILifecycleParticipant <ISiloLifecycle> participant in lifecyleParticipants)
            {
                participant.Participate(fullSiloLifecycle);
            }
            this.Participate(fullSiloLifecycle);

            logger.Info(ErrorCode.SiloInitializingFinished, "-------------- Started silo {0}, ConsistentHashCode {1:X} --------------", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode());
        }
Beispiel #22
0
        /// <summary>
        /// Initialize this Orleans silo for execution with the specified Azure deploymentId
        /// </summary>
        /// <param name="config">If null, Config data will be read from silo config file as normal, otherwise use the specified config data.</param>
        /// <param name="deploymentId">Azure DeploymentId this silo is running under</param>
        /// <param name="connectionString">Azure DataConnectionString. If null, defaults to the DataConnectionString setting from the Azure configuration for this role.</param>
        /// <returns><c>true</c> is the silo startup was successful</returns>
        public bool Start(ClusterConfiguration config, string deploymentId = null, string connectionString = null)
        {
            // Program ident
            Trace.TraceInformation("Starting {0} v{1}", this.GetType().FullName, RuntimeVersion.Current);

            // Check if deployment id was specified
            if (deploymentId == null)
            {
                deploymentId = serviceRuntimeWrapper.DeploymentId;
            }

            // Read endpoint info for this instance from Azure config
            string instanceName = serviceRuntimeWrapper.InstanceName;

            // Configure this Orleans silo instance
            if (config == null)
            {
                host = new SiloHost(instanceName);
                host.LoadOrleansConfig(); // Load config from file + Initializes logger configurations
            }
            else
            {
                host = new SiloHost(instanceName, config); // Use supplied config data + Initializes logger configurations
            }

            IPEndPoint myEndpoint    = serviceRuntimeWrapper.GetIPEndpoint(SiloEndpointConfigurationKeyName);
            IPEndPoint proxyEndpoint = serviceRuntimeWrapper.GetIPEndpoint(ProxyEndpointConfigurationKeyName);

            host.SetSiloType(Silo.SiloType.Secondary);

            int generation = SiloAddress.AllocateNewGeneration();

            // Bootstrap this Orleans silo instance

            myEntry = new SiloInstanceTableEntry
            {
                DeploymentId = deploymentId,
                Address      = myEndpoint.Address.ToString(),
                Port         = myEndpoint.Port.ToString(CultureInfo.InvariantCulture),
                Generation   = generation.ToString(CultureInfo.InvariantCulture),

                HostName  = host.Config.GetOrCreateNodeConfigurationForSilo(host.Name).DNSHostName,
                ProxyPort = (proxyEndpoint != null ? proxyEndpoint.Port : 0).ToString(CultureInfo.InvariantCulture),

                RoleName     = serviceRuntimeWrapper.RoleName,
                InstanceName = instanceName,
                UpdateZone   = serviceRuntimeWrapper.UpdateDomain.ToString(CultureInfo.InvariantCulture),
                FaultZone    = serviceRuntimeWrapper.FaultDomain.ToString(CultureInfo.InvariantCulture),
                StartTime    = TraceLogger.PrintDate(DateTime.UtcNow),

                PartitionKey = deploymentId,
                RowKey       = myEndpoint.Address + "-" + myEndpoint.Port + "-" + generation
            };

            if (connectionString == null)
            {
                connectionString = serviceRuntimeWrapper.GetConfigurationSettingValue(DataConnectionConfigurationSettingName);
            }

            try
            {
                siloInstanceManager = OrleansSiloInstanceManager.GetManager(
                    deploymentId, connectionString).WithTimeout(AzureTableDefaultPolicies.TableCreationTimeout).Result;
            }
            catch (Exception exc)
            {
                var error = String.Format("Failed to create OrleansSiloInstanceManager. This means CreateTableIfNotExist for silo instance table has failed with {0}",
                                          TraceLogger.PrintException(exc));
                Trace.TraceError(error);
                logger.Error(ErrorCode.AzureTable_34, error, exc);
                throw new OrleansException(error, exc);
            }

            // Always use Azure table for membership when running silo in Azure
            host.SetSiloLivenessType(GlobalConfiguration.LivenessProviderType.AzureTable);
            if (host.Config.Globals.ReminderServiceType == GlobalConfiguration.ReminderServiceProviderType.NotSpecified ||
                host.Config.Globals.ReminderServiceType == GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain)
            {
                host.SetReminderServiceType(GlobalConfiguration.ReminderServiceProviderType.AzureTable);
            }
            host.SetExpectedClusterSize(serviceRuntimeWrapper.RoleInstanceCount);
            siloInstanceManager.RegisterSiloInstance(myEntry);

            // Initialise this Orleans silo instance
            host.SetDeploymentId(deploymentId, connectionString);
            host.SetSiloEndpoint(myEndpoint, generation);
            host.SetProxyEndpoint(proxyEndpoint);

            host.InitializeOrleansSilo();
            logger.Info(ErrorCode.Runtime_Error_100288, "Successfully initialized Orleans silo '{0}' as a {1} node.", host.Name, host.Type);
            return(StartSilo());
        }
        internal void ConsumeServices(IServiceProvider services)
        {
            this.ServiceProvider = services;

            var connectionLostHandlers = services.GetServices <ConnectionToClusterLostHandler>();

            foreach (var handler in connectionLostHandlers)
            {
                this.ClusterConnectionLost += handler;
            }

            var clientInvokeCallbacks = services.GetServices <ClientInvokeCallback>();

            foreach (var handler in clientInvokeCallbacks)
            {
                this.ClientInvokeCallback += handler;
            }

            this.InternalGrainFactory = this.ServiceProvider.GetRequiredService <IInternalGrainFactory>();
            this.ClientStatistics     = this.ServiceProvider.GetRequiredService <ClientStatisticsManager>();
            this.SerializationManager = this.ServiceProvider.GetRequiredService <SerializationManager>();
            this.messageFactory       = this.ServiceProvider.GetService <MessageFactory>();

            this.config = services.GetRequiredService <ClientConfiguration>();

            if (!LogManager.IsInitialized)
            {
                LogManager.Initialize(config);
            }
            StatisticsCollector.Initialize(config);
            this.assemblyProcessor = this.ServiceProvider.GetRequiredService <AssemblyProcessor>();
            this.assemblyProcessor.Initialize();

            logger         = LogManager.GetLogger("OutsideRuntimeClient", LoggerType.Runtime);
            this.AppLogger = LogManager.GetLogger("Application", LoggerType.Application);

            BufferPool.InitGlobalBufferPool(config);


            try
            {
                LoadAdditionalAssemblies();

                if (!UnobservedExceptionsHandlerClass.TrySetUnobservedExceptionHandler(UnhandledException))
                {
                    logger.Warn(ErrorCode.Runtime_Error_100153, "Unable to set unobserved exception handler because it was already set.");
                }

                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

                clientProviderRuntime     = this.ServiceProvider.GetRequiredService <ClientProviderRuntime>();
                statisticsProviderManager = new StatisticsProviderManager("Statistics", clientProviderRuntime);
                var statsProviderName = statisticsProviderManager.LoadProvider(config.ProviderConfigurations)
                                        .WaitForResultWithThrow(initTimeout);
                if (statsProviderName != null)
                {
                    config.StatisticsProviderName = statsProviderName;
                }

                responseTimeout   = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout;
                this.localAddress = ClusterConfiguration.GetLocalIPAddress(config.PreferredFamily, config.NetInterface);

                // Client init / sign-on message
                logger.Info(ErrorCode.ClientInitializing, string.Format(
                                "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}",
                                BARS, config.DNSHostName, localAddress, handshakeClientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}",
                                                BARS, RuntimeVersion.Current, PrintAppDomainDetails());
                startMsg = string.Format("{0} Config= " + Environment.NewLine + " {1}", startMsg, config);
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit");
                }

                config.CheckGatewayProviderSettings();

                if (StatisticsCollector.CollectThreadTimeTrackingStats)
                {
                    incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver");
                }
            }
            catch (Exception exc)
            {
                if (logger != null)
                {
                    logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc);
                }
                ConstructorReset();
                throw;
            }
        }
 public EmbeddedConfigurator From(ClusterConfiguration config)
 {
     cluster.From(config);
     return(this);
 }
        /// <summary>Creates a new silo in a remote app domain and returns a handle to it.</summary>
        public static SiloHandle Create(string siloName, Silo.SiloType type, Type siloBuilderFactory, ClusterConfiguration config, NodeConfiguration nodeConfiguration, IDictionary <string, GeneratedAssembly> additionalAssemblies, string applicationBase = null)
        {
            AppDomainSetup setup = GetAppDomainSetupInfo(applicationBase);

            var appDomain = AppDomain.CreateDomain(siloName, null, setup);

            try
            {
                // Load each of the additional assemblies.
                AppDomainSiloHost.CodeGeneratorOptimizer optimizer = null;
                foreach (var assembly in additionalAssemblies.Where(asm => asm.Value != null))
                {
                    if (optimizer == null)
                    {
                        optimizer =
                            (AppDomainSiloHost.CodeGeneratorOptimizer)
                            appDomain.CreateInstanceAndUnwrap(
                                typeof(AppDomainSiloHost.CodeGeneratorOptimizer).Assembly.FullName, typeof(AppDomainSiloHost.CodeGeneratorOptimizer).FullName, false,
                                BindingFlags.Default,
                                null,
                                null,
                                CultureInfo.CurrentCulture,
                                new object[] { });
                    }

                    optimizer.AddCachedAssembly(assembly.Key, assembly.Value);
                }

                var args = new object[] { siloName, siloBuilderFactory, config };

                var siloHost = (AppDomainSiloHost)appDomain.CreateInstanceAndUnwrap(
                    typeof(AppDomainSiloHost).Assembly.FullName, typeof(AppDomainSiloHost).FullName, false,
                    BindingFlags.Default, null, args, CultureInfo.CurrentCulture,
                    new object[] { });

                appDomain.UnhandledException += ReportUnobservedException;

                siloHost.Start();

                var retValue = new AppDomainSiloHandle
                {
                    Name                 = siloName,
                    SiloHost             = siloHost,
                    NodeConfiguration    = nodeConfiguration,
                    SiloAddress          = siloHost.SiloAddress,
                    Type                 = type,
                    AppDomain            = appDomain,
                    additionalAssemblies = additionalAssemblies,
                    AppDomainTestHook    = siloHost.AppDomainTestHook,
                };

                retValue.ImportGeneratedAssemblies();

                return(retValue);
            }
            catch (Exception)
            {
                UnloadAppDomain(appDomain);
                throw;
            }
        }
Beispiel #26
0
        internal Silo(string name, SiloType siloType, ClusterConfiguration config, ILocalDataStore keyStore)
        {
            SystemStatus.Current = SystemStatus.Creating;

            CurrentSilo = this;

            var startTime = DateTime.UtcNow;

            this.siloType = siloType;
            Name          = name;

            siloTerminatedEvent = new ManualResetEvent(false);

            OrleansConfig = config;
            globalConfig  = config.Globals;
            config.OnConfigChange("Defaults", () => nodeConfig = config.GetConfigurationForNode(name));

            if (!TraceLogger.IsInitialized)
            {
                TraceLogger.Initialize(nodeConfig);
            }

            config.OnConfigChange("Defaults/Tracing", () => TraceLogger.Initialize(nodeConfig, true), false);

            LimitManager.Initialize(nodeConfig);
            ActivationData.Init(config);
            StatisticsCollector.Initialize(nodeConfig);
            SerializationManager.Initialize(globalConfig.UseStandardSerializer);
            initTimeout = globalConfig.MaxJoinAttemptTime;
            if (Debugger.IsAttached)
            {
                initTimeout = StandardExtensions.Max(TimeSpan.FromMinutes(10), globalConfig.MaxJoinAttemptTime);
                stopTimeout = initTimeout;
            }

            IPEndPoint here       = nodeConfig.Endpoint;
            int        generation = nodeConfig.Generation;

            if (generation == 0)
            {
                generation            = SiloAddress.AllocateNewGeneration();
                nodeConfig.Generation = generation;
            }
            TraceLogger.MyIPEndPoint = here;
            logger = TraceLogger.GetLogger("Silo", TraceLogger.LoggerType.Runtime);
            logger.Info(ErrorCode.SiloInitializing, "-------------- Initializing {0} silo on {1} at {2}, gen {3} --------------", siloType, nodeConfig.DNSHostName, here, generation);
            logger.Info(ErrorCode.SiloInitConfig, "Starting silo {0} with runtime Version='{1}' Config= " + Environment.NewLine + "{2}", name, RuntimeVersion.Current, config.ToString(name));

            if (keyStore != null)
            {
                // Re-establish reference to shared local key store in this app domain
                LocalDataStoreInstance.LocalDataStore = keyStore;
            }
            healthCheckParticipants = new List <IHealthCheckParticipant>();

            BufferPool.InitGlobalBufferPool(globalConfig);
            PlacementStrategy.Initialize(globalConfig);

            UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnobservedExceptionHandler);
            AppDomain.CurrentDomain.UnhandledException +=
                (obj, ev) => DomainUnobservedExceptionHandler(obj, (Exception)ev.ExceptionObject);

            grainFactory = new GrainFactory();
            typeManager  = new GrainTypeManager(here.Address.Equals(IPAddress.Loopback), grainFactory);

            // Performance metrics
            siloStatistics = new SiloStatisticsManager(globalConfig, nodeConfig);
            config.OnConfigChange("Defaults/LoadShedding", () => siloStatistics.MetricsTable.NodeConfig = nodeConfig, false);

            // The scheduler
            scheduler = new OrleansTaskScheduler(globalConfig, nodeConfig);
            healthCheckParticipants.Add(scheduler);

            // Initialize the message center
            var mc = new MessageCenter(here, generation, globalConfig, siloStatistics.MetricsTable);

            if (nodeConfig.IsGatewayNode)
            {
                mc.InstallGateway(nodeConfig.ProxyGatewayEndpoint);
            }

            messageCenter = mc;

            // GrainRuntime can be created only here, after messageCenter was created.
            grainRuntime = new GrainRuntime(SiloAddress.ToLongString(), grainFactory,
                                            new TimerRegistry(),
                                            new ReminderRegistry(),
                                            new StreamProviderManager());


            // Now the router/directory service
            // This has to come after the message center //; note that it then gets injected back into the message center.;
            localGrainDirectory = new LocalGrainDirectory(this);

            // Now the activation directory.
            // This needs to know which router to use so that it can keep the global directory in synch with the local one.
            activationDirectory = new ActivationDirectory();

            // Now the consistent ring provider
            RingProvider = GlobalConfig.UseVirtualBucketsConsistentRing ?
                           (IConsistentRingProvider) new VirtualBucketsRingProvider(SiloAddress, GlobalConfig.NumVirtualBucketsConsistentRing)
                : new ConsistentRingProvider(SiloAddress);

            Action <Dispatcher> setDispatcher;

            catalog = new Catalog(Constants.CatalogId, SiloAddress, Name, LocalGrainDirectory, typeManager, scheduler, activationDirectory, config, grainRuntime, out setDispatcher);
            var dispatcher = new Dispatcher(scheduler, messageCenter, catalog, config);

            setDispatcher(dispatcher);

            RuntimeClient.Current = new InsideRuntimeClient(
                dispatcher,
                catalog,
                LocalGrainDirectory,
                SiloAddress,
                config,
                RingProvider,
                typeManager,
                grainFactory);
            messageCenter.RerouteHandler       = InsideRuntimeClient.Current.RerouteMessage;
            messageCenter.SniffIncomingMessage = InsideRuntimeClient.Current.SniffIncomingMessage;

            siloStatistics.MetricsTable.Scheduler           = scheduler;
            siloStatistics.MetricsTable.ActivationDirectory = activationDirectory;
            siloStatistics.MetricsTable.ActivationCollector = catalog.ActivationCollector;
            siloStatistics.MetricsTable.MessageCenter       = messageCenter;

            DeploymentLoadPublisher.CreateDeploymentLoadPublisher(this, globalConfig);
            PlacementDirectorsManager.CreatePlacementDirectorsManager(globalConfig);

            // Now the incoming message agents
            incomingSystemAgent = new IncomingMessageAgent(Message.Categories.System, messageCenter, activationDirectory, scheduler, dispatcher);
            incomingPingAgent   = new IncomingMessageAgent(Message.Categories.Ping, messageCenter, activationDirectory, scheduler, dispatcher);
            incomingAgent       = new IncomingMessageAgent(Message.Categories.Application, messageCenter, activationDirectory, scheduler, dispatcher);

            membershipFactory = new MembershipFactory();
            reminderFactory   = new LocalReminderServiceFactory();

            SystemStatus.Current = SystemStatus.Created;

            StringValueStatistic.FindOrCreate(StatisticNames.SILO_START_TIME,
                                              () => TraceLogger.PrintDate(startTime)); // this will help troubleshoot production deployment when looking at MDS logs.

            TestHookup = new TestHookups(this);

            logger.Info(ErrorCode.SiloInitializingFinished, "-------------- Started silo {0}, ConsistentHashCode {1:X} --------------", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode());
        }
Beispiel #27
0
 /// <summary>
 /// Configures the test cluster plus default client in-process.
 /// </summary>
 public TestCluster(ClusterConfiguration clusterConfiguration)
     : this(clusterConfiguration, TestClusterOptions.BuildClientConfiguration(clusterConfiguration))
 {
 }
Beispiel #28
0
 /// <summary> Constructor </summary>
 /// <param name="siloName">Name of this silo.</param>
 /// <param name="config">Silo config that will be used to initialize this silo.</param>
 public SiloHost(string siloName, ClusterConfiguration config) : this(siloName)
 {
     SetSiloConfig(config);
 }
 /// <summary>
 /// Creates a <see cref="ServiceInstanceListener"/> which manages an Orleans silo for a stateless service.
 /// </summary>
 /// <param name="configuration">The Orleans cluster configuration.</param>
 /// <returns>A <see cref="ServiceInstanceListener"/> which manages an Orleans silo.</returns>
 public static ServiceInstanceListener CreateStateless(ClusterConfiguration configuration)
 {
     return new ServiceInstanceListener(context => new OrleansCommunicationListener(context, configuration), OrleansServiceFabricEndpointName);
 }
        /// <summary>
        /// Starts the silo.
        /// </summary>
        /// <param name="config">
        /// The config.
        /// </param>
        /// <returns>
        /// Whether or not initialization was successful.
        /// </returns>
        /// <exception cref="OrleansException">
        /// An exception occurred starting the silo.
        /// </exception>
        public bool Start(ClusterConfiguration config)
        {
            try
            {
                Trace.TraceInformation(
                    $"Starting silo. Name: {this.siloName}, DeploymentId: {this.deploymentId}, Primary Endpoint: {this.SiloEndpoint}");

                // Configure this Orleans silo instance
                if (config == null)
                {
                    Trace.TraceInformation("Loading configuration from default locations.");
                    this.host = new SiloHost(this.siloName);
                    this.host.LoadOrleansConfig();
                }
                else
                {
                    Trace.TraceInformation("Using provided configuration.");
                    this.host = new SiloHost(this.siloName, config);
                }

                // Configure the silo for the current environment.
                var generation = SiloAddress.AllocateNewGeneration();
                this.host.SetSiloType(Silo.SiloType.Secondary);
                this.host.SetSiloLivenessType(config?.Globals.LivenessType??GlobalConfiguration.LivenessProviderType.AzureTable);
                this.host.SetReminderServiceType(config?.Globals.ReminderServiceType ?? GlobalConfiguration.ReminderServiceProviderType.AzureTable);
                this.host.SetDeploymentId(this.deploymentId, this.connectionString);
                this.host.SetSiloEndpoint(this.SiloEndpoint, generation);
                this.host.SetProxyEndpoint(this.ProxyEndpoint);

                this.host.InitializeOrleansSilo();
                Trace.TraceInformation($"Successfully initialized Orleans silo '{this.siloName}'.");
                Trace.TraceInformation($"Starting Orleans silo '{this.siloName}'.");

                var ok = this.host.StartOrleansSilo();
                if (ok)
                {
                    Trace.TraceInformation(
                        $"Successfully started Orleans silo '{this.siloName}'.");
                }
                else
                {
                    Trace.TraceInformation($"Failed to start Orleans silo '{this.siloName}'");
                }

                this.MonitorSilo();
                return ok;
            }
            catch (Exception e)
            {
                this.stopped.TrySetException(e);
                this.Abort();

                throw;
            }
        }
Beispiel #31
0
        /// <summary>
        /// Initialize this Orleans silo for execution with the specified Azure clusterId
        /// </summary>
        /// <param name="config">If null, Config data will be read from silo config file as normal, otherwise use the specified config data.</param>
        /// <param name="clusterId">Azure ClusterId this silo is running under</param>
        /// <param name="connectionString">Azure DataConnectionString. If null, defaults to the DataConnectionString setting from the Azure configuration for this role.</param>
        /// <returns><c>true</c> if the silo startup was successful</returns>
        internal bool Start(ClusterConfiguration config, string clusterId, string connectionString)
        {
            if (config != null && clusterId != null)
            {
                throw new ArgumentException("Cannot use config and clusterId on the same time");
            }

            // Program ident
            Trace.TraceInformation("Starting {0} v{1}", this.GetType().FullName, RuntimeVersion.Current);

            // Read endpoint info for this instance from Azure config
            string instanceName = serviceRuntimeWrapper.InstanceName;

            // Configure this Orleans silo instance
            if (config == null)
            {
                host = new SiloHost(instanceName);
                host.LoadOrleansConfig(); // Load config from file + Initializes logger configurations
            }
            else
            {
                host = new SiloHost(instanceName, config); // Use supplied config data + Initializes logger configurations
            }

            IPEndPoint myEndpoint    = serviceRuntimeWrapper.GetIPEndpoint(SiloEndpointConfigurationKeyName);
            IPEndPoint proxyEndpoint = serviceRuntimeWrapper.GetIPEndpoint(ProxyEndpointConfigurationKeyName);

            host.SetSiloType(Silo.SiloType.Secondary);

            int generation = SiloAddress.AllocateNewGeneration();

            // Bootstrap this Orleans silo instance

            // If clusterId was not direclty provided, take the value in the config. If it is not
            // in the config too, just take the ClusterId from Azure
            if (clusterId == null)
            {
                clusterId = string.IsNullOrWhiteSpace(host.Config.Globals.ClusterId)
                    ? serviceRuntimeWrapper.DeploymentId
                    : host.Config.Globals.ClusterId;
            }

            myEntry = new SiloInstanceTableEntry
            {
                DeploymentId = clusterId,
                Address      = myEndpoint.Address.ToString(),
                Port         = myEndpoint.Port.ToString(CultureInfo.InvariantCulture),
                Generation   = generation.ToString(CultureInfo.InvariantCulture),

                HostName  = host.Config.GetOrCreateNodeConfigurationForSilo(host.Name).DNSHostName,
                ProxyPort = (proxyEndpoint != null ? proxyEndpoint.Port : 0).ToString(CultureInfo.InvariantCulture),

                RoleName   = serviceRuntimeWrapper.RoleName,
                SiloName   = instanceName,
                UpdateZone = serviceRuntimeWrapper.UpdateDomain.ToString(CultureInfo.InvariantCulture),
                FaultZone  = serviceRuntimeWrapper.FaultDomain.ToString(CultureInfo.InvariantCulture),
                StartTime  = LogFormatter.PrintDate(DateTime.UtcNow),

                PartitionKey = clusterId,
                RowKey       = myEndpoint.Address + "-" + myEndpoint.Port + "-" + generation
            };

            if (connectionString == null)
            {
                connectionString = serviceRuntimeWrapper.GetConfigurationSettingValue(DataConnectionConfigurationSettingName);
            }

            try
            {
                siloInstanceManager = OrleansSiloInstanceManager.GetManager(
                    clusterId, connectionString, this.loggerFactory).WithTimeout(AzureTableDefaultPolicies.TableCreationTimeout).Result;
            }
            catch (Exception exc)
            {
                var error = String.Format("Failed to create OrleansSiloInstanceManager. This means CreateTableIfNotExist for silo instance table has failed with {0}",
                                          LogFormatter.PrintException(exc));
                Trace.TraceError(error);
                logger.Error((int)AzureSiloErrorCode.AzureTable_34, error, exc);
                throw new OrleansException(error, exc);
            }

            // Always use Azure table for membership when running silo in Azure
            host.SetSiloLivenessType(GlobalConfiguration.LivenessProviderType.AzureTable);
            if (host.Config.Globals.ReminderServiceType == GlobalConfiguration.ReminderServiceProviderType.NotSpecified ||
                host.Config.Globals.ReminderServiceType == GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain)
            {
                host.SetReminderServiceType(GlobalConfiguration.ReminderServiceProviderType.AzureTable);
            }
            host.SetExpectedClusterSize(serviceRuntimeWrapper.RoleInstanceCount);
            siloInstanceManager.RegisterSiloInstance(myEntry);

            // Initialize this Orleans silo instance
            host.SetDeploymentId(clusterId, connectionString);
            host.SetSiloEndpoint(myEndpoint, generation);
            host.SetProxyEndpoint(proxyEndpoint);

            host.ConfigureSiloHostDelegate = ConfigureSiloHostDelegate;

            host.InitializeOrleansSilo();
            return(StartSilo());
        }
Beispiel #32
0
 /// <summary>
 /// Configures the test cluster plus client in-process,
 /// using the specified silo and client config configurations.
 /// </summary>
 public TestCluster(ClusterConfiguration clusterConfiguration, ClientConfiguration clientConfiguration)
 {
     this.ClusterConfiguration = clusterConfiguration;
     this.ClientConfiguration  = clientConfiguration;
 }
 public static ISiloHostBuilder AddLegacyClusterConfigurationSupport(this ISiloHostBuilder builder, ClusterConfiguration configuration)
 {
     LegacyMembershipConfigurator.ConfigureServices(configuration.Globals, builder);
     LegacyRemindersConfigurator.Configure(configuration.Globals, builder);
     return(builder.ConfigureServices(services => AddLegacyClusterConfigurationSupport(services, configuration)));
 }
Beispiel #34
0
 /// <summary>
 ///     Returns the silo configuration.
 /// </summary>
 /// <returns>
 ///     The silo configuration.
 /// </returns>
 private static ClusterConfiguration GetConfiguration()
 {
     var config = new ClusterConfiguration();
     config.LoadFromFile(Path.Combine(GetAssemblyPath(), "SiloConfiguration.xml"));
     return config;
 }
Beispiel #35
0
 private SiloHandle StartOrleansSilo(Silo.SiloType type, ClusterConfiguration clusterConfig, NodeConfiguration nodeConfig)
 {
     return(StartOrleansSilo(this, type, clusterConfig, nodeConfig));
 }
Beispiel #36
0
        /// <summary>
        /// Start a new silo in the target cluster
        /// </summary>
        /// <param name="cluster">The TestCluster in which the silo should be deployed</param>
        /// <param name="type">The type of the silo to deploy</param>
        /// <param name="clusterConfig">The cluster config to use</param>
        /// <param name="nodeConfig">The configuration for the silo to deploy</param>
        /// <returns>A handle to the silo deployed</returns>
        public static SiloHandle StartOrleansSilo(TestCluster cluster, Silo.SiloType type, ClusterConfiguration clusterConfig, NodeConfiguration nodeConfig)
        {
            if (cluster == null)
            {
                throw new ArgumentNullException(nameof(cluster));
            }
            var siloName = nodeConfig.SiloName;

            cluster.WriteLog("Starting a new silo in app domain {0} with config {1}", siloName, clusterConfig.ToString(siloName));
            var handle = cluster.LoadSiloInNewAppDomain(siloName, type, clusterConfig, nodeConfig);

            return(handle);
        }
Beispiel #37
0
        public static void Main(string[] args)
        {
            var configuration =
                ClusterConfiguration.LocalhostPrimarySilo(33333)
                .RegisterDashboard();

            var silo =
                new SiloHostBuilder()
                .UseConfiguration(configuration)
                .UseDashboard(options =>
            {
                options.HostSelf = false;
            })
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            silo.StartAsync().Wait();

            var client =
                new ClientBuilder()
                .UseConfiguration(ClientConfiguration.LocalhostSilo())
                .UseDashboard()
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            client.Connect().Wait();

            var cts = new CancellationTokenSource();

            TestCalls.Make(client, cts);

            WebHost.CreateDefaultBuilder(args)
            .ConfigureServices(services =>
            {
                services.AddServicesForSelfHostedDashboard(client, options =>
                {
                    options.HideTrace = true;
                });
            })
            .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
            .Configure(app =>
            {
                app.UseOrleansDashboard();

                app.Map("/dashboard", d =>
                {
                    d.UseOrleansDashboard();
                });
            })
            .Build()
            .Run();

            cts.Cancel();

            silo.StopAsync().Wait();
        }