public class NormalizedResources extends Object
Modifier and Type | Field and Description |
---|---|
static ResourceNameNormalizer |
RESOURCE_NAME_NORMALIZER |
Constructor and Description |
---|
NormalizedResources(Map<String,Double> normalizedResources)
Create a new normalized set of resources.
|
NormalizedResources(NormalizedResources other)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(NormalizedResources other) |
void |
add(WorkerResources value)
Add the resources from a worker to this.
|
boolean |
anyNonCpuOverZero()
Are any of the non cpu resources positive.
|
boolean |
areAnyOverZero()
Are any of the resources positive.
|
double |
calculateAveragePercentageUsedBy(NormalizedResources used,
double totalMemoryMb,
double usedMemoryMb)
Calculate the average resource usage percentage with this being the total resources and used being the amounts used.
|
double |
calculateMinPercentageUsedBy(NormalizedResources used,
double totalMemoryMb,
double usedMemoryMb)
Calculate the minimum resource usage percentage with this being the total resources and used being the amounts used.
|
void |
clear()
Set all resources to 0.
|
boolean |
couldHoldIgnoringSharedMemory(NormalizedResources other,
double thisTotalMemoryMb,
double otherTotalMemoryMb)
A simple sanity check to see if all of the resources in this would be large enough to hold the resources in other ignoring memory.
|
boolean |
couldHoldIgnoringSharedMemoryAndCpu(NormalizedResources other,
double thisTotalMemoryMb,
double otherTotalMemoryMb)
A simple sanity check to see if all of the resources in this would be large enough to hold the resources in other ignoring memory.
|
double |
getTotalCpu()
Get the total amount of cpu.
|
boolean |
remove(NormalizedResources other,
ResourceMetrics resourceMetrics)
Remove the other resources from this.
|
boolean |
remove(WorkerResources value)
Remove the resources of a worker from this.
|
static void |
resetResourceNames()
This is for testing only.
|
Map<String,Double> |
toNormalizedMap()
Return a Map of the normalized resource name to a double.
|
String |
toString() |
void |
updateForRareResourceAffinity(NormalizedResources request)
If a node or rack has a kind of resource not in a request, make that resource negative so when sorting that node or rack will
be less likely to be selected.
|
public static ResourceNameNormalizer RESOURCE_NAME_NORMALIZER
public NormalizedResources(NormalizedResources other)
public NormalizedResources(Map<String,Double> normalizedResources)
normalizedResources
- the normalized resource mappublic static void resetResourceNames()
public double getTotalCpu()
public void add(NormalizedResources other)
public void add(WorkerResources value)
value
- the worker resources that should be added to this.public boolean remove(NormalizedResources other, ResourceMetrics resourceMetrics)
other
- the resources we want removed.resourceMetrics
- The resource related metricspublic boolean remove(WorkerResources value)
value
- the worker resources that should be removed from this.public Map<String,Double> toNormalizedMap()
public boolean couldHoldIgnoringSharedMemory(NormalizedResources other, double thisTotalMemoryMb, double otherTotalMemoryMb)
other
- the resources that we want to check if they would fit in this.thisTotalMemoryMb
- The total memory in MB of thisotherTotalMemoryMb
- The total memory in MB of otherpublic boolean couldHoldIgnoringSharedMemoryAndCpu(NormalizedResources other, double thisTotalMemoryMb, double otherTotalMemoryMb)
other
- the resources that we want to check if they would fit in this.thisTotalMemoryMb
- The total memory in MB of thisotherTotalMemoryMb
- The total memory in MB of otherpublic double calculateAveragePercentageUsedBy(NormalizedResources used, double totalMemoryMb, double usedMemoryMb)
used
- the amount of resources used.totalMemoryMb
- The total memory in MBusedMemoryMb
- The used memory in MBIllegalArgumentException
- if any resource in used has a greater value than the same resource in the total, or used has generic
resources that are not present in the total.public double calculateMinPercentageUsedBy(NormalizedResources used, double totalMemoryMb, double usedMemoryMb)
used
- the amount of resources used.totalMemoryMb
- The total memory in MBusedMemoryMb
- The used memory in MBIllegalArgumentException
- if any resource in used has a greater value than the same resource in the total, or used has generic
resources that are not present in the total.public void updateForRareResourceAffinity(NormalizedResources request)
request
- the requested resources.public void clear()
public boolean areAnyOverZero()
public boolean anyNonCpuOverZero()
Copyright © 2023 The Apache Software Foundation. All rights reserved.