types

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Create action
	Create = generated.NextActionCreate
	// Sign action
	Sign = generated.NextActionSign
	// Pay action
	Pay = generated.NextActionPay
	// Deploy action
	Deploy = generated.NextActionDeploy
	// Delete action
	Delete = generated.NextActionDelete
	// Invalid action
	Invalid = generated.NextActionInvalid
	// Deleted action
	Deleted = generated.NextActionDeleted
)
View Source
const (
	// ConversionCollection name
	ConversionCollection = "conversion"
)
View Source
const (
	// ReservationCollection db collection name
	ReservationCollection = "reservation"
)
View Source
const (
	// WorkloadCollection db collection name
	WorkloadCollection = "workload"
)

Variables

View Source
var ErrNoConversion = errors.New("no conversion yet")

ErrNoConversion means no conversion is saved for a user

Functions

func ReservationCreate

func ReservationCreate(ctx context.Context, db *mongo.Database, r Reservation) (schema.ID, error)

ReservationCreate save new reservation to database. NOTE: use reservations only that are returned from calling Pipeline.Next() no validation is done here, this is just a CRUD operation

func ReservationLastID

func ReservationLastID(ctx context.Context, db *mongo.Database) (schema.ID, error)

ReservationLastID get the current last ID number in the reservations collection

func ReservationPushSignature

func ReservationPushSignature(ctx context.Context, db *mongo.Database, id schema.ID, mode SignatureMode, signature generated.SigningSignature) error

ReservationPushSignature push signature to reservation

func ReservationSetNextAction

func ReservationSetNextAction(ctx context.Context, db *mongo.Database, id schema.ID, action generated.NextActionEnum) error

ReservationSetNextAction update the reservation next action in db

func ReservationToDeploy

func ReservationToDeploy(ctx context.Context, db *mongo.Database, reservation *Reservation) error

ReservationToDeploy marks a reservation to deploy and schedule the workloads for the nodes it's a short cut to SetNextAction then PushWorkloads

func ResultPush

func ResultPush(ctx context.Context, db *mongo.Database, id schema.ID, result Result) error

ResultPush pushes result to a reservation result array. NOTE: this is just a crud operation, no validation is done here

func SaveUserConversion

func SaveUserConversion(ctx context.Context, db *mongo.Database, user schema.ID, workloads []WorkloaderType) error

SaveUserConversion saves a conversion for a user

func SetUserConversionSucceeded

func SetUserConversionSucceeded(ctx context.Context, db *mongo.Database, user schema.ID) error

SetUserConversionSucceeded updates the converted field

func Setup

func Setup(ctx context.Context, db *mongo.Database) error

Setup sets up indexes for types, must be called at least Onetime during the life time of the object

func WorkloadCreate

func WorkloadCreate(ctx context.Context, db *mongo.Database, w WorkloaderType) (schema.ID, error)

WorkloadCreate save new workload to database. NOTE: use reservations only that are returned from calling Pipeline.Next() no validation is done here, this is just a CRUD operation

func WorkloadPop

func WorkloadPop(ctx context.Context, db *mongo.Database, id schema.ID) error

WorkloadPop removes workload from queue

func WorkloadPush

func WorkloadPush(ctx context.Context, db *mongo.Database, w ...WorkloaderType) error

WorkloadPush pushes a workload to the queue

func WorkloadPushSignature

func WorkloadPushSignature(ctx context.Context, db *mongo.Database, id schema.ID, mode SignatureMode, signature generated.SigningSignature) error

WorkloadPushSignature push signature to workload

func WorkloadResultPush

func WorkloadResultPush(ctx context.Context, db *mongo.Database, id schema.ID, result Result) error

WorkloadResultPush pushes result to a reservation result array. NOTE: this is just a crud operation, no validation is done here

func WorkloadSetNextAction

func WorkloadSetNextAction(ctx context.Context, db *mongo.Database, id schema.ID, action generated.NextActionEnum) error

WorkloadSetNextAction update the workload next action in db

func WorkloadToDeploy

func WorkloadToDeploy(ctx context.Context, db *mongo.Database, w WorkloaderType) error

WorkloadToDeploy marks a workload to deploy and schedule it for the nodes it's a short cut to SetNextAction then PushWorkloads

func WorkloadTypePop

func WorkloadTypePop(ctx context.Context, db *mongo.Database, id string, nodeID string) error

WorkloadTypePop removes workload from queue

func WorkloadTypePush

func WorkloadTypePush(ctx context.Context, db *mongo.Database, w WorkloaderType) error

WorkloadTypePush pushes a workload to the queue

func WorkloadsLastID

func WorkloadsLastID(ctx context.Context, db *mongo.Database) (schema.ID, error)

WorkloadsLastID get the current last ID number in the workloads collection

Types

type ConversionDoc

type ConversionDoc struct {
	User      schema.ID        `bson:"user"`
	Workloads []WorkloaderType `bson:"workloads"`
	Converted bool             `bson:"converted"`
	Timestamp int64            `bson:"timestamp"`
}

ConversionDoc holds some data about a geenrated conversion for a user

func GetUserConversion

func GetUserConversion(ctx context.Context, db *mongo.Database, user schema.ID) (ConversionDoc, error)

GetUserConversion loads a conversion for a user

type Pipeline

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

Pipeline changes Reservation R as defined by the reservation pipeline returns new reservation object, and true if the reservation has changed

func NewPipeline

func NewPipeline(R Reservation) (*Pipeline, error)

NewPipeline creates a reservation pipeline, all reservation must be processes through the pipeline before any action is taken. This will always make sure that reservation is in the right state.

func (*Pipeline) Next

func (p *Pipeline) Next() (Reservation, bool)

Next gets new modified reservation, and true if the reservation has changed from the input

type QueueFilter

type QueueFilter bson.D

QueueFilter for workloads in temporary queue

func (QueueFilter) Find

func (f QueueFilter) Find(ctx context.Context, db *mongo.Database, opts ...*options.FindOptions) (*mongo.Cursor, error)

Find runs the filter, and return a cursor

func (QueueFilter) WithNodeID

func (f QueueFilter) WithNodeID(nodeID string) QueueFilter

WithNodeID search queue with node-id

type Reservation

type Reservation generated.Reservation

Reservation is a wrapper around generated type

func (*Reservation) AllDeleted

func (r *Reservation) AllDeleted() bool

AllDeleted checks of all workloads has been marked

func (*Reservation) Expired

func (r *Reservation) Expired() bool

Expired checks if this reservation has expired

func (*Reservation) GatewayIDs

func (r *Reservation) GatewayIDs() []string

GatewayIDs return a list of all the gateway IDs used in this reservation

func (*Reservation) IsAny

func (r *Reservation) IsAny(status ...generated.NextActionEnum) bool

IsAny checks if the reservation status is any of the given status

func (*Reservation) IsSuccessfullyDeployed

func (r *Reservation) IsSuccessfullyDeployed() bool

IsSuccessfullyDeployed check if all the workloads defined in the reservation have sent a positive result

func (*Reservation) NodeIDs

func (r *Reservation) NodeIDs() []string

NodeIDs used by this reservation

func (*Reservation) ResultOf

func (r *Reservation) ResultOf(id string) *Result

ResultOf return result of a workload ID

func (*Reservation) SignatureVerify

func (r *Reservation) SignatureVerify(pk string, sig []byte) error

SignatureVerify is similar to Verify but the verification is done against `str(Reservation.ID) + Reservation.JSON`

func (*Reservation) Validate

func (r *Reservation) Validate() error

Validate that the reservation is valid

func (*Reservation) Verify

func (r *Reservation) Verify(pk string, sig []byte) error

Verify signature against Reserveration.JSON pk is the public key used as verification key in hex encoded format the signature is the signature to verify (in raw binary format)

func (*Reservation) Workloads

func (r *Reservation) Workloads(nodeID string) []WorkloaderType

Workloads returns all reservation workloads (filter by nodeID) if nodeID is empty, return all workloads

type ReservationFilter

type ReservationFilter bson.D

ReservationFilter type

func ApplyQueryFilter

func ApplyQueryFilter(r *http.Request, filter ReservationFilter) (ReservationFilter, error)

ApplyQueryFilter parese the query string

func (ReservationFilter) Count

func (f ReservationFilter) Count(ctx context.Context, db *mongo.Database) (int64, error)

Count number of documents matching

func (ReservationFilter) Find

Find all users that matches filter

func (ReservationFilter) Get

func (f ReservationFilter) Get(ctx context.Context, db *mongo.Database) (reservation Reservation, err error)

Get gets single reservation that matches the filter

func (ReservationFilter) Or

Or returns filter that reads as (f or o)

func (ReservationFilter) WithCustomerID

func (f ReservationFilter) WithCustomerID(customerID int64) ReservationFilter

WithCustomerID filter reservation on customer

func (ReservationFilter) WithID

WithID filter reservation with ID

func (ReservationFilter) WithIDGE

WithIDGE return find reservations with

func (ReservationFilter) WithNextAction

WithNextAction filter reservations with next action

func (ReservationFilter) WithNodeID

func (f ReservationFilter) WithNodeID(id string) ReservationFilter

WithNodeID searsch reservations with NodeID

type Result

type Result generated.Result

Result is a wrapper around TfgridWorkloadsReservationResult1 type

func (*Result) Verify

func (r *Result) Verify(pk string) error

Verify that the signature matches the result data

type SignatureMode

type SignatureMode string

SignatureMode type

const (
	// SignatureProvision mode
	SignatureProvision SignatureMode = "signatures_provision"
	// SignatureDelete mode
	SignatureDelete SignatureMode = "signatures_delete"
)

type Workload

type Workload struct {
	generated.ReservationWorkload `bson:",inline"`
	NodeID                        string `json:"node_id" bson:"node_id"`
}

Workload is a wrapper around generated TfgridWorkloadsReservationWorkload1 type

type WorkloadFilter

type WorkloadFilter bson.D

WorkloadFilter type

func ApplyQueryFilterWorkload

func ApplyQueryFilterWorkload(r *http.Request, filter WorkloadFilter) (WorkloadFilter, error)

ApplyQueryFilterWorkload parses the query string

func (WorkloadFilter) Count

func (f WorkloadFilter) Count(ctx context.Context, db *mongo.Database) (int64, error)

Count number of documents matching

func (WorkloadFilter) Find

Find all users workloads matches filter

func (WorkloadFilter) FindCursor

func (f WorkloadFilter) FindCursor(ctx context.Context, db *mongo.Database, opts ...*options.FindOptions) (*mongo.Cursor, error)

FindCursor all users workloads matches filter, and return a plain cursor to them

func (WorkloadFilter) Get

Get gets single workload that matches the filter

func (WorkloadFilter) Or

Or returns filter that reads as (f or o)

func (WorkloadFilter) WithCustomerID

func (f WorkloadFilter) WithCustomerID(customerID int64) WorkloadFilter

WithCustomerID filter workload on customer

func (WorkloadFilter) WithID

func (f WorkloadFilter) WithID(id schema.ID) WorkloadFilter

WithID filter workload with ID

func (WorkloadFilter) WithIDGE

func (f WorkloadFilter) WithIDGE(id schema.ID) WorkloadFilter

WithIDGE return find workloads with

func (WorkloadFilter) WithNextAction

func (f WorkloadFilter) WithNextAction(action generated.NextActionEnum) WorkloadFilter

WithNextAction filter workloads with next action

func (WorkloadFilter) WithNodeID

func (f WorkloadFilter) WithNodeID(id string) WorkloadFilter

WithNodeID searsch workloads with NodeID

func (WorkloadFilter) WithPoolID

func (f WorkloadFilter) WithPoolID(poolID int64) WorkloadFilter

WithPoolID searches for workloads with pool id

func (WorkloadFilter) WithPublicIP added in v0.4.8

func (f WorkloadFilter) WithPublicIP(publicIP schema.ID) WorkloadFilter

WithPublicIP filter workloads with a certain public ip

func (WorkloadFilter) WithReference

func (f WorkloadFilter) WithReference(ref string) WorkloadFilter

WithReference searches workloads with reference

func (WorkloadFilter) WithWorkloadType added in v0.4.8

func (f WorkloadFilter) WithWorkloadType(workloadType generated.WorkloadTypeEnum) WorkloadFilter

WithWorkloadType filter workloads with workload type

type WorkloadPipeline

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

WorkloadPipeline changes WorkloaderType W as defined by the workload pipeline returns new workload object, and true if the workload has changed

func NewWorkloaderPipeline

func NewWorkloaderPipeline(W WorkloaderType) (*WorkloadPipeline, error)

NewWorkloaderPipeline creates a reservation pipeline, all reservation must be processes through the pipeline before any action is taken. This will always make sure that reservation is in the right state.

func (*WorkloadPipeline) Next

func (p *WorkloadPipeline) Next() (WorkloaderType, bool)

Next gets new modified reservation, and true if the reservation has changed from the input

type WorkloaderType

type WorkloaderType struct {
	generated.Workloader
}

WorkloaderType is a wrapper struct around the Workloader interface

func (*WorkloaderType) AllDeleted

func (w *WorkloaderType) AllDeleted() bool

AllDeleted checks of all workloads has been marked

func (*WorkloaderType) IsAny

func (w *WorkloaderType) IsAny(status ...generated.NextActionEnum) bool

IsAny checks if the workload status is any of the given status

func (*WorkloaderType) IsSuccessfullyDeployed

func (w *WorkloaderType) IsSuccessfullyDeployed() bool

IsSuccessfullyDeployed check if all the workloads defined in the reservation have sent a positive result

func (WorkloaderType) MarshalBSON

func (w WorkloaderType) MarshalBSON() ([]byte, error)

MarshalBSON implements bson.Marshaller

func (WorkloaderType) MarshalJSON

func (w WorkloaderType) MarshalJSON() ([]byte, error)

MarshalJSON implements JSON.Marshaller

func (*WorkloaderType) ResultOf

func (w *WorkloaderType) ResultOf(id string) *Result

ResultOf return result of a workload ID

func (*WorkloaderType) SignatureDeleteRequestVerify

func (w *WorkloaderType) SignatureDeleteRequestVerify(pk string, sig generated.SigningSignature) error

SignatureDeleteRequestVerify verify the signature from a signature request this is used for workload delete the signature is created from the workload siging challenge + "delete" + customer tid

func (*WorkloaderType) SignatureProvisionRequestVerify

func (w *WorkloaderType) SignatureProvisionRequestVerify(pk string, sig generated.SigningSignature) error

SignatureProvisionRequestVerify verify the signature from a signature request this is used for provision the signature is created from the workload siging challenge + "provision" + customer tid

func (*WorkloaderType) SignatureVerify

func (w *WorkloaderType) SignatureVerify(pk string, sig []byte) error

SignatureVerify is similar to Verify but the verification is done against `str(WorkloaderType.ID) + WorkloaderType.JSON`

func (*WorkloaderType) UnmarshalBSON

func (w *WorkloaderType) UnmarshalBSON(buf []byte) error

UnmarshalBSON implements bson.Unmarshaller

func (*WorkloaderType) UnmarshalJSON

func (w *WorkloaderType) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements JSON.Unmarshaller

func (*WorkloaderType) Validate

func (w *WorkloaderType) Validate() error

Validate that the reservation is valid

func (*WorkloaderType) Verify

func (w *WorkloaderType) Verify(pk string, sig []byte) error

Verify signature against Workload.JSON pk is the public key used as verification key in hex encoded format the signature is the signature to verify (in raw binary format)

func (*WorkloaderType) Workload

func (w *WorkloaderType) Workload() Workload

Workload returns workload

Jump to

Keyboard shortcuts

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