Search in sources :

Example 21 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException in project Taier by DTStack.

the class TimeParamOperator method doFormatFunction.

/**
 * 处理 format 函数
 * @param line
 * @param cycTime
 * @return
 */
private static String doFormatFunction(String line, String cycTime) {
    Matcher formattedMatch = FORMAT_PATTERN.matcher(line);
    if (!formattedMatch.find()) {
        throw new DtCenterDefException("illegal command " + line);
    }
    // 获取需要处理的属性
    String format = formattedMatch.group("format");
    Boolean operate = "+".equals(formattedMatch.group("operate"));
    Integer number = StringUtils.isBlank(formattedMatch.group("number")) ? 0 : Integer.valueOf(formattedMatch.group("number"));
    String unit = formattedMatch.group("unit");
    String formatResult = formattedMatch.group("formatResult");
    return doFormatFunctionCyctime(cycTime, operate, number, unit, formatResult);
}
Also used : Matcher(java.util.regex.Matcher) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException)

Example 22 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException in project Taier by DTStack.

the class SFTPHandler method deleteDir.

public void deleteDir(String ftpPath) {
    try {
        channelSftp.cd(ftpPath);
    } catch (SftpException e) {
        logger.info("", e);
        return;
    }
    try {
        Vector files = channelSftp.ls(ftpPath);
        for (Iterator<ChannelSftp.LsEntry> iterator = files.iterator(); iterator.hasNext(); ) {
            ChannelSftp.LsEntry str = iterator.next();
            String filename = str.getFilename();
            if (".".equals(filename) || "..".equals(filename)) {
                continue;
            }
            SftpATTRS attrs = str.getAttrs();
            if (attrs.isDir()) {
                deleteDir(ftpPath + "/" + filename);
            } else {
                channelSftp.rm(ftpPath + "/" + filename);
            }
        }
        if (channelSftp.ls(ftpPath).size() == 2) {
            channelSftp.rmdir(ftpPath);
        }
    } catch (SftpException e) {
        logger.error("", e);
        throw new DtCenterDefException("删除sftp路径失败,sftpPath=" + ftpPath);
    }
}
Also used : DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) Vector(java.util.Vector)

Example 23 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException 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 24 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException in project Taier by DTStack.

the class KerberosService method prepareKerberosConfig.

/**
 * 预处理Kerberos配置
 */
public void prepareKerberosConfig(DsInfoBO dsInfoBO) {
    if (dsInfoBO.getKerberosConfig() == null) {
        return;
    }
    try {
        // 获取kerberos本地路径
        String localKerberosConf = getLocalKerberosPath(dsInfoBO.getId());
        downloadKerberosFromSftp(dsInfoBO.getIsMeta(), dsInfoBO.getId(), DataSourceUtils.getDataSourceJson(dsInfoBO.getDataJson()), localKerberosConf, dsInfoBO.getTenantId());
    } catch (SftpException e) {
        throw new DtCenterDefException(String.format("获取kerberos认证文件失败,Caused by: %s", e.getMessage()), e);
    }
    String localKerberosPath = getLocalKerberosPath(dsInfoBO.getId());
    JSONObject dataJson = dsInfoBO.getData();
    // principal 键
    String principal = dataJson.getString(FormNames.PRINCIPAL);
    Map<String, Object> kerberosConfig = dsInfoBO.getKerberosConfig();
    if (Strings.isNotBlank(principal)) {
        kerberosConfig.put(HadoopConfTool.PRINCIPAL, principal);
    }
    // Hbase master kerberos Principal
    String hbaseMasterPrincipal = dataJson.getString(FormNames.HBASE_MASTER_PRINCIPAL);
    if (Strings.isNotBlank(hbaseMasterPrincipal)) {
        kerberosConfig.put(HadoopConfTool.HBASE_MASTER_PRINCIPAL, hbaseMasterPrincipal);
    }
    // Hbase region kerberos Principal
    String hbasePrincipal = dataJson.getString(FormNames.HBASE_REGION_PRINCIPAL);
    if (Strings.isNotBlank(hbasePrincipal)) {
        kerberosConfig.put(HadoopConfTool.HBASE_REGION_PRINCIPAL, hbasePrincipal);
    }
    DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(dsInfoBO.getDataType(), dsInfoBO.getDataVersion());
    IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
    kerberos.prepareKerberosForConnect(kerberosConfig, localKerberosPath);
    dsInfoBO.setKerberosConfig(kerberosConfig);
}
Also used : DataSourceTypeEnum(com.dtstack.taier.common.enums.DataSourceTypeEnum) JSONObject(com.alibaba.fastjson.JSONObject) SftpException(com.jcraft.jsch.SftpException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) JSONObject(com.alibaba.fastjson.JSONObject) IKerberos(com.dtstack.dtcenter.loader.client.IKerberos)

Example 25 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException in project Taier by DTStack.

the class KerberosConfigVerify method parseConfMap.

@Deprecated
public static Map<String, Map<String, String>> parseConfMap(List<File> unzipFileList, String unZipLocation) throws Exception {
    Map<String, File> confFileMap = new HashMap<>();
    List<File> xmlFileList = new ArrayList<>();
    filterXml(unzipFileList, unZipLocation, xmlFileList, confFileMap);
    Map<String, Map<String, String>> confMap = null;
    if (CollectionUtils.isNotEmpty(xmlFileList)) {
        try {
            confMap = parseAndRead(xmlFileList);
        } catch (Exception e) {
            logger.error("{}", e);
            throw new DtCenterDefException("配置文件解析失败");
        }
    }
    return confMap;
}
Also used : DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) File(java.io.File) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SftpException(com.jcraft.jsch.SftpException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException)

Aggregations

DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)26 IOException (java.io.IOException)11 JSONObject (com.alibaba.fastjson.JSONObject)7 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)7 SftpException (com.jcraft.jsch.SftpException)6 IHdfsFile (com.dtstack.dtcenter.loader.client.IHdfsFile)5 HdfsSourceDTO (com.dtstack.dtcenter.loader.dto.source.HdfsSourceDTO)5 UnknownHostException (java.net.UnknownHostException)5 Matcher (java.util.regex.Matcher)4 ArrayList (java.util.ArrayList)3 IClient (com.dtstack.dtcenter.loader.client.IClient)2 IKerberos (com.dtstack.dtcenter.loader.client.IKerberos)2 ColumnMetaDTO (com.dtstack.dtcenter.loader.dto.ColumnMetaDTO)2 SqlQueryDTO (com.dtstack.dtcenter.loader.dto.SqlQueryDTO)2 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)2 DataSourceTypeEnum (com.dtstack.taier.common.enums.DataSourceTypeEnum)2 PubSvcDefineException (com.dtstack.taier.common.exception.PubSvcDefineException)2 DsInfo (com.dtstack.taier.dao.domain.DsInfo)2 File (java.io.File)2 HttpEntity (org.apache.http.HttpEntity)2