Exemplo n.º 1
0
        /// <summary>
        /// Helper method to call ValidateConfigurationUpgrade method using provided currentParameters and targetParameters.
        /// </summary>
        /// <param name="currentParameters"></param>
        /// <param name="targetParameters"></param>
        private void TestValidateConfigurationUpgrade(List <SettingsOverridesTypeSectionParameter> currentParameters, List <SettingsOverridesTypeSectionParameter> targetParameters)
        {
            WindowsFabricSettings currentWindowsFabricSettings = GetWindowsFabricSettings(currentParameters);
            WindowsFabricSettings targetWindowsFabricSettings  = GetWindowsFabricSettings(targetParameters);

            Validator.ValidateConfigurationUpgrade(GetWindowsFabricSettings(currentParameters), GetWindowsFabricSettings(targetParameters));
        }
Exemplo n.º 2
0
        public void TestValidateConfigurationUpgradeWithNullCurrentTargetReplicaSize()
        {
            WindowsFabricSettings currentWindowsFabricSettings = GetWindowsFabricSettings(CurrentParameters);
            WindowsFabricSettings targetWindowsFabricSettings  = GetWindowsFabricSettings(CurrentParameters);

            // Remove FabricValidatorConstants.ParameterNames.TargetReplicaSetSize setting in currentWindowsFabricSettings
            Dictionary <string, WindowsFabricSettings.SettingsValue> parameterNameToSettingsValue = new Dictionary <string, WindowsFabricSettings.SettingsValue>();

            currentWindowsFabricSettings.SettingsMap.TryGetValue(FabricValidatorConstants.SectionNames.FailoverManager, out parameterNameToSettingsValue);
            parameterNameToSettingsValue.Remove(FabricValidatorConstants.ParameterNames.TargetReplicaSetSize);

            Verify.Throws <ArgumentException>(() =>
            {
                Validator.ValidateConfigurationUpgrade(currentWindowsFabricSettings, targetWindowsFabricSettings);
            },
                                              "Current value for configuration TargetReplicaSetSize is null.");
        }
        private void TestValidateConfigurationUpgrade(
            List <SettingsOverridesTypeSectionParameter> currentParameters,
            List <SettingsOverridesTypeSectionParameter> targetParameters,
            bool expectError)
        {
            WindowsFabricSettings currentWindowsFabricSettings = GetWindowsFabricSettings(currentParameters);
            WindowsFabricSettings targetWindowsFabricSettings  = GetWindowsFabricSettings(targetParameters);

            if (expectError)
            {
                try
                {
                    this.validator.ValidateConfigurationUpgrade(currentWindowsFabricSettings, targetWindowsFabricSettings);
                    Verify.Fail("should fail");
                }
                catch (ArgumentException)
                {
                }
            }
            else
            {
                this.validator.ValidateConfigurationUpgrade(currentWindowsFabricSettings, targetWindowsFabricSettings);
            }
        }
        internal static void CompareAndAnalyze(ClusterManifestType currentClusterManifest, ClusterManifestType targetClusterManifest, Infrastructure infrastructure, DeploymentParameters parameters)
        {
            // If the infrastructure elements are different, the update cannot continue
            if (targetClusterManifest.Infrastructure.Item.GetType() != currentClusterManifest.Infrastructure.Item.GetType())
            {
                DeployerTrace.WriteError("Invalid Operation. Cannot update from 1 infrastructure type to another");
                throw new ClusterManifestValidationException(StringResources.Error_FabricDeployer_InvalidClusterManifest_Formatted);
            }

            // Validate that the new cluster manifest and the node list are valid
            try
            {
                var currentWindowsFabricSettings = new WindowsFabricSettings(currentClusterManifest);
                var targetWindowsFabricSettings  = new WindowsFabricSettings(targetClusterManifest);
                FabricValidator.Create(targetClusterManifest, infrastructure.InfrastructureNodes, targetWindowsFabricSettings, parameters.Operation).Validate();
                //Validate if the SeedNodeCount increases by one
                int           currentSeedNodes = 0, targetSeedNodes = 0;
                List <String> currentSeedNodesList = new List <String>();
                List <String> targetSeedNodesList  = new List <String>();
                if (currentClusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure)
                {
                    ClusterManifestTypeInfrastructureWindowsAzure currentInfrastructure = currentClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzure;
                    ClusterManifestTypeInfrastructureWindowsAzure targetInfrastructure  = targetClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzure;
                    for (int i = 0; i < currentInfrastructure.Roles.Length; i++)
                    {
                        currentSeedNodes += currentInfrastructure.Roles[i].SeedNodeCount;
                    }
                    for (int j = 0; j < targetInfrastructure.Roles.Length; j++)
                    {
                        targetSeedNodes += targetInfrastructure.Roles[j].SeedNodeCount;
                    }
                }
                else if (currentClusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzureStaticTopology)
                {
                    ClusterManifestTypeInfrastructureWindowsAzureStaticTopology currentInfrastructure = currentClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzureStaticTopology;
                    ClusterManifestTypeInfrastructureWindowsAzureStaticTopology targetInfrastructure  = targetClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzureStaticTopology;
                    foreach (FabricNodeType nodelist in currentInfrastructure.NodeList)
                    {
                        if (nodelist.IsSeedNode)
                        {
                            currentSeedNodes++;
                        }
                    }
                    foreach (FabricNodeType nodelist in targetInfrastructure.NodeList)
                    {
                        if (nodelist.IsSeedNode)
                        {
                            targetSeedNodes++;
                        }
                    }
                }
#if DotNetCoreClrLinux
                else if (currentClusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux)
                {
                    var currentInfrastructure = currentClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureLinux;
                    var targetInfrastructure  = targetClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureLinux;
#else
                else if (currentClusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer)
                {
                    var currentInfrastructure = currentClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsServer;
                    var targetInfrastructure  = targetClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsServer;
#endif
                    foreach (FabricNodeType nodelist in currentInfrastructure.NodeList)
                    {
                        if (nodelist.IsSeedNode)
                        {
                            currentSeedNodes++;
                            currentSeedNodesList.Add(nodelist.NodeName);
                        }
                    }
                    foreach (FabricNodeType nodelist in targetInfrastructure.NodeList)
                    {
                        if (nodelist.IsSeedNode)
                        {
                            targetSeedNodes++;
                            targetSeedNodesList.Add(nodelist.NodeName);
                        }
                    }
                }
                if (System.Math.Abs(currentSeedNodes - targetSeedNodes) > 1)
                {
                    DeployerTrace.WriteError(StringResources.Warning_SeedNodeCountCanOnlyChangeByOne);
                    throw new ClusterManifestValidationException(StringResources.Warning_SeedNodeCountCanOnlyChangeByOne);
                }
                else if (currentSeedNodesList.Except(targetSeedNodesList).Union(targetSeedNodesList.Except(currentSeedNodesList)).Count() > 1)
                {
                    DeployerTrace.WriteError(StringResources.Warning_SeedNodeSetCannotHaveMultipleChanges);
                    throw new ClusterManifestValidationException(StringResources.Warning_SeedNodeSetCannotHaveMultipleChanges);
                }

                var fabricValidator = FabricValidator.Create(currentClusterManifest, null, currentWindowsFabricSettings, parameters.Operation);
                // Finally, compare the settings and decide if fabric must restart or not
                IEnumerable <KeyValuePair <string, string> > modifiedStaticSettings = fabricValidator.CompareAndAnalyze(targetClusterManifest, parameters.NodeTypeName);
                if (modifiedStaticSettings.Count() > 0)
                {
                    WriteModifiedStaticSettingsToFile(modifiedStaticSettings, targetClusterManifest.FabricSettings, parameters.OutputFile);
                    throw new FabricHostRestartRequiredException("Fabric host restart is required");
                }
                else
                {
                    throw new FabricHostRestartNotRequiredException("Fabric host restart is not required");
                }
            }
            catch (Exception e)
            {
                if (e is FabricHostRestartRequiredException || e is FabricHostRestartNotRequiredException)
                {
                    throw e;
                }
                else
                {
                    throw new ClusterManifestValidationException(
                              string.Format(StringResources.Error_FabricDeployer_InvalidClusterManifest_Formatted, e));
                }
            }
        }