Add operation to client hadoop webhdfs

Java client, I quit working together:

import java.io.File; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; public class HdfsAppend { public static final String hdfs = "hdfs://my222host.com"; public static final String hpath = "/tmp/odp/testfile"; public static final String message = "Hello, world!\n"; public static void main(String[] args) throws IOException { Configuration conf = new Configuration(); conf.set("fs.defaultFS", hdfs); FileSystem fs = FileSystem.get(conf); Path filenamePath = new Path(hpath); FSDataOutputStream out = fs.append(filenamePath); out.writeBytes("DUPA DUPA DUPA\n"); } } 

But both curl and the Python whoops client fail in this way, twist here:

 curl -i -X POST "http://my222host:50070/webhdfs/v1/tmp/odp/testfile?op=APPEND" HTTP/1.1 307 TEMPORARY_REDIRECT Cache-Control: no-cache Expires: Tue, 13 Aug 2013 13:26:22 GMT Date: Tue, 13 Aug 2013 13:26:22 GMT Pragma: no-cache Expires: Tue, 13 Aug 2013 13:26:22 GMT Date: Tue, 13 Aug 2013 13:26:22 GMT Pragma: no-cache Content-Type: application/octet-stream Location: http://my333host:50075/webhdfs/v1/tmp/odp/testfile?op=APPEND&namenoderpcaddress=my222host:8020 Content-Length: 0 Server: Jetty(6.1.26.cloudera.2) curl -i -X POST -T /tmp/abc "http://my333host:50075/webhdfs/v1/tmp/odp/testfile?op=APPEND&namenoderpcaddress=my222host:8020" HTTP/1.1 100 Continue HTTP/1.1 403 Forbidden Cache-Control: no-cache Expires: Tue, 13 Aug 2013 13:26:26 GMT Date: Tue, 13 Aug 2013 13:26:26 GMT Pragma: no-cache Expires: Tue, 13 Aug 2013 13:26:26 GMT Date: Tue, 13 Aug 2013 13:26:26 GMT Pragma: no-cache Content-Type: application/json Transfer-Encoding: chunked Server: Jetty(6.1.26.cloudera.2) {"RemoteException":{"exception":"AccessControlException","javaClassName":"org.apache.hadoop.security.AccessControlException","message":"Permission denied: user=dr.who, access=WRITE, inode=\"/tmp/odp/testfile\":root:hadoop:-rw-r--r--\n\tat org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:224)\n\tat org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:155)\n\tat org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkPermission(FSNamesystem.java:4716)\n\tat org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkPermission(FSNamesystem.java:4698)\n\tat org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkPathAccess(FSNamesystem.java:4660)\n\tat org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFileInternal(FSNamesystem.java:1837)\n\tat org.apache.hadoop.hdfs.server.namenode.FSNamesystem.appendFileInt(FSNamesystem.java:2105)\n\tat org.apache.hadoop.hdfs.server.namenode.FSNamesystem.appendFile(FSNamesystem.java:2081)\n\tat org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.append(NameNodeRpcServer.java:434)\n\tat org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.append(ClientNamenodeProtocolServerSideTranslatorPB.java:224)\n\tat org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java:44944)\n\tat org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:453)\n\tat org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1002)\n\tat org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1701)\n\tat org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1697)\n\tat java.security.AccessController.doPrivileged(Native Method)\n\tat javax.security.auth.Subject.doAs(Subject.java:396)\n\tat org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)\n\tat org.apache.hadoop.ipc.Server$Handler.run(Server.java:1695)\n"}} 

Client failure "failure" with "connection failure". What is the problem? The only key I have is "user = dr.who" in java exception when using curl, but I have no idea what the user is using for the Configuration class or how to get it (if this is the root of the problem). Help Pls!

+4
source share
1 answer

Assuming your username is hdfs , add &user.name=hdfs to your URL. A valid user is required for write operations.

Your Java code works because it extracts your user information from a unix environment.

If you see dr.who anywhere, this is probably because you did not set user.name in your query.

+4
source

Source: https://habr.com/ru/post/1496808/


All Articles