Search in sources :

Example 1 with JobShardingStrategyOption

use of com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategyOption in project elastic-job by dangdangdotcom.

the class ShardingService method shardingIfNecessary.

/**
     * 如果需要分片且当前节点为主节点, 则作业分片.
     * 如果当前无可用节点则不分片.
     */
public void shardingIfNecessary() {
    List<String> availableShardingServers = serverService.getAvailableShardingServers();
    if (availableShardingServers.isEmpty()) {
        clearShardingInfo();
        return;
    }
    if (!isNeedSharding()) {
        return;
    }
    if (!leaderElectionService.isLeader()) {
        blockUntilShardingCompleted();
        return;
    }
    LiteJobConfiguration liteJobConfig = configService.load(false);
    if (liteJobConfig.isMonitorExecution()) {
        waitingOtherJobCompleted();
    }
    log.debug("Job '{}' sharding begin.", jobName);
    jobNodeStorage.fillEphemeralJobNode(ShardingNode.PROCESSING, "");
    clearShardingInfo();
    JobShardingStrategy jobShardingStrategy = JobShardingStrategyFactory.getStrategy(liteJobConfig.getJobShardingStrategyClass());
    JobShardingStrategyOption option = new JobShardingStrategyOption(jobName, liteJobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount());
    jobNodeStorage.executeInTransaction(new PersistShardingInfoTransactionExecutionCallback(jobShardingStrategy.sharding(availableShardingServers, option)));
    log.debug("Job '{}' sharding complete.", jobName);
}
Also used : JobShardingStrategyOption(com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategyOption) LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) JobShardingStrategy(com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategy)

Aggregations

JobShardingStrategy (com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategy)1 JobShardingStrategyOption (com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategyOption)1 LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)1