api

package
v0.0.0-...-88aa921 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2015 License: Apache-2.0 Imports: 73 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogstashDays = func() ([]string, error) {
	response, e := elastigo.DoCommand("GET", "/_aliases", nil)
	if e != nil {
		return []string{}, fmt.Errorf("couldn't fetch list of indices: %s", e)
	}
	var aliasMap map[string]interface{}
	if e = json.Unmarshal(response, &aliasMap); e != nil {
		return []string{}, fmt.Errorf("couldn't parse response (%s): %s", response, e)
	}
	result := make([]string, 0, len(aliasMap))
	for index := range aliasMap {
		if trimmed := strings.TrimPrefix(index, "logstash-"); trimmed != index {
			if trimmed, e = NormalizeYYYYMMDD(trimmed); e != nil {
				trimmed = ""
			}
			result = append(result, trimmed)
		}
	}
	sort.Sort(sort.Reverse(sort.StringSlice(result)))
	return result, nil
}

Returns a list of all the dates with a logstash-YYYY.MM.DD index available in ElasticSearch. The strings are in YYYY.MM.DD format, and in reverse chronological order.

Functions

func GetAgentIP

func GetAgentIP() string

GetAgentIP returns the agent ip address

func GetDockerDNS

func GetDockerDNS() []string

GetDockerDNS returns the docker dns address

func GetESStartupTimeout

func GetESStartupTimeout() int

GetESStartupTimeout returns the Elastic Search Startup Timeout

func GetGateway

func GetGateway(defaultRPCPort int) string

GetGateway returns the default gateway

func GetVarPath

func GetVarPath() string

GetVarPath returns the serviced varpath

func LoadOptions

func LoadOptions(ops Options)

LoadOptions overwrites the existing server options

func NormalizeYYYYMMDD

func NormalizeYYYYMMDD(s string) (string, error)

NormalizeYYYYMMDD matches optional non-digits, 4 digits, optional non-digits, 2 digits, optional non-digits, 2 digits, optional non-digits Returns those 8 digits formatted as "dddd.dd.dd", or error if unparseable.

Types

type API

type API interface {

	// Server
	StartServer() error
	StartProxy(ControllerOptions) error

	// Hosts
	GetHosts() ([]host.Host, error)
	GetHost(string) (*host.Host, error)
	AddHost(HostConfig) (*host.Host, error)
	RemoveHost(string) error

	// Pools
	GetResourcePools() ([]pool.ResourcePool, error)
	GetResourcePool(string) (*pool.ResourcePool, error)
	AddResourcePool(PoolConfig) (*pool.ResourcePool, error)
	RemoveResourcePool(string) error
	GetPoolIPs(string) (*facade.PoolIPs, error)
	AddVirtualIP(pool.VirtualIP) error
	RemoveVirtualIP(pool.VirtualIP) error

	// Services
	GetServices() ([]service.Service, error)
	GetServiceStates(string) ([]servicestate.ServiceState, error)
	GetServiceStatus(string) (map[string]dao.ServiceStatus, error)
	GetService(string) (*service.Service, error)
	GetServicesByName(string) ([]service.Service, error)
	AddService(ServiceConfig) (*service.Service, error)
	RemoveService(string) error
	UpdateService(io.Reader) (*service.Service, error)
	StartService(SchedulerConfig) (int, error)
	RestartService(SchedulerConfig) (int, error)
	StopService(SchedulerConfig) (int, error)
	AssignIP(IPConfig) error

	// RunningServices (ServiceStates)
	GetRunningServices() ([]dao.RunningService, error)
	Attach(AttachConfig) error
	Action(AttachConfig) error

	// Shell
	StartShell(ShellConfig) error
	RunShell(ShellConfig) error

	// Snapshots
	GetSnapshots() ([]dao.SnapshotInfo, error)
	GetSnapshotsByServiceID(string) ([]dao.SnapshotInfo, error)
	AddSnapshot(string, string) (string, error)
	RemoveSnapshot(string) error
	Commit(string) (string, error)
	Rollback(string, bool) error

	// Templates
	GetServiceTemplates() ([]template.ServiceTemplate, error)
	GetServiceTemplate(string) (*template.ServiceTemplate, error)
	AddServiceTemplate(io.Reader) (*template.ServiceTemplate, error)
	RemoveServiceTemplate(string) error
	CompileServiceTemplate(CompileTemplateConfig) (*template.ServiceTemplate, error)
	DeployServiceTemplate(DeployTemplateConfig) ([]service.Service, error)

	// Backup & Restore
	Backup(string) (string, error)
	Restore(string) error

	// Docker
	ResetRegistry() error
	Squash(imageName, downToLayer, newName, tempDir string) (string, error)
	RegistrySync() error

	// Logs
	ExportLogs(config ExportLogsConfig) error

	// Metric
	PostMetric(metricName string, metricValue string) (string, error)

	ScriptRun(fileName string, config *script.Config, stopChan chan struct{}) error
	ScriptParse(fileName string, config *script.Config) error
}

API is the intermediary between the command-line interface and the dao layer

func New

func New() API

New creates a new API type

type AttachConfig

type AttachConfig struct {
	Running *dao.RunningService
	Command string
	Args    []string
}

AttachConfig is the deserialized object from the command-line

type CompileTemplateConfig

type CompileTemplateConfig struct {
	Dir string
	Map ImageMap
}

CompileTemplateConfig is the configuration object to conpile a template directory

type ControllerOptions

type ControllerOptions struct {
	ServiceID               string   // The uuid of the service to launch
	InstanceID              string   // The service state instance id
	Command                 []string // The command to launch
	MuxPort                 int      // the TCP port for the remote mux
	Mux                     bool     // True if a remote mux is used
	TLS                     bool     // True if TLS should be used on the mux
	KeyPEMFile              string   // path to the KeyPEMfile
	CertPEMFile             string   // path to the CertPEMfile
	ServicedEndpoint        string
	Autorestart             bool
	MetricForwarderPort     string // port to which container processes send performance data to
	Logstash                bool
	LogstashBinary          string // path to the logstash-forwarder binary
	LogstashConfig          string // path to the logstash-forwarder config file
	LogstashIdleFlushTime   string // how often should log stash flush its logs
	LogstashSettleTime      string // how long to wait for log stash to flush its logs before exiting
	VirtualAddressSubnet    string // The subnet of virtual addresses, 10.3
	MetricForwardingEnabled bool   // Enable metric forwarding from the container
}

ControllerOptions are options to be run when starting a new proxy server

type DeployTemplateConfig

type DeployTemplateConfig struct {
	ID              string
	PoolID          string
	DeploymentID    string
	ManualAssignIPs bool
}

DeployTemplateConfig is the configuration object to deploy a template

type ExportLogsConfig

type ExportLogsConfig struct {
	ServiceIDs []string
	FromDate   string
	ToDate     string
	Outfile    string
}

ExportLogsConfig is the deserialized object from the command-line

type HostConfig

type HostConfig struct {
	Address *URL
	PoolID  string
	IPs     []string
}

HostConfig is the deserialized object from the command-line

type IPConfig

type IPConfig struct {
	ServiceID string
	IPAddress string
}

IPConfig is the deserialized object from the command-line

type ImageMap

type ImageMap map[string]string

ImageMap parses docker image data

func (*ImageMap) Set

func (m *ImageMap) Set(value string) error

Set converts a docker image mapping into an ImageMap

func (*ImageMap) String

func (m *ImageMap) String() string

type Options

type Options struct {
	Endpoint             string // the endpoint address to make RPC requests to
	UIPort               string
	Listen               string
	OutboundIP           string // outbound ip to listen on
	Master               bool
	DockerDNS            []string
	Agent                bool
	MuxPort              int
	TLS                  bool
	KeyPEMFile           string
	CertPEMFile          string
	VarPath              string
	ResourcePath         string
	Zookeepers           []string
	RemoteZookeepers     []string
	ReportStats          bool
	HostStats            string
	StatsPeriod          int
	MCUsername           string
	MCPasswd             string
	Mount                []string
	ResourcePeriod       int
	FSType               string
	ESStartupTimeout     int
	HostAliases          []string
	Verbosity            int
	StaticIPs            []string
	DockerRegistry       string
	CPUProfile           string // write cpu profile to file
	MaxContainerAge      int    // max container age in seconds
	MaxDFSTimeout        int    // max timeout for snapshot
	VirtualAddressSubnet string
	MasterPoolID         string
	LogstashES           string //logstatsh elasticsearch host:port
	LogstashMaxDays      int    // Days to keep logstash indices
	LogstashMaxSize      int    // Max size of logstash data
	DebugPort            int    // Port to listen for profile clients
	AdminGroup           string // user group that can log in to control center
	MaxRPCClients        int    // the max number of rpc clients to an endpoint
	RPCDialTimeout       int
	SnapshotTTL          int // hours to keep snapshots around, zero for infinity
}

Options are the server options

type PoolConfig

type PoolConfig struct {
	PoolID      string
	Realm       string
	CoreLimit   int
	MemoryLimit uint64
}

PoolConfig is the deserialized data from the command-line

type PortMap

PortMap parses remote and local port data from the command line

func (*PortMap) Set

func (m *PortMap) Set(value string) error

Set converts a port mapping string from the command line to a PortMap object

func (*PortMap) String

func (m *PortMap) String() string

type RunningService

type RunningService struct {
	Service *service.Service
	State   *servicestate.ServiceState
}

RunningService contains the service for a state

type SchedulerConfig

type SchedulerConfig struct {
	ServiceID  string
	AutoLaunch bool
}

type ServiceConfig

type ServiceConfig struct {
	Name            string
	ParentServiceID string
	ImageID         string
	Command         string
	LocalPorts      *PortMap
	RemotePorts     *PortMap
}

ServiceConfig is the deserialized object from the command-line

type ServiceMap

type ServiceMap map[string]service.Service

ServiceMap maps services by its service id

func NewServiceMap

func NewServiceMap(services []service.Service) ServiceMap

NewServiceMap creates a new service map from a slice of services

func (ServiceMap) Add

func (m ServiceMap) Add(service service.Service) error

Add appends a service to the service map

func (ServiceMap) Get

func (m ServiceMap) Get(serviceID string) service.Service

Get gets a service from the service map identified by its service id

func (ServiceMap) Remove

func (m ServiceMap) Remove(serviceID string) error

Remove removes a service from the service map

func (ServiceMap) Tree

func (m ServiceMap) Tree() map[string][]string

Tree returns a map of parent services and its list of children

func (ServiceMap) Update

func (m ServiceMap) Update(service service.Service)

Update updates an existing service within the ServiceMap. If the service not exist, it gets created.

type ServiceStateController

type ServiceStateController func(SchedulerConfig) (int, error)

Type of method that controls the state of a service

type ShellConfig

type ShellConfig struct {
	ServiceID        string
	Command          string
	Args             []string
	Username         string
	SaveAs           string
	IsTTY            bool
	Mounts           []string
	ServicedEndpoint string
	LogToStderr      bool
	LogStash         struct {
		Enable        bool
		SettleTime    string
		IdleFlushTime string
	}
}

ShellConfig is the deserialized object from the command-line

type URL

type URL struct {
	Host string
	Port int
}

URL parses and handles URL typed options

func (*URL) Set

func (u *URL) Set(value string) error

Set converts a URL string to a URL object

func (*URL) String

func (u *URL) String() string

Jump to

Keyboard shortcuts

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