Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void addToArchive(java.nio.file.Path archiveDestination, org.neo4j.diagnostics.DiagnosticsReporterProgress progress) throws java.io.IOException
            public void addToArchive(Path archiveDestination, DiagnosticsReporterProgress progress)
            {
                using (PrintStream printStream = new PrintStream(Files.newOutputStream(archiveDestination)))
                {
                    _outerInstance.systemProperties.list(printStream);
                }
            }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void execute(String[] stringArgs) throws org.neo4j.commandline.admin.IncorrectUsage, org.neo4j.commandline.admin.CommandFailed
        public override void Execute(string[] stringArgs)
        {
            Args args = Args.withFlags("list", "to", "verbose", "force", PID_KEY).parse(stringArgs);

            _verbose   = args.Has("verbose");
            _jmxDumper = new JMXDumper(_homeDir, _fs, @out, _err, _verbose);
            _pid       = ParsePid(args);
            bool force = args.Has("force");

            DiagnosticsReporter reporter = CreateAndRegisterSources();

            Optional <ISet <string> > classifiers = ParseAndValidateArguments(args, reporter);

            if (!classifiers.Present)
            {
                return;
            }

            DiagnosticsReporterProgress progress = BuildProgress();

            // Start dumping
            Path destinationDir = (new File(_destinationArgument.parse(args))).toPath();

            try
            {
                Path reportFile = destinationDir.resolve(DefaultFilename);
                @out.println("Writing report to " + reportFile.toAbsolutePath().ToString());
                reporter.Dump(classifiers.get(), reportFile, progress, force);
            }
            catch (IOException e)
            {
                throw new CommandFailed("Creating archive failed", e);
            }
        }
Пример #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long estimatedSize(org.neo4j.diagnostics.DiagnosticsReporterProgress progress) throws java.io.IOException
            public long estimatedSize(DiagnosticsReporterProgress progress)
            {
                MemoryMXBean bean        = ManagementFactory.getPlatformMXBean(_outerInstance.mBeanServer, typeof(MemoryMXBean));
                long         totalMemory = bean.HeapMemoryUsage.Committed + bean.NonHeapMemoryUsage.Committed;

                // We first write raw to disk then write to archive, 5x compression is a reasonable worst case estimation
                return(( long )(totalMemory * 1.2));
            }
Пример #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void addToArchive(java.nio.file.Path archiveDestination, DiagnosticsReporterProgress progress) throws java.io.IOException
            public override void AddToArchive(Path archiveDestination, DiagnosticsReporterProgress progress)
            {
                long   size = Fs.getFileSize(Source);
                Stream @in  = Fs.openAsInputStream(Source);

                // Track progress of the file reading, source might be a very large file
                using (ProgressAwareInputStream inStream = new ProgressAwareInputStream(@in, size, progress.percentChanged))
                {
                    Files.copy(inStream, archiveDestination);
                }
            }
Пример #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void addToArchive(java.nio.file.Path archiveDestination, org.neo4j.diagnostics.DiagnosticsReporterProgress progress) throws java.io.IOException
            public void addToArchive(Path archiveDestination, DiagnosticsReporterProgress progress)
            {
                // Heap dump has to target an actual file, we cannot stream directly to the archive
                progress.Info("dumping...");
                Path tempFile = Files.createTempFile("neo4j-heapdump", ".hprof");

                Files.deleteIfExists(tempFile);
                outerInstance.heapDump(tempFile.toAbsolutePath().ToString());

                // Track progress of archiving process
                progress.Info("archiving...");
                long   size = Files.size(tempFile);
                Stream @in  = Files.newInputStream(tempFile);

                using (ProgressAwareInputStream inStream = new ProgressAwareInputStream(@in, size, progress.percentChanged))
                {
                    Files.copy(inStream, archiveDestination);
                }

                Files.delete(tempFile);
            }
Пример #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void estimateSizeAndCheckAvailableDiskSpace(java.nio.file.Path destination, DiagnosticsReporterProgress progress, java.util.List<DiagnosticsReportSource> sources, java.nio.file.Path destinationFolder, boolean force) throws java.io.IOException
        private void EstimateSizeAndCheckAvailableDiskSpace(Path destination, DiagnosticsReporterProgress progress, IList <DiagnosticsReportSource> sources, Path destinationFolder, bool force)
        {
            if (force)
            {
                return;
            }

            long estimatedFinalSize = 0;

            foreach (DiagnosticsReportSource source in sources)
            {
                estimatedFinalSize += source.EstimatedSize(progress);
            }

            long freeSpace = destinationFolder.toFile().FreeSpace;

            if (estimatedFinalSize > freeSpace)
            {
                string message = string.Format("Free available disk space for {0} is {1}, worst case estimate is {2}. To ignore add '--force' to the command.", destination.FileName, Format.bytes(freeSpace), Format.bytes(estimatedFinalSize));
                throw new Exception(message);
            }
        }
Пример #7
0
 public override long EstimatedSize(DiagnosticsReporterProgress progress)
 {
     return(0);                        // Size of strings should be negligible
 }
Пример #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void addToArchive(java.nio.file.Path archiveDestination, DiagnosticsReporterProgress progress) throws java.io.IOException
            public override void AddToArchive(Path archiveDestination, DiagnosticsReporterProgress progress)
            {
                string message = MessageSupplier.get();

                Files.write(archiveDestination, message.GetBytes(Encoding.UTF8), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
            }
Пример #9
0
 public override long EstimatedSize(DiagnosticsReporterProgress progress)
 {
     return(Fs.getFileSize(Source));
 }
Пример #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void dump(java.util.Set<String> classifiers, java.nio.file.Path destination, DiagnosticsReporterProgress progress, boolean force) throws java.io.IOException
        public virtual void Dump(ISet <string> classifiers, Path destination, DiagnosticsReporterProgress progress, bool force)
        {
            // Collect sources
            IList <DiagnosticsReportSource> sources = new List <DiagnosticsReportSource>();

            foreach (DiagnosticsOfflineReportProvider provider in _providers)
            {
                ((IList <DiagnosticsReportSource>)sources).AddRange(provider.GetDiagnosticsSources(classifiers));
            }

            // Add additional sources
            foreach (KeyValuePair <string, IList <DiagnosticsReportSource> > classifier in _additionalSources.SetOfKeyValuePairs())
            {
                if (classifiers.Contains("all") || classifiers.Contains(classifier.Key))
                {
                    ((IList <DiagnosticsReportSource>)sources).AddRange(classifier.Value);
                }
            }

            // Make sure target directory exists
            Path destinationFolder = destination.Parent;

            Files.createDirectories(destinationFolder);

            // Estimate an upper bound of the final size and make sure it will fit, if not, end reporting
            EstimateSizeAndCheckAvailableDiskSpace(destination, progress, sources, destinationFolder, force);

            // Compress all files to destination
            IDictionary <string, object> env = new Dictionary <string, object>();

            env["create"]      = "true";
            env["useTempFile"] = true;

            // NOTE: we need the toUri() in order to handle windows file paths
            URI uri = URI.create("jar:file:" + destination.toAbsolutePath().toUri().RawPath);

            using (FileSystem fs = FileSystems.newFileSystem(uri, env))
            {
                progress.TotalSteps = sources.Count;
                for (int i = 0; i < sources.Count; i++)
                {
                    DiagnosticsReportSource source = sources[i];
                    Path path = fs.getPath(source.DestinationPath());
                    if (path.Parent != null)
                    {
                        Files.createDirectories(path.Parent);
                    }

                    progress.Started(i + 1, path.ToString());
                    try
                    {
                        source.AddToArchive(path, progress);
                    }
                    catch (Exception e)
                    {
                        progress.Error("Step failed", e);
                        continue;
                    }
                    progress.Finished();
                }
            }
        }
Пример #11
0
 public long estimatedSize(DiagnosticsReporterProgress progress)
 {
     return(0);
 }
Пример #12
0
 public override long EstimatedSize(DiagnosticsReporterProgress progress)
 {
     return(0);
 }
Пример #13
0
 public override void AddToArchive(Path archiveDestination, DiagnosticsReporterProgress progress)
 {
     progress.PercentChanged(30);
     throw new Exception("You had it coming...");
 }