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 writeEnabled;
private boolean batchEnabled;
private boolean batchWorkerEnabled;
private boolean batchManagerEnabled;
public boolean isReadOnlyMode() {
return readEnabled && !writeEnabled && !batchEnabled;
}
public boolean isWriteOnlyMode() {
return !readEnabled && writeEnabled && !batchEnabled;
}
public boolean isBatchOnlyMode() {
return !readEnabled && !writeEnabled && batchEnabled;
return readEnabled && !writeEnabled && !batchWorkerEnabled && !batchManagerEnabled;
}
}
}
@@ -71,7 +71,8 @@ public class InstanceModeApiResource implements InitializingBean {
log.warn("------------------------------------------------------------");
fineractProperties.getMode().setReadEnabled(request.isReadEnabled());
fineractProperties.getMode().setWriteEnabled(request.isWriteEnabled());
fineractProperties.getMode().setBatchEnabled(request.isBatchEnabled());
fineractProperties.getMode().setBatchWorkerEnabled(request.isBatchWorkerEnabled());
fineractProperties.getMode().setBatchManagerEnabled(request.isBatchManagerEnabled());
return Response.ok().build();
}
}
@@ -34,6 +34,8 @@ public class InstanceModeApiResourceSwagger {
@Schema(required = true, example = "true")
public boolean writeEnabled;
@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 {
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")));
private final FineractProperties fineractProperties;
@@ -133,7 +133,7 @@ public class SchedulerJobApiResource {
@QueryParam(SchedulerJobApiConstants.COMMAND) @Parameter(description = "command") final String commandParam) {
// check the logged in user have permissions to execute scheduler jobs
Response response;
if (fineractProperties.getMode().isBatchEnabled()) {
if (fineractProperties.getMode().isBatchManagerEnabled()) {
final boolean hasNotPermission = this.context.authenticatedUser().hasNotPermissionForAnyOf("ALL_FUNCTIONS",
"EXECUTEJOB_SCHEDULER");
if (hasNotPermission) {
@@ -98,7 +98,7 @@ public class JobRegisterServiceImpl implements JobRegisterService, ApplicationLi
@PostConstruct
public void loadAllJobs() {
// If the instance is not Batch Enabled will not load the Jobs
if (!fineractProperties.getMode().isBatchEnabled()) {
if (!fineractProperties.getMode().isBatchManagerEnabled()) {
return;
}
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.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
@@ -147,7 +147,7 @@ public class DataSourcePerTenantServiceFactoryTest {
void testCreateNewDataSourceFor_ShouldUseNormalConfiguration_WhenInAllMode() {
// given
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);
// when
@@ -173,7 +173,7 @@ public class DataSourcePerTenantServiceFactoryTest {
@Test
void testCreateNewDataSourceFor_ShouldUseReadOnlyConfiguration_WhenInReadOnlyMode() {
// given
FineractProperties.FineractModeProperties modeProperties = createModeProps(true, false, false);
FineractProperties.FineractModeProperties modeProperties = createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
// when
@@ -199,7 +199,7 @@ public class DataSourcePerTenantServiceFactoryTest {
@Test
void testCreateNewDataSourceFor_ShouldUseNormalConfiguration_WhenInBatchOnlyMode() {
// given
FineractProperties.FineractModeProperties modeProperties = createModeProps(false, false, true);
FineractProperties.FineractModeProperties modeProperties = createModeProps(false, false, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties);
// when
@@ -222,11 +222,13 @@ public class DataSourcePerTenantServiceFactoryTest {
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();
modeProperties.setReadEnabled(readEnabled);
modeProperties.setWriteEnabled(writeEnabled);
modeProperties.setBatchEnabled(batchEnabled);
modeProperties.setBatchWorkerEnabled(batchWorkerEnabled);
modeProperties.setBatchManagerEnabled(batchManagerEnabled);
return modeProperties;
}
@@ -31,7 +31,8 @@ public class InstanceTypeStepDefinitions implements En {
Given("Set every Fineract instance type to false", () -> {
fineractProperties.getMode().setWriteEnabled(false);
fineractProperties.getMode().setReadEnabled(false);
fineractProperties.getMode().setBatchEnabled(false);
fineractProperties.getMode().setBatchWorkerEnabled(false);
fineractProperties.getMode().setBatchManagerEnabled(false);
});
Given("Fineract instance is a write instance", () -> {
fineractProperties.getMode().setWriteEnabled(true);
@@ -39,8 +40,8 @@ public class InstanceTypeStepDefinitions implements En {
Given("Fineract instance is a read instance", () -> {
fineractProperties.getMode().setReadEnabled(true);
});
Given("Fineract instance is a batch instance", () -> {
fineractProperties.getMode().setBatchEnabled(true);
Given("Fineract instance is a batch manager instance", () -> {
fineractProperties.getMode().setBatchManagerEnabled(true);
});
}
}
@@ -27,11 +27,12 @@ public final class InstanceModeMock {
}
public static FineractProperties.FineractModeProperties createModeProps(boolean readEnabled, boolean writeEnabled,
boolean batchEnabled) {
boolean batchWorkerEnabled, boolean batchManagerEnabled) {
FineractProperties.FineractModeProperties modeProperties = new FineractProperties.FineractModeProperties();
modeProperties.setReadEnabled(readEnabled);
modeProperties.setWriteEnabled(writeEnabled);
modeProperties.setBatchEnabled(batchEnabled);
modeProperties.setBatchWorkerEnabled(batchWorkerEnabled);
modeProperties.setBatchManagerEnabled(batchManagerEnabled);
return modeProperties;
}
}
@@ -71,7 +71,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldLetReadApisThrough_WhenFineractIsInAllModeAndIsGetApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, true, true);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, true, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getPathInfo()).willReturn("/loans");
@@ -84,7 +84,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldLetReadApisThrough_WhenFineractIsInReadOnlyModeAndIsGetApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getPathInfo()).willReturn("/loans");
@@ -98,7 +98,7 @@ class FineractInstanceModeApiFilterTest {
void testDoFilterInternal_ShouldLetActuatorApisThrough_WhenFineractIsInReadOnlyModeAndIsHealthApi()
throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getServletPath()).willReturn("/actuator/health");
@@ -112,7 +112,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldNotLetWriteApisThrough_WhenFineractIsInReadOnlyModeAndIsPostApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/loans");
@@ -126,7 +126,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldNotLetBatchApisThrough_WhenFineractIsInReadOnlyModeAndIsJobsApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(true, false, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/jobs/1");
@@ -140,7 +140,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldLetReadApisThrough_WhenFineractIsInWriteModeAndIsGetApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getPathInfo()).willReturn("/loans");
@@ -153,7 +153,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldLetWriteApisThrough_WhenFineractIsInWriteModeAndIsPostApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/loans");
@@ -166,7 +166,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldLetWriteApisThrough_WhenFineractIsInWriteModeAndIsPutApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.PUT.name());
given(request.getPathInfo()).willReturn("/loans/1");
@@ -179,7 +179,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldLetActuatorApisThrough_WhenFineractIsInWriteModeAndIsHelathApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getServletPath()).willReturn("/actuator/health");
@@ -193,7 +193,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldNotLetBatchApisThrough_WhenFineractIsInWriteModeAndIsJobsApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, true, false, false);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/jobs/1");
@@ -207,7 +207,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldLetBatchApisThrough_WhenFineractIsInBatchModeAndIsJobsApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.POST.name());
given(request.getPathInfo()).willReturn("/jobs/1");
@@ -221,7 +221,7 @@ class FineractInstanceModeApiFilterTest {
void testDoFilterInternal_ShouldLetBatchApisThrough_WhenFineractIsInBatchModeAndIsListingJobsApi()
throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getPathInfo()).willReturn("/jobs");
@@ -234,7 +234,7 @@ class FineractInstanceModeApiFilterTest {
@Test
void testDoFilterInternal_ShouldLetActuatorApisThrough_WhenFineractIsInBatchModeAndIsHealthApi() throws ServletException, IOException {
// given
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true);
FineractProperties.FineractModeProperties modeProperties = InstanceModeMock.createModeProps(false, false, true, true);
given(fineractProperties.getMode()).willReturn(modeProperties);
given(request.getMethod()).willReturn(HttpMethod.GET.name());
given(request.getServletPath()).willReturn("/actuator/health");
@@ -36,7 +36,7 @@ Feature: Core Infrastructure
@infrastructure
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 Fineract instance is a batch instance
Given Fineract instance is a batch manager instance
Given Liquibase is enabled with a default tenant
When The database migration process is executed
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);
}
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchEnabled = false)
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test
public void testGetHeadOfficeWorks_WhenInstanceModeIsReadOnly() {
// given
@@ -70,7 +70,7 @@ public class InstanceModeIntegrationTest {
assertNotNull(result);
}
@ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchEnabled = false)
@ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test
public void testGetHeadOfficeWorks_WhenInstanceModeIsWriteOnly() {
// given
@@ -80,7 +80,7 @@ public class InstanceModeIntegrationTest {
assertNotNull(result);
}
@ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchEnabled = true)
@ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchWorkerEnabled = true, batchManagerEnabled = true)
@Test
public void testGetHeadOfficeDoesntWork_WhenInstanceModeIsBatchOnly() {
// given
@@ -89,7 +89,7 @@ public class InstanceModeIntegrationTest {
// then no exception is thrown
}
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchEnabled = false)
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test
public void testCreateClientDoesntWork_WhenReadOnly() {
// given
@@ -99,7 +99,7 @@ public class InstanceModeIntegrationTest {
// then no exception thrown
}
@ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchEnabled = false)
@ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test
public void testCreateClientWorks_WhenWriteOnly() {
// given
@@ -110,7 +110,7 @@ public class InstanceModeIntegrationTest {
assertNotNull(result);
}
@ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchEnabled = true)
@ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchWorkerEnabled = true, batchManagerEnabled = true)
@Test
public void testCreateClientDoesntWork_WhenBatchOnly() {
// given
@@ -120,7 +120,7 @@ public class InstanceModeIntegrationTest {
// then no exception thrown
}
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchEnabled = false)
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test
public void testRunSchedulerJobDoesntWork_WhenReadOnly() {
// given
@@ -129,7 +129,7 @@ public class InstanceModeIntegrationTest {
// then no exception thrown
}
@ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchEnabled = false)
@ConfigureInstanceMode(readEnabled = false, writeEnabled = true, batchWorkerEnabled = false, batchManagerEnabled = false)
@Test
public void testRunSchedulerJobDoesntWork_WhenWriteOnly() {
// given
@@ -138,7 +138,7 @@ public class InstanceModeIntegrationTest {
// then no exception thrown
}
@ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchEnabled = true)
@ConfigureInstanceMode(readEnabled = false, writeEnabled = false, batchWorkerEnabled = true, batchManagerEnabled = true)
@Test
public void testRunSchedulerJobWorks_WhenBatchOnly() {
// given
@@ -32,5 +32,7 @@ public @interface ConfigureInstanceMode {
boolean writeEnabled();
boolean batchEnabled();
boolean batchWorkerEnabled();
boolean batchManagerEnabled();
}
@@ -31,9 +31,9 @@ public class InstanceModeHelper {
private static final Gson GSON = new JSON().getGson();
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)
.batchEnabled(batchEnabled);
.batchWorkerEnabled(batchWorkerEnabled).batchManagerEnabled(batchManagerEnabled);
String requestStr = GSON.toJson(request);
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) {
boolean readEnabled = annotation.readEnabled();
boolean writeEnabled = annotation.writeEnabled();
boolean batchEnabled = annotation.batchEnabled();
changeInstanceMode(context, readEnabled, writeEnabled, batchEnabled);
boolean batchWorkerEnabled = annotation.batchWorkerEnabled();
boolean batchManagerEnabled = annotation.batchWorkerEnabled();
changeInstanceMode(context, readEnabled, writeEnabled, batchWorkerEnabled, batchManagerEnabled);
}
});
}
@@ -53,12 +54,13 @@ public class InstanceModeSupportExtension implements BeforeTestExecutionCallback
context.getTestMethod().ifPresent(m -> {
ConfigureInstanceMode annotation = m.getAnnotation(ConfigureInstanceMode.class);
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);
String authKey = store.getOrComputeIfAbsent(AUTH_KEY, k -> Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(),
String.class);
@@ -66,6 +68,6 @@ public class InstanceModeSupportExtension implements BeforeTestExecutionCallback
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
requestSpec.header("Authorization", "Basic " + authKey);
InstanceModeHelper.changeMode(requestSpec, responseSpec, readEnabled, writeEnabled, batchEnabled);
InstanceModeHelper.changeMode(requestSpec, responseSpec, readEnabled, writeEnabled, batchWorkerEnabled, batchManagerEnabled);
}
}