Exemplo n.º 1
0
        public static ISiloHostBuilder AddLoggers(this ISiloHostBuilder siloBuilder, OrleansConfig config)
        {
            LoggerType loggerType = config.GetLoggerTypes();

            siloBuilder.ConfigureLogging(builder =>
            {
                if (loggerType.HasFlag(LoggerType.Console))
                {
                    builder.AddConsole();
                }

                if (loggerType.HasFlag(LoggerType.Debug))
                {
                    builder.AddDebug();
                }

                builder.SetMinimumLevel(Enum.Parse <LogLevel>(config.LogLevel));
            });

            if (loggerType.HasFlag(LoggerType.AppInsights))
            {
                siloBuilder.AddApplicationInsightsTelemetryConsumer(config.AppInsightsKey);
            }

            return(siloBuilder);
        }
Exemplo n.º 2
0
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)
                   .ConfigureLogging(builder =>
            {
                OrleansConfig orleansConfig = GetOrleansConfiguration();
                LogLevel orleansLogLevel = Enum.Parse <LogLevel>(orleansConfig.LogLevel, true);
                LoggerType loggers = orleansConfig.GetLoggerTypes();

                if (loggers.HasFlag(LoggerType.Console))
                {
                    builder.AddConsole();
                }

                if (loggers.HasFlag(LoggerType.Debug))
                {
                    builder.AddDebug();
                }

                if (loggers.HasFlag(LoggerType.AppInsights) &&
                    !string.IsNullOrEmpty(orleansConfig.InstrumentationKey))
                {
                    builder.AddApplicationInsights(orleansConfig.InstrumentationKey);
                }

                builder.SetMinimumLevel(orleansLogLevel);
                builder.Services.AddSingleton <ILog, Logger>();
            })
                   .ConfigureServices((hostContext, services) =>
            {
                services.AddOrleansConfiguration();
                services.AddSingleton <Logger>();              //add the logger
                services.AddHostedService <SiloHostService>(); //start the silo host
            }));
        }
Exemplo n.º 3
0
        private void CreateClusteredSiloHost()
        {
            var silo = new SiloHostBuilder()
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = orleansConfig.ClusterId;
                options.ServiceId = orleansConfig.ServiceId;
            });
            //.EnableDirectClient();

            string storageType = GetStorageType(orleansConfig.DataConnectionString);

            if (storageType.ToLowerInvariant() == "redis")
            {
                silo.UseRedisMembership(options => options.ConnectionString            = orleansConfig.DataConnectionString);
                silo.AddRedisGrainStorage("store", options => options.ConnectionString = orleansConfig.DataConnectionString);
            }
            else if (storageType.ToLowerInvariant() == "azurestorage")
            {
                silo.UseAzureStorageClustering(options => options.ConnectionString         = orleansConfig.DataConnectionString);
                silo.AddAzureBlobGrainStorage("store", options => options.ConnectionString = orleansConfig.DataConnectionString);
            }
            else
            {
                //throw
            }

            silo.ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000);

            LogLevel orleansLogLevel = GetLogLevel();
            var      loggers         = orleansConfig.GetLoggerTypes();

            silo.ConfigureLogging(builder =>
            {
                if (loggers.HasFlag(LoggerType.Console))
                {
                    builder.AddConsole();
                }
                if (loggers.HasFlag(LoggerType.Debug))
                {
                    builder.AddDebug();
                }
                builder.SetMinimumLevel(orleansLogLevel);
            });

            if (loggers.HasFlag(LoggerType.AppInsights) && !string.IsNullOrEmpty(orleansConfig.AppInsightsKey))
            {
                silo.AddApplicationInsightsTelemetryConsumer(orleansConfig.AppInsightsKey);
            }
            host = silo.Build();

            var clusterClient = (IClusterClient)host.Services.GetService(typeof(IClusterClient));

            GraphManager.Initialize(clusterClient);
        }
Exemplo n.º 4
0
 public PiraeusGatewayOptions(OrleansConfig config)
 {
     Dockerized           = config.Dockerized;
     ClusterId            = config.ClusterId;
     ServiceId            = config.ServiceId;
     DataConnectionString = config.DataConnectionString;
     AppInsightKey        = config.AppInsightsKey;
     LoggerTypes          = config.GetLoggerTypes();
     LoggingLevel         = Enum.Parse <LogLevel>(config.LogLevel);
     SetStorageType();
 }
Exemplo n.º 5
0
        private static IClientBuilder AddOrleansClusterClient(this IClientBuilder builder, OrleansConfig config)
        {
            builder.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IPiSystem).Assembly));

#if DEBUG
            builder.UseLocalhostClustering();
#else
            builder.Configure <ClusterOptions>(options =>
            {
                options.ClusterId = config.ClusterId;
                options.ServiceId = config.ServiceId;
            });

            if (config.DataConnectionString.Contains("6379") || config.DataConnectionString.Contains("6380"))
            {
                builder.UseRedisGatewayListProvider(options => options.ConnectionString = config.DataConnectionString);
            }
            else
            {
                builder.UseAzureStorageClustering(options => options.ConnectionString = config.DataConnectionString);
            }
#endif

            LoggerType loggers = config.GetLoggerTypes();

            if (loggers.HasFlag(LoggerType.AppInsights))
            {
                builder.AddApplicationInsightsTelemetryConsumer(config.InstrumentationKey);
            }

            builder.ConfigureLogging(op =>
            {
                if (loggers.HasFlag(LoggerType.AppInsights))
                {
                    op.AddApplicationInsights(config.InstrumentationKey);
                    op.SetMinimumLevel(Enum.Parse <LogLevel>(config.LogLevel, true));
                }

                if (loggers.HasFlag(LoggerType.Console))
                {
                    op.AddConsole();
                    op.SetMinimumLevel(Enum.Parse <LogLevel>(config.LogLevel, true));
                }

                if (loggers.HasFlag(LoggerType.Debug))
                {
                    op.AddDebug();
                    op.SetMinimumLevel(Enum.Parse <LogLevel>(config.LogLevel, true));
                }
            });

            return(builder);
        }
Exemplo n.º 6
0
        private ISiloHost AddClusteredSiloHost()
        {
            var silo = new SiloHostBuilder()
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = orleansConfig.ClusterId;
                options.ServiceId = orleansConfig.ServiceId;
            });


            if (string.IsNullOrEmpty(orleansConfig.DataConnectionString))
            {
                silo.AddMemoryGrainStorage("store");
            }
            else if (orleansConfig.DataConnectionString.Contains("6379") ||
                     orleansConfig.DataConnectionString.Contains("6380"))
            {
                silo.UseRedisMembership(options => options.ConnectionString            = orleansConfig.DataConnectionString);
                silo.AddRedisGrainStorage("store", options => options.ConnectionString = orleansConfig.DataConnectionString);
            }
            else
            {
                silo.UseAzureStorageClustering(options => options.ConnectionString         = orleansConfig.DataConnectionString);
                silo.AddAzureBlobGrainStorage("store", options => options.ConnectionString = orleansConfig.DataConnectionString);
            }

            silo.ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000);

            LogLevel orleansLogLevel = Enum.Parse <LogLevel>(orleansConfig.LogLevel);
            var      loggers         = orleansConfig.GetLoggerTypes();

            silo.ConfigureLogging(builder =>
            {
                if (loggers.HasFlag(LoggerType.Console))
                {
                    builder.AddConsole();
                }
                if (loggers.HasFlag(LoggerType.Debug))
                {
                    builder.AddDebug();
                }
                builder.SetMinimumLevel(orleansLogLevel);
            });

            if (!string.IsNullOrEmpty(orleansConfig.AppInsightsKey))
            {
                silo.AddApplicationInsightsTelemetryConsumer(orleansConfig.AppInsightsKey);
            }

            return(silo.Build());
        }
Exemplo n.º 7
0
        public void ConfigureServices(IServiceCollection services)
        {
            OrleansConfig oconfig = null;
            PiraeusConfig pconfig = null;

            //LoggerFactory loggerFactory = new LoggerFactory();

            IConfigurationBuilder configBuilder = new ConfigurationBuilder();

            configBuilder.AddOrleansConfiguration(out oconfig);
            configBuilder.AddPiraeusConfiguration(out pconfig);

            PiraeusGatewayOptions pgo = new PiraeusGatewayOptions(oconfig);
            //services.AddGatewayService(typeof(TcpGatewayService), null);

            //services.AddOrleansConfiguration();
            //services.AddPiraeusConfiguration();
            //services.AddOrleansClusterClient(loggerFactory, options => options.IsLocal = false);

            IServiceProvider sp         = services.BuildServiceProvider();
            LoggerType       loggerType = oconfig.GetLoggerTypes();

            if (!loggerType.HasFlag(LoggerType.None))
            {
                services.AddLogging(builder =>
                {
                    if (loggerType.HasFlag(LoggerType.Console))
                    {
                        builder.AddConsole();
                    }
                    if (loggerType.HasFlag(LoggerType.Debug))
                    {
                        builder.AddDebug();
                    }
                    if (loggerType.HasFlag(LoggerType.AppInsights) && !string.IsNullOrEmpty(oconfig.AppInsightsKey))
                    {
                        builder.AddApplicationInsights(oconfig.AppInsightsKey);
                    }

                    builder.SetMinimumLevel(LogLevel.Warning);
                });
            }

            TcpGatewayService tgs = sp.GetRequiredService <TcpGatewayService>();

            tgs.Init(oconfig.Dockerized);

            //services.AddSingleton<TcpGatewayService>((f) => f.GetRequiredService<TcpGatewayService>());
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a new instance of GraphManager
 /// </summary>
 /// <param name="config"></param>
 /// <remarks>Creates a new IClusterClient per instance of GraphManager.</remarks>
 public GraphManager(OrleansConfig config)
     : this(config.DataConnectionString, config.GetLoggerTypes(), Enum.Parse <LogLevel>(config.LogLevel, true), config.AppInsightsKey)
 {
 }