Last active
July 19, 2018 22:47
-
-
Save frrist/01405d6b36aae85108fad80c2c40d3fb to your computer and use it in GitHub Desktop.
interface description of iptb TestbedNode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package testbedi | |
import ( | |
"context" | |
"io" | |
"time" | |
"github.com/ipfs/go-cid" | |
"github.com/multiformats/go-multiaddr" | |
) | |
type NewNodeFunc func(dir string, extras map[string]interface{}) (TestbedNode, error) | |
type GetAttrListFunc func() []string | |
type GetAttrDescFunc func(attr string) (string, error) | |
type TestbedNode interface { | |
Libp2p | |
Config | |
Attributes | |
Metrics | |
Core | |
} | |
type Libp2p interface { | |
// PeerID returns the peer id | |
PeerID() (*cid.Cid, error) | |
// APIAddr returns the multiaddr for the api | |
APIAddr() (multiaddr.Multiaddr, error) | |
// SwarmAddrs returns the swarm addrs for the node | |
SwarmAddrs() ([]multiaddr.Multiaddr, error) | |
} | |
type Config interface { | |
// GetConfig returns the configuration of the node | |
GetConfig() (interface{}, error) | |
// WriteConfig writes the configuration of the node | |
WriteConfig(interface{}) error | |
} | |
// Attributes are ways to shape process execution and additional information that alters the | |
// environment the process executes in | |
type Attributes interface { | |
// GetAttr returns the value of attr | |
GetAttr(attr string) (string, error) | |
// SetAttr sets the attr to val | |
SetAttr(attr string, val string) error | |
// GetAttrList returns a list of attrs that can be retrieved | |
GetAttrList() []string | |
// GetAttrDesc returns the description of attr | |
GetAttrDesc(attr string) (string, error) | |
/* Example: | |
* Network: | |
- Bandwidth | |
- Jitter | |
- Latency | |
- Packet_Loss | |
* CPU | |
- Limit | |
* RAM | |
- Limit | |
*/ | |
} | |
// Metrics are ways to gather information during process execution | |
type Metrics interface { | |
// Events returns reader for events | |
Events() (io.ReadCloser, error) | |
// Logs returns reader for logs | |
Logs() (io.ReadCloser, error) | |
// Heartbeat returns key values pairs of a defined set of metrics | |
Heartbeat() (map[string]interface{}, error) | |
// Metric returns metric value at key | |
Metric(key string) (interface{}, error) | |
/* Examples: | |
* Filesystem: | |
- device_name | |
- swap | |
- mount_point | |
- total | |
- pct_used | |
* CPU | |
- cores | |
- iowait | |
- pct_used | |
* RAM | |
- total | |
- pct_used | |
* Network | |
- bwout | |
- bwin | |
- ping | |
*/ | |
} | |
// TestbedNode specifies the interface to a process controlled by iptb | |
type Core interface { | |
// Allows a node to run an initialization it may require | |
// Ex: Installing additional dependencies / setting up configuration | |
Init(ctx context.Context, agrs ...string) (TBOutput, error) | |
// Starts the node | |
Start(ctx context.Context, args ...string) error | |
// Stops the node | |
Stop(ctx context.Context, wait bool) error | |
// Runs a command in the context of the node | |
RunCmd(ctx context.Context, args ...string) (TBOutput, error) | |
// Connect the node to another | |
Connect(ctx context.Context, tbn TestbedNode, timeout time.Duration) error | |
// Starts a shell in the context of the node | |
Shell(ctx context.Context, nodes []TestbedNode) error | |
// Writes a log line to stdout | |
Infof(format string, args ...interface{}) | |
// Writes a log line to stderr | |
Errorf(format string, args ...interface{}) | |
// StderrReader returns reader of stderr for the node | |
StderrReader() (io.ReadCloser, error) | |
// StdoutReader returns reader of stdout for the node | |
StdoutReader() (io.ReadCloser, error) | |
// Dir returns the iptb directory assigned to the node | |
Dir() string | |
// Type returns the type of node | |
Type() string | |
// Type returns the deployment | |
Deployment() string | |
// String returns a unique identify | |
String() string | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
possible inspiration for attribute types: https://github.com/uber-go/zap/blob/master/zapcore/field.go#L97-L103