api

package
v0.0.0-...-4862416 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IllegalInputCharRegex = `[^-*+()?&! _\w\d.@,:/\\]`
View Source
var Unconfiguring bool

Global "static" field to remember that unconfig is in progress. We can't tell from the configstate in the node object because it eventually gets deleted at the end of unconfiguration.

Functions

func CreateHorizonDevice

func CreateHorizonDevice(device *HorizonDevice,
	errorhandler ErrorHandler,
	getOrg exchange.OrgHandlerWithContext,
	getPatterns exchange.PatternHandlerWithContext,
	em *events.EventStateManager,
	db *bolt.DB) (bool, *HorizonDevice, *HorizonDevice)

Given a demarshalled HorizonDevice object, validate it and save it, returning any errors.

func DeleteAgreement

func DeleteAgreement(errorhandler ErrorHandler, agreementId string, db *bolt.DB) (bool, *events.ApiAgreementCancelationMessage)

func DeleteHorizonDevice

func DeleteHorizonDevice(removeNode string,
	block string,
	em *events.EventStateManager,
	msgQueue chan events.Message,
	errorhandler ErrorHandler,
	db *bolt.DB) bool

Handles the DELETE verb on this resource.

func DeletePublicKey

func DeletePublicKey(fileName string,
	config *config.HorizonConfig,
	errorhandler ErrorHandler) bool

func FinalizeAttributesSpecifiedInService

func FinalizeAttributesSpecifiedInService(defaultRAM int64, sensorURL string, attributes []persistence.Attribute) []persistence.Attribute

func FindAgreementsForOutput

func FindAgreementsForOutput(db *bolt.DB) (map[string]map[string][]persistence.EstablishedAgreement, error)

func FindAndWrapAttributesForOutput

func FindAndWrapAttributesForOutput(db *bolt.DB, id string) (map[string][]Attribute, error)

serializeAttributeForOutput retrieves attributes by url from the DB and then serializes then as JSON, returning a byte array for convenient writing to an HTTP response.

func FindEventLogsForOutput

func FindEventLogsForOutput(db *bolt.DB, all_logs bool, selections map[string][]string) ([]persistence.EventLog, error)

This API returns the event logs saved on the db.

func FindPublicKeyForOutput

func FindPublicKeyForOutput(fileName string, config *config.HorizonConfig) (string, error)

func FindPublicKeysForOutput

func FindPublicKeysForOutput(config *config.HorizonConfig, verbose bool) (map[string][]interface{}, error)

func FindServiceConfigForOutput

func FindServiceConfigForOutput(pm *policy.PolicyManager, db *bolt.DB) (map[string][]MicroserviceConfig, error)

func GetMicroserviceContainer

func GetMicroserviceContainer(dockerEndpoint string, mURL string, mVersion string, mInstanceId string) ([]dockerclient.APIContainers, error)

Get docker container metadata from the docker API for microservice containers

func GetWorkloadContainers

func GetWorkloadContainers(dockerEndpoint string, agreementId string) ([]dockerclient.APIContainers, error)

Get docker container metadata from the docker API for workload containers

func InputIsIllegal

func InputIsIllegal(str string) (string, error)

func LogDeviceEvent

func LogDeviceEvent(db *bolt.DB, severity string, message string, event_code string, device interface{})

func LogServiceEvent

func LogServiceEvent(db *bolt.DB, severity string, message string, event_code string, service *Service)

func MapInputIsIllegal

func MapInputIsIllegal(m map[string]interface{}) (string, string, error)

returns: faulty value, msg, error

func NoOpStateChange

func NoOpStateChange(from string, to string) bool

func UpdateHorizonDevice

func UpdateHorizonDevice(device *HorizonDevice,
	errorhandler ErrorHandler,
	db *bolt.DB) (bool, *HorizonDevice, *HorizonDevice)

Handles the PATCH verb on this resource. Only the exchange token is updateable.

func UploadPublicKey

func UploadPublicKey(filename string,
	inBytes []byte,
	config *config.HorizonConfig,
	errorhandler ErrorHandler) bool

func ValidStateChange

func ValidStateChange(from string, to string) bool

func ValidateAndConvertAPIAttribute

func ValidateAndConvertAPIAttribute(errorhandler ErrorHandler, permitEmpty bool, given Attribute) (persistence.Attribute, bool, error)

Types

type API

type API struct {
	worker.Manager // embedded field

	EC *worker.BaseExchangeContext
	// contains filtered or unexported fields
}

func NewAPIListener

func NewAPIListener(name string, config *config.HorizonConfig, db *bolt.DB, pm *policy.PolicyManager) *API

func (*API) GetExchangeId

func (a *API) GetExchangeId() string

A local implementation of the ExchangeContext interface because the API object is not an anax worker.

func (*API) GetExchangeToken

func (a *API) GetExchangeToken() string

func (*API) GetExchangeURL

func (a *API) GetExchangeURL() string

func (*API) GetHTTPFactory

func (a *API) GetHTTPFactory() *config.HTTPClientFactory

func (*API) GetName

func (a *API) GetName() string

func (*API) Messages

func (a *API) Messages() chan events.Message

Worker framework functions

func (*API) NewEvent

func (a *API) NewEvent(incoming events.Message)

type APIMicroserviceConfig

type APIMicroserviceConfig struct {
	SensorUrl     string        `json:"sensor_url"`     // uniquely identifying
	SensorOrg     string        `json:"sensor_org"`     // The org that holds the ms definition
	SensorVersion string        `json:"sensor_version"` // added for ms split. It is only used for microsevice. If it is omitted, old behavior is assumed.
	AutoUpgrade   bool          `json:"auto_upgrade"`   // added for ms split. The default is true. If the sensor (microservice) should be automatically upgraded when new versions become available.
	ActiveUpgrade bool          `json:"active_upgrade"` // added for ms split. The default is false. If horizon should actively terminate agreements when new versions become available (active) or wait for all the associated agreements terminated before making upgrade.
	Attributes    []interface{} `json:"attributes"`
}

type APIUserInputError

type APIUserInputError struct {
	Err   string `json:"error"`
	Input string `json:"input,omitempty"`
}

APIUserInputError is for problems found with input path variables or input bodies. The Input field is flexible; could be a field name or other. Note: the info in this field is intended to be consumed by humans, either API consumers or developers of the UI. Add enum codes if these are to be evaluated in frontend code.

func NewAPIUserInputError

func NewAPIUserInputError(err string, input string) *APIUserInputError

func (APIUserInputError) Error

func (e APIUserInputError) Error() string

type AllMicroservices

type AllMicroservices struct {
	Config      []MicroserviceConfig     `json:"config"`      // the microservice configurations
	Instances   map[string][]interface{} `json:"instances"`   // the microservice instances that are running
	Definitions map[string][]interface{} `json:"definitions"` // the definitions of microservices from the exchange
}

The output format for GET microservice

func NewMicroserviceOutput

func NewMicroserviceOutput() *AllMicroservices

type AllServices

type AllServices struct {
	Config      []MicroserviceConfig     `json:"config"`      // the service configurations
	Instances   map[string][]interface{} `json:"instances"`   // the mservice instances that are running
	Definitions map[string][]interface{} `json:"definitions"` // the definitions of services from the exchange
}

The output format for GET service

func FindServicesForOutput

func FindServicesForOutput(pm *policy.PolicyManager,
	db *bolt.DB,
	config *config.HorizonConfig) (*AllServices, error)

This API returns everything we know about services configured to and running on an edge node. It includes service definition metadata that is cached from the exchange, userInput variable config for each service, running containers for each service, and the state of each service as it is being managed by anax.

func NewServiceOutput

func NewServiceOutput() *AllServices

type AllWorkloads

type AllWorkloads struct {
	Containers *[]dockerclient.APIContainers `json:"containers"` // the docker info for a running container
}

The output format for GET workload

func NewWorkloadOutput

func NewWorkloadOutput() *AllWorkloads

type Attribute

type Attribute struct {
	Id          *string                 `json:"id"`
	Type        *string                 `json:"type"`
	SensorUrls  *[]string               `json:"sensor_urls"`
	Label       *string                 `json:"label"`
	Publishable *bool                   `json:"publishable"`
	HostOnly    *bool                   `json:"host_only"`
	Mappings    *map[string]interface{} `json:"mappings"`
}

func NewAttribute

func NewAttribute(t string, sURLs []string, l string, publishable bool, hostOnly bool, mappings map[string]interface{}) *Attribute

func (Attribute) String

func (a Attribute) String() string

type AttributeVerifier

type AttributeVerifier func(attr persistence.Attribute) (bool, error)

AttributeVerifier returns true if there is a handled inputError (one that caused a write to the http responsewriter) and error if there is a system processing problem

type BadRequestError

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

Bad Requests are expected, since they can occur as the result of incorrect usage of the API.

func NewBadRequestError

func NewBadRequestError(err string) *BadRequestError

func (BadRequestError) Error

func (e BadRequestError) Error() string

type BlockchainState

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

type Configstate

type Configstate struct {
	State          *string `json:"state"`
	LastUpdateTime *uint64 `json:"last_update_time,omitempty"`
}

func FindConfigstateForOutput

func FindConfigstateForOutput(db *bolt.DB) (*Configstate, error)

func UpdateConfigstate

func UpdateConfigstate(cfg *Configstate,
	errorhandler ErrorHandler,
	getPatterns exchange.PatternHandler,
	resolveService exchange.ServiceResolverHandler,
	getService exchange.ServiceHandler,
	db *bolt.DB,
	config *config.HorizonConfig) (bool, *Configstate, []*events.PolicyCreatedMessage)

Given a demarshalled Configstate object, validate it and save, returning any errors.

func (*Configstate) String

func (c *Configstate) String() string

type ConflictError

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

Conflict Errors are expected, since they can occur as the result of incorrect usage of the API.

func NewConflictError

func NewConflictError(err string) *ConflictError

func (ConflictError) Error

func (e ConflictError) Error() string

type DuplicateServiceError

type DuplicateServiceError struct {
	Err   string `json:"error"`
	Input string `json:"input,omitempty"`
}

DuplicateServiceError occurs when a microservice configuration is attempted for a service that has already been configured.

func NewDuplicateServiceError

func NewDuplicateServiceError(err string, input string) *DuplicateServiceError

func (DuplicateServiceError) Error

func (e DuplicateServiceError) Error() string

type ErrorHandler

type ErrorHandler func(err error) bool

This function type is used to enable plug replaceable error handlers within the API implementation so that business logic can be tested independently from the HTTP transport that is used to access the API.

func GetHTTPErrorHandler

func GetHTTPErrorHandler(w http.ResponseWriter) ErrorHandler

Use this function to obtain an error handler that writes errors to the HTTP response.

func GetPassThroughErrorHandler

func GetPassThroughErrorHandler(passthruErr *error) ErrorHandler

Use this function to obtain an error handler that simply passes the error through itself back to caller. This is done by modifying the error variable passed to this function.

type EstablishedAgreementsByAgreementCreationTime

type EstablishedAgreementsByAgreementCreationTime []persistence.EstablishedAgreement

Functions and types that plug into the go sorting feature

func (EstablishedAgreementsByAgreementCreationTime) Len

func (EstablishedAgreementsByAgreementCreationTime) Less

func (EstablishedAgreementsByAgreementCreationTime) Swap

type EstablishedAgreementsByAgreementTerminatedTime

type EstablishedAgreementsByAgreementTerminatedTime []persistence.EstablishedAgreement

func (EstablishedAgreementsByAgreementTerminatedTime) Len

func (EstablishedAgreementsByAgreementTerminatedTime) Less

func (EstablishedAgreementsByAgreementTerminatedTime) Swap

type EventLogByRecordId

type EventLogByRecordId []persistence.EventLog

func (EventLogByRecordId) Len

func (s EventLogByRecordId) Len() int

func (EventLogByRecordId) Less

func (s EventLogByRecordId) Less(i, j int) bool

func (EventLogByRecordId) Swap

func (s EventLogByRecordId) Swap(i, j int)

type HorizonDevice

type HorizonDevice struct {
	Id                 *string      `json:"id"`
	Org                *string      `json:"organization"`
	Pattern            *string      `json:"pattern"` // a simple name, not prefixed with the org
	Name               *string      `json:"name,omitempty"`
	Token              *string      `json:"token,omitempty"`
	TokenLastValidTime *uint64      `json:"token_last_valid_time,omitempty"`
	TokenValid         *bool        `json:"token_valid,omitempty"`
	HA                 *bool        `json:"ha,omitempty"`
	Config             *Configstate `json:"configstate,omitempty"`
}

func ConvertFromPersistentHorizonDevice

func ConvertFromPersistentHorizonDevice(pDevice *persistence.ExchangeDevice) *HorizonDevice

This is a type conversion function but note that the token field within the persistent is explicitly omitted so that it's not exposed in the API.

func FindHorizonDeviceForOutput

func FindHorizonDeviceForOutput(db *bolt.DB) (*HorizonDevice, error)

func (HorizonDevice) String

func (h HorizonDevice) String() string

type KeyPairSimpleRecord

type KeyPairSimpleRecord struct {
	// embedded
	listkeys.KeyPairSimple
	ID string `json:"id"`
}

type MSMissingVariableConfigError

type MSMissingVariableConfigError struct {
	Err   string `json:"error"`
	Input string `json:"input,omitempty"`
}

MSMissingVariableConfigError is for problems found with microservice configuration where the microservice definition requires 1 or more input variables to be set but 1 or more of those variables has not been set.

func NewMSMissingVariableConfigError

func NewMSMissingVariableConfigError(err string, input string) *MSMissingVariableConfigError

func (MSMissingVariableConfigError) Error

type MicroserviceConfig

type MicroserviceConfig struct {
	SensorUrl     string                  `json:"sensor_url"`     // uniquely identifying
	SensorOrg     string                  `json:"sensor_org"`     // The org that holds the ms definition
	SensorVersion string                  `json:"sensor_version"` // added for ms split. It is only used for microsevice. If it is omitted, old behavior is assumed.
	AutoUpgrade   bool                    `json:"auto_upgrade"`   // added for ms split. The default is true. If the sensor (microservice) should be automatically upgraded when new versions become available.
	ActiveUpgrade bool                    `json:"active_upgrade"` // added for ms split. The default is false. If horizon should actively terminate agreements when new versions become available (active) or wait for all the associated agreements terminated before making upgrade.
	Attributes    []persistence.Attribute `json:"attributes"`
}

The output format for microservice config

func NewMicroserviceConfig

func NewMicroserviceConfig(url string, org string, version string) *MicroserviceConfig

type MicroserviceDefById

type MicroserviceDefById []interface{}

func (MicroserviceDefById) Len

func (s MicroserviceDefById) Len() int

func (MicroserviceDefById) Less

func (s MicroserviceDefById) Less(i, j int) bool

func (MicroserviceDefById) Swap

func (s MicroserviceDefById) Swap(i, j int)

type MicroserviceDefByUpgradeStartTime

type MicroserviceDefByUpgradeStartTime []interface{}

func (MicroserviceDefByUpgradeStartTime) Len

func (MicroserviceDefByUpgradeStartTime) Less

func (MicroserviceDefByUpgradeStartTime) Swap

type MicroserviceInstanceByCleanupStartTime

type MicroserviceInstanceByCleanupStartTime []interface{}

func (MicroserviceInstanceByCleanupStartTime) Len

func (MicroserviceInstanceByCleanupStartTime) Less

func (MicroserviceInstanceByCleanupStartTime) Swap

type MicroserviceInstanceByMicroserviceDefId

type MicroserviceInstanceByMicroserviceDefId []interface{}

func (MicroserviceInstanceByMicroserviceDefId) Len

func (MicroserviceInstanceByMicroserviceDefId) Less

func (MicroserviceInstanceByMicroserviceDefId) Swap

type MicroserviceInstanceOutput

type MicroserviceInstanceOutput struct {
	persistence.MicroserviceInstance                               // an embedded field
	Containers                       *[]dockerclient.APIContainers `json:"containers"` // the docker info for a running container
}

The output format for microservice instances

type NotFoundError

type NotFoundError struct {
	Err   string `json:"error"`
	Input string `json:"input,omitempty"`
}

Not Found errors are expected, since they can occur as the result of incorrect usage of the API.

func NewNotFoundError

func NewNotFoundError(err string, input string) *NotFoundError

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Service

type Service struct {
	Url           *string      `json:"url"`            // The URL of the service definition.
	Org           *string      `json:"organization"`   // The org that holds the service definition.
	Name          *string      `json:"name"`           // Optional, may not be uniquely identifying.
	Arch          *string      `json:"arch"`           // The arch of the service to be configured, could be a synonym.
	VersionRange  *string      `json:"versionRange"`   // The version range that the configuration applies to.
	AutoUpgrade   *bool        `json:"auto_upgrade"`   // The default is true. If the service should be automatically upgraded when a new version becomes available.
	ActiveUpgrade *bool        `json:"active_upgrade"` // The default is false. If horizon should actively terminate agreements when new versions become available (active) or wait for all the associated agreements to terminate before upgrading.
	Attributes    *[]Attribute `json:"attributes"`
}

uses pointers for members b/c it allows nil-checking at deserialization; !Important!: the json field names here must not change w/out changing the error messages returned from the API, they are not programmatically determined

func CreateService

func CreateService(service *Service,
	errorhandler ErrorHandler,
	getPatterns exchange.PatternHandler,
	resolveService exchange.ServiceResolverHandler,
	getService exchange.ServiceHandler,
	db *bolt.DB,
	config *config.HorizonConfig,
	from_user bool) (bool, *Service, *events.PolicyCreatedMessage)

Given a demarshalled Service object, validate it and save it, returning any errors.

func NewService

func NewService(url string, org string, name string, arch string, v string) *Service

Constructor used to create service objects for programmatic creation of services.

func (*Service) String

func (s *Service) String() string

type SystemError

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

System Errors are generally unexpected, infrastructural problems that just need to be reported out to the caller.

func NewSystemError

func NewSystemError(err string) *SystemError

func (SystemError) Error

func (e SystemError) Error() string

Jump to

Keyboard shortcuts

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