metascheduler

package
v1.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2024 License: LGPL-3.0 Imports: 31 Imported by: 0

Documentation

Overview

Package metascheduler defines APIs for interacting with the DeepSquare Grid.

Package metascheduler providers implementations for interacting with the smart-contract.

Index

Constants

View Source
const DefaultOracleURL = "https://meta-scheduler.deepsquare.run"

DefaultOracleURL is the default oracle URL.

Variables

View Source
var ErrDivByZero = errors.New("division by zero")

ErrDivByZero is the error returned when a division by zero happens.

View Source
var (
	// ErrNewRequestJobNotFound happens when submitting a job, but the job is not found.
	//
	// This would typically be used for panicking.
	ErrNewRequestJobNotFound = errors.New("new request job event not found")
)

Functions

func CheckAffinities added in v1.5.0

func CheckAffinities(
	affinities []types.Affinity,
	labels []metaschedulerabi.Label,
) bool

CheckAffinities checks if the given labels satisfy the given affinities.

func CheckReceiptError added in v1.5.4

func CheckReceiptError(
	ctx context.Context,
	client ethereum.GasEstimator,
	tx *types.Transaction,
	receipt *types.Receipt,
) error

func CompareValues added in v1.5.0

func CompareValues(op, valueA, valueB string) bool

CompareValues compares two values using the given operator.

func CreditToDuration

func CreditToDuration(
	prices metaschedulerabi.ProviderPrices,
	definition metaschedulerabi.JobDefinition,
	creditsWei *big.Int,
) (*big.Int, error)

CreditToDuration converts credits to a job duration based on pricing and resources allocation.

func DurationToCredit

func DurationToCredit(
	prices metaschedulerabi.ProviderPrices,
	definition metaschedulerabi.JobDefinition,
	durationMinutes *big.Int,
) *big.Int

DurationToCredit converts a job duration to credits based on pricing and resources allocation.

func IsPanicError

func IsPanicError(value byte) bool

IsPanicError checks if the byte of an error data is a panic error code.

func JobIDFromHex added in v1.2.2

func JobIDFromHex(jobID string) [32]byte

JobIDFromHex converts a 32 bytes hexstring to a jobID

func JobIDToHex added in v1.2.2

func JobIDToHex(jobID [32]byte) string

JobIDToHex converts a jobID to an 32 bytes hexstring

func ParseArrayLengthMismatch

func ParseArrayLengthMismatch(inputs []interface{}) error

func ParseDoubleEndedQueueError

func ParseDoubleEndedQueueError(name string, inputs []interface{}) error

func ParseError

func ParseError(name string, inputs []interface{}) error

func ParseInvalidNodesCount

func ParseInvalidNodesCount(inputs []interface{}) error

func ParseInvalidTotalCpus

func ParseInvalidTotalCpus(inputs []interface{}) error

func ParseInvalidTotalMem

func ParseInvalidTotalMem(inputs []interface{}) error

func ParseNoJob

func ParseNoJob(inputs []interface{}) error

func WrapError

func WrapError(originalErr error) (newErr error)

Types

type AllowanceManager added in v1.5.4

type AllowanceManager struct {
	*RPCClientSet
	*metaschedulerabi.IERC20
}

AllowanceManager is a manager for allowances.

func (*AllowanceManager) ClearAllowance added in v1.5.4

func (c *AllowanceManager) ClearAllowance(ctx context.Context) error

ClearAllowance clears the allowance for the metascheduler.

func (*AllowanceManager) GetAllowance added in v1.5.4

func (c *AllowanceManager) GetAllowance(ctx context.Context) (*big.Int, error)

GetAllowance gets the allowance for the metascheduler.

func (*AllowanceManager) ReduceToAllowance added in v1.5.4

func (c *AllowanceManager) ReduceToAllowance(
	ctx context.Context,
	approvals <-chan types.Approval,
) (<-chan *big.Int, error)

ReduceToAllowance reduces the stream of allowance to the allowance.

func (*AllowanceManager) SetAllowance added in v1.5.4

func (c *AllowanceManager) SetAllowance(ctx context.Context, amount *big.Int) error

SetAllowance sets the allowance for the metascheduler.

type AlreadyDone

type AlreadyDone struct{}

func ParseAlreadyDone

func ParseAlreadyDone(_ []interface{}) *AlreadyDone

func (*AlreadyDone) Error

func (e *AlreadyDone) Error() string

type ArrayLengthMismatch

type ArrayLengthMismatch struct{}

func (*ArrayLengthMismatch) Error

func (e *ArrayLengthMismatch) Error() string

type Backend

type Backend struct {
	MetaschedulerAddress common.Address
	// EthereumBackend is the Ethereum Client.
	EthereumBackend
	// ChainID of the blockchain.
	ChainID *big.Int
	// PrivateKey of the user.
	UserPrivateKey *ecdsa.PrivateKey
}

Backend is a wrapper around the EthereumBackend used to interact with the Meta-Scheduler smart-contract.

type Banned

type Banned struct{}

func ParseBanned

func ParseBanned(_ []interface{}) *Banned

func (*Banned) Error

func (e *Banned) Error() string

type CreditManager added in v1.5.4

type CreditManager struct {
	*RPCClientSet
	*metaschedulerabi.IERC20
}

CreditManager is a manager for credits.

func (*CreditManager) Balance added in v1.5.4

func (c *CreditManager) Balance(ctx context.Context) (*big.Int, error)

Balance returns the balance of the user.

func (*CreditManager) BalanceOf added in v1.5.4

func (c *CreditManager) BalanceOf(ctx context.Context, address common.Address) (*big.Int, error)

BalanceOf returns the balance of the given address.

func (*CreditManager) ReduceToBalance added in v1.5.4

func (c *CreditManager) ReduceToBalance(
	ctx context.Context,
	transfers <-chan types.Transfer,
) (<-chan *big.Int, error)

ReduceToBalance reduces the balance to the given value.

func (*CreditManager) Transfer added in v1.5.4

func (c *CreditManager) Transfer(ctx context.Context, to common.Address, amount *big.Int) error

Transfer transfers the given amount to the given address.

type CustomerMetaSchedulerProviderOnly

type CustomerMetaSchedulerProviderOnly struct{}

func ParseCustomerMetaSchedulerProviderOnly

func ParseCustomerMetaSchedulerProviderOnly(
	inputs []interface{},
) *CustomerMetaSchedulerProviderOnly

func (*CustomerMetaSchedulerProviderOnly) Error

type CustomerOnly

type CustomerOnly struct {
	Current  common.Address
	Expected common.Address
}

func ParseCustomerOnly

func ParseCustomerOnly(inputs []interface{}) *CustomerOnly

func (*CustomerOnly) Error

func (e *CustomerOnly) Error() string

type DoubleEndedQueueEmpty

type DoubleEndedQueueEmpty struct{}

func ParseDoubleEndedQueueEmpty

func ParseDoubleEndedQueueEmpty(inputs []interface{}) *DoubleEndedQueueEmpty

func (*DoubleEndedQueueEmpty) Error

func (e *DoubleEndedQueueEmpty) Error() string

type DoubleEndedQueueOutOfBounds

type DoubleEndedQueueOutOfBounds struct{}

func ParseDoubleEndedQueueOutOfBounds

func ParseDoubleEndedQueueOutOfBounds(inputs []interface{}) *DoubleEndedQueueOutOfBounds

func (*DoubleEndedQueueOutOfBounds) Error

type EthereumBackend

type EthereumBackend interface {
	bind.ContractBackend
	bind.DeployBackend
}

EthereumBackend combines bind.ContractBackend and bind.DeployBackend.

type EventSubscriber added in v1.5.4

type EventSubscriber struct {
	// contains filtered or unexported fields
}

EventSubscriber is a subscriber for events.

func NewEventSubscriber

func NewEventSubscriber(
	rpc Backend,
	ws Backend,
) *EventSubscriber

NewEventSubscriber creates an EventSubscriber used to watch events.

func (*EventSubscriber) SubscribeEvents added in v1.5.4

func (c *EventSubscriber) SubscribeEvents(
	ctx context.Context,
	opts ...event.SubscriptionOption,
) (ethereum.Subscription, error)

SubscribeEvents subscribes to events.

type InsufficientFunds

type InsufficientFunds struct {
	Available *big.Int
	Required  *big.Int
}

func ParseInsufficientFunds

func ParseInsufficientFunds(inputs []interface{}) *InsufficientFunds

func (*InsufficientFunds) Error

func (e *InsufficientFunds) Error() string

type InvalidJob

type InvalidJob struct{}

func ParseInvalidJob

func ParseInvalidJob(inputs []interface{}) *InvalidJob

func (*InvalidJob) Error

func (e *InvalidJob) Error() string

type InvalidJobDefinition

type InvalidJobDefinition struct{}

func ParseInvalidJobDefinition

func ParseInvalidJobDefinition(
	inputs []interface{},
) *InvalidJobDefinition

func (*InvalidJobDefinition) Error

func (e *InvalidJobDefinition) Error() string

type InvalidNodesCount

type InvalidNodesCount struct{}

func (*InvalidNodesCount) Error

func (e *InvalidNodesCount) Error() string

type InvalidTotalCpus

type InvalidTotalCpus struct{}

func (*InvalidTotalCpus) Error

func (e *InvalidTotalCpus) Error() string

type InvalidTotalMem

type InvalidTotalMem struct{}

func (*InvalidTotalMem) Error

func (e *InvalidTotalMem) Error() string

type InvalidTransition

type InvalidTransition struct {
	From JobStatus
	To   JobStatus
}

func ParseInvalidTransition

func ParseInvalidTransition(inputs []interface{}) *InvalidTransition

func (*InvalidTransition) Error

func (e *InvalidTransition) Error() string

type JobFetcher added in v1.5.4

type JobFetcher struct {
	*RPCClientSet
	*metaschedulerabi.IJobRepository
}

JobFetcher is a fetcher for jobs.

func (*JobFetcher) GetJob added in v1.5.4

func (c *JobFetcher) GetJob(ctx context.Context, id [32]byte) (types.Job, error)

GetJob returns a job by its ID.

func (*JobFetcher) GetJobs added in v1.5.4

func (c *JobFetcher) GetJobs(ctx context.Context) (*job.Iterator, error)

GetJobs returns all jobs of the user.

func (*JobFetcher) Next added in v1.5.4

func (c *JobFetcher) Next(ctx context.Context, it job.LazyIterator) (ok bool)

Next returns the next job in the iterator.

type JobHotStatusOnly

type JobHotStatusOnly struct {
	Current JobStatus
}

func ParseJobHotStatusOnly

func ParseJobHotStatusOnly(inputs []interface{}) *JobHotStatusOnly

func (*JobHotStatusOnly) Error

func (e *JobHotStatusOnly) Error() string

type JobProviderOnly

type JobProviderOnly struct {
	Current  common.Address
	Expected common.Address
}

func ParseJobProviderOnly

func ParseJobProviderOnly(inputs []interface{}) *JobProviderOnly

func (*JobProviderOnly) Error

func (e *JobProviderOnly) Error() string

type JobScheduler added in v1.5.4

type JobScheduler struct {
	*RPCClientSet
	*metaschedulerabi.MetaScheduler
	*sbatch.Service
}

JobScheduler is a scheduler for jobs.

func (*JobScheduler) CancelJob added in v1.5.4

func (c *JobScheduler) CancelJob(ctx context.Context, id [32]byte) error

CancelJob cancels the job with the given ID.

func (*JobScheduler) PanicJob added in v1.5.4

func (c *JobScheduler) PanicJob(ctx context.Context, id [32]byte, reason string) error

PanicJob panics the job with the given reason.

func (*JobScheduler) SubmitJob added in v1.5.4

func (c *JobScheduler) SubmitJob(
	ctx context.Context,
	j *sbatch.Job,
	lockedAmount *big.Int,
	jobName [32]byte,
	opts ...job.SubmitJobOption,
) ([32]byte, error)

SubmitJob submits a job to the scheduler.

func (*JobScheduler) TopUpJob added in v1.5.4

func (c *JobScheduler) TopUpJob(ctx context.Context, id [32]byte, amount *big.Int) error

TopUpJob tops up the job with the given amount.

type JobStatus

type JobStatus uint8

JobStatus is the job status stored in the smart-contract.

const (
	// JobStatusPending means the job has been submitted, but the meta-scheduler
	// hasn't considered to schedule it yet.
	JobStatusPending JobStatus = 0
	// JobStatusMetaScheduled means that the job has been scheduled to a cluster, but that cluster has not yet handled it.
	JobStatusMetaScheduled JobStatus = 1
	// JobStatusScheduled means that the job has been scheduled to a worker node.
	JobStatusScheduled JobStatus = 2
	// JobStatusRunning means that the job is running on a worker node.
	JobStatusRunning JobStatus = 3
	// JobStatusCancelled means that the job has been cancelled by the user or admin.
	JobStatusCancelled JobStatus = 4
	// JobStatusFinished means that the job has finished with success.
	JobStatusFinished JobStatus = 5
	// JobStatusFailed means that the job has failed.
	JobStatusFailed JobStatus = 6
	// JobStatusOutOfCredits means that the job has timed out.
	JobStatusOutOfCredits JobStatus = 7
	// JobStatusPanicked means that the job has failed from an unexpected error.
	JobStatusPanicked JobStatus = 8
	// JobStatusUnknown is a unknown state.
	JobStatusUnknown JobStatus = 255
)

func (JobStatus) String

func (s JobStatus) String() string

type MetaScheduledScheduledStatusOnly

type MetaScheduledScheduledStatusOnly struct {
	Current JobStatus
}

func ParseMetaScheduledScheduledStatusOnly

func ParseMetaScheduledScheduledStatusOnly(
	inputs []interface{},
) *MetaScheduledScheduledStatusOnly

func (*MetaScheduledScheduledStatusOnly) Error

type NewJobRequestDisabled

type NewJobRequestDisabled struct{}

func ParseNewJobRequestDisabled

func ParseNewJobRequestDisabled(inputs []interface{}) *NewJobRequestDisabled

func (*NewJobRequestDisabled) Error

func (e *NewJobRequestDisabled) Error() string

type NoJob

type NoJob struct{}

func (*NoJob) Error

func (e *NoJob) Error() string

type NoProvider

type NoProvider struct{}

func ParseNoProvider

func ParseNoProvider(_ []interface{}) *NoProvider

func (*NoProvider) Error

func (e *NoProvider) Error() string

type NoSpendingAuthority

type NoSpendingAuthority struct{}

func ParseNoSpendingAuthority

func ParseNoSpendingAuthority(inputs []interface{}) *NoSpendingAuthority

func (*NoSpendingAuthority) Error

func (e *NoSpendingAuthority) Error() string

type Oracle added in v1.5.4

type Oracle struct {
	// contains filtered or unexported fields
}

Oracle is a client for the meta-scheduler oracle.

func NewOracle added in v1.2.2

func NewOracle(url string, opts OracleOptions) *Oracle

NewOracle instanciates an Oracle.

func (*Oracle) GetMetaScheduledJobIDs added in v1.5.4

func (o *Oracle) GetMetaScheduledJobIDs(ctx context.Context) ([][32]byte, error)

GetMetaScheduledJobIDs returns the IDs of all running jobs.

type OracleOptions added in v1.2.2

type OracleOptions struct {
	Client *http.Client
}

OracleOptions are options for the oracle.

type PanicError

type PanicError byte

PanicError is an native EVM error.

const (
	// PanicErrorAssertionError happens when `assert` fails.
	PanicErrorAssertionError PanicError = 0x1
	// PanicErrorArithmeticUnderOrOverflow happens when a number under or overflows.
	PanicErrorArithmeticUnderOrOverflow PanicError = 0x11
	// PanicErrorDivisionByZero happens when a number is divided by a zero denominator.
	PanicErrorDivisionByZero PanicError = 0x12
	// PanicErrorEnumConversionOutOfBounds happens when a number is out of bounds of an enum.
	PanicErrorEnumConversionOutOfBounds PanicError = 0x21
	// PanicErrorIncorrectlyEncodedStorageByteArray happens when byte array is badly encoded.
	PanicErrorIncorrectlyEncodedStorageByteArray PanicError = 0x22
	// PanicErrorPopOnEmptyArray happens when calling pop on an empty array.
	PanicErrorPopOnEmptyArray PanicError = 0x31
	// PanicErrorArrayAccessOutOfBounds happens when calling an element from an index out of bounds of an array.
	PanicErrorArrayAccessOutOfBounds PanicError = 0x32
	// PanicErrorTooMuchMemoryAllocated happens when there is too much memory allocated for the EVM.
	PanicErrorTooMuchMemoryAllocated PanicError = 0x41
	// PanicErrorZeroInitializedVariable happens when a variable is not initialized and it is forbidden to use the zero value of that variable.
	PanicErrorZeroInitializedVariable PanicError = 0x51
)

func (PanicError) Error

func (e PanicError) Error() string

type ProviderManager added in v1.5.4

type ProviderManager struct {
	*RPCClientSet
	*metaschedulerabi.IProviderManager
}

ProviderManager is a manager for providers.

func (*ProviderManager) ApproveProvider added in v1.5.4

func (c *ProviderManager) ApproveProvider(ctx context.Context, provider common.Address) error

ApproveProvider approves a provider.

func (*ProviderManager) GetProvider added in v1.5.4

func (c *ProviderManager) GetProvider(
	ctx context.Context,
	address common.Address,
	opts ...provider.GetProviderOption,
) (detail provider.Detail, err error)

GetProvider returns a provider.

func (*ProviderManager) GetProviders added in v1.5.4

func (c *ProviderManager) GetProviders(
	ctx context.Context,
	opts ...provider.GetProviderOption,
) (providers []provider.Detail, err error)

GetProviders returns all providers.

func (*ProviderManager) RemoveProvider added in v1.5.4

func (c *ProviderManager) RemoveProvider(ctx context.Context, provider common.Address) error

RemoveProvider removes a provider.

type ProviderNotJoined

type ProviderNotJoined struct{}

func ParseProviderNotJoined

func ParseProviderNotJoined(inputs []interface{}) *ProviderNotJoined

func (*ProviderNotJoined) Error

func (e *ProviderNotJoined) Error() string

type RPCClientSet

type RPCClientSet struct {
	*Backend
}

RPCClientSet is a set of clients that interact with DeepSquare.

func NewRPCClientSet

func NewRPCClientSet(b Backend) *RPCClientSet

NewRPCClientSet creates an RPCClientSet.

func (*RPCClientSet) AllowanceManager

func (c *RPCClientSet) AllowanceManager() *AllowanceManager

AllowanceManager creates an AllowanceManager.

func (*RPCClientSet) CreditManager

func (c *RPCClientSet) CreditManager() *CreditManager

CreditManager creates a CreditManager.

func (*RPCClientSet) JobFetcher

func (c *RPCClientSet) JobFetcher() *JobFetcher

JobFetcher creates a JobFetcher.

func (*RPCClientSet) JobScheduler

func (c *RPCClientSet) JobScheduler(
	sbatch *sbatch.Service,
) *JobScheduler

JobScheduler creates a JobScheduler.

func (*RPCClientSet) ProviderManager

func (c *RPCClientSet) ProviderManager() *ProviderManager

ProviderManager creates a ProviderManager.

type RemainingTimeAboveLimit

type RemainingTimeAboveLimit struct {
	Remaining *big.Int
	Limit     *big.Int
}

func ParseRemainingTimeAboveLimit

func ParseRemainingTimeAboveLimit(
	inputs []interface{},
) *RemainingTimeAboveLimit

func (*RemainingTimeAboveLimit) Error

func (e *RemainingTimeAboveLimit) Error() string

type RunningColdStatusOnly

type RunningColdStatusOnly struct {
	Current JobStatus
}

func ParseRunningColdStatusOnly

func ParseRunningColdStatusOnly(
	inputs []interface{},
) *RunningColdStatusOnly

func (*RunningColdStatusOnly) Error

func (e *RunningColdStatusOnly) Error() string

type RunningJobsByProviderFetcher added in v1.5.4

type RunningJobsByProviderFetcher struct {
	job.MetaScheduledIDsFetcher
	job.Fetcher
}

RunningJobsByProviderFetcher is a fetcher for jobs by provider.

func NewJobsByProviderFetcher added in v1.2.2

func NewJobsByProviderFetcher(
	oracle job.MetaScheduledIDsFetcher,
	fetcher job.Fetcher,
) *RunningJobsByProviderFetcher

NewJobsByProviderFetcher instanciates a JobsByProviderFetcher.

func (*RunningJobsByProviderFetcher) GetJobsByProvider added in v1.5.4

func (f *RunningJobsByProviderFetcher) GetJobsByProvider(
	ctx context.Context,
	providerAddress common.Address,
) ([]types.Job, error)

GetJobsByProvider returns all jobs for a given provider.

type RunningScheduledStatusOnly

type RunningScheduledStatusOnly struct {
	Current JobStatus
}

func ParseRunningScheduledStatusOnly

func ParseRunningScheduledStatusOnly(
	inputs []interface{},
) *RunningScheduledStatusOnly

func (*RunningScheduledStatusOnly) Error

type SameStatusError

type SameStatusError struct{}

func ParseSameStatusError

func ParseSameStatusError(inputs []interface{}) *SameStatusError

func (*SameStatusError) Error

func (e *SameStatusError) Error() string

type WaitingApprovalOnly

type WaitingApprovalOnly struct{}

func ParseWaitingApprovalOnly

func ParseWaitingApprovalOnly(_ []interface{}) *WaitingApprovalOnly

func (*WaitingApprovalOnly) Error

func (e *WaitingApprovalOnly) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL