Package org.apache.storm.scheduler.resource.normalization

# Class NormalizedResourceOffer

java.lang.Object
org.apache.storm.scheduler.resource.normalization.NormalizedResourceOffer

All Implemented Interfaces:
  `NormalizedResourcesWithMemory`

public class NormalizedResourceOffer extends Object implements NormalizedResourcesWithMemory
An offer of resources with normalized resource names.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NormalizedResourceOffer()`
  Create an offer with all resources set to 0.
  `NormalizedResourceOffer(Map<String,? extends Number> resources)`
  Create a new normalized resource offer.
  `NormalizedResourceOffer(NormalizedResourceOffer other)`
  Copy Constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(NormalizedResourcesWithMemory other)`
  `boolean`
  `areAnyOverZero()`
  Return true if any of the resources are > 0.
  `double`
  `calculateAveragePercentageUsedBy(NormalizedResourceOffer used)`
  Calculate the average percentage used.
  `double`
  `calculateMinPercentageUsedBy(NormalizedResourceOffer used)`
  Calculate the min percentage used of the resource.
  `void`
  `clear()`
  Set all resources to 0.
  `boolean`
  `couldFit(double minWorkerCpu, NormalizedResourceRequest requestedResources)`
  Is there any possibility that a resource request could ever fit on this.
  `boolean`
  `couldHoldIgnoringSharedMemory(NormalizedResourcesWithMemory other)`
  Check if resources might be able to fit.
  `boolean`
  `couldHoldIgnoringSharedMemoryAndCpu(NormalizedResourcesWithMemory other)`
  `NormalizedResources`
  `getNormalizedResources()`
  `double`
  `getTotalCpu()`
  `double`
  `getTotalMemoryMb()`
  `boolean`
  `remove(WorkerResources other, ResourceMetrics resourceMetrics)`
  Remove the resources in other from this.
  `boolean`
  `remove(NormalizedResourcesWithMemory other)`
  `boolean`
  `remove(NormalizedResourcesWithMemory other, ResourceMetrics resourceMetrics)`
  Remove the resources in other from this.
  `Map<String,Double>`
  `toNormalizedMap()`
  Return these resources as a normalized map.
  `String`
  `toString()`
  `void`
  `updateForRareResourceAffinity(NormalizedResourceRequest requestedResources)`
  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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### NormalizedResourceOffer

    public NormalizedResourceOffer(Map<String,? extends Number> resources)
    Create a new normalized resource offer.
    Parameters:
      `resources` - the resources to be normalized.

  - ### NormalizedResourceOffer

    public NormalizedResourceOffer()
    Create an offer with all resources set to 0.

  - ### NormalizedResourceOffer

    public NormalizedResourceOffer(NormalizedResourceOffer other)
    Copy Constructor.
    Parameters:
      `other` - what to copy.

- ## Method Details

  - ### getTotalMemoryMb

    public double getTotalMemoryMb()
    Specified by:
      `getTotalMemoryMb` in interface `NormalizedResourcesWithMemory`

  - ### toNormalizedMap

    public Map<String,Double> toNormalizedMap()
    Return these resources as a normalized map.
    Returns:
      the normalized map.

  - ### add

    public void add(NormalizedResourcesWithMemory other)

  - ### remove

    public boolean remove(NormalizedResourcesWithMemory other, ResourceMetrics resourceMetrics)
    Remove the resources in other from this.
    Parameters:
      `other` - the resources to be removed.
      `resourceMetrics` - The resource related metrics
    Returns:
      true if one or more resources in other were larger than available resources in this, else false.

  - ### remove

    public boolean remove(NormalizedResourcesWithMemory other)

  - ### remove

    public boolean remove(WorkerResources other, ResourceMetrics resourceMetrics)
    Remove the resources in other from this.
    Parameters:
      `other` - the resources to be removed.
      `resourceMetrics` - The resource related metrics
    Returns:
      true if one or more resources in other were larger than available resources in this, else false.

  - ### calculateAveragePercentageUsedBy

    public double calculateAveragePercentageUsedBy(NormalizedResourceOffer used)
    Calculate the average percentage used.
    See Also:
      - `NormalizedResources.calculateAveragePercentageUsedBy(org.apache.storm.scheduler.resource.normalization.NormalizedResources, double, double)`

  - ### calculateMinPercentageUsedBy

    public double calculateMinPercentageUsedBy(NormalizedResourceOffer used)
    Calculate the min percentage used of the resource.
    See Also:
      - `NormalizedResources.calculateMinPercentageUsedBy(org.apache.storm.scheduler.resource.normalization.NormalizedResources, double, double)`

  - ### couldHoldIgnoringSharedMemory

    public boolean couldHoldIgnoringSharedMemory(NormalizedResourcesWithMemory other)
    Check if resources might be able to fit.
    See Also:
      - `NormalizedResources.couldHoldIgnoringSharedMemory(org.apache.storm.scheduler.resource.normalization.NormalizedResources, double, double)`

  - ### couldHoldIgnoringSharedMemoryAndCpu

    public boolean couldHoldIgnoringSharedMemoryAndCpu(NormalizedResourcesWithMemory other)

  - ### getTotalCpu

    public double getTotalCpu()

  - ### getNormalizedResources

    public NormalizedResources getNormalizedResources()
    Specified by:
      `getNormalizedResources` in interface `NormalizedResourcesWithMemory`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### updateForRareResourceAffinity

    public void updateForRareResourceAffinity(NormalizedResourceRequest requestedResources)
    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.
    Parameters:
      `requestedResources` - the requested resources.

  - ### clear

    public void clear()
    Description copied from interface: `NormalizedResourcesWithMemory`
    Set all resources to 0.
    Specified by:
      `clear` in interface `NormalizedResourcesWithMemory`

  - ### areAnyOverZero

    public boolean areAnyOverZero()
    Description copied from interface: `NormalizedResourcesWithMemory`
    Return true if any of the resources are > 0.
    Specified by:
      `areAnyOverZero` in interface `NormalizedResourcesWithMemory`

  - ### couldFit

    public boolean couldFit(double minWorkerCpu, NormalizedResourceRequest requestedResources)
    Is there any possibility that a resource request could ever fit on this.
    Parameters:
      `minWorkerCpu` - the configured minimum worker CPU
      `requestedResources` - the requested resources
    Returns:
      true if there is the possibility it might fit, no guarantee that it will, or false if there is no way it would ever fit.