Class ServiceUtils
java.lang.Object
org.apache.hadoop.yarn.service.utils.ServiceUtils
These are slider-specific Util methods
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProcess termination handler - exist with specified exit code after waiting a while for ATS state to be in sync. -
Method Summary
Modifier and TypeMethodDescriptionstatic ClasspathConstructorbuildClasspath(String sliderConfDir, String libdir, SliderFileSystem sliderFileSystem, String configClassPath, boolean usingMiniMRCluster) Build up the classpath for execution -behaves very differently on a mini test cluster vs a production production one.buildEnvMap(Configuration conf, Map<String, String> tokenMap) Take a collection, return a list containing the string value of every element in the collection.static voidcopy(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path srcFile, org.apache.hadoop.fs.Path destFile) Copy a file to a new FS -both paths must be qualified.static StringcreateDescriptionTag(String description) static FilenameFilterAccept all filenames ending with.jarstatic org.apache.hadoop.fs.PathcreateLocalPath(File file) Create a file:// path from a local filestatic StringcreateNameTag(String name) static StringcreateVersionTag(String version) static FilefindContainingJar(Class my_class) Find a containing JARstatic FilefindContainingJarOrFail(Class clazz) Find a containing JARstatic String[]static StringgetLocalHostName(org.apache.hadoop.conf.Configuration conf) static intGet a random open portstatic booleanstatic booleanisPortAvailable(int port) See if a port is available for listening on by trying to listen on it and seeing if that works or fails.static booleanstatic booleanImplementation of set-ness, groovy definition of true/false for a stringstatic StringJoin an array of strings with a separator that appears after every instance in the list -optionally at the endstatic Stringjoin(Collection collection, String separator) Join an collection of objects with a separator that appears after every instance in the list -including at the endstatic Stringjoin(Collection collection, String separator, boolean trailing) Join an collection of objects with a separator that appears after every instance in the list -optionally at the endstatic StringResolve a mandatory environment variablestatic <T1,T2> Map<T1, T2> mergeMapsIgnoreDuplicateKeys(Map<T1, T2> first, Map<T1, T2> second) Generic map merge logicstatic voidputAllJars(Map<String, org.apache.hadoop.yarn.api.records.LocalResource> providerResources, SliderFileSystem sliderFileSystem, org.apache.hadoop.fs.Path tempPath, String libDir, String srcPath) Submit a JAR containing and map itstatic org.apache.hadoop.yarn.api.records.LocalResourceputJar(Map<String, org.apache.hadoop.yarn.api.records.LocalResource> providerResources, SliderFileSystem sliderFileSystem, Class clazz, org.apache.hadoop.fs.Path tempPath, String libdir, String jarName) Submit a JAR containing a specific class and map itstatic Stringstringify(org.apache.hadoop.yarn.api.records.URL url) Convert a YARN URL into a string value of a normal URLstatic StringstringifyMap(Map<String, String> map) Convert a map to a multi-line string for printingstatic voidtarGzipFolder(String[] libDirs, File tarGzipFile, FilenameFilter filter) Given a source folder create a tar.gz file
-
Method Details
-
isUnset
Implementation of set-ness, groovy definition of true/false for a string- Parameters:
s- string- Returns:
- true iff the string is neither null nor empty
-
isSet
-
isEmpty
-
findContainingJarOrFail
Find a containing JAR- Parameters:
clazz- class to find- Returns:
- the file
- Throws:
IOException- any IO problem, including the class not having a classloaderFileNotFoundException- if the class did not resolve to a file
-
findContainingJar
Find a containing JAR- Parameters:
my_class- class to find- Returns:
- the file or null if it is not found
- Throws:
IOException- any IO problem, including the class not having a classloader
-
copy
public static void copy(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path srcFile, org.apache.hadoop.fs.Path destFile) throws IOException, BadClusterStateException Copy a file to a new FS -both paths must be qualified.- Parameters:
conf- conf filesrcFile- src filedestFile- dest file- Throws:
IOExceptionBadClusterStateException
-
collectionToStringList
Take a collection, return a list containing the string value of every element in the collection.- Parameters:
c- collection- Returns:
- a stringified list
-
join
Join an collection of objects with a separator that appears after every instance in the list -including at the end- Parameters:
collection- collection to call toString() on each elementseparator- separator string- Returns:
- the joined entries
-
join
Join an collection of objects with a separator that appears after every instance in the list -optionally at the end- Parameters:
collection- collection to call toString() on each elementseparator- separator stringtrailing- add a trailing entry or not- Returns:
- the joined entries
-
join
Join an array of strings with a separator that appears after every instance in the list -optionally at the end- Parameters:
collection- stringsseparator- separator stringtrailing- add a trailing entry or not- Returns:
- the joined entries
-
mandatoryEnvVariable
Resolve a mandatory environment variable- Parameters:
key- env var- Returns:
- the resolved value
- Throws:
BadClusterStateException
-
mergeMapsIgnoreDuplicateKeys
Generic map merge logic- Type Parameters:
T1- key typeT2- value type- Parameters:
first- first mapsecond- second map- Returns:
- 'first' merged with the second
-
stringifyMap
Convert a map to a multi-line string for printing- Parameters:
map- map to stringify- Returns:
- a string representation of the map
-
stringify
Convert a YARN URL into a string value of a normal URL- Parameters:
url- URL- Returns:
- string representatin
-
getOpenPort
Get a random open port- Returns:
- true if the port was available for listening on
- Throws:
IOException
-
isPortAvailable
public static boolean isPortAvailable(int port) See if a port is available for listening on by trying to listen on it and seeing if that works or fails.- Parameters:
port- port to listen to- Returns:
- true if the port was available for listening on
-
buildEnvMap
-
getLibDirs
-
putJar
public static org.apache.hadoop.yarn.api.records.LocalResource putJar(Map<String, org.apache.hadoop.yarn.api.records.LocalResource> providerResources, SliderFileSystem sliderFileSystem, Class clazz, org.apache.hadoop.fs.Path tempPath, String libdir, String jarName) throws IOException, SliderExceptionSubmit a JAR containing a specific class and map it- Parameters:
providerResources- provider map to build upsliderFileSystem- remote fsclazz- class to look forlibdir- lib directoryjarName- At the destination- Returns:
- the local resource ref
- Throws:
IOException- trouble copying to HDFSSliderException
-
putAllJars
public static void putAllJars(Map<String, org.apache.hadoop.yarn.api.records.LocalResource> providerResources, SliderFileSystem sliderFileSystem, org.apache.hadoop.fs.Path tempPath, String libDir, String srcPath) throws IOException, SliderExceptionSubmit a JAR containing and map it- Parameters:
providerResources- provider map to build upsliderFileSystem- remote fslibDir- lib directorysrcPath- copy jars from- Throws:
IOExceptionSliderException
-
createJarFilter
Accept all filenames ending with.jar- Returns:
- a filename filter
-
createLocalPath
Create a file:// path from a local file- Parameters:
file- file to point the path- Returns:
- a new Path
-
buildClasspath
public static ClasspathConstructor buildClasspath(String sliderConfDir, String libdir, SliderFileSystem sliderFileSystem, String configClassPath, boolean usingMiniMRCluster) Build up the classpath for execution -behaves very differently on a mini test cluster vs a production production one.- Parameters:
sliderConfDir- relative path to the dir containing slider config options to put on the classpath -or nulllibdir- directory containing the JAR filesconfigClassPath- extra class path configured in yarn-site.xmlusingMiniMRCluster- flag to indicate the MiniMR cluster is in use (and hence the current classpath should be used, not anything built up)- Returns:
- a classpath
-
tarGzipFolder
public static void tarGzipFolder(String[] libDirs, File tarGzipFile, FilenameFilter filter) throws IOException Given a source folder create a tar.gz file- Parameters:
libDirs-tarGzipFile-- Throws:
IOException
-
createNameTag
-
createVersionTag
-
createDescriptionTag
-
getLocalHostName
public static String getLocalHostName(@Nullable org.apache.hadoop.conf.Configuration conf) throws UnknownHostException - Throws:
UnknownHostException
-