refactor(web): 优化统一的返回值封装和适配

This commit is contained in:
2023-07-06 14:31:24 +08:00
parent 47bd555fbf
commit 894faae2ed
18 changed files with 288 additions and 242 deletions

View File

@@ -3,6 +3,8 @@ package com.lanyuanxiaoyao.service.web.controller;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.web.controller.base.AmisCrudResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisMapResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse; import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import com.lanyuanxiaoyao.service.web.entity.CloudServiceVO; import com.lanyuanxiaoyao.service.web.entity.CloudServiceVO;
@@ -81,19 +83,19 @@ public class CloudController extends BaseController {
} }
@GetMapping("list") @GetMapping("list")
public AmisResponse list() { public AmisCrudResponse list() {
ImmutableList<CloudServiceVO> serviceVOS = serviceVOS(CloudServiceVO.Service::getServiceId); ImmutableList<CloudServiceVO> serviceVOS = serviceVOS(CloudServiceVO.Service::getServiceId);
return AmisResponse.responseCrudData(serviceVOS, serviceVOS.size()); return AmisResponse.responseCrudData(serviceVOS, serviceVOS.size());
} }
@GetMapping("list_ip") @GetMapping("list_ip")
public AmisResponse listIp() { public AmisCrudResponse listIp() {
ImmutableList<CloudServiceVO> serviceVOS = serviceVOS(CloudServiceVO.Service::getHost); ImmutableList<CloudServiceVO> serviceVOS = serviceVOS(CloudServiceVO.Service::getHost);
return AmisResponse.responseCrudData(serviceVOS, serviceVOS.size()); return AmisResponse.responseCrudData(serviceVOS, serviceVOS.size());
} }
@GetMapping("deploy_plan") @GetMapping("deploy_plan")
public AmisResponse deployPlan() { public AmisMapResponse deployPlan() {
ImmutableList<CloudServiceVO.Service> services = services(); ImmutableList<CloudServiceVO.Service> services = services();
ImmutableList<String> deployExists = services.collect(service -> StrUtil.format("{}-{}", service.getServiceId(), service.getHost())); ImmutableList<String> deployExists = services.collect(service -> StrUtil.format("{}-{}", service.getServiceId(), service.getHost()));
ImmutableList<String> serviceIds = services.collect(CloudServiceVO.Service::getServiceId).distinct().toSortedList().toImmutable(); ImmutableList<String> serviceIds = services.collect(CloudServiceVO.Service::getServiceId).distinct().toSortedList().toImmutable();
@@ -122,7 +124,7 @@ public class CloudController extends BaseController {
.put("tpl", "${" + key + "}") .put("tpl", "${" + key + "}")
.build(); .build();
})); }));
return AmisResponse.responseData( return AmisResponse.responseMapData(
MapUtil.<String, Object>builder() MapUtil.<String, Object>builder()
.put("type", "service") .put("type", "service")
.put("data", MapUtil.builder() .put("data", MapUtil.builder()
@@ -140,7 +142,7 @@ public class CloudController extends BaseController {
} }
@GetMapping("heart") @GetMapping("heart")
public AmisResponse heart() { public AmisMapResponse heart() {
return AmisResponse.responseData().withData("status", true); return AmisResponse.responseMapData("status", true);
} }
} }

View File

@@ -2,9 +2,11 @@ package com.lanyuanxiaoyao.service.web.controller;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.configuration.ExecutorProvider; import com.lanyuanxiaoyao.service.configuration.ExecutorProvider;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.entity.flink.FlinkCheckpoint; import com.lanyuanxiaoyao.service.configuration.entity.flink.FlinkCheckpoint;
import com.lanyuanxiaoyao.service.configuration.entity.flink.FlinkOverview;
import com.lanyuanxiaoyao.service.forest.service.FlinkService; import com.lanyuanxiaoyao.service.forest.service.FlinkService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisCrudResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import com.lanyuanxiaoyao.service.web.entity.FlinkVertexVO; import com.lanyuanxiaoyao.service.web.entity.FlinkVertexVO;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@@ -35,12 +37,12 @@ public class FlinkController extends BaseController {
} }
@GetMapping("overview") @GetMapping("overview")
public AmisResponse overview(@RequestParam("url") String url) throws ExecutionException, InterruptedException { public AmisResponse<FlinkOverview> overview(@RequestParam("url") String url) throws ExecutionException, InterruptedException {
return AmisResponse.responseDetail(flinkService.overview(url)); return AmisResponse.responseSuccess(flinkService.overview(url));
} }
@GetMapping("jobs") @GetMapping("jobs")
public AmisResponse jobs( public AmisCrudResponse jobs(
@RequestParam("url") String url, @RequestParam("url") String url,
@RequestParam(value = "mode", required = false) String mode, @RequestParam(value = "mode", required = false) String mode,
@RequestParam(value = "schema", required = false) String schema, @RequestParam(value = "schema", required = false) String schema,

View File

@@ -2,10 +2,12 @@ package com.lanyuanxiaoyao.service.web.controller;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.entity.PageResponse; import com.lanyuanxiaoyao.service.configuration.entity.PageResponse;
import com.lanyuanxiaoyao.service.configuration.entity.hudi.HudiCompactionPlan;
import com.lanyuanxiaoyao.service.configuration.entity.hudi.HudiInstant; import com.lanyuanxiaoyao.service.configuration.entity.hudi.HudiInstant;
import com.lanyuanxiaoyao.service.forest.service.HudiService; import com.lanyuanxiaoyao.service.forest.service.HudiService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisCrudResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
@@ -29,7 +31,10 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("hudi") @RequestMapping("hudi")
public class HudiController extends BaseController { public class HudiController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(HudiController.class); private static final Logger logger = LoggerFactory.getLogger(HudiController.class);
private static final ImmutableMap<String, Function<HudiInstant, String>> TIMELINE_SORT_MAP = Maps.immutable.of(
"timestamp",
HudiInstant::getTimestamp
);
private final HudiService hudiService; private final HudiService hudiService;
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@@ -37,13 +42,8 @@ public class HudiController extends BaseController {
this.hudiService = hudiService; this.hudiService = hudiService;
} }
private static final ImmutableMap<String, Function<HudiInstant, String>> TIMELINE_SORT_MAP = Maps.immutable.of(
"timestamp",
HudiInstant::getTimestamp
);
@GetMapping("/timeline/list") @GetMapping("/timeline/list")
public AmisResponse timeline( public AmisCrudResponse timeline(
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "count", defaultValue = "10") Integer count, @RequestParam(value = "count", defaultValue = "10") Integer count,
@RequestParam(value = "order", defaultValue = "timestamp") String order, @RequestParam(value = "order", defaultValue = "timestamp") String order,
@@ -69,7 +69,7 @@ public class HudiController extends BaseController {
} }
@GetMapping("/timeline/list_hdfs") @GetMapping("/timeline/list_hdfs")
public AmisResponse timelineHdfs( public AmisCrudResponse timelineHdfs(
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "count", defaultValue = "10") Integer count, @RequestParam(value = "count", defaultValue = "10") Integer count,
@RequestParam(value = "order", defaultValue = "timestamp") String order, @RequestParam(value = "order", defaultValue = "timestamp") String order,
@@ -103,16 +103,16 @@ public class HudiController extends BaseController {
} }
@GetMapping("read_compaction_plan") @GetMapping("read_compaction_plan")
public AmisResponse readCompactionPlan( public AmisResponse<HudiCompactionPlan> readCompactionPlan(
@RequestParam(value = "flink_job_id", required = false) Long flinkJobId, @RequestParam(value = "flink_job_id", required = false) Long flinkJobId,
@RequestParam(value = "alias", required = false) String alias, @RequestParam(value = "alias", required = false) String alias,
@RequestParam(value = "hdfs", required = false) String hdfs, @RequestParam(value = "hdfs", required = false) String hdfs,
@RequestParam("instant") String instant @RequestParam("instant") String instant
) throws Exception { ) throws Exception {
if (StrUtil.isNotBlank(hdfs)) { if (StrUtil.isNotBlank(hdfs)) {
return AmisResponse.responseDetail(hudiService.readCompactionPlanHdfs(hdfs, instant)); return AmisResponse.responseSuccess(hudiService.readCompactionPlanHdfs(hdfs, instant));
} else if (ObjectUtil.isNotNull(flinkJobId) && StrUtil.isNotBlank(alias)) { } else if (ObjectUtil.isNotNull(flinkJobId) && StrUtil.isNotBlank(alias)) {
return AmisResponse.responseDetail(hudiService.readCompactionPlan(flinkJobId, alias, instant)); return AmisResponse.responseSuccess(hudiService.readCompactionPlan(flinkJobId, alias, instant));
} }
throw new Exception("Flink job id and alias or hdfs cannot be blank"); throw new Exception("Flink job id and alias or hdfs cannot be blank");
} }

View File

@@ -1,9 +1,10 @@
package com.lanyuanxiaoyao.service.web.controller; package com.lanyuanxiaoyao.service.web.controller;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.entity.loki.LokiLogLine; import com.lanyuanxiaoyao.service.configuration.entity.loki.LokiLogLine;
import com.lanyuanxiaoyao.service.forest.service.LokiService; import com.lanyuanxiaoyao.service.forest.service.LokiService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisDetailResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -37,8 +38,8 @@ public class LogController extends BaseController {
} }
@GetMapping("query_sync_log") @GetMapping("query_sync_log")
public AmisResponse querySyncLog(@RequestParam("flink_job_id") Long flinkJobId) { public AmisDetailResponse querySyncLog(@RequestParam("flink_job_id") Long flinkJobId) {
return AmisResponse.responseDetail(lokiService.queryRange(MapUtil.<String, String>builder() return AmisResponse.responseDetailData(lokiService.queryRange(MapUtil.<String, String>builder()
.put("app", "hudi-sync") .put("app", "hudi-sync")
.put("run_type", "sync") .put("run_type", "sync")
.put("flink_job_id", flinkJobId.toString()) .put("flink_job_id", flinkJobId.toString())
@@ -50,8 +51,8 @@ public class LogController extends BaseController {
} }
@GetMapping("query_compaction_log") @GetMapping("query_compaction_log")
public AmisResponse queryCompactionLog(@RequestParam("flink_job_id") Long flinkJobId, @RequestParam("alias") String alias) { public AmisDetailResponse queryCompactionLog(@RequestParam("flink_job_id") Long flinkJobId, @RequestParam("alias") String alias) {
return AmisResponse.responseDetail(lokiService.queryRange(MapUtil.<String, String>builder() return AmisResponse.responseDetailData(lokiService.queryRange(MapUtil.<String, String>builder()
.put("app", "hudi-sync") .put("app", "hudi-sync")
.put("run_type", "compaction") .put("run_type", "compaction")
.put("flink_job_id", flinkJobId.toString()) .put("flink_job_id", flinkJobId.toString())
@@ -64,8 +65,8 @@ public class LogController extends BaseController {
} }
@GetMapping("query_application_log") @GetMapping("query_application_log")
public AmisResponse queryApplicationLog(@RequestParam("application_id") String applicationId) { public AmisDetailResponse queryApplicationLog(@RequestParam("application_id") String applicationId) {
return AmisResponse.responseDetail(lokiService.queryRange(MapUtil.<String, String>builder() return AmisResponse.responseDetailData(lokiService.queryRange(MapUtil.<String, String>builder()
.put("app", "hudi-sync") .put("app", "hudi-sync")
.put("app_id", applicationId) .put("app_id", applicationId)
.build()) .build())

View File

@@ -9,6 +9,8 @@ import com.lanyuanxiaoyao.service.forest.service.InfoService;
import com.lanyuanxiaoyao.service.forest.service.QueueService; import com.lanyuanxiaoyao.service.forest.service.QueueService;
import com.lanyuanxiaoyao.service.forest.service.ScheduleService; import com.lanyuanxiaoyao.service.forest.service.ScheduleService;
import com.lanyuanxiaoyao.service.forest.service.YarnService; import com.lanyuanxiaoyao.service.forest.service.YarnService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisCrudResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisMapResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse; import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import com.lanyuanxiaoyao.service.web.entity.JobIdAndAliasVO; import com.lanyuanxiaoyao.service.web.entity.JobIdAndAliasVO;
@@ -35,7 +37,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("overview") @RequestMapping("overview")
public class OverviewController extends BaseController { public class OverviewController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(OverviewController.class); private static final Logger logger = LoggerFactory.getLogger(OverviewController.class);
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
private final InfoService infoService; private final InfoService infoService;
private final YarnService yarnService; private final YarnService yarnService;
private final QueueService queueService; private final QueueService queueService;
@@ -50,7 +52,7 @@ public class OverviewController extends BaseController {
} }
@GetMapping("") @GetMapping("")
public AmisResponse overview() throws ExecutionException, InterruptedException { public AmisMapResponse overview() throws ExecutionException, InterruptedException {
CompletableFuture<Long> tableCountFuture = CompletableFuture.supplyAsync(infoService::tableCount, ExecutorProvider.EXECUTORS); CompletableFuture<Long> tableCountFuture = CompletableFuture.supplyAsync(infoService::tableCount, ExecutorProvider.EXECUTORS);
CompletableFuture<Long> tableFocusCountFuture = CompletableFuture.supplyAsync(infoService::tableFocusCount, ExecutorProvider.EXECUTORS); CompletableFuture<Long> tableFocusCountFuture = CompletableFuture.supplyAsync(infoService::tableFocusCount, ExecutorProvider.EXECUTORS);
CompletableFuture<Long> hudiCountFuture = CompletableFuture.supplyAsync(infoService::hudiCount, ExecutorProvider.EXECUTORS); CompletableFuture<Long> hudiCountFuture = CompletableFuture.supplyAsync(infoService::hudiCount, ExecutorProvider.EXECUTORS);
@@ -65,66 +67,63 @@ public class OverviewController extends BaseController {
hiveCountFuture, hiveCountFuture,
hiveFocusCountFuture hiveFocusCountFuture
).get(); ).get();
return AmisResponse.responseData() return AmisResponse.responseMapData()
.withData("table_count", tableCountFuture.get()) .setData("table_count", tableCountFuture.get())
.withData("table_focus_count", tableFocusCountFuture.get()) .setData("table_focus_count", tableFocusCountFuture.get())
.withData("hudi_count", hudiCountFuture.get()) .setData("hudi_count", hudiCountFuture.get())
.withData("hudi_focus_count", hudiFocusCountFuture.get()) .setData("hudi_focus_count", hudiFocusCountFuture.get())
.withData("hive_count", hiveCountFuture.get()) .setData("hive_count", hiveCountFuture.get())
.withData("hive_focus_count", hiveFocusCountFuture.get()); .setData("hive_focus_count", hiveFocusCountFuture.get());
} }
@GetMapping("yarn-job") @GetMapping("yarn-job")
private AmisResponse yarnOverview(@RequestParam("cluster") String cluster, @RequestParam("search") String text) { private AmisMapResponse yarnOverview(@RequestParam("cluster") String cluster, @RequestParam("search") String text) {
boolean isSearch = StrUtil.isNotBlank(text); boolean isSearch = StrUtil.isNotBlank(text);
ImmutableList<YarnApplication> applications = yarnService.jobList(cluster).select(app -> !isSearch || StrUtil.contains(app.getName(), text)); ImmutableList<YarnApplication> applications = yarnService.jobList(cluster).select(app -> !isSearch || StrUtil.contains(app.getName(), text));
return AmisResponse.responseData() return AmisResponse.responseMapData()
.withData("name", cluster) .setData("name", cluster)
.withData("total", applications.size()) .setData("total", applications.size())
.withData("running", applications.count(app -> StrUtil.equals(app.getState(), "RUNNING"))) .setData("running", applications.count(app -> StrUtil.equals(app.getState(), "RUNNING")))
.withData("running", applications.count(app -> StrUtil.equals(app.getState(), "RUNNING"))) .setData("running", applications.count(app -> StrUtil.equals(app.getState(), "RUNNING")))
.withData("scheduling", applications.count(app -> StrUtil.equals(app.getState(), "ACCEPTED"))) .setData("scheduling", applications.count(app -> StrUtil.equals(app.getState(), "ACCEPTED")))
.withData("failure", applications.count(app -> StrUtil.equals(app.getState(), "FAILED"))); .setData("failure", applications.count(app -> StrUtil.equals(app.getState(), "FAILED")));
} }
@GetMapping("yarn-cluster") @GetMapping("yarn-cluster")
public AmisResponse yarnClusterOverview(@RequestParam("cluster") String cluster, @RequestParam("queue") String queue) { public AmisMapResponse yarnClusterOverview(@RequestParam("cluster") String cluster, @RequestParam("queue") String queue) {
AmisResponse response = AmisResponse.responseData(); AmisMapResponse response = AmisResponse.responseMapData();
YarnRootQueue root = yarnService.cluster(cluster); YarnRootQueue root = yarnService.cluster(cluster);
response.withData("root", root); response.setData("root", root);
if (StrUtil.isNotBlank(queue)) { if (StrUtil.isNotBlank(queue)) {
yarnService.queueList(cluster) yarnService.queueList(cluster)
.select(q -> StrUtil.equals(q.getQueueName(), queue)) .select(q -> StrUtil.equals(q.getQueueName(), queue))
.getFirstOptional() .getFirstOptional()
.ifPresent(yarnQueue -> response.withData("target", yarnQueue)); .ifPresent(yarnQueue -> response.setData("target", yarnQueue));
} }
return response; return response;
} }
@GetMapping("queue") @GetMapping("queue")
public AmisResponse queueOverview(@RequestParam("queue") String queue) { public AmisMapResponse queueOverview(@RequestParam("queue") String queue) {
return AmisResponse.responseData() return AmisResponse.responseMapData("size", queueService.size(queue));
.withData("size", queueService.size(queue));
} }
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
@GetMapping("version") @GetMapping("version")
public AmisResponse versionOverview() throws ExecutionException, InterruptedException { public AmisMapResponse versionOverview() throws ExecutionException, InterruptedException {
String version = LocalDateTime.now().minusDays(1).format(FORMATTER); String version = LocalDateTime.now().minusDays(1).format(FORMATTER);
CompletableFuture<Long> unReceiveNormalTableCount = CompletableFuture.supplyAsync(() -> infoService.unReceiveVersionNormalTableCount(version), ExecutorProvider.EXECUTORS); CompletableFuture<Long> unReceiveNormalTableCount = CompletableFuture.supplyAsync(() -> infoService.unReceiveVersionNormalTableCount(version), ExecutorProvider.EXECUTORS);
CompletableFuture<Long> unReceiveFocusCount = CompletableFuture.supplyAsync(() -> infoService.unReceiveVersionFocusTableCount(version), ExecutorProvider.EXECUTORS); CompletableFuture<Long> unReceiveFocusCount = CompletableFuture.supplyAsync(() -> infoService.unReceiveVersionFocusTableCount(version), ExecutorProvider.EXECUTORS);
CompletableFuture<Long> unScheduledNormalTableCount = CompletableFuture.supplyAsync(() -> infoService.unScheduledNormalTableCount(version), ExecutorProvider.EXECUTORS); CompletableFuture<Long> unScheduledNormalTableCount = CompletableFuture.supplyAsync(() -> infoService.unScheduledNormalTableCount(version), ExecutorProvider.EXECUTORS);
CompletableFuture<Long> unScheduledFocusTableCount = CompletableFuture.supplyAsync(() -> infoService.unScheduledFocusTableCount(version), ExecutorProvider.EXECUTORS); CompletableFuture<Long> unScheduledFocusTableCount = CompletableFuture.supplyAsync(() -> infoService.unScheduledFocusTableCount(version), ExecutorProvider.EXECUTORS);
CompletableFuture.allOf(unReceiveNormalTableCount, unReceiveFocusCount, unScheduledNormalTableCount, unScheduledFocusTableCount).get(); CompletableFuture.allOf(unReceiveNormalTableCount, unReceiveFocusCount, unScheduledNormalTableCount, unScheduledFocusTableCount).get();
return AmisResponse.responseData() return AmisResponse.responseMapData()
.withData("version", version) .setData("version", version)
.withData("unReceive", Maps.immutable.of("normal", unReceiveNormalTableCount.get(), "focus", unReceiveFocusCount.get())) .setData("unReceive", Maps.immutable.of("normal", unReceiveNormalTableCount.get(), "focus", unReceiveFocusCount.get()))
.withData("unSchedule", Maps.immutable.of("normal", unScheduledNormalTableCount.get(), "focus", unScheduledFocusTableCount.get())); .setData("unSchedule", Maps.immutable.of("normal", unScheduledNormalTableCount.get(), "focus", unScheduledFocusTableCount.get()));
} }
@GetMapping("version_detail") @GetMapping("version_detail")
public AmisResponse versionDetail(String target, String version) throws Exception { public AmisCrudResponse versionDetail(String target, String version) throws Exception {
ImmutableList<JobIdAndAlias> jobIdAndAliases; ImmutableList<JobIdAndAlias> jobIdAndAliases;
if (StrUtil.equals("unReceive_focus", target)) { if (StrUtil.equals("unReceive_focus", target)) {
jobIdAndAliases = infoService.unReceiveVersionFocusTable(version); jobIdAndAliases = infoService.unReceiveVersionFocusTable(version);
@@ -141,7 +140,7 @@ public class OverviewController extends BaseController {
} }
@GetMapping("schedule_jobs") @GetMapping("schedule_jobs")
public AmisResponse scheduleJobs() { public AmisCrudResponse scheduleJobs() {
return AmisResponse.responseCrudData(scheduleService.scheduleJobs()); return AmisResponse.responseCrudData(scheduleService.scheduleJobs());
} }
} }

View File

@@ -1,7 +1,7 @@
package com.lanyuanxiaoyao.service.web.controller; package com.lanyuanxiaoyao.service.web.controller;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.forest.service.PulsarService; import com.lanyuanxiaoyao.service.forest.service.PulsarService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import com.lanyuanxiaoyao.service.web.entity.TopicVO; import com.lanyuanxiaoyao.service.web.entity.TopicVO;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -30,7 +30,7 @@ public class PulsarController extends BaseController {
} }
@GetMapping("topic") @GetMapping("topic")
public AmisResponse topic(@RequestParam("pulsar_url") String pulsarUrl, @RequestParam("topic") String topic) { public AmisResponse<TopicVO> topic(@RequestParam("pulsar_url") String pulsarUrl, @RequestParam("topic") String topic) {
return AmisResponse.responseDetail(new TopicVO(pulsarService.topic(pulsarService.name(pulsarUrl), topic))); return AmisResponse.responseSuccess(new TopicVO(pulsarService.topic(pulsarService.name(pulsarUrl), topic)));
} }
} }

View File

@@ -1,8 +1,9 @@
package com.lanyuanxiaoyao.service.web.controller; package com.lanyuanxiaoyao.service.web.controller;
import com.lanyuanxiaoyao.micro.service.entity.queue.QueueItem; import com.lanyuanxiaoyao.micro.service.entity.queue.QueueItem;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.forest.service.QueueService; import com.lanyuanxiaoyao.service.forest.service.QueueService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisCrudResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -30,7 +31,7 @@ public class QueueController extends BaseController {
} }
@GetMapping("all") @GetMapping("all")
public AmisResponse all(@RequestParam("name") String name) { public AmisCrudResponse all(@RequestParam("name") String name) {
return AmisResponse.responseCrudData(queueService.all(name).toSortedList(QueueItem::compareTo)); return AmisResponse.responseCrudData(queueService.all(name).toSortedList(QueueItem::compareTo));
} }
} }

View File

@@ -5,9 +5,10 @@ import com.eshore.odcp.hudi.connector.utils.NameHelper;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.lanyuanxiaoyao.service.configuration.ExecutorProvider; import com.lanyuanxiaoyao.service.configuration.ExecutorProvider;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.entity.zookeeper.ZookeeperNode; import com.lanyuanxiaoyao.service.configuration.entity.zookeeper.ZookeeperNode;
import com.lanyuanxiaoyao.service.forest.service.ZookeeperService; import com.lanyuanxiaoyao.service.forest.service.ZookeeperService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisCrudResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import com.lanyuanxiaoyao.service.web.entity.ZookeeperNodeVO; import com.lanyuanxiaoyao.service.web.entity.ZookeeperNodeVO;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -38,7 +39,7 @@ public class RunningController extends BaseController {
} }
@GetMapping("sync") @GetMapping("sync")
public AmisResponse sync() { public AmisCrudResponse sync() {
return AmisResponse.responseCrudData( return AmisResponse.responseCrudData(
zookeeperService.getChildren(NameHelper.ZK_SYNC_RUNNING_LOCK_PATH) zookeeperService.getChildren(NameHelper.ZK_SYNC_RUNNING_LOCK_PATH)
.asParallel(ExecutorProvider.EXECUTORS, 1) .asParallel(ExecutorProvider.EXECUTORS, 1)
@@ -50,7 +51,7 @@ public class RunningController extends BaseController {
} }
@GetMapping("compaction") @GetMapping("compaction")
public AmisResponse compaction() { public AmisCrudResponse compaction() {
return AmisResponse.responseCrudData( return AmisResponse.responseCrudData(
zookeeperService.getChildren(NameHelper.ZK_COMPACTION_RUNNING_LOCK_PATH) zookeeperService.getChildren(NameHelper.ZK_COMPACTION_RUNNING_LOCK_PATH)
.asParallel(ExecutorProvider.EXECUTORS, 1) .asParallel(ExecutorProvider.EXECUTORS, 1)

View File

@@ -9,12 +9,14 @@ import com.eshore.odcp.hudi.connector.entity.TableMeta;
import com.eshore.odcp.hudi.connector.utils.NameHelper; import com.eshore.odcp.hudi.connector.utils.NameHelper;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.lanyuanxiaoyao.service.configuration.ExecutorProvider; import com.lanyuanxiaoyao.service.configuration.ExecutorProvider;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.entity.PageResponse; import com.lanyuanxiaoyao.service.configuration.entity.PageResponse;
import com.lanyuanxiaoyao.service.configuration.entity.info.CompactionMetrics; import com.lanyuanxiaoyao.service.configuration.entity.info.CompactionMetrics;
import com.lanyuanxiaoyao.service.configuration.entity.info.JobIdAndAlias; import com.lanyuanxiaoyao.service.configuration.entity.info.JobIdAndAlias;
import com.lanyuanxiaoyao.service.forest.service.InfoService; import com.lanyuanxiaoyao.service.forest.service.InfoService;
import com.lanyuanxiaoyao.service.forest.service.ZookeeperService; import com.lanyuanxiaoyao.service.forest.service.ZookeeperService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisCrudResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisMapResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import com.lanyuanxiaoyao.service.web.entity.CompactionMetricsVO; import com.lanyuanxiaoyao.service.web.entity.CompactionMetricsVO;
import com.lanyuanxiaoyao.service.web.entity.FlinkJobVO; import com.lanyuanxiaoyao.service.web.entity.FlinkJobVO;
@@ -142,7 +144,7 @@ public class TableController extends BaseController {
} }
@GetMapping("list_metas") @GetMapping("list_metas")
public AmisResponse listTableMetas(@RequestParam("flink_job_id") Long flinkJobId) throws Exception { public AmisCrudResponse listTableMetas(@RequestParam("flink_job_id") Long flinkJobId) throws Exception {
if (ObjectUtil.isNull(flinkJobId)) { if (ObjectUtil.isNull(flinkJobId)) {
throw new Exception("flink job id is null"); throw new Exception("flink job id is null");
} }
@@ -150,20 +152,20 @@ public class TableController extends BaseController {
} }
@GetMapping("detail") @GetMapping("detail")
public AmisResponse getMeta(@RequestParam("flink_job_id") Long flinkJobId, @RequestParam("alias") String alias) throws Exception { public AmisMapResponse getMeta(@RequestParam("flink_job_id") Long flinkJobId, @RequestParam("alias") String alias) throws Exception {
if (ObjectUtil.isNull(flinkJobId) || ObjectUtil.isNull(alias)) { if (ObjectUtil.isNull(flinkJobId) || ObjectUtil.isNull(alias)) {
throw new Exception("flink job id or alias is null"); throw new Exception("flink job id or alias is null");
} }
CompletableFuture<FlinkJob> flinkJobFuture = CompletableFuture.supplyAsync(() -> infoService.flinkJobDetail(flinkJobId), ExecutorProvider.EXECUTORS); CompletableFuture<FlinkJob> flinkJobFuture = CompletableFuture.supplyAsync(() -> infoService.flinkJobDetail(flinkJobId), ExecutorProvider.EXECUTORS);
CompletableFuture<TableMeta> tableMetaFuture = CompletableFuture.supplyAsync(() -> infoService.tableMetaDetail(flinkJobId, alias), ExecutorProvider.EXECUTORS); CompletableFuture<TableMeta> tableMetaFuture = CompletableFuture.supplyAsync(() -> infoService.tableMetaDetail(flinkJobId, alias), ExecutorProvider.EXECUTORS);
CompletableFuture.allOf(flinkJobFuture, tableMetaFuture).get(); CompletableFuture.allOf(flinkJobFuture, tableMetaFuture).get();
return AmisResponse.responseData() return AmisResponse.responseMapData()
.withData("flinkJob", new FlinkJobVO(flinkJobFuture.get())) .setData("flinkJob", new FlinkJobVO(flinkJobFuture.get()))
.withData("tableMeta", tableMetaFuture.get()); .setData("tableMeta", tableMetaFuture.get());
} }
@GetMapping("list_compaction_metrics") @GetMapping("list_compaction_metrics")
public AmisResponse listCompactionMetrics( public AmisCrudResponse listCompactionMetrics(
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "count", defaultValue = "10") Integer count, @RequestParam(value = "count", defaultValue = "10") Integer count,
@RequestParam(value = "order", required = false) String order, @RequestParam(value = "order", required = false) String order,

View File

@@ -5,10 +5,11 @@ import cn.hutool.core.util.StrUtil;
import com.eshore.odcp.hudi.connector.entity.FlinkJob; import com.eshore.odcp.hudi.connector.entity.FlinkJob;
import com.eshore.odcp.hudi.connector.entity.TableMeta; import com.eshore.odcp.hudi.connector.entity.TableMeta;
import com.lanyuanxiaoyao.service.configuration.ExecutorProvider; import com.lanyuanxiaoyao.service.configuration.ExecutorProvider;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.entity.PageResponse; import com.lanyuanxiaoyao.service.configuration.entity.PageResponse;
import com.lanyuanxiaoyao.service.configuration.entity.info.VersionUpdated; import com.lanyuanxiaoyao.service.configuration.entity.info.VersionUpdated;
import com.lanyuanxiaoyao.service.forest.service.InfoService; import com.lanyuanxiaoyao.service.forest.service.InfoService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisMapResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import com.lanyuanxiaoyao.service.web.entity.VersionUpdateVO; import com.lanyuanxiaoyao.service.web.entity.VersionUpdateVO;
import java.util.List; import java.util.List;
@@ -43,7 +44,7 @@ public class VersionController extends BaseController {
} }
@GetMapping("list") @GetMapping("list")
public AmisResponse list( public AmisMapResponse list(
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "count", defaultValue = "10") Integer count, @RequestParam(value = "count", defaultValue = "10") Integer count,
@RequestParam(value = "order", required = false) String order, @RequestParam(value = "order", required = false) String order,
@@ -87,7 +88,7 @@ public class VersionController extends BaseController {
.toList() .toList()
.toImmutable(); .toImmutable();
return AmisResponse.responseCrudData(vos, total) return AmisResponse.responseCrudData(vos, total)
.withData("scheduled", pageResponse.getMetadata().get("scheduled")) .setData("scheduled", pageResponse.getMetadata().get("scheduled"))
.withData("unScheduled", pageResponse.getMetadata().get("unScheduled")); .setData("unScheduled", pageResponse.getMetadata().get("unScheduled"));
} }
} }

View File

@@ -1,21 +1,22 @@
package com.lanyuanxiaoyao.service.web.controller; package com.lanyuanxiaoyao.service.web.controller;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.configuration.ExecutorProvider; import com.lanyuanxiaoyao.service.configuration.ExecutorProvider;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.entity.flink.FlinkVertex; import com.lanyuanxiaoyao.service.configuration.entity.flink.FlinkVertex;
import com.lanyuanxiaoyao.service.configuration.entity.flink.FlinkVertexOverview; import com.lanyuanxiaoyao.service.configuration.entity.flink.FlinkVertexOverview;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication; import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue; import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnRootQueue; import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnRootQueue;
import com.lanyuanxiaoyao.service.configuration.utils.ComparatorUtil;
import com.lanyuanxiaoyao.service.forest.service.FlinkService; import com.lanyuanxiaoyao.service.forest.service.FlinkService;
import com.lanyuanxiaoyao.service.forest.service.YarnService; import com.lanyuanxiaoyao.service.forest.service.YarnService;
import com.lanyuanxiaoyao.service.web.controller.base.AmisCrudResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisMapResponse;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.controller.base.BaseController;
import com.lanyuanxiaoyao.service.web.entity.YarnApplicationVO; import com.lanyuanxiaoyao.service.web.entity.YarnApplicationVO;
import com.lanyuanxiaoyao.service.web.entity.YarnClusterVO; import com.lanyuanxiaoyao.service.web.entity.YarnClusterVO;
import com.lanyuanxiaoyao.service.configuration.utils.ComparatorUtil;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@@ -57,7 +58,7 @@ public class YarnController extends BaseController {
} }
@GetMapping("job_list") @GetMapping("job_list")
public AmisResponse jobList( public AmisMapResponse jobList(
@RequestParam("clusters") List<String> clusters, @RequestParam("clusters") List<String> clusters,
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "count", defaultValue = "10") Integer count, @RequestParam(value = "count", defaultValue = "10") Integer count,
@@ -120,12 +121,12 @@ public class YarnController extends BaseController {
.toList() .toList()
.toImmutable(); .toImmutable();
return AmisResponse.responseCrudData(result, applications.size()) return AmisResponse.responseCrudData(result, applications.size())
.withData("running", running) .setData("running", running)
.withData("unRunning", unRunning); .setData("unRunning", unRunning);
} }
@GetMapping("job_current") @GetMapping("job_current")
public AmisResponse jobCurrent(@RequestParam("clusters") List<String> clusters, @RequestParam("name") String name) { public AmisMapResponse jobCurrent(@RequestParam("clusters") List<String> clusters, @RequestParam("name") String name) {
Optional<YarnApplication> currentApp = Lists.immutable.ofAll(clusters) Optional<YarnApplication> currentApp = Lists.immutable.ofAll(clusters)
.asParallel(ExecutorProvider.EXECUTORS, 1) .asParallel(ExecutorProvider.EXECUTORS, 1)
.flatCollect(cluster -> yarnService.jobListEquals(cluster, name)) .flatCollect(cluster -> yarnService.jobListEquals(cluster, name))
@@ -133,16 +134,16 @@ public class YarnController extends BaseController {
.toSortedList(ComparatorUtil.longComparator("startedTime", ComparatorUtil.DESC, SORT_MAP)) .toSortedList(ComparatorUtil.longComparator("startedTime", ComparatorUtil.DESC, SORT_MAP))
.getFirstOptional(); .getFirstOptional();
if (currentApp.isPresent()) { if (currentApp.isPresent()) {
return AmisResponse.responseData() return AmisResponse.responseMapData()
.withData("hasCurrent", true) .setData("hasCurrent", true)
.withData("current", currentApp.get()); .setData("current", currentApp.get());
} else { } else {
return AmisResponse.responseData().withData("hasCurrent", false); return AmisResponse.responseMapData("hasCurrent", false);
} }
} }
@GetMapping("queue_list") @GetMapping("queue_list")
public AmisResponse queueList(@RequestParam("clusters") List<String> clusters, @RequestParam(value = "names", defaultValue = "") String names) { public AmisCrudResponse queueList(@RequestParam("clusters") List<String> clusters, @RequestParam(value = "names", defaultValue = "") String names) {
boolean isFilterNames = StrUtil.isNotBlank(names); boolean isFilterNames = StrUtil.isNotBlank(names);
ImmutableList<String> filterNames = Lists.immutable.of(names.split(",")); ImmutableList<String> filterNames = Lists.immutable.of(names.split(","));
ImmutableList<YarnClusterVO> results = Lists.immutable.ofAll(clusters) ImmutableList<YarnClusterVO> results = Lists.immutable.ofAll(clusters)
@@ -158,23 +159,23 @@ public class YarnController extends BaseController {
} }
@GetMapping("queue_names") @GetMapping("queue_names")
public AmisResponse queueNames(@RequestParam("clusters") List<String> clusters) { public AmisMapResponse queueNames(@RequestParam("clusters") List<String> clusters) {
ImmutableList<String> names = Lists.immutable.ofAll(clusters) ImmutableList<String> names = Lists.immutable.ofAll(clusters)
.asParallel(ExecutorProvider.EXECUTORS, 1) .asParallel(ExecutorProvider.EXECUTORS, 1)
.flatCollect(yarnService::queueList) .flatCollect(yarnService::queueList)
.collect(YarnQueue::getQueueName) .collect(YarnQueue::getQueueName)
.toList() .toList()
.toImmutable(); .toImmutable();
return AmisResponse.responseData(MapUtil.of("queueNames", names)); return AmisResponse.responseMapData("queueNames", names);
} }
@GetMapping("clusters") @GetMapping("clusters")
public AmisResponse clusters(@RequestParam("clusters") List<String> clusters) { public AmisMapResponse clusters(@RequestParam("clusters") List<String> clusters) {
ImmutableList<YarnRootQueue> roots = (ImmutableList<YarnRootQueue>) Lists.immutable.ofAll(clusters) ImmutableList<YarnRootQueue> roots = Lists.immutable.ofAll(clusters)
.asParallel(ExecutorProvider.EXECUTORS, 1) .asParallel(ExecutorProvider.EXECUTORS, 1)
.collect(yarnService::cluster) .collect(yarnService::cluster)
.toList() .toList()
.toImmutable(); .toImmutable();
return AmisResponse.responseData(MapUtil.of("cluster", clusters)); return AmisResponse.responseMapData("cluster", clusters);
} }
} }

View File

@@ -0,0 +1,30 @@
package com.lanyuanxiaoyao.service.web.controller.base;
/**
* Crud 响应
*
* @author lanyuanxiaoyao
* @date 2023-07-06
*/
public class AmisCrudResponse extends AmisMapResponse {
public void setData(Iterable<?> list) {
getData().put("item", list);
}
public void setTotal(Long total) {
getData().put("total", total);
}
public void setTotal(Integer total) {
setTotal(total.longValue());
}
public void setData(Iterable<?> list, Long total) {
setData(list);
setTotal(total);
}
public void setData(Iterable<?> list, Integer total) {
setData(list, total.longValue());
}
}

View File

@@ -0,0 +1,13 @@
package com.lanyuanxiaoyao.service.web.controller.base;
/**
* Crud 响应
*
* @author lanyuanxiaoyao
* @date 2023-07-06
*/
public class AmisDetailResponse extends AmisMapResponse {
public void setDetail(Object detail) {
getData().put("detail", detail);
}
}

View File

@@ -0,0 +1,21 @@
package com.lanyuanxiaoyao.service.web.controller.base;
import java.util.HashMap;
import java.util.Map;
/**
* Map 响应
*
* @author lanyuanxiaoyao
* @date 2023-07-06
*/
public class AmisMapResponse extends AmisResponse<Map<String, Object>> {
public AmisMapResponse() {
setData(new HashMap<>());
}
public AmisMapResponse setData(String key, Object value) {
getData().put(key, value);
return this;
}
}

View File

@@ -1,7 +1,5 @@
package com.lanyuanxiaoyao.service.web.controller.base; package com.lanyuanxiaoyao.service.web.controller.base;
import cn.hutool.core.map.MapUtil;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@@ -10,19 +8,102 @@ import java.util.Map;
* @author lanyuanxiaoyao * @author lanyuanxiaoyao
* @date 2022-09-21 * @date 2022-09-21
*/ */
public class AmisResponse { public class AmisResponse<T> {
private static final int SUCCESS_STATUS = 0;
private static final int ERROR_STATUS = 500;
private static final String SUCCESS_MESSAGE = "OK";
private static final String ERROR_MESSAGE = "ERROR";
private Integer status; private Integer status;
private String message; private String message;
private Map<String, Object> data; private T data;
public AmisResponse(Builder builder) { public static AmisResponse<Object> responseError() {
this.status = builder.status; AmisResponse<Object> response = new AmisResponse<>();
this.message = builder.message; response.setStatus(ERROR_STATUS);
this.data = builder.data; response.setMessage(ERROR_MESSAGE);
return response;
} }
public static Builder builder() { public static AmisResponse<Object> responseError(String message) {
return new Builder(); AmisResponse<Object> response = new AmisResponse<>();
response.setStatus(ERROR_STATUS);
response.setMessage(message);
return response;
}
public static AmisResponse<Object> responseSuccess() {
AmisResponse<Object> response = new AmisResponse<>();
response.setStatus(SUCCESS_STATUS);
response.setMessage(SUCCESS_MESSAGE);
return response;
}
public static AmisResponse<Object> responseSuccess(String message) {
AmisResponse<Object> response = new AmisResponse<>();
response.setStatus(SUCCESS_STATUS);
response.setMessage(message);
return response;
}
public static <E> AmisResponse<E> responseSuccess(String message, E data) {
AmisResponse<E> response = new AmisResponse<>();
response.setStatus(SUCCESS_STATUS);
response.setMessage(message);
response.setData(data);
return response;
}
public static <E> AmisResponse<E> responseSuccess(E data) {
AmisResponse<E> response = new AmisResponse<>();
response.setStatus(SUCCESS_STATUS);
response.setMessage(SUCCESS_MESSAGE);
response.setData(data);
return response;
}
public static AmisMapResponse responseMapData() {
AmisMapResponse response = new AmisMapResponse();
response.setStatus(SUCCESS_STATUS);
response.setMessage(SUCCESS_MESSAGE);
return response;
}
public static AmisMapResponse responseMapData(Map<String, Object> data) {
AmisMapResponse response = responseMapData();
response.setData(data);
return response;
}
public static AmisMapResponse responseMapData(String key, Object value) {
AmisMapResponse response = responseMapData();
response.setData(key, value);
return response;
}
public static AmisCrudResponse responseCrudData(Iterable<?> data) {
AmisCrudResponse response = new AmisCrudResponse();
response.setStatus(SUCCESS_STATUS);
response.setMessage(SUCCESS_MESSAGE);
response.setData(data);
return response;
}
public static AmisCrudResponse responseCrudData(Iterable<?> data, Integer total) {
AmisCrudResponse response = responseCrudData(data);
response.setTotal(total);
return response;
}
public static AmisCrudResponse responseCrudData(Iterable<?> data, Long total) {
AmisCrudResponse response = responseCrudData(data);
response.setTotal(total);
return response;
}
public static AmisDetailResponse responseDetailData(Object detail) {
AmisDetailResponse response = new AmisDetailResponse();
response.setDetail(detail);
return response;
} }
public Integer getStatus() { public Integer getStatus() {
@@ -41,19 +122,14 @@ public class AmisResponse {
this.message = message; this.message = message;
} }
public Map<String, Object> getData() { public T getData() {
return data; return data;
} }
public void setData(Map<String, Object> data) { public void setData(T data) {
this.data = data; this.data = data;
} }
public AmisResponse withData(String key, Object value) {
data.put(key, value);
return this;
}
@Override @Override
public String toString() { public String toString() {
return "AmisResponse{" + return "AmisResponse{" +
@@ -62,102 +138,4 @@ public class AmisResponse {
", data=" + data + ", data=" + data +
'}'; '}';
} }
public static final class Builder {
private Integer status = 0;
private String message = "";
private Map<String, Object> data = null;
private Builder() {
}
public Builder status(Integer status) {
this.status = status;
return this;
}
public Builder message(String message) {
this.message = message;
return this;
}
public Builder data(Map<String, Object> data) {
this.data = data;
return this;
}
public AmisResponse build() {
return new AmisResponse(this);
}
}
private static final int SUCCESS_STATUS = 0;
private static final int ERROR_STATUS = 500;
private static final String SUCCESS_MESSAGE = "OK";
private static final String ERROR_MESSAGE = "ERROR";
public static AmisResponse responseError() {
return AmisResponse.builder()
.status(ERROR_STATUS)
.message(ERROR_MESSAGE)
.build();
}
public static AmisResponse responseError(String message) {
return AmisResponse.builder()
.status(ERROR_STATUS)
.message(message)
.build();
}
public static AmisResponse responseData() {
return AmisResponse.builder()
.status(SUCCESS_STATUS)
.message(SUCCESS_MESSAGE)
.data(new HashMap<>())
.build();
}
public static AmisResponse responseData(Map<String, Object> data) {
return AmisResponse.builder()
.status(SUCCESS_STATUS)
.message(SUCCESS_MESSAGE)
.data(data)
.build();
}
public static AmisResponse responseDetail(Object detail) {
return AmisResponse.builder()
.status(SUCCESS_STATUS)
.message(SUCCESS_MESSAGE)
.data(MapUtil.<String, Object>builder()
.put("detail", detail)
.build())
.build();
}
public static AmisResponse responseCrudData(Iterable<?> data) {
return AmisResponse.builder()
.status(SUCCESS_STATUS)
.message(SUCCESS_MESSAGE)
.data(MapUtil.<String, Object>builder()
.put("items", data)
.build())
.build();
}
public static AmisResponse responseCrudData(Iterable<?> data, Integer total) {
return responseCrudData(data, Integer.toUnsignedLong(total));
}
public static AmisResponse responseCrudData(Iterable<?> data, Long total) {
return AmisResponse.builder()
.status(SUCCESS_STATUS)
.message(SUCCESS_MESSAGE)
.data(MapUtil.<String, Object>builder()
.put("items", data)
.put("total", total)
.build())
.build();
}
} }

View File

@@ -1,13 +1,9 @@
package com.lanyuanxiaoyao.service.web.controller.base; package com.lanyuanxiaoyao.service.web.controller.base;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.configuration.Constants; import com.lanyuanxiaoyao.service.configuration.Constants;
import com.lanyuanxiaoyao.service.web.controller.base.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.exception.TableNotFoundException; import com.lanyuanxiaoyao.service.configuration.exception.TableNotFoundException;
import com.lanyuanxiaoyao.service.forest.service.InfoService; import com.lanyuanxiaoyao.service.forest.service.InfoService;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.map.MutableMap;

View File

@@ -1,8 +1,6 @@
package com.lanyuanxiaoyao.service.web.controller.base; package com.lanyuanxiaoyao.service.web.controller.base;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;

View File

@@ -456,15 +456,15 @@ function simpleYarnDialog(cluster, title, filterField) {
title: 'Flink 基本信息', title: 'Flink 基本信息',
column: 4, column: 4,
items: [ items: [
{label: 'Flink 版本', content: '${detail.flinkVersion}'}, {label: 'Flink 版本', content: '${flinkVersion}'},
{label: 'Flink 小版本', content: '${detail.flinkCommit}', span: 3}, {label: 'Flink 小版本', content: '${flinkCommit}', span: 3},
{label: '运行中', content: '${detail.jobsRunning}'}, {label: '运行中', content: '${jobsRunning}'},
{label: '已结束', content: '${detail.jobsFinished}'}, {label: '已结束', content: '${jobsFinished}'},
{label: '已失败', content: '${detail.jobsFailed}'}, {label: '已失败', content: '${jobsFailed}'},
{label: '被取消', content: '${detail.jobsCanceled}'}, {label: '被取消', content: '${jobsCanceled}'},
{ {
label: 'Slot (可用/总数)', label: 'Slot (可用/总数)',
content: '${detail.slotsAvailable}/${detail.slotsTotal}', content: '${slotsAvailable}/${slotsTotal}',
span: 4 span: 4
}, },
] ]
@@ -816,7 +816,7 @@ function timelineColumns() {
}, },
adaptor: (payload, response) => { adaptor: (payload, response) => {
return { return {
items: (payload['data']['detail']['operations'] ? payload['data']['detail']['operations'] : []) items: (payload['data']['operations'] ? payload['data']['operations'] : [])
.map(operation => { .map(operation => {
if (operation['deltaFilePaths']) { if (operation['deltaFilePaths']) {
operation.deltaFilePaths = operation.deltaFilePaths operation.deltaFilePaths = operation.deltaFilePaths
@@ -1132,8 +1132,8 @@ function tableMetaDialog() {
type: 'property', type: 'property',
title: '基本信息', title: '基本信息',
items: [ items: [
{label: 'Topic', content: copyField('detail.name'), span: 2}, {label: 'Topic', content: copyField('name'), span: 2},
{label: '最末位移', content: copyField('detail.lastMessageId')}, {label: '最末位移', content: copyField('lastMessageId')},
], ],
}, },
{type: 'divider'}, {type: 'divider'},
@@ -1142,40 +1142,40 @@ function tableMetaDialog() {
title: '指标信息', title: '指标信息',
column: 4, column: 4,
items: [ items: [
{label: '入队列消息速率', content: '${detail.state.messageRateIn}'}, {label: '入队列消息速率', content: '${state.messageRateIn}'},
{ {
label: '出队列消息速率', label: '出队列消息速率',
content: '${detail.state.messageRateOut}' content: '${state.messageRateOut}'
}, },
{ {
label: '入队列消息吞吐量', label: '入队列消息吞吐量',
content: '${detail.state.messageThroughputIn}' content: '${state.messageThroughputIn}'
}, },
{ {
label: '出队列消息吞吐量', label: '出队列消息吞吐量',
content: '${detail.state.messageThroughputOut}' content: '${state.messageThroughputOut}'
}, },
{ {
label: '入队列消息数量', label: '入队列消息数量',
content: '${detail.state.messageInCounter}' content: '${state.messageInCounter}'
}, },
{ {
label: '出队列消息数量', label: '出队列消息数量',
content: '${detail.state.messageOutCounter}' content: '${state.messageOutCounter}'
}, },
{ {
label: '入队列消息字节数', label: '入队列消息字节数',
content: '${detail.state.byteInCounter}' content: '${state.byteInCounter}'
}, },
{ {
label: '出队列消息字节数', label: '出队列消息字节数',
content: '${detail.state.byteOutCounter}' content: '${state.byteOutCounter}'
}, },
{label: '存储消息大小', content: '${detail.state. storageSize}'}, {label: '存储消息大小', content: '${state.storageSize}'},
{label: '积压消息大小', content: '${detail.state.backlogSize}'}, {label: '积压消息大小', content: '${state.backlogSize}'},
{ {
label: '平均消息大小', label: '平均消息大小',
content: '${detail.state.averageMessageSize}' content: '${state.averageMessageSize}'
}, },
], ],
}, },
@@ -1183,7 +1183,7 @@ function tableMetaDialog() {
{ {
type: 'table', type: 'table',
title: '消费者们', title: '消费者们',
source: '${detail.subscriptionStateVOS}', source: '${subscriptionStateVOS}',
itemAction: { itemAction: {
type: 'action', type: 'action',
actionType: 'dialog', actionType: 'dialog',
@@ -1315,7 +1315,7 @@ function tableMetaDialog() {
{ {
type: 'table', type: 'table',
title: '生产者们', title: '生产者们',
source: '${detail.state.publishers}', source: '${state.publishers}',
itemAction: { itemAction: {
type: 'action', type: 'action',
actionType: 'dialog', actionType: 'dialog',