configurator

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: BSD-3-Clause Imports: 19 Imported by: 19

Documentation

Overview

Package configurator contains the Configurator service which manages configuration of and relationships between logical network entities.

Index

Constants

View Source
const (
	// ServiceName is the name of this service
	ServiceName = "CONFIGURATOR"

	// NetworkConfigSerdeDomain is the Serde domain for network configs
	NetworkConfigSerdeDomain = "configurator_network_configs"

	// NetworkEntitySerdeDomain is the Serde domain for network entity configs
	NetworkEntitySerdeDomain = "configurator_entity_configs"

	GatewayEntityType = "gateway"
)

Variables

This section is empty.

Functions

func ClearMconfigBuilders

func ClearMconfigBuilders(_ *testing.T)

ClearMconfigBuilders exists ONLY for testing - this the required but unused *testing.T parameter. DO NOT USE IN ANYTHING BUT TESTS

func CreateMconfig

func CreateMconfig(networkID string, gatewayID string, graph *storage.EntityGraph, network *storage.Network) (*protos.GatewayConfigs, error)

func CreateNetwork

func CreateNetwork(network Network) error

func CreateOrUpdateEntityConfig

func CreateOrUpdateEntityConfig(networkID string, entityType string, entityKey string, config interface{}) error

func CreateOrUpdateEntityConfigAndAssoc

func CreateOrUpdateEntityConfigAndAssoc(networkID string, entityType string, entityKey string, config interface{}, updatedAssoc []storage2.TypeAndKey) error

func DeleteEntities

func DeleteEntities(networkID string, ids []storage2.TypeAndKey) error

DeleteEntity deletes the entity specified by networkID, type, key We also have cascading deletes to delete foreign keys for assocs

func DeleteEntity

func DeleteEntity(networkID string, entityType string, entityKey string) error

func DeleteEntityConfig

func DeleteEntityConfig(networkID, entityType, entityKey string) error

func DeleteInternalEntity

func DeleteInternalEntity(entityType, entityKey string) error

DeleteInternalEntity is a loose wrapper around DeleteEntities to delete an entity in the internal network structure

func DeleteNetwork

func DeleteNetwork(networkID string) error

DeleteNetwork deletes a network.

func DeleteNetworkConfig

func DeleteNetworkConfig(networkID, configType string) error

func DeleteNetworks

func DeleteNetworks(networkIDs []string) error

DeleteNetworks deletes the network specified by networkID

func DoEntitiesExist

func DoEntitiesExist(networkID string, ids []storage2.TypeAndKey) (bool, error)

DoEntitiesExist returns a boolean that indicated whether all entities specified exist in the network

func DoesEntityExist

func DoesEntityExist(networkID, entityType, entityKey string) (bool, error)

DoesEntityExist returns a boolean that indicated whether the entity specified exists in the network

func DoesInternalEntityExist

func DoesInternalEntityExist(entityType, entityKey string) (bool, error)

DoesInternalEntityExist calls DoesEntityExist with the internal networkID

func DoesNetworkExist

func DoesNetworkExist(networkID string) (bool, error)

DoesNetworkExist returns a boolean that indicates whether the networkID

func GetMconfigFor

func GetMconfigFor(hardwareID string) (*protos.GetMconfigResponse, error)

func GetNetworkAndEntityIDForPhysicalID

func GetNetworkAndEntityIDForPhysicalID(physicalID string) (string, string, error)

GetNetworkAndEntityIDForPhysicalID gets the network ID and entity ID for the associated physical ID. If not found, returns ErrNotFound from "github.com/go-magma/magma/lib/go/errors.

func GetNetworkConfigsByType

func GetNetworkConfigsByType(networkID string, configType string) (interface{}, error)

func GetPhysicalIDOfEntity

func GetPhysicalIDOfEntity(networkID, entityType, entityKey string) (string, error)

GetPhysicalIDOfEntity gets the physicalID associated with the entity identified by (networkID, entityType, entityKey) If not found, returns ErrNotFound from "github.com/go-magma/magma/lib/go/errors.

func ListEntityKeys

func ListEntityKeys(networkID string, entityType string) ([]string, error)

ListEntityKeys returns all keys for an entity type in a network.

func ListInternalEntityKeys

func ListInternalEntityKeys(entityType string) ([]string, error)

ListInternalEntityKeys calls ListEntityKeys with the internal networkID

func ListNetworkIDs

func ListNetworkIDs() ([]string, error)

ListNetworkIDs loads a list of all networkIDs registered

func ListNetworksOfType

func ListNetworksOfType(networkType string) ([]string, error)

ListNetworksOfType returns a list of all network IDs which match the given type

func LoadEntityConfig

func LoadEntityConfig(networkID, entityType, entityKey string) (interface{}, error)

LoadEntityConfig loads the config for the entity identified by (network ID, entity type, entity key). If not found, returns ErrNotFound from "github.com/go-magma/magma/lib/go/errors.

func LoadNetworkConfig

func LoadNetworkConfig(networkID, configType string) (interface{}, error)

LoadNetworkConfig loads network config of type configType registered under the network ID. If not found, returns ErrNotFound from "github.com/go-magma/magma/lib/go/errors.

func NewNetworkConfigSerde

func NewNetworkConfigSerde(configType string, modelPtr serde.BinaryConvertible) serde.Serde

NewNetworkConfigSerde returns a network config domain Serde implementation for a pointer to a structure implementing both BinaryMarshaler and BinaryUnmarshaler. If the modelPtr argument is not a pointer to a struct matching those requirements, this function will panic.

func NewNetworkEntityConfigSerde

func NewNetworkEntityConfigSerde(configType string, modelPtr serde.BinaryConvertible) serde.Serde

NewNetworkEntityConfigSerde returns a network entity config domain Serde implementation/ for a pointer to a structure implementing both BinaryMarshaler and BinaryUnmarshaler. If the modelPtr argument is not a pointer to a struct matching those requirements, this function will panic.

func RegisterMconfigBuilders

func RegisterMconfigBuilders(builders ...MconfigBuilder)

RegisterMconfigBuilders registers a collection of MconfigBuilders to make available to the southbound configurator servicer to call when gateways request mconfigs.

func UpdateEntities

func UpdateEntities(networkID string, updates []EntityUpdateCriteria) (map[string]NetworkEntity, error)

UpdateEntities updates the registered entities and returns the updated entities

func UpdateNetworkConfig

func UpdateNetworkConfig(networkID, configType string, config interface{}) error

func UpdateNetworks

func UpdateNetworks(updates []NetworkUpdateCriteria) error

UpdateNetworks updates the specified networks and returns the updated networks

func WriteEntities

func WriteEntities(networkID string, writes ...EntityWriteOperation) error

WriteEntities executes a series of entity writes (creation or update) to be executed in order within a single transaction. This function is all-or-nothing - any failure or error encountered during any operation will rollback the entire batch.

Types

type EntityGraph

type EntityGraph struct {
	Entities     []NetworkEntity
	RootEntities []storage2.TypeAndKey
	Edges        []GraphEdge
	// contains filtered or unexported fields
}

EntityGraph represents a DAG of associated network entities

func (EntityGraph) FromStorageProto

func (eg EntityGraph) FromStorageProto(protoGraph *storage.EntityGraph) (EntityGraph, error)

FromStorageProto converts a proto EntityGraph to it's go struct format.

func (*EntityGraph) GetAllChildrenOfType

func (eg *EntityGraph) GetAllChildrenOfType(parent NetworkEntity, targetType string) ([]NetworkEntity, error)

func (*EntityGraph) GetEntitiesOfType

func (eg *EntityGraph) GetEntitiesOfType(entType string) []NetworkEntity

func (*EntityGraph) GetEntity

func (eg *EntityGraph) GetEntity(entType string, key string) (NetworkEntity, error)

func (*EntityGraph) GetEntityByTK

func (eg *EntityGraph) GetEntityByTK(id storage.TypeAndKey) (NetworkEntity, error)

func (*EntityGraph) GetFirstAncestorOfType

func (eg *EntityGraph) GetFirstAncestorOfType(start NetworkEntity, targetType string) (NetworkEntity, error)

func (EntityGraph) ToStorageProto

func (eg EntityGraph) ToStorageProto() (*storage.EntityGraph, error)

ToStorageProto converts an EntityGraph struct to it's proto representation.

type EntityLoadCriteria

type EntityLoadCriteria struct {
	// Set LoadMetadata to true to load the metadata fields (name, description)
	LoadMetadata bool

	LoadConfig bool

	LoadAssocsToThis   bool
	LoadAssocsFromThis bool
}

EntityLoadCriteria specifies how much of an entity to load

func FullEntityLoadCriteria

func FullEntityLoadCriteria() EntityLoadCriteria

FullEntityLoadCriteria returns an EntityLoadCriteria that loads everything possible on an entity

type EntityLoadFilter

type EntityLoadFilter struct {
	// If TypeFilter is provided, the query will return all entities matching
	// the given type.
	TypeFilter *string

	// If KeyFilter is provided, the query will return all entities matching the
	// given ID.
	KeyFilter *string

	// If IDs is provided, the query will return all entities matching the
	// provided TypeAndKeys. TypeFilter and KeyFilter are ignored if IDs is
	// provided.
	IDs []storage2.TypeAndKey

	// If PhysicalID is provided, the query will return all entities matching
	// the provided ID value.
	PhysicalID *string
}

EntityLoadFilter specifies which entities to load from storage

type EntityLoadResult

type EntityLoadResult struct {
	// Loaded entities
	Entities []NetworkEntity
	// Entities which were not found
	EntitiesNotFound []storage2.TypeAndKey
}

EntityLoadResult encapsulates the result of a LoadEntities call

type EntityUpdateCriteria

type EntityUpdateCriteria struct {
	// (Type, Key) of the entity to update
	Type string
	Key  string

	// Set DeleteEntity to true to mark the entity for deletion
	DeleteEntity bool

	NewName        *string
	NewDescription *string

	NewPhysicalID *string

	// A nil value here indicates no update.
	NewConfig interface{}

	// Set to true to clear the entity's config
	DeleteConfig bool

	// IMPORTANT: Setting AssociationsToSet to an empty, non-nil array value
	// specifies an intent to clear all associations originating from this
	// entity.
	// A nil field value will be ignored.
	AssociationsToSet    []storage2.TypeAndKey
	AssociationsToAdd    []storage2.TypeAndKey
	AssociationsToDelete []storage2.TypeAndKey
}

EntityUpdateCriteria specifies a patch operation on a network entity.

func (EntityUpdateCriteria) GetTypeAndKey

func (euc EntityUpdateCriteria) GetTypeAndKey() storage2.TypeAndKey

type EntityWriteOperation

type EntityWriteOperation interface {
	// contains filtered or unexported methods
}

EntityWriteOperation is an interface around entity creation/update for the generic multi-operation configurator endpoint.

type GraphEdge

type GraphEdge struct {
	From storage2.TypeAndKey
	To   storage2.TypeAndKey
}

type MconfigBuilder

type MconfigBuilder interface {
	// Build fills the mconfigOut parameter with parts of the gateway mconfig
	// that this mconfig builder is responsible for.
	// The whole entity graph associated with the gateway to build the mconfig
	// for is provided in the graph parameter, as well as the network that
	// the gateway belongs to. Both the graph and network will be loaded with
	// all fields.
	// mconfigOut is an output parameter - all updates should be made in-place
	// to this parameter.
	Build(networkID string, gatewayID string, graph EntityGraph, network Network, mconfigOut map[string]proto.Message) error
}

MconfigBuilder fills in a partial mconfig for a given gateway within a network.

type Network

type Network struct {
	ID string
	// Specifies the type of network. (lte, wifi, etc)
	Type string

	Name        string
	Description string

	// Configs maps between a type value and a generic configuration blob.
	// The map key will point to the Serde implementation which can
	// serialize the associated value.
	Configs map[string]interface{}

	Version uint64
}

A network represents a tenant. Networks can be configured in a hierarchical manner - network-level configurations are assumed to apply across multiple entities within the network.

func CreateNetworks

func CreateNetworks(networks []Network) ([]Network, error)

CreateNetworks registers the given list of Networks and returns the created networks

func LoadNetwork

func LoadNetwork(networkID string, loadMetadata bool, loadConfigs bool) (Network, error)

LoadNetwork loads the network identified by the network ID. If not found, returns ErrNotFound from "github.com/go-magma/magma/lib/go/errors.

func LoadNetworks

func LoadNetworks(networks []string, loadMetadata bool, loadConfigs bool) ([]Network, []string, error)

LoadNetworks loads networks specified by networks according to criteria specified and returns the result

func LoadNetworksByType

func LoadNetworksByType(typeVal string, loadMetadata bool, loadConfigs bool) ([]Network, error)

func (Network) FromStorageProto

func (n Network) FromStorageProto(protoNet *storage.Network) (Network, error)

FromStorageProto converts a Network proto to it's internal go struct format.

func (Network) ToStorageProto

func (n Network) ToStorageProto() (*storage.Network, error)

ToStorageProto converts a Network struct to its proto representation.

type NetworkEntities

type NetworkEntities []NetworkEntity

func LoadEntities

func LoadEntities(
	networkID string,
	typeFilter *string,
	keyFilter *string,
	physicalID *string,
	ids []storage2.TypeAndKey,
	criteria EntityLoadCriteria,
) (NetworkEntities, []storage2.TypeAndKey, error)

LoadEntities loads entities specified by the parameters. typeFilter, keyFilter, physicalID, and ids are all used to define a filter to filter out results - if they are all nil, it will return all network entities

func (NetworkEntities) ToEntitiesByID

func (ne NetworkEntities) ToEntitiesByID() map[storage2.TypeAndKey]NetworkEntity

type NetworkEntity

type NetworkEntity struct {
	// Network that the entity belongs to. This is a READ-ONLY field and will
	// be ignored if provided to write APIs.
	NetworkID string

	// (Type, Key) forms a unique identifier for the network entity within its
	// network.
	Type string
	Key  string

	Name        string
	Description string

	// PhysicalID will be non-empty if the entity corresponds to a physical
	// asset.
	PhysicalID string

	Config interface{}

	// GraphID is a mostly-internal field to designate the DAG that this
	// network entity belongs to. This field is system-generated and will be
	// ignored if set during entity creation.
	GraphID string

	// Associations are the directed edges originating from this entity.
	Associations []storage2.TypeAndKey

	// ParentAssociations are the directed edges ending at this entity.
	// This is a read-only field and will be ignored if set during entity
	// creation.
	ParentAssociations []storage2.TypeAndKey

	Version uint64
}

NetworkEntity is the storage representation of a logical component of a network. Networks are partitioned into DAGs of entities.

func CreateEntities

func CreateEntities(networkID string, entities []NetworkEntity) ([]NetworkEntity, error)

CreateEntities registers the given entities and returns the created network entities

func CreateEntity

func CreateEntity(networkID string, entity NetworkEntity) (NetworkEntity, error)

func CreateInternalEntity

func CreateInternalEntity(entity NetworkEntity) (NetworkEntity, error)

CreateInternalEntity is a loose wrapper around CreateEntity to create an entity in the internal network structure

func LoadAllEntitiesInNetwork

func LoadAllEntitiesInNetwork(networkID string, entityType string, criteria EntityLoadCriteria) ([]NetworkEntity, error)

LoadAllEntitiesInNetwork fetches all entities of specified type in a network

func LoadEntity

func LoadEntity(networkID string, entityType string, entityKey string, criteria EntityLoadCriteria) (NetworkEntity, error)

LoadEntity loads the network entity identified by (network ID, entity type, entity key). If not found, returns ErrNotFound from "github.com/go-magma/magma/lib/go/errors.

func LoadEntityForPhysicalID

func LoadEntityForPhysicalID(physicalID string, criteria EntityLoadCriteria) (NetworkEntity, error)

LoadEntityForPhysicalID loads the network entity identified by the physical ID. If not found, returns ErrNotFound from "github.com/go-magma/magma/lib/go/errors.

func LoadInternalEntity

func LoadInternalEntity(entityType string, entityKey string, criteria EntityLoadCriteria) (NetworkEntity, error)

LoadInternalEntity calls LoadEntity with the internal network ID. If not found, returns ErrNotFound from "github.com/go-magma/magma/lib/go/errors.

func UpdateEntity

func UpdateEntity(networkID string, update EntityUpdateCriteria) (NetworkEntity, error)

func UpdateInternalEntity

func UpdateInternalEntity(update EntityUpdateCriteria) (NetworkEntity, error)

UpdateInternalEntity is a loose wrapper around UpdateEntity to update an entity in the internal network structure

func (NetworkEntity) GetFirstParentOfType

func (ent NetworkEntity) GetFirstParentOfType(target string) (storage.TypeAndKey, error)

GetFirstParentOfType iterates through the parent associations of the entity and returns the TypeAndKey of first association that matches the target type. Returns ErrNotFound if no such association is found.

func (NetworkEntity) GetTypeAndKey

func (ent NetworkEntity) GetTypeAndKey() storage2.TypeAndKey

type NetworkUpdateCriteria

type NetworkUpdateCriteria struct {
	// ID of the network to update
	ID string

	// Set DeleteNetwork to true to delete the network
	DeleteNetwork bool

	// Set NewType, NewName or NewDescription to nil to indicate that no update is
	// desired. To clear the value of name or description, set these fields to
	// a pointer to an empty string.
	NewType        *string
	NewName        *string
	NewDescription *string

	// New config values to add or existing ones to update
	ConfigsToAddOrUpdate map[string]interface{}

	// Config values to delete
	ConfigsToDelete []string
}

NetworkUpdateCriteria specifies how to update a network

Directories

Path Synopsis
Package storage defines the storage interfaces and implementations for the configurator service.
Package storage defines the storage interfaces and implementations for the configurator service.

Jump to

Keyboard shortcuts

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