refactor(web): 优化 yarn 信息的获取
This commit is contained in:
@@ -8,7 +8,6 @@ import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnRootQueue;
|
||||
import com.lanyuanxiaoyao.service.forest.service.YarnClusterService;
|
||||
import com.lanyuanxiaoyao.service.forest.service.YarnService;
|
||||
import com.lanyuanxiaoyao.service.web.entity.YarnApplicationVO;
|
||||
import com.lanyuanxiaoyao.service.web.entity.YarnClusterVO;
|
||||
import com.lanyuanxiaoyao.service.web.utils.ComparatorUtil;
|
||||
@@ -20,6 +19,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.function.Function;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.slf4j.Logger;
|
||||
@@ -46,21 +46,10 @@ public class YarnController extends BaseController {
|
||||
"finishedTime",
|
||||
YarnApplication::getFinishedTime
|
||||
);
|
||||
private final ImmutableMap<String, YarnService> yarnServices;
|
||||
private final YarnClusterService yarnClusterService;
|
||||
|
||||
public YarnController(YarnClusterService yarnClusterService) {
|
||||
this.yarnServices = yarnClusterService.servicesMap();
|
||||
}
|
||||
|
||||
private YarnService getService(String cluster) {
|
||||
if (!yarnServices.containsKey(cluster)) {
|
||||
throw new RuntimeException(StrUtil.format("Cluster {} not found", cluster));
|
||||
}
|
||||
return yarnServices.get(cluster);
|
||||
}
|
||||
|
||||
private ImmutableList<YarnService> getServices(List<String> clusters) {
|
||||
return Lists.immutable.ofAll(clusters).collect(this::getService);
|
||||
this.yarnClusterService = yarnClusterService;
|
||||
}
|
||||
|
||||
@GetMapping("job_list")
|
||||
@@ -81,9 +70,8 @@ public class YarnController extends BaseController {
|
||||
boolean isSearchId = StrUtil.isNotBlank(searchId);
|
||||
boolean isSearchName = StrUtil.isNotBlank(searchName);
|
||||
Comparator<YarnApplication> comparator = ComparatorUtil.longComparator(order, direction, SORT_MAP);
|
||||
ImmutableList<YarnApplication> applications = getServices(clusters)
|
||||
ImmutableList<YarnApplication> applications = yarnClusterService.jobList(Sets.immutable.ofAll(clusters))
|
||||
.asParallel(EXECUTOR, 1)
|
||||
.flatCollect(YarnService::jobList)
|
||||
.select(app -> !isFilterState || ObjectUtil.contains(filterState, app.getState()))
|
||||
.select(app -> !isFilterFinalStatus || ObjectUtil.contains(filterFinalStatus, app.getFinalStatus()))
|
||||
.select(app -> !isSearchId || (precise ? StrUtil.equals(app.getId(), searchId) : StrUtil.contains(app.getId(), searchId)))
|
||||
@@ -103,10 +91,8 @@ public class YarnController extends BaseController {
|
||||
|
||||
@GetMapping("job_current")
|
||||
public AmisResponse jobCurrent(@RequestParam("clusters") List<String> clusters, @RequestParam("name") String name) {
|
||||
Optional<YarnApplication> currentApp = getServices(clusters)
|
||||
Optional<YarnApplication> currentApp = yarnClusterService.jobListEquals(Sets.immutable.ofAll(clusters), name)
|
||||
.asParallel(EXECUTOR, 1)
|
||||
.flatCollect(YarnService::jobList)
|
||||
.select(app -> ObjectUtil.equals(app.getName(), name))
|
||||
.select(app -> ObjectUtil.equals(app.getState(), "RUNNING"))
|
||||
.toSortedList(ComparatorUtil.longComparator("startedTime", ComparatorUtil.DESC, SORT_MAP))
|
||||
.getFirstOptional();
|
||||
@@ -123,7 +109,7 @@ public class YarnController extends BaseController {
|
||||
public AmisResponse queueList(@RequestParam("clusters") List<String> clusters, @RequestParam(value = "names", defaultValue = "") String names) {
|
||||
boolean isFilterNames = StrUtil.isNotBlank(names);
|
||||
ImmutableList<String> filterNames = Lists.immutable.of(names.split(","));
|
||||
ImmutableList<YarnClusterVO> results = getServices(clusters)
|
||||
ImmutableList<YarnClusterVO> results = yarnClusterService.services()
|
||||
.asParallel(EXECUTOR, 1)
|
||||
.collect(yarnService -> {
|
||||
YarnRootQueue cluster = yarnService.cluster();
|
||||
@@ -137,11 +123,11 @@ public class YarnController extends BaseController {
|
||||
|
||||
@GetMapping("queue_names")
|
||||
public AmisResponse queueNames(@RequestParam("clusters") List<String> clusters) {
|
||||
return responseData(MapUtil.of("queueNames", getServices(clusters).flatCollect(YarnService::queueList).collect(YarnQueue::getQueueName)));
|
||||
return responseData(MapUtil.of("queueNames", yarnClusterService.queueList(Sets.immutable.ofAll(clusters)).collect(YarnQueue::getQueueName)));
|
||||
}
|
||||
|
||||
@GetMapping("clusters")
|
||||
public AmisResponse clusters(@RequestParam("clusters") List<String> clusters) {
|
||||
return responseData(MapUtil.of("cluster", getServices(clusters).collect(YarnService::cluster)));
|
||||
return responseData(MapUtil.of("cluster", yarnClusterService.cluster(Sets.immutable.ofAll(clusters))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user