| | 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 | {{{ |
| | 33 | cd ~/hadoop_labs/lab004 |
| | 34 | ant |
| | 35 | hadoop fs -ls |
| | 36 | hadoop fs -rmr input |
| | 37 | hadoop jar copyFromLocal.jar doc input |
| | 38 | hadoop fs -ls |
| | 39 | touch test |
| | 40 | hadoop jar copyFromLocal.jar test file |
| | 41 | hadoop fs -ls |
| | 42 | |
| | 43 | export HADOOP_CONF_DIR=~/hadoop/conf.local/ |
| | 44 | hadoop fs -ls |
| | 45 | hadoop jar copyFromLocal.jar doc input |
| | 46 | hadoop fs -ls |
| | 47 | hadoop jar copyFromLocal.jar test file |
| | 48 | hadoop fs -ls |
| | 49 | unset HADOOP_CONF_DIR |
| | 50 | |
| | 51 | ant clean |
| | 52 | }}} |