New Instance type: Batch Manager

This commit is contained in:
taskain7
2022-06-28 15:32:17 +02:00
committed by Arnold Gálovics
parent 67850e3889
commit ffb9147770
16 changed files with 62 additions and 57 deletions
@@ -55,18 +55,11 @@ public class FineractProperties {
private boolean readEnabled; private boolean readEnabled;
private boolean writeEnabled; private boolean writeEnabled;
private boolean batchEnabled; private boolean batchWorkerEnabled;
private boolean batchManagerEnabled;
public boolean isReadOnlyMode() { public boolean isReadOnlyMode() {
return readEnabled && !writeEnabled && !batchEnabled; return readEnabled && !writeEnabled && !batchWorkerEnabled && !batchManagerEnabled;
}
public boolean isWriteOnlyMode() {
return !readEnabled && writeEnabled && !batchEnabled;
}
public boolean isBatchOnlyMode() {
return !readEnabled && !writeEnabled && batchEnabled;
} }
} }
} }
@@ -71,7 +71,8 @@ public class InstanceModeApiResource implements InitializingBean {
log.warn("------------------------------------------------------------"); log.warn("------------------------------------------------------------");
fineractProperties.getMode().setReadEnabled(request.isReadEnabled()); fineractProperties.getMode().setReadEnabled(request.isReadEnabled());
fineractProperties.getMode().setWriteEnabled(request.isWriteEnabled()); fineractProperties.getMode().setWriteEnabled(request.isWriteEnabled());
fineractProperties.getMode().setBatchEnabled(request.isBatchEnabled()); fineractProperties.getMode().setBatchWorkerEnabled(request.isBatchWorkerEnabled());
fineractProperties.getMode().setBatchManagerEnabled(request.isBatchManagerEnabled());
return Response.ok().build(); return Response.ok().build();
} }
} }
@@ -34,6 +34,8 @@ public class InstanceModeApiResourceSwagger {
@Schema(required = true, example = "true") @Schema(required = true, example = "true")
public boolean writeEnabled; public boolean writeEnabled;
@Schema(required = true, example = "true") @Schema(required = true, example = "true")
public boolean batchEnabled; public boolean batchWorkerEnabled;
@Schema(required = true, example = "true")
public boolean batchManagerEnabled;
} }
} }
@@ -44,7 +44,7 @@ import org.springframework.web.filter.OncePerRequestFilter;
public class FineractInstanceModeApiFilter extends OncePerRequestFilter { public class FineractInstanceModeApiFilter extends OncePerRequestFilter {
private static final List<ExceptionListItem> EXCEPTION_LIST = List.of( private static final List<ExceptionListItem> EXCEPTION_LIST = List.of(
item(FineractProperties.FineractModeProperties::isBatchEnabled, pi -> pi.startsWith("/jobs")), item(FineractProperties.FineractModeProperties::isBatchManagerEnabled, pi -> pi.startsWith("/jobs")),
item(p -> true, pi -> pi.startsWith("/instance-mode"))); item(p -> true, pi -> pi.startsWith("/instance-mode")));
private final FineractProperties fineractProperties; private final FineractProperties fineractProperties;
@@ -133,7 +133,7 @@ public class SchedulerJobApiResource {
@QueryParam(SchedulerJobApiConstants.COMMAND) @Parameter(description = "command") final String commandParam) { @QueryParam(SchedulerJobApiConstants.COMMAND) @Parameter(description = "command") final String commandParam) {
// check the logged in user have permissions to execute scheduler jobs // check the logged in user have permissions to execute scheduler jobs
Response response; Response response;
if (fineractProperties.getMode().isBatchEnabled()) { if (fineractProperties.getMode().isBatchManagerEnabled()) {
final boolean hasNotPermission = this.context.authenticatedUser().hasNotPermissionForAnyOf("ALL_FUNCTIONS", final boolean hasNotPermission = this.context.authenticatedUser().hasNotPermissionForAnyOf("ALL_FUNCTIONS",
"EXECUTEJOB_SCHEDULER"); "EXECUTEJOB_SCHEDULER");
if (hasNotPermission) { if (hasNotPermission) {
@@ -98,7 +98,7 @@ public class JobRegisterServiceImpl implements JobRegisterService, ApplicationLi
@PostConstruct @PostConstruct
public void loadAllJobs() { public void loadAllJobs() {
// If the instance is not Batch Enabled will not load the Jobs // If the instance is not Batch Enabled will not load the Jobs
if (!fineractProperties.getMode().isBatchEnabled()) { if (!fineractProperties.getMode().isBatchManagerEnabled()) {
return; return;
} }
final List<FineractPlatformTenant> allTenants = this.tenantDetailsService.findAllTenants(); final List<FineractPlatformTenant> allTenants = this.tenantDetailsService.findAllTenants();
@@ -37,7 +37,8 @@ fineract.tenant.description=${FINERACT_DEFAULT_TENANTDB_DESCRIPTION:Default Demo
fineract.mode.read-enabled=${FINERACT_MODE_READ_ENABLED:true} fineract.mode.read-enabled=${FINERACT_MODE_READ_ENABLED:true}
fineract.mode.write-enabled=${FINERACT_MODE_WRITE_ENABLED:true} fineract.mode.write-enabled=${FINERACT_MODE_WRITE_ENABLED:true}
fineract.mode.batch-enabled=${FINERACT_MODE_BATCH_ENABLED:true} fineract.mode.batch-worker-enabled=${FINERACT_MODE_BATCH_WORKER_ENABLED:true}
fineract.mode.batch-manager-enabled=${FINERACT_MODE_BATCH_MANAGER_ENABLED:true}
management.health.jms.enabled=false management.health.jms.enabled=false
@@ -147,7 +147,7 @@ public class DataSourcePerTenantServiceFactoryTest {
void testCreateNewDataSourceFor_ShouldUseNormalConfiguration_WhenInAllMode() { void testCreateNewDataSourceFor_ShouldUseNormalConfiguration_WhenInAllMode() {
// given // given
FineractProperties.FineractModeProperties modeProperties = createModeProps(MASTER_DB_AUTO_COMMIT_ENABLED, FineractProperties.FineractModeProperties modeProperties = createModeProps(MASTER_DB_AUTO_COMMIT_ENABLED,
MASTER_DB_AUTO_COMMIT_ENABLED, MASTER_DB_AUTO_COMMIT_ENABLED); MASTER_DB_AUTO_COMMIT_ENABLED, MASTER_DB_AUTO_COMMIT_ENABLED, MASTER_DB_AUTO_COMMIT_ENABLED);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
// when // when
@@ -173,7 +173,7 @@ public class DataSourcePerTenantServiceFactoryTest {
@Test @Test
void testCreateNewDataSourceFor_ShouldUseReadOnlyConfiguration_WhenInReadOnlyMode() { void testCreateNewDataSourceFor_ShouldUseReadOnlyConfiguration_WhenInReadOnlyMode() {
// given // given
FineractProperties.FineractModeProperties modeProperties = createModeProps(true, false, false); FineractProperties.FineractModeProperties modeProperties = createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
// when // when
@@ -199,7 +199,7 @@ public class DataSourcePerTenantServiceFactoryTest {
@Test @Test
void testCreateNewDataSourceFor_ShouldUseNormalConfiguration_WhenInBatchOnlyMode() { void testCreateNewDataSourceFor_ShouldUseNormalConfiguration_WhenInBatchOnlyMode() {
// given // given
FineractProperties.FineractModeProperties modeProperties = createModeProps(false, false, true); FineractProperties.FineractModeProperties modeProperties = createModeProps(false, false, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
// when // when
@@ -222,11 +222,13 @@ public class DataSourcePerTenantServiceFactoryTest {
assertEquals(MASTER_DB_AUTO_COMMIT_ENABLED, hikariConfig.isAutoCommit()); assertEquals(MASTER_DB_AUTO_COMMIT_ENABLED, hikariConfig.isAutoCommit());
} }
private FineractProperties.FineractModeProperties createModeProps(boolean readEnabled, boolean writeEnabled, boolean batchEnabled) { private FineractProperties.FineractModeProperties createModeProps(boolean readEnabled, boolean writeEnabled, boolean batchWorkerEnabled,
boolean batchManagerEnabled) {
FineractProperties.FineractModeProperties modeProperties = new FineractProperties.FineractModeProperties(); FineractProperties.FineractModeProperties modeProperties = new FineractProperties.FineractModeProperties();
modeProperties.setReadEnabled(readEnabled); modeProperties.setReadEnabled(readEnabled);
modeProperties.setWriteEnabled(writeEnabled); modeProperties.setWriteEnabled(writeEnabled);
modeProperties.setBatchEnabled(batchEnabled); modeProperties.setBatchWorkerEnabled(batchWorkerEnabled);
modeProperties.setBatchManagerEnabled(batchManagerEnabled);
return modeProperties; return modeProperties;
} }
@@ -31,7 +31,8 @@ public class InstanceTypeStepDefinitions implements En {
Given("Set every Fineract instance type to false", () -> { Given("Set every Fineract instance type to false", () -> {
fineractProperties.getMode().setWriteEnabled(false); fineractProperties.getMode().setWriteEnabled(false);
fineractProperties.getMode().setReadEnabled(false); fineractProperties.getMode().setReadEnabled(false);
fineractProperties.getMode().setBatchEnabled(false); fineractProperties.getMode().setBatchWorkerEnabled(false);
fineractProperties.getMode().setBatchManagerEnabled(false);
}); });
Given("Fineract instance is a write instance", () -> { Given("Fineract instance is a write instance", () -> {
fineractProperties.getMode().setWriteEnabled(true); fineractProperties.getMode().setWriteEnabled(true);
@@ -39,8 +40,8 @@ public class InstanceTypeStepDefinitions implements En {
Given("Fineract instance is a read instance", () -> { Given("Fineract instance is a read instance", () -> {
fineractProperties.getMode().setReadEnabled(true); fineractProperties.getMode().setReadEnabled(true);
}); });
Given("Fineract instance is a batch instance", () -> { Given("Fineract instance is a batch manager instance", () -> {
fineractProperties.getMode().setBatchEnabled(true); fineractProperties.getMode().setBatchManagerEnabled(true);
}); });
} }
} }
@@ -27,11 +27,12 @@ public final class InstanceModeMock {
} }
public static FineractProperties.FineractModeProperties createModeProps(boolean readEnabled, boolean writeEnabled, public static FineractProperties.FineractModeProperties createModeProps(boolean readEnabled, boolean writeEnabled,
boolean batchEnabled) { boolean batchWorkerEnabled, boolean batchManagerEnabled) {
FineractProperties.FineractModeProperties modeProperties = new FineractProperties.FineractModeProperties(); FineractProperties.FineractModeProperties modeProperties = new FineractProperties.FineractModeProperties();
modeProperties.setReadEnabled(readEnabled); modeProperties.setReadEnabled(readEnabled);
modeProperties.setWriteEnabled(writeEnabled); modeProperties.setWriteEnabled(writeEnabled);
modeProperties.setBatchEnabled(batchEnabled); modeProperties.setBatchWorkerEnabled(batchWorkerEnabled);
modeProperties.setBatchManagerEnabled(batchManagerEnabled);
return modeProperties; return modeProperties;
} }
} }
@@ -71,7 +71,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldLetReadApisThrough_WhenFineractIsInAllModeAndIsGetApi() throws ServletException, IOException { void testDoFilterInternal_ShouldLetReadApisThrough_WhenFineractIsInAllModeAndIsGetApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, true, true); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, true, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name()); given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getPathInfo()).willReturn("/loans"); given(request.getPathInfo()).willReturn("/loans");
@@ -84,7 +84,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldLetReadApisThrough_WhenFineractIsInReadOnlyModeAndIsGetApi() throws ServletException, IOException { void testDoFilterInternal_ShouldLetReadApisThrough_WhenFineractIsInReadOnlyModeAndIsGetApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name()); given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getPathInfo()).willReturn("/loans"); given(request.getPathInfo()).willReturn("/loans");
@@ -98,7 +98,7 @@ class FineractInstanceModeApiFilterTest {
void testDoFilterInternal_ShouldLetActuatorApisThrough_WhenFineractIsInReadOnlyModeAndIsHealthApi() void testDoFilterInternal_ShouldLetActuatorApisThrough_WhenFineractIsInReadOnlyModeAndIsHealthApi()
throws ServletException, IOException { throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name()); given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getServletPath()).willReturn("/actuator/health"); given(request.getServletPath()).willReturn("/actuator/health");
@@ -112,7 +112,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldNotLetWriteApisThrough_WhenFineractIsInReadOnlyModeAndIsPostApi() throws ServletException, IOException { void testDoFilterInternal_ShouldNotLetWriteApisThrough_WhenFineractIsInReadOnlyModeAndIsPostApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name()); given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/loans"); given(request.getPathInfo()).willReturn("/loans");
@@ -126,7 +126,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldNotLetBatchApisThrough_WhenFineractIsInReadOnlyModeAndIsJobsApi() throws ServletException, IOException { void testDoFilterInternal_ShouldNotLetBatchApisThrough_WhenFineractIsInReadOnlyModeAndIsJobsApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name()); given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/jobs/1"); given(request.getPathInfo()).willReturn("/jobs/1");
@@ -140,7 +140,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldLetReadApisThrough_WhenFineractIsInWriteModeAndIsGetApi() throws ServletException, IOException { void testDoFilterInternal_ShouldLetReadApisThrough_WhenFineractIsInWriteModeAndIsGetApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name()); given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getPathInfo()).willReturn("/loans"); given(request.getPathInfo()).willReturn("/loans");
@@ -153,7 +153,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldLetWriteApisThrough_WhenFineractIsInWriteModeAndIsPostApi() throws ServletException, IOException { void testDoFilterInternal_ShouldLetWriteApisThrough_WhenFineractIsInWriteModeAndIsPostApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name()); given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/loans"); given(request.getPathInfo()).willReturn("/loans");
@@ -166,7 +166,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldLetWriteApisThrough_WhenFineractIsInWriteModeAndIsPutApi() throws ServletException, IOException { void testDoFilterInternal_ShouldLetWriteApisThrough_WhenFineractIsInWriteModeAndIsPutApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.PUT.name()); given(request.getMethod()).willReturn(HttpMethod.PUT.name());
given(request.getPathInfo()).willReturn("/loans/1"); given(request.getPathInfo()).willReturn("/loans/1");
@@ -179,7 +179,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldLetActuatorApisThrough_WhenFineractIsInWriteModeAndIsHelathApi() throws ServletException, IOException { void testDoFilterInternal_ShouldLetActuatorApisThrough_WhenFineractIsInWriteModeAndIsHelathApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name()); given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getServletPath()).willReturn("/actuator/health"); given(request.getServletPath()).willReturn("/actuator/health");
@@ -193,7 +193,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldNotLetBatchApisThrough_WhenFineractIsInWriteModeAndIsJobsApi() throws ServletException, IOException { void testDoFilterInternal_ShouldNotLetBatchApisThrough_WhenFineractIsInWriteModeAndIsJobsApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name()); given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/jobs/1"); given(request.getPathInfo()).willReturn("/jobs/1");
@@ -207,7 +207,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldLetBatchApisThrough_WhenFineractIsInBatchModeAndIsJobsApi() throws ServletException, IOException { void testDoFilterInternal_ShouldLetBatchApisThrough_WhenFineractIsInBatchModeAndIsJobsApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name()); given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/jobs/1"); given(request.getPathInfo()).willReturn("/jobs/1");
@@ -221,7 +221,7 @@ class FineractInstanceModeApiFilterTest {
void testDoFilterInternal_ShouldLetBatchApisThrough_WhenFineractIsInBatchModeAndIsListingJobsApi() void testDoFilterInternal_ShouldLetBatchApisThrough_WhenFineractIsInBatchModeAndIsListingJobsApi()
throws ServletException, IOException { throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name()); given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getPathInfo()).willReturn("/jobs"); given(request.getPathInfo()).willReturn("/jobs");
@@ -234,7 +234,7 @@ class FineractInstanceModeApiFilterTest {
@Test @Test
void testDoFilterInternal_ShouldLetActuatorApisThrough_WhenFineractIsInBatchModeAndIsHealthApi() throws ServletException, IOException { void testDoFilterInternal_ShouldLetActuatorApisThrough_WhenFineractIsInBatchModeAndIsHealthApi() throws ServletException, IOException {
// given // given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true); FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties); given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name()); given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getServletPath()).willReturn("/actuator/health"); given(request.getServletPath()).willReturn("/actuator/health");
@@ -36,7 +36,7 @@ Feature: Core Infrastructure
@infrastructure @infrastructure
Scenario: Verify that schema migration is not executed when the Fineract instance is a batch instance Scenario: Verify that schema migration is not executed when the Fineract instance is a batch instance
Given Set every Fineract instance type to false Given Set every Fineract instance type to false
Given Fineract instance is a batch instance Given Fineract instance is a batch manager instance
Given Liquibase is enabled with a default tenant Given Liquibase is enabled with a default tenant
When The database migration process is executed When The database migration process is executed
Then The database migration did not do anything, because it is not a write instance Then The database migration did not do anything, because it is not a write instance
@@ -60,7 +60,7 @@ public class InstanceModeIntegrationTest {
jobId = schedulerJobHelper.getSchedulerJobIdByName(jobName); jobId = schedulerJobHelper.getSchedulerJobIdByName(jobName);
} }
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchEnabled = false) @ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test @Test
public void testGetHeadOfficeWorks_WhenInstanceModeIsReadOnly() { public void testGetHeadOfficeWorks_WhenInstanceModeIsReadOnly() {
// given // given
@@ -70,7 +70,7 @@ public class InstanceModeIntegrationTest {
assertNotNull(result); assertNotNull(result);
} }
@ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchEnabled = false) @ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test @Test
public void testGetHeadOfficeWorks_WhenInstanceModeIsWriteOnly() { public void testGetHeadOfficeWorks_WhenInstanceModeIsWriteOnly() {
// given // given
@@ -80,7 +80,7 @@ public class InstanceModeIntegrationTest {
assertNotNull(result); assertNotNull(result);
} }
@ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchEnabled = true) @ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchWorkerEnabled = true, batchManagerEnabled = true)
@Test @Test
public void testGetHeadOfficeDoesntWork_WhenInstanceModeIsBatchOnly() { public void testGetHeadOfficeDoesntWork_WhenInstanceModeIsBatchOnly() {
// given // given
@@ -89,7 +89,7 @@ public class InstanceModeIntegrationTest {
// then no exception is thrown // then no exception is thrown
} }
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchEnabled = false) @ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test @Test
public void testCreateClientDoesntWork_WhenReadOnly() { public void testCreateClientDoesntWork_WhenReadOnly() {
// given // given
@@ -99,7 +99,7 @@ public class InstanceModeIntegrationTest {
// then no exception thrown // then no exception thrown
} }
@ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchEnabled = false) @ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test @Test
public void testCreateClientWorks_WhenWriteOnly() { public void testCreateClientWorks_WhenWriteOnly() {
// given // given
@@ -110,7 +110,7 @@ public class InstanceModeIntegrationTest {
assertNotNull(result); assertNotNull(result);
} }
@ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchEnabled = true) @ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchWorkerEnabled = true, batchManagerEnabled = true)
@Test @Test
public void testCreateClientDoesntWork_WhenBatchOnly() { public void testCreateClientDoesntWork_WhenBatchOnly() {
// given // given
@@ -120,7 +120,7 @@ public class InstanceModeIntegrationTest {
// then no exception thrown // then no exception thrown
} }
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchEnabled = false) @ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test @Test
public void testRunSchedulerJobDoesntWork_WhenReadOnly() { public void testRunSchedulerJobDoesntWork_WhenReadOnly() {
// given // given
@@ -129,7 +129,7 @@ public class InstanceModeIntegrationTest {
// then no exception thrown // then no exception thrown
} }
@ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchEnabled = false) @ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test @Test
public void testRunSchedulerJobDoesntWork_WhenWriteOnly() { public void testRunSchedulerJobDoesntWork_WhenWriteOnly() {
// given // given
@@ -138,7 +138,7 @@ public class InstanceModeIntegrationTest {
// then no exception thrown // then no exception thrown
} }
@ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchEnabled = true) @ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchWorkerEnabled = true, batchManagerEnabled = true)
@Test @Test
public void testRunSchedulerJobWorks_WhenBatchOnly() { public void testRunSchedulerJobWorks_WhenBatchOnly() {
// given // given
@@ -32,5 +32,7 @@ public @interface ConfigureInstanceMode {
boolean writeEnabled(); boolean writeEnabled();
boolean batchEnabled(); boolean batchWorkerEnabled();
boolean batchManagerEnabled();
} }
@@ -31,9 +31,9 @@ public class InstanceModeHelper {
private static final Gson GSON = new JSON().getGson(); private static final Gson GSON = new JSON().getGson();
public static void changeMode(RequestSpecification requestSpec, ResponseSpecification responseSpec, boolean readEnabled, public static void changeMode(RequestSpecification requestSpec, ResponseSpecification responseSpec, boolean readEnabled,
boolean writeEnabled, boolean batchEnabled) { boolean writeEnabled, boolean batchWorkerEnabled, boolean batchManagerEnabled) {
ChangeInstanceModeRequest request = new ChangeInstanceModeRequest().readEnabled(readEnabled).writeEnabled(writeEnabled) ChangeInstanceModeRequest request = new ChangeInstanceModeRequest().readEnabled(readEnabled).writeEnabled(writeEnabled)
.batchEnabled(batchEnabled); .batchWorkerEnabled(batchWorkerEnabled).batchManagerEnabled(batchManagerEnabled);
String requestStr = GSON.toJson(request); String requestStr = GSON.toJson(request);
Utils.performServerPut(requestSpec, responseSpec, "/fineract-provider/api/v1/instance-mode?" + Utils.TENANT_IDENTIFIER, requestStr); Utils.performServerPut(requestSpec, responseSpec, "/fineract-provider/api/v1/instance-mode?" + Utils.TENANT_IDENTIFIER, requestStr);
} }
@@ -42,8 +42,9 @@ public class InstanceModeSupportExtension implements BeforeTestExecutionCallback
if (annotation != null) { if (annotation != null) {
boolean readEnabled = annotation.readEnabled(); boolean readEnabled = annotation.readEnabled();
boolean writeEnabled = annotation.writeEnabled(); boolean writeEnabled = annotation.writeEnabled();
boolean batchEnabled = annotation.batchEnabled(); boolean batchWorkerEnabled = annotation.batchWorkerEnabled();
changeInstanceMode(context, readEnabled, writeEnabled, batchEnabled); boolean batchManagerEnabled = annotation.batchWorkerEnabled();
changeInstanceMode(context, readEnabled, writeEnabled, batchWorkerEnabled, batchManagerEnabled);
} }
}); });
} }
@@ -53,12 +54,13 @@ public class InstanceModeSupportExtension implements BeforeTestExecutionCallback
context.getTestMethod().ifPresent(m -> { context.getTestMethod().ifPresent(m -> {
ConfigureInstanceMode annotation = m.getAnnotation(ConfigureInstanceMode.class); ConfigureInstanceMode annotation = m.getAnnotation(ConfigureInstanceMode.class);
if (annotation != null) { if (annotation != null) {
changeInstanceMode(context, true, true, true); changeInstanceMode(context, true, true, true, true);
} }
}); });
} }
private void changeInstanceMode(ExtensionContext extensionContext, boolean readEnabled, boolean writeEnabled, boolean batchEnabled) { private void changeInstanceMode(ExtensionContext extensionContext, boolean readEnabled, boolean writeEnabled,
boolean batchWorkerEnabled, boolean batchManagerEnabled) {
Store store = extensionContext.getStore(INSTANCE_MODE_NAMESPACE); Store store = extensionContext.getStore(INSTANCE_MODE_NAMESPACE);
String authKey = store.getOrComputeIfAbsent(AUTH_KEY, k -> Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(), String authKey = store.getOrComputeIfAbsent(AUTH_KEY, k -> Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(),
String.class); String.class);
@@ -66,6 +68,6 @@ public class InstanceModeSupportExtension implements BeforeTestExecutionCallback
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
requestSpec.header("Authorization", "Basic " + authKey); requestSpec.header("Authorization", "Basic " + authKey);
InstanceModeHelper.changeMode(requestSpec, responseSpec, readEnabled, writeEnabled, batchEnabled); InstanceModeHelper.changeMode(requestSpec, responseSpec, readEnabled, writeEnabled, batchWorkerEnabled, batchManagerEnabled);
} }
} }