Remote Java client uploads files to Hdfs__java

Source: Internet
Author: User
Tags xsl

Hadoop cluster Environment:

Three machines: Namenode0, Datanode1, Datanode2 operating system: Ubuntu 11.04 Server version Haddop: hadoop-0.20.2-cdh3u1 HBase version: hbase-0.90.4-cdh3u2 java version: jdk-6u29-linux-x64

Client machine: Note: Conf needs to add Core-site.xml configuration file, and its content is correct. Permissions problem: The machine in the cluster is running in a Hadoop account, my local machine is running on Lotus account, if upload to hdfs://namenode0:54310/usr/directory will fail, throw permission denied exception. Because owner of the/usr directory is Hadoop, uploading to the hdfs://namenode0:54310/usr/lotus/directory is successful because the Lotus directory owner is set to Lotus account.

<?xml version= "1.0"?> <?xml-stylesheet type= "text/xsl"
href= "configuration.xsl"?>

<!--put Site-specific property overrides in this file. -->

<configuration>
	<property>
		<name>fs.default.name</name>
		< value>hdfs://namenode0:54310</value>
	</property>
</configuration>

Code
Import Java.io.File;

Import Java.net.URI;
Import org.apache.hadoop.conf.Configuration;
Import Org.apache.hadoop.fs.FileStatus;
Import Org.apache.hadoop.fs.FileSystem;


Import Org.apache.hadoop.fs.Path;
	public class Hdfsupload {//hdfsupload Srcfilepath, Dstfilepath public static void Main (string[] args) throws Exception
			{if (Args.length < 2) {System.out.print ("command line:hdfsupload srcfilepath dstfilepath");
		Return
		} String Srcfilepath = Args[0];
		
		String Dstfilepath = args[1];
		Configuration conf = new Configuration ();
		Conf.addresource (New Path ("/home/lotus/work/hadoop-0.20.2-cdh3u1/conf/core-site.xml"));
		
		
		FileSystem HDFs = filesystem.get (conf);
		Path src = new path (Srcfilepath);
		Path DST = new path (Dstfilepath);
		System.out.print ("Start upload");
		Long starttime = System.currenttimemillis ();
		Hdfs.copyfromlocalfile (SRC, DST);
		Long endtime = System.currenttimemillis (); System.out.print ("Finish upload, Cost time:" + string.valueof (EndtIme-starttime)); }

}



Performance test: Hdfsupload/media/pc-book/dd/win2000.dd hdfs://namenode0:54310/usr/lotus/win2000.dd upload a 3.9G DD file, took 428 seconds, The second upload took 377 seconds to study after the performance problem.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.