浏览代码

HDFS-15102. HttpFS: put requests are not supported for path "/". Contributed by hemanthboyina.

Takanobu Asanuma 5 年之前
父节点
当前提交
782c0556fb

+ 23 - 0
hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java

@@ -642,6 +642,29 @@ public class HttpFSServer {
     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.

+ 7 - 0
hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java

@@ -1783,5 +1783,12 @@ public class TestHttpFSServer extends HFSTestCase {
     // 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());
   }
 }