From 782c0556fb413d54c9d028ddc11d67cdc32585ff Mon Sep 17 00:00:00 2001 From: Takanobu Asanuma Date: Fri, 10 Jan 2020 09:52:13 +0900 Subject: [PATCH] HDFS-15102. HttpFS: put requests are not supported for path "/". Contributed by hemanthboyina. --- .../hadoop/fs/http/server/HttpFSServer.java | 23 +++++++++++++++++++ .../fs/http/server/TestHttpFSServer.java | 7 ++++++ 2 files changed, 30 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java index 4ad1c158e15..faa47c5af73 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java @@ -642,6 +642,29 @@ protected URI createUploadRedirectionURL(UriInfo uriInfo, Enum uploadOperatio return uriBuilder.build(null); } + /** + * Special binding for '/' as it is not handled by the wildcard binding. + * @param is the inputstream for the request payload. + * @param uriInfo the of the request. + * @param op the HttpFS operation of the request. + * @param params the HttpFS parameters of the request. + * + * @return the request response. + * + * @throws IOException thrown if an IO error occurred. Thrown exceptions are + * handled by {@link HttpFSExceptionProvider}. + * @throws FileSystemAccessException thrown if a FileSystemAccess related + * error occurred. Thrown exceptions are handled by + * {@link HttpFSExceptionProvider}. + */ + @PUT + @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8 }) + public Response putRoot(InputStream is, @Context UriInfo uriInfo, + @QueryParam(OperationParam.NAME) OperationParam op, + @Context Parameters params, @Context HttpServletRequest request) + throws IOException, FileSystemAccessException { + return put(is, uriInfo, "/", op, params, request); + } /** * Binding to handle PUT requests. diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java index bcc8e9af85d..88364d264dd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java @@ -1783,5 +1783,12 @@ public void testErasureCodingPolicy() throws Exception { // response should be null dfsDirLst = dfs.getErasureCodingPolicy(path1); Assert.assertNull(dfsDirLst); + + // test put opeartion with path as "/" + final String dir1 = "/"; + HttpURLConnection conn3 = + putCmdWithReturn(dir1, "SETECPOLICY", "ecpolicy=" + ecPolicyName); + // Should return HTTP_OK + Assert.assertEquals(HttpURLConnection.HTTP_OK, conn3.getResponseCode()); } }