api

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2015 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JobTypeService indicates a long-running processes
	JobTypeService = "service"

	// JobTypeBatch indicates a short-lived process
	JobTypeBatch = "batch"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent encapsulates an API client which talks to Nomad's agent endpoints for a specific node.

func (*Agent) Datacenter

func (a *Agent) Datacenter() (string, error)

Datacenter is used to return the name of the datacenter which the agent is a member of.

func (*Agent) ForceLeave

func (a *Agent) ForceLeave(node string) error

ForceLeave is used to eject an existing node from the cluster.

func (*Agent) Join

func (a *Agent) Join(addrs ...string) (int, error)

Join is used to instruct a server node to join another server via the gossip protocol. Multiple addresses may be specified. We attempt to join all of the hosts in the list. Returns the number of nodes successfully joined and any error. If one or more nodes have a successful result, no error is returned.

func (*Agent) Members

func (a *Agent) Members() ([]*AgentMember, error)

Members is used to query all of the known server members

func (*Agent) NodeName

func (a *Agent) NodeName() (string, error)

NodeName is used to query the Nomad agent for its node name.

func (*Agent) Region

func (a *Agent) Region() (string, error)

Region is used to look up the region the agent is in.

func (*Agent) Self

func (a *Agent) Self() (map[string]map[string]interface{}, error)

Self is used to query the /v1/agent/self endpoint and returns information specific to the running agent.

func (*Agent) Servers

func (a *Agent) Servers() ([]string, error)

Servers is used to query the list of servers on a client node.

func (*Agent) SetServers

func (a *Agent) SetServers(addrs []string) error

SetServers is used to update the list of servers on a client node.

type AgentMember

type AgentMember struct {
	Name        string
	Addr        string
	Port        uint16
	Tags        map[string]string
	Status      string
	ProtocolMin uint8
	ProtocolMax uint8
	ProtocolCur uint8
	DelegateMin uint8
	DelegateMax uint8
	DelegateCur uint8
}

AgentMember represents a cluster member known to the agent

type AllocIndexSort

type AllocIndexSort []*AllocationListStub

AllocIndexSort reverse sorts allocs by CreateIndex.

func (AllocIndexSort) Len

func (a AllocIndexSort) Len() int

func (AllocIndexSort) Less

func (a AllocIndexSort) Less(i, j int) bool

func (AllocIndexSort) Swap

func (a AllocIndexSort) Swap(i, j int)

type Allocation

type Allocation struct {
	ID                 string
	EvalID             string
	Name               string
	NodeID             string
	JobID              string
	Job                *Job
	TaskGroup          string
	Resources          *Resources
	TaskResources      map[string]*Resources
	Metrics            *AllocationMetric
	DesiredStatus      string
	DesiredDescription string
	ClientStatus       string
	ClientDescription  string
	CreateIndex        uint64
	ModifyIndex        uint64
}

Allocation is used for serialization of allocations.

type AllocationListStub

type AllocationListStub struct {
	ID                 string
	EvalID             string
	Name               string
	NodeID             string
	JobID              string
	TaskGroup          string
	DesiredStatus      string
	DesiredDescription string
	ClientStatus       string
	ClientDescription  string
	CreateIndex        uint64
	ModifyIndex        uint64
}

AllocationListStub is used to return a subset of an allocation during list operations.

type AllocationMetric

type AllocationMetric struct {
	NodesEvaluated     int
	NodesFiltered      int
	ClassFiltered      map[string]int
	ConstraintFiltered map[string]int
	NodesExhausted     int
	ClassExhausted     map[string]int
	DimensionExhausted map[string]int
	Scores             map[string]float64
	AllocationTime     time.Duration
	CoalescedFailures  int
}

AllocationMetric is used to deserialize allocation metrics.

type Allocations

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

Allocations is used to query the alloc-related endpoints.

func (*Allocations) Info

func (a *Allocations) Info(allocID string, q *QueryOptions) (*Allocation, *QueryMeta, error)

Info is used to retrieve a single allocation.

func (*Allocations) List

List returns a list of all of the allocations.

type Client

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

Client provides a client to the Nomad API

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient returns a new client

func (*Client) Agent

func (c *Client) Agent() *Agent

Agent returns a new agent which can be used to query the agent-specific endpoints.

func (*Client) Allocations

func (c *Client) Allocations() *Allocations

Allocations returns a handle on the allocs endpoints.

func (*Client) Evaluations

func (c *Client) Evaluations() *Evaluations

Evaluations returns a new handle on the evaluations.

func (*Client) Jobs

func (c *Client) Jobs() *Jobs

Jobs returns a handle on the jobs endpoints.

func (*Client) Nodes

func (c *Client) Nodes() *Nodes

Nodes returns a handle on the node endpoints.

func (*Client) Raw

func (c *Client) Raw() *Raw

Raw returns a handle to query endpoints

func (*Client) Status

func (c *Client) Status() *Status

Status returns a handle on the status endpoints.

type Config

type Config struct {
	// Address is the address of the Nomad agent
	Address string

	// Region to use. If not provided, the default agent region is used.
	Region string

	// HttpClient is the client to use. Default will be
	// used if not provided.
	HttpClient *http.Client

	// WaitTime limits how long a Watch will block. If not provided,
	// the agent default values will be used.
	WaitTime time.Duration
}

Config is used to configure the creation of a client

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration for the client

type Constraint

type Constraint struct {
	Hard    bool
	LTarget string
	RTarget string
	Operand string
	Weight  int
}

Constraint is used to serialize a job placement constraint.

func HardConstraint

func HardConstraint(left, operand, right string) *Constraint

HardConstraint is used to create a new hard constraint.

func SoftConstraint

func SoftConstraint(left, operand, right string, weight int) *Constraint

SoftConstraint is used to create a new soft constraint. It takes an additional weight parameter to allow balancing multiple soft constraints amongst eachother.

type EvalIndexSort

type EvalIndexSort []*Evaluation

EvalIndexSort is a wrapper to sort evaluations by CreateIndex. We reverse the test so that we get the highest index first.

func (EvalIndexSort) Len

func (e EvalIndexSort) Len() int

func (EvalIndexSort) Less

func (e EvalIndexSort) Less(i, j int) bool

func (EvalIndexSort) Swap

func (e EvalIndexSort) Swap(i, j int)

type Evaluation

type Evaluation struct {
	ID                string
	Priority          int
	Type              string
	TriggeredBy       string
	JobID             string
	JobModifyIndex    uint64
	NodeID            string
	NodeModifyIndex   uint64
	Status            string
	StatusDescription string
	Wait              time.Duration
	NextEval          string
	PreviousEval      string
	CreateIndex       uint64
	ModifyIndex       uint64
}

Evaluation is used to serialize an evaluation.

type Evaluations

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

Evaluations is used to query the evaluation endpoints.

func (*Evaluations) Allocations

func (e *Evaluations) Allocations(evalID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error)

Allocations is used to retrieve a set of allocations given an evaluation ID.

func (*Evaluations) Info

func (e *Evaluations) Info(evalID string, q *QueryOptions) (*Evaluation, *QueryMeta, error)

Info is used to query a single evaluation by its ID.

func (*Evaluations) List

func (e *Evaluations) List(q *QueryOptions) ([]*Evaluation, *QueryMeta, error)

List is used to dump all of the evaluations.

type Job

type Job struct {
	Region            string
	ID                string
	Name              string
	Type              string
	Priority          int
	AllAtOnce         bool
	Datacenters       []string
	Constraints       []*Constraint
	TaskGroups        []*TaskGroup
	Meta              map[string]string
	Status            string
	StatusDescription string
	CreateIndex       uint64
	ModifyIndex       uint64
}

Job is used to serialize a job.

func NewBatchJob

func NewBatchJob(id, name, region string, pri int) *Job

NewBatchJob creates and returns a new batch-style job for short-lived processes using the provided name and ID along with the relative job priority.

func NewServiceJob

func NewServiceJob(id, name, region string, pri int) *Job

NewServiceJob creates and returns a new service-style job for long-lived processes using the provided name, ID, and relative job priority.

func (*Job) AddDatacenter

func (j *Job) AddDatacenter(dc string) *Job

AddDatacenter is used to add a datacenter to a job.

func (*Job) AddTaskGroup

func (j *Job) AddTaskGroup(grp *TaskGroup) *Job

AddTaskGroup adds a task group to an existing job.

func (*Job) Constrain

func (j *Job) Constrain(c *Constraint) *Job

Constrain is used to add a constraint to a job.

func (*Job) SetMeta

func (j *Job) SetMeta(key, val string) *Job

SetMeta is used to set arbitrary k/v pairs of metadata on a job.

type JobIDSort

type JobIDSort []*JobListStub

JobIDSort is used to sort jobs by their job ID's.

func (JobIDSort) Len

func (j JobIDSort) Len() int

func (JobIDSort) Less

func (j JobIDSort) Less(a, b int) bool

func (JobIDSort) Swap

func (j JobIDSort) Swap(a, b int)

type JobListStub

type JobListStub struct {
	ID                string
	Name              string
	Type              string
	Priority          int
	Status            string
	StatusDescription string
	CreateIndex       uint64
	ModifyIndex       uint64
}

JobListStub is used to return a subset of information about jobs during list operations.

type Jobs

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

Jobs is used to access the job-specific endpoints.

func (*Jobs) Allocations

func (j *Jobs) Allocations(jobID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error)

Allocations is used to return the allocs for a given job ID.

func (*Jobs) Deregister

func (j *Jobs) Deregister(jobID string, q *WriteOptions) (string, *WriteMeta, error)

Deregister is used to remove an existing job.

func (*Jobs) Evaluations

func (j *Jobs) Evaluations(jobID string, q *QueryOptions) ([]*Evaluation, *QueryMeta, error)

Evaluations is used to query the evaluations associated with the given job ID.

func (*Jobs) ForceEvaluate

func (j *Jobs) ForceEvaluate(jobID string, q *WriteOptions) (string, *WriteMeta, error)

ForceEvaluate is used to force-evaluate an existing job.

func (*Jobs) Info

func (j *Jobs) Info(jobID string, q *QueryOptions) (*Job, *QueryMeta, error)

Info is used to retrieve information about a particular job given its unique ID.

func (*Jobs) List

func (j *Jobs) List(q *QueryOptions) ([]*JobListStub, *QueryMeta, error)

List is used to list all of the existing jobs.

func (*Jobs) Register

func (j *Jobs) Register(job *Job, q *WriteOptions) (string, *WriteMeta, error)

Register is used to register a new job. It returns the ID of the evaluation, along with any errors encountered.

type NetworkResource

type NetworkResource struct {
	Public        bool
	CIDR          string
	ReservedPorts []int
	DynamicPorts  []string
	MBits         int
}

NetworkResource is used to describe required network resources of a given task.

type Node

type Node struct {
	ID                string
	Datacenter        string
	Name              string
	Attributes        map[string]string
	Resources         *Resources
	Reserved          *Resources
	Links             map[string]string
	NodeClass         string
	Drain             bool
	Status            string
	StatusDescription string
	CreateIndex       uint64
	ModifyIndex       uint64
}

Node is used to deserialize a node entry.

type NodeIndexSort

type NodeIndexSort []*NodeListStub

NodeIndexSort reverse sorts nodes by CreateIndex

func (NodeIndexSort) Len

func (n NodeIndexSort) Len() int

func (NodeIndexSort) Less

func (n NodeIndexSort) Less(i, j int) bool

func (NodeIndexSort) Swap

func (n NodeIndexSort) Swap(i, j int)

type NodeListStub

type NodeListStub struct {
	ID                string
	Datacenter        string
	Name              string
	NodeClass         string
	Drain             bool
	Status            string
	StatusDescription string
	CreateIndex       uint64
	ModifyIndex       uint64
}

NodeListStub is a subset of information returned during node list operations.

type Nodes

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

Nodes is used to query node-related API endpoints

func (*Nodes) Allocations

func (n *Nodes) Allocations(nodeID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error)

Allocations is used to return the allocations associated with a node.

func (*Nodes) ForceEvaluate

func (n *Nodes) ForceEvaluate(nodeID string, q *WriteOptions) (string, *WriteMeta, error)

ForceEvaluate is used to force-evaluate an existing node.

func (*Nodes) Info

func (n *Nodes) Info(nodeID string, q *QueryOptions) (*Node, *QueryMeta, error)

Info is used to query a specific node by its ID.

func (*Nodes) List

func (n *Nodes) List(q *QueryOptions) ([]*NodeListStub, *QueryMeta, error)

List is used to list out all of the nodes

func (*Nodes) ToggleDrain

func (n *Nodes) ToggleDrain(nodeID string, drain bool, q *WriteOptions) (*WriteMeta, error)

ToggleDrain is used to toggle drain mode on/off for a given node.

type QueryMeta

type QueryMeta struct {
	// LastIndex. This can be used as a WaitIndex to perform
	// a blocking query
	LastIndex uint64

	// Time of last contact from the leader for the
	// server servicing the request
	LastContact time.Duration

	// Is there a known leader
	KnownLeader bool

	// How long did the request take
	RequestTime time.Duration
}

QueryMeta is used to return meta data about a query

type QueryOptions

type QueryOptions struct {
	// Providing a datacenter overwrites the region provided
	// by the Config
	Region string

	// AllowStale allows any Nomad server (non-leader) to service
	// a read. This allows for lower latency and higher throughput
	AllowStale bool

	// WaitIndex is used to enable a blocking query. Waits
	// until the timeout or the next index is reached
	WaitIndex uint64

	// WaitTime is used to bound the duration of a wait.
	// Defaults to that of the Config, but can be overriden.
	WaitTime time.Duration
}

QueryOptions are used to parameterize a query

type Raw

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

Raw can be used to do raw queries against custom endpoints

func (*Raw) Delete

func (raw *Raw) Delete(endpoint string, out interface{}, q *WriteOptions) (*WriteMeta, error)

Delete is used to do a DELETE request against an endpoint and serialize/deserialized using the standard Nomad conventions.

func (*Raw) Query

func (raw *Raw) Query(endpoint string, out interface{}, q *QueryOptions) (*QueryMeta, error)

Query is used to do a GET request against an endpoint and deserialize the response into an interface using standard Nomad conventions.

func (*Raw) Write

func (raw *Raw) Write(endpoint string, in, out interface{}, q *WriteOptions) (*WriteMeta, error)

Write is used to do a PUT request against an endpoint and serialize/deserialized using the standard Nomad conventions.

type Resources

type Resources struct {
	CPU      int
	MemoryMB int
	DiskMB   int
	IOPS     int
	Networks []*NetworkResource
}

Resources encapsulates the required resources of a given task or task group.

type Status

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

Status is used to query the status-related endpoints.

func (*Status) Leader

func (s *Status) Leader() (string, error)

Leader is used to query for the current cluster leader.

func (*Status) Peers

func (s *Status) Peers() ([]string, error)

Peers is used to query the addresses of the server peers in the cluster.

type Task

type Task struct {
	Name        string
	Driver      string
	Config      map[string]string
	Constraints []*Constraint
	Env         map[string]string
	Resources   *Resources
	Meta        map[string]string
}

Task is a single process in a task group.

func NewTask

func NewTask(name, driver string) *Task

NewTask creates and initializes a new Task.

func (*Task) Constrain

func (t *Task) Constrain(c *Constraint) *Task

Constraint adds a new constraints to a single task.

func (*Task) Require

func (t *Task) Require(r *Resources) *Task

Require is used to add resource requirements to a task.

func (*Task) SetConfig

func (t *Task) SetConfig(key, val string) *Task

Configure is used to configure a single k/v pair on the task.

func (*Task) SetMeta

func (t *Task) SetMeta(key, val string) *Task

SetMeta is used to add metadata k/v pairs to the task.

type TaskGroup

type TaskGroup struct {
	Name        string
	Count       int
	Constraints []*Constraint
	Tasks       []*Task
	Meta        map[string]string
}

TaskGroup is the unit of scheduling.

func NewTaskGroup

func NewTaskGroup(name string, count int) *TaskGroup

NewTaskGroup creates a new TaskGroup.

func (*TaskGroup) AddTask

func (g *TaskGroup) AddTask(t *Task) *TaskGroup

AddTask is used to add a new task to a task group.

func (*TaskGroup) Constrain

func (g *TaskGroup) Constrain(c *Constraint) *TaskGroup

Constrain is used to add a constraint to a task group.

func (*TaskGroup) SetMeta

func (g *TaskGroup) SetMeta(key, val string) *TaskGroup

AddMeta is used to add a meta k/v pair to a task group

type WriteMeta

type WriteMeta struct {
	// LastIndex. This can be used as a WaitIndex to perform
	// a blocking query
	LastIndex uint64

	// How long did the request take
	RequestTime time.Duration
}

WriteMeta is used to return meta data about a write

type WriteOptions

type WriteOptions struct {
	// Providing a datacenter overwrites the region provided
	// by the Config
	Region string
}

WriteOptions are used to parameterize a write

Jump to

Keyboard shortcuts

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