CheckInfo.tsx 15.3 KB
Newer Older
R
Rongfeng Fu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
import { useState } from 'react';
import { useModel } from 'umi';
import { Space, Button, Table, Row, Col, Alert, Tooltip } from 'antd';
import { ProCard } from '@ant-design/pro-components';
import type { ColumnsType } from 'antd/es/table';
import { EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons';
import useRequest from '@/utils/useRequest';
import { createDeploymentConfig } from '@/services/ob-deploy-web/Deployments';
import { handleQuit } from '@/utils';
import {
  componentsNameConfig,
  allComponentsKeys,
  onlyComponentsKeys,
  modeConfig,
  obproxyComponent,
} from '../constants';
import styles from './index.less';
interface ComponentsNodeConfig {
  name: string;
  servers: string[];
  key: string;
  isTooltip: boolean;
}

export default function CheckInfo() {
  const {
    configData,
    currentType,
    setCheckOK,
    lowVersion,
    setCurrentStep,
    handleQuitProgress,
  } = useModel('global');
  const { components = {}, auth, home_path } = configData || {};
  const {
    oceanbase = {},
    obproxy = {},
    ocpexpress = {},
    obagent = {},
  } = components;
  const [showPwd, setShowPwd] = useState(false);

  const { run: handleCreateConfig, loading } = useRequest(
    createDeploymentConfig,
    {
      onSuccess: ({ success }: API.OBResponse) => {
        if (success) {
          setCheckOK(true);
        }
      },
    },
  );

  const prevStep = () => {
    setCurrentStep(3);
  };

  const handlePreCheck = () => {
    handleCreateConfig({ name: oceanbase?.appname }, { ...configData });
  };

  const getComponentsList = () => {
    const componentsList: API.TableComponentInfo[] = [];
    allComponentsKeys.forEach((key) => {
      if (components?.[key]) {
        const componentConfig = componentsNameConfig?.[key] || {};
        componentsList.push({
          ...componentConfig,
          version: components?.[key].version,
          key,
        });
      }
    });
    return componentsList;
  };

  const getComponentsNodeConfigList = () => {
    const componentsNodeConfigList: ComponentsNodeConfig[] = [];
    let currentOnlyComponentsKeys = onlyComponentsKeys.filter(
      (key) => key !== 'obagent',
    );
    if (lowVersion) {
      currentOnlyComponentsKeys = currentOnlyComponentsKeys.filter(
        (key) => key !== 'ocpexpress',
      );
    }
    currentOnlyComponentsKeys.forEach((key) => {
      if (componentsNameConfig?.[key]) {
        componentsNodeConfigList.push({
          key,
          name: componentsNameConfig?.[key]?.name,
          servers: components?.[key]?.servers?.join(''),
          isTooltip: key === obproxyComponent,
        });
      }
    });

    return componentsNodeConfigList;
  };

  const dbConfigColumns: ColumnsType<API.DBConfig> = [
    {
      title: 'Zone 名称',
      dataIndex: 'name',
      width: 200,
      render: (text) => text || '-',
    },
    {
      title: 'OB Server 节点',
      dataIndex: 'servers',
      render: (text) => {
        const serversIps = text.map((item: API.OceanbaseServers) => item.ip);
        const str = serversIps.join('');
        return (
          <Tooltip title={str} placement="topLeft">
            <div className="ellipsis">{str}</div>
          </Tooltip>
        );
      },
    },
    {
      title: 'Root Server 节点',
      dataIndex: 'rootservice',
      width: 200,
      render: (text) => text || '-',
    },
  ];

  const getMoreColumns = (label: string) => {
    const columns: ColumnsType<API.MoreParameter> = [
      {
        title: `${label}参数名称`,
        dataIndex: 'key',
        render: (text) => text,
      },
      {
        title: '参数值',
        dataIndex: 'value',
        render: (text, record) => (record.adaptive ? '自适应' : text || '-'),
      },
      {
        title: '介绍',
        dataIndex: 'description',
        render: (text) => (
          <Tooltip title={text} placement="topLeft">
            <div className="ellipsis">{text}</div>
          </Tooltip>
        ),
      },
    ];
    return columns;
  };

  const componentsList = getComponentsList();
  const componentsNodeConfigList = getComponentsNodeConfigList();
  const initDir = `${home_path}/oceanbase/store`;
  const clusterConfigInfo = [
    {
      key: 'cluster',
      group: '集群配置',
      content: [
        { label: '配置模式', value: modeConfig[oceanbase?.mode] },
        {
          label: 'root@sys 密码',
          value: (
            <Tooltip title={oceanbase?.root_password} placement="topLeft">
              <div className="ellipsis">{oceanbase?.root_password}</div>
            </Tooltip>
          ),
        },
        {
          label: '数据目录',
          value: (
            <Tooltip title={oceanbase?.data_dir || initDir} placement="topLeft">
              <div className="ellipsis">{oceanbase?.data_dir || initDir}</div>
            </Tooltip>
          ),
        },
        {
          label: '日志目录',
          value: (
            <Tooltip title={oceanbase?.redo_dir || initDir} placement="topLeft">
              <div className="ellipsis">{oceanbase?.redo_dir || initDir}</div>
            </Tooltip>
          ),
        },
        { label: 'SQL 端口', value: oceanbase?.mysql_port },
        { label: 'RPC 端口', value: oceanbase?.rpc_port },
      ],
      more: oceanbase?.parameters?.length
        ? [
            {
              label: componentsNameConfig['oceanbase'].name,
              parameters: oceanbase?.parameters,
            },
          ]
        : [],
    },
  ];

  if (currentType === 'all') {
    const content = [
      { label: 'OBProxy 服务端口', value: obproxy?.listen_port },
      {
        label: 'OBProxy Exporter 端口',
        value: obproxy?.prometheus_listen_port,
      },
R
Rongfeng Fu 已提交
208 209
      { label: 'OBAgent 监控服务端口', value: obagent?.monagent_http_port },
      { label: 'OBAgent 管理服务端口', value: obagent?.mgragent_http_port },
R
Rongfeng Fu 已提交
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
    ];

    if (!lowVersion) {
      content.push({ label: 'OCPExpress 端口', value: ocpexpress?.port });
    }

    let more: any = [];
    if (obproxy?.parameters?.length) {
      more = [
        {
          label: componentsNameConfig['obproxy'].name,
          parameters: obproxy?.parameters,
        },
        {
          label: componentsNameConfig['obagent'].name,
          parameters: obagent?.parameters,
        },
      ];
      if (!lowVersion) {
        more.push({
          label: componentsNameConfig['ocpexpress'].name,
          parameters: ocpexpress?.parameters,
        });
      }
    }
    clusterConfigInfo.push({
      key: 'components',
      group: '组件配置',
      content,
      more,
    });
  }

  return (
    <Space
      className={`${styles.spaceWidth} ${styles.checkInfoSpace}`}
      direction="vertical"
      size="middle"
    >
      <Alert
        message="OceanBase 安装信息配置已完成,请检查并确认以下配置信息,确定后开始预检查。"
        type="info"
        showIcon
      />
      <ProCard className={styles.pageCard} split="horizontal">
        <Row gutter={16}>
          <ProCard title="部署配置" className="card-padding-bottom-24">
            <Col span={12}>
              <ProCard className={styles.infoSubCard} split="vertical">
                <ProCard colSpan={10} title="部署集群名称">
                  {oceanbase?.appname}
                </ProCard>
                <ProCard colSpan={14} title="部署类型">
                  {currentType === 'all' ? '完全部署' : '精简部署'}
                </ProCard>
              </ProCard>
            </Col>
          </ProCard>
          <ProCard
            title="部署组件"
            className="card-header-padding-top-0 card-padding-bottom-24 "
          >
            <Row gutter={16}>
              {componentsList.map(
                (item: API.TableComponentInfo, index: number) => (
                  <Col
                    span={12}
                    style={index > 1 ? { marginTop: 16 } : {}}
                    key={item.key}
                  >
                    <ProCard
                      className={styles.infoSubCard}
                      split="vertical"
                      key={item.key}
                    >
                      <ProCard colSpan={10} title="组件">
                        {item?.showComponentName}
                      </ProCard>
                      <ProCard colSpan={7} title="类型">
                        {componentsNameConfig[item.key]?.type}
                      </ProCard>
                      <ProCard colSpan={7} title="版本">
                        {item?.version}
                      </ProCard>
                    </ProCard>
                  </Col>
                ),
              )}
            </Row>
          </ProCard>
        </Row>
      </ProCard>
      <ProCard className={styles.pageCard} split="horizontal">
        <Row gutter={16}>
          <ProCard title="数据库节点配置" className="card-padding-bottom-24">
            <ProCard
              className={styles.infoSubCard}
              style={{ border: '1px solid #e2e8f3' }}
              split="vertical"
            >
              <Table
                className={`${styles.infoCheckTable}  ob-table`}
                columns={dbConfigColumns}
                dataSource={oceanbase?.topology}
                rowKey="id"
                scroll={{ y: 300 }}
                pagination={false}
              />
            </ProCard>
          </ProCard>
          {currentType === 'all' ? (
            <ProCard
              title="组件节点配置"
              className="card-header-padding-top-0 card-padding-bottom-24"
            >
              <Col span={componentsNodeConfigList?.length === 1 ? 12 : 24}>
                <ProCard className={styles.infoSubCard} split="vertical">
                  {componentsNodeConfigList.map(
                    (item: ComponentsNodeConfig) => (
                      <ProCard title={item.name} key={item.key}>
                        {item.isTooltip ? (
                          <Tooltip title={item?.servers} placement="topLeft">
                            <div className="ellipsis">{item?.servers}</div>
                          </Tooltip>
                        ) : (
                          item?.servers
                        )}
                      </ProCard>
                    ),
                  )}
                </ProCard>
              </Col>
            </ProCard>
          ) : null}
          <ProCard
            title="部署用户配置"
            className="card-header-padding-top-0 card-padding-bottom-24"
          >
            <Col span={12}>
              <ProCard className={styles.infoSubCard} split="vertical">
                <ProCard title="用户名">{auth?.user}</ProCard>
                <ProCard title="密码">
                  {auth?.password ? (
                    <div style={{ position: 'relative' }}>
                      {showPwd ? (
                        <div>
                          <Tooltip title={auth?.password} placement="topLeft">
                            <div
                              className="ellipsis"
                              style={{ width: 'calc(100% - 20px)' }}
                            >
                              {auth?.password}
                            </div>
                          </Tooltip>
                          <EyeOutlined
                            className={styles.pwdIcon}
                            onClick={() => setShowPwd(false)}
                          />
                        </div>
                      ) : (
                        <div>
                          ******
                          <EyeInvisibleOutlined
                            className={styles.pwdIcon}
                            onClick={() => setShowPwd(true)}
                          />
                        </div>
                      )}
                    </div>
                  ) : (
                    '-'
                  )}
                </ProCard>
              </ProCard>
            </Col>
          </ProCard>
          <ProCard
            title="软件路径配置"
            className="card-header-padding-top-0 card-padding-bottom-24"
          >
            <Col span={12}>
              <ProCard className={styles.infoSubCard} split="vertical">
                <ProCard title="软件路径">
                  <Tooltip title={home_path} placement="topLeft">
                    {home_path}
                  </Tooltip>
                </ProCard>
              </ProCard>
            </Col>
          </ProCard>
        </Row>
      </ProCard>
      <ProCard split="horizontal">
        <Row gutter={16}>
          {clusterConfigInfo?.map((item, index) => (
            <ProCard
              title={item.group}
              key={item.key}
              className={`${
                index === clusterConfigInfo?.length - 1
                  ? 'card-header-padding-top-0 card-padding-bottom-24'
                  : 'card-padding-bottom-24'
              }`}
            >
              <Col span={24}>
                <ProCard className={styles.infoSubCard} split="vertical">
                  {item.content.map((subItem) => (
                    <ProCard title={subItem.label} key={subItem.label}>
                      {subItem.value}
                    </ProCard>
                  ))}
                </ProCard>
              </Col>
              <Space
                direction="vertical"
                size="middle"
                style={{ marginTop: 16 }}
              >
                {item?.more?.length
                  ? item?.more.map((moreItem) => (
                      <ProCard
                        className={styles.infoSubCard}
                        style={{ border: '1px solid #e2e8f3' }}
                        split="vertical"
                        key={moreItem.label}
                      >
                        <Table
                          className={`${styles.infoCheckTable}  ob-table`}
                          columns={getMoreColumns(moreItem.label)}
                          dataSource={moreItem?.parameters}
                          pagination={false}
                          scroll={{ y: 300 }}
                          rowKey="key"
                        />
                      </ProCard>
                    ))
                  : null}
              </Space>
            </ProCard>
          ))}
        </Row>
      </ProCard>
      <footer className={styles.pageFooterContainer}>
        <div className={styles.pageFooter}>
          <Space className={styles.foolterAction}>
            <Button
              onClick={() => handleQuit(handleQuitProgress, setCurrentStep)}
              data-aspm-click="c307504.d317275"
              data-aspm-desc="预检查-退出"
              data-aspm-param={``}
              data-aspm-expo
            >
              退出
            </Button>
            <Button
              onClick={prevStep}
              data-aspm-click="c307504.d317274"
              data-aspm-desc="预检查-上一步"
              data-aspm-param={``}
              data-aspm-expo
            >
              上一步
            </Button>
            <Button
              type="primary"
              onClick={handlePreCheck}
              loading={loading}
              data-aspm-click="c307504.d317273"
              data-aspm-desc="预检查-预检查"
              data-aspm-param={``}
              data-aspm-expo
            >
              预检查
            </Button>
          </Space>
        </div>
      </footer>
    </Space>
  );
}