FINERACT-2081: async liquibase
This commit is contained in:
committed by
Arnold Gálovics
parent
4e3bcbf970
commit
dcb18d8f5e
+3
@@ -282,6 +282,9 @@ public class FineractProperties {
|
||||
|
||||
private int defaultTaskExecutorCorePoolSize;
|
||||
private int defaultTaskExecutorMaxPoolSize;
|
||||
private int tenantUpgradeTaskExecutorCorePoolSize;
|
||||
private int tenantUpgradeTaskExecutorMaxPoolSize;
|
||||
private int tenantUpgradeTaskExecutorQueueCapacity;
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
+33
-2
@@ -21,10 +21,15 @@ package org.apache.fineract.infrastructure.core.service.migration;
|
||||
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Function;
|
||||
import javax.sql.DataSource;
|
||||
import liquibase.Scope;
|
||||
import liquibase.ThreadLocalScopeManager;
|
||||
import liquibase.change.custom.CustomTaskChange;
|
||||
import liquibase.exception.LiquibaseException;
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
@@ -37,6 +42,7 @@ import org.apache.fineract.infrastructure.core.service.tenant.TenantDetailsServi
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -76,6 +82,7 @@ public class TenantDatabaseUpgradeService implements InitializingBean {
|
||||
}
|
||||
}
|
||||
try {
|
||||
Scope.setScopeManager(new ThreadLocalScopeManager());
|
||||
upgradeTenantStore();
|
||||
upgradeIndividualTenants();
|
||||
} catch (LiquibaseException e) {
|
||||
@@ -121,17 +128,41 @@ public class TenantDatabaseUpgradeService implements InitializingBean {
|
||||
|
||||
}
|
||||
|
||||
private void upgradeIndividualTenants() throws LiquibaseException {
|
||||
private void upgradeIndividualTenants() {
|
||||
log.info("Upgrading all tenants");
|
||||
List<FineractPlatformTenant> tenants = tenantDetailsService.findAllTenants();
|
||||
List<Future<String>> futures = new ArrayList<>();
|
||||
final ThreadPoolTaskExecutor tenantUpgradeThreadPoolTaskExecutor = createTenantUpgradeThreadPoolTaskExecutor();
|
||||
if (isNotEmpty(tenants)) {
|
||||
for (FineractPlatformTenant tenant : tenants) {
|
||||
upgradeIndividualTenant(tenant);
|
||||
futures.add(tenantUpgradeThreadPoolTaskExecutor.submit(() -> {
|
||||
upgradeIndividualTenant(tenant);
|
||||
return tenant.getName();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
for (Future<String> future : futures) {
|
||||
future.get();
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
} finally {
|
||||
tenantUpgradeThreadPoolTaskExecutor.shutdown();
|
||||
}
|
||||
log.info("Tenant upgrades have finished");
|
||||
}
|
||||
|
||||
private ThreadPoolTaskExecutor createTenantUpgradeThreadPoolTaskExecutor() {
|
||||
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
|
||||
threadPoolTaskExecutor.setCorePoolSize(fineractProperties.getTaskExecutor().getTenantUpgradeTaskExecutorCorePoolSize());
|
||||
threadPoolTaskExecutor.setMaxPoolSize(fineractProperties.getTaskExecutor().getTenantUpgradeTaskExecutorMaxPoolSize());
|
||||
threadPoolTaskExecutor.setQueueCapacity(fineractProperties.getTaskExecutor().getTenantUpgradeTaskExecutorQueueCapacity());
|
||||
threadPoolTaskExecutor.initialize();
|
||||
return threadPoolTaskExecutor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade each tenant's database
|
||||
*
|
||||
|
||||
@@ -131,6 +131,9 @@ fineract.events.external.producer.kafka.admin.extra-properties=${FINERACT_EXTERN
|
||||
|
||||
fineract.task-executor.default-task-executor-core-pool-size=${FINERACT_DEFAULT_TASK_EXECUTOR_CORE_POOL_SIZE:10}
|
||||
fineract.task-executor.default-task-executor-max-pool-size=${FINERACT_DEFAULT_TASK_EXECUTOR_MAX_POOL_SIZE:100}
|
||||
fineract.task-executor.tenant-upgrade-task-executor-core-pool-size=${FINERACT_TENANT_UPGRADE_TASK_EXECUTOR_CORE_POOL_SIZE:1}
|
||||
fineract.task-executor.tenant-upgrade-task-executor-max-pool-size=${FINERACT_TENANT_UPGRADE_TASK_EXECUTOR_MAX_POOL_SIZE:1}
|
||||
fineract.task-executor.tenant-upgrade-task-executor-queue-capacity=${FINERACT_TENANT_UPGRADE_TASK_EXECUTOR_QUEUE_CAPACITY:100}
|
||||
|
||||
fineract.idempotency-key-header-name=${FINERACT_IDEMPOTENCY_KEY_HEADER_NAME:Idempotency-Key}
|
||||
|
||||
|
||||
+2
@@ -104,6 +104,8 @@ public class LiquibaseStepDefinitions implements En {
|
||||
tenantDatabaseUpgradeService.afterPropertiesSet();
|
||||
} catch (SchemaUpgradeNeededException e) {
|
||||
executionException = e;
|
||||
} catch (RuntimeException e) {
|
||||
executionException = (SchemaUpgradeNeededException) e.getCause().getCause();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -65,6 +65,9 @@ fineract.events.external.producer.jms.thread-pool-task-executor-max-pool-size=${
|
||||
|
||||
fineract.task-executor.default-task-executor-core-pool-size=${FINERACT_DEFAULT_TASK_EXECUTOR_CORE_POOL_SIZE:10}
|
||||
fineract.task-executor.default-task-executor-max-pool-size=${FINERACT_DEFAULT_TASK_EXECUTOR_MAX_POOL_SIZE:100}
|
||||
fineract.task-executor.tenant-upgrade-task-executor-core-pool-size=${FINERACT_TENANT_UPGRADE_TASK_EXECUTOR_CORE_POOL_SIZE:1}
|
||||
fineract.task-executor.tenant-upgrade-task-executor-max-pool-size=${FINERACT_TENANT_UPGRADE_TASK_EXECUTOR_MAX_POOL_SIZE:1}
|
||||
fineract.task-executor.tenant-upgrade-task-executor-queue-capacity=${FINERACT_TENANT_UPGRADE_TASK_EXECUTOR_QUEUE_CAPACITY:100}
|
||||
|
||||
fineract.loan.transactionprocessor.creocore.enabled=true
|
||||
fineract.loan.transactionprocessor.early-repayment.enabled=true
|
||||
|
||||
Reference in New Issue
Block a user