Search in sources :

Example 1 with DataSource

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;
}
Also used : ArrayList(java.util.ArrayList) ConfigLoader.isConfigFile(org.opentripplanner.standalone.config.ConfigLoader.isConfigFile) File(java.io.File) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource)

Example 2 with DataSource

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));
                });
            }
        });
    }
}
Also used : DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource)

Example 3 with DataSource

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));
            }
        }
    }
}
Also used : GraphVisualizer(org.opentripplanner.visualizer.GraphVisualizer) Graph(org.opentripplanner.routing.graph.Graph) Router(org.opentripplanner.standalone.server.Router) GraphBuilder(org.opentripplanner.graph_builder.GraphBuilder) GrizzlyServer(org.opentripplanner.standalone.server.GrizzlyServer) OTPAppConstruction(org.opentripplanner.standalone.configure.OTPAppConstruction) SerializedGraphObject(org.opentripplanner.routing.graph.SerializedGraphObject) DataSource(org.opentripplanner.datastore.DataSource)

Example 4 with DataSource

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());
}
Also used : File(java.io.File) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Example 5 with DataSource

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"));
}
Also used : CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Aggregations

DataSource (org.opentripplanner.datastore.DataSource)19 CompositeDataSource (org.opentripplanner.datastore.CompositeDataSource)13 Test (org.junit.Test)11 File (java.io.File)7 ArrayList (java.util.ArrayList)3 FileDataSource (org.opentripplanner.datastore.file.FileDataSource)3 IOException (java.io.IOException)2 URI (java.net.URI)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 IOUtils (org.apache.commons.io.IOUtils)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 ConstantsForTests (org.opentripplanner.ConstantsForTests)2 GTFS (org.opentripplanner.datastore.FileType.GTFS)2 BinaryOpenStreetMapProvider (org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider)2 Blob (com.google.cloud.storage.Blob)1