【问题标题】:How to access partition properties in java ee batch / jberet如何在 java ee batch / jberet 中访问分区属性
【发布时间】:2020-03-12 15:25:07
【问题描述】:

我的工作定义如下:

<step id="file-transfer">
    <chunk checkpoint-policy="item" item-count="10" retry-limit="10">
        <reader ref="allTrusteeCustomerFilesReader">
            <properties>
                <property name="part-page-first-offset" value="#{partitionPlan['part-page-first-offset']}"/>
                <property name="part-page-last-offset" value="#{partitionPlan['part-page-last-offset']}"/>
                <property name="part-page-length" value="#{partitionPlan['part-page-length']}"/>
                <property name="part-sort-field" value="#{partitionPlan['part-sort-field']}"/>
                <property name="part-sort-ascending" value="#{partitionPlan['part-sort-ascending']}"/>
            </properties>
        </reader>
        <processor ref="customerFileLocalToGoogleStorageProcessor"/>
        <writer ref="customerFileWriter">
            <properties>
                <property name="set-google-cloud-migrated" value="true"/>
            </properties>
        </writer>


        <skippable-exception-classes>
            <include class="be.valuya.gestemps.server.file.batch.error.NoLocalStorageDataException"/>
            <include class="be.valuya.gestemps.server.file.batch.error.TargetAlreadyPresentException"/>
            <include class="be.valuya.gestemps.server.file.batch.error.CustomerFileAlreadyMigratedException"/>
        </skippable-exception-classes>
        <retryable-exception-classes>
            <include class="be.valuya.gestemps.server.file.batch.error.TransferToGoogleFailedException"/>
        </retryable-exception-classes>
    </chunk>

    <partition>
        <mapper ref="customerFilePartitionMapper"/>
    </partition>

    <end on="COMPLETED"/>
</step>

引用的映射器创建一个具有定义值的属性数组,并返回它:

    PartitionPlanImpl partitionPlan = new PartitionPlanImpl();
    partitionPlan.setPartitions(partitionCount);
    partitionPlan.setPartitionProperties(partitionProperties);

    return partitionPlan;

在步骤开始时正确调用它并返回定义了正确键的属性。

但是,我无法从阅读器步骤中获取分区计划属性。作业上下文属性和步骤上下文属性都不包含任何内容。我在控制台中没有看到错误。作业实例参数只包含运行时设置的参数。没有任何参数/属性名称冲突。尝试使用 @BatchProperty 注入它们,将字段保留为空。

批处理开始如下:

    Properties properties = new Properties();
    // Fill parameters...
    long executionId = jobOperator.start(jobName, properties);

我错过了什么?

【问题讨论】:

  • 你能通过例如github分享一个简化的测试应用程序吗?我调试它会更容易。或者您也可以提交JIRA issue 并在处附加复制器测试应用程序
  • 我创建了一个最小的应用程序来重现:github.com/cghislai/jberet-partitoin-test
  • 真该死,在分区计划属性中设置原语int 是个问题:/

标签: jakarta-ee jsr352 jberet


【解决方案1】:

要查看工作中的分区属性,您需要将项目阅读器属性注入到项目阅读器类中。例如,


public class AllTrusteeCustomerFilesReader implements ItemReader {
  @Inject
  @BatchProperty(name = "part-page-first-offset")
  String partPageFirstOffset;

...
}

上述字段partPageFirstOffset 将保存项目读取器属性part-page-first-offset 的值,该值在job.xml 中定义以引用分区属性part-page-first-offset

【讨论】:

    【解决方案2】:

    分区计划将整数放入Properties 映射中。似乎需要字符串:

    //
    Properties partProperties;
    partProperties.setProperty("plan-property", "20"); // <--- Use setProperty to enforce String values rather than put
    // ...
    
    PartitionPlanImpl partitionPlan = new PartitionPlanImpl();
    partitionPlan.setPartitions(partitionCount);
    partitionPlan.setPartitionProperties(partitionProperties);
    
    return partitionPlan;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      相关资源
      最近更新 更多