From 28b3fd9ca1409657822042fb00ccade3b92c34ce Mon Sep 17 00:00:00 2001 From: v-zhangjc9 Date: Sat, 12 Oct 2024 14:43:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(hudi-query):=20=E5=A2=9E=E5=8A=A0=E5=85=B3?= =?UTF-8?q?=E4=BA=8Ehdfs=E6=96=87=E4=BB=B6=E6=95=B0=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/forest/service/HudiService.java | 9 ++++++++ .../hudi/controller/HdfsController.java | 15 ++++++++++++ .../service/hudi/service/HdfsService.java | 23 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/HudiService.java b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/HudiService.java index 5132eea..82c2b93 100644 --- a/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/HudiService.java +++ b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/HudiService.java @@ -107,4 +107,13 @@ public interface HudiService { @Get("/hdfs/size") Long size(@Query("root") String root); + + @Get("/hdfs/count") + Long count(@Query("root") String root); + + @Get("/hdfs/file_count") + Long fileCount(@Query("root") String root); + + @Get("/hdfs/directory_count") + Long directoryCount(@Query("root") String root); } diff --git a/service-hudi-query/src/main/java/com/lanyuanxiaoyao/service/hudi/controller/HdfsController.java b/service-hudi-query/src/main/java/com/lanyuanxiaoyao/service/hudi/controller/HdfsController.java index e90baee..78fe75c 100644 --- a/service-hudi-query/src/main/java/com/lanyuanxiaoyao/service/hudi/controller/HdfsController.java +++ b/service-hudi-query/src/main/java/com/lanyuanxiaoyao/service/hudi/controller/HdfsController.java @@ -82,4 +82,19 @@ public class HdfsController { public Long size(@RequestParam("root") String root) throws IOException { return hdfsService.size(root); } + + @GetMapping("count") + public Long count(@RequestParam("root") String root) throws IOException { + return hdfsService.size(root); + } + + @GetMapping("file_count") + public Long fileCount(@RequestParam("root") String root) throws IOException { + return hdfsService.size(root); + } + + @GetMapping("directory_count") + public Long DirectoryCount(@RequestParam("root") String root) throws IOException { + return hdfsService.size(root); + } } diff --git a/service-hudi-query/src/main/java/com/lanyuanxiaoyao/service/hudi/service/HdfsService.java b/service-hudi-query/src/main/java/com/lanyuanxiaoyao/service/hudi/service/HdfsService.java index 85aff10..02d6cb1 100644 --- a/service-hudi-query/src/main/java/com/lanyuanxiaoyao/service/hudi/service/HdfsService.java +++ b/service-hudi-query/src/main/java/com/lanyuanxiaoyao/service/hudi/service/HdfsService.java @@ -8,6 +8,7 @@ import com.lanyuanxiaoyao.service.forest.service.InfoService; import java.io.IOException; import java.io.OutputStream; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.ContentSummary; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; @@ -160,4 +161,26 @@ public class HdfsService { return fileSystem.getContentSummary(new Path(root)).getLength(); } } + + @Cacheable(value = "count-hpath", sync = true) + public Long count(String root) throws IOException { + try (FileSystem fileSystem = FileSystem.get(new Configuration())) { + ContentSummary summary = fileSystem.getContentSummary(new Path(root)); + return summary.getFileCount() + summary.getDirectoryCount(); + } + } + + @Cacheable(value = "file-count-hpath", sync = true) + public Long countFiles(String root) throws IOException { + try (FileSystem fileSystem = FileSystem.get(new Configuration())) { + return fileSystem.getContentSummary(new Path(root)).getFileCount(); + } + } + + @Cacheable(value = "directory-count-hpath", sync = true) + public Long countDirectories(String root) throws IOException { + try (FileSystem fileSystem = FileSystem.get(new Configuration())) { + return fileSystem.getContentSummary(new Path(root)).getDirectoryCount(); + } + } }