feature(web): 增加查询当前运行任务接口
获取当前最新一个运行的 yarn 任务,方便后续 flink 状态查询
This commit is contained in:
@@ -10,7 +10,9 @@ import com.lanyuanxiaoyao.service.forest.service.YarnService;
|
||||
import com.lanyuanxiaoyao.service.web.entity.YarnApplicationVO;
|
||||
import com.lanyuanxiaoyao.service.web.utils.ComparatorUtil;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
@@ -33,6 +35,14 @@ public class BaseController {
|
||||
YarnApplication::getFinishedTime
|
||||
);
|
||||
|
||||
protected AmisResponse responseData() {
|
||||
return AmisResponse.builder()
|
||||
.status(SUCCESS_STATUS)
|
||||
.message(SUCCESS_MESSAGE)
|
||||
.data(new HashMap<>())
|
||||
.build();
|
||||
}
|
||||
|
||||
protected AmisResponse responseData(Map<String, Object> data) {
|
||||
return AmisResponse.builder()
|
||||
.status(SUCCESS_STATUS)
|
||||
@@ -86,6 +96,7 @@ public class BaseController {
|
||||
String filterFinalStatus,
|
||||
String searchId,
|
||||
String searchName,
|
||||
// 是否使用精确查询
|
||||
Boolean precise
|
||||
) {
|
||||
boolean isFilterState = StrUtil.isNotBlank(filterState);
|
||||
@@ -111,6 +122,21 @@ public class BaseController {
|
||||
.withData("unRunning", unRunning);
|
||||
}
|
||||
|
||||
protected AmisResponse jobCurrent(YarnService yarnService, String name) {
|
||||
Optional<YarnApplication> currentApp = 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();
|
||||
if (currentApp.isPresent()) {
|
||||
return responseData()
|
||||
.withData("hasCurrent", true)
|
||||
.withData("current", currentApp.get());
|
||||
} else {
|
||||
return responseData().withData("hasCurrent", false);
|
||||
}
|
||||
}
|
||||
|
||||
protected AmisResponse queueList(YarnService yarnService, String names) {
|
||||
boolean isFilterNames = StrUtil.isNotBlank(names);
|
||||
ImmutableList<String> filterNames = Lists.immutable.of(names.split(","));
|
||||
|
||||
@@ -42,6 +42,11 @@ public class CompactionYarnController extends BaseController {
|
||||
return jobList(compactionYarnService, page, count, order, direction, filterState, filterFinalStatus, searchId, searchName, precise);
|
||||
}
|
||||
|
||||
@GetMapping("job_current")
|
||||
public AmisResponse jobCurrent(@RequestParam("name") String name) {
|
||||
return jobCurrent(compactionYarnService, name);
|
||||
}
|
||||
|
||||
@GetMapping("queue_list")
|
||||
public AmisResponse queueList(@RequestParam(value = "names", defaultValue = "") String names) {
|
||||
return queueList(compactionYarnService, names);
|
||||
|
||||
@@ -42,6 +42,11 @@ public class SyncYarnController extends BaseController {
|
||||
return jobList(syncYarnService, page, count, order, direction, filterState, filterFinalStatus, searchId, searchName, precise);
|
||||
}
|
||||
|
||||
@GetMapping("job_current")
|
||||
public AmisResponse jobCurrent(@RequestParam("name") String name) {
|
||||
return jobCurrent(syncYarnService, name);
|
||||
}
|
||||
|
||||
@GetMapping("queue_list")
|
||||
public AmisResponse queueList(@RequestParam(value = "names", defaultValue = "") String names) {
|
||||
return queueList(syncYarnService, names);
|
||||
|
||||
@@ -12,8 +12,8 @@ import org.eclipse.collections.api.map.ImmutableMap;
|
||||
* @date 2023-04-21
|
||||
*/
|
||||
public class ComparatorUtil {
|
||||
private static final String ASC = "asc";
|
||||
private static final String DESC = "desc";
|
||||
public static final String ASC = "asc";
|
||||
public static final String DESC = "desc";
|
||||
|
||||
public static <T> Comparator<T> longComparator(String order, String direction, ImmutableMap<String, Function<T, Long>> getters) {
|
||||
if (StrUtil.isBlank(order) || StrUtil.isBlank(direction) || !getters.containsKey(order)) {
|
||||
|
||||
@@ -170,16 +170,23 @@ function simpleYarnDialog(mode, title) {
|
||||
body: [
|
||||
/*{
|
||||
type: 'service',
|
||||
api: {
|
||||
method: 'get',
|
||||
url: `\${base}/${mode}_yarn/job_current`,
|
||||
data: {
|
||||
name: `\${${mode}JobName}`,
|
||||
}
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: 'hello',
|
||||
visibleOn: '${1 == 1}',
|
||||
type: 'iframe',
|
||||
src: '${current.trackingUrl}',
|
||||
visibleOn: '${hasCurrent}',
|
||||
},
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: 'hello',
|
||||
visibleOn: '${1 == 2}',
|
||||
tpl: '没有正在运行的任务',
|
||||
visibleOn: '${!hasCurrent}',
|
||||
},
|
||||
],
|
||||
},*/
|
||||
|
||||
Reference in New Issue
Block a user