From dfdae40b702e4946da5da35085c5a25ea49e9400 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Tue, 6 Jun 2023 18:20:20 +0800 Subject: [PATCH] =?UTF-8?q?feature(forest):=20=E5=A2=9E=E5=8A=A0=20launche?= =?UTF-8?q?r=20=E6=8E=A5=E5=8F=A3=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/launcher/A4LauncherService.java | 11 +++ .../service/launcher/B1LauncherService.java | 13 ++++ .../service/launcher/B5LauncherService.java | 11 +++ .../service/launcher/LauncherService.java | 16 +++++ .../service/launcher/LaunchersService.java | 69 +++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/A4LauncherService.java create mode 100644 service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/B1LauncherService.java create mode 100644 service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/B5LauncherService.java create mode 100644 service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/LauncherService.java create mode 100644 service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/LaunchersService.java diff --git a/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/A4LauncherService.java b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/A4LauncherService.java new file mode 100644 index 0000000..2cad086 --- /dev/null +++ b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/A4LauncherService.java @@ -0,0 +1,11 @@ +package com.lanyuanxiaoyao.service.forest.service.launcher; + +import com.dtflys.forest.annotation.BaseRequest; + +/** + * @author lanyuanxiaoyao + * @date 2023-06-06 + */ +@BaseRequest(baseURL = "http://service-launcher-compaction-a4") +public interface A4LauncherService extends LauncherService{ +} diff --git a/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/B1LauncherService.java b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/B1LauncherService.java new file mode 100644 index 0000000..d7f3124 --- /dev/null +++ b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/B1LauncherService.java @@ -0,0 +1,13 @@ +package com.lanyuanxiaoyao.service.forest.service.launcher; + +import com.dtflys.forest.annotation.BaseRequest; +import com.dtflys.forest.annotation.Get; +import com.dtflys.forest.annotation.Query; + +/** + * @author lanyuanxiaoyao + * @date 2023-06-06 + */ +@BaseRequest(baseURL = "http://service-launcher-compaction-b1") +public interface B1LauncherService extends LauncherService{ +} diff --git a/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/B5LauncherService.java b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/B5LauncherService.java new file mode 100644 index 0000000..6c5b7c8 --- /dev/null +++ b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/B5LauncherService.java @@ -0,0 +1,11 @@ +package com.lanyuanxiaoyao.service.forest.service.launcher; + +import com.dtflys.forest.annotation.BaseRequest; + +/** + * @author lanyuanxiaoyao + * @date 2023-06-06 + */ +@BaseRequest(baseURL = "http://service-launcher-compaction-b5") +public interface B5LauncherService extends LauncherService{ +} diff --git a/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/LauncherService.java b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/LauncherService.java new file mode 100644 index 0000000..71874e4 --- /dev/null +++ b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/LauncherService.java @@ -0,0 +1,16 @@ +package com.lanyuanxiaoyao.service.forest.service.launcher; + +import com.dtflys.forest.annotation.Get; +import com.dtflys.forest.annotation.Query; + +/** + * @author lanyuanxiaoyao + * @date 2023-06-06 + */ +public interface LauncherService { + @Get("/compaction/stop") + void stop(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias); + + @Get("/compaction/stop_app") + void stopApp(@Query("application_id") String applicationId); +} diff --git a/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/LaunchersService.java b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/LaunchersService.java new file mode 100644 index 0000000..7b70442 --- /dev/null +++ b/service-forest/src/main/java/com/lanyuanxiaoyao/service/forest/service/launcher/LaunchersService.java @@ -0,0 +1,69 @@ +package com.lanyuanxiaoyao.service.forest.service.launcher; + +import cn.hutool.core.util.StrUtil; +import com.eshore.odcp.hudi.connector.Constants; +import org.eclipse.collections.api.factory.Maps; +import org.eclipse.collections.api.list.ImmutableList; +import org.eclipse.collections.api.map.ImmutableMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +/** + * @author lanyuanxiaoyao + * @date 2023-06-06 + */ +@Service +public class LaunchersService { + private static final Logger logger = LoggerFactory.getLogger(LaunchersService.class); + + private final ImmutableMap serviceMap; + + public LaunchersService( + A4LauncherService a4LauncherService, + B1LauncherService b1LauncherService, + B5LauncherService b5LauncherService + ) { + serviceMap = Maps.immutable.of( + Constants.CLUSTER_A4, + a4LauncherService, + Constants.CLUSTER_B1, + b1LauncherService, + Constants.CLUSTER_B5, + b5LauncherService + ); + } + + private LauncherService getService(String cluster) { + if (serviceMap.containsKey(cluster)) { + return serviceMap.get(cluster); + } + throw new RuntimeException(StrUtil.format("Cluster {} not found", cluster)); + } + + private ImmutableList getServices() { + return serviceMap.valuesView().toList().toImmutable(); + } + + public void stop(Long flinkJobId, String alias) { + for (LauncherService service : getServices()) { + service.stop(flinkJobId, alias); + } + } + + public void stop(String cluster, Long flinkJobId, String alias) { + LauncherService service = getService(cluster); + service.stop(flinkJobId, alias); + } + + public void stopApp(String applicationId) { + for (LauncherService service : getServices()) { + service.stopApp(applicationId); + } + } + + public void stopApp(String cluster, String applicationId) { + LauncherService service = getService(cluster); + service.stopApp(applicationId); + } +}