org.apache.ignite.internal.processors.igfs

## Class IgfsUtils

- java.lang.Object
- - org.apache.ignite.internal.processors.igfs.IgfsUtils

    public class IgfsUtils
    extends Object

Common IGFS utility methods.

### Field Summary

Fields
`static String` `DATA_CACHE_SUFFIX` Data cache suffix.
`static IgniteUuid` `DELETE_LOCK_ID` Lock Id used to lock files being deleted from TRASH.
`static String` `IGFS_CACHE_PREFIX` Filesystem cache prefix.
`static String` `META_CACHE_SUFFIX` Meta cache suffix.
`static String` `PROP_GROUP_NAME` File property: group name.
`static String` `PROP_PERMISSION` File property: permission.
`static String` `PROP_PREFER_LOCAL_WRITES` File property: prefer writes to local node.
`static String` `PROP_USER_NAME` File property: user name.
`static IgniteUuid` `ROOT_ID` ID for the root directory.
`static int` `TRASH_CONCURRENCY` Constant trash concurrency level.

### Method Summary

Methods
`static boolean` `canContain(IgfsMode parent, IgfsMode child)` Answers if directory of this mode can contain a subdirectory of the given mode.
`static IgfsDirectoryInfo` `createDirectory(IgniteUuid id)` Create empty directory with the given ID.
`static IgfsDirectoryInfo` `createDirectory(IgniteUuid id, Map<String,IgfsListingEntry> listing, Map<String,String> props)` Create directory.
`static IgfsDirectoryInfo` `createDirectory(IgniteUuid id, Map<String,IgfsListingEntry> listing, Map<String,String> props, long createTime, long modificationTime)` Create directory.
`static IgfsFileInfo` `createFile(IgniteUuid id, int blockSize, long len, IgniteUuid affKey, IgniteUuid lockId, boolean evictExclude, Map<String,String> props, long accessTime, long modificationTime)` Create file.
`static <T> T` `doInTransactionWithRetries(IgniteInternalCache cache, IgniteOutClosureX<T> clo)` Performs an operation with transaction with retries.
`static IgfsPath` `extractOriginalPathFromTrash(String name)` Parses the TRASH file name to extract the original path.
`static String` `fixUserName(String user)` Provides non-null user name.
`static byte` `flags(boolean isDir, boolean isFile)` Create flags value.
`static boolean` `isDirectory(byte flags)` Check whether passed flags represent directory.
`static boolean` `isDualMode(IgfsMode mode)` Check whether mode is dual.
`static boolean` `isFile(byte flags)` Check whether passed flags represent file.
`static boolean` `isIgfsCache(IgniteConfiguration cfg, String cacheName)`
`static boolean` `isIgfsNode(ClusterNode node, String igfsName)` Check whether provided node contains IGFS with the given name.
`static boolean` `isRootId(IgniteUuid id)` Check whether provided ID is root ID.
`static boolean` `isRootOrTrashId(IgniteUuid id)` Check whether provided ID is either root ID or trash ID.
`static boolean` `matchIgfsCacheName(String cacheName)`
`static IgfsException` `newIgfsException(Class<? extends IgfsException> cls, String msg, Throwable cause)` Construct new IGFS exception passing specified message and cause.
`static void` `prepareCacheConfigurations(IgniteConfiguration cfg)` Prepare cache configuration if this is IGFS meta or data cache.
`static ArrayList<T2<IgfsPath,IgfsMode>>` `preparePathModes(IgfsMode dfltMode, List<T2<IgfsPath,IgfsMode>> modes, Set<IgfsPath> dualParentsContainingPrimaryChildren)` Checks, filters and sorts the modes.
`static IgniteUuid` `randomTrashId()` Get random trash ID.
`static IgfsFileAffinityRange` `readFileAffinityRange(BinaryRawReader reader)` Read IgfsFileAffinityRange.
`static IgfsListingEntry` `readListingEntry(BinaryRawReader in)` Read listing entry.
`static IgfsListingEntry` `readListingEntry(DataInput in)` Read listing entry.
`static IgfsPath` `readPath(BinaryRawReader reader)` Read IGFS path.
`static IgfsPath` `readPath(ObjectInput in)` Read non-null path from the input.
`static Map<String,String>` `readProperties(BinaryRawReader in)` Read entry properties.
`static Map<String,String>` `readProperties(DataInput in)` Read entry properties.
`static Map<String,String>` `readStringMap(DataInput in)` Reads string-to-string map written by `writeStringMap(DataOutput, Map)`.
`static String` `readUTF(DataInput in)` Read UTF string which can be `null`.
`static void` `sendEvents(GridKernalContext kernalCtx, IgfsPath path, IgfsPath newPath, int type)` Sends a series of event.
`static void` `sendEvents(GridKernalContext kernalCtx, IgfsPath path, int type)` Sends a series of event.
`static IgfsException` `toIgfsException(Throwable err)` Converts any passed exception to IGFS exception.
`static IgniteUuid` `trashId(int idx)` Get trash ID for the given index.
`static void` `writeFileAffinityRange(BinaryRawWriter writer, IgfsFileAffinityRange affRange)` Write IgfsFileAffinityRange.
`static void` `writeListingEntry(BinaryRawWriter out, IgfsListingEntry entry)` Write listing entry.
`static void` `writeListingEntry(DataOutput out, IgfsListingEntry entry)` Write listing entry.
`static void` `writePath(BinaryRawWriter writer, IgfsPath path)` Write IGFS path.
`static void` `writeProperties(BinaryRawWriter out, Map<String,String> props)` Write entry properties.
`static void` `writeProperties(DataOutput out, Map<String,String> props)` Write entry properties.
`static void` `writeStringMap(DataOutput out, Map<String,String> map)` Writes string-to-string map to given data output.
`static void` `writeUTF(DataOutput out, String val)` Write UTF string which can be `null`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### ROOT_ID

    public static final IgniteUuid ROOT_ID

ID for the root directory.

#### DELETE_LOCK_ID

    public static final IgniteUuid DELETE_LOCK_ID

Lock Id used to lock files being deleted from TRASH. This is a global constant.

#### TRASH_CONCURRENCY

    public static final int TRASH_CONCURRENCY

Constant trash concurrency level.

See Also:
  Constant Field Values

#### PROP_USER_NAME

    public static final String PROP_USER_NAME

File property: user name.

See Also:
  Constant Field Values

#### PROP_GROUP_NAME

    public static final String PROP_GROUP_NAME

File property: group name.

See Also:
  Constant Field Values

#### PROP_PERMISSION

    public static final String PROP_PERMISSION

File property: permission.

See Also:
  Constant Field Values

#### PROP_PREFER_LOCAL_WRITES

    public static final String PROP_PREFER_LOCAL_WRITES

File property: prefer writes to local node.

See Also:
  Constant Field Values

#### IGFS_CACHE_PREFIX

    public static final String IGFS_CACHE_PREFIX

Filesystem cache prefix.

See Also:
  Constant Field Values

#### DATA_CACHE_SUFFIX

    public static final String DATA_CACHE_SUFFIX

Data cache suffix.

See Also:
  Constant Field Values

#### META_CACHE_SUFFIX

    public static final String META_CACHE_SUFFIX

Meta cache suffix.

See Also:
  Constant Field Values

### Method Detail

#### randomTrashId

    public static IgniteUuid randomTrashId()

Get random trash ID.

Returns:
  Trash ID.

#### trashId

    public static IgniteUuid trashId(int idx)

Get trash ID for the given index.

Parameters:
  `idx` - Index.
Returns:
  Trahs ID.

#### isRootOrTrashId

    public static boolean isRootOrTrashId(@Nullable
                          IgniteUuid id)

Check whether provided ID is either root ID or trash ID.

Parameters:
  `id` - ID.
Returns:
  `True` if this is root ID or trash ID.

#### isRootId

    public static boolean isRootId(@Nullable
                   IgniteUuid id)

Check whether provided ID is root ID.

Parameters:
  `id` - ID.
Returns:
  `True` if this is root ID.

#### toIgfsException

    public static IgfsException toIgfsException(Throwable err)

Converts any passed exception to IGFS exception.

Parameters:
  `err` - Initial exception.
Returns:
  Converted IGFS exception.

#### newIgfsException

    public static IgfsException newIgfsException(Class<? extends IgfsException> cls,
                                 String msg,
                                 Throwable cause)

Construct new IGFS exception passing specified message and cause.

Parameters:
  `cls` - Class.
  `msg` - Message.
  `cause` - Cause.
Returns:
  New IGFS exception.

#### fixUserName

    public static String fixUserName(@Nullable
                     String user)

Provides non-null user name. If the user name is null or empty string, defaults to `FileSystemConfiguration.DFLT_USER_NAME`, which is the current process owner user.

Parameters:
  `user` - a user name to be fixed.
Returns:
  non-null interned user name.

#### doInTransactionWithRetries

    public static <T> T doInTransactionWithRetries(IgniteInternalCache cache,
                                   IgniteOutClosureX<T> clo)
                                        throws IgniteCheckedException

Performs an operation with transaction with retries.

Parameters:
  `cache` - Cache to do the transaction on.
  `clo` - Closure.
Returns:
  Result of closure execution.
Throws:
  `IgniteCheckedException` - If failed.

#### sendEvents

    public static void sendEvents(GridKernalContext kernalCtx,
                  IgfsPath path,
                  int type)

Sends a series of event.

Parameters:
  `kernalCtx` - Kernal context.
  `path` - The path of the created file.
  `type` - The type of event to send.

#### sendEvents

    public static void sendEvents(GridKernalContext kernalCtx,
                  IgfsPath path,
                  IgfsPath newPath,
                  int type)

Sends a series of event.

Parameters:
  `kernalCtx` - Kernal context.
  `path` - The path of the created file.
  `newPath` - New path.
  `type` - The type of event to send.

#### matchIgfsCacheName

    public static boolean matchIgfsCacheName(@Nullable
                             String cacheName)

Parameters:
  `cacheName` - Cache name.
Returns:
  `True` in this is IGFS data or meta cache.

#### isIgfsCache

    public static boolean isIgfsCache(IgniteConfiguration cfg,
                      @Nullable
                      String cacheName)

Parameters:
  `cfg` - Grid configuration.
  `cacheName` - Cache name.
Returns:
  `True` in this is IGFS data or meta cache.

#### prepareCacheConfigurations

    public static void prepareCacheConfigurations(IgniteConfiguration cfg)
                                           throws IgniteCheckedException

Prepare cache configuration if this is IGFS meta or data cache.

Parameters:
  `cfg` - Configuration.
Throws:
  `IgniteCheckedException` - If failed.

#### createDirectory

    public static IgfsDirectoryInfo createDirectory(IgniteUuid id)

Create empty directory with the given ID.

Parameters:
  `id` - ID.
Returns:
  File info.

#### createDirectory

    public static IgfsDirectoryInfo createDirectory(IgniteUuid id,
                                    @Nullable
                                    Map<String,IgfsListingEntry> listing,
                                    @Nullable
                                    Map<String,String> props)

Create directory.

Parameters:
  `id` - ID.
  `listing` - Listing.
  `props` - Properties.
Returns:
  File info.

#### createDirectory

    public static IgfsDirectoryInfo createDirectory(IgniteUuid id,
                                    @Nullable
                                    Map<String,IgfsListingEntry> listing,
                                    @Nullable
                                    Map<String,String> props,
                                    long createTime,
                                    long modificationTime)

Create directory.

Parameters:
  `id` - ID.
  `listing` - Listing.
  `props` - Properties.
  `createTime` - Create time.
  `modificationTime` - Modification time.
Returns:
  File info.

#### createFile

    public static IgfsFileInfo createFile(IgniteUuid id,
                          int blockSize,
                          long len,
                          @Nullable
                          IgniteUuid affKey,
                          @Nullable
                          IgniteUuid lockId,
                          boolean evictExclude,
                          @Nullable
                          Map<String,String> props,
                          long accessTime,
                          long modificationTime)

Create file.

Parameters:
  `id` - File ID.
  `blockSize` - Block size.
  `len` - Length.
  `affKey` - Affinity key.
  `lockId` - Lock ID.
  `evictExclude` - Evict exclude flag.
  `props` - Properties.
  `accessTime` - Access time.
  `modificationTime` - Modification time.
Returns:
  File info.

#### writeListingEntry

    public static void writeListingEntry(BinaryRawWriter out,
                         @Nullable
                         IgfsListingEntry entry)

Write listing entry.

Parameters:
  `out` - Writer.
  `entry` - Entry.

#### readListingEntry

    @Nullable
    public static IgfsListingEntry readListingEntry(BinaryRawReader in)

Read listing entry.

Parameters:
  `in` - Reader.
Returns:
  Entry.

#### writeListingEntry

    public static void writeListingEntry(DataOutput out,
                         @Nullable
                         IgfsListingEntry entry)
                                  throws IOException

Write listing entry.

Parameters:
  `out` - Writer.
  `entry` - Entry.
Throws:
  `IOException` - If failed.

#### readListingEntry

    @Nullable
    public static IgfsListingEntry readListingEntry(DataInput in)
                                             throws IOException

Read listing entry.

Parameters:
  `in` - Reader.
Returns:
  Entry.
Throws:
  `IOException` - If failed.

#### writeProperties

    public static void writeProperties(BinaryRawWriter out,
                       @Nullable
                       Map<String,String> props)

Write entry properties. Rely on reference equality for well-known properties.

Parameters:
  `out` - Writer.
  `props` - Properties.

#### readProperties

    @Nullable
    public static Map<String,String> readProperties(BinaryRawReader in)

Read entry properties.

Parameters:
  `in` - Reader.
Returns:
  Properties.

#### writeProperties

    public static void writeProperties(DataOutput out,
                       @Nullable
                       Map<String,String> props)
                                throws IOException

Write entry properties. Rely on reference equality for well-known properties.

Parameters:
  `out` - Writer.
  `props` - Properties.
Throws:
  `IOException` - If failed.

#### readProperties

    @Nullable
    public static Map<String,String> readProperties(DataInput in)
                                             throws IOException

Read entry properties.

Parameters:
  `in` - Reader.
Returns:
  Properties.
Throws:
  `IOException` - If failed.

#### writePath

    public static void writePath(BinaryRawWriter writer,
                 @Nullable
                 IgfsPath path)

Write IGFS path.

Parameters:
  `writer` - Writer.
  `path` - Path.

#### readPath

    @Nullable
    public static IgfsPath readPath(BinaryRawReader reader)

Read IGFS path.

Parameters:
  `reader` - Reader.
Returns:
  Path.

#### readPath

    public static IgfsPath readPath(ObjectInput in)
                             throws IOException

Read non-null path from the input.

Parameters:
  `in` - Input.
Returns:
  IGFS path.
Throws:
  `IOException` - If failed.

#### writeFileAffinityRange

    public static void writeFileAffinityRange(BinaryRawWriter writer,
                              @Nullable
                              IgfsFileAffinityRange affRange)

Write IgfsFileAffinityRange.

Parameters:
  `writer` - Writer
  `affRange` - affinity range.

#### readFileAffinityRange

    public static IgfsFileAffinityRange readFileAffinityRange(BinaryRawReader reader)

Read IgfsFileAffinityRange.

Parameters:
  `reader` - Reader.
Returns:
  File affinity range.

#### extractOriginalPathFromTrash

    public static IgfsPath extractOriginalPathFromTrash(String name)

Parses the TRASH file name to extract the original path.

Parameters:
  `name` - The TRASH short (entry) name.
Returns:
  The original path, or null in case of failure.

#### isIgfsNode

    public static boolean isIgfsNode(ClusterNode node,
                     String igfsName)

Check whether provided node contains IGFS with the given name.

Parameters:
  `node` - Node.
  `igfsName` - IGFS name.
Returns:
  `True` if it contains IGFS.

#### isDualMode

    public static boolean isDualMode(IgfsMode mode)

Check whether mode is dual.

Parameters:
  `mode` - Mode.
Returns:
  `True` if dual.

#### canContain

    public static boolean canContain(IgfsMode parent,
                     IgfsMode child)

Answers if directory of this mode can contain a subdirectory of the given mode.

Parameters:
  `parent` - Parent mode.
  `child` - Child mode.
Returns:
  `true` if directory of this mode can contain a directory of the given mode.

#### preparePathModes

    public static ArrayList<T2<IgfsPath,IgfsMode>> preparePathModes(IgfsMode dfltMode,
                                                    @Nullable
                                                    List<T2<IgfsPath,IgfsMode>> modes,
                                                    Set<IgfsPath> dualParentsContainingPrimaryChildren)
                                                             throws IgniteCheckedException

Checks, filters and sorts the modes.

Parameters:
  `dfltMode` - The root mode. Must always be not null.
  `modes` - The subdirectory modes.
  `dualParentsContainingPrimaryChildren` - The set to store parents into.
Returns:
  Descending list of filtered and checked modes.
Throws:
  `IgniteCheckedException` - On error.

#### flags

    public static byte flags(boolean isDir,
             boolean isFile)

Create flags value.

Parameters:
  `isDir` - Directory flag.
  `isFile` - File flag.
Returns:
  Result.

#### isDirectory

    public static boolean isDirectory(byte flags)

Check whether passed flags represent directory.

Parameters:
  `flags` - Flags.
Returns:
  `True` if this is directory.

#### isFile

    public static boolean isFile(byte flags)

Check whether passed flags represent file.

Parameters:
  `flags` - Flags.
Returns:
  `True` if this is file.

#### readStringMap

    public static Map<String,String> readStringMap(DataInput in)
                                            throws IOException

Reads string-to-string map written by `writeStringMap(DataOutput, Map)`.

Parameters:
  `in` - Data input.
Returns:
  Read result.
Throws:
  `IOException` - If write failed.

#### writeStringMap

    public static void writeStringMap(DataOutput out,
                      @Nullable
                      Map<String,String> map)
                               throws IOException

Writes string-to-string map to given data output.

Parameters:
  `out` - Data output.
  `map` - Map.
Throws:
  `IOException` - If write failed.

#### writeUTF

    public static void writeUTF(DataOutput out,
                @Nullable
                String val)
                         throws IOException

Write UTF string which can be `null`.

Parameters:
  `out` - Output stream.
  `val` - Value.
Throws:
  `IOException` - If failed.

#### readUTF

    public static String readUTF(DataInput in)
                          throws IOException

Read UTF string which can be `null`.

Parameters:
  `in` - Input stream.
Returns:
  Value.
Throws:
  `IOException` - If failed.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.1.0
Release Date | : July 20 2017