简体   繁体   English

带有分区的Java Batch Step返回错误的batchStatus和exitStatus

[英]Java Batch Step with partition returns wrong batchStatus and exitStatus

I have a (very simple) java batch job in JDL with just two steps. 我在JDL中有一个(非常简单的)Java批处理作业,仅需两个步骤。

When the step "download" return the status "STOPPED" the job should stop. 当步骤“下载”返回状态“已停止”时,作业应停止。 After restart the stop notify should be called. 重新启动后,应该调用停止通知。

Without the partition everything works fine. 没有分区,一切正常。

stats without partition 没有分区的统计

after step=download batchStatus=COMPLETED exitStatus=STOPPED
after job=job       batchStatus=STOPPED   exitStatus=STOPPED

With partition i get realy strange stati for batch end exit. 随着分区我得到真正的奇怪的状态为批处理结束出口。 And the job doesn't stop if the download step returns "STOPPED". 如果下载步骤返回“已停止”,则作业不会停止。 Even if the partition has just one thread and one partition. 即使该分区只有一个线程和一个分区。

When trying to restart the following error is raised (of course). 尝试重新启动时,会引发以下错误(当然)。 JBERET000609: Job execution 1 has already completed and cannot be restarted. JBERET000609:作业执行1已经完成,无法重新启动。

stats with partition 分区统计

after step=download batchStatus=STARTED   exitStatus=null
after job=job       batchStatus=COMPLETED exitStatus=COMPLETED

job descrition 工作描述

<job id="job" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0" restartable="true">
    <step id="download" next="notify">
        <batchlet ref="downloadBatchlet">
        </batchlet>
        <partition>
            <mapper ref="basicPartition" />
        </partition>
        <stop on="STOPPED" restart="notify"/>
    </step>
    <step id="notify">
        <batchlet ref="notifyBatchlet"></batchlet>
        <end on="COMPLETED"/>
    </step>
</job>

Every hint an suggestions are welcome. 任何提示都欢迎提出建议。 What I am missing? 我缺少什么?

Without partition 无分区

On job start the job calls the - downloadBatchlet => STOPPED and stopps. 在作业开始时,作业将调用-downloadBatchlet => STOPPED并停止。

On restart the job calls the - notifyBatchlet => COMPLETED and ends. 在重新启动作业时,调用-notifyBatchlet => COMPLETED并结束。

With partition 带隔板

On job start the job calls the - downloadBatchlet => STOPPED and stopps. 在作业开始时,作业将调用-downloadBatchlet => STOPPED并停止。

On restart the job calls NO STEPS and ends. 在重新启动作业时,将调用“ 无步骤”并结束。

@Named
public class DownloadBatchlet extends AbstractBatchlet {
    @Override
    public String process() throws Exception {

        return BatchStatus.STOPPED.toString();
    }
    @Override
    public void stop() throws Exception {
    }
}

Partition vs Top Level Batch/Exit Status 分区与顶级批处理/退出状态

In Java Batch, there is a separate batch and exit status for the step itself and also for each partition. 在Java Batch中,步骤本身以及每个分区都有单独的批处理和退出状态。

Since "transitioning" (to the next step, or for stopping the job, in your case) occurs at the job level here, you would need to set a non-default exit status at the "top level" of the step, not merely at the level of each partition. 由于“过渡”(在您的情况下为下一步,或者用于停止工作)发生在此处的工作级别,因此您需要在该步骤的“顶层”设置非默认退出状态,而不仅仅是在每个分区的级别。

If you want to include logic which reacts to each partition's status, a good starting point would be the PartitionAnalyzer#analyzeStatus method, which is called as each partition terminates. 如果要包括对每个分区的状态做出反应的逻辑,则最好的起点是PartitionAnalyzer#analyzeStatus方法,该方法在每个分区终止时被称为。 This runs on the "top level" thread (as does the PartitionReducer). 它在“顶层”线程上运行(PartitionReducer也是如此)。

Simple example Analyzer 简单的示例分析器

public class MyPartitionAnalyzer extends AbstractPartitionAnalyzer {

    @Inject
    private StepContext stepCtx;

    @Override
    public void analyzeStatus(BatchStatus batchStatus, String exitStatus) throws Exception {

        // Overrides default exit status if non-COMPLETED partition seen
        if (!exitStatus.equals(BatchStatus.COMPLETED)) {
            stepCtx.setExitStatus(exitStatus);
        }
    }
}

You can use whatever logic you want to react (or not) to the partitions' batch and exit statuses. 您可以使用想要对分区的批处理和退出状态做出反应(或不做出反应)的任何逻辑。 The key here is that the analyzer runs on the top-level step thread, and so sets the step-level status. 这里的关键是分析器在顶级步骤线程上运行,因此设置了步骤状态。 The batchlet's return value, on the other hand, only sets the partition-level status. 另一方面,批处理程序的返回值仅设置分区级别的状态。

The analyzer can be used to "aggregate" partition-level status however you want. 分析器可用于根据需要“聚合”分区级别的状态。 If you do nothing, the step-level exit status defaults to the step-level batch status, so if the step completes normally the step level exit status is COMPLETED. 如果不执行任何操作,则步骤级退出状态默认为步骤级批处理状态,因此,如果步骤正常完成,则步骤级退出状态为COMPLETED。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM