小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Hadoop云盤系統(tǒng)

 whbsdu 2015-01-08

 項(xiàng)目名稱:  《Hadoop云盤系統(tǒng)》                

  項(xiàng)目開發(fā)環(huán)境:Linux下Hadoop分布式系統(tǒng)

  項(xiàng)目開發(fā)環(huán)境:Ubuntu11.04+Hadoop0.20.2+JDK1.6+Eclipse3.3.2。

  使用技術(shù):Hadoop + Java

  作品展示地址:http://blog.csdn.net/jtlyuan/article/details/7980826

  作品描述:1、個(gè)人獨(dú)立完成,課余興趣作品。包含全部設(shè)計(jì)、分析、編碼、優(yōu)化。

2、功能實(shí)現(xiàn),文件上傳、下載、刪除、維護(hù)、文件夾的新建、文件路徑跟蹤、以及個(gè)人文件搜索功能實(shí)現(xiàn)和文件分類展現(xiàn)等。

3、基于Hadoop開發(fā)的分布式云平臺(tái)的文件管理系統(tǒng)。

  一、 概況:
    1、這是個(gè)人的業(yè)余愛好項(xiàng)目,自己進(jìn)行了全部的設(shè)計(jì)、分析、編碼、和優(yōu)化。
    2、 根據(jù)現(xiàn)場需求進(jìn)行流程分析與編寫。
    
    3、 根據(jù)所需求的業(yè)務(wù)進(jìn)行開發(fā),代碼編寫,實(shí)現(xiàn)功能。
    4、 對(duì)程序業(yè)務(wù)邏輯進(jìn)行優(yōu)化,使其達(dá)到更高的性能。
    項(xiàng)目難點(diǎn):1、搜索的實(shí)現(xiàn)利用了回溯法進(jìn)行所有文件的搜索,利用字符是否包含來判斷是否進(jìn)入結(jié)果容器中
             2、目錄跟蹤顯示的實(shí)現(xiàn)
這是本人仿照《百度網(wǎng)盤》,利用Hadoop技術(shù)進(jìn)行開發(fā)的《Hadoop云盤系統(tǒng)》
 
       如下圖所示,《百度網(wǎng)盤》和自己做的《Hadoop云盤系統(tǒng)》進(jìn)行了對(duì)比。

                 

                  再看個(gè)人的《云盤》

                  

                                    

                           

                        總結(jié):界面設(shè)計(jì)簡潔,整齊,操作方面,用戶體驗(yàn)良好。

 

三、Hadoop集群主要配置和啟動(dòng)操作操作過程

 

    1、查看集群的主節(jié)點(diǎn)配置。先在Linux中啟動(dòng)Hadoop,如下:查看現(xiàn)在JPS運(yùn)行的進(jìn)程,檢查系統(tǒng)是否正常啟動(dòng)

 

                  

             

 

      2、查看 core-site.xml文件查看主節(jié)點(diǎn)的配置。

                

                                                                  

        3、并在web中 查看 http://192.168.236.132:50030/http://192.168.236.132:50070/ web界面集群啟動(dòng)情況,確定

            無誤后,可以利用Eclipse 啟動(dòng)程序運(yùn)行程序了。

 

四、系統(tǒng)部分測試和主要代碼解析

 

            1、上傳文件,是從本地文件系統(tǒng)中上傳到HDFS中,上傳到當(dāng)前進(jìn)入的目錄當(dāng)中

                              

        主要代碼分析:

  1. JFileChooser chooser = new JFileChooser();  
  2. chooser.setVisible(true);  
  3. int returnVal = chooser.showOpenDialog(null);  
  4. if (returnVal == JFileChooser.APPROVE_OPTION) {// 為確定或OK是  
  5. String localPath = chooser.getSelectedFile()  
  6. .getPath();  
  7. String filename = chooser.getSelectedFile()  
  8. .getName();  
  9. InputStream in = null;  
  10. try {  
  11. in = new BufferedInputStream(  
  12. new FileInputStream(localPath));//本地文件輸入流  
  13. } catch (FileNotFoundException e3) {  
  14. e3.printStackTrace();  
  15. }  
  16. OutputStream out = null;  
  17. try {  
  18. out = hdfs.create(new Path(currentPath  
  19. + "/" + filename),  
  20. new Progressable() {  
  21. public void progress() {  
  22. System.out.print(".");  
  23. }  
  24. });//HDFS路徑的輸出流抽象  
  25. } catch (IOException e2) {  
  26. e2.printStackTrace();  
  27. }  
  28. try {  
  29. IOUtils.copyBytes(in, out, 4096, true);//利用IOUtils工具類實(shí)現(xiàn)上傳  
  30. } catch (IOException e1) {  
  31. e1.printStackTrace();  
  32. }  
  33. try {  
  34. showTable(currentPath);//上傳完畢就刷新當(dāng)前路徑的文件表格  
  35. } catch (IOException e1) {  
  36. e1.printStackTrace();  
  37. }  
  38. }   

 
            2、文件下載分析:從在HDFS中下載到本地文件系統(tǒng)中,
                                                  
                主要代碼分析:
                   
  1. if (e.getSource() == deleItem) {  
  2. int ensuce = JOptionPane.showConfirmDialog(new MainWindow(),  
  3. "確定刪除所選文件嗎", "確認(rèn)對(duì)話框", JOptionPane.YES_NO_OPTION);  
  4. if (ensuce == JOptionPane.NO_OPTION) {  
  5. return;  
  6. }  
  7. if (ensuce == JOptionPane.YES_OPTION) {  
  8. if (fileList.getSelectedRow() >= 0) {  
  9. String temp = currentPath  
  10. + "/"  
  11. + fileList.getValueAt(  
  12. fileList.getSelectedRow(), 0);//獲取要?jiǎng)h掉文件的路徑  
  13. try {  
  14. hdfs.delete(new Path(temp), true);  
  15. } catch (IOException e1) {  
  16. e1.printStackTrace();  
  17. }  
  18. try {  
  19. showTable(currentPath);  
  20. } catch (IOException e1) {  
  21. e1.printStackTrace();  
  22. }  
  23. }  
  24. }   

 
                3、文件表格展現(xiàn)
                           
                   主要代碼:
                         
  1. /*-------------------------------------把currentPath路徑下的文件和文件夾屬性全都顯示表格中----------------------------------------------------------*/  
  2. private void showTable(String currentPath) throws IOException {  
  3. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");  
  4. Path inputDir = new Path(currentPath);/* 獲取文件的路徑*/  
  5. /* FileStatue類*/  
  6. FileStatus[] status = hdfs.listStatus(inputDir);/* 得到文件路徑目錄下文件列表*/  
  7. DefaultTableModel model = (DefaultTableModel) fileList.getModel(); // 獲取表格模型  
  8. if (fileList.getRowCount() != 0) { // 當(dāng)表格中有數(shù)據(jù)  
  9. ((DefaultTableModel) fileList.getModel()).setRowCount(0);// 將表格置空  
  10. }  
  11. for (int i = 0; i < status.length; i++) {  
  12. String filename = null;  
  13. String lenStr = null;  
  14. String modifDate = null;  
  15. filename = status[i].getPath().getName();  
  16. String length = null; // 獲取文件大小信息  
  17. DecimalFormat df = new DecimalFormat("#.00");  
  18. if (status[i].isDir()) {  
  19. lenStr = "-";  
  20. } else {  
  21. if (status[i].getLen() > (1024 * 1024 * 1024)) {  
  22. length = df.format(status[i].getLen()  
  23. / (1024.0 * 1024 * 1024));  
  24. lenStr = " " + length + "G";  
  25. } else if (status[i].getLen() > (1024 * 1024)) {  
  26. length = df.format(status[i].getLen() / (1024.0 * 1024));  
  27. lenStr = " " + length + "M";  
  28. } else if (status[i].getLen() > 1024) {  
  29. length = df.format(status[i].getLen() / 1024.0);  
  30. lenStr = " " + length + "KB";  
  31. } else {  
  32. length = df.format(status[i].getLen());  
  33. lenStr = " " + length + "B";  
  34. }  
  35. }  
  36. modifDate = sdf.format(status[i].getModificationTime());  
  37. model.addRow(new Object[] { filename, lenStr, modifDate }); // 將文件名、文件大小、文件創(chuàng)建日期添加到表格  
  38. }  
  39. }  

 
                    4、文件搜索功能實(shí)現(xiàn)(利用回溯算法+字符匹配來實(shí)現(xiàn))
                
                        先測試一下功能吧!我們輸入“Hadoop”關(guān)鍵字搜索比配的文件
                                          
                        再入:輸入“數(shù)學(xué)”搜索一下結(jié)果
                                        
                        
                      主要實(shí)現(xiàn)代碼
                     
  1. showAllResult(target);//具體實(shí)現(xiàn)   
  2. /*--------------------獲取所有要搜索到的文件路徑---------------------------------*/  
  3. private List<String> findAllFile(String target) {  
  4. List<String> result = new ArrayList<String>();  
  5. char[] tar = target.toCharArray();  
  6. int count = 0;  
  7. String findPath = currentPath;//默認(rèn)搜索的路徑是目前打開目錄下為根的目錄樹  
  8. getAllFile(tar, result, findPath, count);  
  9. return result;  
  10. }  
  11. /*-----------------------------回溯檢測樹形下的文件---------------------------------------------------------*/  
  12. private void getAllFile(char[] tar, List<String> result, String findPath,  
  13. int count) {  
  14. conf = new Configuration();  
  15. try {  
  16. hdfs = FileSystem.get(URI.create(findPath), conf);  
  17. } catch (IOException e) {  
  18. e.printStackTrace();  
  19. }  
  20. try {  
  21. if (hdfs.isFile(new Path(findPath))) {  
  22. String name = hdfs.getFileStatus(new Path(findPath)).getPath()  
  23. .getName();  
  24. if (isFind(tar, name.toCharArray())) {//檢測是否字符匹配,匹配為找到  
  25. result.add(findPath);// 搜索到加入數(shù)組  
  26. }  
  27. return;  
  28. }  
  29. } catch (IOException e) {  
  30. e.printStackTrace();  
  31. }  
  32. FileStatus[] sta = null;  
  33. try {  
  34. sta = hdfs.listStatus(new Path(findPath));  
  35. } catch (IOException e) {  
  36. e.printStackTrace();  
  37. }  
  38. for (int i = 0; i < sta.length; i++) {//回溯法實(shí)現(xiàn)循環(huán)遞歸遍歷  
  39. getAllFile(tar, result, sta[i].getPath().toString(), count++);  
  40. }  
  41. }  
  42. /*-----------------------查看字符串是否包含--------------------------------------------*/  
  43. private boolean isFind(char[] tar, char[] sour) {  
  44. int all=0.0;for (int i = 0; i < tar.length; i++) {  
  45. int j = 0;  
  46. for (; j < sour.length; ++j) {  
  47. if (tar[i] == sour[j]) {  
  48. all++;break;  
  49. }  
  50. }  
  51. if (j == sour.length&&all/sour.length<0.75) {//概率匹配  
  52. return false;  
  53. }  
  54. }  
  55. return true;  
  56. }  

                5、文件分類實(shí)現(xiàn)查詢
                        a、文件分類管理查看,查看“文檔”列出系統(tǒng)中所有的文檔                                            
                                
                          b、“圖片”
                                
                           c、“音樂”
                                    
                           等等 。。。 。。。
                   6、其他的實(shí)現(xiàn),目錄文件跟蹤、文件維護(hù)等:
       *最后說說本系統(tǒng)的信息處理的實(shí)現(xiàn)---MapReduce解決
           首先說下其實(shí)登陸不只是利用數(shù)據(jù)庫來實(shí)現(xiàn)的,解決方法有如下幾種:
           方案一:用另外一臺(tái)機(jī)器專門用于對(duì)數(shù)據(jù)庫操作的。要是在一個(gè)Hadoop中集群中安裝一個(gè)數(shù)據(jù)庫,我們不應(yīng)該把數(shù)據(jù)庫放在namenode中,而是放到另外的一臺(tái)機(jī),因
                          為namenode的任務(wù)已經(jīng)夠多了,安裝在namenode上,多用戶登陸時(shí)對(duì)數(shù)據(jù)庫操作會(huì)消耗namenode的內(nèi)存,會(huì)影響namenode對(duì)datanode的管理和調(diào)度等。
                          所以我們應(yīng)該放到指定的一臺(tái)機(jī)器上。
          方案二:利用利用Hadoop中分布式數(shù)據(jù)庫HBase解決。這個(gè)毫無疑問是最好的解決方案,是針對(duì)云技術(shù)分布式的數(shù)據(jù)庫。不過本人對(duì)HBase還是處于了解階段,所以沒
                         有用上它。
         最終方案:HBase用不上,不過沒關(guān)系,因?yàn)楝F(xiàn)在只是對(duì)一個(gè)用戶信息處理實(shí)現(xiàn),業(yè)務(wù)量很少,我可以仿照Hive那樣,在數(shù)據(jù)進(jìn)行的時(shí)候轉(zhuǎn)化為MapReduce進(jìn)行,利用MapReduce來進(jìn)行表與表的關(guān)聯(lián)。        
                   例如如下表:                                        信息表:
                        登陸表:                                  
                                               
               有待擴(kuò)展的功能模塊我的分享----可以做成分享一個(gè)文件提供所有人下載,也可以做成分享給具體的某個(gè)用戶。
                             實(shí)現(xiàn)方式:做一個(gè)分享表,記錄了 分享人,被分享人,文件獲取的路徑(或者獲取文件所需的參數(shù)參數(shù))
                                       如下:
                                              

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多