receptor

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2015 License: Apache-2.0 Imports: 13 Imported by: 0

README

Receptor

Restful API for Diego, which lives on every cell.

Documentation

Index

Constants

View Source
const (
	TaskGuidAlreadyExists = "TaskGuidAlreadyExists"
	TaskNotDeletable      = "TaskNotDeletable"
	TaskNotFound          = "TaskNotFound"
	InvalidTask           = "InvalidTask"

	DesiredLRPAlreadyExists = "DesiredLRPAlreadyExists"
	DesiredLRPNotFound      = "DesiredLRPNotFound"
	InvalidLRP              = "InvalidLRP"

	InvalidDomain = "InvalidDomain"

	InvalidJSON    = "InvalidJSON"
	InvalidRequest = "InvalidRequest"

	UnknownError = "UnknownError"
	Unauthorized = "Unauthorized"

	ActualLRPIndexNotFound = "ActualLRPIndexNotFound"
)
View Source
const (
	TaskStateInvalid   = "INVALID"
	TaskStatePending   = "PENDING"
	TaskStateRunning   = "RUNNING"
	TaskStateCompleted = "COMPLETED"
	TaskStateResolving = "RESOLVING"
)
View Source
const (
	// Tasks
	CreateTaskRoute = "CreateTask"
	TasksRoute      = "Tasks"
	GetTaskRoute    = "GetTask"
	DeleteTaskRoute = "DeleteTask"
	CancelTaskRoute = "CancelTask"

	// DesiredLRPs
	CreateDesiredLRPRoute = "CreateDesiredLRP"
	GetDesiredLRPRoute    = "GetDesiredLRP"
	UpdateDesiredLRPRoute = "UpdateDesiredLRP"
	DeleteDesiredLRPRoute = "DeleteDesiredLRP"
	DesiredLRPsRoute      = "DesiredLRPs"

	// ActualLRPs
	ActualLRPsRoute                         = "ActualLRPs"
	ActualLRPsByProcessGuidRoute            = "ActualLRPsByProcessGuid"
	ActualLRPByProcessGuidAndIndexRoute     = "ActualLRPByProcessGuidAndIndex"
	KillActualLRPByProcessGuidAndIndexRoute = "KillActualLRPByProcessGuidAndIndex"

	// Cells
	CellsRoute = "Cells"

	// Domains
	UpsertDomainRoute = "UpsertDomain"
	DomainsRoute      = "Domains"

	// Event Streaming
	EventStream = "EventStream"
)
View Source
const AuthorizationCookieName = "receptor_authorization"

Variables

View Source
var ErrHubAlreadyClosed = errors.New("hub already closed")
View Source
var ErrReadFromClosedSource = errors.New("read from closed source")
View Source
var ErrSendToClosedSource = errors.New("send to closed source")
View Source
var ErrSlowConsumer = errors.New("slow consumer")
View Source
var ErrSourceAlreadyClosed = errors.New("source already closed")
View Source
var ErrSourceClosed = errors.New("source closed")
View Source
var ErrSubscribedToClosedHub = errors.New("subscribed to closed hub")
View Source
var ErrUnrecognizedEventType = errors.New("unrecognized event type")
View Source
var Routes = rata.Routes{

	{Path: "/v1/tasks", Method: "POST", Name: CreateTaskRoute},
	{Path: "/v1/tasks", Method: "GET", Name: TasksRoute},
	{Path: "/v1/tasks/:task_guid", Method: "GET", Name: GetTaskRoute},
	{Path: "/v1/tasks/:task_guid", Method: "DELETE", Name: DeleteTaskRoute},
	{Path: "/v1/tasks/:task_guid/cancel", Method: "POST", Name: CancelTaskRoute},

	{Path: "/v1/desired_lrps", Method: "GET", Name: DesiredLRPsRoute},
	{Path: "/v1/desired_lrps", Method: "POST", Name: CreateDesiredLRPRoute},
	{Path: "/v1/desired_lrps/:process_guid", Method: "GET", Name: GetDesiredLRPRoute},
	{Path: "/v1/desired_lrps/:process_guid", Method: "PUT", Name: UpdateDesiredLRPRoute},
	{Path: "/v1/desired_lrps/:process_guid", Method: "DELETE", Name: DeleteDesiredLRPRoute},

	{Path: "/v1/actual_lrps", Method: "GET", Name: ActualLRPsRoute},
	{Path: "/v1/actual_lrps/:process_guid", Method: "GET", Name: ActualLRPsByProcessGuidRoute},
	{Path: "/v1/actual_lrps/:process_guid/index/:index", Method: "GET", Name: ActualLRPByProcessGuidAndIndexRoute},
	{Path: "/v1/actual_lrps/:process_guid/index/:index", Method: "DELETE", Name: KillActualLRPByProcessGuidAndIndexRoute},

	{Path: "/v1/cells", Method: "GET", Name: CellsRoute},

	{Path: "/v1/domains/:domain", Method: "PUT", Name: UpsertDomainRoute},
	{Path: "/v1/domains", Method: "GET", Name: DomainsRoute},

	{Path: "/v1/events", Method: "GET", Name: EventStream},
}

Functions

func NewCloseError

func NewCloseError(err error) error

func NewInvalidPayloadError

func NewInvalidPayloadError(jsonErr error) error

func NewRawEventSourceError

func NewRawEventSourceError(rawError error) error

Types

type ActualLRPChangedEvent

type ActualLRPChangedEvent struct {
	Before ActualLRPResponse `json:"actual_lrp_before"`
	After  ActualLRPResponse `json:"actual_lrp_after"`
}

func NewActualLRPChangedEvent

func NewActualLRPChangedEvent(before, after ActualLRPResponse) ActualLRPChangedEvent

func (ActualLRPChangedEvent) EventType

func (ActualLRPChangedEvent) EventType() EventType

func (ActualLRPChangedEvent) Key

func (e ActualLRPChangedEvent) Key() string

type ActualLRPCreatedEvent

type ActualLRPCreatedEvent struct {
	ActualLRPResponse ActualLRPResponse `json:"actual_lrp"`
}

func NewActualLRPCreatedEvent

func NewActualLRPCreatedEvent(actualLRP ActualLRPResponse) ActualLRPCreatedEvent

func (ActualLRPCreatedEvent) EventType

func (ActualLRPCreatedEvent) EventType() EventType

func (ActualLRPCreatedEvent) Key

func (e ActualLRPCreatedEvent) Key() string

type ActualLRPRemovedEvent

type ActualLRPRemovedEvent struct {
	ActualLRPResponse ActualLRPResponse `json:"actual_lrp"`
}

func NewActualLRPRemovedEvent

func NewActualLRPRemovedEvent(actualLRP ActualLRPResponse) ActualLRPRemovedEvent

func (ActualLRPRemovedEvent) EventType

func (ActualLRPRemovedEvent) EventType() EventType

func (ActualLRPRemovedEvent) Key

func (e ActualLRPRemovedEvent) Key() string

type ActualLRPResponse

type ActualLRPResponse struct {
	ProcessGuid     string          `json:"process_guid"`
	InstanceGuid    string          `json:"instance_guid"`
	CellID          string          `json:"cell_id"`
	Domain          string          `json:"domain"`
	Index           int             `json:"index"`
	Address         string          `json:"address"`
	Ports           []PortMapping   `json:"ports"`
	State           ActualLRPState  `json:"state"`
	CrashCount      int             `json:"crash_count"`
	CrashReason     string          `json:"crash_reason,omitempty"`
	PlacementError  string          `json:"placement_error,omitempty"`
	Since           int64           `json:"since"`
	Evacuating      bool            `json:"evacuating"`
	ModificationTag ModificationTag `json:"modification_tag"`
}

type ActualLRPState

type ActualLRPState string
const (
	ActualLRPStateInvalid   ActualLRPState = "INVALID"
	ActualLRPStateUnclaimed ActualLRPState = "UNCLAIMED"
	ActualLRPStateClaimed   ActualLRPState = "CLAIMED"
	ActualLRPStateRunning   ActualLRPState = "RUNNING"
	ActualLRPStateCrashed   ActualLRPState = "CRASHED"
)

type CellCapacity

type CellCapacity struct {
	MemoryMB   int `json:"memory_mb"`
	DiskMB     int `json:"disk_mb"`
	Containers int `json:"containers"`
}

type CellResponse

type CellResponse struct {
	CellID   string       `json:"cell_id"`
	Stack    string       `json:"stack"`
	Zone     string       `json:"zone"`
	Capacity CellCapacity `json:"capacity"`
}

type Client

type Client interface {
	CreateTask(TaskCreateRequest) error
	Tasks() ([]TaskResponse, error)
	TasksByDomain(domain string) ([]TaskResponse, error)
	GetTask(taskId string) (TaskResponse, error)
	DeleteTask(taskId string) error
	CancelTask(taskId string) error

	CreateDesiredLRP(DesiredLRPCreateRequest) error
	GetDesiredLRP(processGuid string) (DesiredLRPResponse, error)
	UpdateDesiredLRP(processGuid string, update DesiredLRPUpdateRequest) error
	DeleteDesiredLRP(processGuid string) error
	DesiredLRPs() ([]DesiredLRPResponse, error)
	DesiredLRPsByDomain(domain string) ([]DesiredLRPResponse, error)

	ActualLRPs() ([]ActualLRPResponse, error)
	ActualLRPsByDomain(domain string) ([]ActualLRPResponse, error)
	ActualLRPsByProcessGuid(processGuid string) ([]ActualLRPResponse, error)
	ActualLRPByProcessGuidAndIndex(processGuid string, index int) (ActualLRPResponse, error)
	KillActualLRPByProcessGuidAndIndex(processGuid string, index int) error

	SubscribeToEvents() (EventSource, error)

	Cells() ([]CellResponse, error)

	UpsertDomain(domain string, ttl time.Duration) error
	Domains() ([]string, error)
}

func NewClient

func NewClient(url string) Client

type DesiredLRPChangedEvent

type DesiredLRPChangedEvent struct {
	Before DesiredLRPResponse `json:"desired_lrp_before"`
	After  DesiredLRPResponse `json:"desired_lrp_after"`
}

func NewDesiredLRPChangedEvent

func NewDesiredLRPChangedEvent(before, after DesiredLRPResponse) DesiredLRPChangedEvent

func (DesiredLRPChangedEvent) EventType

func (DesiredLRPChangedEvent) EventType() EventType

func (DesiredLRPChangedEvent) Key

type DesiredLRPCreateRequest

type DesiredLRPCreateRequest struct {
	ProcessGuid          string                     `json:"process_guid"`
	Domain               string                     `json:"domain"`
	RootFSPath           string                     `json:"rootfs"`
	Instances            int                        `json:"instances"`
	Stack                string                     `json:"stack"`
	EnvironmentVariables []EnvironmentVariable      `json:"env,omitempty"`
	Setup                models.Action              `json:"-"`
	Action               models.Action              `json:"-"`
	Monitor              models.Action              `json:"-"`
	StartTimeout         uint                       `json:"start_timeout"`
	DiskMB               int                        `json:"disk_mb"`
	MemoryMB             int                        `json:"memory_mb"`
	CPUWeight            uint                       `json:"cpu_weight"`
	Privileged           bool                       `json:"privileged"`
	Ports                []uint16                   `json:"ports"`
	Routes               RoutingInfo                `json:"routes,omitempty"`
	LogGuid              string                     `json:"log_guid"`
	LogSource            string                     `json:"log_source"`
	MetricsGuid          string                     `json:"metrics_guid"`
	Annotation           string                     `json:"annotation,omitempty"`
	EgressRules          []models.SecurityGroupRule `json:"egress_rules,omitempty"`
}

func (DesiredLRPCreateRequest) MarshalJSON

func (request DesiredLRPCreateRequest) MarshalJSON() ([]byte, error)

func (*DesiredLRPCreateRequest) UnmarshalJSON

func (request *DesiredLRPCreateRequest) UnmarshalJSON(payload []byte) error

type DesiredLRPCreatedEvent

type DesiredLRPCreatedEvent struct {
	DesiredLRPResponse DesiredLRPResponse `json:"desired_lrp"`
}

func NewDesiredLRPCreatedEvent

func NewDesiredLRPCreatedEvent(desiredLRP DesiredLRPResponse) DesiredLRPCreatedEvent

func (DesiredLRPCreatedEvent) EventType

func (DesiredLRPCreatedEvent) EventType() EventType

func (DesiredLRPCreatedEvent) Key

type DesiredLRPRemovedEvent

type DesiredLRPRemovedEvent struct {
	DesiredLRPResponse DesiredLRPResponse `json:"desired_lrp"`
}

func NewDesiredLRPRemovedEvent

func NewDesiredLRPRemovedEvent(desiredLRP DesiredLRPResponse) DesiredLRPRemovedEvent

func (DesiredLRPRemovedEvent) EventType

func (DesiredLRPRemovedEvent) EventType() EventType

func (DesiredLRPRemovedEvent) Key

type DesiredLRPResponse

type DesiredLRPResponse struct {
	ProcessGuid          string                     `json:"process_guid"`
	Domain               string                     `json:"domain"`
	RootFSPath           string                     `json:"rootfs"`
	Instances            int                        `json:"instances"`
	Stack                string                     `json:"stack"`
	EnvironmentVariables []EnvironmentVariable      `json:"env,omitempty"`
	Setup                models.Action              `json:"setup"`
	Action               models.Action              `json:"action"`
	Monitor              models.Action              `json:"monitor"`
	StartTimeout         uint                       `json:"start_timeout"`
	DiskMB               int                        `json:"disk_mb"`
	MemoryMB             int                        `json:"memory_mb"`
	CPUWeight            uint                       `json:"cpu_weight"`
	Privileged           bool                       `json:"privileged"`
	Ports                []uint16                   `json:"ports"`
	Routes               RoutingInfo                `json:"routes,omitempty"`
	LogGuid              string                     `json:"log_guid"`
	LogSource            string                     `json:"log_source"`
	MetricsGuid          string                     `json:"metrics_guid"`
	Annotation           string                     `json:"annotation,omitempty"`
	EgressRules          []models.SecurityGroupRule `json:"egress_rules,omitempty"`
	ModificationTag      ModificationTag            `json:"modification_tag"`
}

func (DesiredLRPResponse) MarshalJSON

func (response DesiredLRPResponse) MarshalJSON() ([]byte, error)

func (*DesiredLRPResponse) UnmarshalJSON

func (response *DesiredLRPResponse) UnmarshalJSON(payload []byte) error

type DesiredLRPUpdateRequest

type DesiredLRPUpdateRequest struct {
	Instances  *int        `json:"instances,omitempty"`
	Routes     RoutingInfo `json:"routes,omitempty"`
	Annotation *string     `json:"annotation,omitempty"`
}

type EnvironmentVariable

type EnvironmentVariable struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Error

type Error struct {
	Type    string `json:"name"`
	Message string `json:"message"`
}

func (Error) Error

func (err Error) Error() string

type Event

type Event interface {
	EventType() EventType
	Key() string
}

type EventSource

type EventSource interface {
	// Next reads the next event from the source. If the connection is lost, it
	// automatically reconnects.
	//
	// If the end of the stream is reached cleanly (which should actually never
	// happen), io.EOF is returned. If called after or during Close,
	// ErrSourceClosed is returned.
	Next() (Event, error)

	// Close releases the underlying response, interrupts any in-flight Next, and
	// prevents further calls to Next.
	Close() error
}

EventSource provides sequential access to a stream of events.

func NewEventSource

func NewEventSource(raw RawEventSource) EventSource

type EventType

type EventType string
const (
	EventTypeInvalid EventType = ""

	EventTypeDesiredLRPCreated EventType = "desired_lrp_created"
	EventTypeDesiredLRPChanged EventType = "desired_lrp_changed"
	EventTypeDesiredLRPRemoved EventType = "desired_lrp_removed"
	EventTypeActualLRPCreated  EventType = "actual_lrp_created"
	EventTypeActualLRPChanged  EventType = "actual_lrp_changed"
	EventTypeActualLRPRemoved  EventType = "actual_lrp_removed"
)

type InnerDesiredLRPCreateRequest

type InnerDesiredLRPCreateRequest DesiredLRPCreateRequest

type InnerDesiredLRPResponse

type InnerDesiredLRPResponse DesiredLRPResponse

type InnerTaskCreateRequest

type InnerTaskCreateRequest TaskCreateRequest

type InnerTaskResponse

type InnerTaskResponse TaskResponse

type ModificationTag

type ModificationTag struct {
	Epoch string `json:"epoch"`
	Index uint   `json:"index"`
}

func (*ModificationTag) Equal

func (m *ModificationTag) Equal(other ModificationTag) bool

func (*ModificationTag) SucceededBy

func (m *ModificationTag) SucceededBy(other ModificationTag) bool

type PortMapping

type PortMapping struct {
	ContainerPort uint16 `json:"container_port"`
	HostPort      uint16 `json:"host_port,omitempty"`
}

type RawEventSource

type RawEventSource interface {
	Next() (sse.Event, error)
	Close() error
}

type RoutingInfo

type RoutingInfo map[string]*json.RawMessage

type TaskCreateRequest

type TaskCreateRequest struct {
	Action                models.Action              `json:"-"`
	Annotation            string                     `json:"annotation,omitempty"`
	CompletionCallbackURL string                     `json:"completion_callback_url"`
	CPUWeight             uint                       `json:"cpu_weight"`
	DiskMB                int                        `json:"disk_mb"`
	Domain                string                     `json:"domain"`
	LogGuid               string                     `json:"log_guid"`
	LogSource             string                     `json:"log_source"`
	MetricsGuid           string                     `json:"metrics_guid"`
	MemoryMB              int                        `json:"memory_mb"`
	ResultFile            string                     `json:"result_file"`
	Stack                 string                     `json:"stack"`
	TaskGuid              string                     `json:"task_guid"`
	RootFSPath            string                     `json:"rootfs"`
	Privileged            bool                       `json:"privileged"`
	EnvironmentVariables  []EnvironmentVariable      `json:"env,omitempty"`
	EgressRules           []models.SecurityGroupRule `json:"egress_rules,omitempty"`
}

func (TaskCreateRequest) MarshalJSON

func (request TaskCreateRequest) MarshalJSON() ([]byte, error)

func (*TaskCreateRequest) UnmarshalJSON

func (request *TaskCreateRequest) UnmarshalJSON(payload []byte) error

type TaskResponse

type TaskResponse struct {
	Action                models.Action              `json:"-"`
	Annotation            string                     `json:"annotation,omitempty"`
	CompletionCallbackURL string                     `json:"completion_callback_url"`
	CPUWeight             uint                       `json:"cpu_weight"`
	DiskMB                int                        `json:"disk_mb"`
	Domain                string                     `json:"domain"`
	LogGuid               string                     `json:"log_guid"`
	LogSource             string                     `json:"log_source"`
	MetricsGuid           string                     `json:"metrics_guid"`
	MemoryMB              int                        `json:"memory_mb"`
	ResultFile            string                     `json:"result_file"`
	Stack                 string                     `json:"stack"`
	TaskGuid              string                     `json:"task_guid"`
	RootFSPath            string                     `json:"rootfs"`
	Privileged            bool                       `json:"privileged"`
	EnvironmentVariables  []EnvironmentVariable      `json:"env,omitempty"`
	CellID                string                     `json:"cell_id"`
	CreatedAt             int64                      `json:"created_at"`
	Failed                bool                       `json:"failed"`
	FailureReason         string                     `json:"failure_reason"`
	Result                string                     `json:"result"`
	State                 string                     `json:"state"`
	EgressRules           []models.SecurityGroupRule `json:"egress_rules,omitempty"`
}

func (TaskResponse) MarshalJSON

func (response TaskResponse) MarshalJSON() ([]byte, error)

func (*TaskResponse) UnmarshalJSON

func (response *TaskResponse) UnmarshalJSON(payload []byte) error

Directories

Path Synopsis
cmd
eventfakes
This file was generated by counterfeiter
This file was generated by counterfeiter
This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter
This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter
handler_fakes
This file was generated by counterfeiter
This file was generated by counterfeiter

Jump to

Keyboard shortcuts

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