use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.
the class FileDataSourceRepository method listExistingSources.
@Override
public List<DataSource> listExistingSources(FileType type) {
// Return ALL resources of the given type, this is
// auto-detecting matching files on the local file system
List<DataSource> existingFiles = new ArrayList<>();
File[] files = baseDir.listFiles();
if (files == null) {
LOG.error("'{}' is not a readable input directory.", baseDir);
return existingFiles;
}
for (File file : files) {
if (type == resolveFileType(file)) {
if (isCompositeDataSource(file)) {
existingFiles.add(createCompositeSource(file, type));
} else {
existingFiles.add(new FileDataSource(file, type));
}
}
}
return existingFiles;
}
use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.
the class NetexBundle method loadZipFileEntries.
/* private methods */
/**
* Load all files entries in the bundle
*/
private void loadZipFileEntries() {
// Add a global(this zip file) shared NeTEX DAO
netexIndex.addFirst(new NetexImportDataIndex());
// Load global shared files
loadFilesThenMapToOtpTransitModel("shared file", hierarchy.sharedEntries());
for (GroupEntries group : hierarchy.groups()) {
LOG.info("reading group {}", group.name());
newNetexImportDataScope(() -> {
// Load shared group files
loadFilesThenMapToOtpTransitModel("shared group file", group.sharedEntries());
for (DataSource entry : group.independentEntries()) {
newNetexImportDataScope(() -> {
// Load each independent file in group
loadFilesThenMapToOtpTransitModel("group file", singletonList(entry));
});
}
});
}
}
use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.
the class OTPMain method startOTPServer.
/**
* All startup logic is in an instance method instead of the static main method so it is possible to build graphs
* from web services or scripts, not just from the command line. If options cause an OTP API server to start up,
* this method will return when the web server shuts down.
*
* @throws RuntimeException if an error occurs while loading the graph.
*/
private static void startOTPServer(CommandLineParameters params) {
LOG.info("Searching for configuration and input files in {}", params.getBaseDirectory().getAbsolutePath());
Graph graph = null;
OTPAppConstruction app = new OTPAppConstruction(params);
// Validate data sources, command line arguments and config before loading and
// processing input data to fail early
app.validateConfigAndDataSources();
/* Load graph from disk if one is not present from build. */
if (params.doLoadGraph() || params.doLoadStreetGraph()) {
DataSource inputGraph = params.doLoadGraph() ? app.store().getGraph() : app.store().getStreetGraph();
SerializedGraphObject obj = SerializedGraphObject.load(inputGraph);
graph = obj.graph;
app.config().updateConfigFromSerializedGraph(obj.buildConfig, obj.routerConfig);
}
/* Start graph builder if requested. */
if (params.doBuildStreet() || params.doBuildTransit()) {
// Abort building a graph if the file can not be saved
SerializedGraphObject.verifyTheOutputGraphIsWritableIfDataSourceExist(app.graphOutputDataSource());
GraphBuilder graphBuilder = app.createGraphBuilder(graph);
if (graphBuilder != null) {
graphBuilder.run();
// Hand off the graph to the server as the default graph
graph = graphBuilder.getGraph();
} else {
throw new IllegalStateException("An error occurred while building the graph.");
}
// Store graph and config used to build it, also store router-config for easy deployment
// with using the embedded router config.
new SerializedGraphObject(graph, app.config().buildConfig(), app.config().routerConfig()).save(app.graphOutputDataSource());
}
if (graph == null) {
LOG.error("Nothing to do, no graph loaded or build. Exiting.");
System.exit(101);
}
if (!params.doServe()) {
LOG.info("Done building graph. Exiting.");
return;
}
// Index graph for travel search
graph.index();
Router router = new Router(graph, app.config().routerConfig());
router.startup();
/* Start visualizer if requested. */
if (params.visualize) {
router.graphVisualizer = new GraphVisualizer(router);
router.graphVisualizer.run();
}
// However, currently the server runs in a blocking way and waits for shutdown, so has to run last.
if (params.doServe()) {
GrizzlyServer grizzlyServer = app.createGrizzlyServer(router);
// Loop to restart server on uncaught fatal exceptions.
while (true) {
try {
grizzlyServer.run();
return;
} catch (Throwable throwable) {
LOG.error("An uncaught error occurred inside OTP. Restarting server. Error was: {}", ThrowableUtils.detailedString(throwable));
}
}
}
}
use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.
the class ZipFileDataSourceTest method testEntryProperties.
@Test
public void testEntryProperties() {
// Given:
File target = new File(FILENAME);
CompositeDataSource subject = new ZipFileDataSource(target, GTFS);
DataSource entry = subject.entry("trips.txt");
assertEquals("trips.txt", entry.name());
assertEquals("trips.txt (" + subject.path() + ")", entry.path());
assertEquals(GTFS, entry.type());
assertTrue("Last modified: " + entry.lastModified(), entry.lastModified() > TIME);
assertTrue("Size: " + entry.size(), entry.size() > 100);
assertTrue(entry.exists());
// We do not support writing to zip entries
assertFalse(entry.isWritable());
}
use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.
the class GsIntegrationTest method testReadingZipFile.
@Test
public // @Ignore("This test is a manual test, because it require an Google Cloud Store to run.")
void testReadingZipFile() throws Exception {
CompositeDataSource ds = repo.findCompositeSource(GTFS_URI, FileType.GTFS);
DataSource stops = ds.entry("stops.txt");
String text = IOUtils.toString(stops.asInputStream(), UTF_8);
assertTrue(text, text.contains("stop"));
}
Aggregations