From babea215b7063114f5b5a415596fb646610d15b7 Mon Sep 17 00:00:00 2001 From: Jacob Fielding Date: Sun, 1 Sep 2024 18:42:17 -0700 Subject: [PATCH 1/3] Added and tested baseline default config --- config/build.gradle.kts | 6 + .../src/main/kotlin/ValhallaConfigDefault.kt | 130 ++++++++ config/src/test/kotlin/AdditionalDataTest.kt | 20 -- config/src/test/kotlin/MoshiAdapterTest.kt | 26 +- config/src/test/kotlin/ValhallaConfigTest.kt | 18 ++ config/src/test/resources/default-config.json | 281 ++++++++++++++++++ openapi-config.yaml | 130 +++++--- 7 files changed, 522 insertions(+), 89 deletions(-) create mode 100644 config/src/main/kotlin/ValhallaConfigDefault.kt delete mode 100644 config/src/test/kotlin/AdditionalDataTest.kt create mode 100644 config/src/test/kotlin/ValhallaConfigTest.kt create mode 100644 config/src/test/resources/default-config.json diff --git a/config/build.gradle.kts b/config/build.gradle.kts index 33bcaf8..14cfa9d 100644 --- a/config/build.gradle.kts +++ b/config/build.gradle.kts @@ -19,6 +19,12 @@ dependencies { implementation("com.squareup.moshi:moshi-adapters:$moshiVersion") testImplementation(kotlin("test")) + + val kotestVersion = "5.9.0" + testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion") + testImplementation("io.kotest:kotest-assertions-core:$kotestVersion") + testImplementation("io.kotest:kotest-assertions-json:$kotestVersion") +// testImplementation("io.kotest:kotest-property:$kotestVersion") } kotlin { diff --git a/config/src/main/kotlin/ValhallaConfigDefault.kt b/config/src/main/kotlin/ValhallaConfigDefault.kt new file mode 100644 index 0000000..5fdee30 --- /dev/null +++ b/config/src/main/kotlin/ValhallaConfigDefault.kt @@ -0,0 +1,130 @@ +import com.valhalla.config.models.AdditionalData +import com.valhalla.config.models.Httpd +import com.valhalla.config.models.HttpdService +import com.valhalla.config.models.Logging +import com.valhalla.config.models.Loki +import com.valhalla.config.models.LokiLogging +import com.valhalla.config.models.LokiService +import com.valhalla.config.models.LokiServiceDefaults +import com.valhalla.config.models.Meili +import com.valhalla.config.models.MeiliAuto +import com.valhalla.config.models.MeiliBicycle +import com.valhalla.config.models.MeiliDefault +import com.valhalla.config.models.MeiliGrid +import com.valhalla.config.models.MeiliMultimodal +import com.valhalla.config.models.MeiliPedestrian +import com.valhalla.config.models.MeiliService +import com.valhalla.config.models.Mjolnir +import com.valhalla.config.models.MjolnirDataProcessing +import com.valhalla.config.models.Odin +import com.valhalla.config.models.OdinMarkupFormatter +import com.valhalla.config.models.OdinService +import com.valhalla.config.models.ServiceLimits +import com.valhalla.config.models.ServiceLimitsAuto +import com.valhalla.config.models.ServiceLimitsBicycle +import com.valhalla.config.models.ServiceLimitsBus +import com.valhalla.config.models.ServiceLimitsCentroid +import com.valhalla.config.models.ServiceLimitsIsochrone +import com.valhalla.config.models.ServiceLimitsMultimodal +import com.valhalla.config.models.ServiceLimitsPedestrian +import com.valhalla.config.models.ServiceLimitsSkadi +import com.valhalla.config.models.ServiceLimitsStatus +import com.valhalla.config.models.ServiceLimitsTrace +import com.valhalla.config.models.Statsd +import com.valhalla.config.models.Thor +import com.valhalla.config.models.ThorLogging +import com.valhalla.config.models.ThorService +import com.valhalla.config.models.ValhallaConfig + +class ValhallaConfigBuilder { + + private var config = ValhallaConfigBuilder.DEFAULT + + // TODO: Add more feature rich/dynamic builder functionality + + /** + * Set the tile extract path + * + * e.g. /data/user/0/com.valhalla.valhalla.test/files/valhalla_tiles.tar + */ + fun withTileExtract(tileExtract: String): ValhallaConfigBuilder { + config = config.copy( + mjolnir = config.mjolnir?.copy( + tileExtract = tileExtract + ) + ) + return this + } + + fun withTileDir(tileDir: String): ValhallaConfigBuilder { + config = config.copy( + mjolnir = config.mjolnir?.copy( + tileDir = tileDir + ) + ) + return this + } + + fun build(): ValhallaConfig { + return config + } + + companion object { + val DEFAULT = ValhallaConfig( + additionalData = AdditionalData(), + httpd = Httpd( + HttpdService( + // TODO: We can remove this if we fix the asterisk becoming a _* from openapi-generator. + listen = "tcp://*:8002" + ) + ), + loki = Loki( + logging = LokiLogging(), + service = LokiService(), + serviceDefaults = LokiServiceDefaults(), + ), + meili = Meili( + auto = MeiliAuto(), + bicycle = MeiliBicycle(), + default = MeiliDefault(), + grid = MeiliGrid(), + logging = Logging(), + multimodal = MeiliMultimodal(), + pedestrian = MeiliPedestrian(), + service = MeiliService() + ), + mjolnir = Mjolnir( + dataProcessing = MjolnirDataProcessing(), + logging = Logging(), + ), + odin = Odin( + logging = Logging(), + markupFormatter = OdinMarkupFormatter(), + service = OdinService() + ), + serviceLimits = ServiceLimits( + auto = ServiceLimitsAuto(), + bicycle = ServiceLimitsBicycle(), + bikeshare = ServiceLimitsBicycle(), + bus = ServiceLimitsBus(), + centroid = ServiceLimitsCentroid(), + isochrone = ServiceLimitsIsochrone(), + motorScooter = ServiceLimitsBicycle(), + motorcycle = ServiceLimitsBicycle(), + multimodal = ServiceLimitsMultimodal(), + pedestrian = ServiceLimitsPedestrian(), + skadi = ServiceLimitsSkadi(), + status = ServiceLimitsStatus(), + taxi = ServiceLimitsAuto(), + trace = ServiceLimitsTrace(), + transit = ServiceLimitsBicycle(), + truck = ServiceLimitsAuto() + ), + statsd = Statsd(), + thor = Thor( + logging = ThorLogging(), + service = ThorService() + ) + ) + } +} \ No newline at end of file diff --git a/config/src/test/kotlin/AdditionalDataTest.kt b/config/src/test/kotlin/AdditionalDataTest.kt deleted file mode 100644 index 5304b99..0000000 --- a/config/src/test/kotlin/AdditionalDataTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -import com.valhalla.config.models.AdditionalData -import kotlin.test.Test -import kotlin.test.assertEquals - -class AdditionalDataTest { - - @Test - fun testDefault() { - val additionalData = AdditionalData() - assertEquals("/custom_files/elevation_data", additionalData.elevation) - } - - @Test - fun testCustom() { - val additionalData = AdditionalData( - "/folder/elevation_data" - ) - assertEquals("/folder/elevation_data", additionalData.elevation) - } -} diff --git a/config/src/test/kotlin/MoshiAdapterTest.kt b/config/src/test/kotlin/MoshiAdapterTest.kt index cff565c..52bb962 100644 --- a/config/src/test/kotlin/MoshiAdapterTest.kt +++ b/config/src/test/kotlin/MoshiAdapterTest.kt @@ -1,37 +1,17 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory -import com.valhalla.config.models.AdditionalData -import com.valhalla.config.models.Httpd -import com.valhalla.config.models.Loki -import com.valhalla.config.models.Meili -import com.valhalla.config.models.Mjolnir -import com.valhalla.config.models.Odin -import com.valhalla.config.models.ServiceLimits -import com.valhalla.config.models.Statsd -import com.valhalla.config.models.Thor +import com.valhalla.config.models.ValhallaConfig import kotlin.test.Test import kotlin.test.assertNotNull -data class AllModels( - val additionalData: AdditionalData = AdditionalData(), - val httpd: Httpd = Httpd(), - val loki: Loki = Loki(), - val meili: Meili = Meili(), - val mjolnir: Mjolnir = Mjolnir(), - val odin: Odin = Odin(), - val serviceLimits: ServiceLimits = ServiceLimits(), - val statsd: Statsd = Statsd(), - val thor: Thor = Thor() -) - class MoshiAdapterTest { private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() @Test fun testEncode() { - val all = AllModels() - val encoded = moshi.adapter(AllModels::class.java).toJson(all) + val config = ValhallaConfigBuilder.DEFAULT + val encoded = moshi.adapter(ValhallaConfig::class.java).toJson(config) assertNotNull(encoded) } } diff --git a/config/src/test/kotlin/ValhallaConfigTest.kt b/config/src/test/kotlin/ValhallaConfigTest.kt new file mode 100644 index 0000000..16a4625 --- /dev/null +++ b/config/src/test/kotlin/ValhallaConfigTest.kt @@ -0,0 +1,18 @@ +import com.squareup.moshi.Moshi +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory +import com.valhalla.config.models.ValhallaConfig +import io.kotest.assertions.json.shouldMatchJsonResource +import kotlin.test.Test + +class ValhallaConfigTest { + + private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() + + @Test + fun testDefault() { + val config = ValhallaConfigBuilder.DEFAULT + val configJson = moshi.adapter(ValhallaConfig::class.java).toJson(config) + + configJson.shouldMatchJsonResource("/default-config.json") + } +} diff --git a/config/src/test/resources/default-config.json b/config/src/test/resources/default-config.json new file mode 100644 index 0000000..a87a8d7 --- /dev/null +++ b/config/src/test/resources/default-config.json @@ -0,0 +1,281 @@ +{ + "additional_data": { + "elevation": "/custom_files/elevation_data" + }, + "httpd": { + "service": { + "drain_seconds": 28, + "interrupt": "ipc:///tmp/interrupt", + "listen": "tcp://*:8002", + "loopback": "ipc:///tmp/loopback", + "shutdown_seconds": 1 + } + }, + "loki": { + "actions": [ + "locate", + "route", + "height", + "sources_to_targets", + "optimized_route", + "isochrone", + "trace_route", + "trace_attributes", + "transit_available", + "expansion", + "centroid", + "status" + ], + "logging": { + "color": true, + "file_name": "path_to_some_file.log", + "long_request": 100, + "type": "std_out" + }, + "service": { + "proxy": "ipc:///tmp/loki" + }, + "service_defaults": { + "heading_tolerance": 60, + "minimum_reachability": 50, + "node_snap_tolerance": 5, + "radius": 0, + "search_cutoff": 35000, + "street_side_max_distance": 1000, + "street_side_tolerance": 5 + }, + "use_connectivity": true + }, + "meili": { + "auto": { + "search_radius": 50, + "turn_penalty_factor": 200 + }, + "bicycle": { + "turn_penalty_factor": 140 + }, + "customizable": [ + "mode", + "search_radius", + "turn_penalty_factor", + "gps_accuracy", + "interpolation_distance", + "sigma_z", + "beta", + "max_route_distance_factor", + "max_route_time_factor" + ], + "default": { + "beta": 3, + "breakage_distance": 2000, + "geometry": false, + "gps_accuracy": 5, + "interpolation_distance": 10, + "max_route_distance_factor": 5, + "max_route_time_factor": 5, + "max_search_radius": 100, + "route": true, + "search_radius": 50, + "sigma_z": 4.07, + "turn_penalty_factor": 0 + }, + "grid": { + "cache_size": 100240, + "size": 500 + }, + "logging": { + "color": true, + "file_name": "path_to_some_file.log", + "type": "std_out" + }, + "mode": "auto", + "multimodal": { + "turn_penalty_factor": 70 + }, + "pedestrian": { + "search_radius": 50, + "turn_penalty_factor": 100 + }, + "service": { + "proxy": "ipc:///tmp/meili" + }, + "verbose": false + }, + "mjolnir": { + "admin": "/custom_data/admins.sqlite", + "data_processing": { + "allow_alt_name": false, + "apply_country_overrides": true, + "infer_internal_intersections": true, + "infer_turn_channels": true, + "scan_tar": false, + "use_admin_db": true, + "use_direction_on_ways": false, + "use_rest_area": false, + "use_urban_tag": false + }, + "global_synchronized_cache": false, + "hierarchy": true, + "id_table_size": 1300000000, + "import_bike_share_stations": false, + "include_bicycle": true, + "include_construction": false, + "include_driveways": true, + "include_driving": true, + "include_pedestrian": true, + "logging": { + "color": true, + "file_name": "path_to_some_file.log", + "type": "std_out" + }, + "lru_mem_cache_hard_control": false, + "max_cache_size": 1000000000, + "max_concurrent_reader_users": 1, + "reclassify_links": true, + "shortcuts": true, + "tile_dir": "", + "tile_extract": "", + "timezone": "timezones.sqlite", + "traffic_extract": "", + "transit_dir": "", + "transit_feeds_dir": "", + "use_lru_mem_cache": false, + "use_simple_mem_cache": false + }, + "odin": { + "logging": { + "color": true, + "file_name": "path_to_some_file.log", + "type": "std_out" + }, + "markup_formatter": { + "markup_enabled": false, + "phoneme_format": " (phoneme>//)" + }, + "service": { + "proxy": "ipc:///tmp/odin" + } + }, + "service_limits": { + "auto": { + "max_distance": 5000000, + "max_locations": 20, + "max_matrix_distance": 400000, + "max_matrix_location_pairs": 2500 + }, + "bicycle": { + "max_distance": 500000, + "max_locations": 50, + "max_matrix_distance": 200000, + "max_matrix_location_pairs": 2500 + }, + "bikeshare": { + "max_distance": 500000, + "max_locations": 50, + "max_matrix_distance": 200000, + "max_matrix_location_pairs": 2500 + }, + "bus": { + "max_distance": 5000000, + "max_locations": 50, + "max_matrix_distance": 400000, + "max_matrix_location_pairs": 2500 + }, + "centroid": { + "max_distance": 200000, + "max_locations": 5 + }, + "isochrone": { + "max_contours": 4, + "max_distance": 25000, + "max_distance_contour": 200, + "max_locations": 1, + "max_time_contour": 120 + }, + "max_alternates": 2, + "max_exclude_locations": 50, + "max_exclude_polygons_length": 10000, + "max_radius": 200, + "max_reachability": 100, + "max_timedep_distance": 500000, + "max_timedep_distance_matrix": 0, + "motor_scooter": { + "max_distance": 500000, + "max_locations": 50, + "max_matrix_distance": 200000, + "max_matrix_location_pairs": 2500 + }, + "motorcycle": { + "max_distance": 500000, + "max_locations": 50, + "max_matrix_distance": 200000, + "max_matrix_location_pairs": 2500 + }, + "multimodal": { + "max_distance": 500000, + "max_locations": 50, + "max_matrix_distance": 0, + "max_matrix_location_pairs": 0 + }, + "pedestrian": { + "max_distance": 250000, + "max_locations": 50, + "max_matrix_distance": 200000, + "max_matrix_location_pairs": 2500, + "max_transit_walking_distance": 10000, + "min_transit_walking_distance": 1 + }, + "skadi": { + "max_shape": 750000, + "min_resample": 10 + }, + "status": { + "allow_verbose": false + }, + "taxi": { + "max_distance": 5000000, + "max_locations": 20, + "max_matrix_distance": 400000, + "max_matrix_location_pairs": 2500 + }, + "trace": { + "max_alternates": 3, + "max_alternates_shape": 100, + "max_distance": 200000, + "max_gps_accuracy": 100, + "max_search_radius": 100, + "max_shape": 16000 + }, + "transit": { + "max_distance": 500000, + "max_locations": 50, + "max_matrix_distance": 200000, + "max_matrix_location_pairs": 2500 + }, + "truck": { + "max_distance": 5000000, + "max_locations": 20, + "max_matrix_distance": 400000, + "max_matrix_location_pairs": 2500 + } + }, + "statsd": { + "port": 8125, + "prefix": "valhalla" + }, + "thor": { + "clear_reserved_memory": false, + "extended_search": false, + "logging": { + "color": true, + "file_name": "path_to_some_file.log", + "long_request": 110, + "type": "std_out" + }, + "max_reserved_labels_count": 1000000, + "service": { + "proxy": "ipc:///tmp/thor" + }, + "source_to_target_algorithm": "select_optimal" + } +} \ No newline at end of file diff --git a/openapi-config.yaml b/openapi-config.yaml index 3f9c316..40eed94 100644 --- a/openapi-config.yaml +++ b/openapi-config.yaml @@ -6,7 +6,40 @@ info: name: Valhalla url: 'https://github.com/valhalla/valhalla' components: - schemas: + schemas: + logging: + type: object + properties: + color: + type: boolean + default: true + file_name: + type: string + default: path_to_some_file.log + type: + type: string + default: std_out + valhalla_config: + type: object + properties: + additional_data: + $ref: '#/components/schemas/additional_data' + httpd: + $ref: '#/components/schemas/httpd' + loki: + $ref: '#/components/schemas/loki' + meili: + $ref: '#/components/schemas/meili' + mjolnir: + $ref: '#/components/schemas/mjolnir' + odin: + $ref: '#/components/schemas/odin' + service_limits: + $ref: '#/components/schemas/service_limits' + statsd: + $ref: '#/components/schemas/statsd' + thor: + $ref: '#/components/schemas/thor' additional_data: type: object properties: @@ -57,16 +90,17 @@ components: ] logging: type: object - properties: - color: + properties: + color: type: boolean - file_name: + default: true + file_name: type: string default: path_to_some_file.log - long_request: + long_request: type: integer default: 100 - type: + type: type: string default: std_out service: @@ -101,6 +135,7 @@ components: default: 5 use_connectivity: type: boolean + default: true meili: type: object properties: @@ -134,7 +169,7 @@ components: "max_route_distance_factor", "max_route_time_factor" ] - default: + default: type: object properties: beta: @@ -145,6 +180,7 @@ components: default: 2000 geometry: type: boolean + default: false gps_accuracy: type: integer default: 5 @@ -162,6 +198,7 @@ components: default: 100 route: type: boolean + default: true search_radius: type: integer default: 50 @@ -182,16 +219,7 @@ components: type: integer default: 500 logging: - type: object - properties: - color: - type: boolean - file_name: - type: string - default: path_to_some_file.log - type: - type: string - default: std_out + $ref: '#/components/schemas/logging' mode: type: string default: auto @@ -218,6 +246,7 @@ components: default: ipc:///tmp/meili verbose: type: boolean + default: false mjolnir: type: object properties: @@ -229,54 +258,63 @@ components: properties: allow_alt_name: type: boolean + default: false apply_country_overrides: type: boolean + default: true infer_internal_intersections: type: boolean + default: true infer_turn_channels: type: boolean + default: true scan_tar: type: boolean + default: false use_admin_db: type: boolean + default: true use_direction_on_ways: type: boolean + default: false use_rest_area: type: boolean + default: false use_urban_tag: type: boolean + default: false global_synchronized_cache: type: boolean + default: false hierarchy: type: boolean + default: true id_table_size: type: integer default: 1300000000 import_bike_share_stations: type: boolean + default: false include_bicycle: type: boolean + default: true include_construction: type: boolean + default: false include_driveways: type: boolean + default: true include_driving: type: boolean + default: true include_pedestrian: type: boolean - logging: - type: object - properties: - color: - type: boolean - file_name: - type: string - default: path_to_some_file.log - type: - type: string - default: std_out + default: true + logging: + $ref: '#/components/schemas/logging' lru_mem_cache_hard_control: type: boolean + default: false max_cache_size: type: integer default: 1000000000 @@ -285,49 +323,45 @@ components: default: 1 reclassify_links: type: boolean + default: true shortcuts: type: boolean + default: true tile_dir: type: string - format: nullable + default: "" tile_extract: type: string - default: /data/user/0/com.valhalla.valhalla.test/files/valhalla_tiles.tar - timezone: + default: "" + timezone: type: string default: timezones.sqlite traffic_extract: type: string - default: + default: "" transit_dir: type: string - default: + default: "" transit_feeds_dir: type: string - default: /data/valhalla/transit_feeds + default: "" use_lru_mem_cache: type: boolean + default: false use_simple_mem_cache: type: boolean + default: false odin: type: object - properties: - logging: - type: object - properties: - color: - type: boolean - file_name: - type: string - default: path_to_some_file.log - type: - type: string - default: std_out + properties: + logging: + $ref: '#/components/schemas/logging' markup_formatter: type: object properties: markup_enabled: type: boolean + default: false phoneme_format: type: string default: (phoneme>//) @@ -528,6 +562,7 @@ components: properties: allow_verbose: type: boolean + default: false taxi: type: object properties: @@ -608,13 +643,16 @@ components: properties: clear_reserved_memory: type: boolean + default: false extended_search: type: boolean + default: false logging: type: object properties: color: type: boolean + default: true file_name: type: string default: path_to_some_file.log From b0aa8502bf2d5a830c79811c991894ba54b11298 Mon Sep 17 00:00:00 2001 From: Jacob Fielding Date: Sun, 1 Sep 2024 18:43:59 -0700 Subject: [PATCH 2/3] Added and tested baseline default config --- config/build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/config/build.gradle.kts b/config/build.gradle.kts index 14cfa9d..c3a9e2c 100644 --- a/config/build.gradle.kts +++ b/config/build.gradle.kts @@ -24,7 +24,6 @@ dependencies { testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion") testImplementation("io.kotest:kotest-assertions-core:$kotestVersion") testImplementation("io.kotest:kotest-assertions-json:$kotestVersion") -// testImplementation("io.kotest:kotest-property:$kotestVersion") } kotlin { From d1af9f024095b9472ba56ab4c9987bedbaa64927 Mon Sep 17 00:00:00 2001 From: Jacob Fielding Date: Sun, 1 Sep 2024 18:44:24 -0700 Subject: [PATCH 3/3] Added and tested baseline default config --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 6d1be0d..82fe9dd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,7 @@ plugins { rootProject.name = "valhalla-api-kotlin" gradle.beforeProject { - extensions.extraProperties["libraryVersion"] = "0.0.4" + extensions.extraProperties["libraryVersion"] = "0.0.5" } include("client")