Search in sources :

Example 1 with WritableResource

use of org.openstreetmap.atlas.streaming.resource.WritableResource in project atlas-generator by osmlab.

the class ShardedAtlasRDDLoaderTest method addTextAtlasResource.

private static void addTextAtlasResource(final String path, final String name) {
    final TextAtlasBuilder builder = new TextAtlasBuilder();
    final PackedAtlas packedAtlas = builder.read(new InputStreamResource(() -> ShardedAtlasRDDLoaderTest.class.getResourceAsStream(name)));
    final WritableResource packedAtlasResource = new ByteArrayResource();
    packedAtlas.save(packedAtlasResource);
    ResourceFileSystem.addResource(path, packedAtlasResource);
}
Also used : TextAtlasBuilder(org.openstreetmap.atlas.geography.atlas.builder.text.TextAtlasBuilder) WritableResource(org.openstreetmap.atlas.streaming.resource.WritableResource) PackedAtlas(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas) ByteArrayResource(org.openstreetmap.atlas.streaming.resource.ByteArrayResource) InputStreamResource(org.openstreetmap.atlas.streaming.resource.InputStreamResource)

Example 2 with WritableResource

use of org.openstreetmap.atlas.streaming.resource.WritableResource in project atlas-generator by osmlab.

the class AtlasShardVerifier method onRun.

@Override
protected int onRun(final CommandMap command) {
    final String atlasFolder = getPathFor(command, ATLAS_FOLDER);
    final int depth = (int) command.get(LIST_DEPTH);
    final Pattern pattern = (Pattern) command.get(PATH_FILTER_REGEX);
    @SuppressWarnings("unchecked") final Set<String> countries = (Set<String>) command.get(COUNTRIES);
    logger.debug("Using regex filter \"{}\"", pattern);
    final PathFilter filter = path -> pattern.matcher(path.toString()).matches();
    final Map<String, String> sparkConfiguration = sparkOptions(command);
    final WritableResource output = FileSystemHelper.writableResource(getPathFor(command, OUTPUT), sparkConfiguration);
    final String expectedShardsPath = getPathFor(command, EXPECTED_SHARDS);
    Set<CountryShard> expectedShards;
    if (FileSystemHelper.isFile(expectedShardsPath, sparkConfiguration)) {
        logger.trace("isFile: {}", expectedShardsPath);
        expectedShards = FileSystemHelper.resource(expectedShardsPath, sparkConfiguration).linesList().stream().map(CountryShard::forName).collect(Collectors.toSet());
    } else if (FileSystemHelper.isDirectory(expectedShardsPath, sparkConfiguration)) {
        logger.trace("isDirectory: {}", expectedShardsPath);
        expectedShards = shardsFromFolder(expectedShardsPath, sparkConfiguration, depth, filter);
    } else {
        throw new CoreException("{} does not exist.", expectedShardsPath);
    }
    expectedShards = expectedShards.stream().filter(countryShard -> countries.isEmpty() || countries.contains(countryShard.getCountry())).collect(Collectors.toSet());
    final Set<CountryShard> existingShards = shardsFromFolder(atlasFolder, sparkConfiguration, depth, filter).stream().filter(countryShard -> countries.isEmpty() || countries.contains(countryShard.getCountry())).collect(Collectors.toSet());
    expectedShards.removeAll(existingShards);
    try (SafeBufferedWriter writer = output.writer()) {
        expectedShards.stream().map(CountryShard::getName).forEach(writer::writeLine);
    } catch (final Exception e) {
        throw new CoreException("Verification failed", e);
    }
    return 0;
}
Also used : Command(org.openstreetmap.atlas.utilities.runtime.Command) WritableResource(org.openstreetmap.atlas.streaming.resource.WritableResource) Logger(org.slf4j.Logger) CoreException(org.openstreetmap.atlas.exception.CoreException) FileSystemHelper(org.openstreetmap.atlas.generator.tools.filesystem.FileSystemHelper) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) PathFilter(org.apache.hadoop.fs.PathFilter) CommandMap(org.openstreetmap.atlas.utilities.runtime.CommandMap) Collectors(java.util.stream.Collectors) SafeBufferedWriter(org.openstreetmap.atlas.streaming.writers.SafeBufferedWriter) CountryShard(org.openstreetmap.atlas.geography.sharding.CountryShard) StringConverter(org.openstreetmap.atlas.utilities.conversion.StringConverter) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) Pattern(java.util.regex.Pattern) StringList(org.openstreetmap.atlas.utilities.collections.StringList) Time(org.openstreetmap.atlas.utilities.time.Time) SparkOptionsStringConverter(org.openstreetmap.atlas.generator.tools.spark.converters.SparkOptionsStringConverter) Sets(org.openstreetmap.atlas.utilities.collections.Sets) Pattern(java.util.regex.Pattern) PathFilter(org.apache.hadoop.fs.PathFilter) Set(java.util.Set) CountryShard(org.openstreetmap.atlas.geography.sharding.CountryShard) SafeBufferedWriter(org.openstreetmap.atlas.streaming.writers.SafeBufferedWriter) CoreException(org.openstreetmap.atlas.exception.CoreException) WritableResource(org.openstreetmap.atlas.streaming.resource.WritableResource) CoreException(org.openstreetmap.atlas.exception.CoreException)

Example 3 with WritableResource

use of org.openstreetmap.atlas.streaming.resource.WritableResource in project atlas-generator by osmlab.

the class SparkFileHelper method copyFile.

private void copyFile(final Resource resource, final String targetPath) {
    final WritableResource output = FileSystemHelper.writableResource(targetPath, this.sparkContext);
    resource.copyTo(output);
}
Also used : WritableResource(org.openstreetmap.atlas.streaming.resource.WritableResource)

Example 4 with WritableResource

use of org.openstreetmap.atlas.streaming.resource.WritableResource in project atlas-generator by osmlab.

the class ResourceFileSystem method create.

@Override
public FSDataOutputStream create(final Path hadoopPath, final FsPermission permission, final boolean overwrite, final int bufferSize, final short replication, final long blockSize, final Progressable progress) throws IOException {
    if (STORE.containsKey(hadoopPath.toString())) {
        delete(hadoopPath, false);
    }
    final String name = hadoopPath.toString();
    final WritableResource resource = new ByteArrayResource().withName(name);
    STORE.put(name, resource);
    return new FSDataOutputStream(resource.write(), STATISTICS_INTERNAL);
}
Also used : WritableResource(org.openstreetmap.atlas.streaming.resource.WritableResource) ByteArrayResource(org.openstreetmap.atlas.streaming.resource.ByteArrayResource) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream)

Example 5 with WritableResource

use of org.openstreetmap.atlas.streaming.resource.WritableResource in project atlas-generator by osmlab.

the class AtlasShardVerifierTest method testCountryFiltering.

@Test
public void testCountryFiltering() {
    final WritableResource atlas = new StringResource("blah");
    ResourceFileSystem.addResource(CHECK + "/ABC/ABC_10-11-12.atlas", atlas);
    ResourceFileSystem.addResource(CHECK + "/ABC/ABC_10-11-13.atlas", atlas);
    ResourceFileSystem.addResource(CHECK + "/DEF/DEF_10-11-14.atlas", atlas);
    ResourceFileSystem.addResource(CHECK + "/DEF/DEF_10-11-15.atlas", atlas);
    ResourceFileSystem.addResource(INPUT + "/ABC/ABC_10-11-12.atlas", atlas);
    ResourceFileSystem.addResource(INPUT + "/XYZ/XYZ_10-11-13.atlas", atlas);
    ResourceFileSystem.addResource(INPUT + "/DEF/DEF_10-11-14.atlas", atlas);
    new AtlasShardVerifier().runWithoutQuitting(getArguments());
    Assert.assertEquals("ABC_10-11-13", FileSystemHelper.resource(OUTPUT, ResourceFileSystem.simpleconfiguration()).all());
}
Also used : WritableResource(org.openstreetmap.atlas.streaming.resource.WritableResource) StringResource(org.openstreetmap.atlas.streaming.resource.StringResource) Test(org.junit.Test)

Aggregations

WritableResource (org.openstreetmap.atlas.streaming.resource.WritableResource)20 Test (org.junit.Test)11 StringResource (org.openstreetmap.atlas.streaming.resource.StringResource)8 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)7 Resource (org.openstreetmap.atlas.streaming.resource.Resource)7 ByteArrayResource (org.openstreetmap.atlas.streaming.resource.ByteArrayResource)6 CoreException (org.openstreetmap.atlas.exception.CoreException)5 File (org.openstreetmap.atlas.streaming.resource.File)4 InputStreamResource (org.openstreetmap.atlas.streaming.resource.InputStreamResource)4 RawAtlasGenerator (org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator)3 RawAtlasSlicer (org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer)3 CountryBoundaryMap (org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap)3 StringList (org.openstreetmap.atlas.utilities.collections.StringList)3 Time (org.openstreetmap.atlas.utilities.time.Time)3 IOException (java.io.IOException)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Pattern (java.util.regex.Pattern)2 Collectors (java.util.stream.Collectors)2 MultiPolygon (org.openstreetmap.atlas.geography.MultiPolygon)2