use of com.baremaps.blob.BlobStore in project baremaps by baremaps.
the class Diff 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("Saving diff");
Path tmpTiles = Files.createFile(Paths.get("diff.tmp"));
try (PrintWriter printWriter = new PrintWriter(Files.newBufferedWriter(tmpTiles))) {
new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, srid, zoom).call();
}
blobStore.put(this.tiles, Blob.builder().withContentLength(Files.size(tmpTiles)).withInputStream(Files.newInputStream(tmpTiles)).build());
Files.deleteIfExists(tmpTiles);
logger.info("Done");
return 0;
}
use of com.baremaps.blob.BlobStore in project baremaps by baremaps.
the class Execute method call.
@Override
public Integer call() throws Exception {
DataSource datasource = PostgresUtils.datasource(database);
BlobStore blobStore = options.blobStore();
for (URI file : files) {
logger.info("Execute {}", file);
String blob = new String(blobStore.get(file).getInputStream().readAllBytes(), StandardCharsets.UTF_8);
blob = interpolate(System.getenv(), blob);
StreamUtils.batch(Splitter.on(";").splitToStream(blob), 1).forEach(query -> {
try (Connection connection = datasource.getConnection();
Statement statement = connection.createStatement()) {
statement.execute(query);
} catch (SQLException e) {
throw new StreamException(e);
}
});
}
logger.info("Done");
return 0;
}
use of com.baremaps.blob.BlobStore in project baremaps by baremaps.
the class Import method call.
@Override
public Integer call() throws Exception {
BlobStore blobStore = options.blobStore();
DataSource datasource = PostgresUtils.datasource(database);
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);
Path directory = Files.createTempDirectory(Paths.get("."), "baremaps_");
Path nodes = Files.createDirectories(directory.resolve("nodes"));
Path referencesKeys = Files.createDirectories(directory.resolve("references_keys"));
Path referencesValues = Files.createDirectories(directory.resolve("references_values"));
LongDataMap<Coordinate> coordinates = new LongAlignedDataDenseMap<>(new LonLatDataType(), new OnDiskMemory(nodes));
LongDataMap<List<Long>> references = new LongDataSortedMap<>(new AlignedDataList<>(new PairDataType<>(new LongDataType(), new LongDataType()), new OnDiskMemory(referencesKeys)), new DataStore<>(new LongListDataType(), new OnDiskMemory(referencesValues)));
logger.info("Importing data");
new ImportService(file, blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, srid).call();
logger.info("Done");
return 0;
}
use of com.baremaps.blob.BlobStore in project baremaps by baremaps.
the class Init method call.
@Override
public Integer call() throws BlobStoreException, IOException {
BlobStore blobStore = options.blobStore();
ObjectMapper mapper = defaultObjectMapper();
if (style != null) {
MbStyle styleObject = new MbStyle();
styleObject.setName("Baremaps");
MbStyleSources sources = new MbStyleSources();
sources.setType("vector");
sources.setUrl("http://localhost:9000/tiles.json");
styleObject.setSources(Map.of("baremaps", sources));
blobStore.put(style, Blob.builder().withByteArray(mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(styleObject)).build());
logger.info("Style initialized: {}", style);
}
if (tileset != null) {
TileJSON tilesetObject = new TileJSON();
tilesetObject.setTilejson("2.2.0");
tilesetObject.setName("Baremaps");
tilesetObject.setTiles(Arrays.asList("http://localhost:9000/tiles.json"));
blobStore.put(tileset, Blob.builder().withByteArray(mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(tilesetObject)).build());
logger.info("Tileset initialized: {}", tileset);
}
return 0;
}
use of com.baremaps.blob.BlobStore in project baremaps by baremaps.
the class View method call.
@Override
public Integer call() throws Exception {
ObjectMapper objectMapper = defaultObjectMapper();
BlobStore blobStore = options.blobStore();
TileJSON tileJSON = objectMapper.readValue(blobStore.get(this.tileset).getInputStream(), TileJSON.class);
CaffeineSpec caffeineSpec = CaffeineSpec.parse(cache);
DataSource datasource = PostgresUtils.datasource(database);
List<PostgresQuery> queries = asPostgresQuery(tileJSON);
TileStore tileStore = new PostgresTileStore(datasource, queries);
TileStore tileCache = new TileCache(tileStore, caffeineSpec);
// Configure the application
ResourceConfig application = new ResourceConfig().register(CorsFilter.class).register(ViewerResources.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(tileCache).to(TileStore.class);
}
});
BlockingStreamingHttpService httpService = new HttpJerseyRouterBuilder().buildBlockingStreaming(application);
ServerContext serverContext = HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
logger.info("Listening on {}", serverContext.listenAddress());
serverContext.awaitShutdown();
return 0;
}
Aggregations