Search in sources :

Example 1 with DataSourceTypeEnum

use of com.dtstack.taier.common.enums.DataSourceTypeEnum in project Taier by DTStack.

the class DatasourceService method convertParamToVO.

/**
 * 转换成datasourceVo
 * @param tenantId
 * @param userId
 * @param dscJson
 * @param dataName
 * @param dataSourceType
 * @param dbName
 * @return
 */
private DataSourceVO convertParamToVO(Long tenantId, Long userId, String dscJson, String dataName, Integer dataSourceType, String dbName) {
    DataSourceVO dataSourceVO = new DataSourceVO();
    dataSourceVO.setUserId(userId);
    dataSourceVO.setTenantId(tenantId);
    dataSourceVO.setGmtCreate(new Date());
    dataSourceVO.setGmtModified(new Date());
    dataSourceVO.setDataName(dataName);
    dataSourceVO.setType(dataSourceType);
    dataSourceVO.setSchemaName(dbName);
    DataSourceTypeEnum typeEnum = DataSourceTypeEnum.valOf(dataSourceType);
    Asserts.notNull(typeEnum, ErrorCode.CAN_NOT_FITABLE_SOURCE_TYPE);
    dataSourceVO.setDataType(typeEnum.getDataType());
    dataSourceVO.setDataVersion(typeEnum.getDataVersion());
    if (Strings.isNotBlank(dscJson)) {
        dataSourceVO.setDataJson(DataSourceUtils.getDataSourceJson(dscJson));
    }
    dataSourceVO.setIsMeta(1);
    return dataSourceVO;
}
Also used : DataSourceVO(com.dtstack.taier.develop.dto.devlop.DataSourceVO) DataSourceTypeEnum(com.dtstack.taier.common.enums.DataSourceTypeEnum) Date(java.util.Date)

Example 2 with DataSourceTypeEnum

use of com.dtstack.taier.common.enums.DataSourceTypeEnum in project Taier by DTStack.

the class DatasourceService method kerberosConnectPrepare.

/**
 * kerberos认证前预处理 :对kerberos参数替换相对路径为绝对路径等操作
 * @param sourceId
 * @return
 */
public Map<String, Object> kerberosConnectPrepare(Long sourceId) {
    DsInfo dataSource = dsInfoService.getOneById(sourceId);
    DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(dataSource.getDataType(), dataSource.getDataVersion());
    if (Objects.isNull(typeEnum)) {
        throw new PubSvcDefineException(ErrorCode.CAN_NOT_FITABLE_SOURCE_TYPE);
    }
    Map<String, Object> kerberosConfig = fillKerberosConfig(dataSource.getId());
    HashMap<String, Object> tmpKerberosConfig = new HashMap<>(kerberosConfig);
    // kerberos获取表操作预处理
    if (MapUtils.isNotEmpty(kerberosConfig)) {
        String localKerberosPath = kerberosService.getLocalKerberosPath(sourceId);
        IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
        try {
            kerberos.prepareKerberosForConnect(tmpKerberosConfig, localKerberosPath);
        } catch (Exception e) {
            LOGGER.error("kerberos连接预处理失败!{}", e.getMessage(), e);
            throw new DtCenterDefException(String.format("kerberos连接预处理失败,Caused by: %s", e.getMessage()), e);
        }
    }
    return tmpKerberosConfig;
}
Also used : DataSourceTypeEnum(com.dtstack.taier.common.enums.DataSourceTypeEnum) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) PubSvcDefineException(com.dtstack.taier.common.exception.PubSvcDefineException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) JSONObject(com.alibaba.fastjson.JSONObject) IKerberos(com.dtstack.dtcenter.loader.client.IKerberos) DsInfo(com.dtstack.taier.dao.domain.DsInfo) SftpException(com.jcraft.jsch.SftpException) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) PubSvcDefineException(com.dtstack.taier.common.exception.PubSvcDefineException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException)

Example 3 with DataSourceTypeEnum

use of com.dtstack.taier.common.enums.DataSourceTypeEnum in project Taier by DTStack.

the class DatasourceService method getPrincipalsWithConf.

/**
 * 解析kerberos文件获取principal列表
 * @param source
 * @param resource
 * @param userId
 * @return
 */
public List<String> getPrincipalsWithConf(DataSourceVO source, Pair<String, String> resource, Long userId) {
    String localKerberosPath;
    Map<String, Object> kerberosConfig;
    // 获取数据源类型,这里要做type version的改造
    DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(source.getDataType(), source.getDataVersion());
    IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
    if (Objects.nonNull(resource)) {
        localKerberosPath = kerberosService.getTempLocalKerberosConf(userId);
        try {
            // 解析Zip文件获取配置对象
            kerberosConfig = kerberos.parseKerberosFromUpload(resource.getRight(), localKerberosPath);
        } catch (IOException e) {
            LOGGER.error("解析principals, kerberos config 解析异常,{}", e.getMessage(), e);
            throw new PubSvcDefineException(String.format("kerberos config 解析异常,Caused by: %s", e.getMessage()), e);
        }
        // 连接 Kerberos 前的准备工作
        kerberos.prepareKerberosForConnect(kerberosConfig, localKerberosPath);
    } else {
        kerberosConfig = kerberosConnectPrepare(source.getId());
    }
    return kerberos.getPrincipals(kerberosConfig);
}
Also used : DataSourceTypeEnum(com.dtstack.taier.common.enums.DataSourceTypeEnum) PubSvcDefineException(com.dtstack.taier.common.exception.PubSvcDefineException) JSONObject(com.alibaba.fastjson.JSONObject) IKerberos(com.dtstack.dtcenter.loader.client.IKerberos) IOException(java.io.IOException)

Example 4 with DataSourceTypeEnum

use of com.dtstack.taier.common.enums.DataSourceTypeEnum in project Taier by DTStack.

the class DatasourceService method checkConnectionWithConf.

/**
 * 数据源连通性测试
 * @param source
 * @param confMap
 * @param localKerberosPath
 * @return
 */
public Boolean checkConnectionWithConf(DataSourceVO source, Map<String, Object> confMap, String localKerberosPath) {
    DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(source.getDataType(), source.getDataVersion());
    if (MapUtils.isEmpty(confMap) && source.getId() > 0L) {
        confMap = fillKerberosConfig(source.getId());
        localKerberosPath = kerberosService.getLocalKerberosPath(source.getId());
    }
    if (DataSourceTypeEnum.ADB_PostgreSQL == typeEnum) {
        typeEnum = DataSourceTypeEnum.PostgreSQL;
    }
    // 替换相对绝对路径
    Map<String, Object> tempConfMap = null;
    if (MapUtils.isNotEmpty(confMap)) {
        tempConfMap = Maps.newHashMap(confMap);
        IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
        kerberos.prepareKerberosForConnect(tempConfMap, localKerberosPath);
    }
    // 测试连通性
    ISourceDTO sourceDTO = SourceDTOType.getSourceDTO(source.getDataJson(), typeEnum.getVal(), tempConfMap, Maps.newHashMap());
    return ClientCache.getClient(typeEnum.getVal()).testCon(sourceDTO);
}
Also used : DataSourceTypeEnum(com.dtstack.taier.common.enums.DataSourceTypeEnum) JSONObject(com.alibaba.fastjson.JSONObject) IKerberos(com.dtstack.dtcenter.loader.client.IKerberos) ISourceDTO(com.dtstack.dtcenter.loader.dto.source.ISourceDTO)

Example 5 with DataSourceTypeEnum

use of com.dtstack.taier.common.enums.DataSourceTypeEnum in project Taier by DTStack.

the class DatasourceService method buildDsInfo.

/**
 * 构建数据源元数据对象
 * @param dataSourceVO
 * @return
 */
private DsInfo buildDsInfo(DataSourceVO dataSourceVO) {
    DsInfo dsInfo = new DsInfo();
    dsInfo.setDataType(dataSourceVO.getDataType());
    dsInfo.setDataVersion(dataSourceVO.getDataVersion());
    dsInfo.setDataName(dataSourceVO.getDataName());
    dsInfo.setDataDesc(dataSourceVO.getDataDesc());
    dsInfo.setStatus(1);
    dsInfo.setIsMeta(dataSourceVO.getIsMeta());
    dsInfo.setTenantId(dataSourceVO.getTenantId());
    dsInfo.setTenantId(dataSourceVO.getTenantId());
    dsInfo.setSchemaName(dataSourceVO.getSchemaName());
    DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(dataSourceVO.getDataType(), dataSourceVO.getDataVersion());
    dsInfo.setDataTypeCode(typeEnum.getVal());
    // dataJson
    if (Objects.nonNull(dataSourceVO.getDataJson())) {
        JSONObject dataJson = dataSourceVO.getDataJson();
        if (dataSourceVO.getDataType().equals(DataSourceTypeEnum.HBASE2.getDataType())) {
            // Hbase需要特殊处理
            JSONObject jsonObject = new JSONObject();
            jsonObject.put(FormNames.HBASE_ZK_QUORUM, dataJson.get(FormNames.HBASE_QUORUM));
            jsonObject.put(FormNames.HBASE_ZK_PARENT, dataJson.get(FormNames.HBASE_PARENT));
            dataJson.put("hbaseConfig", jsonObject);
        }
        JSONObject kerberos;
        if ((kerberos = dataJson.getJSONObject(DataSourceUtils.KERBEROS_CONFIG)) != null) {
            dataJson.put(DataSourceUtils.KERBEROS_FILE_TIMESTAMP, kerberos.getOrDefault(DataSourceUtils.KERBEROS_FILE_TIMESTAMP, System.currentTimeMillis()));
        }
        dsInfo.setDataJson(DataSourceUtils.getEncodeDataSource(dataJson, true));
        String linkInfo = getDataSourceLinkInfo(dataSourceVO.getDataType(), dataSourceVO.getDataVersion(), dataSourceVO.getDataJson());
        dsInfo.setLinkJson(DataSourceUtils.getEncodeDataSource(linkInfo, true));
    } else if (Strings.isNotBlank(dataSourceVO.getDataJsonString())) {
        JSONObject dataSourceJson = DataSourceUtils.getDataSourceJson(dataSourceVO.getDataJsonString());
        if (dataSourceVO.getDataType().equals(DataSourceTypeEnum.HBASE2.getDataType())) {
            // Hbase需要特殊处理
            JSONObject jsonObject = new JSONObject();
            jsonObject.put(FormNames.HBASE_QUORUM, dataSourceJson.get(FormNames.HBASE_QUORUM));
            jsonObject.put(FormNames.HBASE_ZK_PARENT, dataSourceJson.get(FormNames.HBASE_PARENT));
            dataSourceJson.put("hbaseConfig", jsonObject);
        }
        JSONObject kerberos;
        if ((kerberos = dataSourceJson.getJSONObject(DataSourceUtils.KERBEROS_CONFIG)) != null) {
            dataSourceJson.put(DataSourceUtils.KERBEROS_FILE_TIMESTAMP, kerberos.getOrDefault(DataSourceUtils.KERBEROS_FILE_TIMESTAMP, System.currentTimeMillis()));
        }
        dsInfo.setDataJson(DataSourceUtils.getEncodeDataSource(dataSourceJson, true));
        // 获取连接信息
        String linkInfo = getDataSourceLinkInfo(dataSourceVO.getDataType(), dataSourceVO.getDataVersion(), dataSourceJson);
        dsInfo.setLinkJson(DataSourceUtils.getEncodeDataSource(linkInfo, true));
    } else {
        throw new PubSvcDefineException(ErrorCode.DATASOURCE_CONF_ERROR);
    }
    return dsInfo;
}
Also used : DataSourceTypeEnum(com.dtstack.taier.common.enums.DataSourceTypeEnum) JSONObject(com.alibaba.fastjson.JSONObject) PubSvcDefineException(com.dtstack.taier.common.exception.PubSvcDefineException) DsInfo(com.dtstack.taier.dao.domain.DsInfo)

Aggregations

DataSourceTypeEnum (com.dtstack.taier.common.enums.DataSourceTypeEnum)9 JSONObject (com.alibaba.fastjson.JSONObject)8 PubSvcDefineException (com.dtstack.taier.common.exception.PubSvcDefineException)6 IKerberos (com.dtstack.dtcenter.loader.client.IKerberos)5 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)4 DsInfo (com.dtstack.taier.dao.domain.DsInfo)4 SftpException (com.jcraft.jsch.SftpException)4 IOException (java.io.IOException)4 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 Transactional (org.springframework.transaction.annotation.Transactional)2 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)1 DataSourceVO (com.dtstack.taier.develop.dto.devlop.DataSourceVO)1 File (java.io.File)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1