diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBWorkerConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBWorkerConfiguration.java index 038353a0c..71437256a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBWorkerConfiguration.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBWorkerConfiguration.java @@ -93,7 +93,8 @@ public class LoanCOBWorkerConfiguration { public Step loanBusinessStep(@Value("#{stepExecutionContext['partition']}") String partitionName) { return localStepBuilderFactory.get("Loan Business - Step:" + partitionName) .chunk(propertyService.getChunkSize(JobName.LOAN_COB.name())).reader(cobWorkerItemReader()) - .processor(cobWorkerItemProcessor()).writer(cobWorkerItemWriter()).faultTolerant().skip(Exception.class) + .processor(cobWorkerItemProcessor()).writer(cobWorkerItemWriter()).faultTolerant().retry(Exception.class) + .retryLimit(propertyService.getRetryLimit(LoanCOBConstant.JOB_NAME)).skip(Exception.class) .skipLimit(propertyService.getChunkSize(JobName.LOAN_COB.name()) + 1).listener(loanItemListener()).build(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java index 41c05d1f7..3afa01687 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java @@ -147,6 +147,7 @@ public class FineractProperties { private Integer chunkSize; private Integer partitionSize; private Integer threadCount; + private Integer retryLimit; } @Getter diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/springbatch/PropertyService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/springbatch/PropertyService.java index 7a9ba0294..053b2536b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/springbatch/PropertyService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/springbatch/PropertyService.java @@ -23,4 +23,6 @@ public interface PropertyService { Integer getPartitionSize(String jobName); Integer getChunkSize(String jobName); + + Integer getRetryLimit(String jobName); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/springbatch/PropertyServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/springbatch/PropertyServiceImpl.java index 1d4e9d88c..d8cc1ba52 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/springbatch/PropertyServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/springbatch/PropertyServiceImpl.java @@ -50,4 +50,15 @@ public class PropertyServiceImpl implements PropertyService { .map(FineractProperties.PartitionedJobProperty::getChunkSize) // .orElse(1); } + + @Override + public Integer getRetryLimit(String jobName) { + List jobProperties = fineractProperties.getPartitionedJob() + .getPartitionedJobProperties(); + return jobProperties.stream() // + .filter(jobProperty -> jobName.equals(jobProperty.getJobName())) // + .findFirst() // + .map(FineractProperties.PartitionedJobProperty::getRetryLimit) // + .orElse(1); + } } diff --git a/fineract-provider/src/main/resources/application.properties b/fineract-provider/src/main/resources/application.properties index 009b11daf..963f8565c 100644 --- a/fineract-provider/src/main/resources/application.properties +++ b/fineract-provider/src/main/resources/application.properties @@ -65,6 +65,7 @@ fineract.partitioned-job.partitioned-job-properties[0].job-name=LOAN_COB fineract.partitioned-job.partitioned-job-properties[0].chunk-size=${LOAN_COB_CHUNK_SIZE:100} fineract.partitioned-job.partitioned-job-properties[0].partition-size=${LOAN_COB_PARTITION_SIZE:100} fineract.partitioned-job.partitioned-job-properties[0].thread-count=${LOAN_COB_THREAD_COUNT:1} +fineract.partitioned-job.partitioned-job-properties[0].retry-limit=${LOAN_COB_RETRY_LIMIT:5} fineract.remote-job-message-handler.spring-events.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_SPRING_EVENTS_ENABLED:true} fineract.remote-job-message-handler.jms.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_ENABLED:false} diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/springbatch/SpringBatchPropertyServiceDefinitions.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/springbatch/SpringBatchPropertyServiceDefinitions.java new file mode 100644 index 000000000..c124f984f --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/springbatch/SpringBatchPropertyServiceDefinitions.java @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.springbatch; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.cucumber.java8.En; +import org.apache.fineract.infrastructure.core.config.FineractProperties; +import org.springframework.beans.factory.annotation.Autowired; + +public class SpringBatchPropertyServiceDefinitions implements En { + + @Autowired + private FineractProperties fineractProperties; + private PropertyService propertyService; + private int partitionSize; + private int chunkSize; + private int retryLimit; + + public SpringBatchPropertyServiceDefinitions() { + Given("Property Service is initialized", () -> { + propertyService = new PropertyServiceImpl(fineractProperties); + }); + + When("partition size is fetched for {string}", (String jobName) -> { + partitionSize = propertyService.getPartitionSize(jobName); + }); + + When("chunk size is fetched for {string}", (String jobName) -> { + chunkSize = propertyService.getChunkSize(jobName); + }); + + When("retry limit is fetched for {string}", (String jobName) -> { + retryLimit = propertyService.getRetryLimit(jobName); + }); + + Then("partition size is {int}", (Integer value) -> { + assertThat(partitionSize).isEqualTo(value); + }); + + Then("chunk size is {int}", (Integer value) -> { + assertThat(chunkSize).isEqualTo(value); + }); + + Then("retry limit is {int}", (Integer value) -> { + assertThat(retryLimit).isEqualTo(value); + }); + } +} diff --git a/fineract-provider/src/test/resources/application-test.properties b/fineract-provider/src/test/resources/application-test.properties index cc0153d0a..3b6db8af2 100644 --- a/fineract-provider/src/test/resources/application-test.properties +++ b/fineract-provider/src/test/resources/application-test.properties @@ -43,6 +43,7 @@ fineract.partitioned-job.partitioned-job-properties[0].job-name=LOAN_COB fineract.partitioned-job.partitioned-job-properties[0].chunk-size=100 fineract.partitioned-job.partitioned-job-properties[0].partition-size=100 fineract.partitioned-job.partitioned-job-properties[0].thread-count=1 +fineract.partitioned-job.partitioned-job-properties[0].retry-limit=5 fineract.remote-job-message-handler.spring-events.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_SPRING_EVENTS_ENABLED:true} fineract.remote-job-message-handler.jms.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_ENABLED:false} diff --git a/fineract-provider/src/test/resources/features/infrastructure/infrastructure.springbatch.feature b/fineract-provider/src/test/resources/features/infrastructure/infrastructure.springbatch.feature new file mode 100644 index 000000000..02088dccc --- /dev/null +++ b/fineract-provider/src/test/resources/features/infrastructure/infrastructure.springbatch.feature @@ -0,0 +1,40 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +Feature: SpringBatch Infrastructure + + @springbatch + Scenario: Verify that spring batch properties are read correctly for LOAN_COB + Given Property Service is initialized + When partition size is fetched for "LOAN_COB" + When chunk size is fetched for "LOAN_COB" + When retry limit is fetched for "LOAN_COB" + Then partition size is 100 + Then chunk size is 100 + Then retry limit is 5 + + @springbatch + Scenario: Verify that spring batch default properties are read correctly for non-existing job + Given Property Service is initialized + When partition size is fetched for "INVALID_JOB" + When chunk size is fetched for "INVALID_JOB" + When retry limit is fetched for "INVALID_JOB" + Then partition size is 1 + Then chunk size is 1 + Then retry limit is 1