Ejemplo n.º 1
0
        /// <summary>
        /// Escalates the impact category if the estimated impact duration equals or exceeds the given threshold.
        /// </summary>
        /// <param name="oldCategory">The current impact category.</param>
        /// <param name="impactDetail">The impact detail.</param>
        /// <param name="configKeyName">The key of the configuration setting containing the duration threshold value.</param>
        /// <param name="defaultThresholdInSeconds">The default duration threshold value.</param>
        /// <param name="escalateToCategory">The category to escalate to if the threshold is exceeded.</param>
        /// <returns>The new impact category.</returns>
        private ImpactCategory ApplyImpactDurationThreshold(
            ImpactCategory oldCategory,
            AffectedResourceImpact impactDetail,
            string configKeyName,
            int defaultThresholdInSeconds,
            ImpactCategory escalateToCategory)
        {
            ImpactCategory newCategory = oldCategory;

            int thresholdInSeconds = this.configSection.ReadConfigValue(configKeyName, defaultThresholdInSeconds);

            if (impactDetail.EstimatedImpactDurationInSeconds >= thresholdInSeconds)
            {
                newCategory = EscalateImpactCategory(oldCategory, escalateToCategory);

                if (oldCategory != newCategory)
                {
                    tracer.WriteNoise(
                        "Overall impact changed from {0} to {1} due to impact duration of {2} sec (threshold = {3} sec)",
                        oldCategory,
                        newCategory,
                        impactDetail.EstimatedImpactDurationInSeconds,
                        thresholdInSeconds);
                }
            }

            return(newCategory);
        }
Ejemplo n.º 2
0
 public MockImpactInfo()
 {
     ImpactedResources = new AffectedResourceImpact
     {
         ListOfImpactTypes = new List <ImpactTypeEnum>(),
     };
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Translates AffectedResourceImpact to an ImpactCategory.
        /// </summary>
        private ImpactCategory TranslateImpactDetailToCategory(AffectedResourceImpact impactDetail)
        {
            ImpactCategory currentCategory = ImpactCategory.NoImpact;

            // Translate each resource
            currentCategory = ApplyResourceImpact(currentCategory, "Compute", impactDetail.ComputeImpact);
            currentCategory = ApplyResourceImpact(currentCategory, "Disk", impactDetail.DiskImpact);
            currentCategory = ApplyResourceImpact(currentCategory, "Network", impactDetail.NetworkImpact);
            currentCategory = ApplyResourceImpact(currentCategory, "OS", impactDetail.OSImpact);
            currentCategory = ApplyResourceImpact(currentCategory, "ApplicationConfig", impactDetail.ApplicationConfigImpact);

            // Freeze impact of unknown duration should be escalated to a restart
            currentCategory = ApplyUnknownDurationFreezeRule(currentCategory, impactDetail);

            // If there is any impact, escalate based on estimated impact duration
            if (currentCategory != ImpactCategory.NoImpact)
            {
                currentCategory = ApplyImpactDurationThreshold(
                    currentCategory,
                    impactDetail,
                    ConfigKeyDataDestructiveDurationThreshold,
                    DefaultDataDestructiveDurationThreshold,
                    ImpactCategory.DataDestructive);

                currentCategory = ApplyImpactDurationThreshold(
                    currentCategory,
                    impactDetail,
                    ConfigKeyRestartDurationThreshold,
                    DefaultRestartDurationThreshold,
                    ImpactCategory.Restart);
            }

            return(currentCategory);
        }
Ejemplo n.º 4
0
        private void ProcessScriptLine(int lineNumber, string line)
        {
            // Comment/empty lines
            if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line))
            {
                return;
            }

            // Clear configuration
            if (line.StartsWith("!clear"))
            {
                configStore.ClearKeys();
                Console.WriteLine("Config cleared");
                return;
            }

            // Set configuration
            var match = Regex.Match(line, @"^!set (?<key>[^=]+)=(?<value>.*)");

            if (match.Success)
            {
                string configKey   = match.Groups["key"].Value;
                string configValue = match.Groups["value"].Value;
                configStore.UpdateKey(ConfigSectionName, configKey, configValue);
                Console.WriteLine("Set config: {0}={1}", configKey, configValue);
                return;
            }

            // Run test case

            var fields = line.Split(',');

            var action = (ImpactActionEnum)Enum.Parse(typeof(ImpactActionEnum), fields[0]);

            var impact = new AffectedResourceImpact()
            {
                ComputeImpact                    = (Impact)Enum.Parse(typeof(Impact), fields[1]),
                DiskImpact                       = (Impact)Enum.Parse(typeof(Impact), fields[2]),
                NetworkImpact                    = (Impact)Enum.Parse(typeof(Impact), fields[3]),
                OSImpact                         = (Impact)Enum.Parse(typeof(Impact), fields[4]),
                ApplicationConfigImpact          = (Impact)Enum.Parse(typeof(Impact), fields[5]),
                EstimatedImpactDurationInSeconds = long.Parse(fields[6]),
            };

            string expectedResultString = fields[7];
            string message = string.Format("Line {0}: {1}", lineNumber, line);

            if (expectedResultString.StartsWith("!"))
            {
                AssertThrowsException <Exception>(() => translator.TranslateImpactDetailToNodeImpactLevel(action, impact), message);
            }
            else
            {
                NodeImpactLevel actualResult   = translator.TranslateImpactDetailToNodeImpactLevel(action, impact);
                NodeImpactLevel expectedResult = (NodeImpactLevel)Enum.Parse(typeof(NodeImpactLevel), expectedResultString);

                Assert.AreEqual(expectedResult, actualResult, message);
            }
        }
Ejemplo n.º 5
0
 public static bool AllImpactsEqual(AffectedResourceImpact resourceImpact, Impact expectedImpact)
 {
     return
         (resourceImpact.ApplicationConfigImpact == expectedImpact &&
          resourceImpact.ComputeImpact == expectedImpact &&
          resourceImpact.DiskImpact == expectedImpact &&
          resourceImpact.NetworkImpact == expectedImpact &&
          resourceImpact.OSImpact == expectedImpact);
 }
Ejemplo n.º 6
0
        public ImpactInfoWrapper(ImpactInfo impactInfo)
        {
            impactInfo.Validate("impactInfo");

            this.ImpactAction = impactInfo.ImpactAction;

            this.ImpactedResources = impactInfo.ImpactedResources != null
                ? impactInfo.ImpactedResources.Deserialize()
                : new AffectedResourceImpact();

            if (this.ImpactedResources.ListOfImpactTypes == null)
            {
                this.ImpactedResources.ListOfImpactTypes = new List <ImpactTypeEnum>();
            }
        }
        public RoleInstanceImpactedByJobWrapper(RoleInstanceImpactedByJob roleInstanceImpactedByJob)
        {
            roleInstanceImpactedByJob.Validate("roleInstanceImpactedByJob");

            this.RoleInstanceName = roleInstanceImpactedByJob.RoleInstanceName;
            this.UpdateDomain     = roleInstanceImpactedByJob.UpdateDomain;

            this.ExpectedImpact = roleInstanceImpactedByJob.ExpectedImpact != null
                ? roleInstanceImpactedByJob.ExpectedImpact.Deserialize()
                : new AffectedResourceImpact();

            if (this.ExpectedImpact.ListOfImpactTypes == null)
            {
                this.ExpectedImpact.ListOfImpactTypes = new List <ImpactTypeEnum>();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Escalates a freeze of unknown duration, according to configuration.
        /// </summary>
        /// <param name="oldCategory">The current impact category.</param>
        /// <param name="impactDetail">The impact detail.</param>
        /// <returns>The new impact category.</returns>
        private ImpactCategory ApplyUnknownDurationFreezeRule(
            ImpactCategory oldCategory,
            AffectedResourceImpact impactDetail)
        {
            ImpactCategory newCategory = oldCategory;

            if ((oldCategory == ImpactCategory.Freeze) && (impactDetail.EstimatedImpactDurationInSeconds < 0))
            {
                newCategory = this.configSection.ReadConfigValue(ConfigKeyUnknownDurationFreezeMapping, ImpactCategory.Restart);

                if (oldCategory != newCategory)
                {
                    tracer.WriteNoise(
                        "Overall impact changed from {0} to {1} due to freeze of unknown duration",
                        oldCategory,
                        newCategory);
                }
            }

            return(newCategory);
        }
Ejemplo n.º 9
0
        public static ITenantJob CreateNewTenantJob(
            ImpactActionEnum impactAction = ImpactActionEnum.TenantUpdate,
            uint ud = 0,
            List <string> roleInstances = null,
            string context = null)
        {
            var impactedResources = new AffectedResourceImpact
            {
                ListOfImpactTypes = new List <ImpactTypeEnum> {
                    ImpactTypeEnum.Reboot
                }
            };

            if (roleInstances == null)
            {
                roleInstances = new List <string> {
                    "Role_IN_0", "Role_IN_1"
                };
            }

            var tenantJob = new MockTenantJob(Guid.NewGuid())
            {
                JobStep      = CreateNewJobStepInfo(ud, roleInstances),
                ImpactDetail = new MockImpactInfo {
                    ImpactAction = impactAction, ImpactedResources = impactedResources
                },
                JobStatus = JobStatusEnum.Executing,
            };

            if (context != null)
            {
                // the explicit null check is to signify that the context should not be added for jobs like platformupdate etc.
                tenantJob.ContextStringGivenByTenant = context;
            }

            tenantJob.RoleInstancesToBeImpacted =
                tenantJob.JobStep.CurrentlyImpactedRoleInstances.Select(e => e.RoleInstanceName).ToList();

            return(tenantJob);
        }
Ejemplo n.º 10
0
        private bool IsInstanceRemoval(ImpactActionEnum jobType, AffectedResourceImpact impactDetail)
        {
            bool isInstanceRemovalImpact =
                jobType == ImpactActionEnum.TenantUpdate &&
                CoordinatorHelper.AllImpactsEqual(impactDetail, Impact.Wipe);

            bool isInstanceRemovalLegacy = false;

            if (impactDetail.ListOfImpactTypes != null)
            {
                isInstanceRemovalLegacy = impactDetail.ListOfImpactTypes.Contains(ImpactTypeEnum.InstanceRemoval);
            }

            if (isInstanceRemovalImpact != isInstanceRemovalLegacy)
            {
                tracer.WriteWarning(
                    "Mismatch between IsInstanceRemoval result from resource impacts ({0}) and ImpactTypeEnum ({1}); using {0}",
                    isInstanceRemovalImpact,
                    isInstanceRemovalLegacy);
            }

            return(isInstanceRemovalImpact);
        }
 public MockRoleInstanceImpactedByJob()
 {
     this.ExpectedImpact = new AffectedResourceImpact {
         ListOfImpactTypes = new List <ImpactTypeEnum>()
     };
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Translates the impact details to an RM node impact level.
        /// </summary>
        /// <param name="impactDetail">The impact details to be translated.</param>
        /// <returns>The node impact level to be sent to the RM.</returns>
        public NodeImpactLevel TranslateImpactDetailToNodeImpactLevel(ImpactActionEnum jobType, AffectedResourceImpact impactDetail)
        {
            impactDetail.Validate("impactDetail");

            ImpactCategory category;

            if (IsInstanceRemoval(jobType, impactDetail))
            {
                // Handle instance removal as a special case
                category = ImpactCategory.Decommission;
                tracer.WriteInfo("Overall impact set to {0} due to instance removal", category);
            }
            else
            {
                category = TranslateImpactDetailToCategory(impactDetail);
            }

            return(TranslateImpactCategoryToNodeImpactLevel(category));
        }