Search in sources :

Example 1 with Queue

use of com.dtstack.taier.dao.domain.Queue in project Taier by DTStack.

the class ClusterService method pluginInfoJSON.

/**
 * 内部使用
 */
public JSONObject pluginInfoJSON(Long tenantId, Integer taskType, Integer deployMode, String componentVersion) {
    EScheduleJobType engineJobType = EScheduleJobType.getByTaskType(taskType);
    EComponentType componentType = engineJobType.getComponentType();
    if (componentType == null) {
        return null;
    }
    Long clusterId = clusterTenantMapper.getClusterIdByTenantId(tenantId);
    if (null == clusterId) {
        clusterId = DEFAULT_CLUSTER_ID;
    }
    JSONObject clusterConfigJson = buildClusterConfig(clusterId, componentVersion, componentType);
    JSONObject pluginJson = convertPluginInfo(clusterConfigJson, componentType, clusterId, deployMode);
    if (pluginJson == null) {
        throw new RdosDefineException(format("The cluster is not configured [%s] engine", componentType));
    }
    Queue queue = getQueue(tenantId, clusterId);
    pluginJson.put(QUEUE, queue == null ? "" : queue.getQueueName());
    setComponentSftpDir(clusterId, clusterConfigJson, pluginJson, componentType);
    return pluginJson;
}
Also used : EScheduleJobType(com.dtstack.taier.common.enums.EScheduleJobType) JSONObject(com.alibaba.fastjson.JSONObject) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Queue(com.dtstack.taier.dao.domain.Queue) EComponentType(com.dtstack.taier.common.enums.EComponentType)

Example 2 with Queue

use of com.dtstack.taier.dao.domain.Queue in project Taier by DTStack.

the class ClusterService method getQueue.

public Queue getQueue(Long tenantId, Long clusterId) {
    // 先获取绑定的
    Long queueId = clusterTenantMapper.getQueueIdByTenantId(tenantId);
    Queue queue = consoleQueueMapper.selectById(queueId);
    if (queue != null) {
        return queue;
    }
    List<Queue> queues = consoleQueueMapper.listByClusterWithLeaf(clusterId);
    if (CollectionUtils.isEmpty(queues)) {
        return null;
    }
    // 没有绑定集群和队列时,返回第一个队列
    return queues.get(0);
}
Also used : Queue(com.dtstack.taier.dao.domain.Queue)

Example 3 with Queue

use of com.dtstack.taier.dao.domain.Queue in project Taier by DTStack.

the class QueueService method updateAddQueue.

private void updateAddQueue(Map<String, Queue> existQueueMap, Long clusterId, Long parentQueueId, List<ComponentTestResult.QueueDescription> descriptions) {
    // 不会有空队列的
    if (CollectionUtils.isNotEmpty(descriptions)) {
        for (ComponentTestResult.QueueDescription queueDescription : descriptions) {
            Queue queue = new Queue();
            queue.setQueueName(queueDescription.getQueueName());
            queue.setClusterId(clusterId);
            queue.setMaxCapacity(queueDescription.getMaximumCapacity());
            queue.setCapacity(queueDescription.getCapacity());
            queue.setQueueState(queueDescription.getQueueState());
            queue.setQueuePath(queueDescription.getQueuePath());
            Queue oldQueue = existQueueMap.get(queueDescription.getQueuePath());
            if (oldQueue != null) {
                if (oldQueue.baseEquals(queue)) {
                    existQueueMap.remove(queueDescription.getQueuePath());
                } else if (queue.getQueueName().equals(oldQueue.getQueueName())) {
                    oldQueue.setQueueState(queue.getQueueState());
                    oldQueue.setCapacity(queue.getCapacity());
                    oldQueue.setMaxCapacity(queue.getMaxCapacity());
                    consoleQueueMapper.updateById(oldQueue);
                    existQueueMap.remove(queueDescription.getQueuePath());
                }
                queue.setId(oldQueue.getId());
            } else {
                queue.setParentQueueId(parentQueueId);
                Integer insert = consoleQueueMapper.insert(queue);
                if (insert != 1) {
                    throw new RdosDefineException("operation failed");
                }
            }
            // todo 递归调用,当没有子队列后就停止递归
            updateAddQueue(existQueueMap, clusterId, queue.getId(), queueDescription.getChildQueues());
        }
    }
}
Also used : ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Queue(com.dtstack.taier.dao.domain.Queue)

Example 4 with Queue

use of com.dtstack.taier.dao.domain.Queue in project Taier by DTStack.

the class QueueService method newAddQueue.

private void newAddQueue(Long clusterId, Long parentQueueId, List<ComponentTestResult.QueueDescription> descriptions) {
    if (CollectionUtils.isNotEmpty(descriptions)) {
        for (ComponentTestResult.QueueDescription queueDescription : descriptions) {
            Queue queue = new Queue();
            queue.setQueueName(queueDescription.getQueueName());
            queue.setClusterId(clusterId);
            queue.setMaxCapacity(queueDescription.getMaximumCapacity());
            queue.setCapacity(queueDescription.getCapacity());
            queue.setQueueState(queueDescription.getQueueState());
            queue.setParentQueueId(parentQueueId);
            queue.setQueuePath(queueDescription.getQueuePath());
            Integer insert = consoleQueueMapper.insert(queue);
            if (insert != 1) {
                throw new RdosDefineException("operation failed");
            }
            newAddQueue(clusterId, queue.getId(), queueDescription.getChildQueues());
        }
    }
}
Also used : ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Queue(com.dtstack.taier.dao.domain.Queue)

Example 5 with Queue

use of com.dtstack.taier.dao.domain.Queue in project Taier by DTStack.

the class QueueService method updateQueue.

public void updateQueue(Long clusterId, ComponentTestResult.ClusterResourceDescription description) {
    List<Queue> queues = consoleQueueMapper.listByClusterId(clusterId);
    if (CollectionUtils.isEmpty(queues)) {
        newAddQueue(clusterId, ROOT_QUEUE_ID, description.getQueueDescriptions());
    } else {
        Map<String, Queue> existQueueMap = new HashMap<>(queues.size());
        for (Queue queue : queues) {
            existQueueMap.put(queue.getQueuePath(), queue);
        }
        updateAddQueue(existQueueMap, clusterId, ROOT_QUEUE_ID, description.getQueueDescriptions());
        if (!existQueueMap.isEmpty()) {
            Integer delete = consoleQueueMapper.deleteByIds(existQueueMap.values().stream().map(BaseEntity::getId).collect(Collectors.toList()), clusterId);
            if (delete != existQueueMap.size()) {
                throw new RdosDefineException("operation failed");
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) BaseEntity(com.dtstack.taier.dao.domain.BaseEntity) Queue(com.dtstack.taier.dao.domain.Queue)

Aggregations

Queue (com.dtstack.taier.dao.domain.Queue)8 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)6 EComponentType (com.dtstack.taier.common.enums.EComponentType)3 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)2 Deleted (com.dtstack.taier.common.enums.Deleted)2 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)2 Cluster (com.dtstack.taier.dao.domain.Cluster)2 ClusterTenant (com.dtstack.taier.dao.domain.ClusterTenant)2 ComponentTestResult (com.dtstack.taier.pluginapi.pojo.ComponentTestResult)2 ComponentService (com.dtstack.taier.scheduler.service.ComponentService)2 ComponentVO (com.dtstack.taier.scheduler.vo.ComponentVO)2 Collectors (java.util.stream.Collectors)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 EComponentScheduleType (com.dtstack.taier.common.enums.EComponentScheduleType)1 EScheduleJobType (com.dtstack.taier.common.enums.EScheduleJobType)1 MultiEngineType (com.dtstack.taier.common.enums.MultiEngineType)1