1

我的工作定义如下:

<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);

我错过了什么?

4

2 回答 2

0

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


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

...
}

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

于 2020-03-14T04:13:20.763 回答
0

分区计划将整数放入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;
于 2020-03-15T21:24:31.470 回答