Unverified Commit 80c75834 authored by gaoyan's avatar gaoyan Committed by GitHub

Refactor the cluster form (#2122)

* Refactor the cluster form * Refactor the cluster form
parent 865339f6
...@@ -29,7 +29,7 @@ type CodeEditFormProps = { ...@@ -29,7 +29,7 @@ type CodeEditFormProps = {
width?: string; width?: string;
language?: string; language?: string;
options?: any; options?: any;
onChange: (val: string) => void; onChange?: (val: string) => void;
code: string; code: string;
readOnly?: boolean; readOnly?: boolean;
lineNumbers?: string; lineNumbers?: string;
......
...@@ -43,6 +43,7 @@ import {ClusterConfigIcon} from "@/components/Icons/HomeIcon"; ...@@ -43,6 +43,7 @@ import {ClusterConfigIcon} from "@/components/Icons/HomeIcon";
import {imgStyle} from "@/pages/Home/constants"; import {imgStyle} from "@/pages/Home/constants";
import {RunningBtn} from "@/components/CallBackButton/RunningBtn"; import {RunningBtn} from "@/components/CallBackButton/RunningBtn";
import {CLUSTER_CONFIG_TYPE} from "@/pages/RegCenter/Cluster/Configuration/components/contants"; import {CLUSTER_CONFIG_TYPE} from "@/pages/RegCenter/Cluster/Configuration/components/contants";
import {useRequest} from "@umijs/max";
export default () => { export default () => {
...@@ -55,25 +56,8 @@ export default () => { ...@@ -55,25 +56,8 @@ export default () => {
const [createOpen, setCreateOpen] = useState<boolean>(false); const [createOpen, setCreateOpen] = useState<boolean>(false);
const [modifyOpen, setModifyOpen] = useState<boolean>(false); const [modifyOpen, setModifyOpen] = useState<boolean>(false);
const [formValue, setFormValue] = useState<Partial<Cluster.Config>>({}); const [formValue, setFormValue] = useState<Partial<Cluster.Config>>({});
const [data, setData] = useState<Cluster.Config[]>([]);
/**
* execute query list
* set list
*/
const queryDataList = async () => {
await queryList(API_CONSTANTS.CLUSTER_CONFIGURATION).then(res => setData(res.data));
};
/**
* query list
*/
useEffect(() => {
queryDataList();
}, []);
const {data, run} = useRequest({url: API_CONSTANTS.CLUSTER_CONFIGURATION, method: 'POST', data: {}})
/** /**
* execute and callback function * execute and callback function
...@@ -83,7 +67,7 @@ export default () => { ...@@ -83,7 +67,7 @@ export default () => {
const executeAndCallbackRefresh = async (callback: () => void) => { const executeAndCallbackRefresh = async (callback: () => void) => {
setLoading(true); setLoading(true);
await callback(); await callback();
await queryDataList(); await run();
setLoading(false); setLoading(false);
actionRef.current?.reload?.(); actionRef.current?.reload?.();
}; };
...@@ -143,7 +127,7 @@ export default () => { ...@@ -143,7 +127,7 @@ export default () => {
*/ */
const handleSubmit = async (value: Partial<Cluster.Config>) => { const handleSubmit = async (value: Partial<Cluster.Config>) => {
await executeAndCallbackRefresh(async () => { await executeAndCallbackRefresh(async () => {
console.log(value, 'value'); value.configJson = JSON.stringify(value.configJson)
await handleAddOrUpdate(API_CONSTANTS.CLUSTER_CONFIGURATION, value); await handleAddOrUpdate(API_CONSTANTS.CLUSTER_CONFIGURATION, value);
await handleCancel(); await handleCancel();
}); });
...@@ -171,6 +155,7 @@ export default () => { ...@@ -171,6 +155,7 @@ export default () => {
* @param item * @param item
*/ */
const editClick = (item: Cluster.Config) => { const editClick = (item: Cluster.Config) => {
item.configJson = JSON.parse(item.configJson)
setFormValue(item); setFormValue(item);
setModifyOpen(!modifyOpen); setModifyOpen(!modifyOpen);
}; };
...@@ -226,7 +211,7 @@ export default () => { ...@@ -226,7 +211,7 @@ export default () => {
/** /**
* render data list * render data list
*/ */
const renderData = data.map((item) => ({ const renderData = data?.map((item: Cluster.Config) => ({
subTitle: renderDataSubTitle(item), subTitle: renderDataSubTitle(item),
actions: <DataAction>{renderDataActionButton(item)}</DataAction>, actions: <DataAction>{renderDataActionButton(item)}</DataAction>,
avatar: <ClusterConfigIcon style={imgStyle}/>, avatar: <ClusterConfigIcon style={imgStyle}/>,
...@@ -244,7 +229,6 @@ export default () => { ...@@ -244,7 +229,6 @@ export default () => {
* render * render
*/ */
return <> return <>
<ProList<Cluster.Config> <ProList<Cluster.Config>
{...PROTABLE_OPTIONS_PUBLIC} {...PROTABLE_OPTIONS_PUBLIC}
{...PRO_LIST_CARD_OPTIONS as any} {...PRO_LIST_CARD_OPTIONS as any}
......
...@@ -28,7 +28,7 @@ const ApplicationConfig = () => { ...@@ -28,7 +28,7 @@ const ApplicationConfig = () => {
<ProFormGroup labelLayout={'inline'}> <ProFormGroup labelLayout={'inline'}>
<ProFormText <ProFormText
width={'xl'} width={'xl'}
name="userJarPath" name={["configJson","userJarPath"]}
placeholder={l('rc.cc.sqlSubmitJarPathHelp')} placeholder={l('rc.cc.sqlSubmitJarPathHelp')}
label={l('rc.cc.sqlSubmitJarPath')} label={l('rc.cc.sqlSubmitJarPath')}
tooltip={l('rc.cc.sqlSubmitJarPathHelp')} tooltip={l('rc.cc.sqlSubmitJarPathHelp')}
...@@ -37,4 +37,4 @@ const ApplicationConfig = () => { ...@@ -37,4 +37,4 @@ const ApplicationConfig = () => {
</> </>
} }
export default ApplicationConfig export default ApplicationConfig
\ No newline at end of file
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
import React from "react"; import React from "react";
import {Divider} from "antd"; import {Divider} from "antd";
import {l} from "@/utils/intl"; import {l} from "@/utils/intl";
import {ProFormGroup, ProFormSelect, ProFormSwitch, ProFormText} from "@ant-design/pro-components"; import {ProFormDigit, ProFormGroup, ProFormSelect, ProFormSwitch, ProFormText} from "@ant-design/pro-components";
import {CLUSTER_CONFIG_TYPE} from "@/pages/RegCenter/Cluster/Configuration/components/contants"; import {CLUSTER_CONFIG_TYPE} from "@/pages/RegCenter/Cluster/Configuration/components/contants";
const BaseConfig: React.FC = () => { const BaseConfig: React.FC = () => {
...@@ -28,6 +28,10 @@ const BaseConfig: React.FC = () => { ...@@ -28,6 +28,10 @@ const BaseConfig: React.FC = () => {
return <> return <>
<Divider>{l('rc.cc.baseConfig')}</Divider> <Divider>{l('rc.cc.baseConfig')}</Divider>
<ProFormGroup> <ProFormGroup>
<ProFormDigit
name="id"
hidden={true}
/>
<ProFormSelect <ProFormSelect
name="type" name="type"
label={l('rc.cc.type')} label={l('rc.cc.type')}
...@@ -60,4 +64,4 @@ const BaseConfig: React.FC = () => { ...@@ -60,4 +64,4 @@ const BaseConfig: React.FC = () => {
</>; </>;
} }
export default BaseConfig; export default BaseConfig;
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const ExposedTypeOptions = [
{label: 'NodePort', value: 'NodePort'},
{label: 'ClusterIP', value: 'ClusterIP'},
];
export const versionOptions = [
{label: '1.13', value: 'v1_13'},
{label: '1.14', value: 'v1_14'},
{label: '1.15', value: 'v1_15'},
{label: '1.16', value: 'v1_16'},
{label: '1.17', value: 'v1_17'},
{label: '1.18', value: 'v1_18', disabled: true},
];
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {Col, Divider, Row} from "antd";
import {ProCard, ProFormGroup, ProFormItem, ProFormList, ProFormSelect, ProFormText} from "@ant-design/pro-components";
import {l} from "@/utils/intl";
import React from "react";
import CodeEdit from "@/components/CustomEditor/CodeEdit";
import {ClusterType} from "@/pages/RegCenter/Cluster/constants";
import {TagAlignCenter} from "@/components/StyledComponents";
import {
ExposedTypeOptions, versionOptions
} from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/FlinkK8s/contants";
import {KUBERNETES_CONFIG_LIST} from "@/pages/RegCenter/Cluster/Configuration/components/contants";
const CodeEditProps = {
height: '40vh',
width: '90vh',
lineNumbers: 'on',
language: 'yaml',
};
const FlinkK8s = (props: { type: string, value: any }) => {
const {type, value} = props;
const renderK8sConfig = () => {
return <>
{KUBERNETES_CONFIG_LIST
.map(item =>
<ProFormText
tooltip={item.tooltip}
key={item.name}
name={['configJson', 'kubernetesConfig', item.name]}
label={item.label}
width={250}
placeholder={item.placeholder}/>
)}
<ProFormList
name={['configJson', 'flinkConfigList']}
copyIconProps={false}
deleteIconProps={{tooltipText: l('rc.cc.deleteConfig'),}}
creatorButtonProps={{style: {width: '32vw'}, creatorButtonText: l('rc.cc.addConfig'),}}
>
<ProFormGroup key="flinkGroup">
<ProFormText width={'md'} name="name" label={l('rc.cc.key')}/>
<ProFormText width={'sm'} name="value" label={l('rc.cc.value')}/>
</ProFormGroup>
</ProFormList>
</>
};
const configTags = [
{
key: "defaultPodTemplate",
label: <TagAlignCenter>Default Pod Template</TagAlignCenter>,
children:
<ProFormItem key="dpe" name={['configJson', 'podTemplate']}>
<CodeEdit {...CodeEditProps} code={value.configJson.podTemplate}/>
</ProFormItem>
},
{
key: "JMPodTemplate",
label: <TagAlignCenter>JM Pod Template</TagAlignCenter>,
children:
<ProFormItem key="jmdpe" name={['configJson', 'JMpodTemplate']}>
<CodeEdit {...CodeEditProps} code={value.configJson.JMpodTemplate}/>
</ProFormItem>
},
{
key: "TMPodTemplate",
label: <TagAlignCenter>TM Pod Template</TagAlignCenter>,
children:
<ProFormItem key="tmdpe" name={['configJson', 'TMpodTemplate']}>
<CodeEdit {...CodeEditProps} code={value.configJson.TMpodTemplate}/>
</ProFormItem>
},
];
return <>
<Divider>{l('rc.cc.k8sConfig')}</Divider>
<Row gutter={[16, 16]}>
<Col span={10}>
<ProFormGroup>
{(type && type === ClusterType.KUBERNETES_NATIVE) &&
<ProFormSelect
name={['configJson', 'kubernetesConfig', 'kubernetes.rest-service.exposed.type']}
label={l('rc.cc.k8s.exposed')}
tooltip={l('rc.cc.k8s.exposedHelp')}
placeholder={l('rc.cc.k8s.exposedHelp')}
options={ExposedTypeOptions}
width={250}
/>}
{(type && type === ClusterType.KUBERNETES_OPERATOR) &&
<ProFormSelect
name={['configJson', 'flinkVersion']}
label={l('rc.cc.k8sOp.version')}
width={250}
placeholder={l('rc.cc.k8sOp.versionHelp')}
options={versionOptions}
/>}
{renderK8sConfig()}
</ProFormGroup>
</Col>
<ProCard.Divider type={'vertical'}/>
<Col span={12}>
<ProCard size="small" tabs={{type: 'card', items: configTags}}/>
</Col>
</Row>
</>
}
export default FlinkK8s;
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {DOCKER_CONFIG_LIST} from "@/pages/RegCenter/Cluster/Configuration/components/contants";
import {ProFormGroup, ProFormText} from "@ant-design/pro-components";
import {Divider} from "antd";
import {l} from "@/utils/intl";
import React from "react";
const DockerConfig = () => {
const renderDockerConfigForm = () => {
return DOCKER_CONFIG_LIST.map(item => <>
<ProFormText
width={300}
key={item.name}
name={item.name}
label={item.label}
tooltip={item.tooltip}
placeholder={item.placeholder}
initialValue={item.defaultValue}
/>
</>
);
}
return <>
<Divider>{l('rc.cc.dockerConfig')}</Divider>
<ProFormGroup>
{renderDockerConfigForm()}
</ProFormGroup>
</>
};
export default DockerConfig
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {Col, Divider, Row} from "antd";
import {l} from "@/utils/intl";
import React from "react";
import {KUBERNETES_CONFIG_LIST} from "@/pages/RegCenter/Cluster/Configuration/components/contants";
import {ProCard, ProFormGroup, ProFormList, ProFormText} from "@ant-design/pro-components";
import {ClusterType} from "@/pages/RegCenter/Cluster/constants";
const K8sConfig = () => {
const renderK8sConfig = () => {
return KUBERNETES_CONFIG_LIST
.filter(item => item.showOnSubmitType !== ClusterType.KUBERNETES_OPERATOR)
.map(item => <>
<ProFormText
width={250}
key={item.name}
name={item.name}
label={item.label}
tooltip={item.tooltip}
placeholder={item.placeholder}
/>
</>
);
}
return <>
<Divider>{l('rc.cc.k8sConfig')}</Divider>
<Row gutter={[16, 16]}>
<Col span={10}>
<Divider>{l('rc.cc.k8s.preConfig')}</Divider>
<ProFormGroup>
{renderK8sConfig()}
</ProFormGroup>
</Col>
<ProCard.Divider type={'vertical'}/>
<Col span={12}>
<Divider>{l('rc.cc.k8s.defineConfig')}</Divider>
<ProFormList
name="kubernetesConfigList"
copyIconProps={false}
deleteIconProps={{
tooltipText: l('rc.cc.deleteConfig'),
}}
creatorButtonProps={{
style: {width: '32vw'},
creatorButtonText: l('rc.cc.addConfig'),
}}
>
<ProFormGroup key="flinkK8sNativeGroup">
<ProFormText width={'md'} name="name" label={l('rc.cc.key')}/>
<ProFormText width={'sm'} name="value" label={l('rc.cc.value')}/>
</ProFormGroup>
</ProFormList>
</Col>
</Row>
</>;
}
export default K8sConfig;
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import React from "react";
import DockerConfig
from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/FlinkK8sNative/DockerConfig";
import K8sConfig
from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/FlinkK8sNative/K8sConfig";
const FlinkK8sNative = () => {
return <>
<DockerConfig/>
<K8sConfig/>
</>;
}
export default FlinkK8sNative;
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {Col, Divider, Row} from "antd";
import {ProCard, ProFormGroup, ProFormItem, ProFormSelect, ProFormText} from "@ant-design/pro-components";
import {l} from "@/utils/intl";
import React from "react";
import {KUBERNETES_CONFIG_LIST} from "@/pages/RegCenter/Cluster/Configuration/components/contants";
import CodeEdit from "@/components/CustomEditor/CodeEdit";
import {ClusterType} from "@/pages/RegCenter/Cluster/constants";
const CodeEditProps = {
height: '30vh',
width: '60vw',
lineNumbers: 'on',
language: 'yaml',
};
const FlinkK8sOperator = (props: any) => {
const renderFlinkK8sOperatorConfig = () => {
return KUBERNETES_CONFIG_LIST
.filter(item => item.showOnSubmitType !== ClusterType.KUBERNETES_NATIVE && item.showType !== 'code')
.map(item => <>
<ProFormText
width={250}
key={item.name}
name={item.name}
label={item.label}
tooltip={item.tooltip}
placeholder={item.placeholder}
/>
</>
);
};
const renderFlinkK8sOperatorConfigCode = () => {
return KUBERNETES_CONFIG_LIST
.filter(item => item.showType === 'code')
.map(item => <>
<ProFormItem
key={item.name}
name={item.name}
label={item.label}
tooltip={item.tooltip}
>
<CodeEdit {...CodeEditProps} onChange={() => {
}} code={props.code}/>
</ProFormItem>
</>
);
}
return <>
<Divider>{l('rc.cc.k8sConfig')}</Divider>
<Row gutter={[16, 16]}>
<Col span={10}>
<ProFormGroup>
<ProFormSelect
name={'flinkVersion'}
label={l('rc.cc.k8sOp.version')}
width={250}
placeholder={l('rc.cc.k8sOp.versionHelp')}
options={[
{label: '1.13' + l('rc.cc.k8sOp.unSupportBatch'), value: 'v1_13'},
{label: '1.14' + l('rc.cc.k8sOp.unSupportBatch'), value: 'v1_14'},
{label: '1.15', value: 'v1_15'},
{label: '1.16', value: 'v1_16'},
{label: '1.17', value: 'v1_17'},
{label: '1.18', value: 'v1_18', disabled: true},
]}
/>
{renderFlinkK8sOperatorConfig()}
</ProFormGroup>
</Col>
<ProCard.Divider type={'vertical'}/>
<Col span={12}>
{renderFlinkK8sOperatorConfigCode()}
</Col>
</Row>
</>
}
export default FlinkK8sOperator;
\ No newline at end of file
...@@ -28,7 +28,7 @@ const HighPriorityConfig = () => { ...@@ -28,7 +28,7 @@ const HighPriorityConfig = () => {
const renderHighPriorityConfig = () => { const renderHighPriorityConfig = () => {
return FLINK_CONFIG_LIST.map(item => <> return FLINK_CONFIG_LIST.map(item => <>
<ProFormText <ProFormText
name={item.name} name={['configJson', 'flinkConfig', item.name]}
label={item.label} label={item.label}
width={400} width={400}
placeholder={item.placeholder} placeholder={item.placeholder}
...@@ -45,4 +45,4 @@ const HighPriorityConfig = () => { ...@@ -45,4 +45,4 @@ const HighPriorityConfig = () => {
</> </>
} }
export default HighPriorityConfig export default HighPriorityConfig
\ No newline at end of file
...@@ -30,7 +30,7 @@ const YarnConfig = () => { ...@@ -30,7 +30,7 @@ const YarnConfig = () => {
<Divider>{l('rc.cc.hadoopConfig')}</Divider> <Divider>{l('rc.cc.hadoopConfig')}</Divider>
<ProFormGroup> <ProFormGroup>
<ProFormText <ProFormText
name="hadoopConfigPath" name={['configJson', 'hadoopConfigPath']}
label={l('rc.cc.hadoopConfigPath')} label={l('rc.cc.hadoopConfigPath')}
width="md" width="md"
rules={[{required: true, message: l('rc.cc.hadoopConfigPathPlaceholder')}]} rules={[{required: true, message: l('rc.cc.hadoopConfigPathPlaceholder')}]}
...@@ -40,8 +40,8 @@ const YarnConfig = () => { ...@@ -40,8 +40,8 @@ const YarnConfig = () => {
</ProFormGroup> </ProFormGroup>
<Divider>{l('rc.cc.hadoop.defineConfig')}</Divider> <Divider>{l('rc.cc.hadoop.defineConfig')}</Divider>
<ProFormList <ProFormList
name="hadoopConfigList" name={['configJson', 'hadoopConfigList']}
copyIconProps={false} copyIconProps={false}
deleteIconProps={{ deleteIconProps={{
tooltipText: l('rc.cc.deleteConfig'), tooltipText: l('rc.cc.deleteConfig'),
}} }}
...@@ -63,7 +63,7 @@ const YarnConfig = () => { ...@@ -63,7 +63,7 @@ const YarnConfig = () => {
<Divider>{l('rc.cc.flinkConfig')}</Divider> <Divider>{l('rc.cc.flinkConfig')}</Divider>
<ProFormGroup> <ProFormGroup>
<ProFormText <ProFormText
name="flinkLibPath" name={['configJson', 'flinkLibPath']}
label={l('rc.cc.libPath')} label={l('rc.cc.libPath')}
width="md" width="md"
rules={[{required: true, message: l('rc.cc.libPathPlaceholder')}]} rules={[{required: true, message: l('rc.cc.libPathPlaceholder')}]}
...@@ -72,7 +72,7 @@ const YarnConfig = () => { ...@@ -72,7 +72,7 @@ const YarnConfig = () => {
/> />
<ProFormText <ProFormText
name="flinkConfigPath" name={['configJson', 'flinkConfigPath']}
label={l('rc.cc.flinkConfigPath')} label={l('rc.cc.flinkConfigPath')}
width="md" width="md"
rules={[{required: true, message: l('rc.cc.flinkConfigPathPlaceholder')}]} rules={[{required: true, message: l('rc.cc.flinkConfigPathPlaceholder')}]}
...@@ -83,7 +83,7 @@ const YarnConfig = () => { ...@@ -83,7 +83,7 @@ const YarnConfig = () => {
<Divider>{l('rc.cc.flink.defineConfig')}</Divider> <Divider>{l('rc.cc.flink.defineConfig')}</Divider>
<ProFormList <ProFormList
name="flinkConfigList" name={['configJson', 'flinkConfigList']}
copyIconProps={false} copyIconProps={false}
deleteIconProps={{ deleteIconProps={{
tooltipText: l('rc.cc.deleteConfig'), tooltipText: l('rc.cc.deleteConfig'),
...@@ -103,4 +103,4 @@ const YarnConfig = () => { ...@@ -103,4 +103,4 @@ const YarnConfig = () => {
</> </>
} }
export default YarnConfig; export default YarnConfig;
\ No newline at end of file
...@@ -29,11 +29,8 @@ import HighPriorityConfig ...@@ -29,11 +29,8 @@ import HighPriorityConfig
from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/HighPriorityConfig"; from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/HighPriorityConfig";
import YarnConfig import YarnConfig
from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/YarnConfig"; from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/YarnConfig";
import FlinkK8sNative
from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/FlinkK8sNative";
import FlinkK8sOperator
from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/FlinkK8sOperator";
import {ClusterType} from "@/pages/RegCenter/Cluster/constants"; import {ClusterType} from "@/pages/RegCenter/Cluster/constants";
import FlinkK8s from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/FlinkK8s";
type ConfigurationFormProps = { type ConfigurationFormProps = {
...@@ -48,10 +45,7 @@ const ConfigurationForm: React.FC<ConfigurationFormProps> = (props) => { ...@@ -48,10 +45,7 @@ const ConfigurationForm: React.FC<ConfigurationFormProps> = (props) => {
const renderAllForm = () => { const renderAllForm = () => {
return <> return <>
<BaseConfig/> <BaseConfig/>
{(type && type === ClusterType.YARN) && <YarnConfig/>} {(type && type === ClusterType.YARN) ? <YarnConfig/>:<FlinkK8s type={type} value={value}/>}
{(type && type === ClusterType.KUBERNETES_NATIVE) && <FlinkK8sNative/>}
{(type && type === ClusterType.KUBERNETES_OPERATOR) &&
<FlinkK8sOperator code={value['kubernetes.pod-template'] || ''}/>}
<HighPriorityConfig/> <HighPriorityConfig/>
<ApplicationConfig/> <ApplicationConfig/>
</>; </>;
......
...@@ -24,8 +24,6 @@ import {ModalForm} from '@ant-design/pro-components'; ...@@ -24,8 +24,6 @@ import {ModalForm} from '@ant-design/pro-components';
import {l} from '@/utils/intl'; import {l} from '@/utils/intl';
import {FormContextValue} from '@/components/Context/FormContext'; import {FormContextValue} from '@/components/Context/FormContext';
import ConfigurationForm from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm"; import ConfigurationForm from "@/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm";
import {buildClusterConfig, parseConfigJsonToValues} from "@/pages/RegCenter/Cluster/Configuration/components/function";
import {ClusterType} from "@/pages/RegCenter/Cluster/constants";
type ConfigurationModalProps = { type ConfigurationModalProps = {
visible: boolean; visible: boolean;
...@@ -37,9 +35,6 @@ const InstanceModal: React.FC<ConfigurationModalProps> = (props) => { ...@@ -37,9 +35,6 @@ const InstanceModal: React.FC<ConfigurationModalProps> = (props) => {
const {visible, onClose, onSubmit, value} = props; const {visible, onClose, onSubmit, value} = props;
/** /**
* init form * init form
*/ */
...@@ -58,7 +53,7 @@ const InstanceModal: React.FC<ConfigurationModalProps> = (props) => { ...@@ -58,7 +53,7 @@ const InstanceModal: React.FC<ConfigurationModalProps> = (props) => {
* when modalVisible or values changed, set form values * when modalVisible or values changed, set form values
*/ */
useEffect(() => { useEffect(() => {
form.setFieldsValue(parseConfigJsonToValues(value as Cluster.Config)); form.setFieldsValue(value);
}, [visible, value, form]); }, [visible, value, form]);
/** /**
...@@ -75,7 +70,7 @@ const InstanceModal: React.FC<ConfigurationModalProps> = (props) => { ...@@ -75,7 +70,7 @@ const InstanceModal: React.FC<ConfigurationModalProps> = (props) => {
const submitForm = async () => { const submitForm = async () => {
const fieldsValue = await form.validateFields(); const fieldsValue = await form.validateFields();
setSubmitting(true); setSubmitting(true);
await onSubmit({...value, ...buildClusterConfig(fieldsValue)}); await onSubmit(fieldsValue);
handleCancel(); handleCancel();
}; };
...@@ -103,10 +98,10 @@ const InstanceModal: React.FC<ConfigurationModalProps> = (props) => { ...@@ -103,10 +98,10 @@ const InstanceModal: React.FC<ConfigurationModalProps> = (props) => {
}} }}
title={value.id ? l('rc.cc.modify') : l('rc.cc.create')} title={value.id ? l('rc.cc.modify') : l('rc.cc.create')}
submitter={{render: () => [...renderFooter()]}} submitter={{render: () => [...renderFooter()]}}
initialValues={parseConfigJsonToValues(value as Cluster.Config)} initialValues={value}
form={form} form={form}
> >
<ConfigurationForm form={form} value={parseConfigJsonToValues(value as Cluster.Config)}/> <ConfigurationForm form={form} value={value}/>
</ModalForm> </ModalForm>
</>; </>;
}; };
......
...@@ -125,17 +125,16 @@ export const KUBERNETES_CONFIG_LIST: FormConfig[] = [ ...@@ -125,17 +125,16 @@ export const KUBERNETES_CONFIG_LIST: FormConfig[] = [
tooltip: l('rc.cc.k8s.namespaceHelp'), tooltip: l('rc.cc.k8s.namespaceHelp'),
}, },
{ {
name: 'kubernetes.container.image', name: 'kubernetes.service.account',
label: l('rc.cc.k8s.image'), label: l('rc.cc.k8s.account'),
placeholder: l('rc.cc.k8s.imageHelp'), placeholder: l('rc.cc.k8s.accountHelp'),
tooltip: l('rc.cc.k8s.imageHelp'), tooltip: l('rc.cc.k8s.accountHelp'),
}, },
{ {
name: 'kubernetes.rest-service.exposed.type', name: 'kubernetes.container.image',
label: l('rc.cc.k8s.exposed'), label: l('rc.cc.k8s.image'),
placeholder: l('rc.cc.k8s.exposedHelp'), placeholder: l('rc.cc.k8s.imageHelp'),
tooltip: l('rc.cc.k8s.exposedHelp'), tooltip: l('rc.cc.k8s.imageHelp'),
showOnSubmitType: ClusterType.KUBERNETES_NATIVE,
}, },
{ {
name: 'kubernetes.jobmanager.cpu', name: 'kubernetes.jobmanager.cpu',
...@@ -155,19 +154,4 @@ export const KUBERNETES_CONFIG_LIST: FormConfig[] = [ ...@@ -155,19 +154,4 @@ export const KUBERNETES_CONFIG_LIST: FormConfig[] = [
placeholder: l('rc.cc.k8s.configFileHelp'), placeholder: l('rc.cc.k8s.configFileHelp'),
tooltip: l('rc.cc.k8s.configFileHelp'), tooltip: l('rc.cc.k8s.configFileHelp'),
}, },
{ ];
name: 'kubernetes.service.account',
label: l('rc.cc.k8s.account'),
placeholder: l('rc.cc.k8s.accountHelp'),
tooltip: l('rc.cc.k8s.accountHelp'),
showOnSubmitType: ClusterType.KUBERNETES_OPERATOR,
},
{
name: 'kubernetes.pod-template',
label: l('rc.cc.k8s.podTemplate'),
placeholder: l('rc.cc.k8s.podTemplate'),
tooltip: l('rc.cc.k8s.podTemplateHelp'),
showOnSubmitType: ClusterType.KUBERNETES_OPERATOR,
showType: 'code'
},
];
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {Cluster} from "@/types/RegCenter/data";
/**
* parse values to Cluster.Config
* @param {Cluster.Config} values
* @returns {{type: string} | {[p: string]: any, [p: number]: any, [p: symbol]: any, hadoopConfigPath: any, flinkConfigPath: any, flinkConfigList: any, type: string, flinkVersion: any, enabled: boolean, flinkConfig: any, hadoopConfigList: any, dockerConfig: any, flinkLibPath: any, kubernetesConfig: any, hadoopConfig: any, name: string, id: number, userJarPath: any}}
*/
export function parseConfigJsonToValues(values: Cluster.Config) {
if (!values.id) {
return {type: values.type};
}
// base info
const {type, id, name, enabled, configJson} = values;
// parse configJson
let config = JSON.parse(configJson);
// extract configJson from config
const {
hadoopConfigPath, flinkLibPath, flinkConfigPath, flinkVersion,
hadoopConfig, userJarPath, kubernetesConfig, dockerConfig,
flinkConfig, hadoopConfigList, flinkConfigList, ...rest
} = config;
// return values
return {
id,
name,
enabled,
type,
...rest, // ...rest 代表剩余参数
hadoopConfigPath,
flinkLibPath,
flinkConfigPath,
flinkVersion,
hadoopConfigList, // 使用此种方式 + antd 的 ProFormList 组件,可以实现动态表单 自动渲染该数组
flinkConfigList, // 使用此种方式 + antd 的 ProFormList 组件,可以实现动态表单 自动渲染该数组
hadoopConfig,
kubernetesConfig,
dockerConfig,
userJarPath,
flinkConfig,
}
}
/**
* build Cluster.Config from values
* @param values
* @returns {Cluster.Config}
*/
export function buildClusterConfig(values: any): Cluster.Config {
// extract values
const {
type, name, enabled, note,
hadoopConfigPath, flinkLibPath, flinkConfigPath, flinkVersion,
hadoopConfig, userJarPath, kubernetesConfig, dockerConfig,
flinkConfig, hadoopConfigList, flinkConfigList, ...rest
} = values;
// build configJson
const configJson = {
hadoopConfigPath, flinkLibPath, flinkConfigPath, flinkVersion,
hadoopConfig, userJarPath, kubernetesConfig, dockerConfig,
flinkConfig, hadoopConfigList, flinkConfigList, ...rest // ...rest 代表剩余参数
};
// deep copy configJson
const buildConfigJsonResult = JSON.stringify(configJson);
// return values
return {
name,
enabled,
note,
type,
configJson: buildConfigJsonResult,
} as Cluster.Config;
}
...@@ -92,7 +92,7 @@ declare namespace Cluster { ...@@ -92,7 +92,7 @@ declare namespace Cluster {
export type Config = BaseBeanColumns & { export type Config = BaseBeanColumns & {
type: string, type: string,
config?: any, config?: any,
configJson: string, configJson: any,
isAvailable?: boolean, isAvailable?: boolean,
note: string, note: string,
}; };
......
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