Exemplo n.º 1
0
        private static void Main()
        {
            while (true)
            {
                Console.WriteLine("请输入配置文件名称:");
                var configName = Console.ReadLine();
                var configFile = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                    $"{Path.GetFileNameWithoutExtension(configName)}.xml"));
                if (!configFile.Exists)
                {
                    Console.WriteLine($"配置文件:{configFile.FullName},不存在!");
                    continue;
                }
                Console.WriteLine("请输入节点名称:");
                var nodeName = Console.ReadLine() ?? string.Empty;
                using (var host = new SiloHost(nodeName, configFile))
                {
                    host.LoadOrleansConfig();
                    host.InitializeOrleansSilo();
                    host.StartOrleansSilo();

                    Console.WriteLine("已启动,按下任意键退出。");
                    Console.ReadLine();

                    host.StopOrleansSilo();
                }
                break;
            }
        }
Exemplo n.º 2
0
        private static void Run()
        {
            var config = GetClusterConfiguration();
            config.Globals.SeedNodes.Add(new IPEndPoint(IPAddress.Loopback, 11111));
            config.Defaults.HostNameOrIPAddress = "localhost";
            config.Defaults.Port = 11111;
            config.Defaults.ProxyGatewayEndpoint = new IPEndPoint(IPAddress.Loopback, 12345);

            var process = Process.GetCurrentProcess();
            var name = Environment.MachineName + "_" + process.Id + Guid.NewGuid().ToString("N").Substring(3);

            var silo = new SiloHost(name, config);

            // Configure the silo for the current environment.
            silo.SetSiloType(Silo.SiloType.Primary);

            Trace.TraceInformation("Silo configuration: \n" + silo.Config.ToString(name));

            silo.InitializeOrleansSilo();
            Trace.TraceInformation("Successfully initialized Orleans silo '{0}' as a {1} node.", silo.Name, silo.Type);
            Trace.TraceInformation("Starting Orleans silo '{0}' as a {1} node.", silo.Name, silo.Type);

            if (silo.StartOrleansSilo())
            {
                silo.WaitForOrleansSiloShutdown();
            }
        }
Exemplo n.º 3
0
 private static void ShutdownSilo()
 {
     if (null == _host) return;
     _host.StopOrleansSilo();
     _host.Dispose();
     _host = null;
 }
Exemplo n.º 4
0
 private static void ShutdownSilo()
 {
     if (siloHost != null)
     {
         siloHost.Dispose();
         siloHost = null;
     }
 }
Exemplo n.º 5
0
 static void ShutdownSilo()
 {
     if (siloHost != null)
     {
         siloHost.Dispose();
         GC.SuppressFinalize(siloHost);
         siloHost = null;
     }
 }
Exemplo n.º 6
0
        static void ShutdownSilo()
        {
            if (_siloHost == null)
                return;

            _siloHost.Dispose();
            GC.SuppressFinalize(_siloHost);
            _siloHost = null;
        }
Exemplo n.º 7
0
 private static void InitSilo(string[] args)
 {
     siloHost=new SiloHost(System.Net.Dns.GetHostName());
     siloHost.ConfigFileName = "OrleansConfiguration.xml";
     siloHost.InitializeOrleansSilo();
     var startedOk = siloHost.StartOrleansSilo();
     if (!startedOk)
     {
         throw new SystemException(String.Format("Failed to start Orleans silo '{0}' as a {1} node", siloHost.Name, siloHost.Type));
     }
 }
Exemplo n.º 8
0
        static void InitSilo(string[] args)
        {
            siloHost = new SiloHost(System.Net.Dns.GetHostName());
            // The Cluster config is quirky and weird to configure in code, so we're going to use a config file
            siloHost.ConfigFileName = "OrleansConfiguration.xml";

            siloHost.InitializeOrleansSilo();
            var startedok = siloHost.StartOrleansSilo();
            if (!startedok)
                throw new SystemException(String.Format("Failed to start Orleans silo '{0}' as a {1} node", siloHost.Name, siloHost.Type));
        }
Exemplo n.º 9
0
        public override void Dispose()
        {
            if (host == null)
                return;

            host.StopOrleansSilo();
            host.UnInitializeOrleansSilo();
            host.Dispose();
            host = null;

            configurator.Dispose();
        }
Exemplo n.º 10
0
        private static void Main(string[] args){
            using (SiloHost host = new SiloHost("Default")){
                host.LoadOrleansConfig();
                host.InitializeOrleansSilo();
                host.StartOrleansSilo();

                Console.WriteLine("Start--------");
                Console.ReadLine();

                host.StopOrleansSilo();
            }
        }
Exemplo n.º 11
0
        static void InitSilo(string[] args)
        {
            siloHost = new SiloHost(System.Net.Dns.GetHostName());
            // possible from code, but easier via config
            siloHost.ConfigFileName = "OrleansConfiguration.xml";

            siloHost.InitializeOrleansSilo();
            var startedok = siloHost.StartOrleansSilo();
            if (!startedok)
            {
                throw new SystemException(String.Format("Failed to start silo '{0}' as '{1}' node", siloHost.Name, siloHost.Type));
            }
        }
 /// <summary>
 /// start secondary
 /// </summary>
 /// <param name="port"></param>
 /// <param name="proxyPort"></param>
 public OrleansHostWrapper(int port, int proxyPort)
 {
     var config = new ClusterConfiguration();
     var siloAddress = new IPEndPoint(IPAddress.Loopback, 22222);
     config.Globals.LivenessType = GlobalConfiguration.LivenessProviderType.MembershipTableGrain;
     config.Globals.SeedNodes.Add(siloAddress);
     config.Globals.ReminderServiceType = GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain;
     config.Defaults.HostNameOrIPAddress = "localhost";
     config.Defaults.Port = port;
     config.Defaults.ProxyGatewayEndpoint = new IPEndPoint(IPAddress.Loopback, proxyPort);
     config.PrimaryNode = siloAddress;
     siloHost = new SiloHost("secondary", config);
 }
Exemplo n.º 13
0
        static void InitSilo(string[] args)
        {
            _siloHost = new SiloHost(Dns.GetHostName())
            {
                ConfigFileName = "ServerConfiguration.xml"
            };

            _siloHost.InitializeOrleansSilo();

            var startedOk = _siloHost.StartOrleansSilo();

            if (!startedOk)
                throw new SystemException($"Failed to start Orleans silo '{_siloHost.Name}' as a {_siloHost.Type} node");
        }
Exemplo n.º 14
0
        public OrleansHostWrapper(ClusterConfiguration config, string[] args)
        {
            var siloArgs = SiloArgs.ParseArguments(args);
            if (siloArgs == null)
            {
                return;
            }

            if (siloArgs.DeploymentId != null)
            {
                config.Globals.DeploymentId = siloArgs.DeploymentId;
            }

            siloHost = new SiloHost(siloArgs.SiloName, config);
            siloHost.LoadOrleansConfig();
        }
Exemplo n.º 15
0
        public OrleansHostWrapper(ClusterConfiguration config, string[] args)
        {
            var siloArgs = SiloArgs.ParseArguments(args);

            if (siloArgs == null)
            {
                return;
            }

            if (siloArgs.DeploymentId != null)
            {
                config.Globals.DeploymentId = siloArgs.DeploymentId;
            }

            siloHost = new Orleans.Runtime.Host.SiloHost(siloArgs.SiloName, config);
            siloHost.LoadOrleansConfig();
        }
Exemplo n.º 16
0
 private static void InitSilo(string[] args)
 {
     _host = new SiloHost(Dns.GetHostName())
     {
         ConfigFileName = "OrleansConfiguration.xml"
     };
     _host.LoadOrleansConfig();
     _host.InitializeOrleansSilo();
     if (_host.StartOrleansSilo())
     {
         Console.WriteLine($"Started host {_host.Name} as a {_host.Type} node");
     }
     else
     {
         Console.WriteLine($"Failed to start host {_host.Name}");
     }
 }
Exemplo n.º 17
0
        private static void InitSilo(String[] args)
        {
            Common.initConsoleLog();

            siloHost = new SiloHost(Dns.GetHostName())
            {
                ConfigFileName = "OrleansConfiguration.xml"
            };

            siloHost.InitializeOrleansSilo();
            if (!siloHost.StartOrleansSilo())
            {
                throw new Exception(
                    $"Failed to start Orleans silo '{siloHost.Name}' " +
                    $"as a {siloHost.Type} node"
                );
            }
        }
Exemplo n.º 18
0
 private static void InitSilo(string[] args)
 {
     var configFile = Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) , "OrleansConfiguration.xml"); 
     _host = new SiloHost(Dns.GetHostName())
     {
         ConfigFileName = configFile
     };
     _host.LoadOrleansConfig();
     _host.InitializeOrleansSilo();
     if (_host.StartOrleansSilo())
     {
         Console.WriteLine($"Started host {_host.Name} as a {_host.Type} node");
     }
     else
     {
         Console.WriteLine($"Failed to start host {_host.Name}");
     }
 }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("请输入配置文件名称:");
                var configName = Console.ReadLine();
                configName = string.IsNullOrEmpty(configName) ? "OrleansConfiguration" : configName;
                var configFile = new FileInfo(
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                    string.Format("{0}.xml", configName)));
                if (!configFile.Exists)
                {
                    Console.WriteLine("配置文件:{0} 不存在", configFile.Name);
                    continue;
                }
                Console.WriteLine("请输入节点名称");
                var nodeName = Console.ReadLine() ?? string.Empty;

                using (var host = new SiloHost(nodeName, configFile))
                {
                    host.LoadOrleansConfig();
                    host.InitializeOrleansSilo();
                    host.StartOrleansSilo();

                    Console.WriteLine("已启动,按下任意键退出");
                    Console.ReadLine();
                    host.StopOrleansSilo();
                }
            }
           
            //AppDomain hostDomain=AppDomain.CreateDomain("OrleansHost",null,new AppDomainSetup()
            //{
            //    AppDomainInitializer =InitSilo
            //});

            //DoSomeClientWork();
            //Console.WriteLine("Orleans Silo is running.\nPress Enter to terminate...");
            //Console.ReadLine();

            //hostDomain.DoCallBack(ShutdownSilo);
        }
Exemplo n.º 20
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>
        /// <returns><c>true</c> is the silo startup was successful</returns>
        public bool Start(ClusterConfiguration config, string deploymentId = 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.GetConfigurationForNode(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
            };

            var 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);
            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();
        }
Exemplo n.º 21
0
        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 SiloHost(siloName, config);

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

            return true;
        }
Exemplo n.º 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> if the silo startup was successful</returns>
        internal bool Start(ClusterConfiguration config, string deploymentId, string connectionString)
        {
            if (config != null && deploymentId != null)
                throw new ArgumentException("Cannot use config and deploymentId 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 deploymentId was not direclty provided, take the value in the config. If it is not 
            // in the config too, just take the DeploymentId from Azure
            if (deploymentId == null)
                deploymentId = host.Config.Globals.DeploymentId ?? serviceRuntimeWrapper.DeploymentId;

            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,
                SiloName = instanceName,
                UpdateZone = serviceRuntimeWrapper.UpdateDomain.ToString(CultureInfo.InvariantCulture),
                FaultZone = serviceRuntimeWrapper.FaultDomain.ToString(CultureInfo.InvariantCulture),
                StartTime = LogFormatter.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}",
                    LogFormatter.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);

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

            host.InitializeOrleansSilo();
            return StartSilo();
        }
Exemplo n.º 23
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.LoadConfig(); // 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, AzureStorageClusteringOptions.DEFAULT_TABLE_NAME, 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.InitializeSilo();
            return(StartSilo());
        }
Exemplo n.º 24
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.LoadConfig(); // 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);

            // 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;
            }

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

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

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

            host.ConfigureSiloHostDelegate = ConfigureSiloHostDelegate;

            host.InitializeSilo();
            return(StartSilo());
        }
Exemplo n.º 25
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.GetConfigurationForNode(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());
        }
Exemplo n.º 26
0
        public void SiloConfig_Azure_Default()
        {
            const string filename = "Config_Azure_Default.xml";

            string deploymentId = "SiloConfig_Azure_Default" + TestConstants.random.Next();
            string connectionString = StorageTestConstants.DataConnectionString;

            var initialConfig = new ClusterConfiguration();
            initialConfig.LoadFromFile(filename);

            output.WriteLine(initialConfig.Globals);

            // Do same code that AzureSilo does for configuring silo host

            var host = new SiloHost("SiloConfig_Azure_Default", initialConfig); // Use supplied config data + Initializes logger configurations
            host.SetSiloType(Silo.SiloType.Secondary);
            ////// Always use Azure table for membership when running silo in Azure
            host.SetSiloLivenessType(GlobalConfiguration.LivenessProviderType.AzureTable);
            host.SetReminderServiceType(GlobalConfiguration.ReminderServiceProviderType.AzureTable);
            host.SetDeploymentId(deploymentId, connectionString);

            ClusterConfiguration siloConfig = host.Config;

            Assert.AreEqual(GlobalConfiguration.LivenessProviderType.AzureTable, siloConfig.Globals.LivenessType, "LivenessType");
            Assert.AreEqual(GlobalConfiguration.ReminderServiceProviderType.AzureTable, siloConfig.Globals.ReminderServiceType, "ReminderServiceType");

            Assert.AreEqual(deploymentId, siloConfig.Globals.DeploymentId, "DeploymentId");
            Assert.AreEqual(connectionString, siloConfig.Globals.DataConnectionString, "DataConnectionString");

            Assert.IsTrue(siloConfig.Globals.UseAzureSystemStore, "Should be using Azure storage");
            Assert.IsFalse(siloConfig.Globals.UseSqlSystemStore, "Should not be using SqlServer storage");
        }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Parse command line arguments, to allow override of some silo runtime config settings.
        /// </summary>
        /// <param name="args">Command line arguments, as received by the Main program.</param>
        /// <returns></returns>
        public bool ParseArguments(string[] args)
        {
            string siloName = Dns.GetHostName(); // Default to machine name

            SiloHost = new SiloHost(siloName);

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

                    case "/debug":
                        SiloHost.Debug = true;
                        break;

                    default:
                        ConsoleText.WriteError("Bad command line arguments supplied: " + a);
                        return(false);
                    }
                }
                else if (a.Contains("="))
                {
                    string[] split = a.Split('=');
                    if (String.IsNullOrEmpty(split[1]))
                    {
                        ConsoleText.WriteError("Bad command line arguments supplied: " + a);
                        return(false);
                    }
                    switch (split[0].ToLowerInvariant())
                    {
                    case "deploymentid":
                        SiloHost.DeploymentId = split[1];
                        break;

                    case "deploymentgroup":
                        ConsoleText.WriteError("Ignoring deprecated command line argument: " + a);
                        break;

                    default:
                        ConsoleText.WriteError("Bad command line arguments supplied: " + a);
                        return(false);
                    }
                }
                // unqualified arguments below
                else if (argPos == 1)
                {
                    SiloHost.Name = a;
                    argPos++;
                }
                else if (argPos == 2)
                {
                    SiloHost.ConfigFileName = a;
                    argPos++;
                }
                else
                {
                    // Too many command line arguments
                    ConsoleText.WriteError("Too many command line arguments supplied: " + a);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 29
0
 internal ClusterActorSystem(IDisposable configurator, ClusterConfiguration configuration)
 {
     current = this;
     this.configurator = configurator;
     host = new SiloHost(Dns.GetHostName(), configuration);
 }
Exemplo n.º 30
0
        private bool ParseArguments(string[] args)
        {
            string deploymentId = null;

            string configFileName = "DevTestServerConfiguration.xml";
            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;

                    case "deploymentgroup":
                        // TODO: Remove this at some point in future
                        Console.WriteLine("Ignoring deprecated command line argument: " + a);
                        break;

                    default:
                        Console.WriteLine("Bad command line arguments supplied: " + a);
                        return(false);
                    }
                }
                // unqualified arguments below
                else if (argPos == 1)
                {
                    siloName = a;
                    argPos++;
                }
                else if (argPos == 2)
                {
                    configFileName = a;
                    argPos++;
                }
                else
                {
                    // Too many command line arguments
                    Console.WriteLine("Too many command line arguments supplied: " + a);
                    return(false);
                }
            }

            siloHost = new Orleans.Runtime.Host.SiloHost(siloName);
            siloHost.ConfigFileName = configFileName;
            if (deploymentId != null)
            {
                siloHost.DeploymentId = deploymentId;
            }

            return(true);
        }
Exemplo n.º 31
0
 protected virtual void Dispose(bool dispose)
 {
     siloHost.Dispose();
     siloHost = null;
 }
 /// <summary>
 /// start primary
 /// </summary>
 public OrleansHostWrapper()
 {
     siloHost = new SiloHost("primary", ClusterConfiguration.LocalhostPrimarySilo());
 }
Exemplo n.º 33
0
 protected virtual void Dispose(bool dispose)
 {
     siloHost.Dispose();
     siloHost = null;
 }
Exemplo n.º 34
0
 /// <summary>
 ///     The abort.
 /// </summary>
 public void Abort()
 {
     var silo = this.host;
     if (silo != null)
     {
         silo.UnInitializeOrleansSilo();
         silo.Dispose();
         this.host = null;
     }
 }
Exemplo n.º 35
0
        private bool ParseArguments(string[] args)
        {
            string deploymentId = null;

            string configFileName = "DevTestServerConfiguration.xml";
            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;
                        case "deploymentgroup":
                            // TODO: Remove this at some point in future
                            Console.WriteLine("Ignoring deprecated command line argument: " + a);
                            break;
                        default:
                            Console.WriteLine("Bad command line arguments supplied: " + a);
                            return false;
                    }
                }
                // unqualified arguments below
                else if (argPos == 1)
                {
                    siloName = a;
                    argPos++;
                }
                else if (argPos == 2)
                {
                    configFileName = a;
                    argPos++;
                }
                else
                {
                    // Too many command line arguments
                    Console.WriteLine("Too many command line arguments supplied: " + a);
                    return false;
                }
            }

            siloHost = new SiloHost(siloName);
            siloHost.ConfigFileName = configFileName;
            if (deploymentId != null)
                siloHost.DeploymentId = deploymentId;

            return true;
        }
Exemplo n.º 36
0
        /// <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: {0}, DeploymentId: {1}, Primary Endpoint: {2}",
                    this.siloName,
                    this.deploymentId,
                    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(GlobalConfiguration.LivenessProviderType.AzureTable);
                this.host.SetReminderServiceType(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 '{0}' as a {1} node.",
                    this.host.Name,
                    this.host.Type);
                Trace.TraceInformation("Starting Orleans silo '{0}' as a {1} node.", this.host.Name, this.host.Type);

                var ok = this.host.StartOrleansSilo();
                if (ok)
                {
                    Trace.TraceInformation(
                        "Successfully started Orleans silo '{0}' as a {1} node.",
                        this.host.Name,
                        this.host.Type);
                }
                else
                {
                    Trace.TraceInformation(
                        "Failed to start Orleans silo '{0}' as a {1} node.",
                        this.host.Name,
                        this.host.Type);
                }

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

                throw;
            }
        }
Exemplo n.º 37
0
        public void SiloConfig_Programatic()
        {
            string siloName = "SiloConfig_Programatic";

            var config = new ClusterConfiguration();
            config.Globals.CacheSize = 11;

            var host = new SiloHost(siloName, config); // Use supplied config data + Initializes logger configurations

            ClusterConfiguration siloConfig = host.Config;

            output.WriteLine(siloConfig.Globals);

            Assert.AreEqual("", siloConfig.SourceFile, "SourceFile should be blank for programmatic config");
            Assert.AreEqual(11, siloConfig.Globals.CacheSize, "CacheSize picked up from config object");
        }
Exemplo n.º 38
0
        /// <summary>
        /// Parse command line arguments, to allow override of some silo runtime config settings.
        /// </summary>
        /// <param name="args">Command line arguments, as received by the Main program.</param>
        /// <returns></returns>
        public bool ParseArguments(string[] args)
        {
            string siloName = Dns.GetHostName(); // Default to machine name
            SiloHost = new SiloHost(siloName);

            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;
                        case "/debug":
                            SiloHost.Debug = true;
                            break;
                        default:
                            ConsoleText.WriteError("Bad command line arguments supplied: " + a);
                            return false;
                    }
                }
                else if (a.Contains("="))
                {
                    string[] split = a.Split('=');
                    if (String.IsNullOrEmpty(split[1]))
                    {
                        ConsoleText.WriteError("Bad command line arguments supplied: " + a);
                        return false;
                    }
                    switch (split[0].ToLowerInvariant())
                    {
                        case "deploymentid":
                            SiloHost.DeploymentId = split[1];
                            break;
                        case "deploymentgroup":
                            ConsoleText.WriteError("Ignoring deprecated command line argument: " + a);
                            break;
                        default:
                            ConsoleText.WriteError("Bad command line arguments supplied: " + a);
                            return false;
                    }
                }
                // unqualified arguments below
                else if (argPos == 1)
                {
                    SiloHost.Name = a;
                    argPos++;
                }
                else if (argPos == 2)
                {
                    SiloHost.ConfigFileName = a;
                    argPos++;
                }
                else
                {
                    // Too many command line arguments
                    ConsoleText.WriteError("Too many command line arguments supplied: " + a);
                    return false;
                }
            }

            return true;
        }