handlers

package
v0.0.0-...-89602ce Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: BSD-3-Clause Imports: 28 Imported by: 5

Documentation

Index

Constants

View Source
const (
	CommandRootV1           = ManageGatewayPath + "/command"
	RebootGatewayV1         = CommandRootV1 + "/reboot"
	RestartServicesV1       = CommandRootV1 + "/restart_services"
	GatewayPingV1           = CommandRootV1 + "/ping"
	GatewayGenericCommandV1 = CommandRootV1 + "/generic"
	TailGatewayLogsV1       = CommandRootV1 + "/tail_logs"
)
View Source
const (
	Networks                           = "networks"
	ListNetworksPath                   = obsidian.V1Root + Networks
	RegisterNetworkPath                = obsidian.V1Root + Networks
	ManageNetworkPath                  = obsidian.V1Root + Networks + obsidian.UrlSep + ":network_id"
	ManageNetworkNamePath              = ManageNetworkPath + obsidian.UrlSep + "name"
	ManageNetworkTypePath              = ManageNetworkPath + obsidian.UrlSep + "type"
	ManageNetworkDescriptionPath       = ManageNetworkPath + obsidian.UrlSep + "description"
	ManageNetworkFeaturesPath          = ManageNetworkPath + obsidian.UrlSep + "features"
	ManageNetworkDNSPath               = ManageNetworkPath + obsidian.UrlSep + "dns"
	ManageNetworkDNSRecordsPath        = ManageNetworkDNSPath + obsidian.UrlSep + "records"
	ManageNetworkDNSRecordByDomainPath = ManageNetworkDNSRecordsPath + obsidian.UrlSep + ":domain"

	Gateways                     = "gateways"
	ListGatewaysPath             = ManageNetworkPath + obsidian.UrlSep + Gateways
	ManageGatewayPath            = ListGatewaysPath + obsidian.UrlSep + ":gateway_id"
	ManageGatewayNamePath        = ManageGatewayPath + obsidian.UrlSep + "name"
	ManageGatewayDescriptionPath = ManageGatewayPath + obsidian.UrlSep + "description"
	ManageGatewayConfigPath      = ManageGatewayPath + obsidian.UrlSep + "magmad"
	ManageGatewayDevicePath      = ManageGatewayPath + obsidian.UrlSep + "device"
	ManageGatewayStatePath       = ManageGatewayPath + obsidian.UrlSep + "status"
	ManageGatewayTierPath        = ManageGatewayPath + obsidian.UrlSep + "tier"

	Channels               = "channels"
	ListChannelsPath       = obsidian.V1Root + Channels
	ManageChannelPath      = obsidian.V1Root + Channels + obsidian.UrlSep + ":channel_id"
	Tiers                  = "tiers"
	ListTiersPath          = ManageNetworkPath + obsidian.UrlSep + Tiers
	ManageTiersPath        = ListTiersPath + obsidian.UrlSep + ":tier_id"
	ManageTierNamePath     = ManageTiersPath + obsidian.UrlSep + "name"
	ManageTierVersionPath  = ManageTiersPath + obsidian.UrlSep + "version"
	ManageTierImagesPath   = ManageTiersPath + obsidian.UrlSep + "images"
	ManageTierImagePath    = ManageTierImagesPath + obsidian.UrlSep + ":image_name"
	ManageTierGatewaysPath = ManageTiersPath + obsidian.UrlSep + "gateways"
	ManageTierGatewayPath  = ManageTierGatewaysPath + obsidian.UrlSep + ":gateway_id"

	LogSearchQueryPath = ManageNetworkPath + obsidian.UrlSep + "logs" + obsidian.UrlSep + "search"
	LogCountQueryPath  = ManageNetworkPath + obsidian.UrlSep + "logs" + obsidian.UrlSep + "count"
)
View Source
const (
	NetworkLogLabel = "network_id"
)

Variables

This section is empty.

Functions

func CreateDNSRecord

func CreateDNSRecord(c echo.Context) error

func CreateGatewayHandler

func CreateGatewayHandler(c echo.Context) error

func CreateMagmadGatewayFromModel

func CreateMagmadGatewayFromModel(c echo.Context, model MagmadEncompassingGateway) *echo.HTTPError

func DeleteDNSRecord

func DeleteDNSRecord(c echo.Context) error

func DeleteGatewayHandler

func DeleteGatewayHandler(c echo.Context) error

func GetAndValidatePayload

func GetAndValidatePayload(c echo.Context, model interface{}) (serde.ValidatableModel, *echo.HTTPError)

GetAndValidatePayload can be used by any model that implements ValidateModel Example:

payload, nerr := GetAndValidatePayload(c, &models.DNSConfigRecord{})
if nerr != nil {
	return nil, nerr
}
record := payload.(*models.DNSConfigRecord)

func GetCountLogHandler

func GetCountLogHandler(client *elastic.Client) func(c echo.Context) error

GetCountLogHandler returns the count query handler

func GetDeleteGatewayHandler

func GetDeleteGatewayHandler(path string, gatewayType string) obsidian.Handler

func GetGatewayDeviceHandlers

func GetGatewayDeviceHandlers(path string) []obsidian.Handler

GetGatewayDeviceHandlers returns GET and PUT handlers to read and update the device attached to the gateway.

func GetGatewayHandler

func GetGatewayHandler(c echo.Context) error

func GetListGatewaysHandler

func GetListGatewaysHandler(path string, gatewayType string, makeTypedGateways MakeTypedGateways) obsidian.Handler

func GetObsidianHandlers

func GetObsidianHandlers() []obsidian.Handler

GetObsidianHandlers returns all plugin-level obsidian handlers for orc8r

func GetPartialDeleteNetworkHandler

func GetPartialDeleteNetworkHandler(path string, key string) obsidian.Handler

GetPartialDeleteNetworkHandler returns a DELETE obsidian handler at the specified path. The handler will delete a network config specified by the key. Example:

		deleteNetworkFeaturesHandler := handlers.GetPartialDeleteNetworkHandler(URL, "orc8r_features")

     would return a DELETE handler that will remove the network features config from the corresponding network

func GetPartialEntityHandlers

func GetPartialEntityHandlers(path string, paramName string, model PartialEntityModel) []obsidian.Handler

GetPartialEntityHandlers returns both GET and PUT handlers for modifying the portion of a network entity specified by the model.

  • path : the url at which the handler will be registered.
  • paramName: the parameter name in the url at which the entity key is stored
  • model: the input and output of the handler and it also provides FromBackendModels and ToUpdateCriteria to go between the configurator model.

func GetPartialGatewayHandlers

func GetPartialGatewayHandlers(path string, model PartialGatewayModel) []obsidian.Handler

GetPartialGatewayHandlers returns both GET and PUT handlers for modifying the portion of a network entity specified by the model.

  • path : the url at which the handler will be registered.
  • model: the input and output of the handler and it also provides FromBackendModels and ToUpdateCriteria to go between the configurator model.

func GetPartialNetworkHandlers

func GetPartialNetworkHandlers(path string, model PartialNetworkModel, configKey string) []obsidian.Handler

GetPartialNetworkHandlers returns a set of GET/PUT/DELETE handlers according to the parameters. If the configKey is not "", it will add a delete handler for the network config for that key.

func GetPartialReadEntityHandler

func GetPartialReadEntityHandler(path string, paramName string, model PartialEntityModel) obsidian.Handler

GetPartialReadEntityHandler returns a GET obsidian handler at the specified path. This function loads a portion of the gateway specified by the model's FromBackendModels function. Example:

		(m *TierName) FromBackendModels(networkID, tierID string) error {
			entity, err := configurator.LoadEntity(networkID, orc8r.UpgradeTierEntityType, key, configurator.EntityLoadCriteria{LoadMetadata: true})
			if err != nil {
				return err
			}
			*m = TierName(entity.Name)
			return nil
		}
		getTierNameHandler := handlers.GetPartialReadEntityHandler(URL, "tier_id", new(models.TierName))
     would return a GET handler that can read the tier name of a tier with the specified ID.

func GetPartialReadGatewayHandler

func GetPartialReadGatewayHandler(path string, model PartialGatewayModel) obsidian.Handler

GetPartialReadGatewayHandler returns a GET obsidian handler at the specified path. This function loads a portion of the gateway specified by the model's FromBackendModels function. Example:

     (m *MagmadGatewayConfigs) FromBackendModels(networkID, gatewayID) (PartialGatewayModel, error) {
			return configurator.LoadEntityConfig(networkID, orc8r.MagmadGatewayType, gatewayID)
		}
		getMagmadConfigsHandler := handlers.GetPartialReadGatewayHandler(URL, &models.MagmadGatewayConfigs{})

     would return a GET handler that can read the magmad gateway config of a gw with the specified ID.

func GetPartialReadNetworkHandler

func GetPartialReadNetworkHandler(path string, model PartialNetworkModel) obsidian.Handler

GetPartialReadNetworkHandler returns a GET obsidian handler at the specified path. This function loads a network specified by the networkID and returns the part of the network that corresponds to the given model. Example:

     (m *NetworkName) GetFromNetwork(network configurator.Network) interface{} {
			return string(network.Name)
		}
		getNameHandler := handlers.GetPartialReadNetworkHandler(URL, &models.NetworkName{})

     would return a GET handler that can read the network name of a network with the specified ID.

func GetPartialUpdateEntityHandler

func GetPartialUpdateEntityHandler(path string, paramName string, model PartialEntityModel) obsidian.Handler

GetPartialUpdateEntityHandler returns a PUT obsidian handler at the specified path. This function updates a portion of the network entity specified by the model's ToUpdateCriteria function. Example:

     (m *TierName) ToUpdateCriteria(networkID, tierID string) (configurator.EntityUpdateCriteria, error) {
			return configurator.EntityUpdateCriteria{
				{
					Key: gatewayID,
					Type: orc8r.MagmadGatewayType,
					NewName: m,
				}
         }
		}
		updateTierNameHandler := handlers.GetPartialUpdateEntityHandler(URL, "tier_id", new(models.TierName))
     would return a PUT handler that updates the tier name of a tier with the specified ID.

func GetPartialUpdateGatewayHandler

func GetPartialUpdateGatewayHandler(path string, model PartialGatewayModel) obsidian.Handler

GetPartialUpdateGatewayHandler returns a PUT obsidian handler at the specified path. This function updates a portion of the network entity specified by the model's ToUpdateCriteria function. Example:

     (m *MagmadGatewayConfigs) ToUpdateCriteria(networkID, gatewayID) ([]configurator.EntityUpdateCriteria, error) {
			return []configurator.EntityUpdateCriteria{
				{
					Key: gatewayID,
					Type: orc8r.MagmadGatewayType,
					NewConfig: m,
				}
         }
		}
		updateMagmadConfigsHandler := handlers.GetPartialUpdateGatewayHandler(URL, &models.MagmadGatewayConfigs{})

     would return a PUT handler that updates the magmad gateway config of a gw with the specified ID.

func GetPartialUpdateNetworkHandler

func GetPartialUpdateNetworkHandler(path string, model PartialNetworkModel) obsidian.Handler

GetPartialUpdateNetworkHandler returns a PUT obsidian handler at the specified path. The handler will fetch the payload into the configModel and perform validations according to the swagger spec. updater will take the model and apply the change into an existing network. Example:

     (m *NetworkName) ToUpdateCriteria(network configurator.Network) interface{} {
			return configurator.NetworkUpdateCriteria{
				ID:   network.ID,
				Name: *m,
			}
     }
		putNameHandler := handlers.GetPartialUpdateNetworkHandler(URL, &models.NetworkName{})

     would return a PUT handler that will intake a NetworkName model and update the corresponding network

func GetQueryLogHandler

func GetQueryLogHandler(client *elastic.Client) func(c echo.Context) error

func GetReadGatewayDeviceHandler

func GetReadGatewayDeviceHandler(path string) obsidian.Handler

GetReadGatewayDeviceHandler returns a GET handler to read the gateway record of the gateway.

func GetStateHandler

func GetStateHandler(c echo.Context) error

func GetTypedNetworkCRUDHandlers

func GetTypedNetworkCRUDHandlers(listCreatePath string, getUpdateDeletePath string, networkType string, network NetworkModel) []obsidian.Handler

func GetUpdateGatewayDeviceHandler

func GetUpdateGatewayDeviceHandler(path string) obsidian.Handler

GetUpdateGatewayDeviceHandler returns a PUT handler to update the gateway record of the gateway.

func ListGatewaysHandler

func ListGatewaysHandler(c echo.Context) error

func LoadMagmadGatewayModel

func LoadMagmadGatewayModel(networkID string, gatewayID string) (*models.MagmadGateway, *echo.HTTPError)

func ReadDNSRecord

func ReadDNSRecord(c echo.Context) error

func UpdateDNSRecord

func UpdateDNSRecord(c echo.Context) error

func UpdateGatewayHandler

func UpdateGatewayHandler(c echo.Context) error

func UpdateMagmadGatewayFromModel

func UpdateMagmadGatewayFromModel(c echo.Context, nid string, gid string, model MagmadEncompassingGateway) *echo.HTTPError

Types

type GatewayModel

type GatewayModel interface{}

NetworkModel describes models that represent a certain type of gateway. For example, an LTE gateway, that can be read/updated/deleted

type MagmadEncompassingGateway

type MagmadEncompassingGateway interface {
	// ValidatableModel allows the model to be validated by calling
	// ValidateModel()
	serde.ValidatableModel

	// GetMagmadGateway returns the *models.MagmadGateway which is wrapped by
	// the model
	GetMagmadGateway() *models.MagmadGateway

	// GetAdditionalWritesOnCreate returns extra write operations to perform
	// during creation, inside the same backend transaction as the creation
	// of the magmad gateway.
	// Do NOT include the write operation for the magmad gateway in the return
	// value, as *models.MagmadGateway itself implements this interface and
	// will create itself.
	GetAdditionalWritesOnCreate() []configurator.EntityWriteOperation

	// GetAdditionalEntitiesToLoadOnUpdate is a **static** method which
	// returns a list of entity keys to load in addition to the magmad gateway
	// during an update operation. The gateway ID from the API URL parameter
	// is given as an argument.
	// The entities loaded during this operation will be passed to
	// `GetAdditionalWritesOnUpdate`.
	GetAdditionalEntitiesToLoadOnUpdate(gatewayID string) []storage.TypeAndKey

	// GetAdditionalWritesOnUpdate returns extra write operations to perform
	// during a top-level update, inside the same backend transaction as the
	// update of the magmad gateway.
	// The gateway ID from the API URL parameter is given as an argument.
	// Do NOT include the write operation for the magmad gateway in the return
	// value, as *models.MagmadGateway itself implements this interface and
	// will update itself.
	GetAdditionalWritesOnUpdate(
		gatewayID string,
		loadedEntities map[storage.TypeAndKey]configurator.NetworkEntity,
	) ([]configurator.EntityWriteOperation, error)
}

MagmadEncompassingGateway is an interface for a gateway API model which wraps the magmad gateway with more fields that translate into additional network entities in the storage layer. Note that *models.MagmadGateway itself implements this interface as well.

type MakeTypedGateways

type MakeTypedGateways func(
	entsByTK map[storage.TypeAndKey]configurator.NetworkEntity,
	devicesByID map[string]interface{},
	statusesByID map[string]*models.GatewayStatus,
) map[string]GatewayModel

type NetworkModel

type NetworkModel interface {
	serde.ValidatableModel
	// GetEmptyNetwork creates a new instance of the typed NetworkModel.
	// It should be empty
	GetEmptyNetwork() NetworkModel
	// ToConfiguratorNetwork should convert the Network model to
	// a configurator.network
	ToConfiguratorNetwork() configurator.Network
	// ToUpdateCriteria takes in the existing network and applies the change
	// from the model to create a NetworkUpdateCriteria
	ToUpdateCriteria() configurator.NetworkUpdateCriteria
	// FromConfiguratorNetwork should return a copy of the network
	FromConfiguratorNetwork(n configurator.Network) interface{}
}

NetworkModel describes models that represent a certain type of network. For example, an LTE network, that can be read/updated/deleted

type PartialEntityModel

type PartialEntityModel interface {
	serde.ValidatableModel
	// FromBackendModels the same PartialEntityModel from the configurator
	// entities attached to the networkID and key.
	FromBackendModels(networkID string, key string) error
	// ToUpdateCriteria returns a EntityUpdateCriteria needed to apply
	// the change in the model.
	ToUpdateCriteria(networkID string, key string) ([]configurator.EntityUpdateCriteria, error)
}

PartialEntityModel describe models that represents a portion of network entity that can be read and updated.

type PartialGatewayModel

type PartialGatewayModel interface {
	serde.ValidatableModel
	// FromBackendModels the same PartialGatewayModel from the configurator
	// entities attached to the networkID and gatewayID.
	FromBackendModels(networkID string, gatewayID string) error
	// ToUpdateCriteria returns a list of EntityUpdateCriteria needed to apply
	// the change in the model.
	ToUpdateCriteria(networkID string, gatewayID string) ([]configurator.EntityUpdateCriteria, error)
}

PartialGatewayModel describe models that represents a portion of network entity that can be read and updated.

type PartialNetworkModel

type PartialNetworkModel interface {
	serde.ValidatableModel
	// GetFromNetwork grabs the desired model from the configurator network.
	// Returns nil if it is not there.
	GetFromNetwork(network configurator.Network) interface{}
	// ToUpdateCriteria takes in the existing network and applies the change
	// from the model to create a NetworkUpdateCriteria
	ToUpdateCriteria(network configurator.Network) (configurator.NetworkUpdateCriteria, error)
}

PartialNetworkModel describe models that represents a portion of network that can be read, updated, and deleted.

Jump to

Keyboard shortcuts

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