diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 0000000000..ed4f260479 --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,105 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Integration test suite + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] +env: + TEST_IMAGE_NAME: 'local/tomcat-test:latest' + BUILD_PLATFORMS: 'linux/amd64' + + +jobs: + # This way the env variables are accessible in the individual jobs + prepare_environment: + name: Prepare the environment variables + runs-on: ubuntu-latest + outputs: + test_image_name: ${{ env.TEST_IMAGE_NAME }} + build_platforms: ${{ env.BUILD_PLATFORMS }} + steps: + - run: | + echo "Publish environment variables" + container-build-cache: + name: Docker Buildx cache + runs-on: ubuntu-latest + needs: prepare_environment + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + id: buildx + with: + install: true + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + cache: 'maven' + - name: Cache the docker image + uses: actions/cache@v4 + with: + path: /tmp/tomcat-test.tar + key: ${{ runner.os }}-tomcat-test-${{ needs.prepare_environment.outputs.test_image_name }} + restore-keys: | + ${{ runner.os }}-tomcat-test- + - name: Load the docker image from cache if available + run: | + if [ -f /tmp/tomcat-test.tar ]; then + podman load -i /tmp/tomcat-test.tar || echo "Could not load the image from cache. Building it." + fi + - name: Build the podman image for changes + run: | + ./.integration-scenarios/debian-12-tomcat-war-systemd/run.sh -i ${{ needs.prepare_environment.outputs.test_image_name }} + - name: Export the podman image again + run: | + podman save -o /tmp/tomcat-test.tar ${{ needs.prepare_environment.outputs.test_image_name }} + debian-12-tomcat-war-systemd: + name: Run Debian 12 Tomcat WAR systemd integration tests + runs-on: ubuntu-latest + needs: + - prepare_environment + - container-build-cache + strategy: + matrix: + scenario: [ '0_*.sh', '1_*.sh', '2_*.sh' ] + image: [ ubuntu-latest ] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + id: buildx + with: + install: true + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + cache: 'maven' + - name: Cache the docker image + uses: actions/cache@v4 + with: + path: /tmp/tomcat-test.tar + key: ${{ runner.os }}-tomcat-test-${{ needs.prepare_environment.outputs.test_image_name }} + restore-keys: | + ${{ runner.os }}-tomcat-test- + - name: Load the docker image from cache if available + run: | + if [ -f /tmp/tomcat-test.tar ]; then + podman load -i /tmp/tomcat-test.tar || { echo "Could not load the image from cache. Building it."; exit 1; } + fi + - name: Run integration tests + run: ./.integration-scenarios/debian-12-tomcat-war-systemd/run.sh -t -g '${{ matrix.scenario }}' diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml index 7b75805f56..5992791c95 100644 --- a/.github/workflows/release-artifacts.yml +++ b/.github/workflows/release-artifacts.yml @@ -10,13 +10,13 @@ jobs: steps: - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17' - name: Cache Maven packages - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/rpm-build.yml b/.github/workflows/rpm-build.yml index 7c125c2a20..c57a6cff51 100644 --- a/.github/workflows/rpm-build.yml +++ b/.github/workflows/rpm-build.yml @@ -15,13 +15,13 @@ jobs: steps: - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17' - name: Cache Maven packages - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/run_maven_tests.yml b/.github/workflows/run_maven_tests.yml index b09b55c2fd..e45b3c0e19 100644 --- a/.github/workflows/run_maven_tests.yml +++ b/.github/workflows/run_maven_tests.yml @@ -18,7 +18,7 @@ jobs: with: fetch-depth: 0 - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17' @@ -29,7 +29,7 @@ jobs: key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - name: Cache Maven packages - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/vulnerability-scanning.yml b/.github/workflows/vulnerability-scanning.yml index 9d8c4aa6f4..1aa17ebcf0 100644 --- a/.github/workflows/vulnerability-scanning.yml +++ b/.github/workflows/vulnerability-scanning.yml @@ -41,12 +41,12 @@ jobs: with: fetch-depth: 0 - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17' - name: Cache Maven packages - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} diff --git a/.gitignore b/.gitignore index a8349fa6d5..090865537c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.iml *.ipr .DS_Store +**/.m2/ graphs/ graphs-*/ diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/Dockerfile b/.integration-scenarios/debian-12-tomcat-war-systemd/Dockerfile new file mode 100644 index 0000000000..2b6fa55fab --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/Dockerfile @@ -0,0 +1,36 @@ +# To execute this script locally, see the run.sh in the same folder +FROM docker.io/debian:bookworm-slim as builder +RUN apt-get update -y && \ + apt-get install -y openjdk-17-jdk-headless maven curl init systemd vim yq jq + +# Create work directory init +WORKDIR /build +# Copy the project files into the container +COPY ors-api ors-api +COPY ors-engine ors-engine +COPY ors-report-aggregation ors-report-aggregation +COPY pom.xml pom.xml +COPY ors-config.yml ors-config.yml + +ARG UNIT_TESTS=false +# Build the project to cache the layers for faster builds +RUN if [ "$UNIT_TESTS" = "true" ]; then mvn -B clean package -PbuildWar,apitests -DCI=true -T $(nproc); else mvn clean package -DskipTests -PbuildWar -T $(nproc); fi + +# Copy the integration scenarios folder into the container. This changes often so keep it after the mvn build +COPY .integration-scenarios .integration-scenarios + +ARG TOMCAT_MAJOR=10 +ARG USER=ors + +# Create user and group and execute the script +RUN useradd -m -U -s /bin/bash "$USER" && \ + mkdir -p /home/$USER/ && \ + .integration-scenarios/debian-12-tomcat-war-systemd/setup/install.sh -u $USER -w /build/ors-api/target/ors.war && \ + systemctl enable openrouteservice.service + +WORKDIR /home/$USER + +# Expose ports +EXPOSE 8080 +# Start systemd with the following command +CMD [ "/usr/sbin/init" ] \ No newline at end of file diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/Dockerfile.dockerignore b/.integration-scenarios/debian-12-tomcat-war-systemd/Dockerfile.dockerignore new file mode 100644 index 0000000000..7a8a188630 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/Dockerfile.dockerignore @@ -0,0 +1,43 @@ +.metadata/ +.git +.gitignore +**/*.pbf + +.idea/ +*.iml +.DS_Store +nohup.out +.python-version +.project + +# Ignore all ors and app config files except for the sample ones +ors-api/src/main/resources/ors-config* +ors-api/src/main/resources/ors-config-sample.json + +# folders generated by integration test runs +**/graphs-apitests/ +ors-api/logs +.integration-scenarios/ + +# Ignore all target folders +**/target/ + +cgiar_provider/ +cgiar_cache/ +graphs/ +build/ +logs/ +docker/ +docs/ +.github/ +Dockerfile +envs/ +.jqwik-database + +# Exclusions +!.integration-scenarios/debian-12-tomcat-war-systemd/setup/setenv.sh +!.integration-scenarios/debian-12-tomcat-war-systemd/setup/install.sh +!ors-api/src/test/resources/application-test.yml +!ors-api/src/test/files/ +!ors-engine/src/test/files/preprocessed_osm_data.pbf +!.m2/ diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/1_logging.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/1_logging.sh new file mode 100644 index 0000000000..4ce273a793 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/1_logging.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +################################# +# Description: Logging related functions +# Author: Julian Psotta +# Date: 2024-02-24 +# ################################# + +# Debug message in cyan +function log_debug() { + if [[ "${container_log_level_int}" -le 10 ]]; then + echo -e "\e[36m▢ $1\e[0m" + fi + return 0 +} +# Success message in green. Always printed +function log_success() { + if [[ "${container_log_level_int}" -le 20 ]]; then + echo -e "\e[32m✓ $1\e[0m" + fi + return 0 +} +# Info message in blue +function log_info() { + if [[ "${container_log_level_int}" -le 30 ]]; then + echo -e "\e[34mⓘ $1\e[0m" + fi + return 0 +} +# Warning message in yellow +function log_warning() { + if [[ "${container_log_level_int}" -le 40 ]]; then + echo -e "\e[33m⚠ $1\e[0m" + fi + return 0 +} +# Error message in red. +function log_error() { + echo -e "\e[31m✗ $1\e[0m" + return 1 +} +function set_log_level() { + local log_level=${1:-SUCCESS} + case ${log_level} in + "DEBUG") + container_log_level_int=10 + ;; + "SUCCESS") + container_log_level_int=20 + ;; + "INFO") + container_log_level_int=30 + ;; + "WARN") + container_log_level_int=40 + ;; + "ERROR") + container_log_level_int=50 + ;; + *) + log_debug "No matching log level found: ${LOG_LEVEL}." + log_debug "Defaulting to INFO." + LOG_LEVEL="INFO" + container_log_level_int=20 + ;; + esac + log_warning "LOG_LEVEL: ${LOG_LEVEL}. Set LOG_LEVEL=DEBUG for more details." +} + +# Initialize the log level as soon as the script is sourced +set_log_level "${LOG_LEVEL:-INFO}" diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/2_system.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/2_system.sh new file mode 100644 index 0000000000..cdb9bb8262 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/2_system.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash +################################# +# Description: Package related functions +# Author: Julian Psotta +# Date: 2024-02-24 +# ################################# + +# Fail if CONTAINER_NAME is empty or not one of podman or docker +if [ -z "$CONTAINER_ENGINE" ] || [ "$CONTAINER_ENGINE" != "podman" ] && [ "$CONTAINER_ENGINE" != "docker" ]; then + log_error "Please set the CONTAINER_ENGINE variable to either podman or docker." + return 1 +fi + +# Function to check the version of the installed and activated java package. +# Usage: check_java_version +check_java_version() { + local java_version="$1" + + local result + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "java -version 2>&1 | grep \"openjdk version \\\"$java_version.\"") + if [[ -z "$result" ]]; then + log_error "Java version should be $java_version but is not." + return 1 + fi + log_success "Java version is $java_version as expected" +} + +# Function to check if an RPM package is installed +# Usage: check_rpm_installed +check_rpm_installed() { + local package="$1" + local should_be_installed="$2" + + local result + local exit_code + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "rpm -q $package") + exit_code=$? + if [[ "$should_be_installed" = "true" && $exit_code -ne 0 ]]; then + log_error "Package $package should be installed but is not. Message was: $result" + return 1 + elif [[ "$should_be_installed" = "false" && $exit_code -eq 0 ]]; then + log_error "Package $package should not be installed but is. Message was: $result" + return 1 + fi + # If should exist is true, the logging should be different + if [[ "$should_be_installed" = "true" ]]; then + log_success "Package $package is installed as expected." + else + log_success "Package $package is not installed as expected." + fi +} + +# Function to check if a systemd service is enabled +# Usage: check_systemd_service_enabled +check_systemd_service_enabled() { + local service="$1" + local should_be_enabled="$2" + + local result + local exit_code + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "systemctl is-enabled --quiet $service") + exit_code=$? + if [[ "$should_be_enabled" = "true" && $exit_code -ne 0 ]]; then + log_error "Service $service should be enabled but is not. Message was: $result" + return 1 + elif [[ "$should_be_enabled" = "false" && $exit_code -eq 0 ]]; then + log_error "Service $service should not be enabled but is. Message was: $result" + return 1 + fi + # If should exist is true, the logging should be different + if [[ "$should_be_enabled" = "true" ]]; then + log_success "Service $service is enabled as expected." + else + log_success "Service $service is not enabled as expected." + fi +} + +# Function to have a turning pipe. This function returns the next "pipe" position based on a given. +# $1 Start pipe position. Defaults to "|" +piper() { + + if [ "$1" == "|" ] || [ -z "$1" ]; then + echo "/" + elif [ "$1" == "/" ]; then + echo "_" + elif [ "$1" == "_" ]; then + echo "\\" + elif [ "$1" == "\\" ]; then + echo "|" + fi +} + +timer() { + # Return a well formatted time string in the format xx Days xx Hours xx Minutes xx Seconds from a start time. + # Use a start time like this: "local start=$(date +%s)" + # $1 Start time + local start=${1} + local end + local dt + local dd + local dt2 + local dh + local dt3 + local dm + local ds + end=$(date +%s) + dt=$(echo "$end - $start" | bc) + dd=$(echo "$dt/86400" | bc) + dt2=$(echo "$dt-86400*$dd" | bc) + dh=$(echo "$dt2/3600" | bc) + dt3=$(echo "$dt2-3600*$dh" | bc) + dm=$(echo "$dt3/60" | bc) + ds=$(echo "$dt3-60*$dm" | bc) + echo "${dd} Days ${dh} Hours ${dm} Minutes ${ds} Seconds" +} + +# Function to wait for a PID to finish +# Usage: wait_for_pid +wait_for_pid() { + # $1 PID + # $2 Waiting message. If empty none will be shown. + local program_pid=$1 + local message=$2 + local start + local pipe + start=$(date +%s) + sleep 3 + while [ -e /proc/"$program_pid" ]; do + if [ -n "${message}" ]; then + pipe=$(piper "${pipe}") + echo -ne "\r${message} | Runtime: $(timer "$start") ${pipe}" + fi + sleep 1 + done + echo -ne "\n" +} + +# Function to check if a program is installed +# Usage: check_program_installed +check_program_installed() { + if type -p $1 >/dev/null; then + log_success "Program $1 is installed." + return 0 + else + log_error "Program $1 is not installed." + return 1 + fi +} diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/3_files.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/3_files.sh new file mode 100644 index 0000000000..e5b9a38c5f --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/3_files.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env bash +################################# +# Description: Path related functions +# Author: Julian Psotta +# Date: 2024-02-24 +# ################################# + +# Fail if CONTAINER_NAME is empty or not one of podman or docker +if [ "$CONTAINER_ENGINE" != "podman" ] && [ "$CONTAINER_ENGINE" != "docker" ]; then + log_error "Please set the CONTAINER_ENGINE variable to either podman or docker." + return 1 +fi + +# Function to check if a symlink exists +# Usage: check_file_symlink +check_file_is_symlink() { + local path_to_file="$1" + local should_exist="$2" + + # Check if directory exists. Else the symlink will fail if it doesn't exist + local _ + local exit_code + _=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "test -f $path_to_file") + exit_code=$? + if [ "$should_exist" = true ] && [ $exit_code -ne 0 ]; then + log_error "Symlink at $path_to_file does not exist but should. Exit code was: $exit_code." + return 1 + fi + + # Check if directory is a symlink + local result + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "find $path_to_file -type l -xtype f | wc -l") + if [[ "$should_exist" = true && $result -ne 1 ]]; then + log_error "A directory exists at $path_to_file but it is no symlink." + return 1 + elif [[ "$should_exist" = false && $result -ne 0 ]]; then + log_error "The Symlink at $path_to_file shouldn't exist but does." + return 1 + fi + log_success "Symlink at $path_to_file exists as expected." +} + +# Function to check if a directory exists +# Usage: check_file_exists +check_file_exists() { + local path_to_file="$1" + local should_exist="$2" + + local result + local exit_code + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "test -f $path_to_file") + exit_code=$? + if [[ "$should_exist" = true && $exit_code -ne 0 ]]; then + log_error "File or folder at $path_to_file should exist but does not." + return 1 + elif [[ "$should_exist" = false && $exit_code -eq 0 ]]; then + log_error "File or folder at $path_to_file should not exist but does." + return 1 + fi + # If should exist is true, the logging should be different + if [[ "$should_exist" = true ]]; then + log_success "File or folder at $path_to_file exists as expected." + else + log_success "File or folder at $path_to_file does not exist as expected." + fi +} + +# Function to check if a folder exists +# Usage: check_folder_exists +check_folder_exists() { + local path_to_folder="$1" + local should_exist="$2" + + local result + local exit_code + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "test -d $path_to_folder") + exit_code=$? + if [[ "$should_exist" = true && $exit_code -ne 0 ]]; then + log_error "Folder at $path_to_folder should exist but does not." + return 1 + elif [[ "$should_exist" = false && $exit_code -eq 0 ]]; then + log_error "Folder at $path_to_folder should not exist but does." + return 1 + fi + # If should exist is true, the logging should be different + if [[ "$should_exist" = true ]]; then + log_success "Folder at $path_to_folder exists as expected." + else + log_success "Folder at $path_to_folder does not exist as expected." + fi +} + +# Function to check for a line in a directory +# Usage: check_line_in_file +check_line_in_file() { + local line="$1" + local path_to_file="$2" + local should_exist="$3" + + local result + local exit_code + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "grep '$line' $path_to_file") + exit_code=$? + if [[ "$should_exist" = true && $exit_code -ne 0 ]]; then + log_error "Line '$line' should exist in directory $path_to_file but does not." + return 1 + elif [[ "$should_exist" = false && $exit_code -eq 0 ]]; then + log_error "Line '$line' should not exist in directory $path_to_file but does." + return 1 + fi + # If should exist is true, the logging should be different + if [[ "$should_exist" = true ]]; then + log_success "Line '$line' exists in directory $path_to_file as expected." + else + log_success "Line '$line' does not exist in directory $path_to_file as expected." + fi +} + diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/4_permissions.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/4_permissions.sh new file mode 100644 index 0000000000..9bb5ff1c91 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/4_permissions.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +################################# +# Description: Permission related functions +# Author: Julian Psotta +# Date: 2024-02-24 +# ################################# + +# Fail if CONTAINER_NAME is empty or not one of podman or docker +if [ -z "$CONTAINER_ENGINE" ] || [ "$CONTAINER_ENGINE" != "podman" ] && [ "$CONTAINER_ENGINE" != "docker" ]; then + log_error "Please set the CONTAINER_ENGINE variable to either podman or docker." + return 1 +fi + + +# Function to check user and group permissions on a file or folder +# Usage: check_user_group_permissions +check_user_group_permissions() { + local path_to_file="$1" + local user="$2" + local group="$3" + local permissions="$4" + + # Fail if any of the variables are empty + if [ -z "$path_to_file" ] || [ -z "$permissions" ]; then + log_error "Please provide all variables to the check_user_group_permissions function." + return 1 + fi + + # Fail if neither user nor group are set + if [ -z "$user" ] && [ -z "$group" ]; then + log_error "Please provide at least one of user or group to the check_user_group_permissions function." + return 1 + fi + + if [ -n "$user" ] && [ -z "$group" ]; then + # Set group to empty string + group="" + # If only user is set, get stats without group + local result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "stat -c '%a %U' $path_to_file") + if [[ "$result" != "$permissions $user" ]]; then + log_error "Permissions for $path_to_file should be $permissions $user but are $result" + return 1 + fi + log_success "Permissions for $path_to_file are $permissions $user as expected." + return 0 + elif [ -z "$user" ] && [ -n "$group" ]; then + # Check for group only + # Set user to empty string + user="" + local result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "stat -c '%a %G' $path_to_file") + if [[ "$result" != "$permissions $group" ]]; then + log_error "Permissions for $path_to_file should be $permissions $group but are $result" + return 1 + fi + log_success "Permissions for $path_to_file are $permissions $group as expected." + return 0 + else + # Check for user and group + local result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "stat -c '%a %U %G' $path_to_file") + if [[ "$result" != "$permissions $user $group" ]]; then + log_error "Permissions for $path_to_file should be $permissions $user $group but are $result" + return 1 + fi + fi + log_success "Permissions for $path_to_file are $permissions $user $group as expected." +} + +# Function to check if owned content count matches expected count +# Usage: find_owned_content +find_owned_content() { + local folder="$1" + local user="$2" + local group="$3" + local count="$4" + + local user_option="" + local group_option="" + + if [ -n "$user" ]; then + user_option="-user $user" + fi + + if [ -n "$group" ]; then + group_option="-group $group" + fi + + local result + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "find $folder $user_option $group_option | wc -l") + if [ "$result" != "$count" ]; then + log_error "Expected $count owned items in $folder but found $result" + return 1 + fi + log_success "Found $count owned items in $folder for user $user | group $group as expected." +} + diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/5_time.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/5_time.sh new file mode 100644 index 0000000000..203d5da9fd --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/5_time.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +################################# +# Description: Time related functions +# Author: Julian Psotta +# Date: 2024-02-24 +################################# + +# Function to return the current date and time +# Usage: get_date_time +get_date_time() { + date +"%Y-%m-%d %H:%M:%S" +} \ No newline at end of file diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/6_users.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/6_users.sh new file mode 100644 index 0000000000..714e3706b2 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/6_users.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +################################# +# Description: User related functions +# Author: Julian Psotta +# Date: 2024-02-24 +################################# + +# Fail if CONTAINER_NAME is empty or not one of podman or docker +if [ -z "$CONTAINER_ENGINE" ] || [ "$CONTAINER_ENGINE" != "podman" ] && [ "$CONTAINER_ENGINE" != "docker" ]; then + log_error "Please set the CONTAINER_ENGINE variable to either podman or docker." + return 1 +fi + + +# Function to check if a user is in a group +# Usage: check_user_in_group +check_user_in_group() { + local user_name="$1" + local group_name="$2" + + local result + local exit_code + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "getent group $group_name | grep $user_name") + exit_code=$? + if [[ $exit_code -ne 0 ]]; then + log_error "User $user_name should be in group $group_name but is not." + return 1 + fi + log_success "User $user_name is in group $group_name as expected." +} + +# Function to check if a user exists +# Usage: check_user_exists +check_user_exists() { + local user_name="$1" + local should_exist="$2" + + local result + local exit_code + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "getent passwd $user_name") + exit_code=$? + if [[ "$should_exist" = true && $exit_code -ne 0 ]]; then + log_error "User $user_name should exist but does not." + return 1 + elif [[ "$should_exist" = false && $exit_code -eq 0 ]]; then + log_error "User $user_name shouldn't exist but does." + return 1 + fi + # If should exist is true, the logging should be different + if [[ "$should_exist" = true ]]; then + log_success "User $user_name exists as expected." + else + log_success "User $user_name does not exist as expected." + fi +} + +# Function to check if a group exists +# Usage: check_group_exists +check_group_exists() { + local group_name="$1" + local should_exist="$2" + + local result + local exit_code + result=$(${CONTAINER_ENGINE} exec -u root "$CONTAINER_NAME" bash -c "getent group $group_name") + exit_code=$? + if [[ "$should_exist" = true && $exit_code -ne 0 ]]; then + log_error "Group $group_name should exist but does not." + return 1 + elif [[ "$should_exist" = false && $exit_code -eq 0 ]]; then + log_error "Group $group_name shouldn't exist but does." + return 1 + fi + # If should exist is true, the logging should be different + if [[ "$should_exist" = true ]]; then + log_success "Group $group_name exists as expected." + else + log_success "Group $group_name does not exist as expected." + fi +} diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/7_networking.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/7_networking.sh new file mode 100644 index 0000000000..a984ab8c63 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/7_networking.sh @@ -0,0 +1,65 @@ +#!/bin/bash +################################# +# Description: Network related functions +# Author: Julian Psotta +# Date: 2024-02-24 +# ################################# + +# Function to check if a port is open +# Usage: check_port_open +function wait_for_url() { + local url="$1" + local timeout_sec="$2" + local expected_http_code="$3" + local sleep=${4:-2} + local report_every=${5:-10} + + start_time=$(date +%s) + turn=0 + while true; do + response=$(curl -s -o /dev/null -w "%{http_code}" "${url}") + if [[ "$response" == "${expected_http_code}" ]]; then + log_success "Request succeeded for ${url} with expected http code ${expected_http_code}" + return 0 + fi + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) + remaining_time=$(( timeout_sec - elapsed_time)) + if ((elapsed_time >= timeout_sec)); then + log_error "Timed out waiting for response after ${timeout_sec} seconds for ${url}" + return 1 + fi + if [ $(( turn % report_every )) -eq "0" ]; then + log_warning "GET request failed with response code ${response} for ${url}, retrying for another ${remaining_time} seconds..." + fi + (( turn+=1 )) + sleep "$sleep" + done +} + +# Function to return a free port +# Usage: get_free_port +get_free_port() { + # Check for open ports in a given range. Do not echo anything besides the port! + # If no range is given, it is chosen automatically + local lower_port=${1} + local upper_port=${2} + if [ -z "${lower_port}" ]; then + read -r lower_port _ /dev/null | grep "$lower_port") + done + if [[ "$lower_port" -gt "$upper_port" ]]; then + log_error "Could not find a free port to start the container." + exit 1 + fi + echo "$lower_port" +} diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/8_openrouteservice.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/8_openrouteservice.sh new file mode 100644 index 0000000000..49bf82b648 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/helpers/8_openrouteservice.sh @@ -0,0 +1,63 @@ +# Create a function from the above snippet +# Usage: check_number_of_profiles_loaded +check_number_of_profiles_loaded() { + local url="$1" + local expected_number_of_profiles="$2" + if ! curl -s "${url}" | jq ".profiles | length == ${expected_number_of_profiles}" | grep -q true; then + log_error "Expected number of profiles ${expected_number_of_profiles} not found" + return 1 + fi + log_success "Expected number of ${expected_number_of_profiles} profiles are loaded." + return 0 +} + +# Check specific profile is loaded +# Usage: check_profile_loaded +check_profile_loaded() { + local url="$1" + local profile_name="$2" + local profile_expected=${3:-true} + # Get the return json and check if the profile is loaded + response=$(curl -s "${url}") + # If profiles not found or profiles empty return error if profile_expected is true + if ! echo "${response}" | jq ".profiles | length > 0" | grep -q true; then + if [[ "$profile_expected" == true ]]; then + log_error "No profiles found in the response" + return 1 + else + log_success "Profile ${profile_name} is not loaded as expected." + return 0 + fi + fi + # Iterate over profiles and check if the profile is loaded + if [ $profile_expected == true ] && ! echo "${response}" | jq -e ".profiles | to_entries[] | select(.value.profiles == \"${profile_name}\")" > /dev/null; then + log_error "Profile ${profile_name} should be loaded but is not." + return 1 + elif [ $profile_expected == false ] && echo "${response}" | jq -e ".profiles | to_entries[] | select(.value.profiles == \"${profile_name}\")" > /dev/null; then + log_error "Profile ${profile_name} should not be loaded but is." + return 1 + fi + + if [ $profile_expected == true ]; then + log_success "Profile ${profile_name} is loaded, as expected." + return 0 + else + log_success "Profile ${profile_name} is not loaded, as expected." + return 0 + fi +} + +# Function to check for a valid avoid area request in Heidelberg +# Usage: check_avoid_area_request +check_avoid_area_request() { + local url="$1" + local expected_http_code="$2" + local request_body='{"coordinates":[[8.681495,49.41461],[8.686507,49.41943],[8.687872,49.420318]],"options":{"avoid_polygons":{"coordinates":[[[8.684881031827587,49.41768066444595],[8.684881031827587,49.41699648134178],[8.685816955915811,49.41699648134178],[8.685816955915811,49.41768066444595],[8.684881031827587,49.41768066444595]]],"type":"Polygon"}}}' + response=$(curl -s -o /dev/null -w "%{http_code}" -X POST "${url}" -H 'Content-Type: application/json; charset=utf-8' -H 'Accept: application/geo+json; charset=utf-8' -d "${request_body}") + if [[ "$response" == "${expected_http_code}" ]]; then + log_success "Avoid areas request succeeded for ${url} with expected http code ${expected_http_code}" + return 0 + fi + log_error "Avoid areas request failed with response code ${response} for ${url}" + return 1 +} diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/run.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/run.sh new file mode 100755 index 0000000000..cf952e2a8e --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/run.sh @@ -0,0 +1,165 @@ +#!/bin/bash +####### Description ####### +# This script is used to build and run the container that emulates the debian-12 with tomcat and a war file scenario. +# Tomcat itself is started using systemd, and the war file is deployed to the webapps directory. +########################### +################################### +# Initialize the helper functions # +################################### +export SCRIPT_NAME=$(basename "$0") +export CONTAINER_ENGINE="podman" +export CONTAINER_NAME="tomcat-test" +CONTAINER_IMAGE='local/tomcat-test:latest' + +# Get the absolute path of this script +START_DIRECTORY="$( + cd "$(dirname "$0")" >/dev/null 2>&1 || exit 1 + pwd -P +)" + + +################################# +# Parse command-line options with long commands --something +################################# +# Function to display usage information +display_usage() { + echo "This script is used to build and run the container that emulates the debian-12 with tomcat and a war file scenario." + echo "Usage: ./run.sh -c -t -u " + echo "-c: Run in CI mode. Default is false." + echo "-t: Run integration tests. Default is false." + echo "-p: Run tests in parallel. Default is false." + echo "-u: Run unit tests. Default is false." + echo "-i: Container image to use. Default is '-i local/tomcat-test:latest'" + echo "-l: Log level. Default is '-l SUCCESS'" + echo "-h: Display this help message" +} +while getopts 'ctpu:g:i:l:h' opt; do + case ${opt} in + c) + CI=true + ;; + t) + RUN_INTEGRATION_TESTS=true + ;; + p) + PARALLEL_TESTS=true + ;; + u) + UNIT_TESTS=true + ;; + g) + GLOB_PATTERN=${OPTARG} + ;; + i) + CONTAINER_IMAGE=${OPTARG} + ;; + l) + LOG_LEVEL=${OPTARG} + ;; + h) + display_usage + exit 0 + ;; + \?) + warning "Invalid option: -$OPTARG" >&2 + display_usage + exit 1 + ;; + :) + warning "Option -$OPTARG requires an argument." >&2 + display_usage + exit 1 + ;; + esac +done + +export CONTAINER_IMAGE=${CONTAINER_IMAGE} + +# Import logging +. "$START_DIRECTORY/helpers/1_logging.sh" +. "$START_DIRECTORY/helpers/2_system.sh" + +check_program_installed "podman" || exit 1 +check_program_installed "jq" || exit 1 +check_program_installed "bc" || exit 1 +check_program_installed "mvn" || exit 1 + +# Set default values +CI=${CI:-false} +RUN_INTEGRATION_TESTS=${RUN_INTEGRATION_TESTS:-false} +UNIT_TESTS=${UNIT_TESTS:-false} +PARALLEL_TESTS=${PARALLEL_TESTS:-false} +GLOB_PATTERN=${GLOB_PATTERN:-"[0-9]_*.sh"} +export LOG_LEVEL=${LOG_LEVEL:-"SUCCESS"} + +if [ "$CI" = "false" ]; then + log_info "Running in local mode. Tailing catalina.out file in the end." +else + log_info "Running in CI mode. Skipping catalina.out tailing" +fi + +############################# +# Build the container image # +############################# +podman build -v ~/.m2:/root/.m2 --ignorefile ./.integration-scenarios/debian-12-tomcat-war-systemd/Dockerfile.dockerignore -t $CONTAINER_IMAGE --build-arg TOMCAT_MAJOR=10 --build-arg UNIT_TESTS=$UNIT_TESTS -f .integration-scenarios/debian-12-tomcat-war-systemd/Dockerfile . + + +############################## +# Run the integration tests # +############################## +# If parallel tests are enabled, we need to set the log level to ERROR to avoid too much output +if [ "$PARALLEL_TESTS" = "true" ]; then + export LOG_LEVEL="ERROR" +fi + +# declare array +declare -A running_processes + +# Use the glob pattern to find all the tests in the tests folder +for file in $START_DIRECTORY/tests/$GLOB_PATTERN; do + # Skip it run tests is false + if [ "$RUN_INTEGRATION_TESTS" = "false" ]; then + log_info "Skipping $file" + continue + fi + # Run the test in the background + if [ "$PARALLEL_TESTS" = "true" ]; then + log_info "Running parallel test: $file" + bash $file $CONTAINER_IMAGE & + running_processes[$file]=$! + sleep 5 + else + log_info "Running sequential test: $file" + bash $file $CONTAINER_IMAGE + fi +done + +# Reactivate the logging +export LOG_LEVEL="SUCCESS" + +# Wait for all processes to finish +for key in "${!running_processes[@]}"; do + pid=${running_processes[${key}]} + wait_for_pid $pid "Waiting for $key to finish" + log_success "$key finished." +done + +############################## +# Clean up the containers # +############################## + +# Get all containers starting with tomcat-test-* and clean them +CONTAINERS=$(podman ps -a --format "{{.Names}}" | grep $CONTAINER_NAME) +# If empty string, exit +if [ -z "$CONTAINERS" ]; then + log_info "No containers to clean up" + exit 0 +else + # Remove dangling containers + for CONTAINER in $CONTAINERS; do + if [[ $CONTAINER == "tomcat-test-"* ]]; then + log_info "Cleanup container $CONTAINER" + podman rm -f $CONTAINER + fi + done +fi \ No newline at end of file diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/setup/install.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/setup/install.sh new file mode 100755 index 0000000000..f438bce647 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/setup/install.sh @@ -0,0 +1,302 @@ +#!/bin/bash + +# Function to display usage information +display_usage() { + echo "This script is used to setup the openrouteservice environment on a debian 12 system with an external tomcat and systemd." + echo "Minimal usage: install.sh -w " + echo "Full usage: install.sh -v -u -t -g -w " + echo "Example to install Tomcat 10 for user ors:" + echo ">> sudo install.sh -t 10 -u ors -w /path/to/ors.war" +} + +# Function to log error messages +log_error() { + echo -e "\e[31m✗ Error: $1\e[0m" + return 1 +} + +# Function to log success messages +log_success() { + echo -e "\e[32m✓ $1\e[0m" + return 0 +} + +# Parse command-line options +while getopts ":v:u:w:t:g:h" opt; do + case ${opt} in + h) + display_usage + exit 0 + ;; + v) + TOMCAT_VERSION=${OPTARG:-10} + ;; + u) + USER=${OPTARG:-ors} + ;; + t) + TOMCAT_USER=${OPTARG:-tomcat} + ;; + g) + TOMCAT_GROUP=${OPTARG:-tomcat} + ;; + w) + WAR_FILE=${OPTARG} + ;; + \?) + log_error "Invalid option: -$OPTARG" >&2 + display_usage + exit 1 + ;; + :) + log_error "Option -$OPTARG requires an argument." >&2 + display_usage + exit 1 + ;; + esac +done + +# Set default values +TOMCAT_VERSION=${TOMCAT_VERSION:-10} +USER=${USER:-ors} +TOMCAT_USER=${TOMCAT_USER:-tomcat} +TOMCAT_GROUP=${TOMCAT_GROUP:-tomcat} + + +# Ensure required options are set +if [ -z "$TOMCAT_VERSION" ] || [ -z "$USER" ] || [ -z "$WAR_FILE" ] || [ -z "$TOMCAT_USER" ] || [ -z "$TOMCAT_GROUP" ]; then + log_error "Missing one of the following options:" + echo "-v $TOMCAT_VERSION" + echo "-u $USER" + echo "-t $TOMCAT_USER" + echo "-g $TOMCAT_GROUP" + echo "-w $WAR_FILE" + display_usage + exit 1 +fi + +# Ensure war file exists +if [ ! -f "$WAR_FILE" ]; then + log_error "War file does not exist: $WAR_FILE" + display_usage + exit 1 +fi + +# Ensure script is run as root +if [ "$EUID" -ne 0 ]; then + log_error "Please run as root." + exit 1 +fi + +# Check that the script is running on debian and the version is 12.x +if [ ! -f "/etc/debian_version" ] || [[ "$(cat /etc/debian_version)" != "12."* ]]; then + log_error "This script is only supported on debian 12." + exit 1 +fi + +# Print a good message with script parameters +echo "Script started with settings:" +echo "TOMCAT_VERSION: $TOMCAT_VERSION" +echo "USER: $USER" +echo "TOMCAT_USER: $TOMCAT_USER" +echo "TOMCAT_GROUP: $TOMCAT_GROUP" +echo "WAR_FILE: $WAR_FILE" + +# Define variables +HOME_FOLDER="/home/$USER" +TOMCAT_FOLDER="/opt/tomcat/$TOMCAT_VERSION" + +# Install dependencies +if ! apt-get update; then + log_error "Failed to update apt." + exit 1 +fi + +if ! apt-get install -y curl openjdk-17-jdk-headless systemd init maven; then + log_error "Failed to install dependencies." + exit 1 +fi + +# Create tomcat group if it does not exist +if ! getent group "$TOMCAT_GROUP" &>/dev/null; then + if ! groupadd "$TOMCAT_GROUP"; then + log_error "Failed to create $TOMCAT_GROUP group." + exit 1 + fi +fi + +# Create tomcat user if it does not exist +if ! id -u "$TOMCAT_USER" &>/dev/null; then + if ! useradd -g "$TOMCAT_GROUP" -m -d "$TOMCAT_FOLDER" -s /bin/false "$TOMCAT_USER"; then + log_error "Failed to create $TOMCAT_USER user." + exit 1 + fi +fi + +# Create user if it does not exist +if ! id -u "$USER" &>/dev/null; then + if ! useradd -g "$TOMCAT_GROUP" -m -d "$HOME_FOLDER" -s /bin/bash "$USER"; then + log_error "Failed to create $USER." + exit 1 + fi +fi + +# Add user to tomcat group in case the user already existed +if ! usermod -aG "$TOMCAT_GROUP" "$USER"; then + log_error "Failed to add $USER to $TOMCAT_USER group." + exit 1 +fi + +# Add tomcat to tomcat group in case the user already existed +if ! usermod -aG "$TOMCAT_GROUP" "$TOMCAT_USER"; then + log_error "Failed to add $TOMCAT_USER to $TOMCAT_USER group." + exit 1 +fi + +# Download and install tomcat +latest_tomcat_version=$(curl -s "https://dlcdn.apache.org/tomcat/tomcat-${TOMCAT_VERSION}/" | grep -Po '(?<=(v)' | sort -V | tail -n 1) +TOMCAT_URL="https://dlcdn.apache.org/tomcat/tomcat-${TOMCAT_VERSION}/v${latest_tomcat_version}/bin/apache-tomcat-${latest_tomcat_version}.tar.gz" +OUTPUT_FILENAME="apache-tomcat-${latest_tomcat_version}.tar.gz" +if ! curl -o "/tmp/$OUTPUT_FILENAME" "$TOMCAT_URL"; then + log_error "Failed to download Tomcat." + exit 1 +fi + +# Create tomcat folder +if ! mkdir -p "$TOMCAT_FOLDER"; then + log_error "Failed to create $TOMCAT_FOLDER." + exit 1 +fi + +# Extract tomcat archive +if ! tar xzf "/tmp/$OUTPUT_FILENAME" -C "$TOMCAT_FOLDER" --strip-components=1; then + log_error "Failed to extract Tomcat archive." + exit 1 +fi + +# Remove the downloaded archive +if ! rm -rf "$TOMCAT_FOLDER/webapps/*"; then + log_error "Failed to remove webapps." + exit 1 +fi + +# Populate the tomcat folders +for folder in "$TOMCAT_FOLDER/logs" "$TOMCAT_FOLDER/temp" "$TOMCAT_FOLDER/conf" "$TOMCAT_FOLDER/webapps"; do + mkdir -p "$folder" || { log_error "Failed to create $folder"; exit 1; } +done + +# Populate the USER folders +for folder in "$HOME_FOLDER/logs" "$HOME_FOLDER/graphs"; do + mkdir -p "$folder" || { log_error "Failed to create $folder"; exit 1; } +done + +# Copy the war file to the tomcat webapps folder +if ! cp -f "$WAR_FILE" "$TOMCAT_FOLDER/webapps/ors.war"; then + log_error "Failed to copy war file." + exit 1 +fi + +# Copy setenv file to the user folder +if ! cp -f .integration-scenarios/debian-12-tomcat-war-systemd/setup/setenv.sh "$HOME_FOLDER/setenv.sh"; then + log_error "Failed to copy setenv.sh to $HOME_FOLDER/." + exit 1 +fi + +# Create the setenv. sh in the tomcat bin folder and source the user setenv.sh from there +if ! echo ". $HOME_FOLDER/setenv.sh" > "$TOMCAT_FOLDER/bin/setenv.sh"; then + log_error "Failed to source setenv.sh." + exit 1 +fi + +# Create systemd service file +if ! mkdir -p /etc/systemd/system; then + log_error "Failed to create /etc/systemd/system." + exit 1 +fi +cat < /etc/systemd/system/openrouteservice.service +[Unit] +Description=Apache Tomcat Web Application Container for openrouteservice +After=network.target + +[Service] +Type=forking +# Decide where ors will look for the ors-config.yml file +WorkingDirectory=$HOME_FOLDER +Environment=CATALINA_PID=$TOMCAT_FOLDER/temp/tomcat.pid +Environment=CATALINA_HOME=$TOMCAT_FOLDER +Environment=CATALINA_BASE=$TOMCAT_FOLDER +Environment=JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 +# CATALINA_OPTS are extended by $HOME_FOLDER/setenv.sh +Environment=CATALINA_OPTS="" +# JAVA_OPTS are extended by $HOME_FOLDER/setenv.sh +Environment=JAVA_OPTS="" +ExecStart=$TOMCAT_FOLDER/bin/startup.sh +ExecStop=$TOMCAT_FOLDER/bin/shutdown.sh +User=$TOMCAT_USER +Group=$TOMCAT_GROUP +UMask=0777 +Restart=always + +[Install] +WantedBy=multi-user.target +EOF + +# Set correct permissions for the systemd service file +if ! chmod 664 "/etc/systemd/system/openrouteservice.service"; then + log_error "Failed to set permissions for openrouteservice.service." + exit 1 +fi +# Copy relevant files +if ! cp -rf ors-api/src/test/files "$HOME_FOLDER/files"; then + log_error "Failed to copy heidelberg.osm.gz." + exit 1 +fi + +if ! cp -rf ors-api/src/test/files/elevation "$HOME_FOLDER/elevation_cache"; then + log_error "Failed to copy elevation." + exit 1 +fi + +if ! cp -f ors-config.yml "$HOME_FOLDER/ors-config.yml"; then + log_error "Failed to copy ors-config.yml." + exit 1 +fi + +# Fix permissions and ownerships +if ! chown -R "$TOMCAT_USER:tomcat" "$TOMCAT_FOLDER/"; then + log_error "Failed to set permissions and ownerships for $TOMCAT_FOLDER." + exit 1 +fi + +if ! chown -R "$USER:tomcat" "$HOME_FOLDER/"; then + log_error "Failed to set permissions and ownerships for $HOME_FOLDER." + exit 1 +fi + +if ! chgrp -R tomcat "$TOMCAT_FOLDER" "$HOME_FOLDER"; then + log_error "Failed to set permissions." + exit 1 +fi + +if ! chmod -R 770 "$TOMCAT_FOLDER/conf" "$TOMCAT_FOLDER/logs" "$HOME_FOLDER"; then + log_error "Failed to set permissions." + exit 1 +fi + +cat < "$HOME_FOLDER/README.md" +Tomcat $TOMCAT_VERSION has been installed with a systemd service file to start and stop the service. +Alongside, a user '$USER' has been created and added to the tomcat group. +The user should be used to do further configurations in the $HOME_FOLDER folder. +--------------------- Manual steps ------------------------ +0. Investigate the service file with: sudo systemctl cat openrouteservice +1. Adjust the default ors-config.yml and setenv.sh files in $HOME_FOLDER +Note: Everything defined in setenv.sh overwrites the default ors-config.yml file via ENVs. +Note: The default configs run an example setup with the heidelberg.osm.gz file. You should replace this with your own data. +2. Start tomcat using the command: sudo systemctl start openrouteservice +3. Check tomcat logs with: cat $TOMCAT_FOLDER/logs/catalina.out +4. Check ors logs with: cat $HOME_FOLDER/logs/ors.log +5. Make the openrouteservice tomcat process permanent: sudo systemctl enable openrouteservice +----------------------------------------------------------- +EOF + +log_success "Successfully installed Tomcat $TOMCAT_VERSION with systemd service file. Check the README.md file in $HOME_FOLDER for further instructions." \ No newline at end of file diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/setup/setenv.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/setup/setenv.sh new file mode 100644 index 0000000000..bcf1752815 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/setup/setenv.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# This script sets environment variables for the openrouteservice systemd webapp +# There is no other way to pass environment variables to the webapp +export CATALINA_OPTS="$CATALINA_OPTS \ +-Xms100M \ +-Xmx600M \ +-server \ +-XX:+UseParallelGC\ +" + +export JAVA_OPTS="$JAVA_OPTS -Dors.engine.source_file=/home/ors/files/heidelberg.osm.gz" diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/tests/0_test_default.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/tests/0_test_default.sh new file mode 100755 index 0000000000..d455a26fcf --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/tests/0_test_default.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +################################# +# Description: Test the default container +################################# + +# Define container name +SCRIPT_NAME=$(basename "$0") +export CONTAINER_NAME="tomcat-test-$SCRIPT_NAME" +export CONTAINER_IMAGE="${1:-'local/tomcat-test:latest'}" +export CONTAINER_ENGINE="podman" + +# Get the absolute path of this script +START_DIRECTORY="$( + cd "$(dirname "$0")" >/dev/null 2>&1 || exit 1 + pwd -P +)" + + + +# Import logging and networking +. "$START_DIRECTORY/../helpers/1_logging.sh" +. "$START_DIRECTORY/../helpers/2_system.sh" +. "$START_DIRECTORY/../helpers/3_files.sh" +. "$START_DIRECTORY/../helpers/4_permissions.sh" +. "$START_DIRECTORY/../helpers/7_networking.sh" +. "$START_DIRECTORY/../helpers/8_openrouteservice.sh" + +log_info "Running test suite $SCRIPT_NAME with container $CONTAINER_NAME from image $CONTAINER_IMAGE" +# Check if the container exists and remove it +if podman ps -a | grep -q $CONTAINER_NAME; then podman rm -f $CONTAINER_NAME; fi +# Start container +PORT=$(get_free_port) +podman run -d --name $CONTAINER_NAME --systemd true -p ${PORT}:8080 $CONTAINER_IMAGE + +# Check the java version +check_java_version "17" || exit 1 + +# Check if the systemd service is enabled +check_systemd_service_enabled "openrouteservice" true || exit 1 + +# Wait for the container to start +wait_for_url "127.0.0.1:${PORT}/ors/v2/health" 100 200 1 5 || exit 1 + +# Check that one profile is loaded +check_number_of_profiles_loaded "127.0.0.1:${PORT}/ors/v2/status" 1 || exit 1 + +# Check that 'driving-car' is loaded +check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" "driving-car" true|| exit 1 + +# Check that the graphs are properly build +find_owned_content "/home/ors/" "ors" "tomcat" 12 || exit 1 +find_owned_content "/home/ors/graphs/" "ors" "tomcat" 1 || exit 1 +find_owned_content "/home/ors/graphs/car" "tomcat" "tomcat" 28 || exit 1 + +# Check that each of the following folders exist +folders_to_expect=( + "/opt/tomcat/10/webapps/ors" + "/opt/tomcat/10/temp" + "/home/ors/graphs/car" + "/home/ors/elevation_cache" +) +for folder in "${folders_to_expect[@]}"; do + check_folder_exists $folder true || exit 1 +done + +# Check that each of the following files exist +files_to_expect=( + "/home/ors/ors-config.yml" + "/home/ors/logs/ors.log" + "/home/ors/setenv.sh" + "/home/ors/files/heidelberg.osm.gz" + "/opt/tomcat/10/bin/setenv.sh" + "/opt/tomcat/10/webapps/ors.war" + "/etc/systemd/system/openrouteservice.service" +) +for file in "${files_to_expect[@]}"; do + check_file_exists $file true || exit 1 +done + +# assert export JAVA_OPTS="$JAVA_OPTS -Dors.engine.source_file=/home/ors/files/heidelberg.osm.gz" in file setenv.sh +check_line_in_file "export JAVA_OPTS=\"\$JAVA_OPTS -Dors.engine.source_file=/home/ors/files/heidelberg.osm.gz\"" /home/ors/setenv.sh true || exit 1 + +# Assert source /home/ors/setenv.sh in file /opt/tomcat/10/bin/setenv.sh +check_line_in_file ". /home/ors/setenv.sh" /opt/tomcat/10/bin/setenv.sh true || exit 1 + +# Check that /opt/tomcat/10/temp/GeoTools folder doesnt exist yet +check_folder_exists "/opt/tomcat/10/temp/GeoTools" false || exit 1 + +# Check that the server responds with a 200 status code for an avoid polygon request +check_avoid_area_request "http://127.0.0.1:${PORT}/ors/v2/directions/driving-car/geojson" 200 || exit 1 + +# Check that /opt/tomcat/10/temp/GeoTools folder exists now +check_folder_exists "/opt/tomcat/10/temp/GeoTools" true || exit 1 \ No newline at end of file diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/tests/1_test_activate_second_profile_with_config.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/tests/1_test_activate_second_profile_with_config.sh new file mode 100755 index 0000000000..346f5a1e94 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/tests/1_test_activate_second_profile_with_config.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +################################# +# Description: Test the default container +################################# + +# Define container name +SCRIPT_NAME=$(basename "$0") +export CONTAINER_NAME="tomcat-test-$SCRIPT_NAME" +export CONTAINER_IMAGE="${1:-'local/tomcat-test:latest'}" +export CONTAINER_ENGINE="podman" + +# Get the absolute path of this script +START_DIRECTORY="$( + cd "$(dirname "$0")" >/dev/null 2>&1 || exit 1 + pwd -P +)" + + +# Import logging and networking +. "$START_DIRECTORY/../helpers/1_logging.sh" +. "$START_DIRECTORY/../helpers/2_system.sh" +. "$START_DIRECTORY/../helpers/3_files.sh" +. "$START_DIRECTORY/../helpers/7_networking.sh" +. "$START_DIRECTORY/../helpers/8_openrouteservice.sh" + +log_info "Running test suite $SCRIPT_NAME with container $CONTAINER_NAME from image $CONTAINER_IMAGE" +# Check if the container exists and remove it +if podman ps -a | grep -q $CONTAINER_NAME; then podman rm -f $CONTAINER_NAME; fi + +# Start container +PORT=$(get_free_port) +podman run -d --name $CONTAINER_NAME --systemd true -p ${PORT}:8080 $CONTAINER_IMAGE + +# Check the java version +check_java_version "17" || exit 1 + +# Check if the systemd service is enabled +check_systemd_service_enabled "openrouteservice" true || exit 1 + +# Wait for the container to start +wait_for_url "127.0.0.1:${PORT}/ors/v2/health" 100 200 1 5 || exit 1 + +# Check that one profile is loaded +check_number_of_profiles_loaded "127.0.0.1:${PORT}/ors/v2/status" 1 || exit 1 + +# Check that 'driving-car' is loaded +check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" "driving-car" true|| exit 1 + +# Activate the hgv profile +podman exec -it $CONTAINER_NAME /bin/bash -c "yq -y -i '.ors.engine.profiles.hgv.enabled = true' /home/ors/ors-config.yml" || exit 1 + +# Restart the container silently +log_info "Restarting the container to activate the hgv profile" +podman restart $CONTAINER_NAME > /dev/null || exit 1 + +# Wait for the container to start +wait_for_url "127.0.0.1:${PORT}/ors/v2/health" 100 200 1 5 || exit 1 + +# Check that one profile is loaded +check_number_of_profiles_loaded "127.0.0.1:${PORT}/ors/v2/status" 2 || exit 1 + +# Check that 'driving-car' is loaded +check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" "driving-car" true|| exit 1 +check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" "driving-hgv" true|| exit 1 + +# Check that each of the following folders exist +folders_to_expect=( + "/home/ors/graphs/car" + "/home/ors/graphs/hgv" +) +for folder in "${folders_to_expect[@]}"; do + check_folder_exists $folder true || exit 1 +done + +# Check that each of the following files exist +files_to_expect=( + "/home/ors/ors-config.yml" +) +for file in "${files_to_expect[@]}"; do + check_file_exists $file true || exit 1 +done + +# assert export JAVA_OPTS="$JAVA_OPTS -Dors.engine.source_file=/home/ors/files/heidelberg.osm.gz" in file setenv.sh +check_line_in_file "export JAVA_OPTS=\"\$JAVA_OPTS -Dors.engine.source_file=/home/ors/files/heidelberg.osm.gz\"" /home/ors/setenv.sh true || exit 1 + +# Check that /opt/tomcat/10/temp/GeoTools folder doesnt exist yet +check_folder_exists "/opt/tomcat/10/temp/GeoTools" false || exit 1 + +# Check that the server responds with a 200 status code for an avoid polygon request +check_avoid_area_request "http://127.0.0.1:${PORT}/ors/v2/directions/driving-hgv/geojson" 200 || exit 1 + +# Check that /opt/tomcat/10/temp/GeoTools folder exists now +check_folder_exists "/opt/tomcat/10/temp/GeoTools" true || exit 1 \ No newline at end of file diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/tests/2_test_activate_three_profiles_with_env.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/tests/2_test_activate_three_profiles_with_env.sh new file mode 100755 index 0000000000..65738b0ffc --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/tests/2_test_activate_three_profiles_with_env.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash +################################# +# Description: Test the default container +################################# + +# Define container name +SCRIPT_NAME=$(basename "$0") +export CONTAINER_NAME="tomcat-test-$SCRIPT_NAME" +export CONTAINER_IMAGE="${1:-'local/tomcat-test:latest'}" +export CONTAINER_ENGINE="podman" + +# Get the absolute path of this script +START_DIRECTORY="$( + cd "$(dirname "$0")" >/dev/null 2>&1 || exit 1 + pwd -P +)" + + +# Import logging and networking +. "$START_DIRECTORY/../helpers/1_logging.sh" +. "$START_DIRECTORY/../helpers/2_system.sh" +. "$START_DIRECTORY/../helpers/3_files.sh" +. "$START_DIRECTORY/../helpers/7_networking.sh" +. "$START_DIRECTORY/../helpers/8_openrouteservice.sh" + +log_info "Running test suite $SCRIPT_NAME with container $CONTAINER_NAME from image $CONTAINER_IMAGE" +# Check if the container exists and remove it +if podman ps -a | grep -q $CONTAINER_NAME; then podman rm -f $CONTAINER_NAME; fi + +# Start container +PORT=$(get_free_port) +podman run -d --name $CONTAINER_NAME --systemd true -p ${PORT}:8080 $CONTAINER_IMAGE + +# Check the java version +check_java_version "17" || exit 1 + +# Check if the systemd service is enabled +check_systemd_service_enabled "openrouteservice" true || exit 1 + +# Wait for the container to start +wait_for_url "127.0.0.1:${PORT}/ors/v2/health" 100 200 1 5 || exit 1 + +# Check that one profile is loaded +check_number_of_profiles_loaded "127.0.0.1:${PORT}/ors/v2/status" 1 || exit 1 + +# Check that 'driving-car' is loaded +check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" "driving-car" true|| exit 1 + +log_info "Deactivating the hgv profile explicitly" +podman exec -it $CONTAINER_NAME /bin/bash -c "yq -y -i '.ors.engine.profiles.hgv.enabled = false' /home/ors/ors-config.yml" || exit 1 + +log_info "Set the source file to heidelberg.osm.gz through the ors-config.yml" +podman exec -it $CONTAINER_NAME /bin/bash -c "yq -y -i '.ors.engine.source_file = \"/home/ors/files/heidelberg.osm.gz\"' /home/ors/ors-config.yml" || exit 1 + +log_info "Activating the hgv and bike-regular profiles through the setenv.sh" +podman exec -it $CONTAINER_NAME /bin/bash -c "echo 'export JAVA_OPTS=\"\$JAVA_OPTS \ +-Dors.engine.profiles.hgv.enabled=true \ +-Dors.engine.profiles.bike-regular.enabled=true\"' > /home/ors/setenv.sh" || exit 1 + + +# Restart the container silently +log_info "Restarting the container to activate the hgv and bike-regular profiles" +podman restart $CONTAINER_NAME > /dev/null || exit 1 + +# Wait for the container to start +wait_for_url "127.0.0.1:${PORT}/ors/v2/health" 100 200 1 5 || exit 1 + +# Check that one profile is loaded +check_number_of_profiles_loaded "127.0.0.1:${PORT}/ors/v2/status" 3 || exit 1 + +# Check that 'driving-car' is loaded +check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" "driving-car" true|| exit 1 +check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" "driving-hgv" true|| exit 1 +check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" "cycling-regular" true|| exit 1 + +# Check that each of the following folders exist +folders_to_expect=( + "/home/ors/graphs/car" + "/home/ors/graphs/hgv" + "/home/ors/graphs/bike-regular" +) +for folder in "${folders_to_expect[@]}"; do + check_folder_exists $folder true || exit 1 +done + +# Check that each of the following files exist +files_to_expect=( + "/home/ors/ors-config.yml" + "/home/ors/setenv.sh" +) +for file in "${files_to_expect[@]}"; do + check_file_exists $file true || exit 1 +done + +# Check that /opt/tomcat/10/temp/GeoTools folder doesnt exist yet +check_folder_exists "/opt/tomcat/10/temp/GeoTools" false || exit 1 + +# Check that the server responds with a 200 status code for an avoid polygon request +check_avoid_area_request "http://127.0.0.1:${PORT}/ors/v2/directions/cycling-regular/geojson" 200 || exit 1 + +# Check that /opt/tomcat/10/temp/GeoTools folder exists now +check_folder_exists "/opt/tomcat/10/temp/GeoTools" true || exit 1 \ No newline at end of file diff --git a/.integration-scenarios/debian-12-tomcat-war-systemd/tests/3_build_all_profiles.sh b/.integration-scenarios/debian-12-tomcat-war-systemd/tests/3_build_all_profiles.sh new file mode 100755 index 0000000000..c2b79aa397 --- /dev/null +++ b/.integration-scenarios/debian-12-tomcat-war-systemd/tests/3_build_all_profiles.sh @@ -0,0 +1,150 @@ +#!/usr/bin/env bash +################################# +# Description: Test the default container +################################# + +# Define container name +SCRIPT_NAME=$(basename "$0") +export CONTAINER_NAME="tomcat-test-$SCRIPT_NAME" +export CONTAINER_IMAGE="${1:-'local/tomcat-test:latest'}" +export CONTAINER_ENGINE="podman" + +# Get the absolute path of this script +START_DIRECTORY="$( + cd "$(dirname "$0")" >/dev/null 2>&1 || exit 1 + pwd -P +)" + + +# Import logging and networking +. "$START_DIRECTORY/../helpers/1_logging.sh" +. "$START_DIRECTORY/../helpers/2_system.sh" +. "$START_DIRECTORY/../helpers/3_files.sh" +. "$START_DIRECTORY/../helpers/7_networking.sh" +. "$START_DIRECTORY/../helpers/8_openrouteservice.sh" + +log_info "Running test suite $SCRIPT_NAME with container $CONTAINER_NAME from image $CONTAINER_IMAGE" +# Check if the container exists and remove it +if podman ps -a | grep -q $CONTAINER_NAME; then podman rm -f $CONTAINER_NAME; fi + +# Start container +PORT=$(get_free_port) +podman run -d --name $CONTAINER_NAME --systemd true -p ${PORT}:8080 $CONTAINER_IMAGE + +# Check the java version +check_java_version "17" || exit 1 + +# Check if the systemd service is enabled +check_systemd_service_enabled "openrouteservice" true || exit 1 + +# Wait for the container to start +wait_for_url "127.0.0.1:${PORT}/ors/v2/health" 100 200 1 5 || exit 1 + +# Check that one profile is loaded +check_number_of_profiles_loaded "127.0.0.1:${PORT}/ors/v2/status" 1 || exit 1 + +# Check that 'driving-car' is loaded +check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" "driving-car" true|| exit 1 + + +log_info "Set the source file to heidelberg.osm.gz through the ors-config.yml" +podman exec -it $CONTAINER_NAME /bin/bash -c "yq -y -i '.ors.engine.source_file = \"/home/ors/files/heidelberg.osm.gz\"' /home/ors/ors-config.yml" || exit 1 + +log_info "Activating all profiles through the setenv.sh" +podman exec -it $CONTAINER_NAME /bin/bash -c "echo 'export JAVA_OPTS=\"\$JAVA_OPTS \ +-Dors.engine.profiles.car.enabled=true \ +-Dors.engine.profiles.hgv.enabled=true \ +-Dors.engine.profiles.bike-regular.enabled=true \ +-Dors.engine.profiles.bike-mountain.enabled=true \ +-Dors.engine.profiles.bike-road.enabled=true \ +-Dors.engine.profiles.bike-electric.enabled=true \ +-Dors.engine.profiles.walking.enabled=true \ +-Dors.engine.profiles.hiking.enabled=true \ +-Dors.engine.profiles.wheelchair.enabled=true \ +-Dors.engine.profiles.public-transport.enabled=true \ +-Dors.engine.profiles.car.ext_storages.Borders.boundaries=/home/ors/files/borders/borders\.geojson \ +-Dors.engine.profiles.car.ext_storages.Borders.ids=/home/ors/files/borders/ids.csv \ +-Dors.engine.profiles.car.ext_storages.Borders.openborders=/home/ors/files/borders/openborders.csv \ +-Dors.engine.profiles.car.ext_storages.HereTraffic.streets=/home/ors/files/traffic_data/here/Streets.shp \ +-Dors.engine.profiles.car.ext_storages.HereTraffic.ref_pattern=/home/ors/files/traffic_data/here/ref_pattern.csv \ +-Dors.engine.profiles.car.ext_storages.HereTraffic.pattern_15min=/home/ors/files/traffic_data/here/pattern_kph_15min.csv \ +-Dors.engine.profiles.hgv.ext_storages.Borders.boundaries=/home/ors/files/borders/borders.geojson \ +-Dors.engine.profiles.hgv.ext_storages.Borders.ids=/home/ors/files/borders/ids.csv \ +-Dors.engine.profiles.hgv.ext_storages.Borders.openborders=/home/ors/files/borders/openborders.csv \ +-Dors.engine.profiles.hgv.ext_storages.HereTraffic.streets=/home/ors/files/traffic_data/here/Streets.shp \ +-Dors.engine.profiles.hgv.ext_storages.HereTraffic.ref_pattern=/home/ors/files/traffic_data/here/ref_pattern.csv \ +-Dors.engine.profiles.hgv.ext_storages.HereTraffic.pattern_15min=/home/ors/files/traffic_data/here/pattern_kph_15min.csv \ +-Dors.engine.profiles.walking.ext_storages.GreenIndex.filepath=/home/ors/files/green_streets_hd.csv \ +-Dors.engine.profiles.walking.ext_storages.NoiseIndex.filepath=/home/ors/files/noise_data_hd.csv \ +-Dors.engine.profiles.walking.ext_storages.ShadowIndex.filepath=/home/ors/files/shadow_index_hd.csv \ +-Dors.engine.profiles.walking.ext_storages.csv.filepath=/home/ors/files/csv_data_hd.csv \ +-Dors.engine.profiles.hiking.ext_storages.GreenIndex.filepath=/home/ors/files/green_streets_hd.csv \ +-Dors.engine.profiles.hiking.ext_storages.NoiseIndex.filepath=/home/ors/files/noise_data_hd.csv \ +-Dors.engine.profiles.hiking.ext_storages.ShadowIndex.filepath=/home/ors/files/shadow_index_hd.csv \ +-Dors.engine.profiles.hiking.ext_storages.csv.filepath=/home/ors/files/csv_data_hd.csv \ +-Dors.engine.profiles.public-transport.gtfs_file=/home/ors/files/vrn_gtfs_cut.zip\"' > /home/ors/setenv.sh" || exit 1 + +log_info "Cleaning the current graphs under /home/ors/graphs" +podman exec -it $CONTAINER_NAME /bin/bash -c "rm -rf /home/ors/graphs/*" || exit 1 + + +# Restart the container silently +log_info "Restarting the container to activate the hgv and bike-regular profiles" +podman restart $CONTAINER_NAME > /dev/null || exit 1 + +# Wait for the container to start +wait_for_url "127.0.0.1:${PORT}/ors/v2/health" 300 200 5 5 || exit 1 + +# Check that one profile is loaded +check_number_of_profiles_loaded "127.0.0.1:${PORT}/ors/v2/status" 10 || exit 1 + +profiles_to_be_loaded=( + "driving-car" + "driving-hgv" + "cycling-regular" + "cycling-mountain" + "cycling-road" + "cycling-electric" + "foot-walking" + "foot-hiking" + "wheelchair" + "public-transport" +) +for profile in "${profiles_to_be_loaded[@]}"; do + check_profile_loaded "127.0.0.1:${PORT}/ors/v2/status" $profile true || exit 1 +done + +# Check that each of the following folders exist +folders_to_expect=( + "/home/ors/graphs/car" + "/home/ors/graphs/hgv" + "/home/ors/graphs/bike-regular" + "/home/ors/graphs/bike-mountain" + "/home/ors/graphs/bike-road" + "/home/ors/graphs/bike-electric" + "/home/ors/graphs/walking" + "/home/ors/graphs/hiking" + "/home/ors/graphs/wheelchair" + "/home/ors/graphs/public-transport" +) +for folder in "${folders_to_expect[@]}"; do + check_folder_exists $folder true || exit 1 +done + +# Check that each of the following files exist +files_to_expect=( + "/home/ors/ors-config.yml" + "/home/ors/setenv.sh" +) +for file in "${files_to_expect[@]}"; do + check_file_exists $file true || exit 1 +done + +# Check that /opt/tomcat/10/temp/GeoTools folder doesnt exist yet +check_folder_exists "/opt/tomcat/10/temp/GeoTools" false || exit 1 + +# Check that the server responds with a 200 status code for an avoid polygon request +check_avoid_area_request "http://127.0.0.1:${PORT}/ors/v2/directions/cycling-regular/geojson" 200 || exit 1 + +# Check that /opt/tomcat/10/temp/GeoTools folder exists now +check_folder_exists "/opt/tomcat/10/temp/GeoTools" true || exit 1 \ No newline at end of file diff --git a/ors-api/src/main/java/org/heigit/ors/api/ORSEnvironmentPostProcessor.java b/ors-api/src/main/java/org/heigit/ors/api/ORSEnvironmentPostProcessor.java index 5ea9e50c88..c6f6379db7 100644 --- a/ors-api/src/main/java/org/heigit/ors/api/ORSEnvironmentPostProcessor.java +++ b/ors-api/src/main/java/org/heigit/ors/api/ORSEnvironmentPostProcessor.java @@ -36,6 +36,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp // Override values from application.yml with contents of custom config yml file. List configLocations = new ArrayList<>(); log.info(""); + log.info("Configuration lookup started."); if (!StringUtility.isNullOrEmpty(System.getProperty(ORS_CONFIG_LOCATION_PROPERTY))) { configLocations.add(System.getProperty(ORS_CONFIG_LOCATION_PROPERTY)); log.info("Configuration file set by program argument."); @@ -60,6 +61,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp break; } } catch (IllegalStateException | IOException ignored) { + log.debug("Log file '%s' not found.".formatted(path)); } } var relevantPrefixes = List.of( @@ -73,7 +75,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp "spring.", "SERVER_", "server."); - var relevantENVs = System.getenv().entrySet().stream() + var relevantENVs = environment.getSystemProperties().entrySet().stream() .filter(env -> relevantPrefixes.stream().anyMatch(env.getKey()::startsWith)) .sorted(Entry.comparingByKey()).toList(); if (!relevantENVs.isEmpty()) { @@ -81,6 +83,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp log.info("Environment variables overriding openrouteservice configuration parameters detected: "); relevantENVs.forEach(env -> log.info("%s=%s".formatted(env.getKey(), env.getValue()))); } + log.info("Configuration lookup finished."); log.info(""); } }