java.lang.Comparable<Resource>LightWeightResource@Public @Stable public abstract class Resource extends java.lang.Object implements java.lang.Comparable<Resource>
Resource models a set of computer resources in the
cluster.
Currently it models both memory and CPU.
The unit for memory is megabytes. CPU is modeled with virtual cores (vcores), a unit for expressing parallelism. A node's capacity should be configured with virtual cores equal to its number of physical cores. A container should be requested with the number of cores it can saturate, i.e. the average number of threads it expects to have runnable at a time.
Virtual cores take integer values and thus currently CPU-scheduling is very coarse. A complementary axis for CPU requests that represents processing power will likely be added in the future to enable finer-grained resource configuration.
Typically, applications request Resource of suitable
capability to run their component tasks.
| Modifier and Type | Field | Description |
|---|---|---|
static int |
MEMORY_INDEX |
|
protected ResourceInformation[] |
resources |
|
static int |
VCORES_INDEX |
| Constructor | Description |
|---|---|
Resource() |
| Modifier and Type | Method | Description |
|---|---|---|
protected static int |
castToIntSafely(long value) |
Convert long to int for a resource value safely.
|
int |
compareTo(Resource other) |
|
static void |
copy(Resource source,
Resource dest) |
|
boolean |
equals(java.lang.Object obj) |
|
java.util.List<ResourceInformation> |
getAllResourcesListCopy() |
Get list of resource information, this will be used by JAXB.
|
double |
getDisks() |
Get number of disks of the resource.
|
java.lang.String |
getFormattedString() |
This method is to get memory in terms of KB|MB|GB.
|
java.lang.String |
getFormattedString(long memory) |
|
abstract int |
getMemory() |
Deprecated.
|
long |
getMemorySize() |
Get memory of the resource.
|
ResourceInformation |
getResourceInformation(int index) |
Get ResourceInformation for a specified resource from a given index.
|
ResourceInformation |
getResourceInformation(java.lang.String resource) |
Get ResourceInformation for a specified resource.
|
ResourceInformation[] |
getResources() |
Get ResourceInformation for all resources.
|
long |
getResourceValue(java.lang.String resource) |
Get the value for a specified resource.
|
abstract int |
getVirtualCores() |
Get number of virtual cpu cores of the resource.
|
int |
hashCode() |
|
protected static ResourceInformation |
newDefaultInformation(java.lang.String name,
java.lang.String unit,
long value) |
Create ResourceInformation with basic fields.
|
static Resource |
newInstance(int memory,
int vCores) |
|
static Resource |
newInstance(long memory,
int vCores) |
|
static Resource |
newInstance(long memory,
int vCores,
java.util.Map<java.lang.String,java.lang.Long> others) |
Create a new
Resource instance with the given CPU and memory
values and additional resource values as set in the others
parameter. |
static Resource |
newInstance(Resource resource) |
|
void |
setDisks(double disks) |
Set number of disks of the resource.
|
abstract void |
setMemory(int memory) |
Deprecated.
|
void |
setMemorySize(long memory) |
Set memory of the resource.
|
void |
setResourceInformation(int index,
ResourceInformation resourceInformation) |
Set the ResourceInformation object for a particular resource.
|
void |
setResourceInformation(java.lang.String resource,
ResourceInformation resourceInformation) |
Set the ResourceInformation object for a particular resource.
|
protected void |
setResources(ResourceInformation[] resources) |
|
void |
setResourceValue(int index,
long value) |
Set the value of a resource in the ResourceInformation object.
|
void |
setResourceValue(java.lang.String resource,
long value) |
Set the value of a resource in the ResourceInformation object.
|
abstract void |
setVirtualCores(int vCores) |
Set number of virtual cpu cores of the resource.
|
protected void |
throwExceptionWhenArrayOutOfBound(int index) |
|
java.lang.String |
toFormattedString() |
|
java.lang.String |
toString() |
protected ResourceInformation[] resources
@Private public static final int MEMORY_INDEX
@Private public static final int VCORES_INDEX
@Public @Stable public static Resource newInstance(int memory, int vCores)
@Public @Stable public static Resource newInstance(long memory, int vCores)
@Public @Stable public static Resource newInstance(long memory, int vCores, java.util.Map<java.lang.String,java.lang.Long> others)
Resource instance with the given CPU and memory
values and additional resource values as set in the others
parameter. Note that the CPU and memory settings in the others
parameter will be ignored.memory - the memory valuevCores - the CPU valueothers - a map of other resource values indexed by resource nameResource instance with the given resource values@Public @Deprecated public abstract int getMemory()
getMemorySize() instead
Get memory of the resource. Note - while memory has
never had a unit specified, all YARN configurations have specified memory
in MB. The assumption has been that the daemons and applications are always
using the same units. With the introduction of the ResourceInformation
class we have support for units - so this function will continue to return
memory but in the units of MB@Public @Stable public long getMemorySize()
@Public @Deprecated public abstract void setMemory(int memory)
memory - memory(in MB) of the resource@Public @Stable public void setMemorySize(long memory)
memory - memory of the resource@Public @Evolving public abstract int getVirtualCores()
@Public @Evolving public abstract void setVirtualCores(int vCores)
vCores - number of virtual cpu cores of the resource@Private @Unstable public ResourceInformation[] getResources()
@Private @Unstable public java.util.List<ResourceInformation> getAllResourcesListCopy()
@Public @Unstable public ResourceInformation getResourceInformation(java.lang.String resource)
resource - name of the resource@Private @Unstable public ResourceInformation getResourceInformation(int index) throws ResourceNotFoundException
index - of the resourceResourceNotFoundException - if the resource can't be found@Public @Unstable public long getResourceValue(java.lang.String resource)
resource - name of the resource@Public
@Unstable
public void setResourceInformation(java.lang.String resource,
ResourceInformation resourceInformation)
resource - the resource for which the ResourceInformation is providedresourceInformation - ResourceInformation object@Private
@Unstable
public void setResourceInformation(int index,
ResourceInformation resourceInformation)
throws ResourceNotFoundException
index - the resource index for which the ResourceInformation is providedresourceInformation - ResourceInformation objectResourceNotFoundException - if the resource is not found@Public
@Unstable
public void setResourceValue(java.lang.String resource,
long value)
resource - the resource for which the value is provided.value - the value to set@Private
@Unstable
public void setResourceValue(int index,
long value)
throws ResourceNotFoundException
index - the resource index for which the value is provided.value - the value to setResourceNotFoundException - if the resource is not found@Public @Stable public double getDisks()
@Public @Stable public void setDisks(double disks)
disks - number of disks of the resourceprotected void throwExceptionWhenArrayOutOfBound(int index)
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int compareTo(Resource other)
compareTo in interface java.lang.Comparable<Resource>public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toFormattedString()
public java.lang.String getFormattedString()
public int hashCode()
hashCode in class java.lang.Objectprotected static int castToIntSafely(long value)
value - long resource valueprotected static ResourceInformation newDefaultInformation(java.lang.String name, java.lang.String unit, long value)
name - Resource Type Nameunit - Default unit of provided resource typevalue - Value associated with giveb resource@VisibleForTesting protected void setResources(ResourceInformation[] resources)
public java.lang.String getFormattedString(long memory)
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.