Changes between Initial Version and Version 1 of III140118/Lab10


Ignore:
Timestamp:
Jan 18, 2014, 12:23:01 AM (10 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • III140118/Lab10

    v1 v1  
     1◢ <[wiki:III140118/Lab9 實作九]> | <[wiki:III140118 回課程大綱]> ▲ | <[wiki:III140118/Lab11 實作十一]> ◣
     2
     3= 實作十 Lab10 =
     4
     5{{{
     6#!html
     7<p style="text-align: center;"><big style="font-weight: bold;"><big>Hadoop FileSystem API 實作(一) <br/>Local 檔案上傳到 HDFS<br/>Upload Local Files and Directories to HDFS</big></big></p>
     8}}}
     9[[PageOutline]]
     10{{{
     11#!text
     12請先連線至 nodeN.3du.me , N 為您的報名編號
     13}}}
     14
     15 * 在上一個實作中,我們可以觀察 !FsShell.java 是如何使用 Path、Configration、!FileSystem 這幾個類別。
     16 * 我們從模仿 hadoop fs -put 對應的函數 copyFromLocal(Path[] srcs, String dstf) 可以重新撰寫一個 Java Application 來學習 Hadoop !FileSystem API
     17{{{
     18#!java
     19 121   /**
     20 122    * Add local files to the indicated FileSystem name. src is kept.
     21 123    */
     22 124   void copyFromLocal(Path[] srcs, String dstf) throws IOException {
     23 125     Path dstPath = new Path(dstf);
     24 126     FileSystem dstFs = dstPath.getFileSystem(getConf());
     25 127     if (srcs.length == 1 && srcs[0].toString().equals("-"))
     26 128       copyFromStdin(dstPath, dstFs);
     27 129     else
     28 130       dstFs.copyFromLocalFile(false, false, srcs, dstPath);
     29 131   }
     30}}}
     31 * 讓我們先來觀察程式運作的情形,請剪貼以下步驟,並嘗試思考觀察到的現象(特別是 hadoop fs -ls 列出的結果差異):
     32{{{
     33cd ~/hadoop_labs/lab004
     34ant
     35hadoop fs -ls
     36hadoop fs -rmr input
     37hadoop jar copyFromLocal.jar doc input
     38hadoop fs -ls
     39touch test
     40hadoop jar copyFromLocal.jar test file
     41hadoop fs -ls
     42
     43export HADOOP_CONF_DIR=~/hadoop/conf.local/
     44hadoop fs -ls
     45hadoop jar copyFromLocal.jar doc input
     46hadoop fs -ls
     47hadoop jar copyFromLocal.jar test file
     48hadoop fs -ls
     49unset HADOOP_CONF_DIR
     50
     51ant clean
     52}}}