Package org.apache.hadoop.fs.s3a.s3guard
Class S3GuardTool
java.lang.Object
org.apache.hadoop.conf.Configured
org.apache.hadoop.fs.s3a.s3guard.S3GuardTool
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.hadoop.conf.Configurable,org.apache.hadoop.util.Tool
- Direct Known Subclasses:
BucketTool,MarkerTool,S3GuardTool.BucketInfo
@LimitedPrivate("management tools")
@Evolving
public abstract class S3GuardTool
extends org.apache.hadoop.conf.Configured
implements org.apache.hadoop.util.Tool, Closeable
CLI to manage S3Guard Metadata Store.
Some management tools invoke this class directly.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classGet info about a bucket and its S3Guard integration status. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedS3GuardTool(org.apache.hadoop.conf.Configuration conf, int min, int max, String... opts) Constructor a S3Guard tool with HDFS configuration.protectedS3GuardTool(org.apache.hadoop.conf.Configuration conf, String... opts) Constructor a S3Guard tool with HDFS configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidprotected static org.apache.hadoop.util.ExitUtil.ExitExceptionBuild the exception to raise on a bad store/bucket state.protected S3AFileSystembindFilesystem(org.apache.hadoop.fs.FileSystem bindingFS) Sets the filesystem; it must be an S3A FS instance, or a FilterFS around an S3A Filesystem.voidclose()Close the FS.protected voiddumpFileSystemStatistics(PrintStream stream) Dump the filesystem Storage Statistics if the FS is not null.protected static voiderrorln()protected static voidprotected static voidprotected static org.apache.hadoop.util.ExitUtil.ExitExceptionexitException(int exitCode, String format, Object... args) Build a exception to throw with a formatted message.protected final org.apache.hadoop.fs.shell.CommandFormatprotected S3AFileSystemabstract StringgetName()Return sub-command name.abstract StringgetUsage()protected voidinitS3AFileSystem(String path) Create and initialize a new S3A FileSystem instance.protected static org.apache.hadoop.util.ExitUtil.ExitExceptioninvalidArgs(String format, Object... args) Build the exception to raise on invalid arguments.static voidMain entry point.protected static org.apache.hadoop.util.ExitUtil.ExitExceptionHandle FileNotFoundException by converting to an exit exception with specific error code.Parse CLI arguments and returns the position arguments.parseArgsWithErrorReporting(String[] args) Process the arguments.protected static voidprintln(PrintStream out, String format, Object... args) Print a formatted string followed by a newline to the output stream.protected voidReset the store and filesystem bindings.final intabstract intrun(String[] args, PrintStream out) Run the tool, capturing the output (if the tool supports that).static intExecute the command with the given arguments.protected static org.apache.hadoop.util.ExitUtil.ExitExceptionCrate an exception declaring S3Guard is unsupported.protected static URIConvert a path to a URI, catching anyURISyntaxExceptionand converting to an invalid args exception.protected static org.apache.hadoop.util.ExitUtil.ExitExceptionuserAborted(String format, Object... args) Build the exception to raise on user-aborted action.Methods inherited from class org.apache.hadoop.conf.Configured
getConf, setConfMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.conf.Configurable
getConf, setConf
-
Field Details
-
WRONG_FILESYSTEM
Error String when the wrong FS is used for binding: "Wrong filesystem for ".- See Also:
-
META_FLAG
- See Also:
-
DAYS_FLAG
- See Also:
-
HOURS_FLAG
- See Also:
-
MINUTES_FLAG
- See Also:
-
SECONDS_FLAG
- See Also:
-
AGE_OPTIONS_USAGE
- See Also:
-
VERBOSE
- See Also:
-
-
Constructor Details
-
S3GuardTool
Constructor a S3Guard tool with HDFS configuration.- Parameters:
conf- Configuration.opts- any boolean options to support
-
S3GuardTool
Constructor a S3Guard tool with HDFS configuration.- Parameters:
conf- Configuration.min- min number of argsmax- max number of argsopts- any boolean options to support
-
-
Method Details
-
getUsage
-
getName
Return sub-command name.- Returns:
- sub-command name.
-
close
Close the FS.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- on failure.
-
addAgeOptions
protected final void addAgeOptions() -
initS3AFileSystem
Create and initialize a new S3A FileSystem instance.- Parameters:
path- s3a URI- Throws:
IOException- failure to init filesystemorg.apache.hadoop.util.ExitUtil.ExitException- if the FS is not an S3A FS
-
parseArgs
Parse CLI arguments and returns the position arguments. The options are stored incommandFormat.- Parameters:
args- command line arguments.- Returns:
- the position arguments from CLI.
-
parseArgsWithErrorReporting
protected List<String> parseArgsWithErrorReporting(String[] args) throws org.apache.hadoop.util.ExitUtil.ExitException Process the arguments.- Parameters:
args- raw args- Returns:
- process arg list.
- Throws:
org.apache.hadoop.util.ExitUtil.ExitException- if there's an unknown option.
-
getFilesystem
-
bindFilesystem
Sets the filesystem; it must be an S3A FS instance, or a FilterFS around an S3A Filesystem.- Parameters:
bindingFS- filesystem to bind to- Returns:
- the bound FS.
- Throws:
org.apache.hadoop.util.ExitUtil.ExitException- if the FS is not an S3 FS
-
resetBindings
protected void resetBindings()Reset the store and filesystem bindings. -
getCommandFormat
protected final org.apache.hadoop.fs.shell.CommandFormat getCommandFormat() -
run
- Specified by:
runin interfaceorg.apache.hadoop.util.Tool- Throws:
Exception
-
run
public abstract int run(String[] args, PrintStream out) throws Exception, org.apache.hadoop.util.ExitUtil.ExitException Run the tool, capturing the output (if the tool supports that). As well as returning an exit code, the implementations can choose to throw an instance ofExitUtil.ExitExceptionwith their exit code set to the desired exit value. The exit code of such an exception is used for the tool's exit code, and the stack trace only logged at debug.- Parameters:
args- argument listout- output stream- Returns:
- the exit code to return.
- Throws:
Exception- on any failureorg.apache.hadoop.util.ExitUtil.ExitException
-
dumpFileSystemStatistics
Dump the filesystem Storage Statistics if the FS is not null. Only non-zero statistics are printed.- Parameters:
stream- output stream
-
toUri
Convert a path to a URI, catching anyURISyntaxExceptionand converting to an invalid args exception.- Parameters:
s3Path- path to convert to a URI- Returns:
- a URI of the path
- Throws:
org.apache.hadoop.util.ExitUtil.ExitException- INVALID_ARGUMENT if the URI is invalid
-
errorln
protected static void errorln() -
errorln
-
println
Print a formatted string followed by a newline to the output stream.- Parameters:
out- destinationformat- format stringargs- optional arguments
-
notFound
Handle FileNotFoundException by converting to an exit exception with specific error code.- Parameters:
e- exception- Returns:
- a new exception to throw
-
invalidArgs
protected static org.apache.hadoop.util.ExitUtil.ExitException invalidArgs(String format, Object... args) Build the exception to raise on invalid arguments.- Parameters:
format- string formatargs- optional arguments for the string- Returns:
- a new exception to throw
-
badState
protected static org.apache.hadoop.util.ExitUtil.ExitException badState(String format, Object... args) Build the exception to raise on a bad store/bucket state.- Parameters:
format- string formatargs- optional arguments for the string- Returns:
- a new exception to throw
-
s3guardUnsupported
protected static org.apache.hadoop.util.ExitUtil.ExitException s3guardUnsupported()Crate an exception declaring S3Guard is unsupported.- Returns:
- an exception raise.
-
userAborted
protected static org.apache.hadoop.util.ExitUtil.ExitException userAborted(String format, Object... args) Build the exception to raise on user-aborted action.- Parameters:
format- string formatargs- optional arguments for the string- Returns:
- a new exception to throw
-
exitException
protected static org.apache.hadoop.util.ExitUtil.ExitException exitException(int exitCode, String format, Object... args) Build a exception to throw with a formatted message.- Parameters:
exitCode- exit code to useformat- string formatargs- optional arguments for the string- Returns:
- a new exception to throw
-
run
Execute the command with the given arguments.- Parameters:
conf- Hadoop configuration.args- command specific arguments.- Returns:
- exit code.
- Throws:
Exception- on I/O errors.
-
main
Main entry point. CallsSystem.exit()on all execution paths.- Parameters:
args- argument list
-
exit
-