예제 #1
0
        public void LoadConfigFile(string configFile)
        {
            Log.Trace(@"Loading config file {0}", configFile);

            ConfigErrors.Clear();

            ConfigWarnings.Clear();

            ConfigPath = configFile;

            if (Read())
            {
                DoValidation();
            }
            else
            {
                ConfigErrors.Add($"Failed to read the configuration file {configFile}");
            }
        }
예제 #2
0
        private void DoValidation()
        {
            if (string.IsNullOrEmpty(ConfigPath))
            {
                ConfigErrors.Add(@"Config validation failed. There is no config file set.");
                Log.Error(@"Config validation failed. There is no config file set.");
                return;
            }

            Log.Debug("validating config file {0}", ConfigPath);

            // RULE: at least one data source must be specified
            if (!SnapShotSources.Any())
            {
                ConfigErrors.Add("At least one data source must be specified. Check the value for \"d1\" \r\n");
            }

            // RULE: the first parity location must not be empty
            if (string.IsNullOrEmpty(ParityFile1))
            {
                ConfigErrors.Add("The first parity location must not be empty. Check the value for \"parity\"");
            }

            // RULE: number of content files must be at least the (number of parity files + 1)
            if (ContentFiles.Count < ParityPaths.Count + 1)
            {
                ConfigErrors.Add($"The number of content files must be at least one greater than the number of parity files. There should be at least {ParityPaths.Count + 1} content files.");
            }

            // RULE: check that devices are not repeated
            if (!IsRulePassDevicesMustNotRepeat(DataSourcePaths))
            {
                ConfigErrors.Add("Devices for Source and Parity must be unique. Check the values for data and parity");
            }

            // RULE: data paths must be accessible
            foreach (SnapShotSource source in DataSourcePaths)
            {
                // test if path exists
                if (!Directory.Exists(source.DirSource))
                {
                    ConfigErrors.Add($"Source is inaccessible or does not exist: {source.DirSource}");
                }
            }

            // RULE: parity devices should be greater or equal to data devices
            ByteSize largestSourceDevice  = new ByteSize(StorageUtil.GetDriveSizes(DataSourcePaths).Max());
            ByteSize smallestParityDevice = new ByteSize(StorageUtil.GetDriveSizes(ParityPaths).Min());

            if (largestSourceDevice > smallestParityDevice)
            {
                ConfigWarnings.Add($@"One or more data devices [{largestSourceDevice}] are larger than the smallest parity device [{smallestParityDevice}]. All parity devices should be equal or greater in size than all data devices.");
            }

            // RULE: blockSize valid value
            if (BlockSizeKB < 1 || BlockSizeKB > 16384)
            {
                ConfigErrors.Add(@"The blockSize value is invalid and must be between 1 and 16384");
            }

            // RULE: autoSave valid value
            if (AutoSaveGB > Constants.MaxAutoSave)
            {
                ConfigErrors.Add($"The autoSave value is invalid and must be between {Constants.MinAutoSave} and {Constants.MaxAutoSave}");
            }

            if (!IsValid)
            {
                Log.Error(@"The configuration file is not valid. See errors below:");

                foreach (string error in ConfigErrors)
                {
                    Log.Error(@" - {0}", error);
                }
            }
        }