github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/compute/capacity/types.go (about)

     1  package capacity
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/filecoin-project/bacalhau/pkg/model"
     7  )
     8  
     9  // Tracker keeps track of the current resource usage of the compute node.
    10  // The regular flow is to call AddIfHasCapacity before starting a new execution to reserve capacity, and Remove after
    11  // the execution is done to release the reserved capacity.
    12  type Tracker interface {
    13  	// IsWithinLimits returns true if the given resource usage is within the limits of the compute node.
    14  	// Limits refer to the total capacity of the compute node, and not to the currently available capacity.
    15  	IsWithinLimits(ctx context.Context, usage model.ResourceUsageData) bool
    16  	// AddIfHasCapacity atomically adds the given resource usage to the tracker if the compute node has capacity for it.
    17  	AddIfHasCapacity(ctx context.Context, usage model.ResourceUsageData) bool
    18  	// GetAvailableCapacity returns the available capacity of the compute node.
    19  	GetAvailableCapacity(ctx context.Context) model.ResourceUsageData
    20  	// GetMaxCapacity returns the total capacity of the compute node.
    21  	GetMaxCapacity(ctx context.Context) model.ResourceUsageData
    22  	// Remove removes the given resource usage from the tracker.
    23  	Remove(ctx context.Context, usage model.ResourceUsageData)
    24  }
    25  
    26  // UsageCalculator calculates the resource usage of a job.
    27  // Can also be used to populate the resource usage of a job with default values if not defined
    28  type UsageCalculator interface {
    29  	Calculate(ctx context.Context, job model.Job, parsedUsage model.ResourceUsageData) (model.ResourceUsageData, error)
    30  }
    31  
    32  // Provider returns the available capacity of a compute node.
    33  // Implementation can return local node capacity if operating with a single node, or capacity of a cluster if compute
    34  // is backed by a fleet of nodes.
    35  type Provider interface {
    36  	GetAvailableCapacity(ctx context.Context) (model.ResourceUsageData, error)
    37  }