Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void doStatusPolling(boolean verbose, String consoleURL, String bearerToken) throws java.io.IOException, InterruptedException, org.neo4j.commandline.admin.CommandFailed
        private void DoStatusPolling(bool verbose, string consoleURL, string bearerToken)
        {
            _outsideWorld.stdOutLine("We have received your export and it is currently being loaded into your cloud instance.");
            _outsideWorld.stdOutLine("You can wait here, or abort this command and head over to the console to be notified of when your database is running.");
            string bearerTokenHeader = "Bearer " + bearerToken;

            ProgressTrackingOutputStream.Progress statusProgress = new ProgressTrackingOutputStream.Progress(_progressListenerFactory.create("Import status", 3L), 0);
            bool firstRunning         = true;
            long importStartedTimeout = DateTimeHelper.CurrentUnixTimeMillis() + 90 * 1000;               // timeout to switch from first running to loading = 1.5 minute

            while (!statusProgress.Done)
            {
                string status = GetDatabaseStatus(verbose, SafeUrl(consoleURL + "/import/status"), bearerTokenHeader);
                switch (status)
                {
                case "running":
                    // It could happen that the very first call of this method is so fast, that the database is still in state
                    // "running". So we need to check if this is the case and ignore the result in that case and only
                    // take this result as valid, once the status loading or restoring was seen before.
                    if (!firstRunning)
                    {
                        statusProgress.RewindTo(0);
                        statusProgress.Add(3);
                        statusProgress.Done();
                    }
                    else
                    {
                        bool passedStartImportTimeout = DateTimeHelper.CurrentUnixTimeMillis() > importStartedTimeout;
                        if (passedStartImportTimeout)
                        {
                            throw new CommandFailed("We're sorry, it couldn't be detected that the import was started, " + "please check the console for further details.");
                        }
                    }
                    break;

                case "loading":
                    firstRunning = false;
                    statusProgress.RewindTo(0);
                    statusProgress.Add(1);
                    break;

                case "restoring":
                    firstRunning = false;
                    statusProgress.RewindTo(0);
                    statusProgress.Add(2);
                    break;

                case "loading failed":
                    throw new CommandFailed("We're sorry, something has gone wrong. We did not recognize the file you uploaded as a valid Neo4j dump file. " + "Please check the file and try again. If you have received this error after confirming the type of file being uploaded," + "please open a support case.");

                default:
                    throw new CommandFailed(string.Format("We're sorry, something has failed during the loading of your database. " + "Please try again and if this problem persists, please open up a support case. Database status: {0}", status));
                }
                _sleeper.sleep(2000);
            }
            _outsideWorld.stdOutLine("Your data was successfully pushed to cloud and is now running.");
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTrackOffsetAfterRewind() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTrackOffsetAfterRewind()
        {
            // given
            Stream           actual           = mock(typeof(Stream));
            ProgressListener progressListener = mock(typeof(ProgressListener));

            ProgressTrackingOutputStream.Progress progress = new ProgressTrackingOutputStream.Progress(progressListener, 0);
            using (ProgressTrackingOutputStream @out = new ProgressTrackingOutputStream(actual, progress))
            {
                @out.WriteByte(new sbyte[20]);

                // when
                progress.RewindTo(15);                           // i.e. the next 5 bytes we don't track
                @out.WriteByte(new sbyte[3]);                    // now there should be 2 untracked bytes left
                @out.WriteByte(new sbyte[9]);                    // this one should report 7
            }
            progress.Done();

            // then
            InOrder inOrder = inOrder(progressListener);

            inOrder.verify(progressListener).add(20);
            inOrder.verify(progressListener).add(7);
            inOrder.verify(progressListener).done();
            verifyNoMoreInteractions(progressListener);
        }
Example #3
0
        /// <summary>
        /// Uploads source from the given position to the upload location.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean resumeUpload(boolean verbose, java.nio.file.Path source, long sourceLength, long position, java.net.URL uploadLocation, ProgressTrackingOutputStream.Progress uploadProgress) throws java.io.IOException, org.neo4j.commandline.admin.CommandFailed
        private bool ResumeUpload(bool verbose, Path source, long sourceLength, long position, URL uploadLocation, ProgressTrackingOutputStream.Progress uploadProgress)
        {
            HttpURLConnection connection = ( HttpURLConnection )uploadLocation.openConnection();

            try
            {
                connection.RequestMethod = "PUT";
                long contentLength = sourceLength - position;
                connection.setRequestProperty("Content-Length", contentLength.ToString());
                connection.FixedLengthStreamingMode = contentLength;
                if (position > 0)
                {
                    // If we're not starting from the beginning we need to specify what range we're uploading in this format
                    connection.setRequestProperty("Content-Range", format("bytes %d-%d/%d", position, sourceLength - 1, sourceLength));
                }
                connection.DoOutput = true;
                uploadProgress.RewindTo(position);
                using (Stream sourceStream = new FileStream(source.toFile(), FileMode.Open, FileAccess.Read), Stream targetStream = connection.OutputStream)
                {
                    SafeSkip(sourceStream, position);
                    IOUtils.copy(new BufferedInputStream(sourceStream), new ProgressTrackingOutputStream(targetStream, uploadProgress));
                }
                int responseCode = connection.ResponseCode;
                switch (responseCode)
                {
                case HTTP_OK:
                    return(true);                             // the file is now uploaded, all good

                case HTTP_INTERNAL_ERROR:
                case HTTP_UNAVAILABLE:
                    DebugErrorResponse(verbose, connection);
                    return(false);

                default:
                    throw UnexpectedResponse(verbose, connection, "Resumable database upload");
                }
            }
            finally
            {
                connection.disconnect();
            }
        }