|
@@ -25,7 +25,6 @@ import org.apache.hadoop.hdfs.protocol.ClientProtocol;
|
|
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
|
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
|
import org.apache.hadoop.hdfs.protocol.DirectoryListing;
|
|
import org.apache.hadoop.hdfs.protocol.DirectoryListing;
|
|
import org.apache.hadoop.hdfs.server.common.JspHelper;
|
|
import org.apache.hadoop.hdfs.server.common.JspHelper;
|
|
-import org.apache.hadoop.ipc.RemoteException;
|
|
|
|
import org.apache.hadoop.util.VersionInfo;
|
|
import org.apache.hadoop.util.VersionInfo;
|
|
|
|
|
|
import org.znerd.xmlenc.*;
|
|
import org.znerd.xmlenc.*;
|
|
@@ -141,60 +140,61 @@ public class ListPathsServlet extends DfsServlet {
|
|
final Configuration conf =
|
|
final Configuration conf =
|
|
(Configuration) getServletContext().getAttribute(JspHelper.CURRENT_CONF);
|
|
(Configuration) getServletContext().getAttribute(JspHelper.CURRENT_CONF);
|
|
|
|
|
|
- ClientProtocol nnproxy = getUGI(request, conf).doAs
|
|
|
|
- (new PrivilegedExceptionAction<ClientProtocol>() {
|
|
|
|
|
|
+ getUGI(request, conf).doAs(new PrivilegedExceptionAction<Void>() {
|
|
@Override
|
|
@Override
|
|
- public ClientProtocol run() throws IOException {
|
|
|
|
- return createNameNodeProxy();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ public Void run() throws IOException {
|
|
|
|
+ ClientProtocol nn = createNameNodeProxy();
|
|
|
|
+ doc.declaration();
|
|
|
|
+ doc.startTag("listing");
|
|
|
|
+ for (Map.Entry<String, String> m : root.entrySet()) {
|
|
|
|
+ doc.attribute(m.getKey(), m.getValue());
|
|
|
|
+ }
|
|
|
|
|
|
- doc.declaration();
|
|
|
|
- doc.startTag("listing");
|
|
|
|
- for (Map.Entry<String,String> m : root.entrySet()) {
|
|
|
|
- doc.attribute(m.getKey(), m.getValue());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- HdfsFileStatus base = nnproxy.getFileInfo(path);
|
|
|
|
- if ((base != null) && base.isDir()) {
|
|
|
|
- writeInfo(path, base, doc);
|
|
|
|
- }
|
|
|
|
|
|
+ HdfsFileStatus base = nn.getFileInfo(path);
|
|
|
|
+ if ((base != null) && base.isDir()) {
|
|
|
|
+ writeInfo(path, base, doc);
|
|
|
|
+ }
|
|
|
|
|
|
- Stack<String> pathstack = new Stack<String>();
|
|
|
|
- pathstack.push(path);
|
|
|
|
- while (!pathstack.empty()) {
|
|
|
|
- String p = pathstack.pop();
|
|
|
|
- try {
|
|
|
|
- byte[] lastReturnedName = HdfsFileStatus.EMPTY_NAME;
|
|
|
|
- DirectoryListing thisListing;
|
|
|
|
- do {
|
|
|
|
- assert lastReturnedName != null;
|
|
|
|
- thisListing = nnproxy.getListing(p, lastReturnedName);
|
|
|
|
- if (thisListing == null) {
|
|
|
|
- if (lastReturnedName.length == 0) {
|
|
|
|
- LOG.warn("ListPathsServlet - Path " + p + " does not exist");
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
|
|
+ Stack<String> pathstack = new Stack<String>();
|
|
|
|
+ pathstack.push(path);
|
|
|
|
+ while (!pathstack.empty()) {
|
|
|
|
+ String p = pathstack.pop();
|
|
|
|
+ try {
|
|
|
|
+ byte[] lastReturnedName = HdfsFileStatus.EMPTY_NAME;
|
|
|
|
+ DirectoryListing thisListing;
|
|
|
|
+ do {
|
|
|
|
+ assert lastReturnedName != null;
|
|
|
|
+ thisListing = nn.getListing(p, lastReturnedName);
|
|
|
|
+ if (thisListing == null) {
|
|
|
|
+ if (lastReturnedName.length == 0) {
|
|
|
|
+ LOG
|
|
|
|
+ .warn("ListPathsServlet - Path " + p
|
|
|
|
+ + " does not exist");
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ HdfsFileStatus[] listing = thisListing.getPartialListing();
|
|
|
|
+ for (HdfsFileStatus i : listing) {
|
|
|
|
+ String localName = i.getLocalName();
|
|
|
|
+ if (exclude.matcher(localName).matches()
|
|
|
|
+ || !filter.matcher(localName).matches()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (recur && i.isDir()) {
|
|
|
|
+ pathstack.push(new Path(p, localName).toUri().getPath());
|
|
|
|
+ }
|
|
|
|
+ writeInfo(p, i, doc);
|
|
|
|
+ }
|
|
|
|
+ lastReturnedName = thisListing.getLastName();
|
|
|
|
+ } while (thisListing.hasMore());
|
|
|
|
+ } catch (IOException re) {
|
|
|
|
+ writeXml(re, p, doc);
|
|
}
|
|
}
|
|
- HdfsFileStatus[] listing = thisListing.getPartialListing();
|
|
|
|
- for (HdfsFileStatus i : listing) {
|
|
|
|
- String localName = i.getLocalName();
|
|
|
|
- if (exclude.matcher(localName).matches()
|
|
|
|
- || !filter.matcher(localName).matches()) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (recur && i.isDir()) {
|
|
|
|
- pathstack.push(new Path(p, localName).toUri().getPath());
|
|
|
|
- }
|
|
|
|
- writeInfo(p, i, doc);
|
|
|
|
- }
|
|
|
|
- lastReturnedName = thisListing.getLastName();
|
|
|
|
- } while (thisListing.hasMore());
|
|
|
|
- } catch(RemoteException re) {re.writeXml(p, doc);}
|
|
|
|
- }
|
|
|
|
- if (doc != null) {
|
|
|
|
- doc.endDocument();
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ doc.endDocument();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
LOG.warn("ListPathServlet encountered InterruptedException", e);
|
|
LOG.warn("ListPathServlet encountered InterruptedException", e);
|
|
response.sendError(400, e.getMessage());
|
|
response.sendError(400, e.getMessage());
|