Skip to content

Commit

Permalink
multi graph support
Browse files Browse the repository at this point in the history
  • Loading branch information
fpurcell committed May 19, 2016
1 parent 4e1b404 commit fdbd633
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 22 deletions.
2 changes: 1 addition & 1 deletion config/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ xfeeds: [
host : http://127.0.0.1
download : http://maven.conveyal.com.s3.amazonaws.com/org/opentripplanner/otp/0.19.0/otp-0.19.0-shaded.jar
graphs: [
{"name":"prod", "port":"55555", "dir":"cache"},
{"name":"prod", "port":"55555"},
{"name":"call", "port":"51115", "graphs":"TRIMET.zip,SWAN.zip,RIDECONNECTION.zip" }
]

Expand Down
41 changes: 20 additions & 21 deletions ott/loader/otp/graph/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ott.loader.gtfs.gtfs_cache import GtfsCache
from ott.loader.osm.osm_cache import OsmCache
from ott.loader.gtfs.info import Info
from ott.loader.otp.graph import otp_utils
from ott.loader.otp.preflight.test_runner import TestRunner

# constants
Expand All @@ -29,19 +30,16 @@
GRAPH_SIZE = 35000000
OSM_SIZE = 5000000
OSM_NAME = "or-wa"
WEB_PORT = "55555"

VLOG_NAME = "otp.v"
TEST_HTML = "otp_report.html"
OTP_DOWNLOAD_URL="http://maven.conveyal.com.s3.amazonaws.com/org/opentripplanner/otp/0.19.0/otp-0.19.0-shaded.jar"


class Build(CacheBase):
""" build an OTP graph
"""
graph_path = None
otp_path = None
feeds = None
port = WEB_PORT
graphs = None

graph_failed = GRAPH_FAILD
graph_name = GRAPH_NAME
Expand All @@ -54,11 +52,20 @@ class Build(CacheBase):

def __init__(self):
super(Build, self).__init__('otp')
self.feeds = self.config.get_json('feeds', section='gtfs')
self.port = self.config.get('port', def_val=WEB_PORT)
file_utils.cd(self.cache_dir)
self.graph_path = os.path.join(self.cache_dir, self.graph_name)
self.otp_path = self.check_otp_jar()
self.feeds = self.config.get_json('feeds', section='gtfs')
self.graphs = self.get_graphs()

def get_graphs(self):
graphs = self.config.get_json('graphs')
if graphs is None or len(graphs) == 0:
graphs = [otp_utils.get_graph_details(graphs)]
else:
for g in graphs:
dir = otp_utils.config_graph_dir(g, self.this_module_dir)
g['dir'] = dir

for g in graphs:


def build_and_test_graph(self, force_update=False, java_mem=None):
''' will rebuild the graph...
Expand Down Expand Up @@ -183,16 +190,6 @@ def report_error(self, msg):
''' override me to do things like emailing error reports, etc... '''
log.error(msg)

def check_otp_jar(self, jar="otp.jar", expected_size=50000000, download_url=OTP_DOWNLOAD_URL):
""" make sure otp.jar exists ... if not, download it
:return full-path to otp.jar
"""
jar_path = os.path.join(self.this_module_dir, jar)
exists = os.path.exists(jar_path)
if not exists or file_utils.file_size(jar_path) < expected_size:
exe_utils.wget(download_url, jar_path)
return jar_path

@classmethod
def factory(cls):
return Build()
Expand Down Expand Up @@ -226,7 +223,9 @@ def options(cls, argv):

def main(argv=sys.argv):
#import pdb; pdb.set_trace()
Build.options(argv)
#Build.options(argv)
b = Build.factory()
b.check_otp_jar()

if __name__ == '__main__':
main()
58 changes: 58 additions & 0 deletions ott/loader/otp/otp_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import logging
log = logging.getLogger(__file__)

from ott.utils import file_utils
from ott.utils import exe_utils

# constants
DEF_NAME = "prod"
DEF_PORT = "55555"
OTP_DOWNLOAD_URL="http://maven.conveyal.com.s3.amazonaws.com/org/opentripplanner/otp/0.19.0/otp-0.19.0-shaded.jar"


def config_graph_dir(graph_config, base_dir):
''' utility to make the graph dir, copy OTP config files into the graph directory, etc...
'''
name = graph_config.get('name', DEF_NAME)
dir = graph_config.get('dir', name) # optional 'dir' name overrides graph name

# step 1: mkdir (makes the dir if it doesn't exist)
graph_dir = os.path.join(base_dir, dir)
file_utils.mkdir(graph_dir)

# step 2: copy OTP config files
config_dir = os.path.join(base_dir, "config")
file_utils.copy_contents(config_dir, graph_dir, overwrite=False)

# step 3: check OTP jar exists in config dir
check_otp_jar(graph_dir)

return graph_dir

def get_graph_details(graphs, index=0):
''' utility function to find a graph config (e.g., graph folder name, web port, etc...) from self.graphs
@see [otp] section in config/app.ini
'''
ret_val = None
if graphs is None or len(graphs) < 1:
ret_val = {"name":DEF_NAME, "port":DEF_PORT}
log.warn("graphs config was NIL, using default 'prod' graph info")
else:
if index >= len(graphs):
index = 0
log.warn("graph index of {} exceeds list length, so defaulting to index 0".format(index))
ret_val = graphs[index]
return ret_val

def check_otp_jar(graph_dir, jar="otp.jar", expected_size=50000000, download_url=OTP_DOWNLOAD_URL):
""" utility to make sure otp.jar exists in the particular graph dir...
if not, download it
:return full-path to otp.jar
"""
jar_path = os.path.join(graph_dir, jar)
exists = os.path.exists(jar_path)
if not exists or file_utils.file_size(jar_path) < expected_size:
exe_utils.wget(download_url, jar_path)
return jar_path

0 comments on commit fdbd633

Please sign in to comment.