public class Utils
extends Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static String |
BACKUP_STANDALONE_MASTER_PREFIX()
An identifier that backup masters use in their responses.
|
static String |
bytesToString(scala.math.BigInt size) |
static String |
bytesToString(long size)
Convert a quantity in bytes to a human-readable string such as "4.0 MB".
|
static long |
byteStringAsBytes(String str)
Convert a passed byte string (e.g.
|
static long |
byteStringAsGb(String str)
Convert a passed byte string (e.g.
|
static long |
byteStringAsKb(String str)
Convert a passed byte string (e.g.
|
static long |
byteStringAsMb(String str)
Convert a passed byte string (e.g.
|
static void |
checkHost(String host,
String message) |
static void |
checkHostPort(String hostPort,
String message) |
static boolean |
chmod700(java.io.File file)
JDK equivalent of
chmod 700 file . |
static Class<?> |
classForName(String className)
Preferred alternative to Class.forName(className)
|
static boolean |
classIsLoadable(String clazz)
Determines whether the provided class is loadable in the current thread.
|
static <T> T |
clone(T value,
SerializerInstance serializer,
scala.reflect.ClassTag<T> evidence$2)
Clone an object using a Spark serializer.
|
static void |
configTestLog4j(String level)
config a log4j properties used for testsuite
|
static java.net.URI |
constructURIForAuthentication(java.net.URI uri,
org.apache.spark.SecurityManager securityMgr)
Construct a URI container information used for authentication.
|
static void |
copyFileStreamNIO(java.nio.channels.FileChannel input,
java.nio.channels.FileChannel output,
long startPosition,
long bytesToCopy) |
static long |
copyStream(java.io.InputStream in,
java.io.OutputStream out,
boolean closeStreams,
boolean transferToEnabled)
Copy all data from an InputStream to an OutputStream.
|
static java.io.File |
createDirectory(String root,
String namePrefix)
Create a directory inside the given parent directory.
|
static String |
createSecret(SparkConf conf) |
static java.io.File |
createTempDir(String root,
String namePrefix)
Create a temporary directory inside the given parent directory.
|
static String |
decodeFileNameInURI(java.net.URI uri)
Get the file name from uri's raw path and decode it.
|
static int |
DEFAULT_DRIVER_MEM_MB()
Define a default value for driver memory here since this value is referenced across the code
base and nearly all files already use Utils.scala
|
static int |
DEFAULT_MAX_TO_STRING_FIELDS()
The performance overhead of creating and logging strings for wide schemas can be large.
|
static void |
deleteRecursively(java.io.File file)
Delete a file or directory and its contents recursively.
|
static <T> T |
deserialize(byte[] bytes)
Deserialize an object using Java serialization
|
static <T> T |
deserialize(byte[] bytes,
ClassLoader loader)
Deserialize an object using Java serialization and the given ClassLoader
|
static long |
deserializeLongValue(byte[] bytes)
Deserialize a Long value (used for
PythonPartitioner ) |
static void |
deserializeViaNestedStream(java.io.InputStream is,
SerializerInstance ser,
scala.Function1<DeserializationStream,scala.runtime.BoxedUnit> f)
Deserialize via nested stream using specific serializer
|
static boolean |
doesDirectoryContainAnyNewFiles(java.io.File dir,
long cutoff)
Determines if a directory contains any files newer than cutoff seconds.
|
static scala.collection.immutable.Set<String> |
EMPTY_USER_GROUPS() |
static org.json4s.JsonAST.JObject |
emptyJson()
Return an empty JSON object
|
static String |
encodeFileNameToURIRawPath(String fileName)
A file name may contain some invalid URI characters, such as " ".
|
static String |
exceptionString(Throwable e)
Return a nice string representation of the exception.
|
static String |
executeAndGetOutput(scala.collection.Seq<String> command,
java.io.File workingDir,
scala.collection.Map<String,String> extraEnvironment,
boolean redirectStderr)
Execute a command and get its output, throwing an exception if it yields a code other than 0.
|
static Process |
executeCommand(scala.collection.Seq<String> command,
java.io.File workingDir,
scala.collection.Map<String,String> extraEnvironment,
boolean redirectStderr)
Execute a command and return the process running the command.
|
static scala.Tuple2<String,Object> |
extractHostPortFromSparkUrl(String sparkUrl)
Return a pair of host and port extracted from the
sparkUrl . |
static void |
fetchFile(String url,
java.io.File targetDir,
SparkConf conf,
org.apache.spark.SecurityManager securityMgr,
org.apache.hadoop.conf.Configuration hadoopConf,
long timestamp,
boolean useCache)
Download a file or directory to target directory.
|
static org.apache.spark.util.CallSite |
getCallSite(scala.Function1<String,Object> skipClass)
When called inside a class in the spark package, returns the name of the user code class
(outside the spark package) that called into Spark, as well as which Spark method they called.
|
static String[] |
getConfiguredLocalDirs(SparkConf conf)
Return the configured local directories where Spark can write files.
|
static ClassLoader |
getContextOrSparkClassLoader()
Get the Context ClassLoader on this thread or, if not present, the ClassLoader that
loaded Spark.
|
static scala.collection.immutable.Set<String> |
getCurrentUserGroups(SparkConf sparkConf,
String username) |
static String |
getCurrentUserName()
Returns the current user name.
|
static String |
getDefaultPropertiesFile(scala.collection.Map<String,String> env)
Return the path of the default Spark properties file.
|
static int |
getDynamicAllocationInitialExecutors(SparkConf conf)
Return the initial number of executors for dynamic allocation.
|
static long |
getFileLength(java.io.File file,
SparkConf workConf)
Return the file length, if the file is compressed it returns the uncompressed file length.
|
static org.apache.hadoop.fs.Path |
getFilePath(java.io.File dir,
String fileName)
Return the absolute path of a file in the given directory.
|
static String |
getFormattedClassName(Object obj)
Return the class name of the given object, removing all dollar signs
|
static org.apache.hadoop.fs.FileSystem |
getHadoopFileSystem(String path,
org.apache.hadoop.conf.Configuration conf)
Return a Hadoop FileSystem with the scheme encoded in the given path.
|
static org.apache.hadoop.fs.FileSystem |
getHadoopFileSystem(java.net.URI path,
org.apache.hadoop.conf.Configuration conf)
Return a Hadoop FileSystem with the scheme encoded in the given path.
|
static <T> long |
getIteratorSize(scala.collection.Iterator<T> iterator)
Counts the number of elements of an iterator using a while loop rather than calling
TraversableOnce.size() because it uses a for loop, which is slightly slower
in the current version of Scala. |
static <T> scala.collection.Iterator<scala.Tuple2<T,Object>> |
getIteratorZipWithIndex(scala.collection.Iterator<T> iterator,
long startIndex)
Generate a zipWithIndex iterator, avoid index value overflowing problem
in scala's zipWithIndex
|
static String |
getLocalDir(SparkConf conf)
Get the path of a temporary directory.
|
static scala.collection.Seq<String> |
getLocalUserJarsForShell(SparkConf conf)
Return the local jar files which will be added to REPL's classpath.
|
static long |
getMaxResultSize(SparkConf conf) |
static String |
getProcessName()
Returns the name of this JVM process.
|
static scala.collection.Map<String,String> |
getPropertiesFromFile(String filename)
Load properties present in the given file.
|
static ClassLoader |
getSparkClassLoader()
Get the ClassLoader which loaded Spark.
|
static String |
getSparkOrYarnConfig(SparkConf conf,
String key,
String default_)
Return the value of a config either through the SparkConf or the Hadoop configuration
if this is Yarn mode.
|
static scala.Option<String> |
getStderr(Process process,
long timeoutMs)
Return the stderr of a process after waiting for the process to terminate.
|
static scala.collection.Map<String,String> |
getSystemProperties()
Returns the system properties map that is thread-safe to iterator over.
|
static org.apache.spark.util.ThreadStackTrace[] |
getThreadDump()
Return a thread dump of all threads' stacktraces.
|
static scala.Option<org.apache.spark.util.ThreadStackTrace> |
getThreadDumpForThread(long threadId) |
static String |
getUsedTimeMs(long startTimeMs)
Return the string to tell how long has passed in milliseconds.
|
static scala.collection.Seq<String> |
getUserJars(SparkConf conf)
Return the jar files pointed by the "spark.jars" property.
|
static void |
initDaemon(org.slf4j.Logger log)
Utility function that should be called early in
main() for daemons to set up some common
diagnostic state. |
static Object |
invoke(Class<?> clazz,
Object obj,
String methodName,
scala.collection.Seq<scala.Tuple2<Class<?>,Object>> args) |
static boolean |
isBindCollision(Throwable exception)
Return whether the exception is caused by an address-port collision when binding.
|
static boolean |
isDynamicAllocationEnabled(SparkConf conf)
Return whether dynamic allocation is enabled in the given conf.
|
static boolean |
isFatalError(Throwable e)
Returns true if the given exception was fatal.
|
static boolean |
isInDirectory(java.io.File parent,
java.io.File child)
Return whether the specified file is a parent directory of the child file.
|
static boolean |
isLocalMaster(SparkConf conf) |
static boolean |
isMac()
Whether the underlying operating system is Mac OS X.
|
static boolean |
isSymlink(java.io.File file)
Check to see if file is a symbolic link.
|
static boolean |
isTesting()
Indicates whether Spark is currently running unit tests.
|
static boolean |
isWindows()
Whether the underlying operating system is Windows.
|
static scala.Option<org.json4s.JsonAST.JValue> |
jsonOption(org.json4s.JsonAST.JValue json)
Return an option that translates JNothing to None
|
static String |
libraryPathEnvName()
Return the current system LD_LIBRARY_PATH name
|
static String |
libraryPathEnvPrefix(scala.collection.Seq<String> libraryPaths)
Return the prefix of a command that appends the given library paths to the
system-specific library path environment variable.
|
static String |
loadDefaultSparkProperties(SparkConf conf,
String filePath)
Load default Spark properties from the given file.
|
static String |
localHostName()
Get the local machine's hostname.
|
static String |
localHostNameForURI()
Get the local machine's URI.
|
static <T> T |
logUncaughtExceptions(scala.Function0<T> f)
Execute the given block, logging and re-throwing any uncaught exception.
|
static String |
megabytesToString(long megabytes)
Convert a quantity in megabytes to a human-readable string such as "4.0 MB".
|
static int |
memoryStringToMb(String str)
Convert a Java memory parameter passed to -Xmx (such as 300m or 1g) to a number of mebibytes.
|
static String |
msDurationToString(long ms)
Returns a human-readable string representing a duration such as "35ms"
|
static int |
nanSafeCompareDoubles(double x,
double y)
NaN-safe version of
java.lang.Double.compare() which allows NaN values to be compared
according to semantics where NaN == NaN and NaN is greater than any non-NaN double. |
static int |
nanSafeCompareFloats(float x,
float y)
NaN-safe version of
java.lang.Float.compare() which allows NaN values to be compared
according to semantics where NaN == NaN and NaN is greater than any non-NaN float. |
static String[] |
nonLocalPaths(String paths,
boolean testWindows)
Return all non-local paths from a comma-separated list of paths.
|
static int |
nonNegativeHash(Object obj) |
static int |
nonNegativeMod(int x,
int mod) |
static String |
offsetBytes(scala.collection.Seq<java.io.File> files,
scala.collection.Seq<Object> fileLengths,
long start,
long end)
Return a string containing data across a set of files.
|
static String |
offsetBytes(String path,
long length,
long start,
long end)
Return a string containing part of a file from byte 'start' to 'end'.
|
static scala.Tuple2<String,Object> |
parseHostPort(String hostPort) |
static String[] |
parseStandaloneMasterUrls(String masterUrls)
Split the comma delimited string of master URLs into a list.
|
static int |
portMaxRetries(SparkConf conf)
Maximum number of retries when binding to a port before giving up.
|
static Thread |
processStreamByLine(String threadName,
java.io.InputStream inputStream,
scala.Function1<String,scala.runtime.BoxedUnit> processLine)
Return and start a daemon thread that processes the content of the input stream line by line.
|
static java.util.Random |
random() |
static <T> scala.collection.Seq<T> |
randomize(scala.collection.TraversableOnce<T> seq,
scala.reflect.ClassTag<T> evidence$1)
Shuffle the elements of a collection into a random order, returning the
result in a new collection.
|
static <T> Object |
randomizeInPlace(Object arr,
java.util.Random rand)
Shuffle the elements of an array into a random order, modifying the
original array.
|
static scala.collection.Seq<scala.Tuple2<String,String>> |
redact(scala.collection.Map<String,String> kvs)
Looks up the redaction regex from within the key value pairs and uses it to redact the rest
of the key value pairs.
|
static scala.collection.Seq<scala.Tuple2<String,String>> |
redact(scala.Option<scala.util.matching.Regex> regex,
scala.collection.Seq<scala.Tuple2<String,String>> kvs)
Redact the sensitive values in the given map.
|
static scala.collection.Seq<scala.Tuple2<String,String>> |
redact(SparkConf conf,
scala.collection.Seq<scala.Tuple2<String,String>> kvs)
Redact the sensitive values in the given map.
|
static String |
redact(SparkConf conf,
String text)
Redact the sensitive information in the given string.
|
static java.net.URI |
resolveURI(String path)
Return a well-formed URI for the file described by a user input string.
|
static String |
resolveURIs(String paths)
Resolve a comma-separated list of paths.
|
static boolean |
responseFromBackup(String msg)
Return true if the response message is sent from a backup Master on standby.
|
static <T> byte[] |
serialize(T o)
Serialize an object using Java serialization
|
static void |
serializeViaNestedStream(java.io.OutputStream os,
SerializerInstance ser,
scala.Function1<SerializationStream,scala.runtime.BoxedUnit> f)
Serialize via nested stream using specific serializer
|
static void |
setCustomHostname(String hostname)
Allow setting a custom host name because when we run on Mesos we need to use the same
hostname it reports to the master.
|
static void |
setLogLevel(org.apache.log4j.Level l)
configure a new log4j level
|
static java.net.URLConnection |
setupSecureURLConnection(java.net.URLConnection urlConnection,
org.apache.spark.SecurityManager sm)
If the given URL connection is HttpsURLConnection, it sets the SSL socket factory and
the host verifier from the given security manager.
|
static scala.collection.Seq<String> |
sparkJavaOpts(SparkConf conf,
scala.Function1<String,Object> filterKey)
Convert all spark properties set in the given SparkConf to a sequence of java options.
|
static scala.collection.Seq<String> |
splitCommandString(String s)
Split a string of potentially quoted arguments from the command line the way that a shell
would do it to determine arguments to a command.
|
static <T> scala.Tuple2<T,Object> |
startServiceOnPort(int startPort,
scala.Function1<Object,scala.Tuple2<T,Object>> startService,
SparkConf conf,
String serviceName)
Attempt to start a service on the given port, or fail after a number of attempts.
|
static String |
stripDirectory(String path)
Strip the directory from a path name
|
static void |
symlink(java.io.File src,
java.io.File dst)
Creates a symlink.
|
static java.io.File |
tempFileWith(java.io.File path)
Returns a path of temporary file which is in the same directory with
path . |
static scala.Option<Object> |
terminateProcess(Process process,
long timeoutMs)
Terminates a process waiting for at most the specified duration.
|
static long |
timeIt(int numIters,
scala.Function0<scala.runtime.BoxedUnit> f,
scala.Option<scala.Function0<scala.runtime.BoxedUnit>> prepare)
Timing method based on iterations that permit JVM JIT optimization.
|
static void |
times(int numIters,
scala.Function0<scala.runtime.BoxedUnit> f)
Method executed for repeating a task for side effects.
|
static long |
timeStringAsMs(String str)
Convert a time parameter such as (50s, 100ms, or 250us) to microseconds for internal use.
|
static long |
timeStringAsSeconds(String str)
Convert a time parameter such as (50s, 100ms, or 250us) to seconds for internal use.
|
static <T> String |
truncatedString(scala.collection.Seq<T> seq,
String sep)
Shorthand for calling truncatedString() without start or end strings.
|
static <T> String |
truncatedString(scala.collection.Seq<T> seq,
String start,
String sep,
String end,
int maxNumFields)
Format a sequence with semantics similar to calling .mkString().
|
static <T> scala.util.Try<T> |
tryLog(scala.Function0<T> f)
Executes the given block in a Try, logging any uncaught exceptions.
|
static void |
tryLogNonFatalError(scala.Function0<scala.runtime.BoxedUnit> block)
Executes the given block.
|
static void |
tryOrExit(scala.Function0<scala.runtime.BoxedUnit> block)
Execute a block of code that evaluates to Unit, forwarding any uncaught exceptions to the
default UncaughtExceptionHandler
|
static <T> T |
tryOrIOException(scala.Function0<T> block)
Execute a block of code that returns a value, re-throwing any non-fatal uncaught
exceptions as IOException.
|
static void |
tryOrStopSparkContext(SparkContext sc,
scala.Function0<scala.runtime.BoxedUnit> block)
Execute a block of code that evaluates to Unit, stop SparkContext if there is any uncaught
exception
|
static <R extends java.io.Closeable,T> |
tryWithResource(scala.Function0<R> createResource,
scala.Function1<R,T> f) |
static <T> T |
tryWithSafeFinally(scala.Function0<T> block,
scala.Function0<scala.runtime.BoxedUnit> finallyBlock)
Execute a block of code, then a finally block, but if exceptions happen in
the finally block, do not suppress the original exception.
|
static <T> T |
tryWithSafeFinallyAndFailureCallbacks(scala.Function0<T> block,
scala.Function0<scala.runtime.BoxedUnit> catchBlock,
scala.Function0<scala.runtime.BoxedUnit> finallyBlock)
Execute a block of code and call the failure callbacks in the catch block.
|
static scala.collection.immutable.Set<String> |
unionFileLists(scala.Option<String> leftList,
scala.Option<String> rightList)
Unions two comma-separated lists of files and filters out empty strings.
|
static void |
updateSparkConfigFromProperties(SparkConf conf,
scala.collection.Map<String,String> properties)
Updates Spark config with properties from a set of Properties.
|
static int |
userPort(int base,
int offset)
Returns the user port to try when trying to bind a service.
|
static void |
validateURL(java.net.URI uri)
Validate that a given URI is actually a valid URL as well.
|
static scala.util.matching.Regex |
windowsDrive()
Pattern for matching a Windows drive, which contains only a single alphabet character.
|
static <T> T |
withDummyCallSite(SparkContext sc,
scala.Function0<T> body)
To avoid calling
Utils.getCallSite for every single RDD we create in the body,
set a dummy call site that RDDs use instead. |
static void |
writeByteBuffer(java.nio.ByteBuffer bb,
java.io.DataOutput out)
Primitive often used when writing
ByteBuffer to DataOutput |
static void |
writeByteBuffer(java.nio.ByteBuffer bb,
java.io.OutputStream out)
Primitive often used when writing
ByteBuffer to OutputStream |
public static java.util.Random random()
public static int DEFAULT_DRIVER_MEM_MB()
public static int DEFAULT_MAX_TO_STRING_FIELDS()
public static <T> String truncatedString(scala.collection.Seq<T> seq, String start, String sep, String end, int maxNumFields)
seq
- (undocumented)start
- (undocumented)sep
- (undocumented)end
- (undocumented)maxNumFields
- (undocumented)public static <T> String truncatedString(scala.collection.Seq<T> seq, String sep)
public static <T> byte[] serialize(T o)
public static <T> T deserialize(byte[] bytes)
public static <T> T deserialize(byte[] bytes, ClassLoader loader)
public static long deserializeLongValue(byte[] bytes)
PythonPartitioner
)public static void serializeViaNestedStream(java.io.OutputStream os, SerializerInstance ser, scala.Function1<SerializationStream,scala.runtime.BoxedUnit> f)
public static void deserializeViaNestedStream(java.io.InputStream is, SerializerInstance ser, scala.Function1<DeserializationStream,scala.runtime.BoxedUnit> f)
public static ClassLoader getSparkClassLoader()
public static ClassLoader getContextOrSparkClassLoader()
This should be used whenever passing a ClassLoader to Class.ForName or finding the currently active loader when setting up ClassLoader delegation chains.
public static boolean classIsLoadable(String clazz)
public static Class<?> classForName(String className)
public static void writeByteBuffer(java.nio.ByteBuffer bb, java.io.DataOutput out)
ByteBuffer
to DataOutput
bb
- (undocumented)out
- (undocumented)public static void writeByteBuffer(java.nio.ByteBuffer bb, java.io.OutputStream out)
ByteBuffer
to OutputStream
bb
- (undocumented)out
- (undocumented)public static boolean chmod700(java.io.File file)
chmod 700 file
.
file
- the file whose permissions will be modifiedpublic static java.io.File createDirectory(String root, String namePrefix)
root
- (undocumented)namePrefix
- (undocumented)public static java.io.File createTempDir(String root, String namePrefix)
root
- (undocumented)namePrefix
- (undocumented)public static long copyStream(java.io.InputStream in, java.io.OutputStream out, boolean closeStreams, boolean transferToEnabled)
in
- (undocumented)out
- (undocumented)closeStreams
- (undocumented)transferToEnabled
- (undocumented)public static void copyFileStreamNIO(java.nio.channels.FileChannel input, java.nio.channels.FileChannel output, long startPosition, long bytesToCopy)
public static java.net.URI constructURIForAuthentication(java.net.URI uri, org.apache.spark.SecurityManager securityMgr)
Note this relies on the Authenticator.setDefault being set properly to decode the user name and password. This is currently set in the SecurityManager.
uri
- (undocumented)securityMgr
- (undocumented)public static String encodeFileNameToURIRawPath(String fileName)
java.net.URI(String)
.
Note: the file name must not contain "/" or "\"
fileName
- (undocumented)public static String decodeFileNameInURI(java.net.URI uri)
uri
- (undocumented)public static void fetchFile(String url, java.io.File targetDir, SparkConf conf, org.apache.spark.SecurityManager securityMgr, org.apache.hadoop.conf.Configuration hadoopConf, long timestamp, boolean useCache)
If useCache
is true, first attempts to fetch the file to a local cache that's shared
across executors running the same application. useCache
is used mainly for
the executors, and not in local mode.
Throws SparkException if the target file already exists and has different contents than the requested file.
url
- (undocumented)targetDir
- (undocumented)conf
- (undocumented)securityMgr
- (undocumented)hadoopConf
- (undocumented)timestamp
- (undocumented)useCache
- (undocumented)public static void validateURL(java.net.URI uri) throws java.net.MalformedURLException
uri
- The URI to validatejava.net.MalformedURLException
public static String getLocalDir(SparkConf conf)
- If called from inside of a YARN container, this will return a directory chosen by YARN. - If the SPARK_LOCAL_DIRS environment variable is set, this will return a directory from it. - Otherwise, if the spark.local.dir is set, this will return a directory from it. - Otherwise, this will return java.io.tmpdir.
Some of these configuration options might be lists of multiple paths, but this method will always return a single directory.
conf
- (undocumented)public static String[] getConfiguredLocalDirs(SparkConf conf)
conf
- (undocumented)public static <T> scala.collection.Seq<T> randomize(scala.collection.TraversableOnce<T> seq, scala.reflect.ClassTag<T> evidence$1)
seq
- (undocumented)evidence$1
- (undocumented)public static <T> Object randomizeInPlace(Object arr, java.util.Random rand)
arr
- (undocumented)rand
- (undocumented)public static void setCustomHostname(String hostname)
hostname
- (undocumented)public static String localHostName()
public static String localHostNameForURI()
public static void checkHost(String host, String message)
public static void checkHostPort(String hostPort, String message)
public static scala.Tuple2<String,Object> parseHostPort(String hostPort)
public static String getUsedTimeMs(long startTimeMs)
startTimeMs
- (undocumented)public static void deleteRecursively(java.io.File file)
file
- (undocumented)public static boolean isSymlink(java.io.File file)
file
- (undocumented)public static boolean doesDirectoryContainAnyNewFiles(java.io.File dir, long cutoff)
dir
- must be the path to a directory, or IllegalArgumentException is throwncutoff
- measured in seconds. Returns true if there are any files or directories in the
given directory whose last modified time is later than this many seconds agopublic static long timeStringAsMs(String str)
str
- (undocumented)public static long timeStringAsSeconds(String str)
str
- (undocumented)public static long byteStringAsBytes(String str)
If no suffix is provided, the passed number is assumed to be in bytes.
str
- (undocumented)public static long byteStringAsKb(String str)
If no suffix is provided, the passed number is assumed to be in kibibytes.
str
- (undocumented)public static long byteStringAsMb(String str)
If no suffix is provided, the passed number is assumed to be in mebibytes.
str
- (undocumented)public static long byteStringAsGb(String str)
If no suffix is provided, the passed number is assumed to be in gibibytes.
str
- (undocumented)public static int memoryStringToMb(String str)
str
- (undocumented)public static String bytesToString(long size)
size
- (undocumented)public static String bytesToString(scala.math.BigInt size)
public static String msDurationToString(long ms)
ms
- (undocumented)public static String megabytesToString(long megabytes)
megabytes
- (undocumented)public static Process executeCommand(scala.collection.Seq<String> command, java.io.File workingDir, scala.collection.Map<String,String> extraEnvironment, boolean redirectStderr)
command
- (undocumented)workingDir
- (undocumented)extraEnvironment
- (undocumented)redirectStderr
- (undocumented)public static String executeAndGetOutput(scala.collection.Seq<String> command, java.io.File workingDir, scala.collection.Map<String,String> extraEnvironment, boolean redirectStderr)
command
- (undocumented)workingDir
- (undocumented)extraEnvironment
- (undocumented)redirectStderr
- (undocumented)public static Thread processStreamByLine(String threadName, java.io.InputStream inputStream, scala.Function1<String,scala.runtime.BoxedUnit> processLine)
threadName
- (undocumented)inputStream
- (undocumented)processLine
- (undocumented)public static void tryOrExit(scala.Function0<scala.runtime.BoxedUnit> block)
NOTE: This method is to be called by the spark-started JVM process.
block
- (undocumented)public static void tryOrStopSparkContext(SparkContext sc, scala.Function0<scala.runtime.BoxedUnit> block)
NOTE: This method is to be called by the driver-side components to avoid stopping the user-started JVM process completely; in contrast, tryOrExit is to be called in the spark-started JVM process .
sc
- (undocumented)block
- (undocumented)public static <T> T tryOrIOException(scala.Function0<T> block)
block
- (undocumented)public static void tryLogNonFatalError(scala.Function0<scala.runtime.BoxedUnit> block)
public static <T> T tryWithSafeFinally(scala.Function0<T> block, scala.Function0<scala.runtime.BoxedUnit> finallyBlock)
This is primarily an issue with finally { out.close() }
blocks, where
close needs to be called to clean up out
, but if an exception happened
in out.write
, it's likely out
may be corrupted and out.close
will
fail as well. This would then suppress the original/likely more meaningful
exception from the original out.write
call.
block
- (undocumented)finallyBlock
- (undocumented)public static <T> T tryWithSafeFinallyAndFailureCallbacks(scala.Function0<T> block, scala.Function0<scala.runtime.BoxedUnit> catchBlock, scala.Function0<scala.runtime.BoxedUnit> finallyBlock)
This is primarily an issue with catch { abort() }
or finally { out.close() }
blocks,
where the abort/close needs to be called to clean up out
, but if an exception happened
in out.write
, it's likely out
may be corrupted and abort
or out.close
will
fail as well. This would then suppress the original/likely more meaningful
exception from the original out.write
call.
block
- (undocumented)catchBlock
- (undocumented)finallyBlock
- (undocumented)public static org.apache.spark.util.CallSite getCallSite(scala.Function1<String,Object> skipClass)
skipClass
- Function that is used to exclude non-user-code classes.public static long getFileLength(java.io.File file, SparkConf workConf)
file
- (undocumented)workConf
- (undocumented)public static String offsetBytes(String path, long length, long start, long end)
public static String offsetBytes(scala.collection.Seq<java.io.File> files, scala.collection.Seq<Object> fileLengths, long start, long end)
startIndex
and endIndex
is based on the cumulative size of all the files take in
the given order. See figure below for more details.files
- (undocumented)fileLengths
- (undocumented)start
- (undocumented)end
- (undocumented)public static <T> T clone(T value, SerializerInstance serializer, scala.reflect.ClassTag<T> evidence$2)
value
- (undocumented)serializer
- (undocumented)evidence$2
- (undocumented)public static scala.collection.Seq<String> splitCommandString(String s)
s
- (undocumented)public static int nonNegativeMod(int x, int mod)
public static int nonNegativeHash(Object obj)
public static int nanSafeCompareDoubles(double x, double y)
java.lang.Double.compare()
which allows NaN values to be compared
according to semantics where NaN == NaN and NaN is greater than any non-NaN double.x
- (undocumented)y
- (undocumented)public static int nanSafeCompareFloats(float x, float y)
java.lang.Float.compare()
which allows NaN values to be compared
according to semantics where NaN == NaN and NaN is greater than any non-NaN float.x
- (undocumented)y
- (undocumented)public static scala.collection.Map<String,String> getSystemProperties()
public static void times(int numIters, scala.Function0<scala.runtime.BoxedUnit> f)
numIters
- (undocumented)f
- (undocumented)public static long timeIt(int numIters, scala.Function0<scala.runtime.BoxedUnit> f, scala.Option<scala.Function0<scala.runtime.BoxedUnit>> prepare)
numIters
- number of iterationsf
- function to be executed. If prepare is not None, the running time of each call to f
must be an order of magnitude longer than one millisecond for accurate timing.prepare
- function to be executed before each call to f. Its running time doesn't count.public static <T> long getIteratorSize(scala.collection.Iterator<T> iterator)
TraversableOnce.size()
because it uses a for loop, which is slightly slower
in the current version of Scala.iterator
- (undocumented)public static <T> scala.collection.Iterator<scala.Tuple2<T,Object>> getIteratorZipWithIndex(scala.collection.Iterator<T> iterator, long startIndex)
iterator
- (undocumented)startIndex
- (undocumented)public static void symlink(java.io.File src, java.io.File dst)
src
- absolute path to the sourcedst
- relative path for the destinationpublic static String getFormattedClassName(Object obj)
public static scala.Option<org.json4s.JsonAST.JValue> jsonOption(org.json4s.JsonAST.JValue json)
public static org.json4s.JsonAST.JObject emptyJson()
public static org.apache.hadoop.fs.FileSystem getHadoopFileSystem(java.net.URI path, org.apache.hadoop.conf.Configuration conf)
path
- (undocumented)conf
- (undocumented)public static org.apache.hadoop.fs.FileSystem getHadoopFileSystem(String path, org.apache.hadoop.conf.Configuration conf)
path
- (undocumented)conf
- (undocumented)public static org.apache.hadoop.fs.Path getFilePath(java.io.File dir, String fileName)
dir
- (undocumented)fileName
- (undocumented)public static boolean isWindows()
public static boolean isMac()
public static scala.util.matching.Regex windowsDrive()
public static boolean isTesting()
public static String stripDirectory(String path)
path
- (undocumented)public static scala.Option<Object> terminateProcess(Process process, long timeoutMs)
process
- (undocumented)timeoutMs
- (undocumented)public static scala.Option<String> getStderr(Process process, long timeoutMs)
process
- (undocumented)timeoutMs
- (undocumented)public static <T> T logUncaughtExceptions(scala.Function0<T> f)
f
- (undocumented)public static <T> scala.util.Try<T> tryLog(scala.Function0<T> f)
public static boolean isFatalError(Throwable e)
public static java.net.URI resolveURI(String path)
If the supplied path does not contain a scheme, or is a relative path, it will be converted into an absolute path with a file:// scheme.
path
- (undocumented)public static String resolveURIs(String paths)
public static String[] nonLocalPaths(String paths, boolean testWindows)
public static String loadDefaultSparkProperties(SparkConf conf, String filePath)
conf
- (undocumented)filePath
- (undocumented)public static void updateSparkConfigFromProperties(SparkConf conf, scala.collection.Map<String,String> properties)
conf
- (undocumented)properties
- (undocumented)public static scala.collection.Map<String,String> getPropertiesFromFile(String filename)
public static String getDefaultPropertiesFile(scala.collection.Map<String,String> env)
public static String exceptionString(Throwable e)
e
- (undocumented)public static org.apache.spark.util.ThreadStackTrace[] getThreadDump()
public static scala.Option<org.apache.spark.util.ThreadStackTrace> getThreadDumpForThread(long threadId)
public static scala.collection.Seq<String> sparkJavaOpts(SparkConf conf, scala.Function1<String,Object> filterKey)
conf
- (undocumented)filterKey
- (undocumented)public static int portMaxRetries(SparkConf conf)
conf
- (undocumented)public static int userPort(int base, int offset)
base
- (undocumented)offset
- (undocumented)public static <T> scala.Tuple2<T,Object> startServiceOnPort(int startPort, scala.Function1<Object,scala.Tuple2<T,Object>> startService, SparkConf conf, String serviceName)
startPort
- The initial port to start the service on.startService
- Function to start service on a given port.
This is expected to throw java.net.BindException on port collision.conf
- A SparkConf used to get the maximum number of retries when binding to a port.serviceName
- Name of the service.public static boolean isBindCollision(Throwable exception)
exception
- (undocumented)public static void setLogLevel(org.apache.log4j.Level l)
l
- (undocumented)public static void configTestLog4j(String level)
level
- (undocumented)public static java.net.URLConnection setupSecureURLConnection(java.net.URLConnection urlConnection, org.apache.spark.SecurityManager sm)
urlConnection
- (undocumented)sm
- (undocumented)public static Object invoke(Class<?> clazz, Object obj, String methodName, scala.collection.Seq<scala.Tuple2<Class<?>,Object>> args)
public static long getMaxResultSize(SparkConf conf)
public static String libraryPathEnvName()
public static String libraryPathEnvPrefix(scala.collection.Seq<String> libraryPaths)
libraryPaths
- (undocumented)public static String getSparkOrYarnConfig(SparkConf conf, String key, String default_)
conf
- (undocumented)key
- (undocumented)default_
- (undocumented)public static scala.Tuple2<String,Object> extractHostPortFromSparkUrl(String sparkUrl) throws SparkException
sparkUrl
.
A spark url (spark://host:port
) is a special URI that its scheme is spark
and only contains
host and port.
sparkUrl
- (undocumented)SparkException
- if sparkUrl is invalid.public static String getCurrentUserName()
SPARK_USER
environment variable.public static scala.collection.immutable.Set<String> EMPTY_USER_GROUPS()
public static scala.collection.immutable.Set<String> getCurrentUserGroups(SparkConf sparkConf, String username)
public static String[] parseStandaloneMasterUrls(String masterUrls)
masterUrls
- (undocumented)public static String BACKUP_STANDALONE_MASTER_PREFIX()
public static boolean responseFromBackup(String msg)
public static <T> T withDummyCallSite(SparkContext sc, scala.Function0<T> body)
Utils.getCallSite
for every single RDD we create in the body,
set a dummy call site that RDDs use instead. This is for performance optimization.sc
- (undocumented)body
- (undocumented)public static boolean isInDirectory(java.io.File parent, java.io.File child)
parent
- (undocumented)child
- (undocumented)public static boolean isLocalMaster(SparkConf conf)
conf
- (undocumented)public static boolean isDynamicAllocationEnabled(SparkConf conf)
conf
- (undocumented)public static int getDynamicAllocationInitialExecutors(SparkConf conf)
conf
- (undocumented)public static <R extends java.io.Closeable,T> T tryWithResource(scala.Function0<R> createResource, scala.Function1<R,T> f)
public static java.io.File tempFileWith(java.io.File path)
path
.path
- (undocumented)public static String getProcessName()
public static void initDaemon(org.slf4j.Logger log)
main()
for daemons to set up some common
diagnostic state.log
- (undocumented)public static scala.collection.immutable.Set<String> unionFileLists(scala.Option<String> leftList, scala.Option<String> rightList)
leftList
- (undocumented)rightList
- (undocumented)public static scala.collection.Seq<String> getUserJars(SparkConf conf)
conf
- (undocumented)public static scala.collection.Seq<String> getLocalUserJarsForShell(SparkConf conf)
conf
- (undocumented)public static scala.collection.Seq<scala.Tuple2<String,String>> redact(SparkConf conf, scala.collection.Seq<scala.Tuple2<String,String>> kvs)
conf
- (undocumented)kvs
- (undocumented)public static String redact(SparkConf conf, String text)
conf
- (undocumented)text
- (undocumented)public static scala.collection.Seq<scala.Tuple2<String,String>> redact(scala.Option<scala.util.matching.Regex> regex, scala.collection.Seq<scala.Tuple2<String,String>> kvs)
regex
- (undocumented)kvs
- (undocumented)public static scala.collection.Seq<scala.Tuple2<String,String>> redact(scala.collection.Map<String,String> kvs)
kvs
- (undocumented)public static String createSecret(SparkConf conf)