Class FileSystemShellUtils


  • @ThreadSafe
    public final class FileSystemShellUtils
    extends java.lang.Object
    Class for convenience methods used by FileSystemShell.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<alluxio.AlluxioURI> getAlluxioURIs​(alluxio.client.file.FileSystem alluxioClient, alluxio.AlluxioURI inputURI)
      Gets all the AlluxioURIs that match inputURI.
      static boolean getBoolArg​(org.apache.commons.cli.CommandLine cl, org.apache.commons.cli.Option option, boolean defaultValue)
      Gets the value of an option from the command line.
      static java.lang.String getFilePath​(java.lang.String path, alluxio.conf.AlluxioConfiguration alluxioConf)
      Removes Constants.HEADER and hostname:port information from a path, leaving only the local file path.
      static java.util.List<java.io.File> getFiles​(java.lang.String inputPath)
      Gets the files (on the local filesystem) that match the given input path.
      static int getIntArg​(org.apache.commons.cli.CommandLine cl, org.apache.commons.cli.Option option, int defaultValue)
      Gets the value of an option from the command line.
      static long getMs​(java.lang.String time)
      Converts the input time into millisecond unit.
      static long getMsArg​(org.apache.commons.cli.CommandLine cl, org.apache.commons.cli.Option option, long defaultValue)
      Gets the value of an option from the command line.
      static java.util.Map<java.lang.String,​alluxio.cli.Command> loadCommands​(alluxio.client.file.FileSystemContext fsContext)
      Gets all Command instances in the same package as FileSystemShell and load them into a map.
      static boolean match​(java.lang.String filePath, java.lang.String patternPath)
      Returns whether or not filePath matches patternPath.
      static java.lang.String validatePath​(java.lang.String path, alluxio.conf.AlluxioConfiguration alluxioConf)
      Validates the path, verifying that it contains the Constants.HEADER and a hostname:port specified.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getFilePath

        public static java.lang.String getFilePath​(java.lang.String path,
                                                   alluxio.conf.AlluxioConfiguration alluxioConf)
                                            throws java.io.IOException
        Removes Constants.HEADER and hostname:port information from a path, leaving only the local file path.
        Parameters:
        path - the path to obtain the local path from
        alluxioConf - Alluxio configuration
        Returns:
        the local path in string format
        Throws:
        java.io.IOException
      • validatePath

        public static java.lang.String validatePath​(java.lang.String path,
                                                    alluxio.conf.AlluxioConfiguration alluxioConf)
                                             throws java.io.IOException
        Validates the path, verifying that it contains the Constants.HEADER and a hostname:port specified.
        Parameters:
        path - the path to be verified
        alluxioConf - Alluxio configuration
        Returns:
        the verified path in a form like alluxio://host:port/dir. If only the "/dir" or "dir" part is provided, the host and port are retrieved from property, alluxio.master.hostname and alluxio.master.rpc.port, respectively.
        Throws:
        java.io.IOException
      • getAlluxioURIs

        public static java.util.List<alluxio.AlluxioURI> getAlluxioURIs​(alluxio.client.file.FileSystem alluxioClient,
                                                                        alluxio.AlluxioURI inputURI)
                                                                 throws java.io.IOException
        Gets all the AlluxioURIs that match inputURI. If the path is a regular path, the returned list only contains the corresponding URI; Else if the path contains wildcards, the returned list contains all the matched URIs It supports any number of wildcards in inputURI
        Parameters:
        alluxioClient - the client used to fetch information of Alluxio files
        inputURI - the input URI (could contain wildcards)
        Returns:
        a list of AlluxioURIs that matches the inputURI
        Throws:
        java.io.IOException
      • getFiles

        public static java.util.List<java.io.File> getFiles​(java.lang.String inputPath)
        Gets the files (on the local filesystem) that match the given input path. If the path is a regular path, the returned list only contains the corresponding file; Else if the path contains wildcards, the returned list contains all the matched Files.
        Parameters:
        inputPath - The input file path (could contain wildcards)
        Returns:
        a list of files that matches inputPath
      • getBoolArg

        public static boolean getBoolArg​(org.apache.commons.cli.CommandLine cl,
                                         org.apache.commons.cli.Option option,
                                         boolean defaultValue)
        Gets the value of an option from the command line.
        Parameters:
        cl - command line object
        option - the option to check for in the command line
        defaultValue - default value for the option
        Returns:
        argument from command line or default if not present
      • getIntArg

        public static int getIntArg​(org.apache.commons.cli.CommandLine cl,
                                    org.apache.commons.cli.Option option,
                                    int defaultValue)
        Gets the value of an option from the command line.
        Parameters:
        cl - command line object
        option - the option to check for in the command line
        defaultValue - default value for the option
        Returns:
        argument from command line or default if not present
      • getMsArg

        public static long getMsArg​(org.apache.commons.cli.CommandLine cl,
                                    org.apache.commons.cli.Option option,
                                    long defaultValue)
        Gets the value of an option from the command line.
        Parameters:
        cl - command line object
        option - the option to check for in the command line
        defaultValue - default value for the option
        Returns:
        argument from command line or default if not present
      • loadCommands

        public static java.util.Map<java.lang.String,​alluxio.cli.Command> loadCommands​(alluxio.client.file.FileSystemContext fsContext)
        Gets all Command instances in the same package as FileSystemShell and load them into a map. Provides a way to gain these commands information by their CommandName.
        Parameters:
        fsContext - the FileSystemContext instance to construct the command
        Returns:
        a mapping from command name to command instance
      • getMs

        public static long getMs​(java.lang.String time)
        Converts the input time into millisecond unit.
        Parameters:
        time - the time to be converted into milliseconds
        Returns:
        the time in millisecond unit
      • match

        public static boolean match​(java.lang.String filePath,
                                    java.lang.String patternPath)
        Returns whether or not filePath matches patternPath.
        Parameters:
        filePath - path of a given file
        patternPath - path that can contain wildcards
        Returns:
        true if matches; false if not