protocol

package
v0.0.0-...-3735483 Latest Latest
Warning

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

Go to latest
Published: May 11, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package protocol defines the protocol between the Fn Agent and the code running inside of a container. When an Fn Agent wants to perform a function call it needs to pass that call to a container over stdin. The call is encoded in one of the following protocols.

  • Default I/O Format
  • JSON I/O Format
  • HTTP I/O Format

For more information on the function formats see https://github.com/fnproject/fn/blob/master/docs/developers/function-format.md.

Index

Constants

This section is empty.

Variables

View Source
var ErrExcessData = errors.New("Excess data in stream")

Functions

func IsStreamable

func IsStreamable(p Protocol) bool

IsStreamable says whether the given protocol can be used for streaming into hot functions.

Types

type CallInfo

type CallInfo interface {
	IsCloudEvent() bool
	CallID() string
	ContentType() string
	Input() io.Reader
	Deadline() strfmt.DateTime
	CallType() string

	// ProtocolType let's function/fdk's know what type original request is. Only 'http' for now.
	// This could be abstracted into separate Protocol objects for each type and all the following information could go in there.
	// This is a bit confusing because we also have the protocol's for getting information in and out of the function containers.
	ProtocolType() string
	Request() *http.Request
	Method() string
	RequestURL() string
	Headers() map[string][]string
}

CallInfo is passed into dispatch with only the required data the protocols require

func NewCallInfo

func NewCallInfo(isCloudEvent bool, call *models.Call, req *http.Request) CallInfo

type CallRequestHTTP

type CallRequestHTTP struct {
	Type       string      `json:"type"`
	Method     string      `json:"method"`
	RequestURL string      `json:"request_url"`
	Headers    http.Header `json:"headers"`
}

CallRequestHTTP for the protocol that was used by the end user to call this function. We only have HTTP right now.

type CallResponseHTTP

type CallResponseHTTP struct {
	StatusCode int         `json:"status_code,omitempty"`
	Headers    http.Header `json:"headers,omitempty"`
}

CallResponseHTTP for the protocol that was used by the end user to call this function. We only have HTTP right now.

type CloudEvent

type CloudEvent struct {
	CloudEventsVersion string                 `json:"cloudEventsVersion"`
	EventID            string                 `json:"eventID"`
	Source             string                 `json:"source"`
	EventType          string                 `json:"eventType"`
	EventTypeVersion   string                 `json:"eventTypeVersion"`
	EventTime          time.Time              `json:"eventTime"`
	SchemaURL          string                 `json:"schemaURL"`
	ContentType        string                 `json:"contentType"`
	Extensions         map[string]interface{} `json:"extensions"`
	Data               interface{}            `json:"data,omitempty"` // docs: the payload is encoded into a media format which is specified by the contentType attribute (e.g. application/json)
}

CloudEvent is the official JSON representation of a CloudEvent: https://github.com/cloudevents/spec/blob/master/serialization.md

type CloudEventProtocol

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

CloudEventProtocol converts stdin/stdout streams from HTTP into JSON format.

func (*CloudEventProtocol) Dispatch

func (h *CloudEventProtocol) Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error

func (*CloudEventProtocol) IsStreamable

func (p *CloudEventProtocol) IsStreamable() bool

type ContainerIO

type ContainerIO interface {
	IsStreamable() bool

	// Dispatch will handle sending stdin and stdout to a container. Implementers
	// of Dispatch may format the input and output differently. Dispatch must respect
	// the req.Context() timeout / cancellation.
	Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error
}

ContainerIO defines the interface used to talk to a hot function. Internally, a protocol must know when to alternate between stdin and stdout. It returns any protocol error, if present.

func New

func New(p Protocol, in io.Writer, out io.Reader) ContainerIO

New creates a valid protocol handler from a I/O pipe representing containers stdin/stdout.

type DefaultProtocol

type DefaultProtocol struct{}

DefaultProtocol is the protocol used by cold-containers

func (*DefaultProtocol) Dispatch

func (d *DefaultProtocol) Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error

func (*DefaultProtocol) IsStreamable

func (p *DefaultProtocol) IsStreamable() bool

type HTTPProtocol

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

HTTPProtocol converts stdin/stdout streams into HTTP/1.1 compliant communication. It relies on Content-Length to know when to stop reading from containers stdout. It also mandates valid HTTP headers back and forth, thus returning errors in case of parsing problems.

func (*HTTPProtocol) Dispatch

func (h *HTTPProtocol) Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error

func (*HTTPProtocol) IsStreamable

func (p *HTTPProtocol) IsStreamable() bool

type JSONProtocol

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

JSONProtocol converts stdin/stdout streams from HTTP into JSON format.

func (*JSONProtocol) Dispatch

func (h *JSONProtocol) Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error

func (*JSONProtocol) IsStreamable

func (p *JSONProtocol) IsStreamable() bool

type Protocol

type Protocol string

Protocol defines all protocols that operates a ContainerIO.

hot function protocols

func (Protocol) MarshalJSON

func (p Protocol) MarshalJSON() ([]byte, error)

func (*Protocol) UnmarshalJSON

func (p *Protocol) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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