如何在 java ee batch / jberet 中访问分区属性
How to access partition properties in java ee batch / jberet
我的工作定义如下:
<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>
引用的映射器创建了一个具有定义值的属性数组,returns它:
PartitionPlanImpl partitionPlan = new PartitionPlanImpl();
partitionPlan.setPartitions(partitionCount);
partitionPlan.setPartitionProperties(partitionProperties);
return partitionPlan;
它在步骤开始时被正确调用,returns 属性定义了正确的键。
但是,我无法从 reader 步骤中获取分区计划属性。 None 作业上下文属性和步骤上下文属性均不包含任何内容。我在控制台中没有看到任何错误。作业实例参数仅包含运行时设置的参数。 None 个 parameters/properties 个名称冲突。尝试使用 @BatchProperty 注入它们,将字段留空。
批量启动如下:
Properties properties = new Properties();
// Fill parameters...
long executionId = jobOperator.start(jobName, properties);
我错过了什么?
要查看工作中的分区属性,您需要将项目 reader 属性注入项目 reader class。例如,
public class AllTrusteeCustomerFilesReader implements ItemReader {
@Inject
@BatchProperty(name = "part-page-first-offset")
String partPageFirstOffset;
...
}
上面的字段 partPageFirstOffset
将保存项目 reader 属性 part-page-first-offset
的值,它在 job.xml 中定义以引用分区 属性 part-page-first-offset
.
分区计划将整数放入 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;
我的工作定义如下:
<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>
引用的映射器创建了一个具有定义值的属性数组,returns它:
PartitionPlanImpl partitionPlan = new PartitionPlanImpl();
partitionPlan.setPartitions(partitionCount);
partitionPlan.setPartitionProperties(partitionProperties);
return partitionPlan;
它在步骤开始时被正确调用,returns 属性定义了正确的键。
但是,我无法从 reader 步骤中获取分区计划属性。 None 作业上下文属性和步骤上下文属性均不包含任何内容。我在控制台中没有看到任何错误。作业实例参数仅包含运行时设置的参数。 None 个 parameters/properties 个名称冲突。尝试使用 @BatchProperty 注入它们,将字段留空。
批量启动如下:
Properties properties = new Properties();
// Fill parameters...
long executionId = jobOperator.start(jobName, properties);
我错过了什么?
要查看工作中的分区属性,您需要将项目 reader 属性注入项目 reader class。例如,
public class AllTrusteeCustomerFilesReader implements ItemReader {
@Inject
@BatchProperty(name = "part-page-first-offset")
String partPageFirstOffset;
...
}
上面的字段 partPageFirstOffset
将保存项目 reader 属性 part-page-first-offset
的值,它在 job.xml 中定义以引用分区 属性 part-page-first-offset
.
分区计划将整数放入 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;