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);
}
}
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;
}
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");
}
}
}
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;
}
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;
}
Aggregations