Modifier and Type | Class and Description |
---|---|
static class |
Utils.SmartThread
A thread that can answer if it is sleeping in the case of simulated time.
|
static class |
Utils.UptimeComputer |
Modifier and Type | Field and Description |
---|---|
static String |
CLASS_PATH_SEPARATOR |
static String |
CURRENT_BLOB_SUFFIX_ID |
static String |
DEFAULT_BLOB_VERSION_SUFFIX |
static String |
DEFAULT_CURRENT_BLOB_SUFFIX |
static String |
DEFAULT_STREAM_ID |
static String |
FILE_PATH_SEPARATOR |
static boolean |
IS_ON_WINDOWS |
static org.slf4j.Logger |
LOG |
static int |
SIGKILL |
static int |
SIGTERM |
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static void |
addShutdownHookWithForceKillIn1Sec(Runnable func)
Adds the user supplied function as a shutdown hook for cleanup.
|
static String |
addToClasspath(Collection<String> classpaths,
Collection<String> paths) |
static String |
addToClasspath(String classpath,
Collection<String> paths) |
String |
addToClasspathImpl(Collection<String> classpaths,
Collection<String> paths) |
String |
addToClasspathImpl(String classpath,
Collection<String> paths) |
static StormTopology |
addVersions(StormTopology topology)
Add version information to the given topology
|
static Utils.SmartThread |
asyncLoop(Callable afn)
Convenience method used when only the function is given.
|
static Utils.SmartThread |
asyncLoop(Callable afn,
boolean isDaemon,
Thread.UncaughtExceptionHandler eh,
int priority,
boolean isFactory,
boolean startImmediately,
String threadName)
Creates a thread that calls the given code repeatedly, sleeping for an interval of seconds equal to the return value of the previous call.
|
static Utils.SmartThread |
asyncLoop(Callable afn,
String threadName,
Thread.UncaughtExceptionHandler eh)
Convenience method used when only the function and name suffix are given.
|
static long |
bitXor(Long a,
Long b) |
static long |
bitXorVals(List<Long> coll) |
static boolean |
canUserReadBlob(ReadableBlobMeta meta,
String user) |
static boolean |
CheckDirExists(String dir) |
static boolean |
checkFileExists(File path) |
static boolean |
checkFileExists(String path) |
static boolean |
checkFileExists(String dir,
String file) |
static String |
constructBlobCurrentSymlinkName(String fileName) |
static String |
constructBlobWithVersionFileName(String fileName,
long version) |
static String |
constructVersionFileName(String fileName) |
static String |
containerFilePath(String dir) |
static Map<String,Object> |
convertClojureMapToJavaMap(Map map)
converts a clojure PersistentMap to java HashMap
|
static Localizer |
createLocalizer(Map conf,
String baseDir) |
static String |
currentClasspath()
Returns the value of java.class.path System property.
|
String |
currentClasspathImpl() |
static <T> T |
deserialize(byte[] serialized,
Class<T> clazz) |
static void |
downloadResourcesAsSupervisor(String key,
String localFile,
ClientBlobStore cb)
Meant to be called only by the supervisor for stormjar/stormconf/stormcode files.
|
void |
downloadResourcesAsSupervisorImpl(String key,
String localFile,
ClientBlobStore cb) |
static String |
eventLogsFilename(String stormId,
String port) |
static boolean |
exceptionCauseIsInstanceOf(Class klass,
Throwable throwable)
Checks if a throwable is an instance of a particular class
|
static int |
execCommand(String... command) |
static void |
exitProcess(int val,
String msg) |
static void |
extractDirFromJar(String jarpath,
String dir,
File destdir)
Extract dir from the jar to destdir
|
void |
extractDirFromJarImpl(String jarpath,
String dir,
File destdir) |
static Map<String,Object> |
findAndReadConfigFile(String name) |
static Map<String,Object> |
findAndReadConfigFile(String name,
boolean mustExist) |
static List<URL> |
findResources(String name) |
static void |
forceDelete(String path)
Deletes a file or directory and its contents if it exists.
|
protected void |
forceDeleteImpl(String path) |
static void |
forceKillProcess(String pid) |
static Map<String,Object> |
fromCompressedJsonConf(byte[] serialized) |
static <S,T> T |
get(Map<S,T> m,
S key,
T def) |
static int |
getAvailablePort() |
static int |
getAvailablePort(int prefferedPort) |
static boolean |
getBoolean(Object o,
boolean defaultValue) |
static ClientBlobStore |
getClientBlobStore(Map conf) |
static ClientBlobStore |
getClientBlobStoreForSupervisor(Map conf) |
static ComponentCommon |
getComponentCommon(StormTopology topology,
String id) |
static Object |
getConfiguredClass(Map conf,
Object configKey)
Return a new instance of a pluggable specified in the conf.
|
static Double |
getDouble(Object o) |
static Double |
getDouble(Object o,
Double defaultValue) |
static long |
getDU(File dir)
Takes an input dir or file and returns the disk usage on that local directory.
|
static String |
getFileOwner(String path) |
static GlobalStreamId |
getGlobalStreamId(String componentId,
String streamId) |
static Integer |
getInt(Object o) |
static Integer |
getInt(Object o,
Integer defaultValue) |
static BlobStore |
getNimbusBlobStore(Map conf,
NimbusInfo nimbusInfo) |
static BlobStore |
getNimbusBlobStore(Map conf,
String baseDir,
NimbusInfo nimbusInfo) |
static List<String> |
getRepeat(List<String> list) |
static Object |
getSetComponentObject(ComponentObject obj) |
static String |
getString(Object o) |
static String |
getString(Object o,
String defaultValue) |
static List<String> |
getStrings(Object o) |
static org.apache.zookeeper.data.ACL |
getSuperUserAcl(Map<String,Object> conf)
Get the ACL for nimbus/supervisor.
|
static String |
getTopologyId(String name,
Nimbus.Client client) |
static TopologyInfo |
getTopologyInfo(String name,
String asUser,
Map stormConf) |
static List<org.apache.zookeeper.data.ACL> |
getWorkerACL(Map<String,Object> conf)
Get the ZK ACLs that a worker should use when writing to ZK.
|
static byte[] |
gunzip(byte[] data) |
static byte[] |
gzip(byte[] data) |
static void |
handleUncaughtException(Throwable t) |
static String |
hostname()
Gets the storm.local.hostname value, or tries to figure out the local hostname if it is not set in the config.
|
protected String |
hostnameImpl() |
static TreeMap<Integer,Integer> |
integerDivided(int sum,
int numPieces) |
static <T> List<T> |
interleaveAll(List<List<T>> nodeList) |
static boolean |
isAbsolutePath(String path) |
static boolean |
isOnWindows() |
static boolean |
isSystemId(String id) |
static boolean |
isValidConf(Map<String,Object> stormConf) |
static boolean |
isValidKey(String key)
Validates topology name / blob key.
|
static boolean |
isZkAuthenticationConfiguredStormServer(Map conf)
Is the cluster configured to interact with ZooKeeper in a secure way? This only works when called from within Nimbus or a Supervisor process.
|
static boolean |
isZkAuthenticationConfiguredTopology(Map conf)
Is the topology configured to have ZooKeeper authentication.
|
static JarTransformer |
jarTransformer(String klass) |
static <T> T |
javaDeserialize(byte[] serialized,
Class<T> clazz) |
static byte[] |
javaSerialize(Object obj) |
static <T> String |
join(Iterable<T> coll,
String sep) |
static <K,V> Map<K,List<V>> |
joinMaps(Map<K,V>... maps)
Joins any number of maps together into a single map, combining their values into a list, maintaining values in the order the maps were passed in.
|
static void |
killProcessWithSigTerm(String pid) |
static clojure.lang.IFn |
loadClojureFn(String namespace,
String name) |
static String |
localHostname() |
protected String |
localHostnameImpl() |
static long |
localVersionOfBlob(String localFile) |
static String |
logsFilename(String stormId,
String port) |
static Utils.UptimeComputer |
makeUptimeComputer() |
Utils.UptimeComputer |
makeUptimeComputerImpl() |
static String |
memoizedLocalHostname() |
static Runnable |
mkSuicideFn() |
static org.apache.curator.framework.CuratorFramework |
newCurator(Map conf,
List<String> servers,
Object port,
String root,
List<org.apache.zookeeper.data.ACL> defaultAcl) |
static org.apache.curator.framework.CuratorFramework |
newCurator(Map conf,
List<String> servers,
Object port,
String root,
ZookeeperAuthInfo auth,
List<org.apache.zookeeper.data.ACL> defaultAcl) |
static org.apache.curator.framework.CuratorFramework |
newCurator(Map conf,
List<String> servers,
Object port,
ZookeeperAuthInfo auth,
List<org.apache.zookeeper.data.ACL> defaultAcl) |
static org.apache.curator.framework.CuratorFramework |
newCuratorStarted(Map conf,
List<String> servers,
Object port,
String root,
ZookeeperAuthInfo auth,
List<org.apache.zookeeper.data.ACL> defaultAcl) |
static org.apache.curator.framework.CuratorFramework |
newCuratorStarted(Map conf,
List<String> servers,
Object port,
ZookeeperAuthInfo auth,
List<org.apache.zookeeper.data.ACL> defaultAcl) |
static <T> T |
newInstance(Class<T> klass) |
static <T> T |
newInstance(String klass) |
<T> T |
newInstanceImpl(Class<T> klass) |
static long |
nimbusVersionOfBlob(String key,
ClientBlobStore cb) |
static Object |
nullToZero(Object v) |
static <V> V |
OR(V a,
V b)
a or b the first one that is not null
|
static Double |
parseJvmHeapMemByChildOpts(List<String> options,
Double defaultValue)
parses the arguments to extract jvm heap memory size in MB.
|
static org.apache.zookeeper.data.Id |
parseZkId(String id,
String configName) |
static <T> List<List<T>> |
partitionFixed(int maxNumChunks,
Collection<T> coll)
Fills up chunks out of a collection (given a maximum amount of chunks)
|
static String |
processPid() |
static void |
readAndLogStream(String prefix,
InputStream in) |
static Map<String,Object> |
readCommandLineOpts() |
static Map<String,Object> |
readDefaultConfig() |
static Collection<String> |
readDirContents(String dir)
Returns a Collection of file names found under the given directory.
|
static Map<String,Object> |
readStormConfig() |
static Object |
readYamlFile(String yamlFile) |
static Map<Object,String> |
redactValue(Map<Object,String> m,
Object key)
Creates a new map with a string value in the map replaced with an equivalently-lengthed string of ‘#’.
|
static void |
resetClassLoaderForJavaDeSerialize() |
static void |
restrictPermissions(String baseDir) |
static HashMap |
reverseMap(List listSeq)
“[[:a 1] [:b 1] [:c 2]} -> {1 [:a :b] 2 :c}” Reverses an assoc-list style Map like reverseMap(Map…)
|
static <K,V> HashMap<V,List<K>> |
reverseMap(Map<K,V> map)
“{:a 1 :b 1 :c 2} -> {1 [:a :b] 2 :c}”
|
static String |
scriptFilePath(String dir) |
static long |
secureRandomLong() |
static void |
sendSignalToProcess(long lpid,
int signum) |
static byte[] |
serialize(Object obj) |
static void |
setClassLoaderForJavaDeSerialize(ClassLoader cl) |
static Utils |
setInstance(Utils u)
Provide an instance of this class for delegates to use.
|
protected static void |
setupBuilder(org.apache.curator.framework.CuratorFrameworkFactory.Builder builder,
String zkStr,
Map conf,
ZookeeperAuthInfo auth) |
static void |
setupDefaultUncaughtExceptionHandler() |
static String |
shellCmd(List<String> command)
Returns the combined string, escaped for posix shell.
|
static void |
sleep(long millis) |
static void |
testSetupBuilder(org.apache.curator.framework.CuratorFrameworkFactory.Builder builder,
String zkStr,
Map conf,
ZookeeperAuthInfo auth) |
static String |
threadDump()
Gets some information, including stack trace, for a running thread.
|
static <T> T |
thriftDeserialize(Class<T> c,
byte[] b) |
static <T> T |
thriftDeserialize(Class<T> c,
byte[] b,
int offset,
int length) |
static byte[] |
thriftSerialize(org.apache.thrift.TBase t) |
static byte[] |
toByteArray(ByteBuffer buffer) |
static byte[] |
toCompressedJsonConf(Map<String,Object> stormConf) |
static int |
toPositive(int number)
A cheap way to deterministically convert a number to a positive value.
|
static List<Object> |
tuple(Object... values) |
static void |
unJar(File jarFile,
File toDir)
Unpack matching files from a jar.
|
static void |
unpack(File localrsrc,
File dst,
boolean symLinksDisabled) |
static void |
unTar(File inFile,
File untarDir,
boolean symlinksDisabled)
Given a Tar File as input it will untar the file in a the untar directory passed as the second parameter This utility will untar “.tar” files and “.tar.gz”,“tgz” files.
|
static void |
unZip(File inFile,
File toDir)
Given a File input it will unzip the file in a the unzip directory passed as the second parameter
|
static String |
uuid() |
static void |
validateKeyName(String name) |
static void |
validateTopologyBlobStoreMap(Map<String,?> stormConf,
Set<String> blobStoreKeys) |
static RuntimeException |
wrapInRuntime(Exception e) |
static String |
writeScript(String dir,
List<String> command,
Map<String,String> environment)
Writes a posix shell script file to be executed in its own process.
|
static double |
zeroIfNaNOrInf(double x) |
static boolean |
zipDoesContainDir(String zipfile,
String target)
Determines if a zip archive contains a particular directory.
|
static long |
zipFileSize(File myFile)
Given a zip File input it will return its size Only works for zip files whose uncompressed size is less than 4 GB, otherwise returns the size module 2^32, per gzip specifications
|
public static final org.slf4j.Logger LOG
public static final String DEFAULT_STREAM_ID
public static final String DEFAULT_BLOB_VERSION_SUFFIX
public static final String CURRENT_BLOB_SUFFIX_ID
public static final String DEFAULT_CURRENT_BLOB_SUFFIX
public static final boolean IS_ON_WINDOWS
public static final String FILE_PATH_SEPARATOR
public static final String CLASS_PATH_SEPARATOR
public static final int SIGKILL
public static final int SIGTERM
public static Utils setInstance(Utils u)
Provide an instance of this class for delegates to use. To mock out delegated methods, provide an instance of a subclass that overrides the implementation of the delegated method.
u
- a Utils instancepublic static <T> T newInstance(String klass)
public static <T> T newInstance(Class<T> klass)
public <T> T newInstanceImpl(Class<T> klass)
public static JarTransformer jarTransformer(String klass)
public static byte[] serialize(Object obj)
public static <T> T deserialize(byte[] serialized, Class<T> clazz)
public static <T> T thriftDeserialize(Class<T> c, byte[] b, int offset, int length)
public static byte[] javaSerialize(Object obj)
public static <T> T javaDeserialize(byte[] serialized, Class<T> clazz)
public static byte[] gzip(byte[] data)
public static byte[] gunzip(byte[] data)
public static void sleep(long millis)
public static Map<String,Object> findAndReadConfigFile(String name, boolean mustExist)
public static Object getSetComponentObject(ComponentObject obj)
public static <S,T> T get(Map<S,T> m, S key, T def)
public static ClientBlobStore getClientBlobStoreForSupervisor(Map conf)
public static BlobStore getNimbusBlobStore(Map conf, NimbusInfo nimbusInfo)
public static BlobStore getNimbusBlobStore(Map conf, String baseDir, NimbusInfo nimbusInfo)
public static void downloadResourcesAsSupervisor(String key, String localFile, ClientBlobStore cb) throws AuthorizationException, KeyNotFoundException, IOException
Meant to be called only by the supervisor for stormjar/stormconf/stormcode files.
key
- localFile
- cb
- AuthorizationException
KeyNotFoundException
IOException
public void downloadResourcesAsSupervisorImpl(String key, String localFile, ClientBlobStore cb) throws AuthorizationException, KeyNotFoundException, IOException
public static ClientBlobStore getClientBlobStore(Map conf)
public static boolean checkFileExists(File path)
public static boolean checkFileExists(String path)
public static boolean CheckDirExists(String dir)
public static long nimbusVersionOfBlob(String key, ClientBlobStore cb) throws AuthorizationException, KeyNotFoundException
public static String getFileOwner(String path) throws IOException
IOException
public static long localVersionOfBlob(String localFile)
public static String constructBlobWithVersionFileName(String fileName, long version)
public static String constructBlobCurrentSymlinkName(String fileName)
public static void restrictPermissions(String baseDir)
public static boolean isSystemId(String id)
public static ComponentCommon getComponentCommon(StormTopology topology, String id)
public static byte[] thriftSerialize(org.apache.thrift.TBase t)
public static <T> T thriftDeserialize(Class<T> c, byte[] b)
public static boolean getBoolean(Object o, boolean defaultValue)
public static long secureRandomLong()
public static void unJar(File jarFile, File toDir) throws IOException
Unpack matching files from a jar. Entries inside the jar that do not match the given pattern will be skipped.
jarFile
- the .jar file to unpacktoDir
- the destination directory into which to unpack the jarIOException
public static void unTar(File inFile, File untarDir, boolean symlinksDisabled) throws IOException
Given a Tar File as input it will untar the file in a the untar directory passed as the second parameter
This utility will untar “.tar” files and “.tar.gz”,“tgz” files.inFile
- The tar file as input.untarDir
- The untar directory where to untar the tar file.symlinksDisabled
- true if symlinks should be disabled, else false.IOException
public static boolean isOnWindows()
public static boolean isAbsolutePath(String path)
public static void unpack(File localrsrc, File dst, boolean symLinksDisabled) throws IOException
IOException
public static boolean canUserReadBlob(ReadableBlobMeta meta, String user)
public static org.apache.curator.framework.CuratorFramework newCurator(Map conf, List<String> servers, Object port, String root, List<org.apache.zookeeper.data.ACL> defaultAcl)
public static org.apache.curator.framework.CuratorFramework newCurator(Map conf, List<String> servers, Object port, ZookeeperAuthInfo auth, List<org.apache.zookeeper.data.ACL> defaultAcl)
public static org.apache.curator.framework.CuratorFramework newCurator(Map conf, List<String> servers, Object port, String root, ZookeeperAuthInfo auth, List<org.apache.zookeeper.data.ACL> defaultAcl)
protected static void setupBuilder(org.apache.curator.framework.CuratorFrameworkFactory.Builder builder, String zkStr, Map conf, ZookeeperAuthInfo auth)
public static void testSetupBuilder(org.apache.curator.framework.CuratorFrameworkFactory.Builder builder, String zkStr, Map conf, ZookeeperAuthInfo auth)
public static org.apache.curator.framework.CuratorFramework newCuratorStarted(Map conf, List<String> servers, Object port, String root, ZookeeperAuthInfo auth, List<org.apache.zookeeper.data.ACL> defaultAcl)
public static org.apache.curator.framework.CuratorFramework newCuratorStarted(Map conf, List<String> servers, Object port, ZookeeperAuthInfo auth, List<org.apache.zookeeper.data.ACL> defaultAcl)
public static byte[] toByteArray(ByteBuffer buffer)
public static void readAndLogStream(String prefix, InputStream in)
public static boolean exceptionCauseIsInstanceOf(Class klass, Throwable throwable)
Checks if a throwable is an instance of a particular class
klass
- The class you’re expectingthrowable
- The throwable you expect to be an instance of klasspublic static boolean isZkAuthenticationConfiguredStormServer(Map conf)
Is the cluster configured to interact with ZooKeeper in a secure way? This only works when called from within Nimbus or a Supervisor process.
conf
- the storm configuration, not the topology configurationpublic static boolean isZkAuthenticationConfiguredTopology(Map conf)
Is the topology configured to have ZooKeeper authentication.
conf
- the topology configurationpublic static org.apache.zookeeper.data.ACL getSuperUserAcl(Map<String,Object> conf)
Get the ACL for nimbus/supervisor. The Super User ACL. This assumes that security is enabled.
conf
- the config to get the super User ACL frompublic static List<org.apache.zookeeper.data.ACL> getWorkerACL(Map<String,Object> conf)
Get the ZK ACLs that a worker should use when writing to ZK.
conf
- the config for the topology.public static long getDU(File dir)
Takes an input dir or file and returns the disk usage on that local directory. Very basic implementation.
dir
- The input dir to get the disk space of this local dirpublic static String threadDump()
Gets some information, including stack trace, for a running thread.
public static void handleUncaughtException(Throwable t)
public static void validateTopologyBlobStoreMap(Map<String,?> stormConf, Set<String> blobStoreKeys) throws InvalidTopologyException
InvalidTopologyException
public static void unZip(File inFile, File toDir) throws IOException
Given a File input it will unzip the file in a the unzip directory passed as the second parameter
inFile
- The zip file as inputtoDir
- The unzip directory where to unzip the zip file.IOException
public static long zipFileSize(File myFile) throws IOException
Given a zip File input it will return its size Only works for zip files whose uncompressed size is less than 4 GB, otherwise returns the size module 2^32, per gzip specifications
myFile
- The zip file as inputIOException
public static double zeroIfNaNOrInf(double x)
public static Double parseJvmHeapMemByChildOpts(List<String> options, Double defaultValue)
parses the arguments to extract jvm heap memory size in MB.
input
- defaultValue
- public static void setClassLoaderForJavaDeSerialize(ClassLoader cl)
public static void resetClassLoaderForJavaDeSerialize()
public static TopologyInfo getTopologyInfo(String name, String asUser, Map stormConf)
public static String getTopologyId(String name, Nimbus.Client client)
public static int toPositive(int number)
A cheap way to deterministically convert a number to a positive value. When the input is positive, the original value is returned. When the input number is negative, the returned positive value is the original value bit AND against Integer.MAX_VALUE(0x7fffffff) which is not its absolutely value.
number
- a given numberpublic static GlobalStreamId getGlobalStreamId(String componentId, String streamId)
public static RuntimeException wrapInRuntime(Exception e)
public static int getAvailablePort(int prefferedPort)
public static int getAvailablePort()
public static boolean zipDoesContainDir(String zipfile, String target) throws IOException
Determines if a zip archive contains a particular directory.
zipfile
- path to the zipped filetarget
- directory being looked for in the zip.IOException
public static <K,V> Map<K,List<V>> joinMaps(Map<K,V>... maps)
Joins any number of maps together into a single map, combining their values into a list, maintaining values in the order the maps were passed in. Nulls are inserted for given keys when the map does not contain that key.
i.e. joinMaps({‘a’ => 1, ‘b’ => 2}, {‘b’ => 3}, {‘a’ => 4, ‘c’ => 5}) -> {‘a’ => [1, null, 4], ‘b’ => [2, 3, null], ‘c’ => [null, null, 5]}
maps
- variable number of maps to join - order affects order of values in output.public static <T> List<List<T>> partitionFixed(int maxNumChunks, Collection<T> coll)
Fills up chunks out of a collection (given a maximum amount of chunks)
i.e. partitionFixed(5, [1,2,3]) -> 1,2,3 partitionFixed(5, [1..9]) -> [[1,2], [3,4], [5,6], [7,8], [9]] partitionFixed(3, [1..10]) -> [[1,2,3,4], [5,6,7], [8,9,10]]
maxNumChunks
- the maximum number of chunks to returncoll
- the collection to be chunked uppublic static Object getConfiguredClass(Map conf, Object configKey)
Return a new instance of a pluggable specified in the conf.
conf
- The conf to read from.configKey
- The key pointing to the pluggable classpublic static void setupDefaultUncaughtExceptionHandler()
public static Map<Object,String> redactValue(Map<Object,String> m, Object key)
Creates a new map with a string value in the map replaced with an equivalently-lengthed string of ‘#’.
m
- The map that a value will be redacted fromkey
- The key pointing to the value to be redactedpublic static void validateKeyName(String name)
public static String localHostname() throws UnknownHostException
UnknownHostException
protected String localHostnameImpl() throws UnknownHostException
UnknownHostException
public static String memoizedLocalHostname() throws UnknownHostException
UnknownHostException
public static String hostname() throws UnknownHostException
Gets the storm.local.hostname value, or tries to figure out the local hostname if it is not set in the config.
UnknownHostException
protected String hostnameImpl() throws UnknownHostException
UnknownHostException
public static String uuid()
public static void exitProcess(int val, String msg)
public static Runnable mkSuicideFn()
public static <K,V> HashMap<V,List<K>> reverseMap(Map<K,V> map)
“{:a 1 :b 1 :c 2} -> {1 [:a :b] 2 :c}”
Example usage in java: Map<Integer, String> tasks; Map<String, List
The order of he resulting list values depends on the ordering properties of the Map passed in. The caller is responsible for passing an ordered map if they expect the result to be consistently ordered as well.
map
- to reversepublic static HashMap reverseMap(List listSeq)
“[[:a 1] [:b 1] [:c 2]} -> {1 [:a :b] 2 :c}” Reverses an assoc-list style Map like reverseMap(Map…)
listSeq
- to reversepublic static String processPid()
public static int execCommand(String... command) throws org.apache.commons.exec.ExecuteException, IOException
org.apache.commons.exec.ExecuteException
IOException
public static void extractDirFromJar(String jarpath, String dir, File destdir)
Extract dir from the jar to destdir
jarpath
- Path to the jar filedir
- Directory in the jar to pull outdestdir
- Path to the directory where the extracted directory will be putpublic static void sendSignalToProcess(long lpid, int signum) throws IOException
IOException
public static void forceKillProcess(String pid) throws IOException
IOException
public static void killProcessWithSigTerm(String pid) throws IOException
IOException
public static void addShutdownHookWithForceKillIn1Sec(Runnable func)
Adds the user supplied function as a shutdown hook for cleanup. Also adds a function that sleeps for a second and then halts the runtime to avoid any zombie process in case cleanup function hangs.
public static String shellCmd(List<String> command)
Returns the combined string, escaped for posix shell.
command
- the list of strings to be combinedpublic static void forceDelete(String path) throws IOException
Deletes a file or directory and its contents if it exists. Does not complain if the input is null or does not exist.
path
- the path to the file or directoryIOException
protected void forceDeleteImpl(String path) throws IOException
IOException
public static Collection<String> readDirContents(String dir)
Returns a Collection of file names found under the given directory.
dir
- a directorypublic static String currentClasspath()
Returns the value of java.class.path System property. Kept separate for testing.
public String currentClasspathImpl()
public static String addToClasspath(String classpath, Collection<String> paths)
public static String addToClasspath(Collection<String> classpaths, Collection<String> paths)
public String addToClasspathImpl(String classpath, Collection<String> paths)
public String addToClasspathImpl(Collection<String> classpaths, Collection<String> paths)
public static Utils.UptimeComputer makeUptimeComputer()
public Utils.UptimeComputer makeUptimeComputerImpl()
public static <V> V OR(V a, V b)
a or b the first one that is not null
a
- somethingb
- something elsepublic static String writeScript(String dir, List<String> command, Map<String,String> environment) throws IOException
Writes a posix shell script file to be executed in its own process.
dir
- the directory under which the script is to be writtencommand
- the command the script is to executeenvironment
- optional environment variables to set before running the script’s command. May be null.IOException
public static Utils.SmartThread asyncLoop(Callable afn, boolean isDaemon, Thread.UncaughtExceptionHandler eh, int priority, boolean isFactory, boolean startImmediately, String threadName)
Creates a thread that calls the given code repeatedly, sleeping for an interval of seconds equal to the return value of the previous call.
The given afn may be a callable that returns the number of seconds to sleep, or it may be a Callable that returns another Callable that in turn returns the number of seconds to sleep. In the latter case isFactory.
afn
- the code to call on each iterationisDaemon
- whether the new thread should be a daemon threadeh
- code to call when afn throws an exceptionpriority
- the new thread’s priorityisFactory
- whether afn returns a callable instead of sleep secondsstartImmediately
- whether to start the thread before returningthreadName
- a suffix to be appended to the thread nameThread
public static Utils.SmartThread asyncLoop(Callable afn, String threadName, Thread.UncaughtExceptionHandler eh)
Convenience method used when only the function and name suffix are given.
afn
- the code to call on each iterationthreadName
- a suffix to be appended to the thread nameThread
public static Utils.SmartThread asyncLoop(Callable afn)
Convenience method used when only the function is given.
afn
- the code to call on each iterationpublic static Map<String,Object> convertClojureMapToJavaMap(Map map)
converts a clojure PersistentMap to java HashMap
public static StormTopology addVersions(StormTopology topology)
Add version information to the given topology
topology
- the topology being submitted (MIGHT BE MODIFIED)public static boolean isValidKey(String key)
Validates topology name / blob key.
key
- topology name / Key for the blob.Copyright © 2022 The Apache Software Foundation. All Rights Reserved.