nodeutil

package
v0.0.0-...-3b86d9c Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2019 License: Apache-2.0 Imports: 18 Imported by: 16

README

dcos-go/dcos/nodeutil

An easy way of interact with DC/OS specific services and variables.

Overview

dcos-go/dcos/nodeutil provides a golang interface to DC/OS cluster.

  • DetectIP() executes the detect_ip script and validates the result.
  • Role() returns a node's role in a cluster.
  • IsLeader() returns true if the host is a leading master.
  • MesosID(*context.Context) returns a node's mesos ID. Optionally can accept an instance of Context to control request cancellation from a caller.
  • ClusterID() returns a UUID of a cluster.
  • TaskCanonicalID(context.Context, task) returns a canonical node ID for a given task. This includes the mesos agent, framework, executor and container IDs.

Note: Methods IsLeader() and ClusterID() will only work on master nodes.

Usage


import (
    "crypto/tls"
    "net/http"

    "github.com/dcos/dcos-go/dcos/nodeutil"
)

func main() {
    client := &http.Client{
        Transport: &http.Transport{
            TLSClientConfig: &tls.Config{
                InsecureSkipVerify: true,
            },
        },
    }
    d, err := nodeutil.NewNodeInfo(client)
    if err != nil {
        panic(err)
    }

    ip, err := d.DetectIP()
    if err != nil {
        panic(err)
    }

    r, err := d.Role()
    if err != nil {
        panic(err)
    }

    leader, err := d.IsLeader()
    if err != nil {
        panic(err)
    }

    mesosID, err := d.MesosID(nil)
    if err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrContainerIDNotFound = errors.New("invalid task. Container ID not found")

ErrContainerIDNotFound is returned by ContainerIDs() function if the container id is not set.

View Source
var ErrEmptyParam = errors.New("Error using empty parameter")

ErrEmptyParam is the error returned if option is used with empty parameter.

View Source
var ErrTaskNotFound = errors.New("task not found")

ErrTaskNotFound is return if the canonical ID for a given task not found.

Functions

func HeaderFromContext

func HeaderFromContext(ctx context.Context) (http.Header, bool)

HeaderFromContext returns http.Header from a context if it's found.

func NewContextWithHeaders

func NewContextWithHeaders(ctx context.Context, header http.Header) context.Context

NewContextWithHeaders adds http.Header to the instance of context.

Types

type CanonicalTaskID

type CanonicalTaskID struct {
	ID           string
	AgentID      string
	FrameworkID  string
	ExecutorID   string
	ContainerIDs []string
}

CanonicalTaskID is a unique task id.

type ContainerStatus

type ContainerStatus struct {
	ContainerID NestedValue `json:"container_id"`
}

ContainerStatus is a field in state.json

type ErrNodeInfo

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

ErrNodeInfo is an error structure raised by exported functions with meaningful error message.

func (ErrNodeInfo) Error

func (e ErrNodeInfo) Error() string

type Framework

type Framework struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	PID            string `json:"pid"`
	Role           string `json:"role"`
	Tasks          []Task `json:"tasks"`
	CompletedTasks []Task `json:"completed_tasks"`
}

Framework is a field in state.json

type NestedValue

type NestedValue struct {
	Value  string       `json:"value"`
	Parent *NestedValue `json:"parent"`
}

NestedValue represents a nested container ID. The value is the actual container ID and Parent is a reference to another NestedValue structure.

type NodeInfo

type NodeInfo interface {
	DetectIP() (net.IP, error)
	IsLeader() (bool, error)
	MesosID(context.Context) (string, error)
	ClusterID() (string, error)
	TaskCanonicalID(ctx context.Context, task string, completed bool) (*CanonicalTaskID, error)
}

NodeInfo defines an interface to interact with DC/OS cluster via go methods.

func NewNodeInfo

func NewNodeInfo(client *http.Client, role string, options ...Option) (NodeInfo, error)

NewNodeInfo returns a new instance of NodeInfo implementation.

type Option

type Option func(*dcosInfo) error

Option is a functional option that configures a Reader.

func OptionClusterIDFile

func OptionClusterIDFile(f string) Option

OptionClusterIDFile sets a path to cluster-id file.

func OptionDetectIP

func OptionDetectIP(path string) Option

OptionDetectIP sets the location of detectIP script.

func OptionDetectIPTimeout

func OptionDetectIPTimeout(timeout time.Duration) Option

OptionDetectIPTimeout update timeout for detect_ip command.

func OptionLeaderDNSRecord

func OptionLeaderDNSRecord(r string) Option

OptionLeaderDNSRecord sets a mesos leader dns entry.

func OptionMesosStateURL

func OptionMesosStateURL(stateURL string) Option

OptionMesosStateURL sets a domain name to make a get request to /mesos/state in order to retrieve mesos state.json.

func OptionNoCache

func OptionNoCache() Option

OptionNoCache disables cache results.

type Slave

type Slave struct {
	ID       string `json:"id"`
	Hostname string `json:"hostname"`
	Port     int    `json:"port"`
	Pid      string `json:"pid"`
}

Slave is a field in state.json

type State

type State struct {
	ID                  string      `json:"id"`
	Slaves              []Slave     `json:"slaves"`
	Frameworks          []Framework `json:"frameworks"`
	CompletedFrameworks []Framework `json:"completed_frameworks"`
}

State stands for mesos state.json available via /mesos/master/state.json

type Status

type Status struct {
	ContainerStatus ContainerStatus `json:"container_status"`
}

Status is a field in state.json

type Task

type Task struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	FrameworkID string `json:"framework_id"`
	ExecutorID  string `json:"executor_id"`
	SlaveID     string `json:"slave_id"`
	State       string `json:"state"`
	Role        string `json:"role"`

	Statuses []Status `json:"statuses"`
}

Task is a field in state.json

func (Task) ContainerIDs

func (t Task) ContainerIDs() (containerIDs []string, err error)

ContainerIDs returns a slice of container ids , starting with the current, and then appending the parent container ids.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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