首页 > 解决方案 > 我无法向我创建的 Hadoop MiniCluster 写入(放置)

问题描述

    null: [HTTP/1.1 405 HTTP method 
    PUT is not supported by this 
    URL]
    Server: 
    [Jetty(6.1.26.cloudera.4)]
    Pragma: [no-cache]
    Content-Length: [0]
    X-FRAME-OPTIONS: [SAMEORIGIN]
    Date: [Wed, 13 Oct 2021  
     17:05:16 GMT]

''' private static void putTest() throws IOException { System.out.println("putTest : Entry");

URL url = new URL("http://localhost:50070/webapps/v1/longdata.txt&op=CREATE");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("PUT");
        con.setDoOutput(true);
        con.getOutputStream().write("Hey Guys".getBytes(StandardCharsets.UTF_8));
Map<String, List<String>> headers = con.getHeaderFields();
for (String header : headers.keySet())
        {
            
System.out.println(header + ": " + headers.get(header));
        }
System.out.println("putTest : Exit");

}

'''

标签: javahadooplocalhost

解决方案


您需要两个请求- 一个到 namenode 端口,它在 namenode 上创建文件,然后返回一个 datanode 地址,您将在该地址发送第二个地址以写入内容流。

但是,您使用的是 Java,所以只需hadoop-client对方法使用依赖项FileSystem.create,不要使用HttpURLConnection


推荐阅读