From e28afe9e82bc055ee4b97f5587758ace73edcd76 Mon Sep 17 00:00:00 2001 From: v-zhangjc9 Date: Tue, 19 Mar 2024 16:20:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(command):=20=E5=A2=9E=E5=8A=A0=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E5=8E=8B=E7=BC=A9=E4=BB=BB=E5=8A=A1=E7=9A=84=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/commands/CompactionCommand.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 service-command/src/main/java/com/lanyuanxiaoyao/service/command/commands/CompactionCommand.java diff --git a/service-command/src/main/java/com/lanyuanxiaoyao/service/command/commands/CompactionCommand.java b/service-command/src/main/java/com/lanyuanxiaoyao/service/command/commands/CompactionCommand.java new file mode 100644 index 0000000..49a0509 --- /dev/null +++ b/service-command/src/main/java/com/lanyuanxiaoyao/service/command/commands/CompactionCommand.java @@ -0,0 +1,62 @@ +package com.lanyuanxiaoyao.service.command.commands; + +import cn.hutool.core.util.ObjectUtil; +import com.lanyuanxiaoyao.service.command.utils.CommandLineUtils; +import com.lanyuanxiaoyao.service.command.utils.TableUtils; +import com.lanyuanxiaoyao.service.common.Constants; +import com.lanyuanxiaoyao.service.common.entity.TableMeta; +import com.lanyuanxiaoyao.service.forest.service.InfoService; +import com.lanyuanxiaoyao.service.forest.service.launcher.LauncherService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.shell.standard.ShellComponent; +import org.springframework.shell.standard.ShellMethod; +import org.springframework.shell.standard.ShellOption; + +/** + * 压缩相关操作 + * + * @author lanyuanxiaoyao + * @date 2024-03-19 + */ +@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") +@ShellComponent("压缩任务相关操作") +public class CompactionCommand extends AbstractUtilShellComponent { + private static final Logger logger = LoggerFactory.getLogger(CompactionCommand.class); + private final static String RUN_CONFIRMATION_MESSAGE = "操作将会提交压缩任务, 请再次确认操作"; + + private final InfoService infoService; + private final LauncherService launcherService; + + public CompactionCommand(InfoService infoService, LauncherService launcherService) { + this.infoService = infoService; + this.launcherService = launcherService; + } + + @ShellMethod("启动表压缩任务") + public String compactionRun( + @ShellOption(help = "Flink job id") Long flinkJobIds, + @ShellOption(help = "别名") String alias, + @ShellOption( + help = "Ignore double check", + defaultValue = "false" + ) Boolean ignoreCheck + ) { + TableMeta meta = infoService.tableMetaDetail(flinkJobIds, alias); + return CommandLineUtils.generateResultLines( + () -> { + if (ObjectUtil.isEmpty(meta)) { + return "没有找到指定的表信息"; + } else { + System.out.println(TableUtils.makeTableMeta(meta)); + if (doubleCheck(RUN_CONFIRMATION_MESSAGE, ignoreCheck)) { + launcherService.compactionStop(meta.getJob().getId(), meta.getAlias()); + return Constants.OPERATION_DONE; + } else { + return Constants.OPERATION_CANCEL; + } + } + } + ); + } +}