feature(forest): 增加 launcher 接口的操作
This commit is contained in:
@@ -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{
|
||||
}
|
||||
@@ -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{
|
||||
}
|
||||
@@ -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{
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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<String, LauncherService> 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<LauncherService> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user