models

package
v0.3.633 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: Apache-2.0 Imports: 16 Imported by: 105

Documentation

Index

Constants

View Source
const (
	// TypeNone ...
	TypeNone = ""
	// TypeSync ...
	TypeSync = "sync"
	// TypeAsync ...
	TypeAsync = "async"
	// TypeDetached is used for calls which return an ack to the caller as soon as the call starts
	TypeDetached = "detached"
)
View Source
const (
	MinMilliCPUs = 0       // 0 is unlimited
	MaxMilliCPUs = 1024000 // 1024 CPUs
)
View Source
const FnInvokeEndpointAnnotation = "fnproject.io/fn/invokeEndpoint"

FnInvokeEndpointAnnotation is the annotation that exposes the fn invoke endpoint For want of a better place to put this it's here

View Source
const (
	MaxTriggerName = 30
)

TODO we can put constants all in this file too

View Source
const TriggerHTTPEndpointAnnotation = "fnproject.io/trigger/httpEndpoint"

TriggerHTTPEndpointAnnotation is the annotation that exposes the HTTP trigger endpoint For want of a better place to put this it's here

View Source
const TriggerTypeHTTP = "http"

TriggerTypeHTTP represents an HTTP trigger

Variables

View Source
var (
	ErrAppsMissingID = err{
						// contains filtered or unexported fields
	}
	ErrAppIDProvided = err{
						// contains filtered or unexported fields
	}
	ErrAppsIDMismatch = err{
						// contains filtered or unexported fields
	}
	ErrAppsMissingName = err{
						// contains filtered or unexported fields
	}
	ErrAppsTooLongName = err{
						// contains filtered or unexported fields
	}
	ErrAppsInvalidName = err{
						// contains filtered or unexported fields
	}
	ErrAppsAlreadyExists = err{
							// contains filtered or unexported fields
	}
	ErrAppsMissingNew = err{
						// contains filtered or unexported fields
	}
	ErrAppsNameImmutable = err{
							// contains filtered or unexported fields
	}

	ErrAppsNotFound = err{
					// contains filtered or unexported fields
	}
)
View Source
var (
	ErrMethodNotAllowed = err{
						// contains filtered or unexported fields
	}

	ErrInvalidJSON = err{
					// contains filtered or unexported fields
	}
	ErrClientCancel = err{
					// contains filtered or unexported fields
	}
	ErrCallTimeout = err{
					// contains filtered or unexported fields
	}
	ErrCallTimeoutServerBusy = err{
								// contains filtered or unexported fields
	}
	ErrDockerPullTimeout = err{
							// contains filtered or unexported fields
	}
	ErrContainerInitTimeout = err{
							// contains filtered or unexported fields
	}
	ErrUnsupportedMediaType = err{
							// contains filtered or unexported fields
	}

	ErrMissingID = err{
					// contains filtered or unexported fields
	}

	ErrMissingAppID = err{
					// contains filtered or unexported fields
	}
	ErrMissingFnID = err{
					// contains filtered or unexported fields
	}
	ErrMissingName = err{
					// contains filtered or unexported fields
	}

	ErrCreatedAtProvided = err{
							// contains filtered or unexported fields
	}
	ErrUpdatedAtProvided = err{
							// contains filtered or unexported fields
	}

	ErrDatastoreEmptyApp = err{
							// contains filtered or unexported fields
	}
	ErrDatastoreEmptyCallID = err{
							// contains filtered or unexported fields
	}
	ErrDatastoreEmptyFn = err{
						// contains filtered or unexported fields
	}
	ErrDatastoreEmptyFnID = err{
							// contains filtered or unexported fields
	}
	ErrInvalidPayload = err{
						// contains filtered or unexported fields
	}
	ErrFoundDynamicURL = err{
						// contains filtered or unexported fields
	}
	ErrPathMalformed = err{
						// contains filtered or unexported fields
	}
	ErrInvalidToTime = err{
						// contains filtered or unexported fields
	}
	ErrInvalidFromTime = err{
						// contains filtered or unexported fields
	}
	ErrInvalidMemory = err{
						// contains filtered or unexported fields
	}
	ErrCallResourceTooBig = err{
							// contains filtered or unexported fields
	}
	ErrCallNotFound = err{
					// contains filtered or unexported fields
	}
	ErrInvalidCPUs = err{
					// contains filtered or unexported fields
	}
	ErrCallLogNotFound = err{
						// contains filtered or unexported fields
	}
	ErrPathNotFound = err{
					// contains filtered or unexported fields
	}
	ErrFunctionResponseTooBig = err{
								// contains filtered or unexported fields
	}
	ErrFunctionResponse = err{
						// contains filtered or unexported fields
	}
	ErrFunctionFailed = err{
						// contains filtered or unexported fields
	}
	ErrFunctionInvalidResponse = err{
								// contains filtered or unexported fields
	}
	ErrRequestContentTooBig = err{
							// contains filtered or unexported fields
	}
	ErrInvalidAnnotationKey = err{
							// contains filtered or unexported fields
	}
	ErrInvalidAnnotationKeyLength = err{
									// contains filtered or unexported fields
	}
	ErrInvalidAnnotationValue = err{
								// contains filtered or unexported fields
	}
	ErrInvalidAnnotationValueLength = err{
									// contains filtered or unexported fields
	}
	ErrTooManyAnnotationKeys = err{
								// contains filtered or unexported fields
	}
	ErrTooManyRequests = err{
						// contains filtered or unexported fields
	}
	ErrAsyncUnsupported = err{
						// contains filtered or unexported fields
	}

	ErrDetachUnsupported = err{
							// contains filtered or unexported fields
	}

	ErrCallHandlerNotFound = err{
							// contains filtered or unexported fields
	}
	ErrServiceReservationFailure = err{
									// contains filtered or unexported fields
	}
	ErrContainerInitFail = err{
							// contains filtered or unexported fields
	}
)
View Source
var (
	MaxMemory      uint64 = 8 * 1024 // 8GB
	MaxTimeout     int32  = 300      // 5m
	MaxIdleTimeout int32  = 3600     // 1h

	DefaultTimeout     int32  = 30  // seconds
	DefaultIdleTimeout int32  = 30  // seconds
	DefaultMemory      uint64 = 128 // MB

	MaxSyncTimeout  = 120  // 2 minutes
	MaxAsyncTimeout = 3600 // 1 hour

	ErrFnsIDMismatch = err{
						// contains filtered or unexported fields
	}
	ErrFnsIDProvided = err{
						// contains filtered or unexported fields
	}
	ErrFnsMissingID = err{
					// contains filtered or unexported fields
	}
	ErrFnsMissingName = err{
						// contains filtered or unexported fields
	}
	ErrFnsInvalidName = err{
						// contains filtered or unexported fields
	}
	ErrFnsTooLongName = err{
						// contains filtered or unexported fields
	}
	ErrFnsMissingAppID = err{
						// contains filtered or unexported fields
	}
	ErrFnsMissingImage = err{
						// contains filtered or unexported fields
	}
	ErrFnsInvalidImage = err{
						// contains filtered or unexported fields
	}
	ErrFnsInvalidTimeout = err{
							// contains filtered or unexported fields
	}
	ErrFnsInvalidIdleTimeout = err{
								// contains filtered or unexported fields
	}
	ErrFnsNotFound = err{
					// contains filtered or unexported fields
	}
	ErrFnsExists = err{
					// contains filtered or unexported fields
	}
)
View Source
var (
	//ErrTriggerIDProvided indicates that a trigger ID was specified when it shouldn't have been
	ErrTriggerIDProvided = err{
							// contains filtered or unexported fields
	}
	//ErrTriggerIDMismatch indicates an ID was provided that did not match the ID of the corresponding operation/call
	ErrTriggerIDMismatch = err{
							// contains filtered or unexported fields
	}
	//ErrTriggerMissingName - name not specified on a trigger object
	ErrTriggerMissingName = err{
							// contains filtered or unexported fields
	}
	//ErrTriggerTooLongName - name exceeds maximum permitted name
	ErrTriggerTooLongName = err{
							// contains filtered or unexported fields
	}
	//ErrTriggerInvalidName - name does not comply with naming spec
	ErrTriggerInvalidName = err{
							// contains filtered or unexported fields
	}
	//ErrTriggerMissingAppID - no API id specified on trigger creation
	ErrTriggerMissingAppID = err{
							// contains filtered or unexported fields
	}
	//ErrTriggerMissingFnID - no FNID specified on trigger creation
	ErrTriggerMissingFnID = err{
							// contains filtered or unexported fields
	}
	//ErrTriggerFnIDNotSameApp - specified Fn does not belong to the same app as the provided AppID
	ErrTriggerFnIDNotSameApp = err{
								// contains filtered or unexported fields
	}
	//ErrTriggerTypeUnknown - unsupported trigger type
	ErrTriggerTypeUnknown = err{
							// contains filtered or unexported fields
	}
	//ErrTriggerMissingSource - no source spceified for trigger
	ErrTriggerMissingSource = err{
							// contains filtered or unexported fields
	}
	//ErrTriggerMissingSourcePrefix - source does not have a / prefix
	ErrTriggerMissingSourcePrefix = err{
									// contains filtered or unexported fields
	}
	//ErrTriggerNotFound - trigger not found
	ErrTriggerNotFound = err{
						// contains filtered or unexported fields
	}
	//ErrTriggerExists - a trigger with the specified name already exists
	ErrTriggerExists = err{
						// contains filtered or unexported fields
	}
	//ErrTriggerSourceExists - another trigger on the same app has the same source and type
	ErrTriggerSourceExists = err{
							// contains filtered or unexported fields
	}
)

Functions

func GetAPIErrorCode

func GetAPIErrorCode(e error) int

func IsAPIError

func IsAPIError(e error) bool

func ValidTriggerType

func ValidTriggerType(a string) bool

ValidTriggerType checks that a given trigger type is valid on this service

func ValidTriggerTypes

func ValidTriggerTypes() []string

ValidTriggerTypes lists the supported trigger types in this service

Types

type APIError

type APIError interface {
	Code() int
	error
}

APIError any error that implements this interface will return an API response with the provided status code and error message body

func NewAPIError

func NewAPIError(code int, e error) APIError

type APIErrorWrapper

type APIErrorWrapper interface {
	APIError
	RootError() error
}

APIErrorWrapper wraps an error with an APIError such that the APIError governs the HTTP response but the root error remains accessible.

func NewAPIErrorWrapper

func NewAPIErrorWrapper(apiErr APIError, rootErr error) APIErrorWrapper

type Annotations

type Annotations map[string]*annotationValue

Annotations encapsulates key-value metadata associated with resource. The structure is immutable via its public API and nil-safe for its contract permissive nilability is here to simplify updates and reduce the need for nil handling in extensions - annotations should be updated by over-writing the original object:

target.Annotations  = target.Annotations.With("fooKey",1)

old MD remains empty Annotations is lenable

func EmptyAnnotations

func EmptyAnnotations() Annotations

func (Annotations) Equals

func (m Annotations) Equals(other Annotations) bool

Equals is defined based on un-ordered k/v comparison at of the annotation keys and (compacted) values of annotations, JSON object-value equality for values is property-order dependent

func (Annotations) Get

func (m Annotations) Get(key string) ([]byte, bool)

Get returns a raw JSON value of a annotation key

func (Annotations) GetString

func (m Annotations) GetString(key string) (string, error)

GetString returns a string value if the annotation value is a string, otherwise an error

func (Annotations) MergeChange

func (m Annotations) MergeChange(newVs Annotations) Annotations

MergeChange merges a delta (possibly including deletes) with an existing annotations object and returns a new (copy) annotations object or an error. This assumes that both old and new annotations objects contain only valid keys and only newVs may contain deletes

func (*Annotations) Scan

func (m *Annotations) Scan(value interface{}) error

Scan implements sql.Scanner

func (Annotations) Subset

func (m Annotations) Subset(other Annotations) bool

func (Annotations) Validate

func (m Annotations) Validate() APIError

Validate validates a final annotations object prior to store, This will reject partial/patch changes with empty values (containing deletes)

func (Annotations) Value

func (m Annotations) Value() (driver.Value, error)

Value implements sql.Valuer, returning a string

func (Annotations) With

func (m Annotations) With(key string, data interface{}) (Annotations, error)

With Creates a new annotations object containing the specified value - this does not perform size checks on the total number of keys this validates the correctness of the key and value. this returns a new the annotations object with the key set.

func (Annotations) Without

func (m Annotations) Without(key string) Annotations

Without returns a new annotations object with a value excluded

type App

type App struct {
	ID          string          `json:"id" db:"id"`
	Name        string          `json:"name" db:"name"`
	Config      Config          `json:"config,omitempty" db:"config"`
	Annotations Annotations     `json:"annotations,omitempty" db:"annotations"`
	SyslogURL   *string         `json:"syslog_url,omitempty" db:"syslog_url"`
	CreatedAt   common.DateTime `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt   common.DateTime `json:"updated_at,omitempty" db:"updated_at"`
}

func (*App) Clone

func (a *App) Clone() *App

func (*App) Equals

func (a1 *App) Equals(a2 *App) bool

func (*App) EqualsWithAnnotationSubset

func (a1 *App) EqualsWithAnnotationSubset(a2 *App) bool

func (*App) Update

func (a *App) Update(patch *App)

Update adds entries from patch to a.Config and a.Annotations, and removes entries with empty values.

func (*App) Validate

func (a *App) Validate() error

type AppFilter

type AppFilter struct {
	Name    string
	PerPage int
	Cursor  string
}

AppFilter is the filter used for querying apps

type AppList

type AppList struct {
	NextCursor string `json:"next_cursor,omitempty"`
	Items      []*App `json:"items"`
}

type AppWrapper

type AppWrapper struct {
	App *App `json:"app"`
}

func (*AppWrapper) Validate

func (m *AppWrapper) Validate() error

type Call

type Call struct {
	// Unique identifier representing a specific call.
	ID string `json:"id" db:"id"`

	// NOTE: this is stale, retries are not implemented atm, but this is nice, so leaving
	//  States and valid transitions.
	//
	//                  +---------+
	//        +---------> delayed <----------------+
	//                  +----+----+                |
	//                       |                     |
	//                       |                     |
	//                  +----v----+                |
	//        +---------> queued  <----------------+
	//                  +----+----+                *
	//                       |                     *
	//                       |               retry * creates new call
	//                  +----v----+                *
	//                  | running |                *
	//                  +--+-+-+--+                |
	//           +---------|-|-|-----+-------------+
	//       +---|---------+ | +-----|---------+   |
	//       |   |           |       |         |   |
	// +-----v---^-+      +--v-------^+     +--v---^-+
	// | success   |      | cancelled |     |  error |
	// +-----------+      +-----------+     +--------+
	//
	// * delayed - has a delay.
	// * queued - Ready to be consumed when it's turn comes.
	// * running - Currently consumed by a runner which will attempt to process it.
	// * success - (or complete? success/error is common javascript terminology)
	// * error - Something went wrong. In this case more information can be obtained
	//   by inspecting the "reason" field.
	//   - timeout
	//   - killed - forcibly killed by worker due to resource restrictions or access
	//     violations.
	//   - bad_exit - exited with non-zero status due to program termination/crash.
	// * cancelled - cancelled via API. More information in the reason field.
	//   - client_request - Request was cancelled by a client.
	Status string `json:"status" db:"status"`

	// Name of Docker image to use.
	Image string `json:"image,omitempty" db:"-"`

	// Number of seconds to wait before queueing the call for consumption for the
	// first time. Must be a positive integer. Calls with a delay start in state
	// "delayed" and transition to "running" after delay seconds.
	Delay int32 `json:"delay,omitempty" db:"-"`

	// Type indicates whether a task is to be run synchronously or asynchronously.
	Type string `json:"type,omitempty" db:"-"`

	// Payload for the call. This is only used by async calls, to store their input.
	// TODO should we copy it into here too for debugging sync?
	Payload string `json:"payload,omitempty" db:"-"`

	// Full request url that spawned this invocation.
	URL string `json:"url,omitempty" db:"-"`

	// Method of the http request used to make this call.
	Method string `json:"method,omitempty" db:"-"`

	// Priority of the call. Higher has more priority. 3 levels from 0-2. Calls
	// at same priority are processed in FIFO order.
	Priority *int32 `json:"priority,omitempty" db:"-"`

	// Maximum runtime in seconds.
	Timeout int32 `json:"timeout,omitempty" db:"-"`

	// Hot function idle timeout in seconds before termination.
	IdleTimeout int32 `json:"idle_timeout,omitempty" db:"-"`

	// Tmpfs size in megabytes.
	TmpFsSize uint32 `json:"tmpfs_size,omitempty" db:"-"`

	// Memory is the amount of RAM this call is allocated.
	Memory uint64 `json:"memory,omitempty" db:"-"`

	// CPU as in MilliCPUs where each CPU core is split into 1000 units, specified either
	// *) milliCPUs as "100m" which is 1/10 of a CPU or
	// *) as floating point number "0.1" which is 1/10 of a CPU
	CPUs MilliCPUs `json:"cpus,omitempty" db:"-"`

	// Config is the set of configuration variables for the call
	Config Config `json:"config,omitempty" db:"-"`

	// Annotations is the set of annotations for the app/fn of the call.
	Annotations Annotations `json:"annotations,omitempty" db:"-"`

	// Headers are headers from the request that created this call
	Headers http.Header `json:"headers,omitempty" db:"-"`

	// SyslogURL is a syslog URL to send all logs to.
	SyslogURL string `json:"syslog_url,omitempty" db:"-"`

	// Time when call completed, whether it was successul or failed. Always in UTC.
	CompletedAt common.DateTime `json:"completed_at,omitempty" db:"completed_at"`

	// Time when call was submitted. Always in UTC.
	CreatedAt common.DateTime `json:"created_at,omitempty" db:"created_at"`

	// Time when call started execution. Always in UTC.
	StartedAt common.DateTime `json:"started_at,omitempty" db:"started_at"`

	// Stats is a list of metrics from this call's execution, possibly empty.
	Stats drivers.Stats `json:"stats,omitempty" db:"stats"`

	// Error is the reason why the call failed, it is only non-empty if
	// status is equal to "error".
	Error string `json:"error,omitempty" db:"error"`

	// App this call belongs to.
	AppID string `json:"app_id" db:"app_id"`

	// Name of the app.
	AppName string `json:"app_name" db:"app_name"`

	// Trigger this call belongs to.
	TriggerID string `json:"trigger_id" db:"trigger_id"`

	// Fn this call belongs to.
	FnID string `json:"fn_id" db:"fn_id"`
}

Call is a representation of a specific invocation of a fn.

type CallFilter

type CallFilter struct {
	FnID     string //match
	FromTime common.DateTime
	ToTime   common.DateTime
	Cursor   string
	PerPage  int
}

type CallList

type CallList struct {
	NextCursor string  `json:"next_cursor,omitempty"`
	Items      []*Call `json:"items"`
}

type Config

type Config map[string]string

func (Config) Equals

func (c1 Config) Equals(c2 Config) bool

func (*Config) Scan

func (c *Config) Scan(value interface{}) error

implements sql.Scanner

func (*Config) Validate

func (c *Config) Validate() error

func (Config) Value

func (c Config) Value() (driver.Value, error)

implements sql.Valuer, returning a string

type Datastore

type Datastore interface {
	// GetAppByID gets an App by ID.
	// Returns ErrAppsNotFound if no app is found.
	GetAppByID(ctx context.Context, appID string) (*App, error)

	// GetAppID gets an app ID by app name, ensures if app exists.
	// Returns ErrDatastoreEmptyAppName for empty appName.
	// Returns ErrAppsNotFound if no app is found.
	GetAppID(ctx context.Context, appName string) (string, error)

	// GetApps gets a slice of Apps, optionally filtered by name, and a cursor.
	// Missing filter or empty name will match all Apps.
	GetApps(ctx context.Context, filter *AppFilter) (*AppList, error)

	// InsertApp inserts an App. Returns ErrDatastoreEmptyApp when app is nil, and
	// ErrDatastoreEmptyAppName when app.Name is empty.
	// Returns ErrAppsAlreadyExists if an App by the same name already exists.
	InsertApp(ctx context.Context, app *App) (*App, error)

	// UpdateApp updates an App's Config. Returns ErrDatastoreEmptyApp when app is nil, and
	// ErrDatastoreEmptyAppName when app.Name is empty.
	// Returns ErrAppsNotFound if an App is not found.
	UpdateApp(ctx context.Context, app *App) (*App, error)

	// RemoveApp removes the App named appName. Returns ErrDatastoreEmptyAppName if appName is empty.
	// Returns ErrAppsNotFound if an App is not found.
	RemoveApp(ctx context.Context, appID string) error

	// InsertFn inserts a new function if one does not exist, applying any defaults necessary,
	InsertFn(ctx context.Context, fn *Fn) (*Fn, error)

	// UpdateFn  updates a function that exists under the same id.
	// ErrMissingName is func.Name is empty.
	UpdateFn(ctx context.Context, fn *Fn) (*Fn, error)

	// GetFns returns a list of funcs, and a cursor, applying any additional filters provided.
	GetFns(ctx context.Context, filter *FnFilter) (*FnList, error)

	// GetFnByID returns a function by ID. Returns ErrDatastoreEmptyFnID if fnID is empty.
	// Returns ErrFnsNotFound if a fn is not found.
	GetFnByID(ctx context.Context, fnID string) (*Fn, error)

	// RemoveFn removes a function. Returns ErrDatastoreEmptyFnID if fnID is empty.
	// Returns ErrFnsNotFound if a func is not found.
	RemoveFn(ctx context.Context, fnID string) error

	// InsertTrigger inserts a trigger. Returns ErrDatastoreEmptyTrigger when trigger is nil, and specific errors for each field
	// Returns ErrTriggerAlreadyExists if the exact apiID, fnID, source, type combination already exists
	InsertTrigger(ctx context.Context, trigger *Trigger) (*Trigger, error)

	//UpdateTrigger updates a trigger object in the data store
	UpdateTrigger(ctx context.Context, trigger *Trigger) (*Trigger, error)

	// Removes a Trigger. Returns field specific errors if they are empty.
	// Returns nil if successful
	RemoveTrigger(ctx context.Context, triggerID string) error

	// GetTriggerByID gets a trigger by it's id.
	// Returns ErrTriggerNotFound when no matching trigger is found
	GetTriggerByID(ctx context.Context, triggerID string) (*Trigger, error)

	// GetTriggers gets a list of triggers that match the specified filter
	// Return ErrDatastoreEmptyAppId if no AppID set in the filter
	GetTriggers(ctx context.Context, filter *TriggerFilter) (*TriggerList, error)

	// GetTriggerBySource loads a trigger by type and source ID - this is only needed when the data store is also used for agent read access
	GetTriggerBySource(ctx context.Context, appId string, triggerType, source string) (*Trigger, error)

	// implements io.Closer to shutdown
	io.Closer
}

type ErrInvalidSyslog

type ErrInvalidSyslog string

func (ErrInvalidSyslog) Code

func (e ErrInvalidSyslog) Code() int

func (ErrInvalidSyslog) Error

func (e ErrInvalidSyslog) Error() string

type Error

type Error struct {
	Message string `json:"message,omitempty"`
	Fields  string `json:"fields,omitempty"`
}

func (*Error) Validate

func (m *Error) Validate() error

Validate validates this error body

type ErrorWrapper

type ErrorWrapper struct {
	Error *Error `json:"error,omitempty"`
}

ErrorWrapper uniform error output (v1) only

func (*ErrorWrapper) Validate

func (m *ErrorWrapper) Validate() error

type Fn

type Fn struct {
	// ID is the generated resource id.
	ID string `json:"id" db:"id"`
	// Name is a user provided name for this fn.
	Name string `json:"name" db:"name"`
	// AppID is the name of the app this fn belongs to.
	AppID string `json:"app_id" db:"app_id"`
	// Image is the fully qualified container registry address to execute.
	// examples: hub.docker.io/me/myfunc, me/myfunc, me/func:0.0.1
	Image string `json:"image" db:"image"`
	// ResourceConfig specifies resource constraints.
	ResourceConfig // embed (TODO or not?)
	// Config is the configuration passed to a function at execution time.
	Config Config `json:"config" db:"config"`
	// Annotations allow additional configuration of a function, these are not passed to the function.
	Annotations Annotations `json:"annotations,omitempty" db:"annotations"`
	// CreatedAt is the UTC timestamp when this function was created.
	CreatedAt common.DateTime `json:"created_at,omitempty" db:"created_at"`
	// UpdatedAt is the UTC timestamp of the last time this func was modified.
	UpdatedAt common.DateTime `json:"updated_at,omitempty" db:"updated_at"`
}

Fn contains information about a function configuration.

func (*Fn) Clone

func (f *Fn) Clone() *Fn

func (*Fn) Equals

func (f1 *Fn) Equals(f2 *Fn) bool

func (*Fn) EqualsWithAnnotationSubset

func (f1 *Fn) EqualsWithAnnotationSubset(f2 *Fn) bool

func (*Fn) SetDefaults

func (f *Fn) SetDefaults()

SetCreated sets zeroed field to defaults.

func (*Fn) Update

func (f *Fn) Update(patch *Fn)

Update updates fields in f with non-zero field values from new, and sets updated_at if any of the fields change. 0-length slice Header values, and empty-string Config values trigger removal of map entry.

func (*Fn) Validate

func (f *Fn) Validate() error

Validate validates all field values, returning the first error, if any.

type FnFilter

type FnFilter struct {
	AppID   string // this is exact match
	Name    string //exact match
	Cursor  string
	PerPage int
}

type FnList

type FnList struct {
	NextCursor string `json:"next_cursor,omitempty"`
	Items      []*Fn  `json:"items"`
}

type Headers

type Headers http.Header

Headers is an http.Header that implements additional methods.

func (Headers) Equals

func (h1 Headers) Equals(h2 Headers) bool

func (*Headers) Scan

func (h *Headers) Scan(value interface{}) error

implements sql.Scanner

func (Headers) Value

func (h Headers) Value() (driver.Value, error)

implements sql.Valuer, returning a string

type LogStore

type LogStore interface {
	// InsertLog will insert the log at callID, overwriting if it previously
	// existed.
	InsertLog(ctx context.Context, call *Call, callLog io.Reader) error

	// GetLog will return the log at callID, an error will be returned if the log
	// cannot be found.
	GetLog(ctx context.Context, fnID, callID string) (io.Reader, error)

	// InsertCall inserts a call into the datastore, it will error if the call already
	// exists.
	InsertCall(ctx context.Context, call *Call) error

	// GetCall2 returns a call at a certain id
	GetCall(ctx context.Context, fnID, callID string) (*Call, error)

	// GetCalls returns a list of calls that satisfy the given CallFilter. If no
	// calls exist, an empty list and a nil error are returned.
	GetCalls(ctx context.Context, filter *CallFilter) (*CallList, error)

	// Close will close any underlying connections as needed.
	// Close is not safe to be called from multiple threads.
	io.Closer
}

type MessageQueue

type MessageQueue interface {
	// Push a call onto the queue. If any error is returned, the call SHOULD not be
	// queued. Note that this does not completely avoid double queueing, that is
	// OK, a check against the datastore will be performed after a dequeue.
	//
	// If the job's Delay value is > 0, the job should NOT be enqueued. The job
	// should only be available in the queue after at least Delay seconds have
	// elapsed. No ordering is required among multiple jobs queued with similar
	// delays. That is, if jobs {A, C} are queued at t seconds, both with Delay
	// = 5 seconds, and the same priority, then they may be available on the
	// queue as [C, A] or [A, C].
	Push(context.Context, *Call) (*Call, error)

	// Remove a job from the front of the queue, reserve it for a timeout and
	// return it. MQ implementations MUST NOT lose jobs in case of errors. That
	// is, in case of reservation failure, it should be possible to retrieve the
	// job on a future reservation.
	Reserve(context.Context) (*Call, error)

	// If a reservation is pending, consider it acknowledged and delete it. If
	// the job does not have an outstanding reservation, error. If a job did not
	// exist, succeed.
	Delete(context.Context, *Call) error

	// Close will close any underlying connections as needed.
	// Close is not safe to be called from multiple threads.
	io.Closer
}

When a job is required to be restored to the queue, it should maintain it's approximate order in the queue. That is, for jobs [A, B, C], with A being the head of the queue: Reserve() leads to A being passed to a consumer, and timeout started. Next Reserve() leads to B being dequeued. This consumer finishes running the call, leading to Delete() being called. B is now permanently erased from the queue. A's timeout occurs before the job is finished. At this point the ordering should be [A, C] and not [C, A].

type MilliCPUs

type MilliCPUs uint64

MilliCPU units

func (*MilliCPUs) MarshalJSON

func (c *MilliCPUs) MarshalJSON() ([]byte, error)

implements json.Marshaler

func (MilliCPUs) String

func (c MilliCPUs) String() string

implements fmt.Stringer

func (*MilliCPUs) UnmarshalJSON

func (c *MilliCPUs) UnmarshalJSON(data []byte) error

implements json.Unmarshaler

type ResourceConfig

type ResourceConfig struct {
	// Memory is the amount of memory allotted, in MB.
	Memory uint64 `json:"memory,omitempty" db:"memory"`
	// Timeout is the max execution time for a function, in seconds.
	// TODO this should probably be milliseconds?
	Timeout int32 `json:"timeout,omitempty" db:"timeout"`
	// IdleTimeout is the
	// TODO this should probably be milliseconds
	IdleTimeout int32 `json:"idle_timeout,omitempty" db:"idle_timeout"`
}

ResourceConfig specified resource constraints imposed on a function execution.

type Trigger

type Trigger struct {
	ID          string          `json:"id" db:"id"`
	Name        string          `json:"name" db:"name"`
	AppID       string          `json:"app_id" db:"app_id"`
	FnID        string          `json:"fn_id" db:"fn_id"`
	CreatedAt   common.DateTime `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt   common.DateTime `json:"updated_at,omitempty" db:"updated_at"`
	Type        string          `json:"type" db:"type"`
	Source      string          `json:"source" db:"source"`
	Annotations Annotations     `json:"annotations,omitempty" db:"annotations"`
}

Trigger represents a binding between a Function and an external event source

func (*Trigger) Clone

func (t *Trigger) Clone() *Trigger

Clone creates a deep copy of a trigger

func (*Trigger) Equals

func (t *Trigger) Equals(t2 *Trigger) bool

Equals compares two triggers for semantic equality it ignores timestamp fields but includes annotations

func (*Trigger) EqualsWithAnnotationSubset

func (t *Trigger) EqualsWithAnnotationSubset(t2 *Trigger) bool

EqualsWithAnnotationSubset is equivalent to Equals except it accepts cases where t's annotations are strict subset of t2

func (*Trigger) Update

func (t *Trigger) Update(patch *Trigger)

Update applies a change to a trigger

func (*Trigger) Validate

func (t *Trigger) Validate() error

Validate checks that trigger has valid data for inserting into a store

type TriggerFilter

type TriggerFilter struct {
	//AppID searches for triggers in APP - mandatory
	AppID string // this is exact match mandatory
	//FNID searches for triggers belonging to a specific function
	FnID string // this is exact match
	//Name is the name of the trigger
	Name string // exact match

	Cursor  string
	PerPage int
}

TriggerFilter is a search criteria on triggers

type TriggerList

type TriggerList struct {
	NextCursor string     `json:"next_cursor,omitempty"`
	Items      []*Trigger `json:"items"`
}

TriggerList is a container of triggers returned by search, optionally indicating the next page cursor

Jump to

Keyboard shortcuts

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