Class NormalizedResources
java.lang.Object
org.apache.storm.scheduler.resource.normalization.NormalizedResources
Resources that have been normalized. This class is intended as a delegate for more specific types of normalized resource set, since it
does not keep track of memory as a resource.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionNormalizedResources
(Map<String, Double> normalizedResources) Create a new normalized set of resources.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(WorkerResources value) Add the resources from a worker to this.void
add
(NormalizedResources other) boolean
Are any of the non cpu resources positive.boolean
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
Get the total amount of cpu.boolean
remove
(WorkerResources value) Remove the resources of a worker from this.boolean
remove
(NormalizedResources other, ResourceMetrics resourceMetrics) Remove the other resources from this.static void
This is for testing only.Return a Map of the normalized resource name to a double.toString()
void
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.
-
Field Details
-
RESOURCE_NAME_NORMALIZER
-
-
Constructor Details
-
NormalizedResources
Copy constructor. -
NormalizedResources
Create a new normalized set of resources. Note that memory is not managed by this class, as it is not consistent in requests vs offers because of how on heap vs off heap is used.- Parameters:
normalizedResources
- the normalized resource map
-
-
Method Details
-
resetResourceNames
public static void resetResourceNames()This is for testing only. It allows a test to reset the static state relating to resource names. We reset the mapping because some algorithms sadly have different behavior if a resource exists or not. -
getTotalCpu
public double getTotalCpu()Get the total amount of cpu.- Returns:
- the amount of cpu.
-
add
-
add
Add the resources from a worker to this.- Parameters:
value
- the worker resources that should be added to this.
-
remove
Remove the other resources from this. This is the same as subtracting the resources in other from this.- Parameters:
other
- the resources we want removed.resourceMetrics
- The resource related metrics- Returns:
- true if the resources would have gone negative, but were clamped to 0.
-
remove
Remove the resources of a worker from this.- Parameters:
value
- the worker resources that should be removed from this.
-
toString
-
toNormalizedMap
Return a Map of the normalized resource name to a double. This should only be used when returning thrift resource requests to the end user. -
calculateAveragePercentageUsedBy
public 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. Used must be a subset of the total resources. If a resource in the total has a value of zero, it will be skipped in the calculation to avoid division by 0. If all resources are skipped the result is defined to be 100.0.- Parameters:
used
- the amount of resources used.totalMemoryMb
- The total memory in MBusedMemoryMb
- The used memory in MB- Returns:
- the average percentage used 0.0 to 100.0.
- Throws:
IllegalArgumentException
- 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.
-
calculateMinPercentageUsedBy
public 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. Used must be a subset of the total resources. If a resource in the total has a value of zero, it will be skipped in the calculation to avoid division by 0. If all resources are skipped the result is defined to be 100.0.- Parameters:
used
- the amount of resources used.totalMemoryMb
- The total memory in MBusedMemoryMb
- The used memory in MB- Returns:
- the minimum percentage used 0.0 to 100.0.
- Throws:
IllegalArgumentException
- 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.
-
updateForRareResourceAffinity
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. If the resource is in the request, make that resource positive.- Parameters:
request
- the requested resources.
-
clear
public void clear()Set all resources to 0. -
areAnyOverZero
public boolean areAnyOverZero()Are any of the resources positive.- Returns:
- true of any of the resources are positive. False if they are all <= 0.
-
anyNonCpuOverZero
public boolean anyNonCpuOverZero()Are any of the non cpu resources positive.- Returns:
- true of any of the non cpu resources are positive. False if they are all <= 0.
-