Search in sources :

Example 1 with EComponentType

use of com.dtstack.taier.common.enums.EComponentType in project Taier by DTStack.

the class ConsoleComponentService method checkStoresComponent.

private EComponentType checkStoresComponent(Long clusterId, Integer storeType) {
    // 默认为hdfs
    if (null == storeType) {
        return EComponentType.HDFS;
    }
    EComponentType componentType = EComponentType.getByCode(MathUtil.getIntegerVal(storeType));
    Component storeComponent = componentMapper.getByClusterIdAndComponentType(clusterId, componentType.getTypeCode(), null, null);
    if (null == storeComponent) {
        throw new RdosDefineException(ErrorCode.PRE_COMPONENT_NOT_EXISTS.getMsg() + ":" + componentType.getName());
    }
    return componentType;
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) EComponentType(com.dtstack.taier.common.enums.EComponentType)

Example 2 with EComponentType

use of com.dtstack.taier.common.enums.EComponentType in project Taier by DTStack.

the class ConsoleComponentService method downloadFile.

/**
 * 下载文件
 *
 * @param componentId
 * @param downloadType 0:kerberos配置文件 1:配置文件 2:模板文件
 * @return
 */
public File downloadFile(Long componentId, Integer downloadType, Integer componentType, String versionName, Long clusterId, Integer deployType) {
    String localDownLoadPath = "";
    String uploadFileName = "";
    if (null == componentId) {
        EComponentType type = EComponentType.getByCode(componentType);
        // 解析模版中的信息 作为默认值 返回json
        List<ClientTemplate> clientTemplates = this.loadTemplate(clusterId, type, versionName, null, deployType);
        if (CollectionUtils.isNotEmpty(clientTemplates)) {
            Map<String, Object> fileMap = ComponentConfigUtils.convertClientTemplateToMap(clientTemplates);
            uploadFileName = EComponentType.getByCode(componentType).name() + ".json";
            localDownLoadPath = USER_DIR_DOWNLOAD + File.separator + uploadFileName;
            try {
                FileUtils.write(new File(localDownLoadPath), JSONObject.toJSONString(fileMap));
            } catch (Exception e) {
                throw new RdosDefineException("file does not exist");
            }
        }
    } else {
        Component component = componentMapper.selectById(componentId);
        if (null == component) {
            throw new RdosDefineException("Component does not exist");
        }
        SftpConfig sftpConfig = componentService.getComponentByClusterId(clusterId, EComponentType.SFTP.getTypeCode(), false, SftpConfig.class, null);
        if (null == sftpConfig) {
            throw new RdosDefineException("sftp component does not exist");
        }
        localDownLoadPath = USER_DIR_DOWNLOAD + File.separator + component.getComponentName();
        String remoteDir = sftpConfig.getPath() + File.separator + this.buildSftpPath(clusterId, component.getComponentTypeCode());
        SftpFileManage sftpFileManage = null;
        if (DownloadType.Kerberos.getCode() == downloadType) {
            remoteDir = remoteDir + File.separator + KERBEROS;
            localDownLoadPath = localDownLoadPath + File.separator + KERBEROS;
            sftpFileManage = SftpFileManage.getSftpManager(sftpConfig);
            sftpFileManage.downloadDir(remoteDir, localDownLoadPath);
        } else {
            if (StringUtils.isBlank(component.getUploadFileName())) {
                // 一种是  全部手动填写的 如flink
                EComponentType type = EComponentType.getByCode(componentType);
                String componentConfig = componentService.getComponentByClusterId(clusterId, type.getTypeCode(), true, String.class, component.getVersionValue());
                try {
                    localDownLoadPath = localDownLoadPath + ".json";
                    FileUtils.write(new File(localDownLoadPath), filterConfigMessage(componentConfig));
                } catch (IOException e) {
                    LOGGER.error("write upload file {} error", componentConfig, e);
                }
            } else {
                sftpFileManage = SftpFileManage.getSftpManager(sftpConfig);
                // 一种是 上传配置文件的需要到sftp下载
                sftpFileManage.downloadDir(remoteDir + File.separator + component.getUploadFileName(), localDownLoadPath);
            }
        }
        uploadFileName = component.getUploadFileName();
    }
    File file = new File(localDownLoadPath);
    if (!file.exists()) {
        throw new RdosDefineException("file does not exist");
    }
    String zipFilename = StringUtils.isBlank(uploadFileName) ? "download.zip" : uploadFileName;
    if (file.isDirectory()) {
        // 将文件夹压缩成zip文件
        return zipFile(componentId, downloadType, componentType, file, zipFilename);
    } else {
        return new File(localDownLoadPath);
    }
}
Also used : SftpFileManage(com.dtstack.taier.pluginapi.sftp.SftpFileManage) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate) SftpConfig(com.dtstack.taier.pluginapi.sftp.SftpConfig) IOException(java.io.IOException) EComponentType(com.dtstack.taier.common.enums.EComponentType) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File)

Example 3 with EComponentType

use of com.dtstack.taier.common.enums.EComponentType in project Taier by DTStack.

the class ConsoleComponentService method refreshVersion.

/**
 * yarn组件版本变更之后  hdfs组件保存一致
 * 计算组件 如flink的typename也同步变更
 *
 * @param componentType
 * @param clusterId
 * @param addComponent
 * @param dbHadoopVersion 形如 3.1.1
 */
public void refreshVersion(EComponentType componentType, Long clusterId, Component addComponent, String dbHadoopVersion) {
    if (!EComponentType.YARN.equals(componentType)) {
        return;
    }
    if (addComponent.getVersionValue().equals(dbHadoopVersion)) {
        return;
    }
    List<Component> components = componentMapper.listByClusterId(clusterId, null, false);
    PartCluster partCluster = clusterFactory.newImmediatelyLoadCluster(clusterId);
    for (Component component : components) {
        EComponentType eComponentType = EComponentType.getByCode(component.getComponentTypeCode());
        if (!EComponentType.typeComponentVersion.contains(eComponentType)) {
            continue;
        }
        EComponentType storeComponentType = EComponentType.getByCode(component.getStoreType());
        Part part = partCluster.create(eComponentType, component.getVersionName(), storeComponentType, component.getDeployType());
        String pluginName = part.getPluginName();
        ComponentConfig typeNameComponentConfig = componentConfigService.getComponentConfigByKey(component.getId(), TYPE_NAME_KEY);
        if (null != typeNameComponentConfig && StringUtils.isNotBlank(pluginName)) {
            LOGGER.info("refresh clusterId {} component {} typeName {} to {}", component.getClusterId(), component.getComponentName(), typeNameComponentConfig.getValue(), pluginName);
            typeNameComponentConfig.setValue(pluginName);
            componentConfigService.updateValueComponentConfig(typeNameComponentConfig);
        }
    }
}
Also used : PartCluster(com.dtstack.taier.develop.model.PartCluster) Part(com.dtstack.taier.develop.model.Part) EComponentType(com.dtstack.taier.common.enums.EComponentType)

Example 4 with EComponentType

use of com.dtstack.taier.common.enums.EComponentType 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 5 with EComponentType

use of com.dtstack.taier.common.enums.EComponentType in project Taier by DTStack.

the class TenantService method checkClusterCanUse.

public void checkClusterCanUse(String clusterName) throws Exception {
    List<ComponentMultiTestResult> testConnectionVO = consoleComponentService.testConnects(clusterName);
    boolean canUse = true;
    StringBuilder msg = new StringBuilder();
    msg.append("此集群不可用,测试连通性为通过:\n");
    for (ComponentMultiTestResult testResult : testConnectionVO) {
        EComponentType componentType = EComponentType.getByCode(testResult.getComponentTypeCode());
        if (!EComponentType.notCheckComponent.contains(componentType) && !testResult.getResult()) {
            canUse = false;
            msg.append("组件:").append(componentType.getName()).append(" ").append(JSON.toJSONString(testResult.getErrorMsg())).append("\n");
        }
    }
    if (!canUse) {
        throw new RdosDefineException(msg.toString());
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ComponentMultiTestResult(com.dtstack.taier.scheduler.impl.pojo.ComponentMultiTestResult) EComponentType(com.dtstack.taier.common.enums.EComponentType)

Aggregations

EComponentType (com.dtstack.taier.common.enums.EComponentType)23 JSONObject (com.alibaba.fastjson.JSONObject)10 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)10 Component (com.dtstack.taier.dao.domain.Component)9 ComponentVO (com.dtstack.taier.scheduler.vo.ComponentVO)4 EScheduleJobType (com.dtstack.taier.common.enums.EScheduleJobType)3 Part (com.dtstack.taier.develop.model.Part)3 PartCluster (com.dtstack.taier.develop.model.PartCluster)3 EComponentScheduleType (com.dtstack.taier.common.enums.EComponentScheduleType)2 Cluster (com.dtstack.taier.dao.domain.Cluster)2 Dict (com.dtstack.taier.dao.domain.Dict)2 KerberosConfig (com.dtstack.taier.dao.domain.KerberosConfig)2 IComponentService (com.dtstack.taier.develop.service.develop.IComponentService)2 ClientTemplate (com.dtstack.taier.scheduler.impl.pojo.ClientTemplate)2 IComponentVO (com.dtstack.taier.scheduler.vo.IComponentVO)2 Map (java.util.Map)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)1 Strings (com.dtstack.taier.common.util.Strings)1 com.dtstack.taier.dao.domain (com.dtstack.taier.dao.domain)1