Пример #1
0
        private void BuildMaintenanceActionMap()
        {
            // if users specify a generic command. E.g. Reboot, then apply the config setting policy and determine
            // whether to apply it on the VM or on the Host
            InfrastructureServiceMaintenanceAction reboot =
                GetMappedMaintenanceAction(ConfigRebootMaintenanceActionKeyName, InfrastructureServiceMaintenanceAction.Reboot);
            InfrastructureServiceMaintenanceAction repaveData =
                GetMappedMaintenanceAction(ConfigFullReimageMaintenanceActionKeyName, InfrastructureServiceMaintenanceAction.RepaveData);

            AddMaintenanceAction(reboot, AbstractRebootMaintenanceAction);
            AddMaintenanceAction(repaveData, AbstractFullReimageMaintenanceAction);

            // There is no Host/VM target for ReimageOS currently. It is just applicable to VMs
            AddMaintenanceAction(InfrastructureServiceMaintenanceAction.ReimageOS);

            // if users specify the command explicitly. E.g. System.Azure.Reboot, then apply the foll. irrespective of the
            // *MaintenanceAction config setting
            // Note: Unlike ReimageOS above, we haven't added a generic 'Heal' action. Instead users have to specify this explicitly
            AddMaintenanceActionWithNamespace(InfrastructureServiceMaintenanceAction.Reboot);
            AddMaintenanceActionWithNamespace(InfrastructureServiceMaintenanceAction.ReimageOS);
            AddMaintenanceActionWithNamespace(InfrastructureServiceMaintenanceAction.RepaveData);
            AddMaintenanceActionWithNamespace(InfrastructureServiceMaintenanceAction.HostReboot);
            AddMaintenanceActionWithNamespace(InfrastructureServiceMaintenanceAction.HostRepaveData);
            AddMaintenanceActionWithNamespace(InfrastructureServiceMaintenanceAction.Heal);
        }
Пример #2
0
        /// <summary>
        /// This method adds a generic maintenance action to a map of known actions.
        /// This allows users to specify a simpler maintenance action string e.g. 'Reboot' which then gets mapped to either
        /// System.Azure.Reboot or System.Azure.HostReboot based on configuration settings.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="command">The command.</param>
        private void AddMaintenanceAction(InfrastructureServiceMaintenanceAction action, string command = null)
        {
            string key = string.Format(CultureInfo.InvariantCulture, SystemActionFormat, command ?? action.ToString());

            maintenanceActionMap.Add(key, action);

            Trace.WriteInfo(TraceType, "Enabled execution of repair command: {0} with action: {1}", key, action);
        }
Пример #3
0
        /// <summary>
        /// Gets a config setting that governs on what target (currently supported are Host or VM) we execute the maintenance action.
        /// </summary>
        /// <param name="configKeyName">Name of the configuration key.</param>
        /// <param name="defaultValue">The default value to be used if we are unable to get it from the config setting.</param>
        /// <returns>
        /// The config setting value.
        /// </returns>
        private InfrastructureServiceMaintenanceAction GetMappedMaintenanceAction(
            string configKeyName,
            InfrastructureServiceMaintenanceAction defaultValue)
        {
            var action = coordinator.ReadConfigValue(configKeyName, defaultValue);

            Trace.WriteInfo(TraceType, "Maintenance action for key name: {0} maps to: {1}", configKeyName, action);

            return(action);
        }
Пример #4
0
 public void RequestMaintenance(string roleInstanceName, InfrastructureServiceMaintenanceAction action, string reason, string contextId)
 {
     if (RequestMaintenanceAction == null)
     {
         DefaultRequestMaintenanceAction(roleInstanceName, action, reason, contextId);
     }
     else
     {
         RequestMaintenanceAction(roleInstanceName, action, reason, contextId);
     }
 }
Пример #5
0
        /// <summary>
        /// Maps the action object from <see cref="InfrastructureServiceMaintenanceAction" /> to <see cref="MaintenanceAction" />
        /// and invokes the MR API to request maintenance by Azure of the role instance.
        /// </summary>
        /// <param name="roleInstance">The role instance.</param>
        /// <param name="action">The action.</param>
        /// <param name="reason">The reason for requesting the action.</param>
        /// <param name="contextId">An optional context string that will be attached to the MR job resulting from this request.</param>
        /// <exception cref="System.InvalidOperationException">If <c>action</c> cannot map to a valid MR maintenance request.</exception>
        /// <exception cref="ManagementException">If there was an error from MR while requesting maintenance.</exception>
        private static void RequestMaintenance(
            ManagementRoleInstance roleInstance,
            InfrastructureServiceMaintenanceAction action,
            string reason,
            string contextId)
        {
            Trace.WriteInfo(TraceType, "Requesting maintenance. Roleinstance Id: {0}, action: {1}, reason: {2}, context: {3}", roleInstance.Id, action, reason, contextId);

            switch (action)
            {
            case InfrastructureServiceMaintenanceAction.Exclude:
            case InfrastructureServiceMaintenanceAction.Reboot:
            case InfrastructureServiceMaintenanceAction.ReimageOS:
            case InfrastructureServiceMaintenanceAction.RepaveData:
            case InfrastructureServiceMaintenanceAction.HostReboot:
            case InfrastructureServiceMaintenanceAction.HostRepaveData:
            case InfrastructureServiceMaintenanceAction.Heal:
                try
                {
                    roleInstance.RequestMaintenance(action.ToString(), reason, false, contextId);

                    Trace.WriteInfo(
                        TraceType,
                        "Successfully requested maintenance. Roleinstance Id: {0}, action: {1}, reason: {2}, context = {3}",
                        roleInstance.Id,
                        action,
                        reason,
                        contextId);
                }
                catch (Exception ex)
                {
                    string message = string.Format(
                        CultureInfo.InvariantCulture,
                        "Error while requesting maintenance. Roleinstance Id: {0}, action: {1}, reason: {2}, context: {3}, exception: {4}",
                        roleInstance.Id,
                        action,
                        reason,
                        contextId,
                        ex);

                    Trace.WriteWarning(TraceType, message);

                    throw new ManagementException(message, ex);
                }

                break;

            default:
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unexpected InfrastructureServiceMaintenanceAction: {0}", action));
            }
        }
Пример #6
0
        /// <summary>
        /// Requests a maintenance action to Azure through the management protocol (MR).
        /// </summary>
        /// <param name="roleInstanceName">Name of the role instance.</param>
        /// <param name="action">The action.</param>
        /// <param name="reason">The reason.</param>
        /// <param name="contextId">An optional context string that will be attached to the MR job resulting from this request.</param>
        /// <exception cref="KeyNotFoundException">
        /// If the role instance for the specified <c>roleInstanceName</c> is not found.
        /// </exception>
        /// <exception cref="ManagementException">
        /// If there was an error from MR while requesting maintenance.
        /// </exception>
        /// <exception cref="InvalidOperationException">If <c>action</c> cannot map to a valid MR maintenance request.</exception>
        public void RequestMaintenance(string roleInstanceName, InfrastructureServiceMaintenanceAction action, string reason, string contextId)
        {
            ManagementRoleInstance roleInstance;

            IDictionary <string, ManagementRoleInstance> roleInstances;

            try
            {
                roleInstances = this.client.ListRoleInstances();
            }
            catch (Exception ex)
            {
                string message = string.Format(
                    CultureInfo.InvariantCulture,
                    "Error getting role instances. Roleinstance name: {0}, action: {1}, reason: {2}, exception: {3}",
                    roleInstanceName,
                    action,
                    reason,
                    ex);

                Trace.WriteWarning(TraceType, message);

                throw new ManagementException(message, ex);
            }

            // null check not necessary
            if (!roleInstances.TryGetValue(roleInstanceName, out roleInstance))
            {
                // not the best exception type to throw.. but suffices
                throw new KeyNotFoundException(
                          string.Format(CultureInfo.InvariantCulture, "Unable to get role instance info for role instance name: {0}", roleInstanceName));
            }

            // Truncate reason, API does not accept reasons over 255 characters
            if (reason != null && reason.Length > 255)
            {
                reason = reason.Substring(0, 255);
            }

            // ContextId max length = 512, according to MR SDK. Do not silently truncate
            // because it is used as a key to match jobs to repair tasks.
            RequestMaintenance(roleInstance, action, string.IsNullOrWhiteSpace(reason) ? "<null>" : reason, contextId);
        }
Пример #7
0
 private static void DefaultRequestMaintenanceAction(string roleInstanceName,
                                                     InfrastructureServiceMaintenanceAction action, string reason, string contextId)
 {
 }
Пример #8
0
        /// <summary>
        /// This method is used to create an explicit maintenance action. E.g. System.Azure.HostReboot.
        /// </summary>
        /// <param name="action">The action.</param>
        private void AddMaintenanceActionWithNamespace(InfrastructureServiceMaintenanceAction action)
        {
            string command = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", ActionNamespaceAzure, action);

            AddMaintenanceAction(action, command);
        }