Search in sources :

Example 91 with RdosDefineException

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

the class BatchSparkHiveSqlExeService method executeCreateTableSql.

/**
 * 执行create语句
 *
 * @param parseResult
 * @param tenantId
 * @param db
 * @param eScheduleJobType
 */
protected void executeCreateTableSql(ParseResult parseResult, Long tenantId, String db, EScheduleJobType eScheduleJobType) {
    Connection connection = null;
    try {
        connection = jdbcServiceImpl.getConnection(tenantId, null, eScheduleJobType, db);
        jdbcServiceImpl.executeQueryWithoutResult(tenantId, null, eScheduleJobType, db, String.format("set hive.default.fileformat=%s", environmentContext.getCreateTableType()), connection);
        parseResult.getMainTable().setStoreType(environmentContext.getCreateTableType());
        jdbcServiceImpl.executeQueryWithoutResult(tenantId, null, eScheduleJobType, db, parseResult.getStandardSql(), connection);
    } catch (Exception e) {
        throw new RdosDefineException(ErrorCode.CREATE_TABLE_ERR, e);
    } finally {
        DBUtil.closeDBResources(null, null, connection);
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Connection(java.sql.Connection) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 92 with RdosDefineException

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

the class BatchSqlExeService method getDbName.

private String getDbName(final ExecuteContent executeContent) {
    if (StringUtils.isNotBlank(executeContent.getDatabase())) {
        return executeContent.getDatabase();
    }
    TenantComponent tenantEngine = this.developTenantComponentService.getByTenantAndEngineType(executeContent.getTenantId(), executeContent.getTaskType());
    if (Objects.isNull(tenantEngine)) {
        throw new RdosDefineException("引擎不能为空");
    }
    String dbName = tenantEngine.getComponentIdentity();
    executeContent.setDatabase(dbName);
    return dbName;
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) TenantComponent(com.dtstack.taier.dao.domain.TenantComponent)

Example 93 with RdosDefineException

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

the class DatasourceService method setWriterJson.

/**
 * 设置write属性
 *
 * @param map
 * @param taskId
 * @param tenantId
 * @param isFilter 是否过滤账号密码
 * @throws Exception
 */
public void setWriterJson(Map<String, Object> map, Long taskId, Long tenantId, boolean isFilter) throws Exception {
    if (map.get("sourceId") == null) {
        throw new RdosDefineException(ErrorCode.DATA_SOURCE_NOT_SET);
    }
    Long sourceId = Long.parseLong(map.get("sourceId").toString());
    BatchDataSource source = getOne(sourceId);
    Map<String, Object> kerberos = fillKerberosConfig(sourceId);
    map.put("sourceIds", Arrays.asList(sourceId));
    map.put("source", source);
    JSONObject json = JSON.parseObject(source.getDataJson());
    map.put("dataSourceType", source.getType());
    Integer sourceType = source.getType();
    // 根据jdbc信息 替换map中的信息
    replaceJdbcInfoByDataJsonToMap(map, sourceId, source, tenantId, json, sourceType);
    if (DataSourceType.Kudu.getVal().equals(sourceType)) {
        syncBuilderFactory.getSyncBuilder(DataSourceType.Kudu.getVal()).setWriterJson(map, json, kerberos);
        setSftpConfig(sourceId, json, tenantId, map, HADOOP_CONFIG);
    }
    if (DataSourceType.IMPALA.getVal().equals(sourceType)) {
        syncBuilderFactory.getSyncBuilder(DataSourceType.IMPALA.getVal()).setWriterJson(map, json, kerberos);
        setSftpConfig(sourceId, json, tenantId, map, HADOOP_CONFIG);
    }
    if (isFilter) {
        map.remove("username");
        map.remove("password");
        // S3数据源不需要移除 accessKey
        if (!DataSourceType.AWS_S3.getVal().equals(sourceType)) {
            map.remove("accessKey");
        }
    }
}
Also used : BatchDataSource(com.dtstack.taier.dao.domain.BatchDataSource) JSONObject(com.alibaba.fastjson.JSONObject) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) JSONObject(com.alibaba.fastjson.JSONObject)

Example 94 with RdosDefineException

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

the class DatasourceService method preview.

/**
 * 数据同步-获得预览数据,默认展示3条
 *
 * @param sourceId  数据源id
 * @param tableName 表名
 * @return
 * @author toutian
 */
public JSONObject preview(Long sourceId, String tableName, String schema) {
    BatchDataSource source = getOne(sourceId);
    StringBuffer newTableName = new StringBuffer();
    if (DataSourceType.SQLServer.getVal().equals(source.getType()) && StringUtils.isNotBlank(tableName)) {
        if (tableName.indexOf("[") == -1) {
            final String[] tableNames = tableName.split("\\.");
            for (final String name : tableNames) {
                newTableName.append("[").append(name).append("]").append(".");
            }
            tableName = newTableName.substring(0, newTableName.length() - 1);
        }
    }
    String dataJson = source.getDataJson();
    JSONObject json = JSON.parseObject(dataJson);
    // 获取字段信息
    List<String> columnList = new ArrayList<String>();
    // 获取数据
    List<List<String>> dataList = new ArrayList<List<String>>();
    try {
        Map<String, Object> kerberosConfig = fillKerberosConfig(source.getId());
        List<JSONObject> columnJson = getTableColumn(source, tableName, schema);
        if (CollectionUtils.isNotEmpty(columnJson)) {
            for (JSONObject columnMetaDTO : columnJson) {
                columnList.add(columnMetaDTO.getString("key"));
            }
        }
        IClient iClient = ClientCache.getClient(source.getType());
        ISourceDTO iSourceDTO = SourceDTOType.getSourceDTO(json, source.getType(), kerberosConfig, Maps.newHashMap());
        SqlQueryDTO sqlQueryDTO = SqlQueryDTO.builder().schema(schema).tableName(tableName).previewNum(3).build();
        dataList = iClient.getPreview(iSourceDTO, sqlQueryDTO);
        if (DataSourceType.getRDBMS().contains(source.getType())) {
            // 因为会把字段名也会返回 所以要去除第一行
            dataList = dataList.subList(1, dataList.size());
        }
    } catch (Exception e) {
        LOGGER.error("datasource preview end with error.", e);
        throw new RdosDefineException(String.format("%s获取预览数据失败", source.getDataName()), e);
    }
    JSONObject preview = new JSONObject(2);
    preview.put("columnList", columnList);
    preview.put("dataList", dataList);
    return preview;
}
Also used : BatchDataSource(com.dtstack.taier.dao.domain.BatchDataSource) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ArrayList(java.util.ArrayList) IClient(com.dtstack.dtcenter.loader.client.IClient) 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) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(com.alibaba.fastjson.JSONObject) SqlQueryDTO(com.dtstack.dtcenter.loader.dto.SqlQueryDTO) ISourceDTO(com.dtstack.dtcenter.loader.dto.source.ISourceDTO)

Example 95 with RdosDefineException

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

the class HadoopDataDownloadService method typeLogDownloader.

@Override
public IDownload typeLogDownloader(Long tenantId, String jobId, Integer limitNum, String logType) {
    String applicationId = batchJobService.getApplicationId(jobId);
    if (StringUtils.isBlank(applicationId)) {
        throw new RdosDefineException("任务尚未执行完成或提交失败,请稍后再试");
    }
    IDownload iDownload = null;
    try {
        iDownload = RetryUtil.executeWithRetry(() -> {
            final Map<String, Object> hadoopConf = Engine2DTOService.getHdfs(tenantId);
            JSONObject yarnConf = Engine2DTOService.getComponentConfig(tenantId, EComponentType.YARN);
            String submitUserName = getSubmitUserNameByJobId(jobId);
            final LogPluginDownload downloader = new LogPluginDownload(applicationId, yarnConf, hadoopConf, submitUserName, limitNum);
            downloader.configure();
            return downloader;
        }, 3, 1000L, false);
    } catch (Exception e) {
        throw new RdosDefineException(String.format("typeLogDownloader 失败,原因是:%s", e.getMessage()), e);
    }
    return iDownload;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) LogPluginDownload(com.dtstack.taier.develop.utils.develop.hive.service.LogPluginDownload) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IDownload(com.dtstack.taier.develop.utils.develop.common.IDownload) Map(java.util.Map) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Aggregations

RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)176 JSONObject (com.alibaba.fastjson.JSONObject)80 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)20 EComponentType (com.dtstack.taier.common.enums.EComponentType)18 List (java.util.List)18 JSONArray (com.alibaba.fastjson.JSONArray)17 File (java.io.File)16 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)15 Transactional (org.springframework.transaction.annotation.Transactional)15 BatchTask (com.dtstack.taier.dao.domain.BatchTask)14 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)13 Map (java.util.Map)13 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)10 Component (com.dtstack.taier.dao.domain.Component)10 Resource (com.dtstack.taier.dao.dto.Resource)10 HashMap (java.util.HashMap)10 CollectionUtils (org.apache.commons.collections.CollectionUtils)10 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)9 BatchCatalogue (com.dtstack.taier.dao.domain.BatchCatalogue)9