Skip to content

Commit

Permalink
pre-load and pre-parse JSON config files
Browse files Browse the repository at this point in the history
move a bunch of configuration from the command line to two new classes
  • Loading branch information
abyrd committed Feb 3, 2015
1 parent 7948ebf commit 7bd3142
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 156 deletions.
41 changes: 41 additions & 0 deletions docs/Configuration.md
Expand Up @@ -69,3 +69,44 @@ they become available. OTP can use both approaches.




### Vehicle Positions ### Vehicle Positions


```JSON
{
updaters: [
// GTFS-RT service alerts (polling)
{
type: "real-time-alerts",
frequencySec: 30,
url: "http://developer.trimet.org/ws/V1/FeedSpecAlerts/appID/7D841E367D34BA85B11326EB3",
defaultAgencyId: "TriMet"
},

// Bike rental updater for Citybikes (polling)
{
type: "bike-rental",
frequencySec: 300,
sourceType: "city-bikes",
url: "http://host.domain.tld"
},

// Bike parking availability
// bp.type=bike-park

// Stop Time Updates (polling GTFS-RT TripUpdates)
{
type: "stop-time-updater",
frequencySec: 60,
// this is either http or file... shouldn't it default to http or guess from the presence of a URL?
sourceType: "gtfs-http",
url: "http://developer.trimet.org/ws/V1/TripUpdate/appID/7D841E367D34BA85B11326EB3",
defaultAgencyId: "TriMet"
},

// Stop Time Updates (streaming differential GTFS-RT TripUpdates)
{
type: "websocket-gtfs-rt-updater"
}
]
}
```
4 changes: 1 addition & 3 deletions src/main/java/org/opentripplanner/api/resource/Routers.java
Expand Up @@ -274,12 +274,10 @@ public Response buildGraphOverWire (
return Response.status(Response.Status.BAD_REQUEST).entity("Could not extract zip file: " + ex.getMessage()).build(); return Response.status(Response.Status.BAD_REQUEST).entity("Could not extract zip file: " + ex.getMessage()).build();
} }



// set up the build, using default parameters // set up the build, using default parameters
// this is basically simulating calling otp -b on the command line // this is basically simulating calling otp -b on the command line
CommandLineParameters params = otpServer.params.clone(); CommandLineParameters params = otpServer.params.clone();
params.build = Lists.newArrayList(); params.build = tempDir;
params.build.add(tempDir);
params.inMemory = true; params.inMemory = true;


GraphBuilderTask graphBuilder = new OTPConfigurator(params).builderFromParameters(); GraphBuilderTask graphBuilder = new OTPConfigurator(params).builderFromParameters();
Expand Down
Expand Up @@ -48,10 +48,6 @@ public class CommandLineParameters implements Cloneable {
description = "Verbose output.") description = "Verbose output.")
public boolean verbose; public boolean verbose;


@Parameter(names = {"--htmlAnnotations" },
description = "Generates nice HTML report of Graph errors/warnings (annotations). They are stored in the same location as the graph.")
boolean htmlAnnotations = false;

@Parameter(names = {"--basePath"}, validateWith = ReadWriteDirectory.class, @Parameter(names = {"--basePath"}, validateWith = ReadWriteDirectory.class,
description = "Set the path under which graphs, caches, etc. are stored by default.") description = "Set the path under which graphs, caches, etc. are stored by default.")
public String basePath = DEFAULT_BASE_PATH; public String basePath = DEFAULT_BASE_PATH;
Expand All @@ -60,16 +56,12 @@ public class CommandLineParameters implements Cloneable {


@Parameter(names = {"--build"}, validateWith = ReadableDirectory.class, @Parameter(names = {"--build"}, validateWith = ReadableDirectory.class,
description = "Build graphs at specified paths.", variableArity = true) description = "Build graphs at specified paths.", variableArity = true)
public List<File> build; public File build;


@Parameter(names = {"--cache"}, validateWith = ReadWriteDirectory.class, @Parameter(names = {"--cache"}, validateWith = ReadWriteDirectory.class,
description = "The directory under which to cache OSM and NED tiles. Default is BASE_PATH/cache.") description = "The directory under which to cache OSM and NED tiles. Default is BASE_PATH/cache.")
public File cacheDirectory; public File cacheDirectory;


@Parameter(names = {"--elevation"},
description = "download and use elevation data for the graph")
public boolean elevation;

@Parameter(names = {"--inMemory"}, @Parameter(names = {"--inMemory"},
description = "Pass the graph to the server in-memory after building it, without saving to disk.") description = "Pass the graph to the server in-memory after building it, without saving to disk.")
public boolean inMemory; public boolean inMemory;
Expand All @@ -78,39 +70,6 @@ public class CommandLineParameters implements Cloneable {
description = "Pass the graph to the server in-memory after building it, and saving to disk.") description = "Pass the graph to the server in-memory after building it, and saving to disk.")
public boolean preFlight; public boolean preFlight;


@Parameter(names = {"--noTransit"},
description = "Skip all transit input files (GTFS).")
public boolean noTransit;

@Parameter(names = {"--useTransfersTxt"},
description = "Create direct transfer edges from transfers.txt in GTFS, instead of based on distance.")
public boolean useTransfersTxt;

@Parameter(names = {"--noParentStopLinking"},
description = "Skip linking of stops to parent stops (GTFS).")
public boolean noParentStopLinking;

@Parameter(names = {"--parentStationTransfers"},
description = "Create direct transfers between the constituent stops of each parent station.")
public boolean parentStationTransfers = false;

@Parameter(names = {"--noStreets"},
description = "Skip all street input files (OSM/PBF).")
public boolean noStreets;

@Parameter(names = {"--noEmbedConfig"},
description = "Skip embedding config in graph (Embed.properties).")
public boolean noEmbedConfig = false;

@Parameter(names = {"--skipVisibility"},
description = "Skip area visibility calculations, which are often time consuming.")
public boolean skipVisibility;

@Parameter(names = {"--matchBusRoutesToStreets"},
description = "Based on GTFS data, guess which OSM streets each bus runs on to improve stop linking.")
public boolean matchBusRoutesToStreets = false;


/* Options for the server sub-task. */ /* Options for the server sub-task. */


@Parameter(names = {"--analyst"}, @Parameter(names = {"--analyst"},
Expand All @@ -125,21 +84,12 @@ public class CommandLineParameters implements Cloneable {
description = "Server port for HTTPS.") description = "Server port for HTTPS.")
public Integer securePort; public Integer securePort;


// TODO remove this
@Parameter(names = {"--graphConfigFile"}, validateWith = ReadableFile.class,
description = "Path to graph configuration file.")
public String graphConfigFile;

@Parameter(names = {"--autoScan"}, description = "Auto-scan for graphs to register in graph directory.") @Parameter(names = {"--autoScan"}, description = "Auto-scan for graphs to register in graph directory.")
public boolean autoScan = false; public boolean autoScan = false;


@Parameter(names = {"--autoReload"}, description = "Auto-reload registered graphs when source data is modified.") @Parameter(names = {"--autoReload"}, description = "Auto-reload registered graphs when source data is modified.")
public boolean autoReload = false; public boolean autoReload = false;


@Parameter(names = {"--longDistance"},
description = "Use an algorithm tailored for big graphs (the size of New York or the Netherlands).")
public boolean longDistance = false;

@Parameter(names = {"--port"}, validateWith = AvailablePort.class, @Parameter(names = {"--port"}, validateWith = AvailablePort.class,
description = "Server port for plain HTTP.") description = "Server port for plain HTTP.")
public Integer port; public Integer port;
Expand Down Expand Up @@ -205,11 +155,6 @@ public CommandLineParameters clone() {
return null; return null;
} }


if (this.build != null) {
ret.build = Lists.newArrayList();
ret.build.addAll(this.build);
}

if (this.routerIds != null) { if (this.routerIds != null) {
ret.routerIds = Lists.newArrayList(); ret.routerIds = Lists.newArrayList();
ret.routerIds.addAll(this.routerIds); ret.routerIds.addAll(this.routerIds);
Expand Down
@@ -0,0 +1,89 @@
package org.opentripplanner.standalone;

import com.fasterxml.jackson.databind.JsonNode;

/**
* These are parameters that when changed, necessitate a Graph rebuild.
* They are distinct from the RouterParameters which can be applied to a pre-built graph or on the fly at runtime.
* Eventually both classes may be initialized from the same config file so make sure there is no overlap
* in the JSON keys used.
*
* These used to be command line parameters, but there were getting to be too many of them and besides, we want to
* allow different graph builder configuration for each Graph.
* <p>
* TODO maybe have only one giant config file and just annotate the parameters to indicate which ones trigger a rebuild
* ...or just feed the same JSON tree to two different classes, one of which is the build configuration and the other is the router configuration.
*/
public class GraphBuilderParameters {

/**
* Generates nice HTML report of Graph errors/warnings (annotations). They are stored in the same location as the graph.
*/
public final boolean htmlAnnotations;

/**
* Include all transit input files (GTFS) from scanned directory.
*/
public final boolean transit;

/**
* Create direct transfer edges from transfers.txt in GTFS, instead of based on distance.
*/
public final boolean useTransfersTxt;

/**
* Link GTFS stops to their parent stops.
*/
public final boolean parentStopLinking;

/**
* Create direct transfers between the constituent stops of each parent station.
*/
public final boolean parentStationTransfers;

/**
* Include street input files (OSM/PBF).
*/
public final boolean streets;

/**
* Embed the Router config in the graph, which allows it to be sent to a server fully configured over the wire.
*/
public final boolean embedRouterConfig;

/**
* Perform visibility calculations on OSM areas (these calculations can be time consuming).
*/
public final boolean areaVisibility;

/**
* Based on GTFS shape data, guess which OSM streets each bus runs on to improve stop linking.
*/
public final boolean matchBusRoutesToStreets;

/**
* Download and use elevation data for the graph.
*/
public final boolean elevation;


/**
* Set all parameters from the given Jackson JSON tree, applying defaults.
* Supplying MissingNode.getInstance() will cause all the defaults to be applied.
*/
public GraphBuilderParameters(JsonNode config) {

htmlAnnotations = config.path("htmlAnnotations").asBoolean(false);
transit = config.path("transit").asBoolean(true);
useTransfersTxt = config.path("useTransfersTxt").asBoolean(false);
parentStopLinking = config.path("parentStopLinking").asBoolean(false);
parentStationTransfers = config.path("parentStationTransfers").asBoolean(false);
streets = config.path("streets").asBoolean(true);
embedRouterConfig = config.path("embedRouterConfig").asBoolean(true);
areaVisibility = config.path("areaVisibility").asBoolean(false);
matchBusRoutesToStreets = config.path("matchBusRoutesToStreets").asBoolean(true);
elevation = config.path("elevation").asBoolean(false);

}

}

0 comments on commit 7bd3142

Please sign in to comment.