Skip to content

Commit

Permalink
Merge pull request #499 from scireum/feature/aha/SIRI-891
Browse files Browse the repository at this point in the history
Ensures a proper load order for component-x.conf files
  • Loading branch information
andyHa authored Oct 16, 2023
2 parents 3c54204 + a8a7092 commit a37a119
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ the core frameworks and a fair amount of commonly used classes.

## Important files of this module:

* [Default configuration](src/main/resources/component-kernel.conf)
* [Default configuration](src/main/resources/component-050-kernel.conf)
* [Maven setup](pom.xml).

## The Kernel
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/sirius/kernel/Setup.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.StreamHandler;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -238,7 +239,7 @@ protected void setupEncoding() {
/**
* Sets the DNS cache to a sane value.
* <p>
* By default java infinitely caches all DNS entries. Will be changed to 10 seconds...
* By default, java infinitely caches all DNS entries. Will be changed to 10 seconds...
*/
protected void setupDNSCache() {
Sirius.LOG.FINE("Setting DNS-Cache to 10 seconds...");
Expand Down Expand Up @@ -268,7 +269,7 @@ protected static Value getProperty(String property, Object defaultValue, String
* Initializes log4j as logging framework.
* <p>
* In development mode, we log everything to the console. In production mode, we use a rolling file appender and
* log into the logs directory.
* log into the "logs" directory.
*/
protected void setupLogging() {
Logger rootLogger = LogManager.getLogManager().getLogger("");
Expand Down Expand Up @@ -330,8 +331,8 @@ private Config loadConfig(String resourceName, Producer<Config> configMaker, @Nu
/**
* Loads the main application configuration which is shipped with the app.
* <p>
* By default this loads "application.conf" from the classpath. Also "application-*.conf
* are loaded in case it is splitted into several parts.
* By default, this loads "application.conf" from the classpath. Also, "application-*.conf
* are loaded in case it is split into several parts.
*
* @return the main application config. This will override all component configs but be overridden by developer,
* test and instance configs
Expand All @@ -343,9 +344,11 @@ public Config loadApplicationConfig() {
// Load component configurations
Sirius.getClasspath()
.find(Pattern.compile("application-([^.]*?)\\.conf"))
.forEach(value -> result.set(loadConfig(value.group(),
() -> ConfigFactory.parseResources(loader, value.group()),
result.get())));
.map(Matcher::group)
.sorted()
.forEach(configPath -> result.set(loadConfig(configPath,
() -> ConfigFactory.parseResources(loader, configPath),
result.get())));

if (Sirius.class.getResource("/application.conf") != null) {
result.set(loadConfig("application.conf",
Expand All @@ -361,7 +364,7 @@ public Config loadApplicationConfig() {
/**
* Applies the test configuration to the given config object.
* <p>
* By default this loads and applies "test.conf" from the classpath.
* By default, this loads and applies "test.conf" from the classpath.
*
* @param config the config to enhance
* @return the enhanced config
Expand Down Expand Up @@ -396,7 +399,7 @@ public Config applyTestScenarioConfig(@Nullable String scenarioFile, @Nonnull Co
/**
* Applies the corresponding configuration to the given config object.
* <p>
* By default this loads and applies the given "instance.conf", "develop.conf", "staging.conf" or "productive.conf"
* By default, this loads and applies the given "instance.conf", "develop.conf", "staging.conf" or "productive.conf"
* from the file system.
*
* @param config the config to amend
Expand All @@ -419,7 +422,7 @@ public Config applyConfig(@Nonnull Config config, @Nonnull String configType) {
/**
* Loads <b>and parses</b> the environment.
* <p>
* {@link ConfigFactory} by default treats every environment variable as key instead of as path. Therefore we
* {@link ConfigFactory} by default treats every environment variable as key instead of as path. Therefore, we
* manually load the environment be treating variables as path so that compound keys like sirius.nodeName
* can be specified.
*
Expand Down
42 changes: 24 additions & 18 deletions src/main/java/sirius/kernel/Sirius.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -343,27 +344,32 @@ private static void setupApplicationAndSystemConfig() {

if (isStartedAsTest()) {
// Load test configurations (will override component configs)
classpath.find(Pattern.compile("component-test-([^.]*?)\\.conf")).forEach(value -> {
try {
LOG.INFO("Loading test config: %s", value.group());
config = config.withFallback(ConfigFactory.parseResources(setup.getLoader(), value.group()));
} catch (Exception exception) {
handleConfigError(value.group(), exception);
}
});
classpath.find(Pattern.compile("component-test-([^.]*?)\\.conf"))
.map(Matcher::group)
.sorted()
.forEach(configPath -> {
try {
LOG.INFO("Loading test config: %s", configPath);
config = config.withFallback(ConfigFactory.parseResources(setup.getLoader(), configPath));
} catch (Exception exception) {
handleConfigError(configPath, exception);
}
});
}

// Load component configurations
classpath.find(Pattern.compile("component-([^\\-]*?)([^.]*?)\\.conf")).forEach(value -> {
if (!"test".equals(value.group(1))) {
try {
LOG.INFO("Loading config: %s", value.group());
config = config.withFallback(ConfigFactory.parseResources(setup.getLoader(), value.group()));
} catch (Exception exception) {
handleConfigError(value.group(), exception);
}
}
});
classpath.find(Pattern.compile("component-([^\\-]*?)([^.]*?)\\.conf"))
.map(Matcher::group)
.filter(configPath -> !"test".equals(configPath))
.sorted()
.forEach(configPath -> {
try {
LOG.INFO("Loading config: %s", configPath);
config = config.withFallback(ConfigFactory.parseResources(setup.getLoader(), configPath));
} catch (Exception exception) {
handleConfigError(configPath, exception);
}
});

config = config.resolve();

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/sirius/kernel/async/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
/**
* Tracks the execution of a blocking operation.
* <p>
* The operations framework is used to track blocking operations which might possibly hang. As a blocking operation
* The operations framework is used to track blocking operations which might hang. As a blocking operation
* cannot be checked by the calling thread itself, the classical alternative would be to fork a thread which
* monitors the operation. As this approach does not scale very well, the operations framework creates a
* lighweight <tt>Operation</tt> object around a potentially blocking operation using a try-with-resources block.
* lightweight <tt>Operation</tt> object around a potentially blocking operation using a try-with-resources block.
* <p>
* A metrics provider will check for all operations and use its limits (set by <tt>component-kernel.conf</tt>,
* A metrics provider will check for all operations and use its limits (set by <tt>component-050-kernel.conf</tt>,
* to warn if too many operations are active (or are probably hanging).
* <p>
* Other frameworks can provider further help: <tt>SIRIUS-WEB</tt> e.g. provides a list of all operations
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/kernel/cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[Caches](Cache.java) can be created using the [CacheManager](CacheManager.java). Each cache
should be a constant (**static final**). The configuration of a cache is loaded from the
system configuration using **cache** section (see [component-kernel.conf](../../../../resources/component-kernel.conf)).
system configuration using **cache** section (see [component-kernel.conf](../../../../resources/component-050-kernel.conf)).

A coherent cache will be synchronized across a cluster with the help of [CacheCoherence](CacheCoherence.java) -
[sirius-biz](https://github.com/scireum/sirius-biz) provides an implementation for this using **Redis**.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/kernel/info/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Software Distribution Information

With the help of variables in the system configuration
(e.g. [component-kernel.conf](../../../../resources/component-kernel.conf)) the
(e.g. [component-kernel.conf](../../../../resources/component-050-kernel.conf)) the
product name and revision as well as a list of all installed modules and their version can
be queried using [Product](Product.java).
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private EndOfDayTaskInfo executeTask(EndOfDayTask task) {
Exceptions.handle()
.to(Log.BACKGROUND)
.error(exception)
.withSystemErrorMessage("An error occured when executing end of day task %s (%s): %s (%s)",
.withSystemErrorMessage("An error occurred when executing end of day task %s (%s): %s (%s)",
task.getName(),
task.getClass())
.handle();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sirius/kernel/timer/Timers.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class Timers implements Startable, Stoppable {
private static final int RELOAD_INTERVAL = 1000;

/**
* Determines the start and stop order of the timers lifecycle. Exposed as public so that
* Determines the start and stop order of the timer's lifecycle. Exposed as public so that
* dependent lifecycles can determine their own priority based on this.
*/
public static final int LIFECYCLE_PRIORITY = 1000;
Expand Down Expand Up @@ -307,7 +307,7 @@ public void runOneHourTimers() {
* Executes all daily timers (implementing <tt>EveryDay</tt>) if applicable, or if outOfASchedule is <tt>true</tt>.
*
* @param currentHour determines the current hour. Most probably this will be wall-clock time. However, for
* out-of-schedule eecution, this can be set to any value.
* out-of-schedule execution, this can be set to any value.
*/
public void runEveryDayTimers(int currentHour) {
runEveryDayTimers(currentHour, false);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/kernel/xml/Outcall.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public void setReadTimeout(int timeoutMillis) {
* Sets the connect-timeout and read-timeout to the values specified in the config block http.outcall.timeouts.*
* where * equals the configKey parameter.
* <p>
* See the http.outcall.timeouts.soap block in component-kernel.conf for reference.
* See the http.outcall.timeouts.soap block in component-050-kernel.conf for reference.
*
* @param configKey the config key of the timeout configuration block
* @return this for fluent method calls
Expand Down
File renamed without changes.

0 comments on commit a37a119

Please sign in to comment.