Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ORS_CONFIG_LOCATION not logging with wrong paths #1960

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ RELEASING:
- Add missing 'build' in documentation for profile
properties ([#1947](https://github.com/GIScience/openrouteservice/issues//1947))
- Allow vehicles on ferries without explicit access tags ([#1954](https://github.com/GIScience/openrouteservice/pull/1954))
- ORS_CONFIG_LOCATION doesn't log with wrong paths ([#1816](https://github.com/GIScience/openrouteservice/issues/1816))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.core.io.FileSystemResource;

import java.io.IOException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
Expand Down Expand Up @@ -42,8 +43,18 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp
log.info("Configuration file set by program argument.");
}
if (configLocations.isEmpty() && !StringUtility.isNullOrEmpty(System.getenv(ORS_CONFIG_LOCATION_ENV))) {
configLocations.add(System.getenv(ORS_CONFIG_LOCATION_ENV));
log.info("Configuration file set by environment variable.");
String configPath = System.getenv(ORS_CONFIG_LOCATION_ENV);
File configFile = new File(configPath);
// Check if the file exists and log the appropriate message
if (configFile.exists()) {
log.info("ORS config file found at: " + configFile.getAbsolutePath());
configLocations.add(configPath);
log.info("Configuration file set by environment variable.");
} else {
// Add it anyway to provoke error and stop ORS
configLocations.add(configPath);
log.error("ORS config file not found at: " + configPath);
}
}
if (configLocations.isEmpty()) {
String home = System.getProperty("user.home");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package integrationtests;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testcontainers.containers.ContainerLaunchException;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.junit.jupiter.TestcontainersExtension;
Expand Down Expand Up @@ -45,7 +47,7 @@ class ConfigEnvironmentTests {
@MethodSource("utils.ContainerInitializer#ContainerTestImageBareImageStream")
@ParameterizedTest(name = "{0}")
@Execution(ExecutionMode.CONCURRENT)
void testMissingConfigButRequiredParamsAsEnvUpperAndLower(ContainerInitializer.ContainerTestImageBare targetImage) {
void testMissingConfigButRequiredParamsAsEnvUpperAndLower(ContainerTestImageBare targetImage) {
GenericContainer<?> container = initContainer(targetImage, false, "testMissingConfigButRequiredParamsAsEnvUpperAndLower");
container.waitingFor(healthyWaitStrategyWithLogMessage(List.of(
"Configuration file lookup by default locations.",
Expand Down Expand Up @@ -73,8 +75,8 @@ void testMissingConfigButRequiredParamsAsEnvUpperAndLower(ContainerInitializer.C
@MethodSource("utils.ContainerInitializer#ContainerTestImageBareImageStream")
@ParameterizedTest(name = "{0}")
@Execution(ExecutionMode.CONCURRENT)
void testMissingConfigButRequiredParamsAsArg(ContainerInitializer.ContainerTestImageBare targetImage) {
if (targetImage.equals(ContainerInitializer.ContainerTestImageBare.WAR_CONTAINER_BARE)) {
void testMissingConfigButRequiredParamsAsArg(ContainerTestImageBare targetImage) {
if (targetImage.equals(ContainerTestImageBare.WAR_CONTAINER_BARE)) {
// This test is not applicable to the WAR container as it does not support command line arguments.
return;
}
Expand All @@ -86,10 +88,10 @@ void testMissingConfigButRequiredParamsAsArg(ContainerInitializer.ContainerTestI
"Configuration lookup finished."
).toArray(new String[0]), Duration.ofSeconds(60)));
ArrayList<String> command = targetImage.getCommand("250M");
if (targetImage.equals(ContainerInitializer.ContainerTestImageBare.JAR_CONTAINER_BARE)) {
if (targetImage.equals(ContainerTestImageBare.JAR_CONTAINER_BARE)) {
command.add("--ors.engine.profiles.driving-hgv.enabled=true");
command.add("--ors.engine.profile_default.build.source_file=/home/ors/openrouteservice/files/heidelberg.test.pbf");
} else if (targetImage.equals(ContainerInitializer.ContainerTestImageBare.MAVEN_CONTAINER_BARE)) {
} else if (targetImage.equals(ContainerTestImageBare.MAVEN_CONTAINER_BARE)) {
command.add("-Dspring-boot.run.arguments=--ors.engine.profile_default.build.source_file=/home/ors/openrouteservice/files/heidelberg.test.pbf --ors.engine.profiles.driving-hgv.enabled=true");
}
container.setCommand(command.toArray(new String[0]));
Expand All @@ -105,7 +107,7 @@ void testMissingConfigButRequiredParamsAsArg(ContainerInitializer.ContainerTestI
@MethodSource("utils.ContainerInitializer#ContainerTestImageDefaultsImageStream")
@ParameterizedTest(name = "{0}")
@Execution(ExecutionMode.CONCURRENT)
void testPropertyOverridesDefaultConfig(ContainerInitializer.ContainerTestImageDefaults targetImage) {
void testPropertyOverridesDefaultConfig(ContainerTestImageDefaults targetImage) {
GenericContainer<?> container = initContainer(targetImage, false, "testPropertyOverridesDefaultConfig");

container.addEnv("ors.engine.profiles.driving-car.enabled", "false");
Expand All @@ -126,7 +128,7 @@ void testPropertyOverridesDefaultConfig(ContainerInitializer.ContainerTestImageD
@MethodSource("utils.ContainerInitializer#ContainerTestImageBareImageStream")
@ParameterizedTest(name = "{0}")
@Execution(ExecutionMode.CONCURRENT)
void testActivateAllBareGraphsWithEnv(ContainerInitializer.ContainerTestImageBare targetImage) {
void testActivateAllBareGraphsWithEnv(ContainerTestImageBare targetImage) {
GenericContainer<?> container = initContainer(targetImage, false, "testActivateAllBareGraphsWithEnv");
container.addEnv("ors.engine.profile_default.enabled", "true");
container.addEnv("ors.engine.profiles.public-transport.enabled", "false");
Expand Down Expand Up @@ -158,9 +160,9 @@ void testActivateAllBareGraphsWithEnv(ContainerInitializer.ContainerTestImageBar
@MethodSource("utils.ContainerInitializer#ContainerTestImageDefaultsImageStream")
@ParameterizedTest(name = "{0}")
@Execution(ExecutionMode.CONCURRENT)
void testDefaultProfileActivated(ContainerInitializer.ContainerTestImageDefaults targetImage) {
void testDefaultProfileActivated(ContainerTestImageDefaults targetImage) {
GenericContainer<?> container = initContainer(targetImage, false, "testDefaultProfileActivated");
if (targetImage.equals(ContainerInitializer.ContainerTestImageDefaults.WAR_CONTAINER)) {
if (targetImage.equals(ContainerTestImageDefaults.WAR_CONTAINER)) {
container.setWaitStrategy(orsCorrectConfigLoadedWaitStrategy("/home/ors/openrouteservice/ors-config.yml"));
} else {
container.waitingFor(orsCorrectConfigLoadedWaitStrategy("./ors-config.yml"));
Expand All @@ -178,7 +180,7 @@ void testDefaultProfileActivated(ContainerInitializer.ContainerTestImageDefaults
@MethodSource("utils.ContainerInitializer#ContainerTestImageDefaultsImageStream")
@ParameterizedTest(name = "{0}")
@Execution(ExecutionMode.CONCURRENT)
void testActivateEachProfileWithEnvAndOverwriteDefaultConfig(ContainerInitializer.ContainerTestImageDefaults targetImage) {
void testActivateEachProfileWithEnvAndOverwriteDefaultConfig(ContainerTestImageDefaults targetImage) {
GenericContainer<?> container = initContainer(targetImage, false, "testActivateEachProfileWithEnvAndOverwriteDefaultConfig");

// Prepare the environment
Expand All @@ -192,5 +194,35 @@ void testActivateEachProfileWithEnvAndOverwriteDefaultConfig(ContainerInitialize
OrsApiHelper.assertProfilesLoaded(container, allProfiles.stream().collect(HashMap::new, (m, v) -> m.put(v, true), HashMap::putAll));
container.stop();
}

/**
* arg-overrides-default-prop.sh
*/
@MethodSource("utils.ContainerInitializer#ContainerTestImageDefaultsImageStream")
@ParameterizedTest(name = "{0}")
@Execution(ExecutionMode.CONCURRENT)
void testNonExistentConfigFail(ContainerTestImageDefaults targetImage) {
GenericContainer<?> container = initContainer(targetImage, false, "testNonExistentConfigFail");

// Prepare the environment
container.addEnv("ORS_CONFIG_LOCATION", "nonexistent/ors-config.yaml");
container.addEnv("ors.config.location", "");

try {
container.start();

String logs = container.getLogs();
Assertions.assertTrue(logs.contains("ORS config file not found at: nonexistent/ors-config.yaml"));

} catch (ContainerLaunchException e) {
// Pass when throwing this exception since the container is supposed to fail when the config path is wrong.
} catch (Exception e) {
Assertions.fail("Container startup failed with exception: " + e.getMessage());
} finally {
if (container.isRunning()) {
container.stop();
}
}
}
}
}
Loading