|
| 1 | +from ott.utils import object_utils |
| 2 | + |
| 3 | +from ott.osm.osm_cache import OsmCache |
| 4 | +from ott.osm.osm2pgsql.osm2pgsql import Osm2pgsql |
| 5 | +from ott.loader.gtfs.gtfs_cache import GtfsCache |
| 6 | +from ott.loader.otp.graph.otp_exporter import OtpExporter |
| 7 | +from ott.loader.otp.graph.otp_builder import OtpBuilder |
| 8 | +from ott.loader.gtfsdb.gtfsdb_loader import GtfsdbLoader |
| 9 | +from ott.loader.gtfsdb.gtfsdb_exporter import GtfsdbExporter |
| 10 | +from ott.loader.gtfsdb_realtime.gtfsdb_realtime_loader import GtfsdbRealtimeLoader |
| 11 | +from ott.loader.sum.sum_cache import SumCache |
| 12 | +from ott.loader.solr.solr_loader import SolrLoader |
| 13 | +from ott.loader.gtfs.fix import Fix |
| 14 | + |
| 15 | +import logging |
| 16 | +log = logging.getLogger(__file__) |
| 17 | + |
| 18 | + |
| 19 | +def download_data(): |
| 20 | + """ just download data |
| 21 | +
|
| 22 | + does the following: |
| 23 | + 1. update GTFS feeds in cache |
| 24 | + 2. update OSM data in cache |
| 25 | + 3. update SUM data in cache |
| 26 | + """ |
| 27 | + force_update = object_utils.is_force_update() |
| 28 | + if force_update: |
| 29 | + log.info("step 0 IMPORTANT: loading due to 'force_update'!") |
| 30 | + |
| 31 | + log.info("step 1: cache latest gtfs feeds") |
| 32 | + gtfs = GtfsCache() |
| 33 | + updated_feeds = gtfs.check_cached_feeds(force_update=force_update) |
| 34 | + if updated_feeds and len(updated_feeds) > 0: |
| 35 | + log.info("step 1 IMPORTANT: loading on GTFS changes in feed(s): {}!".format(updated_feeds)) |
| 36 | + force_update = True |
| 37 | + |
| 38 | + # step 1b: TODO temp gtfs_fix until OTP is fixed -- commented due to fixed OTP - April 2020 |
| 39 | + #f = Fix("TRIMET.zip") |
| 40 | + #f.remove_deadhead_stop_times(stop="8169", cull=True) |
| 41 | + |
| 42 | + log.info("step 2: cache latest osm data") |
| 43 | + updated_osm = OsmCache.update(force_update=force_update) |
| 44 | + if updated_osm: |
| 45 | + log.info("step 2 IMPORTANT: loading due to OSM changes!") |
| 46 | + force_update = True |
| 47 | + pg = Osm2pgsql() |
| 48 | + pg.run() |
| 49 | + |
| 50 | + log.info("step 3: download SUM data (BIKETOWN)") |
| 51 | + sum_update = SumCache.load |
| 52 | + |
| 53 | + return force_update |
| 54 | + |
| 55 | + |
| 56 | +def load_all(): |
| 57 | + """ will load OTP and gtfsdb |
| 58 | +
|
| 59 | + load gtfsdb |
| 60 | + pg_dump an export file for gtfsdb |
| 61 | +
|
| 62 | + build OTP graph |
| 63 | + test OTP graph |
| 64 | +
|
| 65 | + load SOLR with cached data |
| 66 | + """ |
| 67 | + force_update = object_utils.is_force_update() |
| 68 | + |
| 69 | + # steps 1 - 3: download data (see above) |
| 70 | + # import pdb; pdb.set_trace() |
| 71 | + download_data() |
| 72 | + |
| 73 | + log.info("step 4: load gtfsdb") |
| 74 | + db = GtfsdbLoader() |
| 75 | + db.check_db(force_update=force_update) |
| 76 | + |
| 77 | + log.info("step 5: load otp (build new graph)") |
| 78 | + otp = OtpBuilder(force_update=force_update) |
| 79 | + otp.build_and_test_graphs(force_update=force_update) |
| 80 | + |
| 81 | + log.info("step 6: load various data layers into SOLR") |
| 82 | + solr_load = SolrLoader.load() |
| 83 | + |
| 84 | + |
| 85 | +def export_all(): |
| 86 | + """ |
| 87 | + """ |
| 88 | + log.info("step 1: scp any gtfsdb pg_dump files created in the load_all() call ") |
| 89 | + GtfsdbExporter.scp() |
| 90 | + |
| 91 | + log.info("step 2: load any new OSM database snapshot") |
| 92 | + osm = OsmCache() |
| 93 | + #osm.deploy_db_snapshot() |
| 94 | + |
| 95 | + log.info("step 3: export otp graph") |
| 96 | + OtpExporter.export() |
| 97 | + |
| 98 | + log.info("step 4: export... SOLR updates") |
| 99 | + #solr_load = SolrLoader.load |
| 100 | + |
| 101 | + |
| 102 | +def load_and_export(): |
| 103 | + log.info("***load and build things, then export them and scp' them to production servers ***") |
| 104 | + load_all() |
| 105 | + export_all() |
| 106 | + |
| 107 | + |
| 108 | +def restore_production(): |
| 109 | + """ load (production) new database extracts and deploy new otp graphs |
| 110 | +
|
| 111 | + does the following: |
| 112 | + 1. will any postgres exports into local (production) db |
| 113 | + 2. enable new OTP graph |
| 114 | +
|
| 115 | + """ |
| 116 | + log.info("step 1: restore gtfsdb from export") |
| 117 | + GtfsdbLoader.restore() |
| 118 | + |
| 119 | + log.info("step 2: load any new OSM database snapshot") |
| 120 | + osm = OsmCache() |
| 121 | + #osm.restore_db_snapshots() |
| 122 | + |
| 123 | + log.info("step 4: export... SOLR updates") |
| 124 | + #solr_load = SolrLoader.load |
0 commit comments