From 2a5ffb5a6b092d55515d598d4466a9d3c4321581 Mon Sep 17 00:00:00 2001 From: Takara Baumbach Date: Thu, 27 Jul 2023 13:29:10 +0200 Subject: [PATCH] fix: requested changes --- .github/workflows/build-and-publish.yml | 4 ++-- Dockerfile | 7 +++---- docker-compose.yml | 8 ++++---- docker-entrypoint.sh | 10 +++++----- ors-api/ors-config.yml | 6 +++--- .../servlet/listeners/ORSInitContextListener.java | 12 ++++++++++++ ors-api/src/main/resources/log4j.properties | 2 +- .../ors/apitests/common/InitializeGraphsOnce.java | 7 +------ .../heigit/ors/routing/RoutingProfileManager.java | 2 +- 9 files changed, 32 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index aa2b24ab4a..c0b2292f72 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -113,7 +113,7 @@ jobs: run: | mkdir $(pwd)/graphs $(pwd)/conf sudo chown 1000:1000 $(pwd)/graphs $(pwd)/conf - docker run -it -d -p 8080:8080 --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + docker run -it -d -p 8080:8080 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf -e ORS_CONFIG_LOCATION=ors-conf/ors-config.yml --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Check for health to turn 200 after the graphs are build and spring-boot completely started ./.github/utils/url_check.sh 127.0.0.1 8080 /ors/v2/health 200 ${{ env.HEALTH_WAIT_TIME }} # Check for correct preflight settings to avoid CORS issues with ORIGIN wildcard from the example config @@ -122,7 +122,7 @@ jobs: # Restart the container to apply the config changes docker stop ors-instance docker container prune -f - docker run -it -d -p 8080:8080 -e ORS_CORS_ALLOWED_ORIGINS=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + docker run -it -d -p 8080:8080 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf -e ORS_CORS_ALLOWED_ORIGINS=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Request preflight with https://example.com and https://example.org to see if it gets applied correctly ./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 50 # It should fail with http code 403 for https://example.com since the Origin is not covered. diff --git a/Dockerfile b/Dockerfile index 3fb409f7cc..5f49648f63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -65,9 +65,8 @@ ENV LANG='en_US' LANGUAGE='en_US' LC_ALL='en_US' RUN apk add --no-cache bash=~'5' openssl=~'3' && \ addgroup -g ${GID} ors && \ adduser -D -h ${BASE_FOLDER} -u ${UID} -G ors ors && \ - mkdir -p ${BASE_FOLDER}/logs ${BASE_FOLDER}/graphs ${BASE_FOLDER}/elevation_cache ${BASE_FOLDER}/conf ${BASE_FOLDER}/data ${BASE_FOLDER}/tomcat/logs&& \ - chown -R ors ${BASE_FOLDER}/logs ${BASE_FOLDER}/graphs ${BASE_FOLDER}/elevation_cache ${BASE_FOLDER}/conf ${BASE_FOLDER}/data ${BASE_FOLDER}/tomcat ${BASE_FOLDER}/tomcat/logs - + mkdir -p ${BASE_FOLDER}/ors-core/logs ${BASE_FOLDER}/ors-conf ${BASE_FOLDER}/tomcat/logs && \ + chown -R ors ${BASE_FOLDER}/tomcat ${BASE_FOLDER}/ors-core/logs ${BASE_FOLDER}/ors-conf ${BASE_FOLDER}/tomcat/logs WORKDIR ${BASE_FOLDER} # Copy over the needed bits and pieces from the other stages. @@ -81,7 +80,7 @@ COPY --chown=ors:ors ./$OSM_FILE ${BASE_FOLDER}/tmp/osm_file.pbf USER ${UID}:${GID} ENV BUILD_GRAPHS="False" -ENV ORS_CONFIG_LOCATION=conf/ors-config.yml +ENV ORS_CONFIG_LOCATION=ors-conf/ors-config.yml # Start the container ENTRYPOINT ["/home/ors/docker-entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 5b4ff37d69..cb7ef5b9ca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,12 +12,12 @@ services: # args: # OSM_FILE: ./ors-api/src/test/files/heidelberg.osm.gz volumes: - - ./docker/graphs:/home/ors/graphs - - ./docker/elevation_cache:/home/ors/elevation_cache + - ./docker/graphs:/home/ors/ors-core/data/graphs + - ./docker/elevation_cache:/home/ors/ors-core/data/elevation_cache - ./docker/logs/ors:/home/ors/logs - ./docker/logs/tomcat:/home/ors/tomcat/logs - - ./docker/conf:/home/ors/conf - - ./docker/data:/home/ors/data + - ./docker/conf:/home/ors/ors-conf + - ./docker/data:/home/ors/ors-core/data environment: - BUILD_GRAPHS=False # Forces the container to rebuild the graphs, e.g. when PBF is changed - "JAVA_OPTS=-Djava.awt.headless=true -server -XX:TargetSurvivorRatio=75 -XX:SurvivorRatio=64 -XX:MaxTenuringThreshold=3 -XX:+UseG1GC -XX:+ScavengeBeforeFullGC -XX:ParallelGCThreads=4 -Xms1g -Xmx2g" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 866da2283b..7145c19f46 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -11,7 +11,7 @@ fi ors_base=${1} catalina_base=${ors_base}/tomcat -graphs=${ors_base}/graphs +graphs=${ors_base}/ors-core/data/graphs echo "ORS Path: ${ors_base}" echo "Catalina Path: ${catalina_base}" @@ -38,14 +38,14 @@ if [ "${BUILD_GRAPHS}" = "True" ]; then fi echo "### openrouteservice configuration ###" -if [ ! -f "${ors_base}/conf/ors-config.yml" ]; then +if [ ! -f "${ors_base}/ors-conf/ors-config.yml" ]; then echo "Copy ors-config.yml" - cp -f "${ors_base}/tmp/ors-config.yml" "${ors_base}/conf/ors-config.yml" + cp -f "${ors_base}/tmp/ors-config.yml" "${ors_base}/ors-conf/ors-config.yml" fi -if [ ! -f "${ors_base}/data/osm_file.pbf" ]; then +if [ ! -f "${ors_base}/ors-core/data/osm_file.pbf" ]; then echo "Copy osm_file.pbf" - cp -f "${ors_base}/tmp/osm_file.pbf" "${ors_base}/data/osm_file.pbf" + cp -f "${ors_base}/tmp/osm_file.pbf" "${ors_base}/ors-core/data/osm_file.pbf" fi # so docker can stop the process gracefully diff --git a/ors-api/ors-config.yml b/ors-api/ors-config.yml index 0f6de7df2d..08814bc6d8 100644 --- a/ors-api/ors-config.yml +++ b/ors-api/ors-config.yml @@ -17,10 +17,10 @@ ors: engine: ### use the following line for development setup using test OSM file for Heidelberg # source_file: ./src/test/files/heidelberg.osm.gz - source_file: ./data/osm_file.pbf - graphs_root_path: ./graphs + source_file: ./ors-core/data/osm_file.pbf + graphs_root_path: ./ors-core/data/graphs elevation: - cache_path: ./elevation_cache + cache_path: ./ors-core/data/elevation_cache profiles: car: diff --git a/ors-api/src/main/java/org/heigit/ors/api/servlet/listeners/ORSInitContextListener.java b/ors-api/src/main/java/org/heigit/ors/api/servlet/listeners/ORSInitContextListener.java index 04b3b2b0c0..4235ad80db 100644 --- a/ors-api/src/main/java/org/heigit/ors/api/servlet/listeners/ORSInitContextListener.java +++ b/ors-api/src/main/java/org/heigit/ors/api/servlet/listeners/ORSInitContextListener.java @@ -31,6 +31,10 @@ import jakarta.servlet.ServletContextEvent; import jakarta.servlet.ServletContextListener; +import org.heigit.ors.util.StringUtility; + +import static org.heigit.ors.api.ORSEnvironmentPostProcessor.ORS_CONFIG_LOCATION_ENV; +import static org.heigit.ors.api.ORSEnvironmentPostProcessor.ORS_CONFIG_LOCATION_PROPERTY; public class ORSInitContextListener implements ServletContextListener { private static final Logger LOGGER = Logger.getLogger(ORSInitContextListener.class); @@ -42,6 +46,14 @@ public ORSInitContextListener(EngineProperties engineProperties) { @Override public void contextInitialized(ServletContextEvent contextEvent) { + if (LOGGER.isDebugEnabled()) { + if (!StringUtility.isNullOrEmpty(System.getenv(ORS_CONFIG_LOCATION_ENV))) { + LOGGER.debug("Configuration loaded by ENV, location: " + System.getenv(ORS_CONFIG_LOCATION_ENV)); + } + if (!StringUtility.isNullOrEmpty(System.getProperty(ORS_CONFIG_LOCATION_PROPERTY))) { + LOGGER.debug("Configuration loaded by ARG, location: " + System.getProperty(ORS_CONFIG_LOCATION_PROPERTY)); + } + } final EngineConfig config = EngineConfig.EngineConfigBuilder.init() .setInitializationThreads(engineProperties.getInitThreads()) .setPreparationMode(engineProperties.isPreparationMode()) diff --git a/ors-api/src/main/resources/log4j.properties b/ors-api/src/main/resources/log4j.properties index f29f17215a..1fc6b1e4d5 100644 --- a/ors-api/src/main/resources/log4j.properties +++ b/ors-api/src/main/resources/log4j.properties @@ -4,7 +4,7 @@ log4j.rootLogger=DEBUG, A1 # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout -#log4j.appender.A1.layout.ConversionPattern=%d{dd MMM HH:mm:ss} %p [%c{2}] - %m%n +log4j.appender.A1.layout.ConversionPattern=%d{dd MMM HH:mm:ss} %p [%c{2}] - %m%n log4j.logger.org.heigit=WARN log4j.logger.org.apache=WARN diff --git a/ors-api/src/test/java/org/heigit/ors/apitests/common/InitializeGraphsOnce.java b/ors-api/src/test/java/org/heigit/ors/apitests/common/InitializeGraphsOnce.java index c9aca8a897..1fbb7eee18 100644 --- a/ors-api/src/test/java/org/heigit/ors/apitests/common/InitializeGraphsOnce.java +++ b/ors-api/src/test/java/org/heigit/ors/apitests/common/InitializeGraphsOnce.java @@ -4,7 +4,6 @@ import org.heigit.ors.routing.RoutingProfileManagerStatus; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.FileSystemUtils; @@ -14,7 +13,7 @@ import java.nio.file.Paths; @Order(Integer.MIN_VALUE) // Run before even spring context has been built -public class InitializeGraphsOnce implements BeforeAllCallback, BeforeEachCallback { +public class InitializeGraphsOnce implements BeforeAllCallback { private static final Logger LOGGER = Logger.getLogger(InitializeGraphsOnce.class.getName()); @@ -37,10 +36,6 @@ public void beforeAll(ExtensionContext extensionContext) { } } - @Override - public void beforeEach(ExtensionContext context) { - } - private synchronized static void deleteGraphsFolderOncePerTestRun(ExtensionContext.Store store) { boolean graphsFolderAlreadyDeleted = store.getOrDefault(GRAPHS_FOLDER_DELETED, Boolean.class, Boolean.FALSE); boolean ciPropertySet = System.getProperty("CI") != null && System.getProperty("CI").equalsIgnoreCase("true"); diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java index 1b19b69365..5646e16db5 100644 --- a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java +++ b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java @@ -111,7 +111,7 @@ public void initialize(EngineConfig config) { } } - LOGGER.info("%d tasks submitted.".formatted(nTotalTasks)); + LOGGER.info("%d profile configurations submitted as tasks.".formatted(nTotalTasks)); int nCompletedTasks = 0; while (nCompletedTasks < nTotalTasks) {