Search in sources :

Example 1 with PartCluster

use of com.dtstack.taier.develop.model.PartCluster 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 2 with PartCluster

use of com.dtstack.taier.develop.model.PartCluster in project Taier by DTStack.

the class ConsoleComponentService method loadTemplate.

/**
 * 加载各个组件的默认值
 * 解析yml文件转换为前端渲染格式
 *
 * @param componentType 组件类型
 * @param clusterId   集群ID
 * @param versionName  组件版本名 如Hadoop 2.x
 * @param storeType  存储组件type 如 HDFS
 * @return
 */
public List<ClientTemplate> loadTemplate(Long clusterId, EComponentType componentType, String versionName, EComponentType storeType, Integer deployType) {
    PartCluster cluster = clusterFactory.newImmediatelyLoadCluster(clusterId);
    Part part = cluster.create(componentType, versionName, storeType, deployType);
    List<ComponentConfig> componentConfigs = part.loadTemplate();
    return ComponentConfigUtils.buildDBDataToClientTemplate(componentConfigs);
}
Also used : PartCluster(com.dtstack.taier.develop.model.PartCluster) Part(com.dtstack.taier.develop.model.Part)

Example 3 with PartCluster

use of com.dtstack.taier.develop.model.PartCluster in project Taier by DTStack.

the class ConsoleComponentService method addOrUpdateComponent.

@Transactional(rollbackFor = Exception.class)
public ComponentVO addOrUpdateComponent(Long clusterId, String componentConfig, List<Resource> resources, String versionName, String kerberosFileName, String componentTemplate, EComponentType componentType, Integer storeType, String principals, String principal, boolean isMetadata, Boolean isDefault, Integer deployType) {
    if (StringUtils.isBlank(componentConfig)) {
        componentConfig = new JSONObject().toJSONString();
    }
    EComponentType storeComponent = null == storeType ? null : EComponentType.getByCode(storeType);
    PartCluster partCluster = clusterFactory.newImmediatelyLoadCluster(clusterId);
    Part part = partCluster.create(componentType, versionName, storeComponent, deployType);
    String versionValue = part.getVersionValue();
    String pluginName = part.getPluginName();
    Component componentDTO = new Component();
    componentDTO.setComponentTypeCode(componentType.getTypeCode());
    Cluster cluster = clusterMapper.getOne(clusterId);
    if (null == cluster) {
        throw new RdosDefineException(ErrorCode.CANT_NOT_FIND_CLUSTER);
    }
    String clusterName = cluster.getClusterName();
    Component addComponent = new Component();
    BeanUtils.copyProperties(componentDTO, addComponent);
    // 判断是否是更新组件, 需要校验组件版本
    com.dtstack.taier.dao.domain.Component dbComponent = componentMapper.getByClusterIdAndComponentType(clusterId, componentType.getTypeCode(), ComponentVersionUtil.isMultiVersionComponent(componentType.getTypeCode()) ? versionValue : null, deployType);
    String dbHadoopVersion = "";
    boolean isUpdate = false;
    boolean isOpenKerberos = isOpenKerberos(kerberosFileName, dbComponent);
    if (null != dbComponent) {
        // 更新
        dbHadoopVersion = dbComponent.getVersionValue();
        addComponent = dbComponent;
        isUpdate = true;
    }
    EComponentType storesComponent = this.checkStoresComponent(clusterId, storeType);
    addComponent.setStoreType(storesComponent.getTypeCode());
    addComponent.setVersionValue(versionValue);
    addComponent.setComponentName(componentType.getName());
    addComponent.setComponentTypeCode(componentType.getTypeCode());
    addComponent.setDeployType(deployType);
    if (EComponentType.HDFS == componentType) {
        // hdfs的组件和yarn组件的版本保持强一致
        com.dtstack.taier.dao.domain.Component yarnComponent = componentMapper.getByClusterIdAndComponentType(clusterId, EComponentType.YARN.getTypeCode(), null, null);
        if (null != yarnComponent) {
            versionName = yarnComponent.getVersionName();
        }
    }
    addComponent.setVersionName(versionName);
    if (StringUtils.isNotBlank(kerberosFileName)) {
        addComponent.setKerberosFileName(kerberosFileName);
    }
    changeDefault(BooleanUtils.isTrue(isDefault), clusterId, componentType, addComponent);
    // md5zip 会作为 config 表的一个属性
    String md5Key = updateResource(clusterId, componentConfig, resources, kerberosFileName, componentType.getTypeCode(), principals, principal, addComponent, dbComponent);
    addComponent.setClusterId(clusterId);
    if (isUpdate) {
        componentMapper.updateById(addComponent);
        refreshVersion(componentType, clusterId, addComponent, dbHadoopVersion);
        clusterMapper.updateGmtModified(clusterId);
    } else {
        componentMapper.insert(addComponent);
    }
    changeMetadata(componentType.getTypeCode(), isMetadata, clusterId, addComponent.getIsMetadata());
    List<ClientTemplate> clientTemplates = this.buildTemplate(componentType, componentConfig, isOpenKerberos, md5Key, componentTemplate, pluginName);
    componentConfigService.addOrUpdateComponentConfig(clientTemplates, addComponent.getId(), addComponent.getClusterId(), componentType.getTypeCode());
    // 此时不需要查询默认版本
    List<IComponentVO> componentVos = componentConfigService.getComponentVoByComponent(Lists.newArrayList(addComponent), true, clusterId, true, false);
    this.updateCache();
    if (CollectionUtils.isNotEmpty(componentVos)) {
        ComponentVO componentVO = (ComponentVO) componentVos.get(0);
        componentVO.setClusterName(clusterName);
        componentVO.setPrincipal(principal);
        componentVO.setPrincipals(principals);
        componentVO.setDeployType(deployType);
        componentVO.setIsMetadata(BooleanUtils.toInteger(isMetadata));
        return componentVO;
    }
    return null;
}
Also used : IComponentVO(com.dtstack.taier.scheduler.vo.IComponentVO) PartCluster(com.dtstack.taier.develop.model.PartCluster) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) PartCluster(com.dtstack.taier.develop.model.PartCluster) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate) EComponentType(com.dtstack.taier.common.enums.EComponentType) IComponentVO(com.dtstack.taier.scheduler.vo.IComponentVO) ComponentVO(com.dtstack.taier.scheduler.vo.ComponentVO) JSONObject(com.alibaba.fastjson.JSONObject) Part(com.dtstack.taier.develop.model.Part) com.dtstack.taier.dao.domain(com.dtstack.taier.dao.domain) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with PartCluster

use of com.dtstack.taier.develop.model.PartCluster in project Taier by DTStack.

the class ConsoleComponentService method convertComponentTypeToClient.

/**
 * 根据组件类型转换对应的插件名称
 * 如果只配yarn 需要调用插件时候 hdfs给默认值
 *
 * @param clusterName
 * @param componentType
 * @param versionName
 * @return
 */
public String convertComponentTypeToClient(String clusterName, Integer componentType, String versionName, Integer storeType, Integer deployType) {
    Cluster cluster = clusterMapper.getByClusterName(clusterName);
    EComponentType type = EComponentType.getByCode(componentType);
    EComponentType storeComponent = null == storeType ? null : EComponentType.getByCode(storeType);
    PartCluster partCluster = clusterFactory.newImmediatelyLoadCluster(cluster.getId());
    Part part = partCluster.create(type, versionName, storeComponent, deployType);
    return part.getPluginName();
}
Also used : PartCluster(com.dtstack.taier.develop.model.PartCluster) Part(com.dtstack.taier.develop.model.Part) PartCluster(com.dtstack.taier.develop.model.PartCluster) EComponentType(com.dtstack.taier.common.enums.EComponentType)

Aggregations

Part (com.dtstack.taier.develop.model.Part)4 PartCluster (com.dtstack.taier.develop.model.PartCluster)4 EComponentType (com.dtstack.taier.common.enums.EComponentType)3 JSONObject (com.alibaba.fastjson.JSONObject)1 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)1 com.dtstack.taier.dao.domain (com.dtstack.taier.dao.domain)1 ClientTemplate (com.dtstack.taier.scheduler.impl.pojo.ClientTemplate)1 ComponentVO (com.dtstack.taier.scheduler.vo.ComponentVO)1 IComponentVO (com.dtstack.taier.scheduler.vo.IComponentVO)1 Transactional (org.springframework.transaction.annotation.Transactional)1