use of com.dtstack.taier.dao.domain.TenantComponent in project Taier by DTStack.
the class TenantService method initDataDevelop.
@Transactional(rollbackFor = Exception.class)
public void initDataDevelop(Long clusterId, Long tenantId, Long userId, String tenantName, String tenantDesc, List<ComponentBindDBDTO> bindDBDTOList) throws Exception {
// 初始化目录
List<Component> components = componentService.listAllComponents(clusterId);
List<ComponentVO> componentVOS = ComponentVO.toVOS(components);
batchCatalogueService.initCatalogue(tenantId, userId, componentVOS);
// 初始化数据源相关的信息
IComponentService componentService = null;
for (ComponentBindDBDTO componentBindDBDTO : bindDBDTOList) {
EComponentType eComponentType = EComponentType.getByCode(componentBindDBDTO.getComponentCode());
String componentIdentity = tenantName;
// db相关的操作
if (BooleanUtils.isTrue(componentBindDBDTO.getCreateFlag())) {
componentService = multiEngineServiceFactory.getComponentService(eComponentType.getTypeCode());
componentService.createDatabase(clusterId, eComponentType, componentIdentity, tenantDesc);
} else {
componentIdentity = componentBindDBDTO.getDbName();
}
// 初始化数据源
datasourceService.initDefaultSource(clusterId, eComponentType, tenantId, componentIdentity, tenantDesc, userId);
// 初始化租户引擎关系
TenantComponent tenantEngine = new TenantComponent();
tenantEngine.setTaskType(ComponentTypeToEScheduleJobMapping.getEScheduleTypeByComponentCode(eComponentType.getTypeCode()).getType());
tenantEngine.setTenantId(tenantId);
tenantEngine.setComponentIdentity(componentIdentity);
tenantEngine.setCreateUserId(userId);
tenantEngine.setStatus(0);
developTenantComponentService.insert(tenantEngine);
}
}
use of com.dtstack.taier.dao.domain.TenantComponent in project Taier by DTStack.
the class HadoopDataDownloadService method getSimpleSelectDownLoader.
/**
* 获取简单查询下载器
*
* @param tenantId 租户id
* @param sql 查询sql
* @param taskType 任务类型 仅支持sparkSql和hiveSql
* @return 简单查询结果下载器
*/
public IDownload getSimpleSelectDownLoader(Long tenantId, String sql, Integer taskType) {
Matcher matcher = BatchHadoopSelectSqlService.SIMPLE_QUERY_PATTERN.matcher(sql);
if (!matcher.find()) {
throw new RdosDefineException("该下载器仅支持简单查询结果下载");
}
// 查询字段集合
List<String> queryFieldNames = BatchHadoopSelectSqlService.getSimpleQueryFieldNames(sql, false);
// 字段别名集合
List<String> fieldNamesShow = BatchHadoopSelectSqlService.getSimpleQueryFieldNames(sql, true);
String db = matcher.group("db");
if (StringUtils.isEmpty(db)) {
TenantComponent tenantEngine = developTenantComponentService.getByTenantAndEngineType(tenantId, taskType);
Preconditions.checkNotNull(tenantEngine, String.format("项目:%d 不支持引擎:HADOOP", tenantId));
db = tenantEngine.getComponentIdentity();
}
String tableName = matcher.group("name");
return getSelectDownLoader(tenantId, queryFieldNames, fieldNamesShow, false, db, tableName, null, taskType);
}
use of com.dtstack.taier.dao.domain.TenantComponent in project Taier by DTStack.
the class BatchHadoopSelectSqlService method buildDataWithCheckTaskStatus.
/**
* 组装sql执行结果
*
* @param selectSql
* @param tenantId
* @param result
* @param status
* @return
* @throws Exception
*/
private boolean buildDataWithCheckTaskStatus(BatchSelectSql selectSql, Long tenantId, ExecuteResultVO result, Integer status) throws Exception {
if (TaskStatus.FINISHED.getStatus().equals(status)) {
if (TempJobType.INSERT.getType().equals(selectSql.getIsSelectSql()) || TempJobType.CREATE_AS.getType().equals(selectSql.getIsSelectSql())) {
return true;
}
TenantComponent tenantEngine = developTenantComponentService.getByTenantAndEngineType(tenantId, result.getTaskType());
Preconditions.checkNotNull(tenantEngine, String.format("tenant %d not support hadoop engine.", tenantId));
List<Object> data = hadoopDataDownloadService.queryDataFromTempTable(tenantId, selectSql.getTempTableName(), tenantEngine.getComponentIdentity());
result.setSqlText(selectSql.getSqlText());
result.setResult(data);
}
return false;
}
use of com.dtstack.taier.dao.domain.TenantComponent in project Taier by DTStack.
the class BatchSqlExeService method processSqlText.
/**
* 处理自定义函数 和 构建真正运行的SQL
*
* @param tenantId
* @param taskType
* @param sqlText
* @return
*/
public CheckSyntaxResult processSqlText(final Long tenantId, Integer taskType, final String sqlText) {
CheckSyntaxResult result = new CheckSyntaxResult();
TenantComponent tenantEngine = this.developTenantComponentService.getByTenantAndEngineType(tenantId, taskType);
Preconditions.checkNotNull(tenantEngine, String.format("tenantEngine %d not support task type %d", tenantId, taskType));
ISqlExeService sqlExeService = this.multiEngineServiceFactory.getSqlExeService(taskType);
// 处理自定义函数
String sqlPlus = buildCustomFunctionSparkSql(sqlText, tenantId, taskType);
// 构建真正运行的SQL,去掉注释,加上use db 同时格式化SQL
String sqls = sqlExeService.process(sqlPlus, tenantEngine.getComponentIdentity());
result.setSql(sqls);
result.setCheckResult(true);
return result;
}
use of com.dtstack.taier.dao.domain.TenantComponent 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;
}
Aggregations