HDFS-6170. Support GETFILESTATUS operation in WebImageViewer. Contributed by Akira Ajisaka.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1586152 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9a1f15532f
commit
8af0708580
@ -285,6 +285,9 @@ Release 2.5.0 - UNRELEASED
|
|||||||
|
|
||||||
HDFS-6191. Disable quota checks when replaying edit log. (kihwal)
|
HDFS-6191. Disable quota checks when replaying edit log. (kihwal)
|
||||||
|
|
||||||
|
HDFS-6170. Support GETFILESTATUS operation in WebImageViewer.
|
||||||
|
(Akira Ajisaka via wheat9)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
@ -100,7 +100,9 @@ private void handleOperation(String op, String path, MessageEvent e)
|
|||||||
String content = null;
|
String content = null;
|
||||||
|
|
||||||
if (request.getMethod() == HttpMethod.GET){
|
if (request.getMethod() == HttpMethod.GET){
|
||||||
if (op.equals("LISTSTATUS")) {
|
if (op.equals("GETFILESTATUS")) {
|
||||||
|
content = loader.getFileStatus(path);
|
||||||
|
} else if (op.equals("LISTSTATUS")) {
|
||||||
content = loader.listStatus(path);
|
content = loader.listStatus(path);
|
||||||
} else {
|
} else {
|
||||||
response.setStatus(HttpResponseStatus.BAD_REQUEST);
|
response.setStatus(HttpResponseStatus.BAD_REQUEST);
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
* FSImageLoader loads fsimage and provide methods to return JSON formatted
|
* FSImageLoader loads fsimage and provide methods to return JSON formatted
|
||||||
* file status of the namespace of the fsimage.
|
* file status of the namespace of the fsimage.
|
||||||
*/
|
*/
|
||||||
public class FSImageLoader {
|
class FSImageLoader {
|
||||||
public static final Log LOG = LogFactory.getLog(FSImageHandler.class);
|
public static final Log LOG = LogFactory.getLog(FSImageHandler.class);
|
||||||
|
|
||||||
private static String[] stringTable;
|
private static String[] stringTable;
|
||||||
@ -69,7 +69,7 @@ private FSImageLoader() {}
|
|||||||
* @return FSImageLoader
|
* @return FSImageLoader
|
||||||
* @throws IOException if failed to load fsimage.
|
* @throws IOException if failed to load fsimage.
|
||||||
*/
|
*/
|
||||||
public static FSImageLoader load(String inputFile) throws IOException {
|
static FSImageLoader load(String inputFile) throws IOException {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
RandomAccessFile file = new RandomAccessFile(inputFile, "r");
|
RandomAccessFile file = new RandomAccessFile(inputFile, "r");
|
||||||
if (!FSImageUtil.checkFileFormat(file)) {
|
if (!FSImageUtil.checkFileFormat(file)) {
|
||||||
@ -220,13 +220,26 @@ private static void loadStringTable(InputStream in) throws IOException {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the JSON formatted FileStatus of the specified file.
|
||||||
|
* @param path a path specifies a file
|
||||||
|
* @return JSON formatted FileStatus
|
||||||
|
* @throws IOException if failed to serialize fileStatus to JSON.
|
||||||
|
*/
|
||||||
|
String getFileStatus(String path) throws IOException {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
FsImageProto.INodeSection.INode inode = inodes.get(getINodeId(path));
|
||||||
|
return "{\"FileStatus\":\n"
|
||||||
|
+ mapper.writeValueAsString(getFileStatus(inode, false)) + "\n}\n";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the JSON formatted list of the files in the specified directory.
|
* Return the JSON formatted list of the files in the specified directory.
|
||||||
* @param path a path specifies a directory to list
|
* @param path a path specifies a directory to list
|
||||||
* @return JSON formatted file list in the directory
|
* @return JSON formatted file list in the directory
|
||||||
* @throws IOException if failed to serialize fileStatus to JSON.
|
* @throws IOException if failed to serialize fileStatus to JSON.
|
||||||
*/
|
*/
|
||||||
public String listStatus(String path) throws IOException {
|
String listStatus(String path) throws IOException {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
List<Map<String, Object>> fileStatusList = getFileStatusList(path);
|
List<Map<String, Object>> fileStatusList = getFileStatusList(path);
|
||||||
|
@ -268,6 +268,44 @@ public void testWebImageViewer() throws IOException, InterruptedException,
|
|||||||
// compare a file
|
// compare a file
|
||||||
FileStatus status = webhdfs.listStatus(new Path("/dir0/file0"))[0];
|
FileStatus status = webhdfs.listStatus(new Path("/dir0/file0"))[0];
|
||||||
FileStatus expected = writtenFiles.get("/dir0/file0");
|
FileStatus expected = writtenFiles.get("/dir0/file0");
|
||||||
|
compareFile(expected, status);
|
||||||
|
|
||||||
|
// LISTSTATUS operation to a invalid path
|
||||||
|
URL url = new URL("http://localhost:" + port +
|
||||||
|
"/webhdfs/v1/invalid/?op=LISTSTATUS");
|
||||||
|
verifyHttpResponseCode(HttpURLConnection.HTTP_NOT_FOUND, url);
|
||||||
|
|
||||||
|
// LISTSTATUS operation to a invalid prefix
|
||||||
|
url = new URL("http://localhost:" + port + "/webhdfs/v1?op=LISTSTATUS");
|
||||||
|
verifyHttpResponseCode(HttpURLConnection.HTTP_NOT_FOUND, url);
|
||||||
|
|
||||||
|
// GETFILESTATUS operation
|
||||||
|
status = webhdfs.getFileStatus(new Path("/dir0/file0"));
|
||||||
|
compareFile(expected, status);
|
||||||
|
|
||||||
|
// GETFILESTATUS operation to a invalid path
|
||||||
|
url = new URL("http://localhost:" + port +
|
||||||
|
"/webhdfs/v1/invalid/?op=GETFILESTATUS");
|
||||||
|
verifyHttpResponseCode(HttpURLConnection.HTTP_NOT_FOUND, url);
|
||||||
|
|
||||||
|
// invalid operation
|
||||||
|
url = new URL("http://localhost:" + port + "/webhdfs/v1/?op=INVALID");
|
||||||
|
verifyHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST, url);
|
||||||
|
|
||||||
|
// invalid method
|
||||||
|
url = new URL("http://localhost:" + port + "/webhdfs/v1/?op=LISTSTATUS");
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.connect();
|
||||||
|
assertEquals(HttpURLConnection.HTTP_BAD_METHOD,
|
||||||
|
connection.getResponseCode());
|
||||||
|
} finally {
|
||||||
|
// shutdown the viewer
|
||||||
|
viewer.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void compareFile(FileStatus expected, FileStatus status) {
|
||||||
assertEquals(expected.getAccessTime(), status.getAccessTime());
|
assertEquals(expected.getAccessTime(), status.getAccessTime());
|
||||||
assertEquals(expected.getBlockSize(), status.getBlockSize());
|
assertEquals(expected.getBlockSize(), status.getBlockSize());
|
||||||
assertEquals(expected.getGroup(), status.getGroup());
|
assertEquals(expected.getGroup(), status.getGroup());
|
||||||
@ -278,42 +316,13 @@ public void testWebImageViewer() throws IOException, InterruptedException,
|
|||||||
assertEquals(expected.getPermission(), status.getPermission());
|
assertEquals(expected.getPermission(), status.getPermission());
|
||||||
assertEquals(expected.getReplication(), status.getReplication());
|
assertEquals(expected.getReplication(), status.getReplication());
|
||||||
assertEquals(expected.isDirectory(), status.isDirectory());
|
assertEquals(expected.isDirectory(), status.isDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
// LISTSTATUS operation to a invalid path
|
private void verifyHttpResponseCode(int expectedCode, URL url)
|
||||||
URL url = new URL("http://localhost:" + port +
|
throws IOException {
|
||||||
"/webhdfs/v1/invalid/?op=LISTSTATUS");
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
connection.connect();
|
connection.connect();
|
||||||
assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
|
assertEquals(expectedCode, connection.getResponseCode());
|
||||||
connection.getResponseCode());
|
|
||||||
|
|
||||||
// LISTSTATUS operation to a invalid prefix
|
|
||||||
url = new URL("http://localhost:" + port + "/webhdfs/v1?op=LISTSTATUS");
|
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
connection.connect();
|
|
||||||
assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
|
|
||||||
connection.getResponseCode());
|
|
||||||
|
|
||||||
// invalid operation
|
|
||||||
url = new URL("http://localhost:" + port + "/webhdfs/v1/?op=INVALID");
|
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
connection.connect();
|
|
||||||
assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
|
|
||||||
connection.getResponseCode());
|
|
||||||
|
|
||||||
// invalid method
|
|
||||||
url = new URL("http://localhost:" + port + "/webhdfs/v1/?op=LISTSTATUS");
|
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.connect();
|
|
||||||
assertEquals(HttpURLConnection.HTTP_BAD_METHOD,
|
|
||||||
connection.getResponseCode());
|
|
||||||
} finally {
|
|
||||||
// shutdown the viewer
|
|
||||||
viewer.shutdown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user