[FINERACT-1678] configuration validation for COBs
This commit is contained in:
committed by
Aleksandar Vidakovic
parent
9e949887b9
commit
47d5a85f17
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 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.core.config;
|
||||
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
|
||||
public final class ExplicitConfigurationPropertiesFactory {
|
||||
|
||||
private ExplicitConfigurationPropertiesFactory() {}
|
||||
|
||||
public static <T> T getProperty(ConditionContext context, String propertyName, Class<T> type) {
|
||||
return Binder.get(context.getEnvironment()).bind(propertyName, type).orElse(null);
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -19,10 +19,12 @@
|
||||
package org.apache.fineract.infrastructure.core.config;
|
||||
|
||||
import java.util.Optional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Condition;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
||||
@Slf4j
|
||||
public class FineractModeValidationCondition implements Condition {
|
||||
|
||||
@Override
|
||||
@@ -33,6 +35,11 @@ public class FineractModeValidationCondition implements Condition {
|
||||
.orElse(true);
|
||||
boolean isBatchModeEnabled = Optional.ofNullable(context.getEnvironment().getProperty("fineract.mode.batch-enabled", Boolean.class))
|
||||
.orElse(true);
|
||||
return !isReadModeEnabled && !isWriteModeEnabled && !isBatchModeEnabled;
|
||||
boolean isValidationFails = !isReadModeEnabled && !isWriteModeEnabled && !isBatchModeEnabled;
|
||||
if (isValidationFails) {
|
||||
log.error(
|
||||
"The Fineract instance type is not configured properly. At least one of these environment variables should be true: FINERACT_MODE_READ_ENABLED, FINERACT_MODE_WRITE_ENABLED, FINERACT_MODE_BATCH_ENABLED");
|
||||
}
|
||||
return isValidationFails;
|
||||
}
|
||||
}
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 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.core.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Condition;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
||||
@Slf4j
|
||||
public class FineractPartitionJobConfigValidationCondition implements Condition {
|
||||
|
||||
@Override
|
||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
FineractProperties.FineractPartitionedJob partitionedJobProperties = ExplicitConfigurationPropertiesFactory.getProperty(context,
|
||||
"fineract.partitioned-job", FineractProperties.FineractPartitionedJob.class);
|
||||
if (partitionedJobProperties != null) {
|
||||
List<FineractProperties.PartitionedJobProperty> invalidConfigs = partitionedJobProperties.getPartitionedJobProperties().stream()
|
||||
.filter(isAnyConfigBelowOne().or(FineractPartitionJobConfigValidationCondition::isPartitionRatioInvalid)).toList();
|
||||
if (!invalidConfigs.isEmpty()) {
|
||||
for (FineractProperties.PartitionedJobProperty invalidConfig : invalidConfigs) {
|
||||
log.error(
|
||||
"{} partitioned job is not configured properly. The partition size, chunk size and thread count must be more than 0, and partition size must be less then chunk size * thread count",
|
||||
invalidConfig.getJobName());
|
||||
}
|
||||
}
|
||||
return !invalidConfigs.isEmpty();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static Predicate<FineractProperties.PartitionedJobProperty> isAnyConfigBelowOne() {
|
||||
return partitionedJobProperty -> !(partitionedJobProperty.getPartitionSize() > 0 && partitionedJobProperty.getChunkSize() > 0
|
||||
&& partitionedJobProperty.getThreadCount() > 0);
|
||||
}
|
||||
|
||||
private static boolean isPartitionRatioInvalid(FineractProperties.PartitionedJobProperty partitionedJobProperty) {
|
||||
return partitionedJobProperty.getPartitionSize() < partitionedJobProperty.getThreadCount() * partitionedJobProperty.getChunkSize();
|
||||
}
|
||||
}
|
||||
+21
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.apache.fineract.infrastructure.core.config;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -36,6 +37,8 @@ public class FineractProperties {
|
||||
|
||||
private FineractCorrelationProperties correlation;
|
||||
|
||||
private FineractPartitionedJob partitionedJob;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class FineractTenantProperties {
|
||||
@@ -72,4 +75,22 @@ public class FineractProperties {
|
||||
private boolean enabled;
|
||||
private String headerName;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class FineractPartitionedJob {
|
||||
|
||||
// TODO should be used without wrapper class
|
||||
private List<PartitionedJobProperty> partitionedJobProperties;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class PartitionedJobProperty {
|
||||
|
||||
private String jobName;
|
||||
private Integer chunkSize;
|
||||
private Integer partitionSize;
|
||||
private Integer threadCount;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -32,8 +32,8 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
@RequiredArgsConstructor
|
||||
@Conditional(FineractModeValidationCondition.class)
|
||||
public class FineractModeValidationConfig implements InitializingBean {
|
||||
@Conditional(FineractValidationCondition.class)
|
||||
public class FineractStartupValidationConfig implements InitializingBean {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@@ -43,8 +43,7 @@ public class FineractModeValidationConfig implements InitializingBean {
|
||||
}
|
||||
|
||||
private void terminateApplication() {
|
||||
log.error(
|
||||
"The Fineract instance type is not configured properly. At least one of these environment variables should be true: FINERACT_MODE_READ_ENABLED, FINERACT_MODE_WRITE_ENABLED, FINERACT_MODE_BATCH_ENABLED");
|
||||
((ConfigurableApplicationContext) this.applicationContext).close();
|
||||
log.error("The application startup fails on validations. Please check the log above for the details");
|
||||
((ConfigurableApplicationContext) applicationContext).close();
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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.core.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
|
||||
public class FineractValidationCondition extends AnyNestedCondition {
|
||||
|
||||
public FineractValidationCondition() {
|
||||
super(ConfigurationPhase.PARSE_CONFIGURATION);
|
||||
}
|
||||
|
||||
@Conditional(FineractModeValidationCondition.class)
|
||||
static class FineractModeValidation {}
|
||||
|
||||
@Conditional(FineractPartitionJobConfigValidationCondition.class)
|
||||
static class FineractPartitionedJobValidation {}
|
||||
}
|
||||
@@ -43,6 +43,11 @@ fineract.mode.batch-manager-enabled=${FINERACT_MODE_BATCH_MANAGER_ENABLED:true}
|
||||
fineract.correlation.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:false}
|
||||
fineract.correlation.header-name=${FINERACT_LOGGING_HTTP_CORRELATION_ID_HEADER_NAME:X-Correlation-ID}
|
||||
|
||||
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}
|
||||
|
||||
# Logging pattern for the console
|
||||
logging.pattern.console=${CONSOLE_LOG_PATTERN:%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(%replace([%X{correlationId}]){'\\[\\]', ''}) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user