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; + } + } + } + ); + } +}