Unverified Commit 106d1b53 authored by gaoyan's avatar gaoyan Committed by GitHub

footer use sse get jvm (#2661)

* footer use sse get jvm * footer use sse get jvm
parent f3f4d225
......@@ -24,7 +24,6 @@ import org.dinky.data.annotations.Log;
import org.dinky.data.dto.MetricsLayoutDTO;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.MetricsType;
import org.dinky.data.metrics.Jvm;
import org.dinky.data.model.Metrics;
import org.dinky.data.result.Result;
import org.dinky.data.vo.MetricsVO;
......@@ -41,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
......@@ -124,7 +124,7 @@ public class MonitorController {
@GetMapping("/getJvmInfo")
@ApiOperation("Get Jvm Data Display")
public Result<Jvm> getJvmInfo() {
return Result.succeed(Jvm.of());
public SseEmitter getJvmInfo() {
return monitorService.sendJvmInfo();
}
}
......@@ -56,7 +56,7 @@ public class SseController {
@GetMapping(value = "/connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ApiOperation("Connect Sse")
@ApiImplicitParam(name = "sessionKey", value = "Session unique key", required = true, dataType = "String")
public SseEmitter getJvmInfo(String sessionKey) {
public SseEmitter connect(String sessionKey) {
return SseSessionContextHolder.connectSession(sessionKey);
}
}
......@@ -46,10 +46,9 @@ public interface MonitorService extends IService<Metrics> {
/**
* Send the JVM information to the specified SSE emitter.
*
* @param sseEmitter The SSE emitter to send the JVM information to.
* @return {@link SseEmitter}
*/
SseEmitter sendJvmInfo(SseEmitter sseEmitter);
SseEmitter sendJvmInfo();
/**
* Save the Flink metric layout.
......
......@@ -19,6 +19,7 @@
package org.dinky.service.impl;
import org.dinky.context.SseSessionContextHolder;
import org.dinky.data.MetricsLayoutVo;
import org.dinky.data.constant.PaimonTableConstant;
import org.dinky.data.dto.MetricsLayoutDTO;
......@@ -42,6 +43,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -58,7 +60,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
@Service
......@@ -98,16 +99,18 @@ public class MonitorServiceImpl extends ServiceImpl<MetricsMapper, Metrics> impl
}
@Override
public SseEmitter sendJvmInfo(SseEmitter sseEmitter) {
public SseEmitter sendJvmInfo() {
String sessionKey = UUID.randomUUID().toString();
SseEmitter sseEmitter = SseSessionContextHolder.connectSession(sessionKey);
SseSessionContextHolder.subscribeTopic(sessionKey, CollUtil.newArrayList(sessionKey));
scheduleRefreshMonitorDataExecutor.execute(() -> {
try {
while (true) {
sseEmitter.send(JSONUtil.toJsonStr(Jvm.of()));
SseSessionContextHolder.sendTopic(sessionKey, Jvm.of());
ThreadUtil.sleep(10000);
}
} catch (Exception e) {
e.printStackTrace();
sseEmitter.complete();
log.error("send jvm info failed, complete sse emiter :" + e.getMessage());
}
});
return sseEmitter;
......
......@@ -65,6 +65,9 @@ public class FlinkConfigOptionsUtils {
FlinkConfigOption config = new FlinkConfigOption();
Object fieldValue = ReflectUtil.getStaticFieldValue(field);
String key = ReflectUtil.invoke(fieldValue, "key");
if (!key.contains(".")) {
continue;
}
Object defaultValue = ReflectUtil.invoke(fieldValue, "defaultValue");
config.setKey(key);
if (ObjectUtil.isBasicType(defaultValue)) {
......
......@@ -26,6 +26,7 @@ import {
import { isSql } from '@/pages/DataStudio/HeaderContainer/service';
import { StateType } from '@/pages/DataStudio/model';
import { handleGetOption, handleGetOptionWithoutMsg } from '@/services/BusinessCrud';
import { DIALECT } from '@/services/constants';
import { API_CONSTANTS } from '@/services/endpoints';
import { transformTableDataToCsv } from '@/utils/function';
import { l } from '@/utils/intl';
......@@ -37,7 +38,6 @@ import { FilterConfirmProps } from 'antd/es/table/interface';
import { DataIndex } from 'rc-table/es/interface';
import { useEffect, useRef, useState } from 'react';
import { connect } from 'umi';
import {DIALECT} from "@/services/constants";
type Data = {
[c: string]: any;
......
......@@ -21,8 +21,7 @@ import useThemeValue from '@/hooks/useThemeValue';
import JobRunningModal from '@/pages/DataStudio/FooterContainer/JobRunningModal';
import { getCurrentTab } from '@/pages/DataStudio/function';
import { StateType, TabsPageType, VIEW } from '@/pages/DataStudio/model';
import { getData } from '@/services/api';
import { API_CONSTANTS } from '@/services/endpoints';
import { getSseData } from '@/services/api';
import { l } from '@/utils/intl';
import { connect } from '@@/exports';
import { Button, GlobalToken, Space } from 'antd';
......@@ -60,20 +59,18 @@ const FooterContainer: React.FC<FooterContainerProps & StateType> = (props) => {
const currentTab = getCurrentTab(tabs.panes ?? [], tabs.activeKey);
useEffect(() => {
const t = setInterval(() => {
getData(API_CONSTANTS.MONITOR_GET_JVM_INFO)
.then((res) => {
setMemDetailInfo(
Number(res.data['heapUsed'] / 1024 / 1024).toFixed(0) +
'/' +
Number(res.data['max'] / 1024 / 1024).toFixed(0) +
'M'
);
})
.catch((e) => {});
}, 3000);
const eventSource = getSseData('/api/monitor/getJvmInfo');
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data).data;
setMemDetailInfo(
Number(data['heapUsed'] / 1024 / 1024).toFixed(0) +
'/' +
Number(data['max'] / 1024 / 1024).toFixed(0) +
'M'
);
};
return () => {
clearTimeout(t);
eventSource.close();
};
}, []);
......
......@@ -33,7 +33,8 @@ import {
changeTaskLife,
debugTask,
executeSql,
getJobPlan, isSql
getJobPlan,
isSql
} from '@/pages/DataStudio/HeaderContainer/service';
import { DataStudioTabsItemType, StateType, TabsPageType, VIEW } from '@/pages/DataStudio/model';
import { JOB_LIFE_CYCLE, JOB_STATUS } from '@/pages/DevOps/constants';
......@@ -178,7 +179,7 @@ const HeaderContainer = (props: any) => {
await SuccessMessageAsync(l('pages.datastudio.editor.exec.success'));
currentData.status = JOB_STATUS.RUNNING;
// Common sql task is synchronized, so it needs to automatically update the status to finished.
if(isSql(currentData.dialect)){
if (isSql(currentData.dialect)) {
currentData.status = JOB_STATUS.FINISHED;
}
if (currentTab) currentTab.console.result = res.data.result;
......
......@@ -156,7 +156,7 @@ const Project: React.FC = (props: connect) => {
icon: type,
id: parentId + name,
treeKey: key,
breadcrumbLabel: path.slice(0,path.length-1).join('/'),
breadcrumbLabel: path.slice(0, path.length - 1).join('/'),
label: name,
params: {
taskId: taskId
......
......@@ -724,7 +724,7 @@ const Model: ModelType = {
tabs: {
...state.tabs,
activeKey: item.key,
activeBreadcrumbTitle: [item.type, item.breadcrumbLabel, item.label].join('/'),
activeBreadcrumbTitle: [item.type, item.breadcrumbLabel, item.label].join('/')
},
footContainer: {
...state.footContainer,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment