Example #1
0
 public HealthEndpoint(IServiceEndPointDefinition serviceEndPointDefinition, IServiceInterfaceMapper serviceInterfaceMapper, IActivator activator, IServiceDrainListener drainListener)
 {
     _drainListener            = drainListener;
     ServiceEndPointDefinition = serviceEndPointDefinition;
     ServiceInterfaceMapper    = serviceInterfaceMapper;
     Activator = activator;
 }
Example #2
0
        public HttpServiceListener(IActivator activator, IWorker worker, IServiceEndPointDefinition serviceEndPointDefinition,
                                   ICertificateLocator certificateLocator, ILog log, IEventPublisher <ServiceCallEvent> eventPublisher,
                                   IEnumerable <ICustomEndpoint> customEndpoints,
                                   JsonExceptionSerializer exceptionSerializer,
                                   ServiceSchema serviceSchema,
                                   Func <LoadShedding> loadSheddingConfig,
                                   IServerRequestPublisher serverRequestPublisher)

        {
            ServiceSchema             = serviceSchema;
            _serverRequestPublisher   = serverRequestPublisher;
            ServiceEndPointDefinition = serviceEndPointDefinition;
            Worker              = worker;
            Activator           = activator;
            Log                 = log;
            EventPublisher      = eventPublisher;
            CustomEndpoints     = customEndpoints.ToArray();
            ExceptionSerializer = exceptionSerializer;
            LoadSheddingConfig  = loadSheddingConfig;

            if (serviceEndPointDefinition.UseSecureChannel)
            {
                ServerRootCertHash = certificateLocator.GetCertificate("Service").GetHashOfRootCertificate();
            }

            var urlPrefixTemplate = ServiceEndPointDefinition.UseSecureChannel ? "https://+:{0}/" : "http://+:{0}/";

            Prefix = string.Format(urlPrefixTemplate, ServiceEndPointDefinition.HttpPort);

            Listener = new HttpListener
            {
                IgnoreWriteExceptions = true,
                Prefixes = { Prefix }
            };
        }
        public HttpServiceListener(
            IActivator activator,
            IWorker worker,
            IServiceEndPointDefinition serviceEndPointDefinition,
            ICertificateLocator certificateLocator,
            ILog log,
            IEnumerable <ICustomEndpoint> customEndpoints,
            IEnvironment environment,
            JsonExceptionSerializer exceptionSerializer,
            ServiceSchema serviceSchema,
            Func <LoadShedding> loadSheddingConfig,
            IServerRequestPublisher serverRequestPublisher,
            CurrentApplicationInfo appInfo)
        {
            ServiceSchema           = serviceSchema;
            _serverRequestPublisher = serverRequestPublisher;

            ServiceEndPointDefinition = serviceEndPointDefinition;
            Worker              = worker;
            Activator           = activator;
            Log                 = log;
            CustomEndpoints     = customEndpoints.ToArray();
            Environment         = environment;
            ExceptionSerializer = exceptionSerializer;
            LoadSheddingConfig  = loadSheddingConfig;
            AppInfo             = appInfo;

            if (ServiceEndPointDefinition.HttpsPort != null && ServiceEndPointDefinition.ClientCertificateVerification != ClientCertificateVerificationMode.Disable)
            {
                ServerRootCertHash = certificateLocator.GetCertificate("Service").GetHashOfRootCertificate();
            }

            Listener = new HttpListener {
                IgnoreWriteExceptions = true
            };
            if (ServiceEndPointDefinition.HttpsPort != null)
            {
                Listener.Prefixes.Add($"https://+:{ServiceEndPointDefinition.HttpsPort}/");
            }
            if (ServiceEndPointDefinition.HttpPort != null)
            {
                Listener.Prefixes.Add($"http://+:{ServiceEndPointDefinition.HttpPort}/");
            }
            if (!Listener.Prefixes.Any())
            {
                Log.Warn(_ => _("HttpServiceListener is not listening on any ports, no HTTP or HTTPS ports in ServiceEndPointDefinition"));
            }

            var context = Metric.Context("Service").Context(AppInfo.Name);

            _serializationTime          = context.Timer("Serialization", Unit.Calls);
            _deserializationTime        = context.Timer("Deserialization", Unit.Calls);
            _roundtripTime              = context.Timer("Roundtrip", Unit.Calls);
            _metaEndpointsRoundtripTime = context.Timer("MetaRoundtrip", Unit.Calls);
            _successCounter             = context.Counter("Success", Unit.Calls);
            _failureCounter             = context.Counter("Failed", Unit.Calls);
            _activeRequestsCounter      = context.Timer("ActiveRequests", Unit.Requests);
            _endpointContext            = context.Context("Endpoints");
        }
 public ServerRequestPublisher(IEventPublisher <ServiceCallEvent> eventPublisher,
                               IPropertiesMetadataPropertiesCache metadataPropertiesCache,
                               IServiceEndPointDefinition serviceEndPointDefinition)
 {
     _eventPublisher            = eventPublisher;
     _metadataPropertiesCache   = metadataPropertiesCache;
     _serviceEndPointDefinition = serviceEndPointDefinition;
 }
Example #5
0
 public ServerRequestPublisher(IEventPublisher <ServiceCallEvent> eventPublisher,
                               IMembersToLogExtractor membersToLogExtractor,
                               IServiceEndPointDefinition serviceEndPointDefinition)
 {
     _eventPublisher            = eventPublisher;
     _membersToLogExtractor     = membersToLogExtractor;
     _serviceEndPointDefinition = serviceEndPointDefinition;
 }
Example #6
0
        public HttpServiceListener(IActivator activator, IWorker worker, IServiceEndPointDefinition serviceEndPointDefinition,
                                   ICertificateLocator certificateLocator, ILog log,
                                   IEnumerable <ICustomEndpoint> customEndpoints, IEnvironment environment,
                                   JsonExceptionSerializer exceptionSerializer,
                                   ServiceSchema serviceSchema,
                                   Func <LoadShedding> loadSheddingConfig,
                                   IServerRequestPublisher serverRequestPublisher,
                                   CurrentApplicationInfo appInfo
                                   )
        {
            ServiceSchema           = serviceSchema;
            _serverRequestPublisher = serverRequestPublisher;

            ServiceEndPointDefinition = serviceEndPointDefinition;
            Worker              = worker;
            Activator           = activator;
            Log                 = log;
            CustomEndpoints     = customEndpoints.ToArray();
            Environment         = environment;
            ExceptionSerializer = exceptionSerializer;
            LoadSheddingConfig  = loadSheddingConfig;
            AppInfo             = appInfo;

            if (serviceEndPointDefinition.UseSecureChannel)
            {
                ServerRootCertHash = certificateLocator.GetCertificate("Service").GetHashOfRootCertificate();
            }

            var urlPrefixTemplate = ServiceEndPointDefinition.UseSecureChannel ? "https://+:{0}/" : "http://+:{0}/";

            Prefix = string.Format(urlPrefixTemplate, ServiceEndPointDefinition.HttpPort);

            Listener = new HttpListener
            {
                IgnoreWriteExceptions = true,
                Prefixes = { Prefix }
            };

            var context = Metric.Context("Service").Context(AppInfo.Name);

            _serializationTime          = context.Timer("Serialization", Unit.Calls);
            _deserializationTime        = context.Timer("Deserialization", Unit.Calls);
            _roundtripTime              = context.Timer("Roundtrip", Unit.Calls);
            _metaEndpointsRoundtripTime = context.Timer("MetaRoundtrip", Unit.Calls);
            _successCounter             = context.Counter("Success", Unit.Calls);
            _failureCounter             = context.Counter("Failed", Unit.Calls);
            _activeRequestsCounter      = context.Timer("ActiveRequests", Unit.Requests);
            _endpointContext            = context.Context("Endpoints");
        }
 public OrleansConfigurationBuilder(OrleansConfig orleansConfig, OrleansCodeConfig commonConfig,
                                    OrleansServiceInterfaceMapper orleansServiceInterfaceMapper,
                                    ClusterIdentity clusterIdentity, IServiceEndPointDefinition endPointDefinition,
                                    ServiceArguments serviceArguments,
                                    CurrentApplicationInfo appInfo)
 {
     _orleansConfig = orleansConfig;
     _commonConfig  = commonConfig;
     _orleansServiceInterfaceMapper = orleansServiceInterfaceMapper;
     _clusterIdentity    = clusterIdentity;
     _endPointDefinition = endPointDefinition;
     _serviceArguments   = serviceArguments;
     _appInfo            = appInfo;
     _siloHostBuilder    = InitBuilder();
 }
Example #8
0
        public OrleansConfigurationBuilder(OrleansConfig orleansConfig, OrleansCodeConfig commonConfig, OrleansServiceInterfaceMapper orleansServiceInterfaceMapper,
                                           ClusterConfiguration clusterConfiguration, ClusterIdentity clusterIdentity, IServiceEndPointDefinition endPointDefinition,
                                           OrleansLogConsumer orleansLogConsumer, ZooKeeperLogConsumer zooKeeperLogConsumer, ServiceArguments serviceArguments)
        {
            ClusterConfiguration = clusterConfiguration;

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

            SetAgeLimits(globals, orleansConfig, orleansServiceInterfaceMapper);

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

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

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

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

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

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

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

                globals.LivenessType = GlobalConfiguration.LivenessProviderType.MembershipTableGrain;

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

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

            if (string.IsNullOrEmpty(commonConfig.StorageProviderTypeFullName) == false)
            {
                //globals.RegisterStorageProvider<MemoryStorage>("OrleansStorage");
                globals.RegisterStorageProvider(commonConfig.StorageProviderTypeFullName, "Default");
                globals.RegisterStorageProvider(commonConfig.StorageProviderTypeFullName, commonConfig.StorageProviderName);
            }
        }
Example #9
0
 public HealthEndpoint(IServiceEndPointDefinition serviceEndPointDefinition, IServiceInterfaceMapper serviceInterfaceMapper, IActivator activator)
 {
     ServiceEndPointDefinition = serviceEndPointDefinition;
     ServiceInterfaceMapper    = serviceInterfaceMapper;
     Activator = activator;
 }
        public HttpServiceListener(
            IActivator activator,
            IWorker worker,
            IServiceEndPointDefinition serviceEndPointDefinition,
            ICertificateLocator certificateLocator,
            ILog log,
            IEnumerable <ICustomEndpoint> customEndpoints,
            IEnvironment environment,
            JsonExceptionSerializer exceptionSerializer,
            ServiceSchema serviceSchema,
            Func <LoadShedding> loadSheddingConfig,
            IServerRequestPublisher serverRequestPublisher,
            CurrentApplicationInfo appInfo,
            Func <MicrodotHostingConfig> microdotHostingConfigFactory,
            IMicrodotTypePolicySerializationBinder serializationBinder)
        {
            ServiceSchema           = serviceSchema;
            _serverRequestPublisher = serverRequestPublisher;

            ServiceEndPointDefinition = serviceEndPointDefinition;
            Worker              = worker;
            Activator           = activator;
            Log                 = log;
            CustomEndpoints     = customEndpoints.ToArray();
            Environment         = environment;
            ExceptionSerializer = exceptionSerializer;
            LoadSheddingConfig  = loadSheddingConfig;
            AppInfo             = appInfo;

            JsonSettings.SerializationBinder = serializationBinder;

            if (ServiceEndPointDefinition.HttpsPort != null && ServiceEndPointDefinition.ClientCertificateVerification != ClientCertificateVerificationMode.Disable)
            {
                var serviceCertificate = certificateLocator.GetCertificate("Service");
                Log.Info(_ => _($"Service certificate loaded: {serviceCertificate.FriendlyName}",
                                unencryptedTags: new
                {
                    Thumbprint = serviceCertificate.Thumbprint.Substring(serviceCertificate.Thumbprint.Length - 5),
                }));
                ServerRootCertHash = serviceCertificate.GetHashOfRootCertificate();
            }

            Listener = new HttpListener {
                IgnoreWriteExceptions = true
            };

            _uriPrefixes = new List <string>();

            if (ServiceEndPointDefinition.HttpsPort != null)
            {
                _uriPrefixes.Add($"https://+:{ServiceEndPointDefinition.HttpsPort}/");
            }
            if (ServiceEndPointDefinition.HttpPort != null)
            {
                _uriPrefixes.Add($"http://+:{ServiceEndPointDefinition.HttpPort}/");
            }
            if (!_uriPrefixes.Any())
            {
                Log.Warn(_ => _("HttpServiceListener is not listening on any ports, no HTTP or HTTPS ports in ServiceEndPointDefinition"));
            }
            else
            {
                foreach (string prefix in _uriPrefixes)
                {
                    Listener.Prefixes.Add(prefix);
                }
            }


            var context = Metric.Context("Service").Context(AppInfo.Name);

            _serializationTime          = context.Timer("Serialization", Unit.Calls);
            _deserializationTime        = context.Timer("Deserialization", Unit.Calls);
            _roundtripTime              = context.Timer("Roundtrip", Unit.Calls);
            _metaEndpointsRoundtripTime = context.Timer("MetaRoundtrip", Unit.Calls);
            _successCounter             = context.Counter("Success", Unit.Calls);
            _failureCounter             = context.Counter("Failed", Unit.Calls);
            _activeRequestsCounter      = context.Timer("ActiveRequests", Unit.Requests);
            _endpointContext            = context.Context("Endpoints");
        }