Search in sources :

Example 6 with BlobStore

use of com.baremaps.blob.BlobStore in project baremaps by baremaps.

the class S3BlobStoreTest method readWriteDelete.

@Test
@Tag("integration")
void readWriteDelete() throws IOException, BlobStoreException {
    URI uri = URI.create("s3://test/test/test.txt");
    String content = "content";
    BlobStore blobStore = new S3BlobStore(s3Client);
    // Write data
    blobStore.put(uri, Blob.builder().withByteArray(content.getBytes(Charsets.UTF_8)).build());
    // Read the data
    try (InputStream inputStream = blobStore.get(uri).getInputStream()) {
        assertEquals(content, CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8)));
    }
    // Delete the data
    blobStore.delete(uri);
    // Get unexisting blob
    try (InputStream ignored = blobStore.get(uri).getInputStream()) {
        fail("Expected an IOException to be thrown");
    } catch (BlobStoreException e) {
    // Test exception message...
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) URI(java.net.URI) BlobStore(com.baremaps.blob.BlobStore) BlobStoreException(com.baremaps.blob.BlobStoreException) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 7 with BlobStore

use of com.baremaps.blob.BlobStore in project baremaps by baremaps.

the class Edit method call.

@Override
public Integer call() throws Exception {
    BlobStore blobStore = options.blobStore();
    DataSource dataSource = PostgresUtils.datasource(database);
    // Configure serialization
    ObjectMapper objectMapper = defaultObjectMapper();
    // Configure the application
    ResourceConfig application = new ResourceConfig().register(CorsFilter.class).register(EditorResources.class).register(contextResolverFor(objectMapper)).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(tileset).to(URI.class).named("tileset");
            bind(style).to(URI.class).named("style");
            bind(blobStore).to(BlobStore.class);
            bind(dataSource).to(DataSource.class);
            bind(objectMapper).to(ObjectMapper.class);
        }
    });
    BlockingStreamingHttpService httpService = new HttpJerseyRouterBuilder().buildBlockingStreaming(application);
    ServerContext serverContext = HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
    logger.info("Listening on {}", serverContext.listenAddress());
    serverContext.awaitShutdown();
    return 0;
}
Also used : CorsFilter(com.baremaps.server.common.CorsFilter) BlockingStreamingHttpService(io.servicetalk.http.api.BlockingStreamingHttpService) ServerContext(io.servicetalk.transport.api.ServerContext) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) BlobStore(com.baremaps.blob.BlobStore) DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataSource(javax.sql.DataSource) HttpJerseyRouterBuilder(io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder)

Example 8 with BlobStore

use of com.baremaps.blob.BlobStore in project baremaps by baremaps.

the class Export method call.

@Override
public Integer call() throws TileStoreException, BlobStoreException, IOException {
    ObjectMapper mapper = defaultObjectMapper();
    DataSource datasource = PostgresUtils.datasource(database);
    BlobStore blobStore = options.blobStore();
    TileJSON source = mapper.readValue(blobStore.get(this.tileset).getInputStream(), TileJSON.class);
    TileStore tileSource = sourceTileStore(source, datasource);
    TileStore tileTarget = targetTileStore(source, blobStore);
    Stream<Tile> stream;
    if (tiles == null) {
        Envelope envelope = new Envelope(source.getBounds().get(0), source.getBounds().get(2), source.getBounds().get(1), source.getBounds().get(3));
        long count = Tile.count(envelope, source.getMinzoom(), source.getMaxzoom());
        stream = StreamUtils.stream(Tile.iterator(envelope, source.getMinzoom(), source.getMaxzoom())).peek(new StreamProgress<>(count, 5000));
    } else {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(blobStore.get(tiles).getInputStream()))) {
            stream = reader.lines().flatMap(line -> {
                String[] array = line.split(",");
                int x = Integer.parseInt(array[0]);
                int y = Integer.parseInt(array[1]);
                int z = Integer.parseInt(array[2]);
                Tile tile = new Tile(x, y, z);
                return StreamUtils.stream(Tile.iterator(tile.envelope(), source.getMinzoom(), source.getMaxzoom()));
            });
        }
    }
    logger.info("Exporting tiles");
    StreamUtils.batch(stream, 10).filter(new TileBatchPredicate(batchArraySize, batchArrayIndex)).forEach(new TileChannel(tileSource, tileTarget));
    logger.info("Done");
    return 0;
}
Also used : DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) MBTiles(com.baremaps.tile.mbtiles.MBTiles) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Conversions.asPostgresQuery(com.baremaps.server.ogcapi.Conversions.asPostgresQuery) TileBatchPredicate(com.baremaps.tile.TileBatchPredicate) BigDecimal(java.math.BigDecimal) TileChannel(com.baremaps.tile.TileChannel) Map(java.util.Map) DataSource(javax.sql.DataSource) TileStore(com.baremaps.tile.TileStore) URI(java.net.URI) Command(picocli.CommandLine.Command) SQLiteDataSource(org.sqlite.SQLiteDataSource) PostgresUtils(com.baremaps.postgres.jdbc.PostgresUtils) BlobStoreException(com.baremaps.blob.BlobStoreException) Query(com.baremaps.model.Query) PostgresQuery(com.baremaps.tile.postgres.PostgresQuery) Logger(org.slf4j.Logger) TileJSON(com.baremaps.model.TileJSON) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) Mixin(picocli.CommandLine.Mixin) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) TileBlobStore(com.baremaps.tile.TileBlobStore) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) TileStoreException(com.baremaps.tile.TileStoreException) List(java.util.List) Option(picocli.CommandLine.Option) Stream(java.util.stream.Stream) Tile(com.baremaps.tile.Tile) StreamUtils(com.baremaps.stream.StreamUtils) BlobStore(com.baremaps.blob.BlobStore) StreamProgress(com.baremaps.osm.progress.StreamProgress) BufferedReader(java.io.BufferedReader) Envelope(org.locationtech.jts.geom.Envelope) TileStore(com.baremaps.tile.TileStore) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) InputStreamReader(java.io.InputStreamReader) Tile(com.baremaps.tile.Tile) Envelope(org.locationtech.jts.geom.Envelope) StreamProgress(com.baremaps.osm.progress.StreamProgress) DataSource(javax.sql.DataSource) SQLiteDataSource(org.sqlite.SQLiteDataSource) TileChannel(com.baremaps.tile.TileChannel) TileJSON(com.baremaps.model.TileJSON) BufferedReader(java.io.BufferedReader) TileBatchPredicate(com.baremaps.tile.TileBatchPredicate) DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TileBlobStore(com.baremaps.tile.TileBlobStore) BlobStore(com.baremaps.blob.BlobStore)

Example 9 with BlobStore

use of com.baremaps.blob.BlobStore in project baremaps by baremaps.

the class Update method call.

@Override
public Integer call() throws Exception {
    BlobStore blobStore = options.blobStore();
    DataSource datasource = PostgresUtils.datasource(database);
    LongDataMap<Coordinate> coordinates = new PostgresCoordinateMap(datasource);
    LongDataMap<List<Long>> references = new PostgresReferenceMap(datasource);
    HeaderRepository headerRepository = new PostgresHeaderRepository(datasource);
    Repository<Long, Node> nodeRepository = new PostgresNodeRepository(datasource);
    Repository<Long, Way> wayRepository = new PostgresWayRepository(datasource);
    Repository<Long, Relation> relationRepository = new PostgresRelationRepository(datasource);
    logger.info("Importing changes");
    new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, srid).call();
    logger.info("Done");
    return 0;
}
Also used : PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository) HeaderRepository(com.baremaps.osm.repository.HeaderRepository) PostgresWayRepository(com.baremaps.osm.postgres.PostgresWayRepository) PostgresReferenceMap(com.baremaps.osm.postgres.PostgresReferenceMap) Node(com.baremaps.osm.domain.Node) PostgresCoordinateMap(com.baremaps.osm.postgres.PostgresCoordinateMap) Way(com.baremaps.osm.domain.Way) DataSource(javax.sql.DataSource) Relation(com.baremaps.osm.domain.Relation) UpdateService(com.baremaps.osm.repository.UpdateService) Coordinate(org.locationtech.jts.geom.Coordinate) PostgresNodeRepository(com.baremaps.osm.postgres.PostgresNodeRepository) List(java.util.List) PostgresRelationRepository(com.baremaps.osm.postgres.PostgresRelationRepository) BlobStore(com.baremaps.blob.BlobStore) PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository)

Aggregations

BlobStore (com.baremaps.blob.BlobStore)9 DataSource (javax.sql.DataSource)7 DefaultObjectMapper.defaultObjectMapper (com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 List (java.util.List)4 TileJSON (com.baremaps.model.TileJSON)3 Node (com.baremaps.osm.domain.Node)3 Relation (com.baremaps.osm.domain.Relation)3 Way (com.baremaps.osm.domain.Way)3 PostgresHeaderRepository (com.baremaps.osm.postgres.PostgresHeaderRepository)3 PostgresNodeRepository (com.baremaps.osm.postgres.PostgresNodeRepository)3 PostgresRelationRepository (com.baremaps.osm.postgres.PostgresRelationRepository)3 PostgresWayRepository (com.baremaps.osm.postgres.PostgresWayRepository)3 HeaderRepository (com.baremaps.osm.repository.HeaderRepository)3 BlobStoreException (com.baremaps.blob.BlobStoreException)2 PostgresCoordinateMap (com.baremaps.osm.postgres.PostgresCoordinateMap)2 PostgresReferenceMap (com.baremaps.osm.postgres.PostgresReferenceMap)2 CorsFilter (com.baremaps.server.common.CorsFilter)2 Conversions.asPostgresQuery (com.baremaps.server.ogcapi.Conversions.asPostgresQuery)2 TileStore (com.baremaps.tile.TileStore)2