plugin

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: Apache-2.0 Imports: 18 Imported by: 5

Documentation

Overview

Package plugin provides an easy way to create the required CLI for a plugin. It abstracts away all the command line and file parsing so users just need to implement the actual logic.

Package plugin provides an easy way to create the required CLI for a plugin. It abstracts away all the command line and file parsing so users just need to implement the actual logic.

Package plugin provides an easy way to create the required CLI for a plugin. It abstracts away all the command line and file parsing so users just need to implement the actual logic.

Package plugin provides an easy way to create the required CLI for a plugin. It abstracts away all the command line and file parsing so users just need to implement the actual logic.

Please see the main BPM-SDK documentation for more details on how to implement a new plugin.

Index

Constants

View Source
const (
	ParameterTypeBool   = "bool"
	ParameterTypeString = "string"

	SupportsTest     = "test"
	SupportsUpgrade  = "upgrade"
	SupportsIdentity = "identity"
)
View Source
const (
	// ConfigsDirectory is the subdirectory under the node directory where configs are saved
	ConfigsDirectory = "configs"
)
View Source
const (
	// LogsDirectory is the subdirectory under the node directory where logs are saved
	LogsDirectory = "logs"
)

Variables

This section is empty.

Functions

func Initialize

func Initialize(plugin Plugin)

Initialize creates the CLI for a plugin

Types

type Configurator

type Configurator interface {
	// Function that creates the configuration for the node
	Configure(currentNode node.Node) error

	// Removes configuration related to the node
	RemoveConfig(currentNode node.Node) error
}

Configurator is the interface that wraps the Configure method

type DockerLifecycleHandler

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

DockerLifecycleHandler provides functions to manage a node using plain docker containers

func NewDockerLifecycleHandler

func NewDockerLifecycleHandler(containers []docker.Container) DockerLifecycleHandler

NewDockerLifecycleHandler creates an instance of DockerLifecycleHandler

func (DockerLifecycleHandler) RemoveData

func (d DockerLifecycleHandler) RemoveData(currentNode node.Node) error

RemoveData removes any data (typically the blockchain itself) related to the node

func (DockerLifecycleHandler) RemoveRuntime

func (d DockerLifecycleHandler) RemoveRuntime(currentNode node.Node) error

RemoveRuntime removes the docker network and containers

func (DockerLifecycleHandler) SetUpEnvironment added in v0.14.0

func (d DockerLifecycleHandler) SetUpEnvironment(currentNode node.Node) error

SetUpEnvironment configures the monitoring agents

func (DockerLifecycleHandler) Start

func (d DockerLifecycleHandler) Start(currentNode node.Node) error

Start starts monitoring agents and delegates to another function to start blockchain containers

func (DockerLifecycleHandler) Status

func (d DockerLifecycleHandler) Status(currentNode node.Node) (string, error)

Status returns the status of the running blockchain client and monitoring containers

func (DockerLifecycleHandler) Stop

func (d DockerLifecycleHandler) Stop(currentNode node.Node) error

Stop removes all containers

func (DockerLifecycleHandler) TearDownEnvironment added in v0.14.0

func (d DockerLifecycleHandler) TearDownEnvironment(currentNode node.Node) error

TearDownEnvironment is currently just a placeholder that does nothing

type DockerPlugin

type DockerPlugin struct {
	ParameterValidator
	IdentityCreator
	Configurator
	LifecycleHandler
	Upgrader
	Tester
	// contains filtered or unexported fields
}

DockerPlugin is an implementation of the Plugin interface. It provides based functionality for a docker based plugin

func NewDockerPlugin

func NewDockerPlugin(name string, version string, description string, parameters []Parameter, templates map[string]string, containers []docker.Container) DockerPlugin

NewDockerPlugin creates a new instance of DockerPlugin

func (DockerPlugin) Meta

func (d DockerPlugin) Meta() MetaInfo

Meta returns the MetaInfo of a plugin

func (DockerPlugin) Name

func (d DockerPlugin) Name() string

Name returns the name of a plugin

type DockerUpgrader

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

DockerUpgrader provides a default strategy for upgrading docker based nodes

The default upgrade strategy uses a LifecycleHandler to remove all containers. If they where running they get started again which will pull new container images.

This works as long as only the container versions change. If the the upgrade needs changes to the configs or migrations tasks it is recommended to provide a custom Upgrader.

func NewDockerUpgrader

func NewDockerUpgrader(containers []docker.Container) DockerUpgrader

NewDockerUpgrader instantiates DockerUpgrader

func (DockerUpgrader) Upgrade

func (d DockerUpgrader) Upgrade(currentNode node.Node) error

Upgrade upgrades all containers by removing and starting them again

type DummyTester

type DummyTester struct{}

DummyTester does nothing except panicking

This Tester can be used if the plugin doesn't support testing

func NewDummyTester

func NewDummyTester() DummyTester

func (DummyTester) Test

func (t DummyTester) Test(currentNode node.Node) (bool, error)

type FileConfigurator

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

FileConfigurator creates configuration files from templates

func NewFileConfigurator

func NewFileConfigurator(configFilesAndTemplates map[string]string) FileConfigurator

NewFileConfigurator creates an instance of FileConfigurator

func (FileConfigurator) Configure

func (d FileConfigurator) Configure(currentNode node.Node) error

Configure creates configuration files for the blockchain client

func (FileConfigurator) RemoveConfig

func (d FileConfigurator) RemoveConfig(currentNode node.Node) error

RemoveConfig removes configuration files related to the node

type IdentityCreator

type IdentityCreator interface {
	// Function that creates the identity of a node
	CreateIdentity(currentNode node.Node) error

	// Removes identity related to the node
	RemoveIdentity(currentNode node.Node) error
}

IdentityCreator provides functions to create and remove the identity (e.g. private keys) of a node

type LifecycleHandler

type LifecycleHandler interface {
	// SetUpEnvironment prepares the runtime environment
	SetUpEnvironment(currentNode node.Node) error
	// Function to start a node
	Start(currentNode node.Node) error
	// Function to stop a running node
	Stop(currentNode node.Node) error
	// Function to return the status (running, incomplete, stopped) of a node
	Status(currentNode node.Node) (string, error)
	// Removes any data (typically the blockchain itself) related to the node
	RemoveData(currentNode node.Node) error
	// Removes everything other than data and configuration related to the node
	RemoveRuntime(currentNode node.Node) error
	// TearDownEnvironment removes everything related to the node from the runtime environment
	TearDownEnvironment(currentNode node.Node) error
}

LifecycleHandler provides functions to manage a node

type MetaInfo

type MetaInfo struct {
	Name            string
	Version         string
	Description     string
	ProtocolVersion string `yaml:"protocol_version"`
	Parameters      []Parameter
	Supported       []string
}

func (MetaInfo) ProtocolVersionGreaterEqualThan added in v0.14.0

func (p MetaInfo) ProtocolVersionGreaterEqualThan(version string) bool

ProtocolVersionGreaterEqualThan return true if the protocol version is greater or equal to the provided version

func (MetaInfo) String

func (p MetaInfo) String() string

func (MetaInfo) Supports

func (p MetaInfo) Supports(supported string) bool

Supports returns bool if a particular method is supported

type Parameter

type Parameter struct {
	Type        string
	Name        string
	Description string
	Mandatory   bool
	Default     string
}

type ParameterValidator

type ParameterValidator interface {
	// ValidateParameters validates the ndoe parameters
	ValidateParameters(currentNode node.Node) error
}

ParameterValidator provides a function to validate the node parameters

type Plugin

type Plugin interface {
	// Returns the name of the plugin
	Name() string
	// Return plugin meta information such as: What's supported, possible parameters
	Meta() MetaInfo

	ParameterValidator
	IdentityCreator
	Configurator
	LifecycleHandler
	Upgrader
	Tester
}

Plugin describes and provides the functionality for a plugin

type SimpleParameterValidator

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

SimpleParameterValidator is a simple validator

It checks if all parameters exist and if mandatory parameters have a value

func NewSimpleParameterValidator

func NewSimpleParameterValidator(pluginParameters []Parameter) SimpleParameterValidator

NewSimpleParameterValidator creates an instance of SimpleParameterValidator

func (SimpleParameterValidator) ValidateParameters

func (m SimpleParameterValidator) ValidateParameters(currentNode node.Node) error

ValidateParameters checks if mandatory parameters are passed in

type Tester

type Tester interface {
	// Function to test a node
	Test(currentNode node.Node) (bool, error)
}

Tester is the interface that wraps the Test method

type Upgrader

type Upgrader interface {
	// Function to upgrade a node with a new plugin version
	Upgrade(currentNode node.Node) error
}

Upgrader is the interface that wraps the Upgrade method

Jump to

Keyboard shortcuts

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