// This is a static version that can be called without a TestingSiloHost object (host = null) public static SiloHandle StartOrleansSilo(TestingSiloHost host, Silo.SiloType type, TestingSiloOptions options, int instanceCount, AppDomain shared = null) { // Load initial config settings, then apply some overrides below. ClusterConfiguration config = new ClusterConfiguration(); if (options.SiloConfigFile == null) { config.StandardLoad(); } else { config.LoadFromFile(options.SiloConfigFile.FullName); } 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(DeploymentId)) { config.Globals.DeploymentId = 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; } _livenessStabilizationTime = GetLivenessStabilizationTime(config.Globals); if (host != null) { 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.GetConfigurationForNode(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 = LoadSiloInNewAppDomain(siloName, type, config, out appDomain); silo.Start(); SiloHandle retValue = new SiloHandle { Name = siloName, Silo = silo, Options = options, Endpoint = silo.SiloAddress.Endpoint, AppDomain = appDomain, }; ImportGeneratedAssemblies(retValue); return(retValue); }
private SiloHandle LoadSiloInNewAppDomain(string siloName, Silo.SiloType type, ClusterConfiguration config, NodeConfiguration nodeConfiguration) { return(AppDomainSiloHandle.Create(siloName, type, this.siloBuilderFactoryType, config, nodeConfiguration)); }
private SiloHandle StartOrleansSilo(Silo.SiloType type, TestingSiloOptions options, int instanceCount, AppDomain shared = null) { return(StartOrleansSilo(this, type, options, instanceCount, shared)); }
/// <summary>Adds a silo config to the target cluster config.</summary> /// <param name="config">The target cluster configuration</param> /// <param name="siloType">The type of the silo to add</param> /// <param name="instanceNumber">The instance number of the silo</param> /// <param name="baseSiloPort">Base silo port to use</param> /// <param name="baseGatewayPort">Base gateway silo port to use</param> /// <returns>The silo configuration added</returns> public static NodeConfiguration AddNodeConfiguration(ClusterConfiguration config, Silo.SiloType siloType, short instanceNumber, int baseSiloPort, int baseGatewayPort) { string siloName; switch (siloType) { case Silo.SiloType.Primary: siloName = Silo.PrimarySiloName; break; default: siloName = $"Secondary_{instanceNumber}"; break; } NodeConfiguration nodeConfig = config.GetOrCreateNodeConfigurationForSilo(siloName); nodeConfig.HostNameOrIPAddress = "loopback"; nodeConfig.Port = baseSiloPort + instanceNumber; var proxyAddress = nodeConfig.ProxyGatewayEndpoint?.Address ?? config.Defaults.ProxyGatewayEndpoint?.Address; if (proxyAddress != null) { nodeConfig.ProxyGatewayEndpoint = new IPEndPoint(proxyAddress, baseGatewayPort + instanceNumber); } config.Overrides[siloName] = nodeConfig; return(nodeConfig); }
private SiloHandle StartOrleansSilo(Silo.SiloType type, ClusterConfiguration clusterConfig, NodeConfiguration nodeConfig) { return(StartOrleansSilo(this, type, clusterConfig, nodeConfig)); }
/// <summary> /// Start a new silo in the target cluster /// </summary> /// <param name="host">The target cluster</param> /// <param name="type">The type of the silo to deploy</param> /// <param name="options">The options to use for the silo</param> /// <param name="instanceCount">The instance count of the silo</param> /// <param name="shared">The shared AppDomain to use</param> /// <returns>A handle to the deployed silo</returns> 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; int?gatewayport = null; if (nodeConfig.ProxyGatewayEndpoint != null && nodeConfig.ProxyGatewayEndpoint.Address != null) { gatewayport = (options.ProxyBasePort < 0 ? ProxyBasePort : options.ProxyBasePort) + instanceCount; nodeConfig.ProxyGatewayEndpoint = new IPEndPoint(nodeConfig.ProxyGatewayEndpoint.Address, gatewayport.Value); } 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)); return(AppDomainSiloHandle.Create(siloName, type, config, nodeConfig, host.additionalAssemblies)); }
/// <summary> /// Set the type of this silo. Default is Secondary. /// </summary> /// <param name="siloType">Type of this silo.</param> public void SetSiloType(Silo.SiloType siloType) { logger.Info(ErrorCode.SiloSetSiloType, "Setting silo type {0}", siloType); Type = siloType; }
/// <summary> /// Initializes a new instance of the <see cref="SiloInitializationParameters"/> class. /// </summary> /// <param name="name">The name of this silo.</param> /// <param name="type">The type of this silo.</param> /// <param name="config">The cluster configuration.</param> public SiloInitializationParameters(string name, Silo.SiloType type, ClusterConfiguration config) : this(name, config) { this.Type = type; }
/// <summary>Creates and initializes a silo in the current app domain.</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 AppDomainSiloHost(string name, Silo.SiloType siloType, ClusterConfiguration config) { this.silo = new Silo(name, siloType, config); this.silo.InitializeTestHooksSystemTarget(); this.AppDomainTestHook = new AppDomainTestHooks(this.silo); }
private SiloHandle _StartOrleansSilo(Silo.SiloType type, UnitTestSiloOptions options, AppDomain shared = null) { // Load initial config settings, then apply some overrides below. ClusterConfiguration config = new ClusterConfiguration(); if (options.SiloConfigFile == null) { config.StandardLoad(); } else { config.LoadFromFile(options.SiloConfigFile.FullName); } int basePort = options.BasePort >= 0 ? options.BasePort : 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(DeploymentId)) { config.Globals.DeploymentId = DeploymentId; } config.Defaults.PropagateActivityId = options.PropagateActivityId; if (options.LargeMessageWarningThreshold > 0) { config.Defaults.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold; } config.Globals.LivenessType = options.LivenessType; globalConfig = config.Globals; string siloName; switch (type) { case Silo.SiloType.Primary: siloName = "Primary"; break; default: siloName = "Secondary_" + InstanceCounter.ToString(CultureInfo.InvariantCulture); break; } NodeConfiguration nodeConfig = config.GetConfigurationForNode(siloName); nodeConfig.HostNameOrIPAddress = "loopback"; nodeConfig.Port = basePort + InstanceCounter; nodeConfig.DefaultTraceLevel = config.Defaults.DefaultTraceLevel; nodeConfig.PropagateActivityId = config.Defaults.PropagateActivityId; nodeConfig.BulkMessageLimit = config.Defaults.BulkMessageLimit; config.Globals.ExpectedClusterSize = 2; config.Overrides[siloName] = nodeConfig; InstanceCounter++; Console.WriteLine("Starting a new silo in app domain {0} with config {1}", siloName, config.ToString(siloName)); AppDomain appDomain; Silo silo = _LoadSiloInNewAppDomain(siloName, type, config, out appDomain); silo.Start(); SiloHandle retValue = new SiloHandle { Name = siloName, Silo = silo, Options = options, Endpoint = silo.SiloAddress.Endpoint, AppDomain = appDomain, }; return(retValue); }
/// <summary>Creates and initializes a silo in the current app domain.</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 AppDomainSiloHost(string name, Silo.SiloType siloType, ClusterConfiguration config) { this.silo = new Silo(name, siloType, config); }
/// <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, 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, type, 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; } }
public OrleansConfigurationBuilder(OrleansConfig orleansConfig, OrleansCodeConfig commonConfig, ClusterConfiguration clusterConfiguration, ClusterIdentity clusterIdentity, IServiceEndPointDefinition endPointDefinition, OrleansLogConsumer orleansLogConsumer, ZooKeeperLogConsumer zooKeeperLogConsumer) { ClusterConfiguration = clusterConfiguration; SiloType = Silo.SiloType.Secondary; var globals = ClusterConfiguration.Globals; var defaults = ClusterConfiguration.Defaults; 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; if (orleansConfig.MaxActiveThreads > 0) { defaults.MaxActiveThreads = orleansConfig.MaxActiveThreads; } // 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(commonConfig.StorageProviderTypeFullName, "Default"); globals.RegisterStorageProvider(commonConfig.StorageProviderTypeFullName, commonConfig.StorageProviderName); } }
private SiloHandle LoadSiloInNewAppDomain(string siloName, Silo.SiloType type, ClusterConfiguration config, NodeConfiguration nodeConfiguration) { return(AppDomainSiloHandle.Create(siloName, type, config, nodeConfiguration, this.additionalAssemblies)); }