public class ResourceUtils
extends java.lang.Object
| Modifier and Type | Field | Description |
|---|---|---|
static java.lang.String |
EXTERNAL_VOLUME_RESOURCE_TAG |
|
static java.lang.String |
MAXIMUM_ALLOCATION |
|
static java.lang.String |
MINIMUM_ALLOCATION |
|
static java.util.regex.Pattern |
RESOURCE_REQUEST_VALUE_PATTERN |
|
static java.lang.String |
TAGS |
|
static java.lang.String |
TYPE |
|
static java.lang.String |
UNITS |
|
static java.lang.String |
YARN_IO_OPTIONAL |
| Modifier and Type | Method | Description |
|---|---|---|
static void |
areMandatoryResourcesAvailable(Resource res) |
Are mandatory resources like memory-mb, vcores available?
If not, throw exceptions.
|
static Resource |
createResourceFromString(java.lang.String resourceStr,
java.util.List<ResourceTypeInfo> resourceTypeInfos) |
|
static ResourceInformation[] |
createResourceTypesArray(java.util.Map<java.lang.String,java.lang.Long> res) |
Create an array of
ResourceInformation objects corresponding to
the passed in map of names to values. |
static Resource |
createResourceWithSameValue(long value) |
Return a new
Resource instance with all resource values
initialized to value. |
static Resource |
fetchMaximumAllocationFromConfig(org.apache.hadoop.conf.Configuration conf) |
Get maximum allocation from config, *THIS WILL NOT UPDATE INTERNAL DATA.
|
static java.lang.StringBuilder |
getCustomResourcesStrings(Resource resource) |
|
static java.lang.String |
getDefaultUnit(java.lang.String resourceType) |
Get default unit by given resource type.
|
static java.util.Map<java.lang.String,ResourceInformation> |
getNodeResourceInformation(org.apache.hadoop.conf.Configuration conf) |
Function to get the resources for a node.
|
static int |
getNumberOfCountableResourceTypes() |
|
static int |
getNumberOfKnownResourceTypes() |
|
static java.util.List<ResourceInformation> |
getRequestedResourcesFromConfig(org.apache.hadoop.conf.Configuration configuration,
java.lang.String prefix) |
From a given configuration get all entries representing requested
resources: entries that match the {prefix}{resourceName}={value}[{units}]
pattern.
|
static java.util.List<ResourceTypeInfo> |
getResourcesTypeInfo() |
Get all resource types information from known resource types.
|
static java.util.Map<java.lang.String,java.lang.Integer> |
getResourceTypeIndex() |
Get associate index of resource types such memory, cpu etc.
|
static java.util.Map<java.lang.String,ResourceInformation> |
getResourceTypes() |
Get the resource types to be supported by the system.
|
static ResourceInformation[] |
getResourceTypesArray() |
|
static Resource |
getResourceTypesMaximumAllocation() |
Get a Resource object with for the maximum allocation possible.
|
static Resource |
getResourceTypesMinimumAllocation() |
|
static java.lang.String |
getUnits(java.lang.String resourceValue) |
|
static long |
getValue(java.lang.String resourceValue) |
|
static void |
initializeResourcesFromResourceInformationMap(java.util.Map<java.lang.String,ResourceInformation> resourceInformationMap) |
This method is visible for testing, unit test can construct a
resourceInformationMap and pass it to this method to initialize multiple resources.
|
static Resource |
multiplyFloor(Resource resource,
double multiplier) |
|
static Resource |
multiplyRound(Resource resource,
double multiplier) |
|
static java.lang.String[] |
parseResourceValue(java.lang.String resourceValue) |
Extract unit and actual value from resource value.
|
static void |
reinitializeResources(java.util.List<ResourceTypeInfo> resourceTypeInfo) |
Reinitialize all resource types from external source (in case of client,
server will send the updated list and local resourceutils cache will be
updated as per server's list of resources).
|
static void |
resetNodeResources() |
|
static void |
resetResourceTypes() |
|
static java.util.Map<java.lang.String,ResourceInformation> |
resetResourceTypes(org.apache.hadoop.conf.Configuration conf) |
public static final java.lang.String UNITS
public static final java.lang.String TYPE
public static final java.lang.String TAGS
public static final java.lang.String MINIMUM_ALLOCATION
public static final java.lang.String MAXIMUM_ALLOCATION
public static final java.lang.String EXTERNAL_VOLUME_RESOURCE_TAG
public static final java.util.regex.Pattern RESOURCE_REQUEST_VALUE_PATTERN
public static final java.lang.String YARN_IO_OPTIONAL
public static Resource fetchMaximumAllocationFromConfig(org.apache.hadoop.conf.Configuration conf)
conf - config@VisibleForTesting public static void initializeResourcesFromResourceInformationMap(java.util.Map<java.lang.String,ResourceInformation> resourceInformationMap)
resourceInformationMap - constructed resource information map.public static java.util.Map<java.lang.String,java.lang.Integer> getResourceTypeIndex()
public static java.util.Map<java.lang.String,ResourceInformation> getResourceTypes()
public static ResourceInformation[] getResourceTypesArray()
public static int getNumberOfKnownResourceTypes()
public static int getNumberOfCountableResourceTypes()
@VisibleForTesting public static void resetResourceTypes()
@VisibleForTesting public static java.util.Map<java.lang.String,ResourceInformation> resetResourceTypes(org.apache.hadoop.conf.Configuration conf)
public static java.lang.String getUnits(java.lang.String resourceValue)
public static java.lang.String[] parseResourceValue(java.lang.String resourceValue)
resourceValue - Value of the resourcejava.lang.IllegalArgumentException - if units contain non alpha characterspublic static long getValue(java.lang.String resourceValue)
public static java.util.Map<java.lang.String,ResourceInformation> getNodeResourceInformation(org.apache.hadoop.conf.Configuration conf)
YarnConfiguration.NODE_RESOURCES_CONFIGURATION_FILE to
determine the node resources.conf - configuration file@VisibleForTesting public static void resetNodeResources()
public static Resource getResourceTypesMinimumAllocation()
public static Resource getResourceTypesMaximumAllocation()
public static java.lang.String getDefaultUnit(java.lang.String resourceType)
resourceType - resourceTypepublic static java.util.List<ResourceTypeInfo> getResourcesTypeInfo()
public static void reinitializeResources(java.util.List<ResourceTypeInfo> resourceTypeInfo)
resourceTypeInfo - List of resource typespublic static java.util.List<ResourceInformation> getRequestedResourcesFromConfig(org.apache.hadoop.conf.Configuration configuration, java.lang.String prefix)
configuration - The configurationprefix - Keys with this prefix are considered from the configurationpublic static void areMandatoryResourcesAvailable(Resource res)
res - resourcejava.lang.IllegalArgumentException - if mandatory resource is not available or
value is not within boundarypublic static ResourceInformation[] createResourceTypesArray(java.util.Map<java.lang.String,java.lang.Long> res)
ResourceInformation objects corresponding to
the passed in map of names to values. The array will be ordered according
to the order returned by getResourceTypesArray(). The value of
each resource type in the returned array will either be the value given for
that resource in the res parameter or, if none is given, 0.res - the map of resource type valuesResourceInformation instances@Private @Unstable public static Resource createResourceWithSameValue(long value)
Resource instance with all resource values
initialized to value.value - the value to use for all resourcesResource instance@Private @Unstable public static Resource createResourceFromString(java.lang.String resourceStr, java.util.List<ResourceTypeInfo> resourceTypeInfos)
public static java.lang.StringBuilder getCustomResourcesStrings(Resource resource)
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.