org.apache.ignite.internal.visor.util

## Class VisorTaskUtils

- java.lang.Object
- - org.apache.ignite.internal.visor.util.VisorTaskUtils

    public class VisorTaskUtils
    extends Object

Contains utility methods for Visor tasks and jobs.

### Field Summary

Fields
`static VisorEventMapper` `EVT_MAPPER` Mapper from grid event to Visor data transfer object.
`static int` `LOG_FILES_COUNT_LIMIT` Log files count limit
`static int` `MAX_FOLDER_DEPTH` Maximum folder depth.
`static int[]` `VISOR_ALL_EVTS` Only non task event types that Visor should collect.
`static int[]` `VISOR_NON_TASK_EVTS` Only non task event types that Visor should collect.
`static int[]` `VISOR_TASK_EVTS` Only task event types that Visor should collect.

### Constructor Summary

Constructors
Constructor and Description
`VisorTaskUtils()`

### Method Summary

Methods
`static boolean` `boolValue(String propName, boolean dflt)` Returns boolean value from system property or provided function.
`static boolean` `checkExplicitTaskMonitoring(Ignite ignite)` Checks for explicit events configuration.
`static Collection<VisorGridEvent>` `collectEvents(Ignite ignite, String evtOrderKey, String evtThrottleCntrKey, boolean all)` Grabs local events and detects if events was lost since last poll.
`static Collection<VisorGridEvent>` `collectEvents(Ignite ignite, String evtOrderKey, String evtThrottleCntrKey, int[] evtTypes, IgniteClosure<Event,VisorGridEvent> evtMapper)` Grabs local events and detects if events was lost since last poll.
`static String` `compactArray(Object[] arr)` Joins array elements to string.
`static String` `compactClass(Object obj)` Compact class names.
`static Object` `compactObject(Object obj)` Returns compact class host.
`static int[]` `concat(int[]... arrays)` Concat arrays in one.
`static Charset` `decode(File f)` Decode file charset.
`static String` `escapeName(String name)`
`static Integer` `evictionPolicyMaxSize(EvictionPolicy plc)` Extract max size from eviction policy if available.
`static List<VisorLogFile>` `fileTree(File file, int maxDepth, FileFilter filter)` Finds all files in folder and in it's sub-tree of specified depth.
`static <K,V> V` `getOrElse(Map<K,V> map, K key, V ifNull)` Helper function to get value from map.
`static Integer` `intValue(String propName, Integer dflt)` Returns boolean value from system property or provided function.
`static void` `log(IgniteLogger log, String msg)` Log message.
`static long` `log(IgniteLogger log, String msg, Class<?> clazz, long start)` Log message.
`static void` `logFinish(IgniteLogger log, Class<?> clazz, long start)` Log finished.
`static void` `logMapped(IgniteLogger log, Class<?> clazz, Collection<ClusterNode> nodes)` Log task mapped.
`static void` `logStart(IgniteLogger log, Class<?> clazz, long start)` Log start.
`static List<VisorLogFile>` `matchedFiles(File fld, String ptrn)`
`static Process` `openInConsole(File workFolder, Map<String,String> envVars, String... args)` Run command in separated console.
`static Process` `openInConsole(File workFolder, String... args)` Run command in separated console.
`static Process` `openInConsole(String... args)` Run command in separated console.
`static boolean` `reachableByPing(InetAddress addr, int reachTimeout)` Checks if address can be reached using one argument InetAddress.isReachable() version or ping command if failed.
`static VisorFileBlock` `readBlock(File file, long off, int blockSz, long lastModified)` Read block from file.
`static Path` `resolveIgfsProfilerLogsDir(IgniteFileSystem igfs)` Resolve IGFS profiler logs directory.
`static boolean` `safeEquals(String a, String b)`
`static List<Process>` `startLocalNode(IgniteLogger log, String cfgPath, int nodesToStart, boolean quite, Map<String,String> envVars)` Start local node in terminal.
`static boolean` `textFile(File f, boolean emptyOk)` Check is text file.
`static String` `unescapeName(String name)`
`static byte[]` `zipBytes(byte[] input)` Zips byte array.
`static byte[]` `zipBytes(byte[] input, int initBufSize)` Zips byte array.

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

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

### Field Detail

#### LOG_FILES_COUNT_LIMIT

    public static final int LOG_FILES_COUNT_LIMIT

Log files count limit

See Also:
  Constant Field Values

#### VISOR_TASK_EVTS

    public static final int[] VISOR_TASK_EVTS

Only task event types that Visor should collect.

#### VISOR_NON_TASK_EVTS

    public static final int[] VISOR_NON_TASK_EVTS

Only non task event types that Visor should collect.

#### VISOR_ALL_EVTS

    public static final int[] VISOR_ALL_EVTS

Only non task event types that Visor should collect.

#### MAX_FOLDER_DEPTH

    public static final int MAX_FOLDER_DEPTH

Maximum folder depth. I.e. if depth is 4 we look in starting folder and 3 levels of sub-folders.

See Also:
  Constant Field Values

#### EVT_MAPPER

    public static final VisorEventMapper EVT_MAPPER

Mapper from grid event to Visor data transfer object.

### Constructor Detail

#### VisorTaskUtils

    public VisorTaskUtils()

### Method Detail

#### escapeName

    public static String escapeName(@Nullable
                    String name)

Parameters:
  `name` - Grid-style nullable name.
Returns:
  Name with `null` replaced to <default>.

#### unescapeName

    public static String unescapeName(String name)

Parameters:
  `name` - Escaped name.
Returns:
  Name or `null` for default name.

#### safeEquals

    public static boolean safeEquals(@Nullable
                     String a,
                     @Nullable
                     String b)

Parameters:
  `a` - First name.
  `b` - Second name.
Returns:
  `true` if both names equals.

#### concat

    public static int[] concat(int[]... arrays)

Concat arrays in one.

Parameters:
  `arrays` - Arrays.
Returns:
  Summary array.

#### compactObject

    @Nullable
    public static Object compactObject(Object obj)

Returns compact class host.

Parameters:
  `obj` - Object to compact.
Returns:
  String.

#### compactClass

    @Nullable
    public static String compactClass(@Nullable
                               Object obj)

Compact class names.

Parameters:
  `obj` - Object for compact.
Returns:
  Compacted string.

#### compactArray

    @Nullable
    public static String compactArray(Object[] arr)

Joins array elements to string.

Parameters:
  `arr` - Array.
Returns:
  String.

#### intValue

    public static Integer intValue(String propName,
                   Integer dflt)

Returns boolean value from system property or provided function.

Parameters:
  `propName` - System property name.
  `dflt` - Function that returns `Integer`.
Returns:
  `Integer` value

#### boolValue

    public static boolean boolValue(String propName,
                    boolean dflt)

Returns boolean value from system property or provided function.

Parameters:
  `propName` - System property host.
  `dflt` - Function that returns `Boolean`.
Returns:
  `Boolean` value

#### getOrElse

    public static <K,V> V getOrElse(Map<K,V> map,
                    K key,
                    V ifNull)

Helper function to get value from map.

Type Parameters:
  `K` - Key type.
  `V` - Value type.
Parameters:
  `map` - Map to take value from.
  `key` - Key to search in map.
  `ifNull` - Default value if `null` was returned by map.
Returns:
  Value from map or default value if map return `null`.

#### checkExplicitTaskMonitoring

    public static boolean checkExplicitTaskMonitoring(Ignite ignite)

Checks for explicit events configuration.

Parameters:
  `ignite` - Grid instance.
Returns:
  `true` if all task events explicitly specified in configuration.

#### collectEvents

    public static Collection<VisorGridEvent> collectEvents(Ignite ignite,
                                           String evtOrderKey,
                                           String evtThrottleCntrKey,
                                           boolean all)

Grabs local events and detects if events was lost since last poll.

Parameters:
  `ignite` - Target grid.
  `evtOrderKey` - Unique key to take last order key from node local map.
  `evtThrottleCntrKey` - Unique key to take throttle count from node local map.
  `all` - If `true` then collect all events otherwise collect only non task events.
Returns:
  Collections of node events

#### collectEvents

    public static Collection<VisorGridEvent> collectEvents(Ignite ignite,
                                           String evtOrderKey,
                                           String evtThrottleCntrKey,
                                           int[] evtTypes,
                                           IgniteClosure<Event,VisorGridEvent> evtMapper)

Grabs local events and detects if events was lost since last poll.

Parameters:
  `ignite` - Target grid.
  `evtOrderKey` - Unique key to take last order key from node local map.
  `evtThrottleCntrKey` - Unique key to take throttle count from node local map.
  `evtTypes` - Event types to collect.
  `evtMapper` - Closure to map grid events to Visor data transfer objects.
Returns:
  Collections of node events

#### fileTree

    public static List<VisorLogFile> fileTree(File file,
                              int maxDepth,
                              @Nullable
                              FileFilter filter)

Finds all files in folder and in it's sub-tree of specified depth.

Parameters:
  `file` - Starting folder
  `maxDepth` - Depth of the tree. If 1 - just look in the folder, no sub-folders.
  `filter` - file filter.
Returns:
  List of found files.

#### matchedFiles

    public static List<VisorLogFile> matchedFiles(File fld,
                                  String ptrn)

Parameters:
  `fld` - Folder with files to match.
  `ptrn` - Pattern to match against file name.
Returns:
  Collection of matched files.

#### textFile

    public static boolean textFile(File f,
                   boolean emptyOk)

Check is text file.

Parameters:
  `f` - file reference.
  `emptyOk` - default value if empty file.
Returns:
  Is text file.

#### decode

    public static Charset decode(File f)
                          throws IOException

Decode file charset.

Parameters:
  `f` - File to process.
Returns:
  File charset.
Throws:
  `IOException` - in case of error.

#### readBlock

    public static VisorFileBlock readBlock(File file,
                           long off,
                           int blockSz,
                           long lastModified)
                                    throws IOException

Read block from file.

Parameters:
  `file` - - File to read.
  `off` - - Marker position in file to start read from if `-1` read last blockSz bytes.
  `blockSz` - - Maximum number of chars to read.
  `lastModified` - - File last modification time.
Returns:
  Read file block.
Throws:
  `IOException` - In case of error.

#### resolveIgfsProfilerLogsDir

    public static Path resolveIgfsProfilerLogsDir(IgniteFileSystem igfs)
                                           throws IgniteCheckedException

Resolve IGFS profiler logs directory.

Parameters:
  `igfs` - IGFS instance to resolve logs dir for.
Returns:
  `Path` to log dir or `null` if not found.
Throws:
  `IgniteCheckedException` - if failed to resolve.

#### evictionPolicyMaxSize

    public static Integer evictionPolicyMaxSize(@Nullable
                                EvictionPolicy plc)

Extract max size from eviction policy if available.

Parameters:
  `plc` - Eviction policy.
Returns:
  Extracted max size.

#### logStart

    public static void logStart(@Nullable
                IgniteLogger log,
                Class<?> clazz,
                long start)

Log start.

Parameters:
  `log` - Logger.
  `clazz` - Class.
  `start` - Start time.

#### logFinish

    public static void logFinish(@Nullable
                 IgniteLogger log,
                 Class<?> clazz,
                 long start)

Log finished.

Parameters:
  `log` - Logger.
  `clazz` - Class.
  `start` - Start time.

#### logMapped

    public static void logMapped(@Nullable
                 IgniteLogger log,
                 Class<?> clazz,
                 Collection<ClusterNode> nodes)

Log task mapped.

Parameters:
  `log` - Logger.
  `clazz` - Task class.
  `nodes` - Mapped nodes.

#### log

    public static long log(@Nullable
           IgniteLogger log,
           String msg,
           Class<?> clazz,
           long start)

Log message.

Parameters:
  `log` - Logger.
  `msg` - Message to log.
  `clazz` - class.
  `start` - start time.
Returns:
  Time when message was logged.

#### log

    public static void log(@Nullable
           IgniteLogger log,
           String msg)

Log message.

Parameters:
  `log` - Logger.
  `msg` - Message.

#### reachableByPing

    public static boolean reachableByPing(InetAddress addr,
                          int reachTimeout)

Checks if address can be reached using one argument InetAddress.isReachable() version or ping command if failed.

Parameters:
  `addr` - Address to check.
  `reachTimeout` - Timeout for the check.
Returns:
  `True` if address is reachable.

#### startLocalNode

    public static List<Process> startLocalNode(@Nullable
                               IgniteLogger log,
                               String cfgPath,
                               int nodesToStart,
                               boolean quite,
                               Map<String,String> envVars)
                                        throws IOException

Start local node in terminal.

Parameters:
  `log` - Logger.
  `cfgPath` - Path to node configuration to start with.
  `nodesToStart` - Number of nodes to start.
  `quite` - If `true` then start node in quiet mode.
  `envVars` - Optional map with environment variables.
Returns:
  List of started processes.
Throws:
  `IOException` - If failed to start.

#### openInConsole

    public static Process openInConsole(String... args)
                                 throws IOException

Run command in separated console.

Parameters:
  `args` - A string array containing the program and its arguments.
Returns:
  Started process.
Throws:
  `IOException` - in case of error.

#### openInConsole

    public static Process openInConsole(@Nullable
                        File workFolder,
                        String... args)
                                 throws IOException

Run command in separated console.

Parameters:
  `workFolder` - Work folder for command.
  `args` - A string array containing the program and its arguments.
Returns:
  Started process.
Throws:
  `IOException` - in case of error.

#### openInConsole

    public static Process openInConsole(@Nullable
                        File workFolder,
                        Map<String,String> envVars,
                        String... args)
                                 throws IOException

Run command in separated console.

Parameters:
  `workFolder` - Work folder for command.
  `envVars` - Optional map with environment variables.
  `args` - A string array containing the program and its arguments.
Returns:
  Started process.
Throws:
  `IOException` - If failed to start process.

#### zipBytes

    public static byte[] zipBytes(byte[] input)
                           throws IOException

Zips byte array.

Parameters:
  `input` - Input bytes.
Returns:
  Zipped byte array.
Throws:
  `IOException` - If failed.

#### zipBytes

    public static byte[] zipBytes(byte[] input,
                  int initBufSize)
                           throws IOException

Zips byte array.

Parameters:
  `input` - Input bytes.
  `initBufSize` - Initial buffer size.
Returns:
  Zipped byte array.
Throws:
  `IOException` - If failed.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.7.0
Release Date | : August 1 2016