servicelabel

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

README

Service Label

The servicelabel is a small Core Agent Plugin, which other plugins can use to obtain the microservice label, i.e. the string used to identify the particular VNF. The label is primarily used to prefix keys in etcd datastore so that the configurations of different VNFs do not get mixed up.

API

described in doc.go

Configuration

  • the serviceLabel can be set either by commandline flag microservice-label or environment variable MICROSERVICE_LABEL

Dependencies

-

Example

Example of retrieving and using the microservice label:

plugin.Label = servicelabel.GetAgentLabel()
dbw.Watch(dataChan, cfg.SomeConfigKeyPrefix(plugin.Label))

Documentation

Overview

Package servicelabel provides support for creating/retrieving an identifier (a service label) for a CN-Infra based app.

p := serviceLabel.Plugin{}
// initialization plugin handled by agent core

To retrieve service label of the VNF instance, run:

label = p.GetAgentLabel()

To retrieve prefix that can be used to access configuration of the VNF instance in key-value datastore, run:

prefix = p.GetAgentPrefix()

To retrieve prefix for a different VNF instance, run:

otherPrefix = p.GetDifferentAgentPrefix(differentLabel)

To retrieve prefix that identifies configuration of all instances:

allInstances = p.GetAllAgentsPrefix()

Index

Constants

View Source
const MicroserviceLabelEnvVar = "MICROSERVICE_LABEL"

MicroserviceLabelEnvVar label is inferred from the flag name.

Variables

This section is empty.

Functions

func GetAllAgentsPrefix

func GetAllAgentsPrefix() string

GetAllAgentsPrefix returns the part of the key prefix common to all prefixes of all agents.

func GetDifferentAgentPrefix

func GetDifferentAgentPrefix(microserviceLabel string) string

GetDifferentAgentPrefix returns the key prefix used by (another) Agent instance from microservice labelled as <microserviceLabel>.

Types

type Plugin

type Plugin struct {
	// MicroserviceLabel identifies particular VNF.
	// Used primarily as a key prefix to ETCD data store.
	MicroserviceLabel string
}

Plugin exposes the service label(i.e. the string used to identify the particular VNF) to the other plugins.

func OfDifferentAgent added in v1.0.3

func OfDifferentAgent(microserviceLabel string) *Plugin

OfDifferentAgent sets micorserivce label and returns new instance of Plugin. It is meant for watching DB by prefix of different agent. You can pass/inject instance of this plugin for example to kvdbsync.

func (*Plugin) Close

func (p *Plugin) Close() error

Close is called at plugin cleanup phase.

func (*Plugin) GetAgentLabel

func (p *Plugin) GetAgentLabel() string

GetAgentLabel returns string that is supposed to be used to distinguish (ETCD) key prefixes for particular VNF (particular VPP Agent configuration)

func (*Plugin) GetAgentPrefix

func (p *Plugin) GetAgentPrefix() string

GetAgentPrefix returns the string that is supposed to be used as the prefix for configuration of current MicroserviceLabel "subtree" of the particular VPP Agent instance (e.g. in ETCD).

func (*Plugin) GetAllAgentsPrefix

func (p *Plugin) GetAllAgentsPrefix() string

GetAllAgentsPrefix returns the string that is supposed to be used as the prefix for configuration subtree of the particular VPP Agent instance (e.g. in ETCD).

func (*Plugin) GetDifferentAgentPrefix

func (p *Plugin) GetDifferentAgentPrefix(microserviceLabel string) string

GetDifferentAgentPrefix returns the string that is supposed to be used as the prefix for configuration "subtree" of the particular VPP Agent instance (e.g. in ETCD).

func (*Plugin) Init

func (p *Plugin) Init() error

Init is called at plugin initialization.

type ReaderAPI

type ReaderAPI interface {
	// GetAgentLabel return the microservice label associated with this Agent
	// instance.
	GetAgentLabel() string

	// GetAgentPrefix returns the string that is supposed to be used
	// as the key prefix for the configuration "subtree" of the current Agent
	// instance (e.g. in ETCD).
	GetAgentPrefix() string
	// GetDifferentAgentPrefix returns the key prefix used by (another) Agent
	// instance from microservice labelled as <microserviceLabel>.
	GetDifferentAgentPrefix(microserviceLabel string) string

	// GetAllAgentsPrefix returns the part of the key prefix common to all
	// prefixes of all agents.
	GetAllAgentsPrefix() string
}

ReaderAPI allows to read microservice label and key prefix associated with this Agent instance. The key prefix is supposed to be prepended to all keys used to store/read data in any key-value datastore. The intent is to give a common prefix to all keys used by a single agent. Furthermore, different agents have different prefixes assigned, hence there is no overlap of key spaces in-between agents.

Jump to

Keyboard shortcuts

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