Search in sources :

Example 1 with SaturnExecutionContext

use of com.vip.saturn.job.basic.SaturnExecutionContext in project Saturn by vipshop.

the class ExecutionService method registerJobCompletedControlInfoByItem.

/**
 * 注册作业完成信息.
 */
public void registerJobCompletedControlInfoByItem(final JobExecutionMultipleShardingContext jobExecutionShardingContext, int item) {
    boolean isEnabledReport = configService.isEnabledReport();
    if (!isEnabledReport) {
        return;
    }
    if (jobExecutionShardingContext instanceof SaturnExecutionContext) {
        // 为了展现分片处理失败的状态
        SaturnExecutionContext saturnContext = (SaturnExecutionContext) jobExecutionShardingContext;
        if (saturnContext.isSaturnJob()) {
            SaturnJobReturn jobRet = saturnContext.getShardingItemResults().get(item);
            if (jobRet != null) {
                int errorGroup = jobRet.getErrorGroup();
                if (errorGroup == SaturnSystemErrorGroup.TIMEOUT) {
                    getJobNodeStorage().createJobNodeIfNeeded(ExecutionNode.getTimeoutNode(item));
                } else if (errorGroup == SaturnSystemErrorGroup.FAIL) {
                    getJobNodeStorage().createJobNodeIfNeeded(ExecutionNode.getFailedNode(item));
                }
            } else {
                getJobNodeStorage().createJobNodeIfNeeded(ExecutionNode.getFailedNode(item));
            }
        }
    }
    // create completed node
    getJobNodeStorage().createOrUpdateJobNodeWithValue(ExecutionNode.getCompletedNode(item), executorName);
    // remove running node
    getJobNodeStorage().removeJobNodeIfExisted(ExecutionNode.getRunningNode(item));
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) SaturnExecutionContext(com.vip.saturn.job.basic.SaturnExecutionContext)

Example 2 with SaturnExecutionContext

use of com.vip.saturn.job.basic.SaturnExecutionContext in project Saturn by vipshop.

the class ExecutionContextService method getJobExecutionShardingContext.

/**
 * 获取当前作业服务器运行时分片上下文.
 *
 * @return 当前作业服务器运行时分片上下文
 */
public JobExecutionMultipleShardingContext getJobExecutionShardingContext() {
    SaturnExecutionContext result = new SaturnExecutionContext();
    result.setJobName(configService.getJobName());
    result.setShardingTotalCount(configService.getShardingTotalCount());
    List<Integer> shardingItems = getShardingItems();
    boolean isEnabledReport = configService.isEnabledReport();
    if (isEnabledReport) {
        removeRunningItems(shardingItems);
    }
    result.setShardingItems(shardingItems);
    result.setJobParameter(configService.getJobParameter());
    result.setCustomContext(configService.getCustomContext());
    result.setJobConfiguration(jobConfiguration);
    if (coordinatorRegistryCenter != null) {
        result.setNamespace(coordinatorRegistryCenter.getNamespace());
        result.setExecutorName(coordinatorRegistryCenter.getExecutorName());
    }
    if (result.getShardingItems().isEmpty()) {
        return result;
    }
    Map<Integer, String> shardingItemParameters = configService.getShardingItemParameters();
    if (shardingItemParameters.containsKey(-1)) {
        // 本地模式
        for (int each : result.getShardingItems()) {
            result.getShardingItemParameters().put(each, shardingItemParameters.get(-1));
        }
    } else {
        for (int each : result.getShardingItems()) {
            if (shardingItemParameters.containsKey(each)) {
                result.getShardingItemParameters().put(each, shardingItemParameters.get(each));
            }
        }
    }
    if (jobConfiguration.getTimeoutSeconds() > 0) {
        result.setTimetoutSeconds(jobConfiguration.getTimeoutSeconds());
    }
    return result;
}
Also used : SaturnExecutionContext(com.vip.saturn.job.basic.SaturnExecutionContext)

Example 3 with SaturnExecutionContext

use of com.vip.saturn.job.basic.SaturnExecutionContext in project Saturn by vipshop.

the class ExecutionContextService method getJobExecutionShardingContext.

/**
 * 获取当前作业服务器运行时分片上下文.
 *
 * @return 当前作业服务器运行时分片上下文
 */
public JobExecutionMultipleShardingContext getJobExecutionShardingContext(final Triggered triggered) {
    SaturnExecutionContext result = new SaturnExecutionContext();
    result.setJobName(configService.getJobName());
    result.setShardingTotalCount(configService.getShardingTotalCount());
    result.setTriggered(triggered);
    List<Integer> shardingItems = getShardingItems();
    boolean isEnabledReport = configService.isEnabledReport();
    if (isEnabledReport) {
        removeRunningItems(shardingItems);
    }
    result.setShardingItems(shardingItems);
    result.setJobParameter(configService.getJobParameter());
    result.setCustomContext(configService.getCustomContext());
    result.setJobConfiguration(jobConfiguration);
    if (coordinatorRegistryCenter != null) {
        result.setNamespace(coordinatorRegistryCenter.getNamespace());
        result.setExecutorName(coordinatorRegistryCenter.getExecutorName());
    }
    if (result.getShardingItems().isEmpty()) {
        return result;
    }
    Map<Integer, String> shardingItemParameters = configService.getShardingItemParameters();
    if (shardingItemParameters.containsKey(-1)) {
        // 本地模式
        for (int each : result.getShardingItems()) {
            result.getShardingItemParameters().put(each, shardingItemParameters.get(-1));
        }
    } else {
        for (int each : result.getShardingItems()) {
            if (shardingItemParameters.containsKey(each)) {
                result.getShardingItemParameters().put(each, shardingItemParameters.get(each));
            }
        }
    }
    if (jobConfiguration.getTimeoutSeconds() > 0) {
        result.setTimetoutSeconds(jobConfiguration.getTimeoutSeconds());
    }
    return result;
}
Also used : SaturnExecutionContext(com.vip.saturn.job.basic.SaturnExecutionContext)

Aggregations

SaturnExecutionContext (com.vip.saturn.job.basic.SaturnExecutionContext)3 SaturnJobReturn (com.vip.saturn.job.SaturnJobReturn)1