Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private StoreLogService(org.neo4j.logging.LogProvider userLogProvider, org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File internalLog, java.util.Map<String, org.neo4j.logging.Level> logLevels, org.neo4j.logging.Level defaultLevel, java.time.ZoneId logTimeZone, long internalLogRotationThreshold, long internalLogRotationDelay, int maxInternalLogArchives, java.util.concurrent.Executor rotationExecutor, final System.Action<org.neo4j.logging.LogProvider> rotationListener) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        private StoreLogService(LogProvider userLogProvider, FileSystemAbstraction fileSystem, File internalLog, IDictionary <string, Level> logLevels, Level defaultLevel, ZoneId logTimeZone, long internalLogRotationThreshold, long internalLogRotationDelay, int maxInternalLogArchives, Executor rotationExecutor, System.Action <LogProvider> rotationListener)
        {
            if (!internalLog.ParentFile.exists())
            {
                fileSystem.Mkdirs(internalLog.ParentFile);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.logging.FormattedLogProvider.Builder internalLogBuilder = org.neo4j.logging.FormattedLogProvider.withZoneId(logTimeZone).withDefaultLogLevel(defaultLevel).withLogLevels(logLevels);
            FormattedLogProvider.Builder internalLogBuilder = FormattedLogProvider.withZoneId(logTimeZone).withDefaultLogLevel(defaultLevel).withLogLevels(logLevels);

            FormattedLogProvider internalLogProvider;

            if (internalLogRotationThreshold == 0)
            {
                Stream outputStream = createOrOpenAsOutputStream(fileSystem, internalLog, true);
                internalLogProvider = internalLogBuilder.ToOutputStream(outputStream);
                rotationListener(internalLogProvider);
                this._closeable = outputStream;
            }
            else
            {
                RotatingFileOutputStreamSupplier rotatingSupplier = new RotatingFileOutputStreamSupplier(fileSystem, internalLog, internalLogRotationThreshold, internalLogRotationDelay, maxInternalLogArchives, rotationExecutor, new RotationListenerAnonymousInnerClass(this, rotationListener, internalLogBuilder));
                internalLogProvider = internalLogBuilder.ToOutputStream(rotatingSupplier);
                this._closeable     = rotatingSupplier;
            }
            this._logService = new SimpleLogService(userLogProvider, internalLogProvider);
        }
Exemplo n.º 2
0
        public override ServerControls NewServer()
        {
            try
            {
                using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
                {
                    File userLogFile     = new File(_serverFolder, "neo4j.log");
                    File internalLogFile = new File(_serverFolder, "debug.log");

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.OutputStream logOutputStream;
                    Stream logOutputStream;
                    try
                    {
                        logOutputStream = createOrOpenAsOutputStream(fileSystem, userLogFile, true);
                    }
                    catch (IOException e)
                    {
                        throw new Exception("Unable to create log file", e);
                    }

                    _config[ServerSettings.third_party_packages.name()]           = ToStringForThirdPartyPackageProperty(_extensions.toList());
                    _config[GraphDatabaseSettings.store_internal_log_path.name()] = internalLogFile.AbsolutePath;

                    LogProvider userLogProvider            = FormattedLogProvider.withZoneId(LogZoneIdFrom(_config)).toOutputStream(logOutputStream);
                    GraphDatabaseDependencies dependencies = GraphDatabaseDependencies.newDependencies().userLogProvider(userLogProvider);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: Iterable<org.neo4j.kernel.extension.KernelExtensionFactory<?>> kernelExtensions = append(new Neo4jHarnessExtensions(procedures), dependencies.kernelExtensions());
                    IEnumerable <KernelExtensionFactory <object> > kernelExtensions = append(new Neo4jHarnessExtensions(_procedures), dependencies.KernelExtensions());
                    dependencies = dependencies.KernelExtensions(kernelExtensions);

                    Config       dbConfig             = Config.defaults(_config);
                    GraphFactory graphFactory         = CreateGraphFactory(dbConfig);
                    bool         httpAndHttpsDisabled = dbConfig.EnabledHttpConnectors().Count == 0;

                    NeoServer server = httpAndHttpsDisabled ? new DisabledNeoServer(graphFactory, dependencies, dbConfig) : CreateNeoServer(graphFactory, dbConfig, dependencies);

                    InProcessServerControls controls = new InProcessServerControls(_serverFolder, userLogFile, internalLogFile, server, logOutputStream);
                    controls.Start();

                    try
                    {
                        _fixtures.applyTo(controls);
                    }
                    catch (Exception e)
                    {
                        controls.Close();
                        throw e;
                    }
                    return(controls);
                }
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public AsyncRequestLog(org.neo4j.io.fs.FileSystemAbstraction fs, java.time.ZoneId logTimeZone, String logFile, long rotationSize, int rotationKeepNumber) throws java.io.IOException
        public AsyncRequestLog(FileSystemAbstraction fs, ZoneId logTimeZone, string logFile, long rotationSize, int rotationKeepNumber)
        {
            NamedThreadFactory threadFactory    = new NamedThreadFactory("HTTP-Log-Rotator", true);
            ExecutorService    rotationExecutor = Executors.newCachedThreadPool(threadFactory);

            _outputSupplier = new RotatingFileOutputStreamSupplier(fs, new File(logFile), rotationSize, 0, rotationKeepNumber, rotationExecutor);
            FormattedLogProvider logProvider = FormattedLogProvider.withZoneId(logTimeZone).toOutputStream(_outputSupplier);

            _asyncLogProcessingExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("HTTP-Log-Writer"));
            _asyncEventProcessor        = new AsyncEvents <AsyncLogEvent>(this, this);
            AsyncLogProvider asyncLogProvider = new AsyncLogProvider(_asyncEventProcessor, logProvider);

            _log = asyncLogProvider.GetLog("REQUEST");
        }
Exemplo n.º 4
0
        private static LogService LogService(FileSystemAbstraction fileSystem, Config config)
        {
            File logFile = config.Get(store_internal_log_path);

            try
            {
                ZoneId zoneId = config.Get(GraphDatabaseSettings.db_timezone).ZoneId;
                FormattedLogProvider logProvider = FormattedLogProvider.withZoneId(zoneId).toOutputStream(System.out);
                return(StoreLogService.withUserLogProvider(logProvider).withInternalLog(logFile).build(fileSystem));
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: ConsistencyCheckService.Result run(String... args) throws ToolFailureException
        internal virtual ConsistencyCheckService.Result Run(params string[] args)
        {
            Args arguments = Args.withFlags(VERBOSE).parse(args);

            File   storeDir            = DetermineStoreDirectory(arguments);
            Config tuningConfiguration = ReadConfiguration(arguments);
            bool   verbose             = IsVerbose(arguments);

            DatabaseLayout databaseLayout = DatabaseLayout.of(storeDir);

            CheckDbState(databaseLayout, tuningConfiguration);

            ZoneId      logTimeZone = tuningConfiguration.Get(GraphDatabaseSettings.db_timezone).ZoneId;
            LogProvider logProvider = FormattedLogProvider.withZoneId(logTimeZone).toOutputStream(_systemOut);

            try
            {
                return(_consistencyCheckService.runFullConsistencyCheck(databaseLayout, tuningConfiguration, ProgressMonitorFactory.textual(_systemError), logProvider, _fs, verbose, new ConsistencyFlags(tuningConfiguration)));
            }
            catch (ConsistencyCheckIncompleteException e)
            {
                throw new ToolFailureException("Check aborted due to exception", e);
            }
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static java.net.URI resolveUriWithProvider(String providerName, org.neo4j.kernel.configuration.Config config, String from, org.neo4j.helpers.Args args) throws ToolFailureException
        private static URI ResolveUriWithProvider(string providerName, Config config, string from, Args args)
        {
            BackupExtensionService service;

            try
            {
                service = Service.load(typeof(BackupExtensionService), providerName);
            }
            catch (NoSuchElementException)
            {
                throw new ToolFailureException(string.format(UNKNOWN_SCHEMA_MESSAGE_PATTERN, providerName));
            }

            try
            {
                ZoneId logTimeZone = config.Get(GraphDatabaseSettings.db_timezone).ZoneId;
                FormattedLogProvider userLogProvider = FormattedLogProvider.withZoneId(logTimeZone).toOutputStream(System.out);
                return(service.Resolve(from, args, new SimpleLogService(userLogProvider, NullLogProvider.Instance)));
            }
            catch (Exception t)
            {
                throw new ToolFailureException(t.Message);
            }
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void execute(String[] args) throws org.neo4j.commandline.admin.IncorrectUsage, org.neo4j.commandline.admin.CommandFailed
        public override void Execute(string[] args)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String database;
            string database;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean verbose;
            bool verbose;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Optional<java.nio.file.Path> additionalConfigFile;
            Optional <Path> additionalConfigFile;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.nio.file.Path reportDir;
            Path reportDir;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Optional<java.nio.file.Path> backupPath;
            Optional <Path> backupPath;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean checkGraph;
            bool checkGraph;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean checkIndexes;
            bool checkIndexes;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean checkIndexStructure;
            bool checkIndexStructure;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean checkLabelScanStore;
            bool checkLabelScanStore;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean checkPropertyOwners;
            bool checkPropertyOwners;

            try
            {
                database             = _arguments.parse(args).get(ARG_DATABASE);
                backupPath           = _arguments.getOptionalPath("backup");
                verbose              = _arguments.getBoolean("verbose");
                additionalConfigFile = _arguments.getOptionalPath("additional-config");
                reportDir            = _arguments.getOptionalPath("report-dir").orElseThrow(() => new System.ArgumentException("report-dir must be a valid path"));
            }
            catch (System.ArgumentException e)
            {
                throw new IncorrectUsage(e.Message);
            }

            if (backupPath.Present)
            {
                if (_arguments.has(ARG_DATABASE))
                {
                    throw new IncorrectUsage("Only one of '--" + ARG_DATABASE + "' and '--backup' can be specified.");
                }
                if (!backupPath.get().toFile().Directory)
                {
                    throw new CommandFailed(format("Specified backup should be a directory: %s", backupPath.get()));
                }
            }

            Config config = LoadNeo4jConfig(_homeDir, _configDir, database, LoadAdditionalConfig(additionalConfigFile));

            try
            {
                // We can remove the loading from config file in 4.0
                if (_arguments.has(CHECK_GRAPH))
                {
                    checkGraph = _arguments.getBoolean(CHECK_GRAPH);
                }
                else
                {
                    checkGraph = config.Get(ConsistencyCheckSettings.ConsistencyCheckGraph);
                }
                if (_arguments.has(CHECK_INDEXES))
                {
                    checkIndexes = _arguments.getBoolean(CHECK_INDEXES);
                }
                else
                {
                    checkIndexes = config.Get(ConsistencyCheckSettings.ConsistencyCheckIndexes);
                }
                if (_arguments.has(CHECK_INDEX_STRUCTURE))
                {
                    checkIndexStructure = _arguments.getBoolean(CHECK_INDEX_STRUCTURE);
                }
                else
                {
                    checkIndexStructure = config.Get(ConsistencyCheckSettings.ConsistencyCheckIndexStructure);
                }
                if (_arguments.has(CHECK_LABEL_SCAN_STORE))
                {
                    checkLabelScanStore = _arguments.getBoolean(CHECK_LABEL_SCAN_STORE);
                }
                else
                {
                    checkLabelScanStore = config.Get(ConsistencyCheckSettings.ConsistencyCheckLabelScanStore);
                }
                if (_arguments.has(CHECK_PROPERTY_OWNERS))
                {
                    checkPropertyOwners = _arguments.getBoolean(CHECK_PROPERTY_OWNERS);
                }
                else
                {
                    checkPropertyOwners = config.Get(ConsistencyCheckSettings.ConsistencyCheckPropertyOwners);
                }
            }
            catch (System.ArgumentException e)
            {
                throw new IncorrectUsage(e.Message);
            }

            try
            {
                using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
                {
                    File           databaseDirectory = backupPath.map(Path.toFile).orElse(config.Get(database_path));
                    DatabaseLayout databaseLayout    = DatabaseLayout.of(databaseDirectory);
                    CheckDbState(databaseLayout, config);
                    ZoneId logTimeZone = config.Get(GraphDatabaseSettings.db_timezone).ZoneId;
                    // Only output progress indicator if a console receives the output
                    ProgressMonitorFactory progressMonitorFactory = ProgressMonitorFactory.NONE;
                    if (System.console() != null)
                    {
                        progressMonitorFactory = ProgressMonitorFactory.textual(System.out);
                    }

                    ConsistencyCheckService.Result consistencyCheckResult = _consistencyCheckService.runFullConsistencyCheck(databaseLayout, config, progressMonitorFactory, FormattedLogProvider.withZoneId(logTimeZone).toOutputStream(System.out), fileSystem, verbose, reportDir.toFile(), new ConsistencyFlags(checkGraph, checkIndexes, checkIndexStructure, checkLabelScanStore, checkPropertyOwners));

                    if (!consistencyCheckResult.Successful)
                    {
                        throw new CommandFailed(format("Inconsistencies found. See '%s' for details.", consistencyCheckResult.ReportFile()));
                    }
                }
            }
            catch (Exception e) when(e is ConsistencyCheckIncompleteException || e is IOException)
            {
                throw new CommandFailed("Consistency checking failed." + e.Message, e);
            }
        }