Example #1
0
 /// <summary>
 /// Event handler called when an environment change is to be applied to the role.
 /// Determines whether or not the role instance must be recycled.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The list of changed environment values.</param>
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     // If Azure should recycle the role, e.Cancel should be set to true.
     // If the changes are ones we can handle without a recycle, we set it to false.
     e.Cancel = this.RecycleConfiguration(e.Changes);
     Trace.WriteLine("WebRole environment change - role instance recycling: " + e.Cancel.ToString());
 }
Example #2
0
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     // If a configuration setting is changing
     if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
         // set e.Cancel to true to restart this role instance
         e.Cancel = true;
 }
 private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
     {
         e.Cancel = true;
     }
 }
        private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            if (!e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange)) return;

            Trace.WriteLine("Working", "Environment Change: " + e.Changes.ToList());
            e.Cancel = true;
        }
Example #5
0
        //Event Handler
        public void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            var changes = from ch in e.Changes.OfType<RoleEnvironmentTopologyChange>()
                          select ch;
            if (changes.Any())
            {
                const string semaphoreName = "SemaphoreShutDown";
                Semaphore sem = null;

                // Attempt to open the named semaphore.
                try
                {
                    sem = Semaphore.OpenExisting(semaphoreName);
                }
                catch (WaitHandleCannotBeOpenedException)
                {
                    return;
                }
                sem.Release(1);

                //Note this may be superfulous, as this event may be running on a non-blocking thread.  To be investigated.
                //If a blocking thread, this gives some time for IIS to complete its shutdown, based on the semaphore release
                //above.  
                Thread.Sleep(20000);
            }
        }
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     //Are any of the environment changes a configuration setting change? If so, cancel the event and restart the role
     if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
     {
         e.Cancel = true;
     }
 }
Example #7
0
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     e.Cancel = false; // don't restart for configuration changes
     /*if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
     {
         e.Cancel = true;
     }*/
 }
Example #8
0
 static void RoleEnvironment_Changing(object sender, RoleEnvironmentChangingEventArgs e)
 {
     if (e.Changes.OfType<RoleEnvironmentConfigurationSettingChange>().Count() > 0)
     {
         // Cancel the changing event to force role instance restart
         //e.Cancel = true;
     }
 }
Example #9
0
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     // �������������ֵ�仯
     if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
     {
         // ��e.Cancel��Ϊtrue���������ɫʵ��
         e.Cancel = true;
     }
 }
Example #10
0
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     // 如果配置设置改变
     if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
     {
         // 设置e.Cancel为真重启角色实例
         e.Cancel = true;
     }
 }
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     // for any configuration setting change except EnableTableStorageTraceListener
     if (e.Changes.OfType<RoleEnvironmentConfigurationSettingChange>().Any(change => change.ConfigurationSettingName != "EnableTableStorageTraceListener"))
     {
         // Set e.Cancel to true to restart this role instance
         e.Cancel = true;
     }
 }
Example #12
0
        static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            var i = 1;
            foreach (var c in e.Changes)
                Trace.WriteLine(string.Format("RoleEnvironmentChanging: #{0} Type={1} Change={2}", i++, c.GetType().FullName, c));

            if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
                e.Cancel = true;
        }
 private void HandleRoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     foreach(var c in e.Changes.OfType<RoleEnvironmentTopologyChange>())
     {
         if (c.RoleName.Equals(AzureConstants.StoreWorkerRoleName))
         {
             Trace.TraceInformation("BrightstarCluster: Received RoleEnvironmentTopologyChange event. Updating store worker client list");
             UpdateClientList();
         }
     }
 }
Example #14
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();
            }
        }
Example #15
0
        private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            int i = 1;
            foreach (var c in e.Changes)
            {
                Trace.WriteLine(string.Format("RoleEnvironmentChanging: #{0} Type={1} Change={2}", i++, c.GetType().FullName, c));
            }

            // If a configuration setting is changing);
            if (e.Changes.Any((RoleEnvironmentChange change) => change is RoleEnvironmentConfigurationSettingChange))
            {
                // Set e.Cancel to true to restart this role instance
                e.Cancel = true;
            }
        }
Example #16
0
        void RoleEnvironment_Changing(object sender, RoleEnvironmentChangingEventArgs e)
        {
            Trace.TraceInformation("Change notification");

            if (e.Changes.OfType<RoleEnvironmentConfigurationSettingChange>()
                .Any(c => !string.Equals(c.ConfigurationSettingName, MvcApplication.AzureLoggingVerbositySettingName, StringComparison.Ordinal)))
            {
                Trace.TraceInformation("Cancelling instance");
                e.Cancel = true;
            }
            else
            {
                Trace.TraceInformation("Handling change without recycle");
            }
        }
 private void OnChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     foreach (var change in e.Changes)
     {
         var configChange = change as RoleEnvironmentConfigurationSettingChange;
         if (configChange != null)
         {
             if (configChange.ConfigurationSettingName == "DatabaseConnectionString")
             {
                 // Our database connectionstring changed.
                 // Maybe we need to restart the instance to make sure our cached objects no longer use the previous value.
                 e.Cancel = true;
             }
         }
     }
 }
Example #18
0
        private void RoleEnvironmentOnChanging(object sender, RoleEnvironmentChangingEventArgs roleEnvironmentChangingEventArgs)
        {
            // In order to handle changing configuration
            // this can be avoided if the config is not "singleton" but it is recreated via this event
            // https://msdn.microsoft.com/en-us/library/azure/gg432963.aspx
            // https://alexandrebrisebois.wordpress.com/2013/09/29/handling-cloud-service-role-configuration-changes-in-windows-azure/

            var configurationChanges = roleEnvironmentChangingEventArgs.Changes
                                    .OfType<RoleEnvironmentConfigurationSettingChange>()
                                    .ToList();

            if (!configurationChanges.Any())
            {
                return;
            }

            // TODO for specific settings which are uesd to instantiate any cached objects
            //if(configurationChanges.Any(c => c.ConfigurationSettingName == "StorageAccount"))
            roleEnvironmentChangingEventArgs.Cancel = true;
        }
Example #19
0
        private void RoleEnvironment_Changing(object sender, RoleEnvironmentChangingEventArgs e)
        {
            var changedSettings = e.Changes.OfType<RoleEnvironmentConfigurationSettingChange>()
                                            .Select(c => c.ConfigurationSettingName).ToList();

            Trace.TraceInformation("Configuration Changing notification. Settings being changed: "
                + string.Join(", ", changedSettings));

            if (changedSettings
                .Any(settingName => !string.Equals(settingName, CustomSettingName, StringComparison.Ordinal)))
            {
                Trace.TraceInformation("Cancelling dynamic configuration change (restarting).");

                // Setting this to true will restart the role gracefully. If Cancel is not set to true,
                // and the change is not handled by the application, then the application will not use
                // the new value until it is restarted (either manually or for some other reason).
                e.Cancel = true;
            }
            else
            {
                Trace.TraceInformation("Handling configuration change without restarting.");
            }
        }
        private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            Boolean recycle = false;
            foreach (RoleEnvironmentChange change in e.Changes)
            {
                RoleEnvironmentTopologyChange topologyChange = change as RoleEnvironmentTopologyChange;
                if (topologyChange != null)
                {
                    String roleName = topologyChange.RoleName;
                    ReadOnlyCollection<RoleInstance> oldInstances = RoleEnvironment.Roles[roleName].Instances;
                }
                RoleEnvironmentConfigurationSettingChange settingChange = change as RoleEnvironmentConfigurationSettingChange;
                if (settingChange != null)
                {
                    String settingName = settingChange.ConfigurationSettingName;
                    String oldValue = RoleEnvironment.GetConfigurationSettingValue(settingName);
                    recycle |= settingName == "SettingRequiringRecycle";
                }
            }

            // Recycle when e.Cancel = true;
            e.Cancel = recycle;
        }
Example #21
0
 /// <summary>
 /// Force restart of the instance.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void OnRoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     if (e.Changes.Any(o => o is RoleEnvironmentChange))
         e.Cancel = true;
 }
Example #22
0
        private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            Trace.TraceInformation("RoleEnvironmentChanging Event Fired");

            var changes = e.Changes
                           .OfType<RoleEnvironmentConfigurationSettingChange>()
                           .ToList();

            if (!changes.Any())
            {
                return;
            }

            e.Cancel = true; // Instruct server to reboot on change (if not canceled below)

            // TODO: Implement (for now just repboot server)
            //// Service Bus Connection Strings Updated
            //if (changes.Any(c => c.ConfigurationSettingName == ServiceBus.FrontendServiceBusConnectionStringName))
            //{
            //    e.Cancel = false; // Cancel reboot of server
            //}
            //if (changes.Any(c => c.ConfigurationSettingName == ServiceBus.WorkerServiceBusConnectionStringName))
            //{
            //    e.Cancel = false; // Cancel reboot of server
            //}
        }
Example #23
0
 //Event Handler
 public void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     /*var changes = from ch in e.Changes.OfType<RoleEnvironmentTopologyChange>()
                   select ch;
     if (changes.Any())
     {
         myHost.deActivateHosts();
         ConfigUtility.writeConsoleMessage("\nWorker Role OnStop: Node ID: " + AzureUtility.getRoleInstanceID() + " Has Shut Down. Goodbye!\n", EventLogEntryType.Warning, true, new Sample.HelloServiceSettings.Settings()); 
     }*/
 }
Example #24
0
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     // If a user configuration setting is changing
     if ((from change in e.Changes.OfType<RoleEnvironmentConfigurationSettingChange>()
          where !(change.ConfigurationSettingName.StartsWith("Microsoft.WindowsAzure.Plugins.RemoteAccess.") ||
                  change.ConfigurationSettingName.StartsWith("Microsoft.WindowsAzure.Plugins.RemoteForwarder."))
          select change).Any())
     {
         // Set e.Cancel to true to restart this role instance
         e.Cancel = true;
     }
 }
Example #25
0
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     // 如果一个配置环境发生变化
     if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
     {
         // 将e.Cancel设为true重启这个角色实例
         e.Cancel = true;
     }
 }
Example #26
0
 private void RoleEnvironment_Changing(object sender, RoleEnvironmentChangingEventArgs e)
 {
     // Setting cancel to false indicates that this instance should _not_ be restarted
     // in response to the configuration change.
     e.Cancel = Config.Get().OnConfigurationChanging(e.Changes);
     if (e.Cancel)
     {
         Log.TraceInformation("Role will be restarted due to configuration change");
     }
 }
Example #27
0
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     Func<RoleEnvironmentConfigurationSettingChange, bool> changeIsExempt =
         x => !Settings.ExemptConfigurationItems.Contains(x.ConfigurationSettingName);
     var environmentChanges = e.Changes.OfType<RoleEnvironmentConfigurationSettingChange>();
     e.Cancel = environmentChanges.Any(changeIsExempt);
     DiagnosticsHelper.TraceInformation(string.Format("Role config changing. Cancel set to {0}",
         e.Cancel));
 }
Example #28
0
        /// <summary>
        /// RoleEventChanging - Called when a change is about to be applied to the role.  Determines whether or not to recycle the role instance.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">A list of what is changing</param>
        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            // Note: e.Cancel == true -> Azure should recycle the role.  If all the changes are in our "exempt" list,
            // we don't need to recycle the role.

            e.Cancel = HasNonExemptConfigurationChanges(e.Changes);

            // Note that we use Trace.WriteLine here rather than going through the Diagnostics class so that we will always log
            // this, even when the switch for whether to log or not is being changed.

            if (!e.Cancel)
            {
                Trace.WriteLine("WebRoleDiagnostics::RoleEnvironmentChanging - role is not recycling, getting new switch values from config file.");
            }
            else
            {
                Trace.WriteLine("WebRoleDiagnostics::RoleEnvironmentChanging - recycling role instance due to non-exempt configuration changes.");
            }
        }
Example #29
0
        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            Tracer.WriteLine("RoleEnvironmentChanging", "Information");
            log.WriteEntry("RoleEnvironmentChanging", "", GetLabel());

            // Don't object to any role environment changes
            // See RoleEnvironmentChanged for our attempt to cope with the changes
        }
Example #30
0
 private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 {
     e.Cancel = false;
 }