Documentation ¶
Index ¶
- Constants
- Variables
- func ReservationCreate(ctx context.Context, db *mongo.Database, r Reservation) (schema.ID, error)
- func ReservationLastID(ctx context.Context, db *mongo.Database) (schema.ID, error)
- func ReservationPushSignature(ctx context.Context, db *mongo.Database, id schema.ID, mode SignatureMode, ...) error
- func ReservationSetNextAction(ctx context.Context, db *mongo.Database, id schema.ID, ...) error
- func ReservationToDeploy(ctx context.Context, db *mongo.Database, reservation *Reservation) error
- func ResultPush(ctx context.Context, db *mongo.Database, id schema.ID, result Result) error
- func SaveUserConversion(ctx context.Context, db *mongo.Database, user schema.ID, ...) error
- func SetUserConversionSucceeded(ctx context.Context, db *mongo.Database, user schema.ID) error
- func Setup(ctx context.Context, db *mongo.Database) error
- func WorkloadCreate(ctx context.Context, db *mongo.Database, w WorkloaderType) (schema.ID, error)
- func WorkloadPop(ctx context.Context, db *mongo.Database, id schema.ID) error
- func WorkloadPush(ctx context.Context, db *mongo.Database, w ...WorkloaderType) error
- func WorkloadPushSignature(ctx context.Context, db *mongo.Database, id schema.ID, mode SignatureMode, ...) error
- func WorkloadResultPush(ctx context.Context, db *mongo.Database, id schema.ID, result Result) error
- func WorkloadSetNextAction(ctx context.Context, db *mongo.Database, id schema.ID, ...) error
- func WorkloadToDeploy(ctx context.Context, db *mongo.Database, w WorkloaderType) error
- func WorkloadTypePop(ctx context.Context, db *mongo.Database, id string, nodeID string) error
- func WorkloadTypePush(ctx context.Context, db *mongo.Database, w WorkloaderType) error
- func WorkloadsLastID(ctx context.Context, db *mongo.Database) (schema.ID, error)
- type ConversionDoc
- type Pipeline
- type QueueFilter
- type Reservation
- func (r *Reservation) AllDeleted() bool
- func (r *Reservation) Expired() bool
- func (r *Reservation) GatewayIDs() []string
- func (r *Reservation) IsAny(status ...generated.NextActionEnum) bool
- func (r *Reservation) IsSuccessfullyDeployed() bool
- func (r *Reservation) NodeIDs() []string
- func (r *Reservation) ResultOf(id string) *Result
- func (r *Reservation) SignatureVerify(pk string, sig []byte) error
- func (r *Reservation) Validate() error
- func (r *Reservation) Verify(pk string, sig []byte) error
- func (r *Reservation) Workloads(nodeID string) []WorkloaderType
- type ReservationFilter
- func (f ReservationFilter) Count(ctx context.Context, db *mongo.Database) (int64, error)
- func (f ReservationFilter) Find(ctx context.Context, db *mongo.Database, opts ...*options.FindOptions) (*mongo.Cursor, error)
- func (f ReservationFilter) Get(ctx context.Context, db *mongo.Database) (reservation Reservation, err error)
- func (f ReservationFilter) Or(o ReservationFilter) ReservationFilter
- func (f ReservationFilter) WithCustomerID(customerID int64) ReservationFilter
- func (f ReservationFilter) WithID(id schema.ID) ReservationFilter
- func (f ReservationFilter) WithIDGE(id schema.ID) ReservationFilter
- func (f ReservationFilter) WithNextAction(action generated.NextActionEnum) ReservationFilter
- func (f ReservationFilter) WithNodeID(id string) ReservationFilter
- type Result
- type SignatureMode
- type Workload
- type WorkloadFilter
- func (f WorkloadFilter) Count(ctx context.Context, db *mongo.Database) (int64, error)
- func (f WorkloadFilter) Find(ctx context.Context, db *mongo.Database, opts ...*options.FindOptions) ([]WorkloaderType, error)
- func (f WorkloadFilter) FindCursor(ctx context.Context, db *mongo.Database, opts ...*options.FindOptions) (*mongo.Cursor, error)
- func (f WorkloadFilter) Get(ctx context.Context, db *mongo.Database) (WorkloaderType, error)
- func (f WorkloadFilter) Or(o WorkloadFilter) WorkloadFilter
- func (f WorkloadFilter) WithCustomerID(customerID int) WorkloadFilter
- func (f WorkloadFilter) WithID(id schema.ID) WorkloadFilter
- func (f WorkloadFilter) WithIDGE(id schema.ID) WorkloadFilter
- func (f WorkloadFilter) WithNextAction(action generated.NextActionEnum) WorkloadFilter
- func (f WorkloadFilter) WithNodeID(id string) WorkloadFilter
- func (f WorkloadFilter) WithPoolID(poolID int64) WorkloadFilter
- func (f WorkloadFilter) WithReference(ref string) WorkloadFilter
- type WorkloadPipeline
- type WorkloaderType
- func (w *WorkloaderType) AllDeleted() bool
- func (w *WorkloaderType) IsAny(status ...generated.NextActionEnum) bool
- func (w *WorkloaderType) IsSuccessfullyDeployed() bool
- func (w WorkloaderType) MarshalBSON() ([]byte, error)
- func (w WorkloaderType) MarshalJSON() ([]byte, error)
- func (w *WorkloaderType) ResultOf(id string) *Result
- func (w *WorkloaderType) SignatureDeleteRequestVerify(pk string, sig generated.SigningSignature) error
- func (w *WorkloaderType) SignatureProvisionRequestVerify(pk string, sig generated.SigningSignature) error
- func (w *WorkloaderType) SignatureVerify(pk string, sig []byte) error
- func (w *WorkloaderType) UnmarshalBSON(buf []byte) error
- func (w *WorkloaderType) UnmarshalJSON(buf []byte) error
- func (w *WorkloaderType) Validate() error
- func (w *WorkloaderType) Verify(pk string, sig []byte) error
- func (w *WorkloaderType) Workload() Workload
Constants ¶
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 )
const (
// ConversionCollection name
ConversionCollection = "conversion"
)
const (
// ReservationCollection db collection name
ReservationCollection = "reservation"
)
const (
// WorkloadCollection db collection name
WorkloadCollection = "workload"
)
Variables ¶
var ErrNoConversion = errors.New("no conversion yet")
ErrNoConversion means no conversion is saved for a user
Functions ¶
func ReservationCreate ¶
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 ¶
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 ¶
ReservationToDeploy marks a reservation to deploy and schedule the workloads for the nodes it's a short cut to SetNextAction then PushWorkloads
func ResultPush ¶
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 ¶
SetUserConversionSucceeded updates the converted field
func Setup ¶
Setup sets up indexes for types, must be called at least Onetime during the life time of the object
func WorkloadCreate ¶
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 ¶
WorkloadPop removes workload from queue
func WorkloadPush ¶
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 ¶
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 ¶
WorkloadToDeploy marks a workload to deploy and schedule it for the nodes it's a short cut to SetNextAction then PushWorkloads
func WorkloadTypePop ¶
WorkloadTypePop removes workload from queue
func WorkloadTypePush ¶
WorkloadTypePush pushes a workload to the queue
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 ¶
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 ¶
ReservationFilter type
func ApplyQueryFilter ¶
func ApplyQueryFilter(r *http.Request, filter ReservationFilter) (ReservationFilter, error)
ApplyQueryFilter parese the query string
func (ReservationFilter) Find ¶
func (f ReservationFilter) Find(ctx context.Context, db *mongo.Database, opts ...*options.FindOptions) (*mongo.Cursor, error)
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 ¶
func (f ReservationFilter) Or(o ReservationFilter) ReservationFilter
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 ¶
func (f ReservationFilter) WithID(id schema.ID) ReservationFilter
WithID filter reservation with ID
func (ReservationFilter) WithIDGE ¶
func (f ReservationFilter) WithIDGE(id schema.ID) ReservationFilter
WithIDGE return find reservations with
func (ReservationFilter) WithNextAction ¶
func (f ReservationFilter) WithNextAction(action generated.NextActionEnum) ReservationFilter
WithNextAction filter reservations with next action
func (ReservationFilter) WithNodeID ¶
func (f ReservationFilter) WithNodeID(id string) ReservationFilter
WithNodeID searsch reservations with NodeID
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 ¶
WorkloadFilter type
func ApplyQueryFilterWorkload ¶
func ApplyQueryFilterWorkload(r *http.Request, filter WorkloadFilter) (WorkloadFilter, error)
ApplyQueryFilterWorkload parses the query string
func (WorkloadFilter) Find ¶
func (f WorkloadFilter) Find(ctx context.Context, db *mongo.Database, opts ...*options.FindOptions) ([]WorkloaderType, error)
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 ¶
func (f WorkloadFilter) Get(ctx context.Context, db *mongo.Database) (WorkloaderType, error)
Get gets single workload that matches the filter
func (WorkloadFilter) Or ¶
func (f WorkloadFilter) Or(o WorkloadFilter) WorkloadFilter
Or returns filter that reads as (f or o)
func (WorkloadFilter) WithCustomerID ¶
func (f WorkloadFilter) WithCustomerID(customerID int) 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) WithReference ¶
func (f WorkloadFilter) WithReference(ref string) WorkloadFilter
WithReference searches workloads with reference
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