All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vip.saturn.job.sharding.task.ExecuteJobEnableShardingTask Maven / Gradle / Ivy

package com.vip.saturn.job.sharding.task;

import com.vip.saturn.job.sharding.entity.Executor;
import com.vip.saturn.job.sharding.entity.Shard;
import com.vip.saturn.job.sharding.service.NamespaceShardingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 作业启用,获取该作业的shards,注意要过滤不能运行该作业的executors
 */
public class ExecuteJobEnableShardingTask extends AbstractAsyncShardingTask {

	private static final Logger log = LoggerFactory.getLogger(ExecuteJobEnableShardingTask.class);

	private String jobName;

	public ExecuteJobEnableShardingTask(NamespaceShardingService namespaceShardingService, String jobName) {
		super(namespaceShardingService);
		this.jobName = jobName;
	}

	@Override
	protected void logStartInfo() {
		log.info("Execute the {} with {} enable", this.getClass().getSimpleName(), jobName);
	}

	@Override
	protected List notifyEnableJobsPrior() {
		List notifyEnableJobsPrior = new ArrayList<>();
		notifyEnableJobsPrior.add(jobName);
		return notifyEnableJobsPrior;
	}

	@Override
	protected boolean pick(List allJobs, List allEnableJobs, List shardList,
			List lastOnlineExecutorList, List lastOnlineTrafficExecutorList) throws Exception {
		// 移除已经在Executor运行的该作业的所有Shard
		removeJobShardsOnExecutors(lastOnlineTrafficExecutorList, jobName);

		// 修正该所有executor的对该作业的jobNameList
		fixJobNameList(lastOnlineExecutorList, jobName);

		// 获取该作业的Shard
		shardList.addAll(createShards(jobName, lastOnlineTrafficExecutorList));

		return true;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy