Ejemplo n.º 1
0
        /// <exception cref="Javax.Servlet.ServletException"/>
        /// <exception cref="System.IO.IOException"/>
        protected override void DoGet(HttpServletRequest request, HttpServletResponse response
                                      )
        {
            FileInputStream editFileIn = null;

            try
            {
                ServletContext context = GetServletContext();
                Configuration  conf    = (Configuration)GetServletContext().GetAttribute(JspHelper.CurrentConf
                                                                                         );
                string journalId = request.GetParameter(JournalIdParam);
                QuorumJournalManager.CheckJournalId(journalId);
                JNStorage storage = JournalNodeHttpServer.GetJournalFromContext(context, journalId
                                                                                ).GetStorage();
                // Check security
                if (!CheckRequestorOrSendError(conf, request, response))
                {
                    return;
                }
                // Check that the namespace info is correct
                if (!CheckStorageInfoOrSendError(storage, request, response))
                {
                    return;
                }
                long segmentTxId       = ServletUtil.ParseLongParam(request, SegmentTxidParam);
                FileJournalManager fjm = storage.GetJournalManager();
                FilePath           editFile;
                lock (fjm)
                {
                    // Synchronize on the FJM so that the file doesn't get finalized
                    // out from underneath us while we're in the process of opening
                    // it up.
                    FileJournalManager.EditLogFile elf = fjm.GetLogFile(segmentTxId);
                    if (elf == null)
                    {
                        response.SendError(HttpServletResponse.ScNotFound, "No edit log found starting at txid "
                                           + segmentTxId);
                        return;
                    }
                    editFile = elf.GetFile();
                    ImageServlet.SetVerificationHeadersForGet(response, editFile);
                    ImageServlet.SetFileNameHeaders(response, editFile);
                    editFileIn = new FileInputStream(editFile);
                }
                DataTransferThrottler throttler = ImageServlet.GetThrottler(conf);
                // send edits
                TransferFsImage.CopyFileToStream(response.GetOutputStream(), editFile, editFileIn
                                                 , throttler);
            }
            catch (Exception t)
            {
                string errMsg = "getedit failed. " + StringUtils.StringifyException(t);
                response.SendError(HttpServletResponse.ScInternalServerError, errMsg);
                throw new IOException(errMsg);
            }
            finally
            {
                IOUtils.CloseStream(editFileIn);
            }
        }
Ejemplo n.º 2
0
            /// <param name="request">the object from which this servlet reads the url contents</param>
            /// <param name="response">the object into which this servlet writes the url contents
            ///     </param>
            /// <exception cref="System.IO.IOException">if the request is bad</exception>
            public GetImageParams(HttpServletRequest request, HttpServletResponse response)
            {
                IDictionary <string, string[]> pmap = request.GetParameterMap();

                isGetImage = isGetEdit = fetchLatest = false;
                foreach (KeyValuePair <string, string[]> entry in pmap)
                {
                    string   key = entry.Key;
                    string[] val = entry.Value;
                    if (key.Equals("getimage"))
                    {
                        isGetImage = true;
                        try
                        {
                            txId = ServletUtil.ParseLongParam(request, TxidParam);
                            string imageType = ServletUtil.GetParameter(request, ImageFileType);
                            nnf = imageType == null ? NNStorage.NameNodeFile.Image : NNStorage.NameNodeFile.ValueOf
                                      (imageType);
                        }
                        catch (FormatException nfe)
                        {
                            if (request.GetParameter(TxidParam).Equals(LatestFsimageValue))
                            {
                                fetchLatest = true;
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                    else
                    {
                        if (key.Equals("getedit"))
                        {
                            isGetEdit = true;
                            startTxId = ServletUtil.ParseLongParam(request, StartTxidParam);
                            endTxId   = ServletUtil.ParseLongParam(request, EndTxidParam);
                        }
                        else
                        {
                            if (key.Equals(StorageinfoParam))
                            {
                                storageInfoString = val[0];
                            }
                        }
                    }
                }
                int numGets = (isGetImage ? 1 : 0) + (isGetEdit ? 1 : 0);

                if ((numGets > 1) || (numGets == 0))
                {
                    throw new IOException("Illegal parameters to TransferFsImage");
                }
            }
Ejemplo n.º 3
0
            /// <exception cref="System.IO.IOException"/>
            public PutImageParams(HttpServletRequest request, HttpServletResponse response, Configuration
                                  conf)
            {
                /*
                 * Params required to handle put image request
                 */
                txId = ServletUtil.ParseLongParam(request, TxidParam);
                storageInfoString = ServletUtil.GetParameter(request, StorageinfoParam);
                fileSize          = ServletUtil.ParseLongParam(request, TransferFsImage.FileLength);
                string imageType = ServletUtil.GetParameter(request, ImageFileType);

                nnf = imageType == null ? NNStorage.NameNodeFile.Image : NNStorage.NameNodeFile.ValueOf
                          (imageType);
                if (fileSize == 0 || txId == -1 || storageInfoString == null || storageInfoString
                    .IsEmpty())
                {
                    throw new IOException("Illegal parameters to TransferFsImage");
                }
            }