Class ResourceUtils
java.lang.Object
org.apache.hadoop.yarn.util.resource.ResourceUtils
Helper class to read the resource-types to be supported by the system.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAre mandatory resources like memory-mb, vcores available?static ResourcecreateResourceFromString(String resourceStr, List<ResourceTypeInfo> resourceTypeInfos) static ResourceInformation[]Create an array ofResourceInformationobjects corresponding to the passed in map of names to values.static ResourcecreateResourceWithSameValue(long value) Return a newResourceinstance with all resource values initialized tovalue.static ResourcefetchMaximumAllocationFromConfig(org.apache.hadoop.conf.Configuration conf) Get maximum allocation from config, *THIS WILL NOT UPDATE INTERNAL DATA.static StringBuildergetCustomResourcesStrings(Resource resource) static StringgetDefaultUnit(String resourceType) Get default unit by given resource type.static Map<String,ResourceInformation> getNodeResourceInformation(org.apache.hadoop.conf.Configuration conf) Function to get the resources for a node.static intstatic intstatic List<ResourceInformation>getRequestedResourcesFromConfig(org.apache.hadoop.conf.Configuration configuration, String prefix) From a given configuration get all entries representing requested resources: entries that match the {prefix}{resourceName}={value}[{units}] pattern.static List<ResourceTypeInfo>Get all resource types information from known resource types.Get associate index of resource types such memory, cpu etc.static Map<String,ResourceInformation> Get the resource types to be supported by the system.static ResourceInformation[]static ResourceGet a Resource object with for the maximum allocation possible.static Resourcestatic Stringstatic longstatic voidinitializeResourcesFromResourceInformationMap(Map<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 ResourcemultiplyFloor(Resource resource, double multiplier) static ResourcemultiplyRound(Resource resource, double multiplier) static String[]parseResourceValue(String resourceValue) Extract unit and actual value from resource value.static voidreinitializeResources(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 voidstatic voidstatic Map<String,ResourceInformation> resetResourceTypes(org.apache.hadoop.conf.Configuration conf)
-
Field Details
-
UNITS
- See Also:
-
TYPE
- See Also:
-
TAGS
- See Also:
-
MINIMUM_ALLOCATION
- See Also:
-
MAXIMUM_ALLOCATION
- See Also:
-
EXTERNAL_VOLUME_RESOURCE_TAG
- See Also:
-
RESOURCE_REQUEST_VALUE_PATTERN
-
YARN_IO_OPTIONAL
- See Also:
-
-
Method Details
-
fetchMaximumAllocationFromConfig
Get maximum allocation from config, *THIS WILL NOT UPDATE INTERNAL DATA.- Parameters:
conf- config- Returns:
- maximum allocation
-
initializeResourcesFromResourceInformationMap
@VisibleForTesting public static void initializeResourcesFromResourceInformationMap(Map<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.- Parameters:
resourceInformationMap- constructed resource information map.
-
getResourceTypeIndex
Get associate index of resource types such memory, cpu etc. This could help to access each resource types in a resource faster.- Returns:
- Index map for all Resource Types.
-
getResourceTypes
Get the resource types to be supported by the system.- Returns:
- A map of the resource name to a ResourceInformation object which contains details such as the unit.
-
getResourceTypesArray
-
getNumberOfKnownResourceTypes
public static int getNumberOfKnownResourceTypes() -
getNumberOfCountableResourceTypes
public static int getNumberOfCountableResourceTypes() -
resetResourceTypes
@VisibleForTesting public static void resetResourceTypes() -
resetResourceTypes
@VisibleForTesting public static Map<String,ResourceInformation> resetResourceTypes(org.apache.hadoop.conf.Configuration conf) -
getUnits
-
parseResourceValue
Extract unit and actual value from resource value.- Parameters:
resourceValue- Value of the resource- Returns:
- Array containing unit and value. [0]=unit, [1]=value
- Throws:
IllegalArgumentException- if units contain non alpha characters
-
getValue
-
getNodeResourceInformation
public static Map<String,ResourceInformation> getNodeResourceInformation(org.apache.hadoop.conf.Configuration conf) Function to get the resources for a node. This function will look at the fileYarnConfiguration.NODE_RESOURCES_CONFIGURATION_FILEto determine the node resources.- Parameters:
conf- configuration file- Returns:
- a map to resource name to the ResourceInformation object. The map is guaranteed to have entries for memory and vcores
-
resetNodeResources
@VisibleForTesting public static void resetNodeResources() -
getResourceTypesMinimumAllocation
-
getResourceTypesMaximumAllocation
Get a Resource object with for the maximum allocation possible.- Returns:
- a Resource object with the maximum allocation for the scheduler
-
getDefaultUnit
Get default unit by given resource type.- Parameters:
resourceType- resourceType- Returns:
- default unit
-
getResourcesTypeInfo
Get all resource types information from known resource types.- Returns:
- List of ResourceTypeInfo
-
reinitializeResources
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).- Parameters:
resourceTypeInfo- List of resource types
-
getRequestedResourcesFromConfig
public static List<ResourceInformation> getRequestedResourcesFromConfig(org.apache.hadoop.conf.Configuration configuration, String prefix) From a given configuration get all entries representing requested resources: entries that match the {prefix}{resourceName}={value}[{units}] pattern.- Parameters:
configuration- The configurationprefix- Keys with this prefix are considered from the configuration- Returns:
- The list of requested resources as described by the configuration
-
areMandatoryResourcesAvailable
Are mandatory resources like memory-mb, vcores available? If not, throw exceptions. On availability, ensure those values are within boundary.- Parameters:
res- resource- Throws:
IllegalArgumentException- if mandatory resource is not available or value is not within boundary
-
createResourceTypesArray
Create an array ofResourceInformationobjects corresponding to the passed in map of names to values. The array will be ordered according to the order returned bygetResourceTypesArray(). The value of each resource type in the returned array will either be the value given for that resource in theresparameter or, if none is given, 0.- Parameters:
res- the map of resource type values- Returns:
- an array of
ResourceInformationinstances
-
createResourceWithSameValue
Return a newResourceinstance with all resource values initialized tovalue.- Parameters:
value- the value to use for all resources- Returns:
- a new
Resourceinstance
-
multiplyFloor
-
multiplyRound
-
createResourceFromString
@Private @Unstable public static Resource createResourceFromString(String resourceStr, List<ResourceTypeInfo> resourceTypeInfos) -
getCustomResourcesStrings
-