From 621d21ec56574a7325a88a1567390374f414ffcd Mon Sep 17 00:00:00 2001 From: theiled00 <theiled00@zedat.fu-berlin.de> Date: Tue, 28 Mar 2023 09:34:56 +0000 Subject: [PATCH] Integrate with metric builder --- mapbuilder/Dockerfile | 5 ++- mapbuilder/pom.xml | 7 +--- mapbuilder/src/main/java/map/builder/App.java | 28 +++++++------- .../main/java/map/builder/osm/OSMFetcher.java | 12 +++++- .../main/java/map/builder/osm/OSMParser.java | 4 +- .../java/map/builder/utilities/Config.java | 37 +++++++++++++++++++ .../src/main/resources/config.properties | 2 + 7 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 mapbuilder/src/main/java/map/builder/utilities/Config.java create mode 100644 mapbuilder/src/main/resources/config.properties diff --git a/mapbuilder/Dockerfile b/mapbuilder/Dockerfile index 7e5c62c..c425e1f 100644 --- a/mapbuilder/Dockerfile +++ b/mapbuilder/Dockerfile @@ -1,10 +1,11 @@ -FROM eclipse-temurin:17-jdk-alpine +FROM eclipse-temurin:19-jdk-alpine ADD target/*-jar-with-dependencies.jar app.jar +COPY src/main/resources/config.properties /data/configuration/config.properties # Add the cron job # Calculate the map each day at 00:00 # For testing: set it to * * * * * to run it each minute -RUN echo "0 0 * * * java -jar /app.jar" >> /var/spool/cron/crontabs/root +RUN echo "0 0 * * * java -jar -Xmx10g /app.jar" >> /var/spool/cron/crontabs/root # Start the cron deamon CMD crond -f \ No newline at end of file diff --git a/mapbuilder/pom.xml b/mapbuilder/pom.xml index 009f9a8..6217efb 100644 --- a/mapbuilder/pom.xml +++ b/mapbuilder/pom.xml @@ -24,11 +24,6 @@ <version>4.11</version> <scope>test</scope> </dependency> - <dependency> - <groupId>com.google.protobuf</groupId> - <artifactId>protobuf-java</artifactId> - <version>3.21.12</version> - </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> @@ -42,7 +37,7 @@ <dependency> <groupId>de.fuberlin.navigator</groupId> <artifactId>proto</artifactId> - <version>1.00.003</version> + <version>1.00.05</version> </dependency> </dependencies> diff --git a/mapbuilder/src/main/java/map/builder/App.java b/mapbuilder/src/main/java/map/builder/App.java index 8a12e73..3aaccbd 100644 --- a/mapbuilder/src/main/java/map/builder/App.java +++ b/mapbuilder/src/main/java/map/builder/App.java @@ -2,6 +2,7 @@ package map.builder; import java.io.IOException; +import map.builder.utilities.Config; import org.json.JSONArray; import de.fuberlin.navigator.protos.map_builder.RoadNetwork; @@ -10,8 +11,13 @@ import map.builder.osm.OSMParser; import map.builder.utilities.BoundingBox; import map.builder.utilities.FileHandler; +import static map.builder.utilities.Config.ROAD_NETWORK_OUTPUT_PATH; + public class App { public static void main(String[] args) throws IOException { + System.out.println("Map builder started!"); + Config.load(); + RoadNetwork.Builder roadNetworkBuilder = RoadNetwork.newBuilder(); OSMParser parser = new OSMParser(roadNetworkBuilder); @@ -23,19 +29,11 @@ public class App { float maxLon = 14.330334220133722f; */ - // smaller BBox inside Cottbus, better for the debug tool - float minLat = 51.764092326645475f; - float minLon = 14.310615062713623f; - float maxLat = 51.766591637718435f; - float maxLon = 14.314413070678711f; - - // BBox around Cottbus - /* - float minLat = 51.714692361306376f; - float minLon = 14.26197052001953f; - float maxLat = 51.79290380494767f; - float maxLon = 14.415779113769531f; - */ + // BBox around central and south Brandenburg + float minLat = 51.968768f; + float minLon = 12.144459f; + float maxLat = 52.674160f; + float maxLon = 15.016778f; BoundingBox bbox = new BoundingBox(minLat, minLon, maxLat, maxLon); @@ -43,13 +41,15 @@ public class App { JSONArray roads = OSMFetcher.fetchNodesAndWays(bbox); OSMFetcher.dumpJsonData(roads, "test_data.json"); + System.out.println("Starting to parse."); parser.parseTurnRestrictions(restrictions); parser.parseRoads(roads); + System.out.println("Parsed road network."); RoadNetwork roadNetwork = roadNetworkBuilder.build(); System.out.println("Turn restrictions count: " + roadNetwork.getTurnRestrictionsCount()); System.out.println("Nodes count: " + roadNetwork.getNodesCount()); System.out.println("Segments count: " + roadNetwork.getSegmentsCount()); - FileHandler.saveToFile(roadNetwork, "./roadnetwork_sample.proto"); + FileHandler.saveToFile(roadNetwork, ROAD_NETWORK_OUTPUT_PATH); } } diff --git a/mapbuilder/src/main/java/map/builder/osm/OSMFetcher.java b/mapbuilder/src/main/java/map/builder/osm/OSMFetcher.java index 8634ebb..bc77269 100644 --- a/mapbuilder/src/main/java/map/builder/osm/OSMFetcher.java +++ b/mapbuilder/src/main/java/map/builder/osm/OSMFetcher.java @@ -24,11 +24,19 @@ public class OSMFetcher { } public static JSONArray fetchTurnRestrictions(BoundingBox boundingBox) throws IOException { - return OSMFetcher.runQueryForBBox(OSMFetcher.relationQuery, boundingBox); + System.out.println("Start to fetch turn restrictions."); + JSONArray jsonArray = OSMFetcher.runQueryForBBox(OSMFetcher.relationQuery, boundingBox); + System.out.println("Turn restrictions fetched."); + + return jsonArray; } public static JSONArray fetchNodesAndWays(BoundingBox boundingBox) throws IOException { - return OSMFetcher.runQueryForBBox(OSMFetcher.nodeQuery, boundingBox); + System.out.println("Start to fetch nodes and ways."); + JSONArray jsonArray = OSMFetcher.runQueryForBBox(OSMFetcher.nodeQuery, boundingBox); + System.out.println("Nodes and ways fetched."); + + return jsonArray; } private static JSONArray runQueryForBBox(String query, BoundingBox bbox) throws IOException { diff --git a/mapbuilder/src/main/java/map/builder/osm/OSMParser.java b/mapbuilder/src/main/java/map/builder/osm/OSMParser.java index bf8b782..09a1235 100644 --- a/mapbuilder/src/main/java/map/builder/osm/OSMParser.java +++ b/mapbuilder/src/main/java/map/builder/osm/OSMParser.java @@ -85,10 +85,12 @@ public class OSMParser { boolean oneWay = this.isOneWay(element); int maxSpeed = SegmentUtils.getMaxSpeed(element); + /* System.out.printf("Max speed: %d \n", maxSpeed); System.out.printf("Way id: %d, Start node id : %d, End node id: %d \n", osmId, startNodeId, endNodeId); + */ - long internalId = this.roadNetworkBuilder.getSegmentsCount(); + int internalId = this.roadNetworkBuilder.getSegmentsCount(); Segment segment = Segment.newBuilder() .setOsmId(osmId) diff --git a/mapbuilder/src/main/java/map/builder/utilities/Config.java b/mapbuilder/src/main/java/map/builder/utilities/Config.java new file mode 100644 index 0000000..a8bfe43 --- /dev/null +++ b/mapbuilder/src/main/java/map/builder/utilities/Config.java @@ -0,0 +1,37 @@ +package map.builder.utilities; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; + +public class Config { + + private Config() { + } + + private static Properties props = new Properties(); + + public static String ROAD_NETWORK_OUTPUT_PATH = "roadnetwork.proto"; + + public static void load() { + //The config is used for running the application in a Docker container + String configFilePath = "/data/configuration/config.properties"; + + try (FileInputStream is = new FileInputStream(configFilePath)){ + props.load(is); + + ROAD_NETWORK_OUTPUT_PATH = props.getProperty("ROAD_NETWORK_OUTPUT_PATH", ROAD_NETWORK_OUTPUT_PATH); + System.out.println("Config loaded."); + } catch (FileNotFoundException e) { + // Either way the Docker image was build wrong or this is not + // run in a Docker environment + System.out.println("No config file found. Using default settings!"); + } catch (IOException e) { + // Something else went wrong, but we will + // not let this escalate + e.printStackTrace(); + } + + } +} diff --git a/mapbuilder/src/main/resources/config.properties b/mapbuilder/src/main/resources/config.properties new file mode 100644 index 0000000..639d82d --- /dev/null +++ b/mapbuilder/src/main/resources/config.properties @@ -0,0 +1,2 @@ +# Standard config for Docker +ROAD_NETWORK_OUTPUT_PATH = /data/road_network/roadnetwork.proto \ No newline at end of file -- GitLab