FsckServlet.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.dfs;
  19. import java.util.*;
  20. import java.io.*;
  21. import org.apache.hadoop.mapred.StatusHttpServer;
  22. import org.apache.hadoop.util.StringUtils;
  23. import org.apache.hadoop.conf.*;
  24. import org.apache.commons.logging.*;
  25. import javax.servlet.ServletContext;
  26. import javax.servlet.ServletException;
  27. import javax.servlet.http.HttpServlet;
  28. import javax.servlet.http.HttpServletRequest;
  29. import javax.servlet.http.HttpServletResponse;
  30. /**
  31. * This class is used in Namesystem's jetty to do fsck on namenode.
  32. * @author Milind Bhandarkar
  33. */
  34. public class FsckServlet extends HttpServlet {
  35. private static final Log LOG = LogFactory.getLog("org.apache.hadoop.dfs.FSNamesystem");
  36. @SuppressWarnings("unchecked")
  37. public void doGet(HttpServletRequest request,
  38. HttpServletResponse response
  39. ) throws ServletException, IOException {
  40. Map<String,String[]> pmap = request.getParameterMap();
  41. try {
  42. ServletContext context = getServletContext();
  43. NameNode nn = (NameNode) context.getAttribute("name.node");
  44. Configuration conf = (Configuration) context.getAttribute("name.conf");
  45. NamenodeFsck fscker = new NamenodeFsck(conf, nn, pmap, response);
  46. fscker.fsck();
  47. } catch (IOException ie) {
  48. StringUtils.stringifyException(ie);
  49. LOG.warn(ie);
  50. String errMsg = "Fsck on path " + pmap.get("path") + " failed.";
  51. response.sendError(HttpServletResponse.SC_GONE, errMsg);
  52. throw ie;
  53. }
  54. }
  55. }