Class Utils
- java.lang.Object
-
- io.fabric8.kubernetes.client.utils.Utils
-
public class Utils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
checkNotNull(T ref, String message)
static void
closeQuietly(Closeable... closeables)
Closes and flushes the specifiedCloseable
items.static void
closeQuietly(Iterable<? extends Closeable> closeables)
Closes and flushes the specifiedCloseable
items.static String
coalesce(String... items)
static String
convertSystemPropertyNameToEnvVar(String systemPropertyName)
static ThreadFactory
daemonThreadFactory(Object forObject)
Create aThreadFactory
with daemon threads and a thread name based upon the object passed in.static String
filePath(URL path)
static UUID
generateId()
Utility method to generate UUIDs.static String
getAnnotationValue(Class kubernetesResourceType, Class annotationClass)
static List<String>
getCommandPlatformPrefix()
Returns prefixes needed to invoke specified command in a subprocess.static String
getEnvVar(String envVarName, String defaultValue)
static <T> T
getNonNullOrElse(T obj, T defaultObj)
static String
getProperty(Map<String,Object> properties, String propertyName)
static String
getProperty(Map<String,Object> properties, String propertyName, String defaultValue)
static String
getSystemPathVariable()
Get system PATH variablestatic String
getSystemPropertyOrEnvVar(String systemPropertyName)
static int
getSystemPropertyOrEnvVar(String systemPropertyName, int defaultValue)
static boolean
getSystemPropertyOrEnvVar(String systemPropertyName, Boolean defaultValue)
static String
getSystemPropertyOrEnvVar(String systemPropertyName, String defaultValue)
static String
getSystemPropertyOrEnvVar(String systemPropertyName, String envVarName, String defaultValue)
static String
interpolateString(String templateInput, Map<String,String> valuesMap)
Interpolates a String containing variable placeholders with the values provided in the valuesMap.static <T> boolean
isNotNull(T... refList)
static boolean
isNotNullOrEmpty(String str)
static boolean
isNotNullOrEmpty(String[] array)
static boolean
isNotNullOrEmpty(Map map)
static boolean
isNullOrEmpty(String str)
static boolean
isResourceNamespaced(Class kubernetesResourceType)
Reads @Namespaced annotation in resource class to check whether resource is namespaced or notstatic boolean
isWindowsOperatingSystem()
Check whether platform is windows or notstatic String
join(Object[] array)
static String
join(Object[] array, char separator)
static String
randomString(int length)
static String
replaceAllWithoutRegex(String text, String from, String to)
Replaces all occurrences of the from text with to text without any regular expressionsstatic CompletableFuture<Void>
schedule(Executor executor, Runnable command, long delay, TimeUnit unit)
Schedule a task to run in the givenExecutor
- which should run the task in a different thread as to not hold the scheduling threadstatic CompletableFuture<?>
scheduleAtFixedRate(Executor executor, Runnable command, long initialDelay, long delay, TimeUnit unit)
Schedule a repeated task to run in the givenExecutor
- which should run the task in a different thread as to not hold the scheduling thread.static void
scheduleWithVariableRate(CompletableFuture<?> completion, Executor executor, Runnable command, long initialDelay, LongSupplier nextDelay, TimeUnit unit)
Schedule a repeated task to run in the givenExecutor
- which should run the task in a different thread as to not hold the scheduling thread.static String
toUrlEncoded(String str)
Converts string to URL encoded string.static boolean
waitUntilReady(Future<?> future, long amount, TimeUnit timeUnit)
Wait until another thread signals the completion of a task.static void
waitUntilReadyOrFail(Future<?> future, long amount, TimeUnit timeUnit)
Similar towaitUntilReady(Future, long, TimeUnit)
, but will always throw an exception if not ready
-
-
-
Field Detail
-
WINDOWS
public static final String WINDOWS
- See Also:
- Constant Field Values
-
OS_NAME
public static final String OS_NAME
- See Also:
- Constant Field Values
-
PATH_WINDOWS
public static final String PATH_WINDOWS
- See Also:
- Constant Field Values
-
PATH_UNIX
public static final String PATH_UNIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
checkNotNull
public static <T> T checkNotNull(T ref, String message)
-
getSystemPropertyOrEnvVar
public static String getSystemPropertyOrEnvVar(String systemPropertyName, String envVarName, String defaultValue)
-
convertSystemPropertyNameToEnvVar
public static String convertSystemPropertyNameToEnvVar(String systemPropertyName)
-
getSystemPropertyOrEnvVar
public static String getSystemPropertyOrEnvVar(String systemPropertyName, String defaultValue)
-
getSystemPropertyOrEnvVar
public static String getSystemPropertyOrEnvVar(String systemPropertyName)
-
getSystemPropertyOrEnvVar
public static boolean getSystemPropertyOrEnvVar(String systemPropertyName, Boolean defaultValue)
-
getSystemPropertyOrEnvVar
public static int getSystemPropertyOrEnvVar(String systemPropertyName, int defaultValue)
-
waitUntilReady
public static boolean waitUntilReady(Future<?> future, long amount, TimeUnit timeUnit)
Wait until another thread signals the completion of a task. If an exception is passed, it will be propagated to the caller.- Parameters:
future
- The communication channel.amount
- The amount of time to wait. If less than 0, wait indefinitelytimeUnit
- The time unit.- Returns:
- a boolean value indicating resource is ready or not.
-
waitUntilReadyOrFail
public static void waitUntilReadyOrFail(Future<?> future, long amount, TimeUnit timeUnit)
Similar towaitUntilReady(Future, long, TimeUnit)
, but will always throw an exception if not ready
-
closeQuietly
public static void closeQuietly(Iterable<? extends Closeable> closeables)
Closes and flushes the specifiedCloseable
items.
-
closeQuietly
public static void closeQuietly(Closeable... closeables)
Closes and flushes the specifiedCloseable
items.- Parameters:
closeables
- An array ofCloseable
items.
-
generateId
public static UUID generateId()
Utility method to generate UUIDs. This is taken from Spring Framework's SimpleIdGenerator- Returns:
- generated UUID
-
randomString
public static String randomString(int length)
-
replaceAllWithoutRegex
public static String replaceAllWithoutRegex(String text, String from, String to)
Replaces all occurrences of the from text with to text without any regular expressions- Parameters:
text
- text stringfrom
- from stringto
- to string- Returns:
- returns processed string
-
isNullOrEmpty
public static boolean isNullOrEmpty(String str)
-
isNotNullOrEmpty
public static boolean isNotNullOrEmpty(Map map)
-
isNotNullOrEmpty
public static boolean isNotNullOrEmpty(String str)
-
isNotNullOrEmpty
public static boolean isNotNullOrEmpty(String[] array)
-
isNotNull
public static <T> boolean isNotNull(T... refList)
-
getNonNullOrElse
public static <T> T getNonNullOrElse(T obj, T defaultObj)
-
getProperty
public static String getProperty(Map<String,Object> properties, String propertyName, String defaultValue)
-
toUrlEncoded
public static String toUrlEncoded(String str)
Converts string to URL encoded string.- Parameters:
str
- Url as string- Returns:
- returns encoded string
-
isResourceNamespaced
public static boolean isResourceNamespaced(Class kubernetesResourceType)
Reads @Namespaced annotation in resource class to check whether resource is namespaced or not- Parameters:
kubernetesResourceType
- class for resource- Returns:
- boolean value indicating it's namespaced or not
-
getAnnotationValue
public static String getAnnotationValue(Class kubernetesResourceType, Class annotationClass)
-
interpolateString
public static String interpolateString(String templateInput, Map<String,String> valuesMap)
Interpolates a String containing variable placeholders with the values provided in the valuesMap.This method is intended to interpolate templates loaded from YAML and JSON files.
Placeholders are indicated by the dollar sign and curly braces (
${VARIABLE_KEY}
).Placeholders can also be indicated by the dollar sign and double curly braces (
${{VARIABLE_KEY}}
), when this notation is used, the resulting value will be unquoted (if applicable), expected values should be JSON compatible.- Parameters:
valuesMap
- to interpolate in the StringtemplateInput
- raw input containing a String with placeholders ready to be interpolated- Returns:
- the interpolated String
- See Also:
- OpenShift Templates
-
isWindowsOperatingSystem
public static boolean isWindowsOperatingSystem()
Check whether platform is windows or not- Returns:
- boolean value indicating whether OS is Windows or not.
-
getSystemPathVariable
public static String getSystemPathVariable()
Get system PATH variable- Returns:
- a string containing value of PATH
-
getCommandPlatformPrefix
public static List<String> getCommandPlatformPrefix()
Returns prefixes needed to invoke specified command in a subprocess.- Returns:
- a list of strings containing prefixes
-
daemonThreadFactory
public static ThreadFactory daemonThreadFactory(Object forObject)
Create aThreadFactory
with daemon threads and a thread name based upon the object passed in.
-
schedule
public static CompletableFuture<Void> schedule(Executor executor, Runnable command, long delay, TimeUnit unit)
Schedule a task to run in the givenExecutor
- which should run the task in a different thread as to not hold the scheduling thread
-
scheduleAtFixedRate
public static CompletableFuture<?> scheduleAtFixedRate(Executor executor, Runnable command, long initialDelay, long delay, TimeUnit unit)
Schedule a repeated task to run in the givenExecutor
- which should run the task in a different thread as to not hold the scheduling thread.Has the same general contract as
ScheduledThreadPoolExecutor.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
-
scheduleWithVariableRate
public static void scheduleWithVariableRate(CompletableFuture<?> completion, Executor executor, Runnable command, long initialDelay, LongSupplier nextDelay, TimeUnit unit)
Schedule a repeated task to run in the givenExecutor
- which should run the task in a different thread as to not hold the scheduling thread.- Parameters:
nextDelay
- provides the relative next delay - that is the values are applied cumulatively to the initial start time. Supplying a fixed value produces a fixed rate.
-
-