Search in sources :

Example 1 with DsInfo

use of com.dtstack.taier.dao.domain.DsInfo in project Taier by DTStack.

the class DsInfoService method dsInfoDetail.

/**
 * 根据数据源Id获取数据源详情
 *
 * @param dataInfoId
 * @return
 */
public DsDetailVO dsInfoDetail(Long dataInfoId) {
    DsInfo dsInfo = lambdaQuery().eq(DsInfo::getId, dataInfoId).one();
    DsDetailVO dsDetailVO = DsDetailTransfer.INSTANCE.toInfoVO(dsInfo);
    String dataJson = dsInfo.getDataJson();
    JSONObject dataSourceJson = DataSourceUtils.getDataSourceJson(dataJson);
    if (DataSourceUtils.judgeOpenKerberos(dataJson) && null == dataSourceJson.getString(FormNames.PRINCIPAL)) {
        JSONObject kerberosConfig = dataSourceJson.getJSONObject(FormNames.KERBEROS_CONFIG);
        dataSourceJson.put(FormNames.PRINCIPAL, kerberosConfig.getString(FormNames.PRINCIPAL));
    }
    if (DataSourceUtils.judgeOpenKerberos(dsInfo.getDataJson()) && dsInfo.getDataType().equals(DataSourceTypeEnum.KAFKA.getDataType())) {
        // kafka开启了kerberos认证
        dataSourceJson.put(FormNames.AUTHENTICATION, FormNames.KERBROS);
    }
    return dsDetailVO;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DsDetailVO(com.dtstack.taier.develop.vo.datasource.DsDetailVO) DsInfo(com.dtstack.taier.dao.domain.DsInfo)

Example 2 with DsInfo

use of com.dtstack.taier.dao.domain.DsInfo 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 DsInfo

use of com.dtstack.taier.dao.domain.DsInfo in project Taier by DTStack.

the class DatasourceService method fillKerberosConfig.

/**
 * 根据已有数据源主键填充confMap
 * @param sourceId
 * @return
 */
public Map<String, Object> fillKerberosConfig(Long sourceId) {
    DsInfo dataSource = dsInfoService.getOneById(sourceId);
    Long tenantId = dataSource.getTenantId();
    // 获取Kerberos客户端
    JSONObject kerberosConfig = DataSourceUtils.getOriginKerberosConfig(dataSource.getDataJson(), false);
    if (MapUtils.isEmpty(kerberosConfig)) {
        return Collections.emptyMap();
    }
    try {
        // 获取kerberos本地路径
        String localKerberosConf = kerberosService.getLocalKerberosPath(sourceId);
        kerberosService.downloadKerberosFromSftp(dataSource.getIsMeta(), sourceId, DataSourceUtils.getDataSourceJson(dataSource.getDataJson()), localKerberosConf, tenantId);
    } catch (SftpException e) {
        throw new DtCenterDefException(String.format("获取kerberos认证文件失败,Caused by: %s", e.getMessage()), e);
    }
    return kerberosConfig;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) SftpException(com.jcraft.jsch.SftpException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) DsInfo(com.dtstack.taier.dao.domain.DsInfo)

Example 4 with DsInfo

use of com.dtstack.taier.dao.domain.DsInfo 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)

Example 5 with DsInfo

use of com.dtstack.taier.dao.domain.DsInfo in project Taier by DTStack.

the class DatasourceService method getOne.

public BatchDataSource getOne(Long id) {
    DsInfo dsInfo = dsInfoService.getOneById(id);
    BatchDataSource batchDataSource = new BatchDataSource();
    BeanUtils.copyProperties(dsInfo, batchDataSource);
    batchDataSource.setType(dsInfo.getDataTypeCode());
    batchDataSource.setIsDefault(dsInfo.getIsMeta());
    return batchDataSource;
}
Also used : BatchDataSource(com.dtstack.taier.dao.domain.BatchDataSource) DsInfo(com.dtstack.taier.dao.domain.DsInfo)

Aggregations

DsInfo (com.dtstack.taier.dao.domain.DsInfo)8 JSONObject (com.alibaba.fastjson.JSONObject)7 PubSvcDefineException (com.dtstack.taier.common.exception.PubSvcDefineException)5 DataSourceTypeEnum (com.dtstack.taier.common.enums.DataSourceTypeEnum)4 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)3 SftpException (com.jcraft.jsch.SftpException)3 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)2 IOException (java.io.IOException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 IKerberos (com.dtstack.dtcenter.loader.client.IKerberos)1 BatchDataSource (com.dtstack.taier.dao.domain.BatchDataSource)1 DsDetailVO (com.dtstack.taier.develop.vo.datasource.DsDetailVO)1 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1