Search in sources :

Example 1 with IKerberos

use of com.dtstack.dtcenter.loader.client.IKerberos 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 2 with IKerberos

use of com.dtstack.dtcenter.loader.client.IKerberos in project Taier by DTStack.

the class BatchTaskService method handleKerberos.

/**
 * kerberos配置预处理、替换相对路径为绝对路径等操作
 *
 * @param sourceType
 * @param kerberosMap
 * @param localKerberosConf
 * @return
 */
private Map<String, Object> handleKerberos(Integer sourceType, Map<String, Object> kerberosMap, String localKerberosConf) {
    IKerberos kerberos = ClientCache.getKerberos(sourceType);
    HashMap<String, Object> tmpKerberosConfig = new HashMap<>(kerberosMap);
    try {
        kerberos.prepareKerberosForConnect(tmpKerberosConfig, localKerberosConf);
    } catch (Exception e) {
        throw new RdosDefineException("common-loader中kerberos配置文件处理失败", e);
    }
    return tmpKerberosConfig;
}
Also used : HashMap(java.util.HashMap) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IKerberos(com.dtstack.dtcenter.loader.client.IKerberos) JSONObject(com.alibaba.fastjson.JSONObject) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException)

Example 3 with IKerberos

use of com.dtstack.dtcenter.loader.client.IKerberos 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 IKerberos

use of com.dtstack.dtcenter.loader.client.IKerberos 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 IKerberos

use of com.dtstack.dtcenter.loader.client.IKerberos in project Taier by DTStack.

the class DatasourceService method checkConnectionWithKerberos.

/**
 * 检测kerberos认证的数据源连通性
 * @param source
 * @param resource
 * @param projectId
 * @param userId
 * @return
 */
public Boolean checkConnectionWithKerberos(DataSourceVO source, Pair<String, String> resource, Long projectId, Long userId) {
    Map<String, Object> kerberosConfig;
    String localKerberosPath;
    DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(source.getDataType(), source.getDataVersion());
    IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
    if (Objects.nonNull(resource)) {
        localKerberosPath = kerberosService.getTempLocalKerberosConf(userId);
        try {
            kerberosConfig = kerberos.parseKerberosFromUpload(resource.getRight(), localKerberosPath);
        } catch (IOException e) {
            LOGGER.error("检测连通性, kerberos config 解析异常,{}", e.getMessage(), e);
            throw new PubSvcDefineException(String.format("kerberos config 解析异常,Caused by: %s", e.getMessage()), e);
        }
    } else {
        localKerberosPath = kerberosService.getLocalKerberosPath(source.getId());
        kerberosConfig = fillKerberosConfig(source.getId());
    }
    try {
        source.setDataJson(DataSourceUtils.getDataSourceJson(source.getDataJsonString()));
    } catch (Exception e) {
        LOGGER.error("检查数据源连接,DataJsonString 转化异常", e);
        throw new PubSvcDefineException("JSONObject 转化异常", e);
    }
    // 设置前台传入的principals
    setPrincipals(source.getDataJson(), kerberosConfig);
    return checkConnectionWithConf(source, kerberosConfig, localKerberosPath);
}
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) 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)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)6 IKerberos (com.dtstack.dtcenter.loader.client.IKerberos)6 DataSourceTypeEnum (com.dtstack.taier.common.enums.DataSourceTypeEnum)5 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)4 IOException (java.io.IOException)4 PubSvcDefineException (com.dtstack.taier.common.exception.PubSvcDefineException)3 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 SftpException (com.jcraft.jsch.SftpException)3 HashMap (java.util.HashMap)2 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)1 DsInfo (com.dtstack.taier.dao.domain.DsInfo)1 LinkedHashMap (java.util.LinkedHashMap)1