Search in sources :

Example 1 with QueueInfo

use of com.dtstack.taier.scheduler.server.queue.QueueInfo in project Taier by DTStack.

the class JobSchedulerListener method getAllNodesJobQueueInfo.

/**
 * 同步所有节点的 type类型下的 job实例信息
 * key1: nodeAddress,
 * key2: scheduleType
 */
public Map<String, Map<Integer, QueueInfo>> getAllNodesJobQueueInfo() {
    List<String> allNodeAddress = zkService.getAliveBrokersChildren();
    Pair<String, String> cycTime = getCycTimeLimit();
    Map<String, Map<Integer, QueueInfo>> allNodeJobInfo = Maps.newHashMap();
    for (String nodeAddress : allNodeAddress) {
        if (StringUtils.isBlank(nodeAddress)) {
            continue;
        }
        allNodeJobInfo.computeIfAbsent(nodeAddress, na -> {
            Map<Integer, QueueInfo> nodeJobInfo = Maps.newHashMap();
            for (EScheduleType scheduleType : EScheduleType.values()) {
                executors.forEach(executor -> nodeJobInfo.computeIfAbsent(scheduleType.getType(), k -> {
                    int queueSize = scheduleJobMapper.countTasksByCycTimeTypeAndAddress(nodeAddress, scheduleType.getType(), cycTime.getLeft(), cycTime.getRight());
                    QueueInfo queueInfo = new QueueInfo();
                    queueInfo.setSize(queueSize);
                    return queueInfo;
                }));
            }
            return nodeJobInfo;
        });
    }
    return allNodeJobInfo;
}
Also used : QueueInfo(com.dtstack.taier.scheduler.server.queue.QueueInfo) StringUtils(org.apache.commons.lang.StringUtils) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LoggerFactory(org.slf4j.LoggerFactory) EnvironmentContext(com.dtstack.taier.common.env.EnvironmentContext) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) QueueInfo(com.dtstack.taier.scheduler.server.queue.QueueInfo) FillDataJobScheduler(com.dtstack.taier.scheduler.server.scheduler.FillDataJobScheduler) ArrayList(java.util.ArrayList) CustomThreadFactory(com.dtstack.taier.pluginapi.CustomThreadFactory) Calendar(java.util.Calendar) ZkService(com.dtstack.taier.scheduler.zookeeper.ZkService) Pair(org.apache.commons.lang3.tuple.Pair) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent) RestartJobScheduler(com.dtstack.taier.scheduler.server.scheduler.RestartJobScheduler) Map(java.util.Map) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) ScheduleJobMapper(com.dtstack.taier.dao.mapper.ScheduleJobMapper) CycleJobScheduler(com.dtstack.taier.scheduler.server.scheduler.CycleJobScheduler) EScheduleType(com.dtstack.taier.common.enums.EScheduleType) ApplicationListener(org.springframework.context.ApplicationListener) Maps(com.google.common.collect.Maps) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TimeUnit(java.util.concurrent.TimeUnit) Component(org.springframework.stereotype.Component) List(java.util.List) AbstractJobSummitScheduler(com.dtstack.taier.scheduler.server.scheduler.AbstractJobSummitScheduler) DisposableBean(org.springframework.beans.factory.DisposableBean) EScheduleType(com.dtstack.taier.common.enums.EScheduleType) Map(java.util.Map)

Example 2 with QueueInfo

use of com.dtstack.taier.scheduler.server.queue.QueueInfo in project Taier by DTStack.

the class JobPartitioner method computeBatchJobSize.

/**
 * compute job number per node
 */
public Map<String, Integer> computeBatchJobSize(Integer type, int jobSize) {
    // 节点挂了就会迁移的
    List<String> aliveNodes = zkService.getAliveBrokersChildren();
    Map<Integer, Map<String, QueueInfo>> allNodesJobQueueInfo = queueListener.getAllNodesJobQueueInfo();
    if (allNodesJobQueueInfo.isEmpty()) {
        return getDefaultStrategy(aliveNodes, jobSize);
    }
    Map<String, QueueInfo> nodesJobQueue = allNodesJobQueueInfo.get(type);
    if (nodesJobQueue == null || nodesJobQueue.isEmpty()) {
        return getDefaultStrategy(aliveNodes, jobSize);
    }
    Map<String, Integer> nodeSort = Maps.newHashMap();
    int total = jobSize;
    for (Map.Entry<String, QueueInfo> queueInfoEntry : nodesJobQueue.entrySet()) {
        QueueInfo queueInfo = queueInfoEntry.getValue();
        total += queueInfo.getSize();
        // 排除宕机节点
        if (aliveNodes.contains(queueInfoEntry.getKey())) {
            nodeSort.put(queueInfoEntry.getKey(), queueInfo.getSize());
        }
    }
    if (nodeSort.isEmpty()) {
        return getDefaultStrategy(aliveNodes, jobSize);
    }
    int avg = (total / nodeSort.size()) + 1;
    for (Map.Entry<String, Integer> entry : nodeSort.entrySet()) {
        entry.setValue(avg - entry.getValue());
    }
    return nodeSort;
}
Also used : QueueInfo(com.dtstack.taier.scheduler.server.queue.QueueInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

QueueInfo (com.dtstack.taier.scheduler.server.queue.QueueInfo)2 Map (java.util.Map)2 EScheduleType (com.dtstack.taier.common.enums.EScheduleType)1 EnvironmentContext (com.dtstack.taier.common.env.EnvironmentContext)1 ScheduleJobMapper (com.dtstack.taier.dao.mapper.ScheduleJobMapper)1 CustomThreadFactory (com.dtstack.taier.pluginapi.CustomThreadFactory)1 AbstractJobSummitScheduler (com.dtstack.taier.scheduler.server.scheduler.AbstractJobSummitScheduler)1 CycleJobScheduler (com.dtstack.taier.scheduler.server.scheduler.CycleJobScheduler)1 FillDataJobScheduler (com.dtstack.taier.scheduler.server.scheduler.FillDataJobScheduler)1 RestartJobScheduler (com.dtstack.taier.scheduler.server.scheduler.RestartJobScheduler)1 ZkService (com.dtstack.taier.scheduler.zookeeper.ZkService)1 Maps (com.google.common.collect.Maps)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1