Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public OnlineBackupContext createContext(String... args) throws org.neo4j.commandline.admin.IncorrectUsage, org.neo4j.commandline.admin.CommandFailed
        public virtual OnlineBackupContext CreateContext(params string[] args)
        {
            try
            {
                Arguments arguments = arguments();
                arguments.Parse(args);

                OptionalHostnamePort address = Converters.toOptionalHostnamePortFromRawAddress(arguments.Get(ARG_NAME_BACKUP_SOURCE));
                Path   folder             = this.GetBackupDirectory(arguments);
                string name               = arguments.Get(ARG_NAME_BACKUP_NAME);
                bool   fallbackToFull     = arguments.GetBoolean(ARG_NAME_FALLBACK_FULL);
                bool   doConsistencyCheck = arguments.GetBoolean(ARG_NAME_CHECK_CONSISTENCY);
                long   timeout            = ( long? )arguments.Get(ARG_NAME_TIMEOUT, TimeUtil.parseTimeMillis).Value;
                SelectedBackupProtocol selectedBackupProtocol = SelectedBackupProtocol.fromUserInput(arguments.Get(ARG_NAME_PROTO_OVERRIDE));
                string          pagecacheMemory  = arguments.Get(ARG_NAME_PAGECACHE);
                Optional <Path> additionalConfig = arguments.GetOptionalPath(ARG_NAME_ADDITIONAL_CONFIG_DIR);
                Path            reportDir        = ( Path )arguments.GetOptionalPath(ARG_NAME_REPORT_DIRECTORY).orElseThrow(() =>
                {
                    return(new System.ArgumentException(ARG_NAME_REPORT_DIRECTORY + " must be a path"));
                });
                OnlineBackupRequiredArguments requiredArguments = new OnlineBackupRequiredArguments(address, folder, name, selectedBackupProtocol, fallbackToFull, doConsistencyCheck, timeout, reportDir);

                Path           configFile = _configDir.resolve(Config.DEFAULT_CONFIG_FILE_NAME);
                Config.Builder builder    = Config.fromFile(configFile);
                Path           logPath    = requiredArguments.ResolvedLocationFromName;

                Config config = builder.WithHome(this._homeDir).withSetting(GraphDatabaseSettings.logical_logs_location, logPath.ToString()).withConnectorsDisabled().withNoThrowOnFileLoadFailure().build();

                additionalConfig.map(this.loadAdditionalConfigFile).ifPresent(config.augment);

                // We only replace the page cache memory setting.
                // Any other custom page swapper, etc. settings are preserved and used.
                config.Augment(GraphDatabaseSettings.pagecache_memory, pagecacheMemory);

                // Disable prometheus to avoid binding exceptions
                config.Augment("metrics.prometheus.enabled", Settings.FALSE);

                // Build consistency-checker configuration.
                // Note: We can remove the loading from config file in 4.0.
                System.Func <string, Setting <bool>, bool> oneOf = (a, s) => arguments.Has(a) ? arguments.GetBoolean(a) : config.Get(s);

                ConsistencyFlags consistencyFlags = new ConsistencyFlags(config);

                return(new OnlineBackupContext(requiredArguments, config, consistencyFlags));
            }
            catch (System.ArgumentException e)
            {
                throw new IncorrectUsage(e.Message);
            }
            catch (UncheckedIOException e)
            {
                throw new CommandFailed(e.Message, e);
            }
        }
Ejemplo n.º 2
0
 internal OnlineBackupContext(OnlineBackupRequiredArguments requiredArguments, Config config, ConsistencyFlags consistencyFlags)
 {
     this._requiredArguments = requiredArguments;
     this._config            = config;
     this._consistencyFlags  = consistencyFlags;
 }