Пример #1
0
        internal static bool IsJsonConfigModelValid(StandAloneInstallerJsonModelBase config, StandAloneInstallerJsonModelBase oldConfig, bool validateDownNodes, bool throwIfError = false)
        {
            try
            {
                config.ThrowValidationExceptionIfNull(StringResources.Error_BPAJsonModelInvalid);
                config.ValidateModel();
                var settingsValidator = new StandaloneSettingsValidator(config);
                settingsValidator.Validate(validateDownNodes);

                // UOS validates upgrade config diffs by calling ValidateUpdateFrom() method directly. Test-Configuration invokes IsJsonConfigModelValid() and it calls ValidateUpdateFrom inside.
                // The reason is from Test-Configuration, there is no cluster connection, so that we ignore ValidateTopologyAsync(). Therefore in the ValidateUpdateFrom here there is no need
                // to await the async call. However in UOS, we should call ValidateUpdateFrom in an async manner. That's why I am not trying to have the UOS/TestConfiguration going down the same path.
                if (oldConfig != null)
                {
                    settingsValidator.ValidateUpdateFrom(oldConfig.GetUserConfig(), oldConfig.GetClusterTopology(), connectedToCluster: false).GetAwaiter().GetResult();
                }
            }
            catch (FileNotFoundException ex)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPAPackageFileNotFound, ex.ToString());
                return(false);
            }
            catch (ValidationException ex)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPAModelSettingsValidationFailed, ex.GetMessage(System.Globalization.CultureInfo.InvariantCulture));
                if (throwIfError)
                {
                    throw;
                }

                return(false);
            }

            return(true);
        }
        internal static async Task ValidateModel(StandAloneInstallerJsonModelBase targetJsonConfig, StandaloneSettingsValidator validator, StandAloneCluster cluster, bool validateUpgrade)
        {
            BestPracticesAnalyzer.IsJsonConfigModelValid(targetJsonConfig, oldConfig: null, validateDownNodes: false, throwIfError: true);

            if (validateUpgrade)
            {
                await validator.ValidateUpdateFrom(cluster.Current.CSMConfig, cluster.Topology, connectedToCluster : true).ConfigureAwait(false);
            }
        }
        public void ValidateUpgradeTest()
        {
            // Windows/ GMSA security <-> unsecure is not allowed.
            StandAloneInstallerJSONModelAugust2017 v1model   = Utility.CreateMockupStandAloneJsonModel("testCluster", "1.0.0", security: Utility.CreateGMSASecurity());
            StandAloneInstallerJSONModelAugust2017 v2model   = Utility.CreateMockupStandAloneJsonModel("testCluster", "2.0.0");
            StandaloneSettingsValidator            validator = new StandaloneSettingsValidator(v2model);

            Utility.ValidateExpectedValidationException(
                delegate
            {
                validator.ValidateUpdateFrom(v1model.GetUserConfig(), v1model.GetClusterTopology(), false).GetAwaiter().GetResult();
            },
                ClusterManagementErrorCode.AuthenticationTypeCannotBeChangedFromWindowsToUnsecured);

            // For the same nodename, node IP can't be changed.
            List <NodeDescriptionGA> nodelist   = new List <NodeDescriptionGA>();
            NodeDescriptionGA        node       = Utility.CreateNodeDescription("node1", "NodeType0", "machine1", "fd:/dc1/r0", "UD0");
            List <NodeDescriptionGA> nodelistV2 = new List <NodeDescriptionGA>();
            NodeDescriptionGA        nodeV2     = Utility.CreateNodeDescription("node1", "NodeType0", "machine2", "fd:/dc1/r0", "UD0");

            nodelist.Add(node);
            nodelistV2.Add(nodeV2);
            v1model   = Utility.CreateMockupStandAloneJsonModel("testCluster", "1.0.0", nodes: nodelist);
            v2model   = Utility.CreateMockupStandAloneJsonModel("testCluster", "2.0.0", nodes: nodelistV2);
            validator = new StandaloneSettingsValidator(v2model);

            Utility.ValidateExpectedValidationException(
                delegate
            {
                validator.ValidateUpdateFrom(v1model.GetUserConfig(), v1model.GetClusterTopology(), false).GetAwaiter().GetResult();
            },
                ClusterManagementErrorCode.NodeIPNodeTypeRefCantBeChanged);

            // Reverse proxy port change is allowed.
            v1model = Utility.CreateMockupStandAloneJsonModel("testCluster", "1.0.0");
            v2model = Utility.CreateMockupStandAloneJsonModel("testCluster", "2.0.0");
            foreach (var currentNodeType in v2model.Properties.NodeTypes)
            {
                currentNodeType.ReverseProxyEndpointPort = 19081;
            }
            validator = new StandaloneSettingsValidator(v2model);
            validator.ValidateUpdateFrom(v1model.GetUserConfig(), v1model.GetClusterTopology(), false).GetAwaiter().GetResult();
        }