Unverified Commit e32555e0 authored by gaoyan's avatar gaoyan Committed by GitHub

Optimized clusterinstance (#2578)

* Optimize the process * Optimized the logic of the cluster list * Optimized the logic of the cluster list
parent abbd3f80
......@@ -154,8 +154,10 @@ public class ClusterInstanceController {
paramType = "query",
required = true,
dataTypeClass = JsonNode.class)
public Result<List<ClusterInstance>> listClusterInstance(@RequestParam("keyword") String searchKeyWord) {
return Result.succeed(clusterInstanceService.selectListByKeyWord(searchKeyWord));
public Result<List<ClusterInstance>> listClusterInstance(
@RequestParam(defaultValue = "") String searchKeyWord,
@RequestParam(defaultValue = "false") boolean isAutoCreate) {
return Result.succeed(clusterInstanceService.selectListByKeyWord(searchKeyWord, isAutoCreate));
}
/**
......
......@@ -21,6 +21,7 @@ package org.dinky.job.handler;
import org.dinky.data.model.job.History;
import org.dinky.data.model.job.JobInstance;
import org.dinky.service.ClusterInstanceService;
import org.dinky.service.HistoryService;
import org.dinky.service.JobHistoryService;
import org.dinky.service.JobInstanceService;
......@@ -38,6 +39,7 @@ public class ClearJobHistoryHandler {
private JobInstanceService jobInstanceService;
private JobHistoryService jobHistoryService;
private HistoryService historyService;
private ClusterInstanceService clusterService;
/**
* Clears job history records based on the specified criteria.
......@@ -66,6 +68,9 @@ public class ClearJobHistoryHandler {
List<JobInstance> deleteList = jobInstanceService.list(deleteWrapper);
List<Integer> historyDeleteIds =
deleteList.stream().map(JobInstance::getHistoryId).collect(Collectors.toList());
List<Integer> clusterDeleteIds =
deleteList.stream().map(JobInstance::getClusterId).collect(Collectors.toList());
clusterService.removeBatchByIds(clusterDeleteIds);
jobHistoryService.removeBatchByIds(historyDeleteIds);
jobInstanceService.remove(deleteWrapper);
}
......
......@@ -145,5 +145,5 @@ public interface ClusterInstanceService extends ISuperService<ClusterInstance> {
*/
ClusterInstance deploySessionCluster(Integer id);
List<ClusterInstance> selectListByKeyWord(String searchKeyWord);
List<ClusterInstance> selectListByKeyWord(String searchKeyWord, boolean isAutoCreate);
}
......@@ -213,14 +213,15 @@ public class ClusterInstanceServiceImpl extends SuperServiceImpl<ClusterInstance
* @return
*/
@Override
public List<ClusterInstance> selectListByKeyWord(String searchKeyWord) {
public List<ClusterInstance> selectListByKeyWord(String searchKeyWord, boolean isAutoCreate) {
return getBaseMapper()
.selectList(new LambdaQueryWrapper<ClusterInstance>()
.like(ClusterInstance::getName, searchKeyWord)
.or()
.like(ClusterInstance::getAlias, searchKeyWord)
.or()
.like(ClusterInstance::getNote, searchKeyWord));
.and(true, i -> i.eq(ClusterInstance::getAutoRegisters, isAutoCreate))
.and(true, i -> i.like(ClusterInstance::getName, searchKeyWord)
.or()
.like(ClusterInstance::getAlias, searchKeyWord)
.or()
.like(ClusterInstance::getNote, searchKeyWord)));
}
private boolean checkHealth(ClusterInstance clusterInstance) {
......
......@@ -22,14 +22,15 @@ import { EditBtn } from '@/components/CallBackButton/EditBtn';
import { EnableSwitchBtn } from '@/components/CallBackButton/EnableSwitchBtn';
import { PopconfirmDeleteBtn } from '@/components/CallBackButton/PopconfirmDeleteBtn';
import { Authorized, HasAuthority } from '@/hooks/useAccess';
import useHookRequest from '@/hooks/useHookRequest';
import { CLUSTER_INSTANCE_TYPE } from '@/pages/RegCenter/Cluster/Instance/components/contants';
import { renderWebUiRedirect } from '@/pages/RegCenter/Cluster/Instance/components/function';
import InstanceModal from '@/pages/RegCenter/Cluster/Instance/components/InstanceModal';
import { getData } from '@/services/api';
import {
handleAddOrUpdate,
handleOption,
handleRemoveById,
queryDataByParams,
updateDataByParam
} from '@/services/BusinessCrud';
import { PROTABLE_OPTIONS_PUBLIC, PRO_LIST_CARD_OPTIONS } from '@/services/constants';
......@@ -38,12 +39,7 @@ import { Cluster } from '@/types/RegCenter/data.d';
import { InitClusterInstanceState } from '@/types/RegCenter/init.d';
import { ClusterInstanceState } from '@/types/RegCenter/state.d';
import { l } from '@/utils/intl';
import {
CheckCircleOutlined,
ClearOutlined,
ExclamationCircleOutlined,
HeartTwoTone
} from '@ant-design/icons';
import { CheckCircleOutlined, ExclamationCircleOutlined, HeartTwoTone } from '@ant-design/icons';
import { ActionType, ProList } from '@ant-design/pro-components';
import {
Badge,
......@@ -54,14 +50,15 @@ import {
Divider,
Input,
List,
Popconfirm,
Row,
Space,
Switch,
Tag,
Tooltip,
Typography
} from 'antd';
import { useEffect, useRef, useState } from 'react';
import { useRef, useState } from 'react';
const { Text, Paragraph, Link } = Typography;
export default () => {
......@@ -70,16 +67,18 @@ export default () => {
*/
const [clusterInstanceStatus, setClusterInstanceStatus] =
useState<ClusterInstanceState>(InitClusterInstanceState);
const [isAutoCreate, setIsAutoCreate] = useState<boolean>(false);
const [searchKeyWord, setSearchKeyword] = useState<string>('');
const actionRef = useRef<ActionType>();
const queryClusterInstanceList = async (keyword = '') => {
queryDataByParams(API_CONSTANTS.CLUSTER_INSTANCE_LIST, { keyword }).then((res) => {
setClusterInstanceStatus((prevState) => ({
...prevState,
instanceList: res as Cluster.Instance[]
}));
});
};
const { data, loading } = useHookRequest(getData, {
refreshDeps: [searchKeyWord, isAutoCreate],
defaultParams: [
API_CONSTANTS.CLUSTER_INSTANCE_LIST,
{ searchKeyWord: searchKeyWord, isAutoCreate: isAutoCreate }
]
});
/**
* execute and callback function
* @param {() => void} callback
......@@ -88,15 +87,10 @@ export default () => {
const executeAndCallback = async (callback: () => void) => {
setClusterInstanceStatus((prevState) => ({ ...prevState, loading: true }));
await callback();
queryClusterInstanceList();
setClusterInstanceStatus((prevState) => ({ ...prevState, loading: false }));
actionRef.current?.reload?.();
};
useEffect(() => {
queryClusterInstanceList();
}, []);
/**
* cancel
*/
......@@ -161,15 +155,6 @@ export default () => {
);
};
/**
* recycle instance
*/
const handleRecycle = async () => {
await executeAndCallback(async () =>
handleRemoveById(API_CONSTANTS.CLUSTER_INSTANCE_RECYCLE, 0)
);
};
/**
* tool bar render
*/
......@@ -262,12 +247,10 @@ export default () => {
* tool bar render
*/
const toolBarRender = () => [
<Input.Search
loading={clusterInstanceStatus.loading}
key={`_search`}
allowClear
placeholder={l('rc.ci.search')}
onSearch={(value) => queryClusterInstanceList(value)}
<Switch
checkedChildren={l('rc.ci.ar')}
unCheckedChildren={l('rc.ci.mr')}
onChange={(v) => setIsAutoCreate(v)}
/>,
<Authorized key={`_add_auth`} path='/registration/cluster/instance/add'>
<CreateBtn
......@@ -285,18 +268,6 @@ export default () => {
{l('button.heartbeat')}
</Button>
</Authorized>,
<Authorized key={`_add_recycle`} path='/registration/cluster/instance/recovery'>
<Popconfirm
key={`_add_recycle_pop`}
title={l('rc.ci.recycle')}
description={l('rc.ci.recycleConfirm')}
onConfirm={handleRecycle}
>
<Button key={'recycle_btn'} type={'primary'} icon={<ClearOutlined />}>
{l('button.recycle')}
</Button>
</Popconfirm>
</Authorized>
];
const renderListItem = (item: Cluster.Instance) => {
......@@ -304,12 +275,12 @@ export default () => {
<List.Item className={'card-list-item-wrapper'} key={item.id}>
<Badge.Ribbon
className={'card-list-item-wrapper'}
color={item.autoRegisters ? 'green' : 'yellow'}
color={item.autoRegisters ? '#95de64' : '#ffec3d'}
text={
item.autoRegisters ? (
l('rc.ci.ar')
) : (
<span style={{ color: 'crimson' }}>{l('rc.ci.mr')}</span>
<span style={{ color: '#69b1ff' }}>{l('rc.ci.mr')}</span>
)
}
>
......@@ -334,15 +305,23 @@ export default () => {
return (
<>
<ProList<Cluster.Instance>
headerTitle={l('rc.ci.management')}
headerTitle={
<Input.Search
loading={clusterInstanceStatus.loading}
key={`_search`}
allowClear
placeholder={l('rc.ci.search')}
onSearch={(v) => setSearchKeyword(v)}
/>
}
toolBarRender={toolBarRender}
{...PROTABLE_OPTIONS_PUBLIC}
{...(PRO_LIST_CARD_OPTIONS as any)}
grid={{ gutter: 24, column: 4 }}
pagination={{ size: 'small', defaultPageSize: 12, hideOnSinglePage: true }}
actionRef={actionRef}
dataSource={clusterInstanceStatus.instanceList}
loading={clusterInstanceStatus.loading}
dataSource={data}
loading={loading}
itemLayout={'vertical'}
renderItem={renderListItem}
/>
......
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