Esempio n. 1
0
        private void SetupConfigurationSettingPublisher()
        {
            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            Trace.WriteLine("Setting up configuration setting publishing");
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                RoleEnvironment.Changed += (sender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        // The corresponding configuration setting has changed, propagate the value
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            // In this case, the change to the storage account credentials in the
                            // service configuration is significant enough that the role needs to be
                            // recycled in order to use the latest settings. (for example, the
                            // endpoint has changed)
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Run method to start tomcat process in the worker role instances
        /// </summary>
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("ElasticSearch entry point called", "Information");

            Trace.TraceInformation("Configuring Elastic Search");
            ConfigureElasticSearch();
            Trace.TraceInformation("Configured Elastic Search");

            while (true)
            {
                Thread.Sleep(10000);
                Trace.WriteLine("Working", "Information");

                try
                {
                    if ((_process != null) && _process.HasExited)
                    {
                        _elastic.Log("ElasticSearch Process Exited. Hence recycling role.", "Information");
                        RoleEnvironment.RequestRecycle();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.Message + " " + ex.StackTrace);
                }
            }
        }
Esempio n. 3
0
        void HostControl.Stop()
        {
            _log.Debug("Stop requested by hosted service");

            // this should ask the role to restart
            RoleEnvironment.RequestRecycle();
        }
Esempio n. 4
0
        public override bool OnStart()
        {
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += this.RoleEnvironmentChanging;

            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                RoleEnvironment.Changed += (sender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        // The corresponding configuration setting has changed, propagate the value
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            // In this case, the change to the storage account credentials in the
                            // service configuration is significant enough that the role needs to be
                            // recycled in order to use the latest settings. (for example, the
                            // endpoint has changed)
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });

            return(base.OnStart());
        }
Esempio n. 5
0
        void CatchUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            _log.Fatal("The service threw an unhandled exception", (Exception)e.ExceptionObject);

            HostLogger.Shutdown();

            //            // IF not terminating, then no reason to stop the service?
            //            if (!e.IsTerminating)
            //                return;
            //          This needs to be a configuration option to avoid breaking compatibility

            //   ExitCode = (int)TopshelfExitCode.UnhandledServiceException;
            _unhandledException = e.ExceptionObject as Exception;
            RoleEnvironment.RequestRecycle();

            // it isn't likely that a TPL thread should land here, but if it does let's no block it
            if (Task.CurrentId.HasValue)
            {
                return;
            }

            int deadThreadId = Interlocked.Increment(ref _deadThread);

            Thread.CurrentThread.IsBackground = true;
            Thread.CurrentThread.Name         = "Unhandled Exception " + deadThreadId.ToString();
            while (true)
            {
                Thread.Sleep(TimeSpan.FromHours(1));
            }
        }
Esempio n. 6
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            RoleEnvironment.Changing += RoleEnvironmentChanging;

            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                RoleEnvironment.Changed += (sender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        // The corresponding configuration setting has changed, propagate the value
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });

            return(base.OnStart());
        }
Esempio n. 7
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            Trace.TraceInformation("WorkerRoleCS218 On Start", "Information");
            RoleEnvironment.Changing += RoleEnvironmentChanging;
            RoleEnvironment.Changing += RoleEnvironmentChanging;
            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                RoleEnvironment.Changed += (sender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });
            return(base.OnStart());
        }
Esempio n. 8
0
        protected void Application_Start()
        {
#if AZURESDK
            RoleEnvironment.Changed +=
                (s, a) => { RoleEnvironment.RequestRecycle(); };
#endif
            MaintenanceMode.RefreshIsInMaintainanceMode();

            DatabaseSetup.Initialize();

            container = CreateContainer();

            DependencyResolver.SetResolver(new UnityServiceLocator(container));

            RegisterGlobalFilters(GlobalFilters.Filters);
            RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            AreaRegistration.RegisterAllAreas();
            AppRoutes.RegisterRoutes(RouteTable.Routes);

#if AZURESDK
            if (RoleEnvironment.IsAvailable)
            {
                Trace.Listeners.Add(new DiagnosticMonitorTraceListener());
                Trace.AutoFlush = true;
            }
#endif

            OnStart();
        }
Esempio n. 9
0
        public override bool OnStart()
        {
            DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();

            config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
            config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod         = TimeSpan.FromMinutes(1);
            config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Error;
            DiagnosticMonitor.Start("DiagnosticsConnectionString", config);

            RoleEnvironment.Changing += RoleEnvironmentChanging;
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                RoleEnvironment.Changed += (anotherSender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });

            ChirpManager.Initialize();
            AvatarManager.Initialize();
            ResizeRequestManager.Initialize();

            return(base.OnStart());
        }
Esempio n. 10
0
        public override bool OnStart()
        {
            try
            {
                ServicePointManager.DefaultConnectionLimit = 12;

                RoleEnvironment.Changing += roleEnvironmentChanging;

                m_log = new RenderLog("mergerlog");

                m_engine = new LuxEngine(m_log);
                m_engine.Init();

                m_log.Info("storageAccount created");
                m_dispatcherQueues = new Dictionary <int, MessageQueue <DispetcherMessage> >();
                initQueue();
                m_log.Info("Queue initialized");
                initBlob();
                m_log.Info("Blob initialized");
                m_oneBatchInPercents  = 0;
                m_totalRenderTime     = 0;
                m_percentageCompleted = 0;
                m_log.Info("OnStart successfull");
            }
            catch
            {
                Trace.TraceWarning("Method OnStart() of MergerRole is failed.");
                m_log.Error("Method OnStart() of MergerRole is failed.");
                RoleEnvironment.RequestRecycle();
                return(false);
            }
            return(base.OnStart());
        }
Esempio n. 11
0
        public override bool OnStart()
        {
            DiagnosticMonitor.Start("DiagnosticsConnectionString");

            #region Setup CloudStorageAccount Configuration Setting Publisher

            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                RoleEnvironment.Changed += (sender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        // The corresponding configuration setting has changed, propagate the value
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            // In this case, the change to the storage account credentials in the
                            // service configuration is significant enough that the role needs to be
                            // recycled in order to use the latest settings. (for example, the
                            // endpoint has changed)
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });
            #endregion

            return(base.OnStart());
        }
Esempio n. 12
0
        public override void Run()
        {
            Log("SolrSlaveHostWorkerRole Run() called", "Information");

            while (true)
            {
                Thread.Sleep(10000);

                string masterUrl = HelperLib.Util.GetMasterUrl();
                if (masterUrl != _masterUrl) // master changed?
                {
                    Log("Master Url changed, recycling slave role", "Information");
                    RoleEnvironment.RequestRecycle();
                    return;
                }

                if ((_solrProcess != null) && (_solrProcess.HasExited == true))
                {
                    Log("Solr Process Exited. Hence recycling slave role.", "Information");
                    RoleEnvironment.RequestRecycle();
                    return;
                }

                Log("Working", "Information");
            }
        }
Esempio n. 13
0
        public override bool OnStart()
        {
            try
            {
                ServicePointManager.DefaultConnectionLimit = 12;
                RoleEnvironment.Changing += roleEnvironmentChanging;
                Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
                {
                    configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                });
                // Each render role has own log file
                m_log = new RenderLog("renderlog" + Utils.RoleID().ToString());

                initQueue();
                initBlob();
                initDisk();
                m_log.Info("OnStart successfull");
                m_engine = new LuxEngine(m_log);
                m_engine.Init();
            }
            catch
            {
                m_log.Error("OnStart failed");
                RoleEnvironment.RequestRecycle();
                Trace.TraceWarning("Method OnStart() of WorkerRole is failed.");
                return(false);
            }

            return(base.OnStart());
        }
Esempio n. 14
0
        public override bool OnStart()
        {
            try
            {
                ServicePointManager.DefaultConnectionLimit = 12;

                // For information on handling configuration changes
                // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
                RoleEnvironment.Changing += roleEnvironmentChanging;
                m_threadsID           = new Dictionary <string, int>();
                m_renderAbortHandlers = new Dictionary <int, List <MessageQueue <RenderMessage> > >();
                m_connectionHandlers  = new Dictionary <string, NetMessageHandler>();
                m_log = new RenderLog("dispatcherlog");

                m_log.Info("storageAccount created");
                initQueue();
                m_log.Info("Queue initialized");
                initBlob();
                m_log.Info("Blob initialized");
                m_log.Info("RolesCnt initialized");
                m_scenesId        = SceneID.Get();
                m_instanceManager = InstanceManager.Get(m_log);
                m_log.Info("OnStart completed");
            }
            catch (Exception ex)
            {
                RoleEnvironment.RequestRecycle();    //request role restart
                System.Diagnostics.Trace.TraceWarning("Method OnStart() of WebRole is failed.");
                m_log.Error("Error when initializing: " + ex.Message);
                return(false);
            }

            return(base.OnStart());
        }
Esempio n. 15
0
        private static void SetupEnvironmentChangeHandlers()
        {
            // For information on handling configuration changes see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            #region Setup CloudStorageAccount Configuration Setting Publisher
            // From: http://www.tsjensen.com/blog/2009/11/30/Windows+Azure+10+CloudTableClient+Minimal+Configuration.aspx
            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((string configName, Func <string, bool> configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                RoleEnvironment.Changed += (object sender, RoleEnvironmentChangedEventArgs e) =>
                {
                    if (e.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((RoleEnvironmentConfigurationSettingChange change) => (change.ConfigurationSettingName == configName)))
                    {
                        // The corresponding configuration setting has changed, propagate the value
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            // In this case, the change to the storage account credentials in the
                            // service configuration is significant enough that the role needs to be
                            // recycled in order to use the latest settings. (for example, the
                            // endpoint has changed)
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });
            #endregion
        }
Esempio n. 16
0
        public override bool OnStart()
        {
            DiagnosticMonitor.Start("DiagnosticsConnectionString");

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                RoleEnvironment.Changed += (sender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });

            return(base.OnStart());
        }
Esempio n. 17
0
        public override bool OnStart()
        {
            DiagnosticMonitor.Start("DiagnosticsConnectionString");

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                RoleEnvironment.Changed += (anotherSender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        // The corresponding configuration setting has changed, propagate the value
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            // In this case, the change to the storage account credentials in the
                            // service configuration is significant enough that the role needs to be
                            // recycled in order to use the latest settings. (for example, the
                            // endpoint has changed)
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });

            var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            // Create the table and add some dummy data.
            CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint.AbsoluteUri, account.Credentials);

            tableClient.CreateTableIfNotExist("Person");
            PersonTableStorageContext ctx = new PersonTableStorageContext();
            Person person1 = new Person("DefaultPartition", "Row1")
            {
                Name = "Ared", Age = 24
            };
            Person person2 = new Person("DefaultPartition", "Row2")
            {
                Name = "Lante", Age = 24
            };
            Person person3 = new Person("DefaultPartition", "Row3")
            {
                Name = "Bright", Age = 24
            };

            this.InsertEntityIfNotExist(ctx, person1);
            this.InsertEntityIfNotExist(ctx, person2);
            this.InsertEntityIfNotExist(ctx, person3);

            return(base.OnStart());
        }
Esempio n. 18
0
        private void StartGameService(int retries)
        {
            if (retries == 0)
            {
                RoleEnvironment.RequestRecycle();
                return;
            }

            Trace.TraceInformation("Starting game service host...");

            _serviceHost = new ServiceHost(typeof(GameService));

            _serviceHost.Faulted += (sender, e) =>
            {
                Trace.TraceError("Host fault occured. Aborting and restarting the host. Retry count: {0}", retries);
                _serviceHost.Abort();
                StartGameService(--retries);
            };

            var binding = new NetTcpBinding(SecurityMode.None);

            RoleInstanceEndpoint externalEndPoint =
                RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["GameServer"];
            RoleInstanceEndpoint mexpEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["mexport"];

            var metadatabehavior = new ServiceMetadataBehavior();

            _serviceHost.Description.Behaviors.Add(metadatabehavior);

            Binding mexBinding     = MetadataExchangeBindings.CreateMexTcpBinding();
            string  mexendpointurl = string.Format("net.tcp://{0}/GameServerMetadata", mexpEndPoint.IPEndpoint);

            _serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, mexendpointurl);

            _serviceHost.AddServiceEndpoint(
                typeof(IGameService),
                binding,
                string.Format("net.tcp://{0}/GameServer", externalEndPoint.IPEndpoint));

            try
            {
                _serviceHost.Open();
                Trace.TraceInformation("Game service host started successfully.");
            }
            catch (TimeoutException timeoutException)
            {
                Trace.TraceError(
                    "The service operation timed out. {0}",
                    timeoutException.Message);
            }
            catch (CommunicationException communicationException)
            {
                Trace.TraceError(
                    "Could not start game service host. {0}",
                    communicationException.Message);
            }
        }
Esempio n. 19
0
 void RoleEnvironment_Changed(object sender, RoleEnvironmentChangedEventArgs e)
 {
     WorkerTrace.TraceEvent(TraceEventType.Information, 18, "Role configuration has been changed. Requesting instance recycle");
     if (current != null)
     {
         current.Abandon();
     }
     Thread.Sleep(25); //waiting for logs transfer
     RoleEnvironment.RequestRecycle();
 }
Esempio n. 20
0
        /// <summary>
        /// This method is to restart the role instance when a configuration setting is changing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            // If a configuration setting is changing
            if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
            {
                RoleEnvironment.RequestRecycle();

                // Set e.Cancel to true to restart this role instance
                e.Cancel = true;
            }
        }
Esempio n. 21
0
        public override bool OnStart()
        {
            string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";

            RoleInstanceDiagnosticManager roleInstanceDiagnosticManager =
                CloudAccountDiagnosticMonitorExtensions.CreateRoleInstanceDiagnosticManager(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString),
                                                                                            RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name,
                                                                                            RoleEnvironment.CurrentRoleInstance.Id);


            DiagnosticMonitorConfiguration config = roleInstanceDiagnosticManager.GetCurrentConfiguration();

            // should never be null, but this is a fallback in case it is. I recommend removing this in a production
            // deployment
            if (null == config)
            {
                config = DiagnosticMonitor.GetDefaultInitialConfiguration();
            }

            config.Logs.ScheduledTransferPeriod         = TimeSpan.FromMinutes(15);
            config.Logs.ScheduledTransferLogLevelFilter = Microsoft.WindowsAzure.Diagnostics.LogLevel.Undefined;
            config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = Microsoft.WindowsAzure.Diagnostics.LogLevel.Warning;
            config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod         = TimeSpan.FromMinutes(15);
            config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(15);

            roleInstanceDiagnosticManager.SetCurrentConfiguration(config);
            System.Diagnostics.Trace.TraceInformation("Diagnostics Running");

            #region Setup CloudStorageAccount Configuration Setting Publisher

            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            RoleEnvironment.Changed += (sender, arg) =>
            {
                var key = CloudConfigurationManager.GetSetting(arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>().ToString());
                if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                    .Any((change) => (change.ConfigurationSettingName == key.ToString())))
                {
                    // The corresponding configuration setting has changed, propagate the value
                    RoleEnvironment.GetConfigurationSettingValue(key.ToString());
                    // {
                    // In this case, the change to the storage account credentials in the
                    // service configuration is significant enough that the role needs to be
                    // recycled in order to use the latest settings. (for example, the
                    // endpoint has changed)
                    RoleEnvironment.RequestRecycle();
                    //}
                }
            };
            //});
            #endregion
            return(base.OnStart());
        }
Esempio n. 22
0
        public override bool OnStart()
        {
            try
            {
                DiagnosticMonitorConfiguration diagConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
                //diagConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);
                diagConfig.Logs.ScheduledTransferPeriod         = TimeSpan.FromMinutes(1);
                diagConfig.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

                DiagnosticMonitor.Start("DataConnectionString", diagConfig);

                // For information on handling configuration changes
                // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
                RoleEnvironment.Changing += RoleEnvironmentChanging;

                // This code sets up a handler to update CloudStorageAccount instances when their corresponding
                // configuration settings change in the service configuration file.

                // This code sets up a handler to update CloudStorageAccount instances when their corresponding
                // configuration settings change in the service configuration file.
                CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
                {
                    // Provide the configSetter with the initial value
                    configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                    RoleEnvironment.Changed += (s, arg) =>
                    {
                        if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                            .Any((change) => (change.ConfigurationSettingName == configName)))
                        {
                            // The corresponding configuration setting has changed, propagate the value
                            if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                            {
                                // In this case, the change to the storage account credentials in the
                                // service configuration is significant enough that the role needs to be
                                // recycled in order to use the latest settings. (for example, the
                                // endpoint has changed)
                                RoleEnvironment.RequestRecycle();
                            }
                        }
                    };
                });

                var azureTraceListener = new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener();

                Trace.Listeners.Add(azureTraceListener);
            }
            catch (Exception)
            {
            }
            return(base.OnStart());
        }
Esempio n. 23
0
        protected void Application_Start(object sender, EventArgs e)
        {
            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                RoleEnvironment.Changed += (anotherSender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        // The corresponding configuration setting has changed, propagate the value
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            // In this case, the change to the storage account credentials in the
                            // service configuration is significant enough that the role needs to be
                            // recycled in order to use the latest settings. (for example, the
                            // endpoint has changed)
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });

            var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            // Create the table and add some dummy data.
            CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint.AbsoluteUri, account.Credentials);

            tableClient.CreateTableIfNotExist("Person");
            PersonTableStorageContext ctx = new PersonTableStorageContext();
            Person person1 = new Person("DefaultPartition", "Row1")
            {
                Name = "Ared", Age = 24
            };
            Person person2 = new Person("DefaultPartition", "Row2")
            {
                Name = "Lante", Age = 24
            };
            Person person3 = new Person("DefaultPartition", "Row3")
            {
                Name = "Bright", Age = 24
            };

            this.InsertEntityIfNotExist(ctx, person1);
            this.InsertEntityIfNotExist(ctx, person2);
            this.InsertEntityIfNotExist(ctx, person3);
        }
Esempio n. 24
0
        public static void RequestRecycleIfConfigSettingChanged(ConfigSettings config)
        {
            RoleEnvironment.Changing += (_, e) =>
            {
                var shouldRecycle = e.Changes
                                    .OfType <RoleEnvironmentConfigurationSettingChange>()
                                    .Any(c => config.IsConfigSettingName(c.ConfigurationSettingName));

                if (shouldRecycle)
                {
                    RoleEnvironment.RequestRecycle();
                }
            };
        }
Esempio n. 25
0
        static void OnRoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            // we restart all workers if the configuration changed (e.g. the storage account)
            // for now.

            // We do not request a recycle if only the topology changed,
            // e.g. if some instances have been removed or added.
            var configChanges = e.Changes.OfType <RoleEnvironmentConfigurationSettingChange>();

            if (configChanges.Any())
            {
                RoleEnvironment.RequestRecycle();
            }
        }
        private void StartWCFService(int retries)
        {
            // recycle the role if host cannot be started
            // after the specified number of retries
            if (retries == 0)
            {
                RoleEnvironment.RequestRecycle();
                return;
            }

            Trace.TraceInformation("Starting notification service host...");

            this.serviceHost = new ServiceHost(typeof(NotificationService));

            // Recover the service in case of failure.
            // Log the fault and attempt to restart the service host.
            this.serviceHost.Faulted += (sender, e) =>
            {
                Trace.TraceError("Host fault occured. Aborting and restarting the host. Retry count: {0}", retries);
                this.serviceHost.Abort();
                this.StartWCFService(--retries);
            };

            // use NetTcpBinding with no security
            NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);

            // define an external endpoint for client traffic
            RoleInstanceEndpoint externalEndPoint =
                RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["NotificationService"];

            this.serviceHost.AddServiceEndpoint(
                typeof(INotificationService),
                binding,
                String.Format("net.tcp://{0}/NotificationService", externalEndPoint.IPEndpoint));

            try
            {
                this.serviceHost.Open();
                Trace.TraceInformation("Chat service host started successfully.");
            }
            catch (TimeoutException timeoutException)
            {
                Trace.TraceError("The service operation timed out. {0}", timeoutException.Message);
            }
            catch (CommunicationException communicationException)
            {
                Trace.TraceError("Could not start chat service host. {0}", communicationException.Message);
            }
        }
Esempio n. 27
0
        public override bool OnStart()
        {
            /*
             * var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
             *
             * config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Error;
             * config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);
             * // Start the diagnostic monitor with the modified configuration.
             * DiagnosticMonitor.Start("DiagnosticsConnectionString", config);
             *
             * DiagnosticMonitor.AllowInsecureRemoteConnections = true;
             *
             * // enable collection of crashdumps
             * CrashDumps.EnableCollection(true);
             */
            #region Setup CloudStorageAccount Configuration Setting Publisher

            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                RoleEnvironment.Changed += (sender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        // The corresponding configuration setting has changed, propagate the value
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            // In this case, the change to the storage account credentials in the
                            // service configuration is significant enough that the role needs to be
                            // recycled in order to use the latest settings. (for example, the
                            // endpoint has changed)
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });
            #endregion

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            return(base.OnStart());
        }
Esempio n. 28
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 48;
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            try
            {
                Trace.WriteLine("OnStart:System is starting up", "Information");
                var    endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Http"].IPEndpoint;
                string param;
                if (!AzureSettingsProvider.TryGetString("params", out param))
                {
                    param = "";
                }

                var options = new NodeOptions();
                if (!CommandLineParser.Default.ParseArguments(param.Split(' '), options))
                {
                    throw new Exception("Failed to parse: " + param);
                }

                options.HttpPort    = endpoint.Port;
                options.LocalHttpIp = endpoint.Address.ToString();

                // Uncomment these lines and class BlobTraceListener to write traces into blob.
                //var parts = options.StoreLocation.Split('|');
                //var account = CloudStorageAccount.Parse(parts[0]);
                //var client = account.CreateCloudBlobClient();
                //var container = client.GetContainerReference(parts[1]);
                //var blobListener = new BlobTraceListener(container.GetBlobReference("log.txt"));
                //Trace.Listeners.Add(blobListener);

                Trace.WriteLine("");
                Trace.WriteLine(string.Format("Listening endpoint http://{0}:{1}/", endpoint.Address, endpoint.Port), "Information");

                _entryPoint = NodeEntryPoint.StartWithOptions(options, i => RoleEnvironment.RequestRecycle());
            }
            catch (Exception ex)
            {
                Trace.WriteLine("OnStart:Failed " + ex, "Information");
                throw;
            }

            var result = base.OnStart();

            Trace.WriteLine("OnStart:Exit");
            return(result);
        }
Esempio n. 29
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            #region Setup CloudStorageAccount Configuration Setting Publisher

            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

                RoleEnvironment.Changed += (sender, arg) =>
                {
                    if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        // The corresponding configuration setting has changed, propagate the value
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            // In this case, the change to the storage account credentials in the
                            // service configuration is significant enough that the role needs to be
                            // recycled in order to use the latest settings. (for example, the
                            // endpoint has changed)
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });

            #endregion

            // load up the desired image sizes
            var imageSizes = RoleEnvironment.GetConfigurationSettingValue("ImageSizes");
            foreach (var size in imageSizes.Split(','))
            {
                var dims = size.Split('x');
                _imageSizes.Add(new Size(Int32.Parse(dims[0]), Int32.Parse(dims[1])));
            }

            return(base.OnStart());
        }
Esempio n. 30
0
        public override bool OnStart()
        {
            Log("SolrSlaveHostWorkerRole Start() called", "Information");

            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            RoleEnvironment.Changing += (sender, arg) =>
            {
                RoleEnvironment.RequestRecycle();
            };

            InitDiagnostics();
            StartSolr();

            return(base.OnStart());
        }