Class SparkFileHelper
- java.lang.Object
-
- org.openstreetmap.atlas.generator.tools.spark.utilities.SparkFileHelper
-
- All Implemented Interfaces:
java.io.Serializable
public class SparkFileHelper extends java.lang.Object implements java.io.SerializableHelper class for listing and validating the presence ofAtlasfiles- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDIRECTORY_SEPARATORstatic java.lang.StringEMPTY_STRINGstatic java.lang.StringEXTENSION_SEPARATORstatic java.lang.StringTEMPORARY_FOLDER_NAME
-
Constructor Summary
Constructors Constructor Description SparkFileHelper(java.util.Map<java.lang.String,java.lang.String> sparkContext)Constructs a helper with given context
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<org.openstreetmap.atlas.streaming.resource.Resource>collectAtlasFiles(java.lang.String directory, java.lang.String country, boolean recursive)Returns a list of AtlasResources for the given country in the supplied directoryjava.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>collectSourceFile(java.lang.String uri, org.apache.hadoop.fs.PathFilter... filters)Returns an AtlasResourcefor the given location URI string.java.util.List<org.openstreetmap.atlas.streaming.resource.Resource>collectSourceFiles(java.lang.String directory, boolean recursive, org.apache.hadoop.fs.PathFilter... filters)Returns an list of AtlasResources from the given location URI string.static java.lang.Stringcombine(java.lang.String basePath, java.lang.String... paths)Combines given pathsvoidcommit(SparkFilePath path)Renames theSparkFilePathtemporaryPath to theSparkFilePathtargetPath, taking care to avoid producing nested directories.voidcommitByCopy(SparkFilePath path)Copies theSparkFilePathtemporaryPath to theSparkFilePathtargetPath, taking care to avoid producing nested directories.voiddeleteDirectory(java.lang.String path)Deletes given directory and all it's child itemsbooleandirectoryContainsExpectedCountryAtlases(java.lang.String directory, org.openstreetmap.atlas.utilities.collections.StringList expectedCountries, boolean recursive)Verifies that the input directory containingAtlasfiles contains all the expected countriesbooleanexists(java.lang.String path)static java.lang.StringextensionStartingWithSeparator(java.lang.String path)RemovesEXTENSION_SEPARATORfrom the beginning of given pathbooleanisDirectory(java.lang.String path)java.util.List<org.openstreetmap.atlas.streaming.resource.Resource>list(java.lang.String path)voidmkdir(java.lang.String path)Creates a directory via given pathstatic java.lang.StringparentPath(java.lang.String path)Returns parent of given pathstatic java.lang.StringpathNotEndingWithSeparator(java.lang.String path)RemovesPATH_SEPARATORfrom the end of given pathstatic java.lang.StringpathNotStartingOrEndingWithSeparator(java.lang.String path)static java.lang.StringpathNotStartingWithSeparator(java.lang.String path)RemovesPATH_SEPARATORfrom the beginning of given path.voidrename(java.lang.String sourcePath, java.lang.String destinationPath)Renames a source path to destination pathvoidsave(java.util.List<SparkFileOutput> outputs)ExecutesSparkFileOutput#getSaveFunc()for givenSparkFileOutputsvoidsave(SparkFileOutput... outputs)ExecutesSparkFileOutput#getSaveFunc()for givenSparkFileOutputsvoidwrite(java.lang.String directory, java.lang.String filename, byte[] content)Writes given content into given directory with given filenamevoidwrite(java.lang.String directory, java.lang.String filename, java.lang.String content)Writes given content into given directory with given filename
-
-
-
Field Detail
-
TEMPORARY_FOLDER_NAME
public static final java.lang.String TEMPORARY_FOLDER_NAME
- See Also:
- Constant Field Values
-
EMPTY_STRING
public static final java.lang.String EMPTY_STRING
- See Also:
- Constant Field Values
-
DIRECTORY_SEPARATOR
public static final java.lang.String DIRECTORY_SEPARATOR
- See Also:
- Constant Field Values
-
EXTENSION_SEPARATOR
public static final java.lang.String EXTENSION_SEPARATOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
combine
public static java.lang.String combine(java.lang.String basePath, java.lang.String... paths)Combines given paths- Parameters:
basePath- a base pathpaths- a list of paths- Returns:
- the combined path
-
extensionStartingWithSeparator
public static java.lang.String extensionStartingWithSeparator(java.lang.String path)
RemovesEXTENSION_SEPARATORfrom the beginning of given path- Parameters:
path- Path to removeEXTENSION_SEPARATORfrom the beginning- Returns:
- a path not starting with
EXTENSION_SEPARATOR
-
parentPath
public static java.lang.String parentPath(java.lang.String path)
Returns parent of given path- Parameters:
path- a path- Returns:
- the parent path
-
pathNotEndingWithSeparator
public static java.lang.String pathNotEndingWithSeparator(java.lang.String path)
RemovesPATH_SEPARATORfrom the end of given path- Parameters:
path- a path- Returns:
- a path not ending with
PATH_SEPARATOR
-
pathNotStartingOrEndingWithSeparator
public static java.lang.String pathNotStartingOrEndingWithSeparator(java.lang.String path)
-
pathNotStartingWithSeparator
public static java.lang.String pathNotStartingWithSeparator(java.lang.String path)
RemovesPATH_SEPARATORfrom the beginning of given path.- Parameters:
path- a path- Returns:
- a path not beginning with
PATH_SEPARATOR
-
collectAtlasFiles
public java.util.List<org.openstreetmap.atlas.streaming.resource.Resource> collectAtlasFiles(java.lang.String directory, java.lang.String country, boolean recursive)Returns a list of AtlasResources for the given country in the supplied directory- Parameters:
directory- the directory from which to collect theAtlasfilescountry- the country, whoseAtlasfiles we're interested inrecursive-trueto search the given directory and all sub-directories,falseto only search the root directory- Returns:
- a list of Atlas
Resources for the given country
-
collectSourceFile
public java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource> collectSourceFile(java.lang.String uri, org.apache.hadoop.fs.PathFilter... filters)Returns an AtlasResourcefor the given location URI string. The resource is resolve and returned if the URI points to single resource, not a resource directory, that conforms to a path defined by one of the providedPathFilters. ThePathFilters provide a way to find well known data types that can be used either directly as or transformed to an Atlas. With no filters, the file is collected.- Parameters:
uri- the location of the Atlas datasourcefilters-PathFilters used to find datasource types- Returns:
- an
AtlasResource
-
collectSourceFiles
public java.util.List<org.openstreetmap.atlas.streaming.resource.Resource> collectSourceFiles(java.lang.String directory, boolean recursive, org.apache.hadoop.fs.PathFilter... filters)Returns an list of AtlasResources from the given location URI string. Resources are resolve and returned that conform to any one of thePathFilters. ThePathFilters provide a way to find well known data types that can be used either directly as or transformed to an Atlas.- Parameters:
directory- a location of the Atlas datasourcerecursive-true, to search the given directory and all sub-directories.false, to only search the root directoryfilters-PathFilters used to find datasource types- Returns:
- an Atlas
Resource
-
commit
public void commit(SparkFilePath path)
Renames theSparkFilePathtemporaryPath to theSparkFilePathtargetPath, taking care to avoid producing nested directories.- Parameters:
path-SparkFilePathto commit
-
commitByCopy
public void commitByCopy(SparkFilePath path)
Copies theSparkFilePathtemporaryPath to theSparkFilePathtargetPath, taking care to avoid producing nested directories.- Parameters:
path-SparkFilePathto commit
-
deleteDirectory
public void deleteDirectory(java.lang.String path)
Deletes given directory and all it's child items- Parameters:
path- a path
-
directoryContainsExpectedCountryAtlases
public boolean directoryContainsExpectedCountryAtlases(java.lang.String directory, org.openstreetmap.atlas.utilities.collections.StringList expectedCountries, boolean recursive)Verifies that the input directory containingAtlasfiles contains all the expected countries- Parameters:
directory- the directory which contains theAtlasfilesexpectedCountries- the expectedStringListof country ISO3 codesrecursive-trueto search the given directory and all sub-directories,falseto only search the root directory- Returns:
trueif all expected country ISO3 codes are in the given directory,falseotherwise
-
exists
public boolean exists(java.lang.String path)
- Parameters:
path- Path to check if it exists or not- Returns:
- true if given path exists, otherwise false
-
isDirectory
public boolean isDirectory(java.lang.String path)
- Parameters:
path- Path to check if it is a directory or not- Returns:
- true if given path is directory, otherwise false.
-
list
public java.util.List<org.openstreetmap.atlas.streaming.resource.Resource> list(java.lang.String path)
- Parameters:
path- Path to directory to listResources under.- Returns:
- List of
Resources under given path.
-
mkdir
public void mkdir(java.lang.String path)
Creates a directory via given path- Parameters:
path- a path
-
rename
public void rename(java.lang.String sourcePath, java.lang.String destinationPath)Renames a source path to destination path- Parameters:
sourcePath- source pathdestinationPath- destination path
-
save
public void save(java.util.List<SparkFileOutput> outputs)
ExecutesSparkFileOutput#getSaveFunc()for givenSparkFileOutputs- Parameters:
outputs-SparkFileOutputs to execute
-
save
public void save(SparkFileOutput... outputs)
ExecutesSparkFileOutput#getSaveFunc()for givenSparkFileOutputs- Parameters:
outputs-SparkFileOutputs to execute
-
write
public void write(java.lang.String directory, java.lang.String filename, byte[] content)Writes given content into given directory with given filename- Parameters:
directory- a directory path to write files intofilename- the name of the filecontent- file content in byte array form
-
write
public void write(java.lang.String directory, java.lang.String filename, java.lang.String content)Writes given content into given directory with given filename- Parameters:
directory- a directory path to write files intofilename- the name of the filecontent- file content
-
-