import * as React from 'react'; import { Modal, Table, Button, notification, message, Tooltip, Icon, Popconfirm, Alert, Popover } from 'component/antd'; import { wrapper } from 'store'; import { observer } from 'mobx-react'; import { IXFormWrapper, IMetaData, IRegister } from 'types/base-type'; import { admin } from 'store/admin'; import { users } from 'store/users'; import { registerCluster, createCluster, pauseMonitoring } from 'lib/api'; import { SearchAndFilterContainer } from 'container/search-filter'; import { cluster } from 'store/cluster'; import { customPagination } from 'constants/table'; import { urlPrefix } from 'constants/left-menu'; import { indexUrl } from 'constants/strategy' import { region } from 'store'; import './index.less'; import Monacoeditor from 'component/editor/monacoEditor'; import { getAdminClusterColumns } from '../config'; const { confirm } = Modal; @observer export class ClusterList extends SearchAndFilterContainer { public state = { searchKey: '', }; private xFormModal: IXFormWrapper; // TODO: 公共化 public renderClusterHref(value: number | string, item: IMetaData, key: number) { return ( // 0 暂停监控--不可点击 1 监控中---可正常点击 <> {item.status === 1 ? {value} : {value}} ); } public createOrRegisterCluster(item: IMetaData) { this.xFormModal = { formMap: [ { key: 'clusterName', label: '集群名称', rules: [{ required: true, message: '请输入集群名称', }], attrs: { placeholder: '请输入集群名称', disabled: item ? true : false, }, }, { key: 'zookeeper', label: 'zookeeper地址', type: 'text_area', rules: [{ required: true, message: '请输入zookeeper地址', }], attrs: { placeholder: '请输入zookeeper地址,例如:192.168.0.1:2181,192.168.0.2:2181/logi-kafka', rows: 2, disabled: item ? true : false, }, }, { key: 'bootstrapServers', label: 'bootstrapServers', type: 'text_area', rules: [{ required: true, message: '请输入bootstrapServers', }], attrs: { placeholder: '请输入bootstrapServers,例如:192.168.1.1:9092,192.168.1.2:9092', rows: 2, disabled: item ? true : false, }, }, // { // key: 'idc', // label: '数据中心', // defaultValue: region.regionName, // rules: [{ required: true, message: '请输入数据中心' }], // attrs: { // placeholder: '请输入数据中心', // disabled: true, // }, // }, // { // key: 'mode', // label: '集群类型', // type: 'select', // options: cluster.clusterModes.map(ele => { // return { // label: ele.message, // value: ele.code, // }; // }), // rules: [{ // required: true, // message: '请选择集群类型', // }], // attrs: { // placeholder: '请选择集群类型', // }, // }, { key: 'kafkaVersion', label: 'kafka版本', invisible: item ? false : true, rules: [{ required: false, message: '请输入kafka版本', }], attrs: { placeholder: '请输入kafka版本', disabled: true, }, }, { key: 'securityProperties', label: '安全协议', type: 'text_area', rules: [{ required: false, message: '请输入安全协议', }], attrs: { placeholder: `请输入安全协议,例如: { "security.protocol": "SASL_PLAINTEXT", "sasl.mechanism": "PLAIN", "sasl.jaas.config": "org.apache.kafka.common.security.plain.PlainLoginModule required username=\\"xxxxxx\\" password=\\"xxxxxx\\";" }`, rows: 8, }, }, { key: 'jmxProperties', label: 'JMX认证', type: 'text_area', rules: [{ required: false, message: '请输入JMX认证', }], attrs: { placeholder: `请输入JMX认证,例如: { "maxConn": 10, #KM对单台Broker的最大jmx连接数 "username": "xxxxx", #用户名 "password": "xxxxx", #密码 "openSSL": true, #开启SSL,true表示开启SSL,false表示关闭 }`, rows: 8, }, }, ], formData: item ? item : {}, visible: true, width: 590, title: item ? '编辑' : '接入集群', onSubmit: (value: IRegister) => { value.idc = region.currentRegion; if (item) { value.clusterId = item.clusterId; registerCluster(value).then(data => { admin.getMetaData(true); notification.success({ message: '编辑集群成功' }); }); } else { createCluster(value).then(data => { admin.getMetaData(true); notification.success({ message: '接入集群成功' }); }); } }, }; wrapper.open(this.xFormModal); } public pauseMonitor(item: IMetaData) { const info = item.status === 1 ? '暂停监控' : '开始监控'; const status = item.status === 1 ? 0 : 1; pauseMonitoring(item.clusterId, status).then(data => { admin.getMetaData(true); notification.success({ message: `${info}成功` }); }); } public showMonitor = (record: IMetaData) => { admin.getBrokersRegions(record.clusterId).then((data) => { confirm({ // tslint:disable-next-line:jsx-wrap-multiline title: <> 删除集群  , icon: 'none', content: this.deleteMonitorModal(data), width: 500, okText: '确认', cancelText: '取消', onOk() { if (data.length) { return message.warning('存在逻辑集群,无法删除!'); } admin.deleteCluster(record.clusterId).then(data => { notification.success({ message: '删除成功' }); }); }, }); }); } public deleteMonitorModal = (source: any) => { const cellStyle = { overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', cursor: 'pointer', }; const monitorColumns = [ { title: '逻辑集群列表', dataIndex: 'name', key: 'name', onCell: () => ({ style: { maxWidth: 250, ...cellStyle, }, }), render: (t: string) => { return ( {t} ); }, }, ]; return ( <>
); } public getData(origin: T[]) { let data: T[] = origin; let { searchKey } = this.state; searchKey = (searchKey + '').trim().toLowerCase(); data = searchKey ? origin.filter((item: IMetaData) => (item.clusterName !== undefined && item.clusterName !== null) && item.clusterName.toLowerCase().includes(searchKey as string), ) : origin; return data; } public getColumns = () => { const cols = getAdminClusterColumns(); const role = users.currentUser.role; const col = { title: '操作', render: (value: string, item: IMetaData) => ( <> { role && role === 2 ? <> 编辑 this.pauseMonitor(item)} cancelText="取消" okText="确认" > {item.status === 1 ? '暂停监控' : '开始监控'} 删除 : 编辑 {item.status === 1 ? '暂停监控' : '开始监控'} 删除 } ), }; cols.push(col as any); return cols; } public renderClusterList() { const role = users.currentUser.role; return ( <>
    {this.renderSearch('', '请输入集群名称')}
  • 集群接入指南 { role && role === 2 ? : }
); } public componentDidMount() { admin.getMetaData(true); cluster.getClusterModes(); admin.getDataCenter(); } public render() { return ( admin.metaList ? <> {this.renderClusterList()} : null ); } }