From a82c00a895a3cc885bb613a4836cb324cd2d42d9 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 4 May 2023 15:04:42 +0800 Subject: [PATCH] =?UTF-8?q?feature(web):=20=E5=A2=9E=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=BD=93=E5=89=8D=E8=BF=90=E8=A1=8C=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 获取当前最新一个运行的 yarn 任务,方便后续 flink 状态查询 --- .../web/controller/BaseController.java | 26 +++++++++++++++++++ .../controller/CompactionYarnController.java | 5 ++++ .../web/controller/SyncYarnController.java | 5 ++++ .../service/web/utils/ComparatorUtil.java | 4 +-- .../resources/static/components/common.js | 17 ++++++++---- 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/BaseController.java b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/BaseController.java index bafd64f..52bac28 100644 --- a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/BaseController.java +++ b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/BaseController.java @@ -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 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 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 filterNames = Lists.immutable.of(names.split(",")); diff --git a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/CompactionYarnController.java b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/CompactionYarnController.java index 694bafb..08ea416 100644 --- a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/CompactionYarnController.java +++ b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/CompactionYarnController.java @@ -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); diff --git a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/SyncYarnController.java b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/SyncYarnController.java index cd65f42..08e9151 100644 --- a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/SyncYarnController.java +++ b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/SyncYarnController.java @@ -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); diff --git a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/utils/ComparatorUtil.java b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/utils/ComparatorUtil.java index 9cffb2d..fdb7309 100644 --- a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/utils/ComparatorUtil.java +++ b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/utils/ComparatorUtil.java @@ -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 Comparator longComparator(String order, String direction, ImmutableMap> getters) { if (StrUtil.isBlank(order) || StrUtil.isBlank(direction) || !getters.containsKey(order)) { diff --git a/service-web/src/main/resources/static/components/common.js b/service-web/src/main/resources/static/components/common.js index 40c2fda..45d2a6d 100644 --- a/service-web/src/main/resources/static/components/common.js +++ b/service-web/src/main/resources/static/components/common.js @@ -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}', }, ], },*/