From d457b5d2f63e4b985648af4d645ccfac5b6e9f2c Mon Sep 17 00:00:00 2001 From: v-zhangjc9 Date: Fri, 10 May 2024 09:32:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(command):=20=E5=A2=9E=E5=8A=A0=E5=8D=87?= =?UTF-8?q?=E9=99=8D=E7=BA=A7hoodie.properties=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/command/commands/ToolCommand.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 service-command/src/main/java/com/lanyuanxiaoyao/service/command/commands/ToolCommand.java diff --git a/service-command/src/main/java/com/lanyuanxiaoyao/service/command/commands/ToolCommand.java b/service-command/src/main/java/com/lanyuanxiaoyao/service/command/commands/ToolCommand.java new file mode 100644 index 0000000..672f5b8 --- /dev/null +++ b/service-command/src/main/java/com/lanyuanxiaoyao/service/command/commands/ToolCommand.java @@ -0,0 +1,80 @@ +package com.lanyuanxiaoyao.service.command.commands; + +import cn.hutool.core.util.StrUtil; +import com.lanyuanxiaoyao.service.configuration.ExecutorProvider; +import com.lanyuanxiaoyao.service.forest.service.HudiService; +import com.lanyuanxiaoyao.service.forest.service.InfoService; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.MutableList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.shell.standard.ShellComponent; +import org.springframework.shell.standard.ShellMethod; + +/** + * 工具 + * + * @author lanyuanxiaoyao + * @date 2024-05-08 + */ +@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") +@ShellComponent("额外操作") +public class ToolCommand { + private static final Logger logger = LoggerFactory.getLogger(ToolCommand.class); + + private final InfoService infoService; + private final HudiService hudiService; + + public ToolCommand(InfoService infoService, HudiService hudiService) { + this.infoService = infoService; + this.hudiService = hudiService; + } + + @ShellMethod("升级hoodie.properties") + public void upgradeHoodieProperties() { + MutableList results = Lists.mutable.empty(); + infoService.tableMetaList() + .asParallel(ExecutorProvider.EXECUTORS, 10) + .forEach(meta -> { + String hdfs = meta.getHudi().getTargetHdfsPath(); + if (hudiService.existsPath(hdfs)) { + String propertiesPath = StrUtil.format("{}/.hoodie/hoodie.properties", hdfs); + String content = hudiService.read(propertiesPath); + if (content.contains("org.apache.hudi.common.model.OverwriteWithLatestAvroPayload") && content.contains("org.apache.hudi.keygen.SimpleKeyGenerator")) { + content = content.replace("org.apache.hudi.common.model.OverwriteWithLatestAvroPayload", "org.apache.hudi.common.model.TraceOverwriteWithLatestAvroPayload"); + content = content.replace("org.apache.hudi.keygen.SimpleKeyGenerator", "org.apache.hudi.keygen.DefaultPartitionNameKeyGenerator"); + hudiService.write(propertiesPath, content, true); + logger.info("{} has rewrote", hdfs); + results.add(StrUtil.format("{} {}", meta.getJob().getId(), meta.getAlias())); + } + } else { + logger.warn("{} not found", hdfs); + } + }); + logger.info("Result:\n{}", results.makeString("\n")); + } + + @ShellMethod("降级hoodie.properties") + public void downgradeHoodieProperties() { + MutableList results = Lists.mutable.empty(); + infoService.tableMetaList() + .asParallel(ExecutorProvider.EXECUTORS, 10) + .forEach(meta -> { + String hdfs = meta.getHudi().getTargetHdfsPath(); + if (hudiService.existsPath(hdfs)) { + String propertiesPath = StrUtil.format("{}/.hoodie/hoodie.properties", hdfs); + String content = hudiService.read(propertiesPath); + if (content.contains("org.apache.hudi.common.model.TraceOverwriteWithLatestAvroPayload") && content.contains("org.apache.hudi.keygen.DefaultPartitionNameKeyGenerator")) { + content = content.replace("org.apache.hudi.common.model.TraceOverwriteWithLatestAvroPayload", "org.apache.hudi.common.model.OverwriteWithLatestAvroPayload"); + content = content.replace("org.apache.hudi.keygen.DefaultPartitionNameKeyGenerator", "org.apache.hudi.keygen.SimpleKeyGenerator"); + hudiService.write(propertiesPath, content, true); + logger.info("{} has rewrote", hdfs); + results.add(StrUtil.format("{} {}", meta.getJob().getId(), meta.getAlias())); + } + } else { + logger.warn("{} not found", hdfs); + } + }); + logger.info("Result:\n{}", results.makeString("\n")); + } +}