From 96c23b575984404131a462ce2704cca84a3a5813 Mon Sep 17 00:00:00 2001 From: alan Date: Wed, 4 Sep 2019 16:35:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20KERNEL-1208=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=BC=82=E5=B8=B8=E6=97=B6=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=AF=B9=E5=BA=94=E9=A9=B1=E5=8A=A8=E7=9A=84?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i18n/zh_cn.properties | 3 + private/i18n.ts | 3 + .../test_status/test_status.model.ts | 4 + .../components/test_status/test_status.ts | 61 ++++++-- src/modules/constants/constant.ts | 140 +++++++++++++++++- src/modules/crud/api.ts | 5 + src/modules/crud/decision.api.ts | 8 + src/modules/crud/design.api.ts | 5 + .../list/list_item/list_item.model.ts | 9 +- .../connection/list/list_item/list_item.ts | 21 ++- .../maintain/forms/components/form.jdbc.ts | 2 +- .../pages/maintain/forms/form.model.ts | 3 + src/modules/pages/maintain/forms/form.ts | 16 +- 13 files changed, 256 insertions(+), 24 deletions(-) diff --git a/i18n/zh_cn.properties b/i18n/zh_cn.properties index f1136e2..d889fad 100644 --- a/i18n/zh_cn.properties +++ b/i18n/zh_cn.properties @@ -102,6 +102,9 @@ Dec-Dcm_Connection_JDBC_Warning= 请确认已经将krb5.Conf文件添加到/weba Dec-Dcm_Connection_Form_UserName_Password= 用户名密码 Dec-Dcm_Change_Name= 重命名 Dec-Dcm_Socket_Unable_Connect= Socket未连接,可能存在多人同时编辑造成冲突,相关端口可能未开放 +Dec-Dcm_Connection_HW_DWS=华为云DWS +Dec-Dcm_Connection_Lack_Driver=未找到“{R1}”驱动。 +Dec-Dcm_Connection_Download_Driver=下载对应驱动 BI-Multi_Date_Quarter_End= 季度末 BI-Multi_Date_Month_Begin= 月初 diff --git a/private/i18n.ts b/private/i18n.ts index 15589b4..9813821 100644 --- a/private/i18n.ts +++ b/private/i18n.ts @@ -101,6 +101,9 @@ export default { 'Dec-Dcm_Connection_Form_UserName_Password': '用户名密码', 'Dec-Dcm_Change_Name': '重命名', 'Dec-Dcm_Socket_Unable_Connect': 'Socket未连接,可能存在多人同时编辑造成冲突,相关端口可能未开放', + 'Dec-Dcm_Connection_HW_DWS': '华为云DWS', + 'Dec-Dcm_Connection_Lack_Driver': '未找到“{R1}”驱动。', + 'Dec-Dcm_Connection_Download_Driver': '下载对应驱动', 'BI-Multi_Date_Quarter_End': '季度末', 'BI-Multi_Date_Month_Begin': '月初', 'BI-Multi_Date_YMD': '年月日', diff --git a/src/modules/components/test_status/test_status.model.ts b/src/modules/components/test_status/test_status.model.ts index f5a07db..8a728f4 100644 --- a/src/modules/components/test_status/test_status.model.ts +++ b/src/modules/components/test_status/test_status.model.ts @@ -6,6 +6,7 @@ export class TestStatusModel extends Model { state() { return { status: TEST_STATUS.LOADING, + link: '', }; } @@ -13,5 +14,8 @@ export class TestStatusModel extends Model { setStatus: (status: string) => { this.model.status = status; }, + setLink: (link: string) => { + this.model.link = link; + }, } } diff --git a/src/modules/components/test_status/test_status.ts b/src/modules/components/test_status/test_status.ts index 7d73704..dc49c32 100644 --- a/src/modules/components/test_status/test_status.ts +++ b/src/modules/components/test_status/test_status.ts @@ -1,6 +1,6 @@ import { shortcut, store } from '@core/core'; import { TestStatusModelXtype, TestStatusModel } from './test_status.model'; -import { CenterAdapt, Tab, Horizotal, Vertical } from 'ui'; +import { CenterAdapt, Tab, Vertical, Label, TextButton, Left } from 'ui'; import { TEST_STATUS } from '@constants/constant'; import { TipIconXtype } from './tip_icon/tip_icon'; import { TipFailXtype, EVENT_CLOSE, EVENT_RELOAD, EVENT_DETAIL } from './tip_icon/tip_fail'; @@ -27,6 +27,8 @@ export class TestStatus extends BI.Widget { tab: any; failMessage: any; + failDriverMessage: any; + driverLink: any; detail: any; watch = { @@ -105,25 +107,48 @@ export class TestStatus extends BI.Widget { type: Vertical, cls: 'bi-card', invisible: true, + bgap: 10, items: [ { - type: Horizotal, - height: 73, + type: Vertical, cls: 'bi-header-background', - tgap: 5, - bgap: 10, + vgap: 5, hgap: 10, scrolly: true, - items: [{ - type: 'bi.label', - whiteSpace: 'normal', - width: 400, - textAlign: 'left', - text: '', - ref: (_ref: any) => { - this.failMessage = _ref; + items: [ + { + type: Label, + whiteSpace: 'normal', + width: 400, + textAlign: 'left', + text: '', + ref: (_ref: any) => { + this.failMessage = _ref; + }, }, - }], + { + type: Label, + textAlign: 'left', + invisible: true, + ref: (_ref: any) => { + this.failDriverMessage = _ref; + }, + }, + { + type: Left, + invisible: true, + items: [ + { + type: TextButton, + cls: 'bi-high-light bi-high-light-border-bottom', + text: BI.i18nText('Dec-Dcm_Connection_Download_Driver'), + }, + ], + ref: (_ref: any) => { + this.driverLink = _ref; + }, + }, + ], }, ], ref: (_ref: any) => { @@ -140,9 +165,15 @@ export class TestStatus extends BI.Widget { this.store.setStatus(TEST_STATUS.SUCCESS); } - setFail(message: string) { + setFail(message: string, driver = '', link = '') { this.store.setStatus(TEST_STATUS.FAIL); this.failMessage.setText(message); + this.failDriverMessage.isVisible(!!driver); + this.driverLink.isVisible(!!driver); + if (driver) { + this.failDriverMessage.setText(BI.i18nText('Dec-Dcm_Connection_Lack_Driver', driver)); + this.store.setLink(link); + } } setLoading() { diff --git a/src/modules/constants/constant.ts b/src/modules/constants/constant.ts index 5ad38ac..a6aae32 100644 --- a/src/modules/constants/constant.ts +++ b/src/modules/constants/constant.ts @@ -28,6 +28,144 @@ export const DATA_BASE_TYPES_OTHER = hasSchema: true, kerberos: false, }; +export const DATA_BASE_DRIVER_LINK = DecCst ? [ + { + databaseType: 'ads', + link: DecCst.Hyperlink.Database.ADS, + }, + { + databaseType: 'amazon-redshift', + link: DecCst.Hyperlink.Database.REDSHIFT, + }, + { + databaseType: 'apache-impala', + link: DecCst.Hyperlink.Database.IMPALA, + }, + { + databaseType: 'apache-kylin', + link: DecCst.Hyperlink.Database.PHOENIX, + }, + { + databaseType: 'apache-phoenix', + link: DecCst.Hyperlink.Database.PHOENIX, + }, + { + databaseType: 'derby', + link: DecCst.Hyperlink.Database.DERBY, + }, + { + databaseType: 'gbase-8a', + link: DecCst.Hyperlink.Database.GBASE8A, + }, + { + databaseType: 'gbase-8s', + link: DecCst.Hyperlink.Database.GBASE8S, + }, + { + databaseType: 'gbase-8t', + link: DecCst.Hyperlink.Database.GBASE8T, + }, + { + databaseType: 'h2', + link: DecCst.Hyperlink.Database.H2, + }, + { + databaseType: 'hw-dws', + link: DecCst.Hyperlink.Database.DWS, + }, + { + databaseType: 'hw-elk', + link: DecCst.Hyperlink.Database.ELK, + }, + { + databaseType: 'hw-fusioninsight-hd', + link: DecCst.Hyperlink.Database.FUSIONINSIGHT, + }, + { + databaseType: 'hw-libr-a', + link: DecCst.Hyperlink.Database.LIBRA, + }, + { + databaseType: 'hadoop-hive', + link: DecCst.Hyperlink.Database.HIVE, + }, + { + databaseType: 'hbase', + link: DecCst.Hyperlink.Database.HBASE, + }, + { + databaseType: 'hp-vertica', + link: DecCst.Hyperlink.Database.VERTICA, + }, + { + databaseType: 'hsql', + link: DecCst.Hyperlink.Database.HSQL, + }, + { + databaseType: 'ibm-db2', + link: DecCst.Hyperlink.Database.DB2, + }, + { + databaseType: 'informix', + link: DecCst.Hyperlink.Database.INFORMIX, + }, + { + databaseType: 'kingbase', + link: DecCst.Hyperlink.Database.KINGBASE, + }, + { + databaseType: 'sql-server', + link: DecCst.Hyperlink.Database.SQLSERVER, + }, + { + databaseType: 'mysql', + link: DecCst.Hyperlink.Database.MYSQL, + }, + { + databaseType: 'oracle', + link: DecCst.Hyperlink.Database.ORACLE, + }, + { + databaseType: 'pivotal-greenplum-database', + link: DecCst.Hyperlink.Database.GP, + }, + { + databaseType: 'postgresql', + link: DecCst.Hyperlink.Database.POSTGRE, + }, + { + databaseType: 'presto', + link: DecCst.Hyperlink.Database.PRESTO, + }, + { + databaseType: 'sap-hana', + link: DecCst.Hyperlink.Database.HANA, + }, + { + databaseType: 'sap-sybase', + link: DecCst.Hyperlink.Database.SYBASE, + }, + { + databaseType: 'spark', + link: DecCst.Hyperlink.Database.SPARK, + }, + { + databaseType: 'sqlite', + link: DecCst.Hyperlink.Database.SQLITE, + }, + { + databaseType: 'teradata', + link: DecCst.Hyperlink.Database.TERADATA, + }, + { + databaseType: 'transwarp-inceptor', + link: DecCst.Hyperlink.Database.INCEPTOR, + }, + { + databaseType: 'other', + link: DecCst.Hyperlink.Database.OTHER, + }, +] : []; export const DATA_BASE_TYPES = [ { text: 'ADS', @@ -141,7 +279,7 @@ export const DATA_BASE_TYPES = [ kerberos: false, }, { - text: '华为云DWS', + text: BI.i18nText('Dec-Dcm_Connection_HW_DWS'), databaseType: 'hw-dws', driver: 'org.postgresql.Driver', url: 'jdbc:postgresql://hostname:port/database', diff --git a/src/modules/crud/api.ts b/src/modules/crud/api.ts index aafe39a..c42d101 100644 --- a/src/modules/crud/api.ts +++ b/src/modules/crud/api.ts @@ -56,4 +56,9 @@ export interface Api { * 获取socket连接状态 */ getSocketStatus(): boolean; + + /** + * 判断是否是驱动的错误 + */ + isDriverError(errorCode: string): boolean; } diff --git a/src/modules/crud/decision.api.ts b/src/modules/crud/decision.api.ts index e4b2fe3..bf7651c 100644 --- a/src/modules/crud/decision.api.ts +++ b/src/modules/crud/decision.api.ts @@ -64,6 +64,14 @@ export class DecisionApi implements Api { return false; } + isDriverError(errorCode: string) { + if (Dec) { + return DecCst.ErrorCode.LACK_DRIVER === errorCode; + } + + return false; + } + private sendEditStatusEvent(name: string, type: string): Promise { return new Promise(resolve => { if (Dec && Dec.socket.connected) { diff --git a/src/modules/crud/design.api.ts b/src/modules/crud/design.api.ts index 33a77ad..a551e36 100644 --- a/src/modules/crud/design.api.ts +++ b/src/modules/crud/design.api.ts @@ -61,4 +61,9 @@ export class DesignApi implements Api { // 设计器无socket校验 return true; } + + isDriverError(errorCode: string) { + // 设计器暂不校验 + return false; + } } diff --git a/src/modules/pages/connection/list/list_item/list_item.model.ts b/src/modules/pages/connection/list/list_item/list_item.model.ts index cc4fc11..4107efc 100644 --- a/src/modules/pages/connection/list/list_item/list_item.model.ts +++ b/src/modules/pages/connection/list/list_item/list_item.model.ts @@ -78,11 +78,18 @@ export class ListItemModel extends Model<{ }; }); - return api.updateConnection(connection); + return api.updateConnection(connection).then(re => { + this.setIsEdit(false, oldName); + + return re; + }); }, setIsCopy(isCopy: boolean) { this.model.isCopy = isCopy; }, + isDriverError(errorCode: string) { + return api.isDriverError(errorCode); + }, } removeConnection(name: string) { api.deleteConnection(name).then(re => api.getConnectionlist()) diff --git a/src/modules/pages/connection/list/list_item/list_item.ts b/src/modules/pages/connection/list/list_item/list_item.ts index b072ebd..5ba8c97 100644 --- a/src/modules/pages/connection/list/list_item/list_item.ts +++ b/src/modules/pages/connection/list/list_item/list_item.ts @@ -2,9 +2,11 @@ import { shortcut, store } from '@core/core'; import { Label, LeftRightVerticalAdapt, IconLabel, IconButton, DownListCombo, SignEditor } from 'ui'; import './list_item.less'; import { ListItemModel, ListItemModelXtype } from './list_item.model'; -import { PAGE_INDEX } from '@constants/constant'; +import { PAGE_INDEX, DATA_BASE_DRIVER_LINK } from '@constants/constant'; import { TestStatusXtype, TestStatus, EVENT_CLOSE, EVENT_RELOAD } from 'src/modules/components/test_status/test_status'; import { hasRegistered } from '../list.service'; +import { connectionType } from '@constants/env'; +import { ConnectionJDBC } from 'src/modules/crud/crud.typings'; export const ListItemXtype = 'dec.dcm.connection.list_item'; @shortcut(ListItemXtype) @store(ListItemModelXtype) @@ -68,7 +70,6 @@ export class ListItem extends BI.BasicButton { action: () => { const newName = this.nameEditor.getValue(); this.store.changeName(name, newName).then(() => { - this.store.setIsEdit(false, name); this.nameLabel.setText(newName); }); }, @@ -156,12 +157,24 @@ export class ListItem extends BI.BasicButton { } private testConnectionAction() { - const { name } = this.options; + const { name, databaseType } = this.options; const id = BI.UUID(); const testConnection = () => { this.store.testConnection(name).then(re => { if (re && re.errorCode) { - this.testStatus.setFail(re.errorMsg); + // 判断是否是缺少驱动,如果缺少驱动则显示下载驱动的连接 + if (this.store.isDriverError(re.errorCode)) { + const thisConnection = this.model.connections.find(item => item.connectionName === name); + if (thisConnection.connectionType === connectionType.JDBC) { + const driver = (thisConnection.connectionData as ConnectionJDBC).driver; + const databaseLink = BI.get(DATA_BASE_DRIVER_LINK.find(item => item.databaseType === databaseType), 'link'); + this.testStatus.setFail(re.errorMsg, driver, BI.Services.getService('dec.service.migration').getHelpLink(databaseLink)); + } else { + this.testStatus.setFail(re.errorMsg); + } + } else { + this.testStatus.setFail(re.errorMsg); + } } else if (re.data) { this.testStatus.setSuccess(); setTimeout(() => { diff --git a/src/modules/pages/maintain/forms/components/form.jdbc.ts b/src/modules/pages/maintain/forms/components/form.jdbc.ts index 20aede1..d0735bb 100644 --- a/src/modules/pages/maintain/forms/components/form.jdbc.ts +++ b/src/modules/pages/maintain/forms/components/form.jdbc.ts @@ -285,7 +285,7 @@ export class FormJdbc extends BI.Widget { cls: 'bi-tips', textAlign: 'left', invisible: true, - text: BI.i18nText('Dec-Dcm_Connection_JNDI_Warning'), + text: BI.i18nText('Dec-Dcm_Connection_JDBC_Warning'), ref: (_ref: any) => { this.labelTips = _ref; }, diff --git a/src/modules/pages/maintain/forms/form.model.ts b/src/modules/pages/maintain/forms/form.model.ts index e0071c8..018a679 100644 --- a/src/modules/pages/maintain/forms/form.model.ts +++ b/src/modules/pages/maintain/forms/form.model.ts @@ -36,5 +36,8 @@ export class MaintainFormModel extends Model<{ setIsCopy(isCopy: boolean) { this.model.isCopy = isCopy; }, + isDriverError(errorCode: string) { + return api.isDriverError(errorCode); + }, } } diff --git a/src/modules/pages/maintain/forms/form.ts b/src/modules/pages/maintain/forms/form.ts index ab14cb5..0fd48bf 100644 --- a/src/modules/pages/maintain/forms/form.ts +++ b/src/modules/pages/maintain/forms/form.ts @@ -6,7 +6,7 @@ import { FormPluginXtype } from './components/form.plugin'; import { connectionType } from '@constants/env'; import { ConnectionJDBC, Connection } from 'src/modules/crud/crud.typings'; import { TestStatusXtype, EVENT_RELOAD, EVENT_CLOSE } from 'src/modules/components/test_status/test_status'; -import { DEFAULT_JNDI_DATA, DEFAULT_JDBC_POOL } from '@constants/constant'; +import { DEFAULT_JNDI_DATA, DEFAULT_JDBC_POOL, DATA_BASE_DRIVER_LINK } from '@constants/constant'; import { getJdbcDatabaseType } from 'src/modules/app.service'; export const MaintainFormXtype = 'dec.dcm.maintain.form'; @@ -49,7 +49,19 @@ export class MaintainForm extends BI.Widget { } this.store.testConnection(formValue).then(re => { if (re && re.errorCode) { - this.testStatus.setFail(re.errorMsg); + // 判断是否是缺少驱动,如果缺少驱动则显示下载驱动的连接 + if (this.store.isDriverError(re.errorCode)) { + if (formValue.connectionType === connectionType.JDBC) { + const driver = (formValue.connectionData as ConnectionJDBC).driver; + const databaseType = (formValue.connectionData as ConnectionJDBC).database; + const databaseLink = BI.get(DATA_BASE_DRIVER_LINK.find(item => item.databaseType === databaseType), 'link'); + this.testStatus.setFail(re.errorMsg, driver, BI.Services.getService('dec.service.migration').getHelpLink(databaseLink)); + } else { + this.testStatus.setFail(re.errorMsg); + } + } else { + this.testStatus.setFail(re.errorMsg); + } } else if (re.data) { this.testStatus.setSuccess(); if (re.data.length > 0) {