operator

package
v0.0.0-...-3182038 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 22 Imported by: 2

Documentation

Index

Constants

View Source
const DEFAULT_GROUP_ID = "default"

Variables

This section is empty.

Functions

func ConnectControlEnvProxyServer

func ConnectControlEnvProxyServer(devId string, pool *DevicePool) (*grpc.ClientConn, error)

Connect ControlEnvProxyServer

func CreateHttpHandlers

func CreateHttpHandlers(
	pool *DevicePool,
	polledSet *PolledSet,
	config apiv1.InfraConfig,
	maybeIntercept func(string) *string) *mux.Router

Creates a router with handlers for the following endpoints: GET /infra_config GET /groups GET /devices GET /devices?groupId={groupId} GET /devices/{deviceId} GET /devices/{deviceId}/files/{path} GET /devices/{deviceId}/services GET /devices/{deviceId}/services/{serviceName} GET /devices/{deviceId}/services/{serviceName}/{methodName} POST /devices/{deviceId}/services/{serviceName}/{methodName} GET /devices/{deviceId}/services/{serviceName}/{typeName}/type GET /devices/{deviceId}/openwrt{path:/.*} POST /devices/{deviceId}/openwrt{path:/.*} GET /polled_connections GET /polled_connections/{connId}/messages POST /polled_connections/{connId}/:forward The maybeIntercept parameter is a function that accepts the requested device file and returns a path to a file to be returned instead or nil if the request should be allowed to proceed to the device.

func NewBadRequestError

func NewBadRequestError(msg string, e error) error

func NewInternalError

func NewInternalError(msg string, e error) error

func NewNotFoundError

func NewNotFoundError(msg string, e error) error

func NewServiceUnavailableError

func NewServiceUnavailableError(msg string, e error) error

func PreRegister

func PreRegister(c *JSONUnix, pool *DevicePool, msg *apiv1.PreRegisterMsg)

func ReplyError

func ReplyError(c JSONConn, msg string)

Log and reply with an error

func ReplyJSON

func ReplyJSON(w http.ResponseWriter, obj interface{}, statusCode int) error

Send a JSON http response to the client

func ReplyJSONErr

func ReplyJSONErr(w http.ResponseWriter, err error) error

Send a JSON http response with error to the client

func ReplyJSONOK

func ReplyJSONOK(w http.ResponseWriter, obj interface{}) error

Send a JSON http response with success status code to the client

func SetupControlEndpoint

func SetupControlEndpoint(pool *DevicePool, path string) (func() error, error)

Sets up a unix socket for server control and returns a function that listens on the socket until an error occurrs.

func SetupDeviceEndpoint

func SetupDeviceEndpoint(pool *DevicePool, config apiv1.InfraConfig, path string) (func() error, error)

Sets up a unix socket for devices to connect to and returns a function that listens on the socket until an error occurrs.

Types

type AppError

type AppError struct {
	Msg        string
	StatusCode int
	Err        error
}

func (*AppError) Error

func (e *AppError) Error() string

func (*AppError) JSONResponse

func (e *AppError) JSONResponse() apiv1.ErrorMsg

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

type Client

type Client interface {
	// Send a message to the device
	Send(msg interface{}) error
	// Provides an oportunity for the client to react to the device being disconnected
	OnDeviceDisconnected()
}

type Device

type Device struct {

	// Provided at pre-registration time
	Descriptor apiv1.DeviceDescriptor

	// Reverse proxy to the client files
	Proxy *httputil.ReverseProxy
	// contains filtered or unexported fields
}

func (*Device) DisconnectClients

func (d *Device) DisconnectClients()

Notify the clients that the device has disconnected

func (*Device) Register

func (d *Device) Register(c Client) int

func (*Device) Send

func (d *Device) Send(msg interface{}) error

Sends a message to the device

func (*Device) ToClient

func (d *Device) ToClient(id int, msg interface{}) error

Send a message to the client

func (*Device) Unregister

func (d *Device) Unregister(id int)

type DevicePool

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

Keeps track of the registered devices.

func NewDevicePool

func NewDevicePool() *DevicePool

func (*DevicePool) CancelPreRegistration

func (p *DevicePool) CancelPreRegistration(id string)

func (*DevicePool) DeviceIds

func (p *DevicePool) DeviceIds() []string

List the registered devices' ids

func (*DevicePool) GetDevice

func (p *DevicePool) GetDevice(id string) *Device

func (*DevicePool) GetDeviceDescByGroupId

func (p *DevicePool) GetDeviceDescByGroupId(groupId string) []*apiv1.DeviceDescriptor

func (*DevicePool) GetDeviceDescList

func (p *DevicePool) GetDeviceDescList() []*apiv1.DeviceDescriptor

func (*DevicePool) GroupIds

func (p *DevicePool) GroupIds() []string

List the registered groups' ids

func (*DevicePool) PreRegister

func (p *DevicePool) PreRegister(Descriptor *apiv1.DeviceDescriptor, regCh chan bool) error

PreRegister accepts a channel of boolean which it closes if the pre-registration is cancelled or sends the output of registering the device as a boolean.

func (*DevicePool) Register

func (p *DevicePool) Register(id string, conn *JSONUnix, port int, privateData interface{}) *Device

Register a new device, returns false if a device with that id already exists

func (*DevicePool) Unregister

func (p *DevicePool) Unregister(id string)

type Group

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

type JSONConn

type JSONConn interface {
	Send(val interface{}) error
}

Interface implemented by any connection capable of sending in JSON format

type JSONUnix

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

A Unix socket connection (as returned by Accept) that can send and receive JSON objects. Only one thread should call Recv() at a time, Send and Close are thread safe

func NewJSONUnix

func NewJSONUnix(c *net.UnixConn) *JSONUnix

func (*JSONUnix) Close

func (c *JSONUnix) Close()

func (*JSONUnix) Recv

func (c *JSONUnix) Recv(val interface{}) error

func (*JSONUnix) Send

func (c *JSONUnix) Send(val interface{}) error

type PolledClient

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

Implements the client interface using a polled connection

func (*PolledClient) ClientId

func (c *PolledClient) ClientId() int

func (*PolledClient) GetMessages

func (c *PolledClient) GetMessages(start int, count int) []interface{}

Gets count messages from the device, skipping the first start messages

func (*PolledClient) Id

func (c *PolledClient) Id() string

func (*PolledClient) OnDeviceDisconnected

func (c *PolledClient) OnDeviceDisconnected()

func (*PolledClient) Send

func (c *PolledClient) Send(msg interface{}) error

From IClient

func (*PolledClient) ToDevice

func (c *PolledClient) ToDevice(msg interface{}) error

Sends a message to the device

type PolledSet

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

Basically a map of polled clients by id.

func NewPolledSet

func NewPolledSet() *PolledSet

func (*PolledSet) Destroy

func (s *PolledSet) Destroy(id string)

func (*PolledSet) GetConnection

func (s *PolledSet) GetConnection(id string) *PolledClient

func (*PolledSet) NewConnection

func (s *PolledSet) NewConnection(d *Device) *PolledClient

Jump to

Keyboard shortcuts

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