Example #1
0
 public MonitoredObserver(string name, int stage, ILifecycleObserver observer, ILogger <SiloLifecycleSubject> logger)
 {
     this.Name     = name;
     this.Stage    = stage;
     this.observer = observer;
     this.logger   = logger;
 }
Example #2
0
        public override IDisposable Subscribe(string observerName, int stage, ILifecycleObserver observer)
        {
            var monitoredObserver = new MonitoredObserver(observerName, stage, observer, this.logger);

            this.observers.Add(monitoredObserver);
            return(base.Subscribe(observerName, stage, monitoredObserver));
        }
Example #3
0
        public IDisposable Subscribe(int stage, ILifecycleObserver observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException(nameof(observer));
            }

            var orderedObserver = new OrderedObserver(stage, observer);

            this.subscribers.TryAdd(orderedObserver, orderedObserver);
            return(new Disposable(() => Remove(orderedObserver)));
        }
Example #4
0
        public IDisposable Subscribe(ILifecycleObserver observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException(nameof(observer));
            }

            var key = new object();

            subscribers.TryAdd(key, observer);
            return(new Disposable(() => Remove(key)));
        }
Example #5
0
        public IDisposable Subscribe(ILifecycleObserver observer, int ring = Constants.RingZero)
        {
            if (observer == null)
            {
                throw new ArgumentNullException(nameof(observer));
            }

            var key = new object();

            subscribers.TryAdd(key, new OrderedObserver(observer, ring));
            return(new Disposable(() => Remove(key)));
        }
Example #6
0
        public virtual IDisposable Subscribe(string observerName, int stage, ILifecycleObserver observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException(nameof(observer));
            }
            if (this.highStage.HasValue)
            {
                throw new InvalidOperationException("Lifecycle has already been started.");
            }

            var orderedObserver = new OrderedObserver(stage, observer);

            this.subscribers.Add(orderedObserver);
            return(new Disposable(() => this.subscribers.Remove(orderedObserver)));
        }
Example #7
0
        internal TinkerHost(IServiceCollection appServices, IServiceProvider hostingServiceProvider, IEnumerable <Type> members)
        {
            if (appServices == null)
            {
                throw new ArgumentNullException(nameof(appServices));
            }
            if (hostingServiceProvider == null)
            {
                throw new ArgumentNullException(nameof(hostingServiceProvider));
            }
            if (members == null)
            {
                throw new ArgumentNullException(nameof(members));
            }

            this.members = members.Select(type => hostingServiceProvider.GetService(type) ?? Activator.CreateInstance(type))
                           .ToList();
            this.lifecycle = hostingServiceProvider.GetRequiredService <ILifecycleObserver>();
        }
 public static Task OnStop(this ILifecycleObserver observer)
 {
     return(observer.OnStop(CancellationToken.None));
 }
Example #9
0
 public void RegisterObserver(ILifecycleObserver observer)
 {
     observers.Add(observer);
 }
 public void RemoveObserver(ILifecycleObserver lifecycleObserver)
 {
     _lifecycleObservers.Remove(lifecycleObserver);
 }
 public void AddObserver(ILifecycleObserver lifecycleObserver)
 {
     _lifecycleObservers.Add(lifecycleObserver);
 }
Example #12
0
 public static IDisposable Subscribe(this IGrainLifecycle observable, GrainLifecycleStage stage, ILifecycleObserver observer)
 {
     return(observable.Subscribe((int)stage, observer));
 }
Example #13
0
 public IDisposable Subscribe(string observerName, int stage, ILifecycleObserver observer)
 {
     throw new NotImplementedException();
 }
Example #14
0
 public OrderedObserver(ILifecycleObserver observer, int ring)
 {
     Observer = observer;
     Ring     = ring;
 }
Example #15
0
 /// <summary>
 /// Creates a disposable subscription to the lifecycle.
 /// </summary>
 /// <param name="observable">The lifecycle observable.</param>
 /// <param name="stage">The stage to participate in.</param>
 /// <param name="observer">The observer.</param>
 /// <returns>A <see cref="IDisposable"/> instance which can be disposed to unsubscribe the observer from the lifecycle.</returns>
 public static IDisposable Subscribe(this ILifecycleObservable observable, int stage, ILifecycleObserver observer)
 {
     return(observable.Subscribe(observer.GetType().FullName, stage, observer));
 }
Example #16
0
 /// <summary>
 /// Creates a disposable subscription to the lifecycle.
 /// </summary>
 /// <typeparam name="TObserver">
 /// The observer type, used for diagnostics.
 /// </typeparam>
 /// <param name="observable">The lifecycle observable.</param>
 /// <param name="stage">The stage to participate in.</param>
 /// <param name="observer">The observer.</param>
 /// <returns>A <see cref="IDisposable"/> instance which can be disposed to unsubscribe the observer from the lifecycle.</returns>
 public static IDisposable Subscribe <TObserver>(this ILifecycleObservable observable, int stage, ILifecycleObserver observer)
 {
     return(observable.Subscribe(typeof(TObserver).FullName, stage, observer));
 }
Example #17
0
 public OrderedObserver(int stage, ILifecycleObserver observer)
 {
     Stage    = stage;
     Observer = observer;
 }
Example #18
0
 public OrderedObserver(int stage, ILifecycleObserver observer)
 {
     this.Stage    = stage;
     this.Observer = observer;
 }
Example #19
0
        public Silo(ILocalSiloDetails siloDetails, IServiceProvider services)
        {
            string name = siloDetails.Name;

            // Temporarily still require this. Hopefuly gone when 2.0 is released.
            this.siloDetails       = siloDetails;
            this.SystemStatus      = SystemStatus.Creating;
            AsynchAgent.IsStarting = true;

            var startTime = DateTime.UtcNow;

            IOptions <SiloStatisticsOptions> statisticsOptions = services.GetRequiredService <IOptions <SiloStatisticsOptions> >();

            StatisticsCollector.Initialize(statisticsOptions.Value.CollectionLevel);

            IOptions <MembershipOptions> membershipOptions = services.GetRequiredService <IOptions <MembershipOptions> >();

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

            var localEndpoint = this.siloDetails.SiloAddress.Endpoint;

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

            this.Services = services;
            this.Services.InitializeSiloUnobservedExceptionsHandler();
            //set PropagateActivityId flag from node config
            IOptions <SiloMessagingOptions> messagingOptions = services.GetRequiredService <IOptions <SiloMessagingOptions> >();

            RequestContext.PropagateActivityId = messagingOptions.Value.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 silo on host {0} MachineName {1} at {2}, gen {3} --------------",
                        this.siloDetails.DnsHostName, Environment.MachineName, localEndpoint, this.siloDetails.SiloAddress.Generation);
            logger.Info(ErrorCode.SiloInitConfig, "Starting silo {0}", name);

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

            BufferPool.InitGlobalBufferPool(siloMessagingOptions.Value);

            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.
            this.grainRuntime = Services.GetRequiredService <IGrainRuntime>();

            // 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>();

            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>();
            this.siloOptions = Services.GetRequiredService <IOptions <SiloOptions> >().Value;
            var multiClusterOptions = Services.GetRequiredService <IOptions <MultiClusterOptions> >().Value;

            if (!multiClusterOptions.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;
            // register all lifecycle participants
            IEnumerable <ILifecycleParticipant <ISiloLifecycle> > lifecycleParticipants = this.Services.GetServices <ILifecycleParticipant <ISiloLifecycle> >();

            foreach (ILifecycleParticipant <ISiloLifecycle> participant in lifecycleParticipants)
            {
                participant?.Participate(fullSiloLifecycle);
            }
            // register all named lifecycle participants
            IKeyedServiceCollection <string, ILifecycleParticipant <ISiloLifecycle> > namedLifecycleParticipantCollection = this.Services.GetService <IKeyedServiceCollection <string, ILifecycleParticipant <ISiloLifecycle> > >();

            foreach (ILifecycleParticipant <ISiloLifecycle> participant in namedLifecycleParticipantCollection
                     ?.GetServices(this.Services)
                     ?.Select(s => s.GetService(this.Services)))
            {
                participant?.Participate(fullSiloLifecycle);
            }

            // add self to lifecycle
            this.Participate(fullSiloLifecycle);

            logger.Info(ErrorCode.SiloInitializingFinished, "-------------- Started silo {0}, ConsistentHashCode {1:X} --------------", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode());
        }
Example #20
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);

            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());
        }
Example #21
0
 public LifecycleOrderedObserver(string name, int stage, ILifecycleObserver observer)
     : base(name, stage)
 {
     Observer = observer;
 }