Search in sources :

Example 1 with TenantComponent

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);
    }
}
Also used : IComponentService(com.dtstack.taier.develop.service.develop.IComponentService) ComponentVO(com.dtstack.taier.scheduler.vo.ComponentVO) TenantComponent(com.dtstack.taier.dao.domain.TenantComponent) Component(com.dtstack.taier.dao.domain.Component) TenantComponent(com.dtstack.taier.dao.domain.TenantComponent) EComponentType(com.dtstack.taier.common.enums.EComponentType) ComponentBindDBDTO(com.dtstack.taier.develop.dto.devlop.ComponentBindDBDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with TenantComponent

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);
}
Also used : Matcher(java.util.regex.Matcher) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) TenantComponent(com.dtstack.taier.dao.domain.TenantComponent)

Example 3 with TenantComponent

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;
}
Also used : TenantComponent(com.dtstack.taier.dao.domain.TenantComponent) JSONObject(com.alibaba.fastjson.JSONObject)

Example 4 with TenantComponent

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;
}
Also used : ISqlExeService(com.dtstack.taier.develop.service.develop.ISqlExeService) TenantComponent(com.dtstack.taier.dao.domain.TenantComponent) CheckSyntaxResult(com.dtstack.taier.develop.dto.devlop.CheckSyntaxResult)

Example 5 with TenantComponent

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;
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) TenantComponent(com.dtstack.taier.dao.domain.TenantComponent)

Aggregations

TenantComponent (com.dtstack.taier.dao.domain.TenantComponent)8 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)4 ParseResult (com.dtstack.taier.develop.sql.ParseResult)3 ExecuteResultVO (com.dtstack.taier.develop.dto.devlop.ExecuteResultVO)2 List (java.util.List)2 JSONObject (com.alibaba.fastjson.JSONObject)1 DataSourceType (com.dtstack.taier.common.enums.DataSourceType)1 EComponentType (com.dtstack.taier.common.enums.EComponentType)1 Component (com.dtstack.taier.dao.domain.Component)1 BuildSqlVO (com.dtstack.taier.develop.dto.devlop.BuildSqlVO)1 CheckSyntaxResult (com.dtstack.taier.develop.dto.devlop.CheckSyntaxResult)1 ComponentBindDBDTO (com.dtstack.taier.develop.dto.devlop.ComponentBindDBDTO)1 ExecuteSqlParseVO (com.dtstack.taier.develop.dto.devlop.ExecuteSqlParseVO)1 SqlResultVO (com.dtstack.taier.develop.dto.devlop.SqlResultVO)1 IComponentService (com.dtstack.taier.develop.service.develop.IComponentService)1 ISqlExeService (com.dtstack.taier.develop.service.develop.ISqlExeService)1 SqlParserImpl (com.dtstack.taier.develop.sql.SqlParserImpl)1 ComponentVO (com.dtstack.taier.scheduler.vo.ComponentVO)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1