marathon

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Marathon API

Index

Constants

View Source
const (
	ActionRestart  = "restart"
	ActionVersions = "versions"
	PathTasks      = "tasks"
)
View Source
const (
	DEFAULT_EVENTS_URL = "event"

	/* --- api related constants --- */
	API_VERSION      = "v2"
	API_SUBSCRIPTION = API_VERSION + "/eventSubscriptions"
	API_APPS         = API_VERSION + "/apps"
	API_TASKS        = API_VERSION + "/tasks"
	API_TASKS_DELETE = API_VERSION + "/tasks/delete"
	API_DEPLOYMENTS  = API_VERSION + "/deployments"
	API_GROUPS       = API_VERSION + "/groups"
	API_QUEUE        = API_VERSION + "/queue"
	API_INFO         = API_VERSION + "/info"
	API_LEADER       = API_VERSION + "/leader"
	API_PING         = "ping"
	API_LOGGING      = "logging"
	API_HELP         = "help"
	API_METRICS      = "metrics"

	DefaultTimeout = time.Duration(90) * time.Second
)

Variables

View Source
var (
	ErrorAppExists        = errors.New("The application already exists")
	ErrorGroupExists      = errors.New("The group already exists")
	ErrorInvalidAppId     = errors.New("The application identifier is invalid")
	ErrorInvalidGroupId   = errors.New("The group identifier is invalid")
	ErrorNoAppExists      = errors.New("The application does not exist.  Create an application before updating")
	ErrorGropAppExists    = errors.New("The group does not exist.  Create a group before updating")
	ErrorAppParamsMissing = errors.New("One or more ${PARAMS} that were defined in the app configuration could not be resolved.")
)
View Source
var (
	ErrorTimeout            = errors.New("The operation has timed out")
	ErrorDeploymentNotfound = errors.New("Failed to get deployment in allocated time")
)

Functions

This section is empty.

Types

type AppById

type AppById struct {
	App Application `json:"app"`
}

type AppKillTasksOptions

type AppKillTasksOptions struct {
	Host  string `json:"host"`
	Scale bool   `json:bool`
}

type AppRestartOptions

type AppRestartOptions struct {
	Force bool `json:"force"`
}

type Application

type Application struct {
	ID                    string              `json:"id,omitempty"`
	Cmd                   string              `json:"cmd,omitempty"`
	Args                  []string            `json:"args,omitempty"`
	AcceptedResourceRoles []string            `json:"acceptedResourceRoles,omitempty"`
	Constraints           [][]string          `json:"constraints,omitempty"`
	Container             *Container          `json:"container,omitempty"`
	CPUs                  float64             `json:"cpus,omitempty"`
	Disk                  float64             `json:"disk,omitempty"`
	Env                   map[string]string   `json:"env,omitempty"`
	Labels                map[string]string   `json:"labels,omitempty"`
	Executor              string              `json:"executor,omitempty"`
	HealthChecks          []*HealthCheck      `json:"healthChecks,omitempty"`
	Instances             int                 `json:"instances,omitempty"`
	Mem                   float64             `json:"mem,omitempty"`
	Tasks                 []*Task             `json:"tasks,omitempty"`
	Ports                 []int               `json:"ports,omitempty"`
	ServicePorts          []int               `json:"servicePorts,omitempty"`
	RequirePorts          bool                `json:"requirePorts,omitempty"`
	BackoffFactor         float64             `json:"backoffFactor,omitempty"`
	DeploymentID          []map[string]string `json:"deployments,omitempty"`
	Dependencies          []string            `json:"dependencies,omitempty"`
	TasksRunning          int                 `json:"tasksRunning,omitempty"`
	TasksStaged           int                 `json:"tasksStaged,omitempty"`
	TasksHealthy          int                 `json:"tasksHealthy,omitempty"`
	TasksUnHealthy        int                 `json:"tasksUnHealthy,omitempty"`
	User                  string              `json:"user,omitempty"`
	UpgradeStrategy       *UpgradeStrategy    `json:"upgradeStrategy,omitempty"`
	Uris                  []string            `json:"uris,omitempty"`
	Version               string              `json:"version,omitempty"`
}

func NewApplication

func NewApplication(id string) *Application

func (*Application) CPU

func (app *Application) CPU(cpu float64) *Application

The amount of CPU shares to assign per instance {cpu} - the CPU shares

func (*Application) Count

func (app *Application) Count(count int) *Application

The number of instances that the application should run {count} - number of instances

func (*Application) Memory

func (app *Application) Memory(memory float64) *Application

The amount of memory in MB to assign per instance {memory} - memory in MB

func (*Application) RollbackVersion

func (app *Application) RollbackVersion(version string) *Application

Rolls back an application to a specific version {version} - the version to rollback

type Applications

type Applications struct {
	Apps []Application `json:"apps"`
}

type Container

type Container struct {
	Type    string    `json:"type,omitempty"`
	Docker  *Docker   `json:"docker,omitempty"`
	Volumes []*Volume `json:"volumes,omitempty"`
}

type CreateOptions

type CreateOptions struct {
	// if true will attempt to wait until the new application or group is running
	Wait bool
	// if true and an application/group already exists an update will be performed.
	// if false and an application/group exists an error will be returned
	Force bool
	// If true an error will be returned on params defined in the configuration file that
	// could not resolve to user input and environment variables
	ErrorOnMissingParams bool
	// Additional environment params - looks at this map for token substitution which takes
	// priority over matching environment variables
	EnvParams map[string]string
}

type Deploy

type Deploy struct {
	AffectedApps   []string `json:"affectedApps"`
	DeployID       string   `json:"id"`
	Steps          [][]Step `json:"steps"`
	CurrentActions []Step   `json:"currentActions"`
	Version        string   `json:"version"`
	CurrentStep    int      `json:"currentStep"`
	TotalSteps     int      `json:"totalSteps"`
}

type DeploymentID

type DeploymentID struct {
	DeploymentID string `json:"deploymentId"`
	Version      string `json:"version"`
}

type Deploys

type Deploys []Deploy

type Docker

type Docker struct {
	ForcePullImage bool           `json:"forcePullImage,omitempty"`
	Image          string         `json:"image,omitempty"`
	Network        string         `json:"network,omitempty"`
	Parameters     []*Parameters  `json:"parameters,omitempty"`
	PortMappings   []*PortMapping `json:"portMappings,omitempty"`
	Privileged     bool           `json:"privileged,omitempty"`
}

type Group

type Group struct {
	GroupID      string         `json:"id"`
	Version      string         `json:"version,omitempty"`
	Apps         []*Application `json:"apps,omitempty"`
	Dependencies []string       `json:"dependencies,omitempty"`
	Groups       []*Group       `json:"groups,omitempty"`
}

type Groups

type Groups struct {
	GroupID      string         `json:"id"`
	Version      string         `json:"version"`
	Apps         []*Application `json:"apps"`
	Dependencies []string       `json:"dependencies"`
	Groups       []*Group       `json:"groups"`
}

type HealthCheck

type HealthCheck struct {
	Protocol               string `json:"protocol,omitempty"`
	Path                   string `json:"path,omitempty"`
	GracePeriodSeconds     int    `json:"gracePeriodSeconds,omitempty"`
	IntervalSeconds        int    `json:"intervalSeconds,omitempty"`
	PortIndex              int    `json:"portIndex,omitempty"`
	MaxConsecutiveFailures int    `json:"maxConsecutiveFailures,omitempty"`
	TimeoutSeconds         int    `json:"timeoutSeconds,omitempty"`
}

type HealthCheckResult

type HealthCheckResult struct {
	Alive               bool   `json:"alive"`
	ConsecutiveFailures int    `json:"consecutiveFailures"`
	FirstSuccess        string `json:"firstSuccess"`
	LastFailure         string `json:"lastFailure"`
	LastSuccess         string `json:"lastSuccess"`
	TaskID              string `json:"taskId"`
}

type KillTasksScale added in v0.8.3

type KillTasksScale struct {
	IDs []string `json:"ids"`
}

type LeaderInfo

type LeaderInfo struct {
	Leader string `json:"leader"`
}

type Marathon

type Marathon interface {

	// Creates a new Application from a file and replaces tokenized variables
	// with resolved environment values
	//
	// {filename} - the application file of type [ json | yaml ]
	// {opts}     - create application options
	CreateApplicationFromFile(filename string, opts *CreateOptions) (*Application, error)

	// Creates a new Application
	// {app}   - the application structure containing configuration
	// {wait}  - if true will attempt to wait until the new application is running
	// {force} - if true and a application already exists an update will be performed.
	//         - if false and a application exists an error will be returned
	CreateApplication(app *Application, wait, force bool) (*Application, error)

	// Responsible for parsing an application [ json | yaml ] and susbstituting variables.
	// This method is called as part of the CreateApplicationFromFile method.
	ParseApplicationFromFile(filename string, opts *CreateOptions) (*Application, *CreateOptions, error)

	// Updates an Application
	// {app} - the application structure containing configuration
	// {wait} - if true will attempt to wait until the application updated is running
	UpdateApplication(app *Application, wait bool) (*Application, error)

	// List all applications on a Marathon cluster
	ListApplications() (*Applications, error)

	// Get an Application by Id
	// {id} - application identifier
	GetApplication(id string) (*Application, error)

	// Determines if the application exists
	// {id} - the application identifier
	HasApplication(id string) (bool, error)

	// Removes an Application by Id and all of it's running instances
	// {id} - application identifier
	DestroyApplication(id string) (*DeploymentID, error)

	// Restarts an Application
	// {id} - application identifier
	// {force} - forces a restart if true
	RestartApplication(id string, force bool) (*DeploymentID, error)

	// Scale an Application by Id and Instances
	// {id} - application identifier
	// {instances} - instances to scale to
	ScaleApplication(id string, instances int) (*DeploymentID, error)

	// List application versions that have been deployed to Marathon
	// {id} - the application identifier
	ListVersions(id string) (*Versions, error)

	// Attempts to wait for an application to be running
	// {id} - the application id
	// {timeout} - the max time to wait
	WaitForApplication(id string, timeout time.Duration) error

	// Attempts to wait for an application to be running and healthy (all health checks for all tasks passing)
	// {id} - the application id
	// {timeout} - the max time to wait
	WaitForApplicationHealthy(id string, timeout time.Duration) error

	// Determines whether a deployment for the specified Id exists
	// {id} - deployment identifier
	HasDeployment(id string) (bool, error)

	// List the current deployments
	ListDeployments() ([]*Deploy, error)

	// Deletes a deployment
	// {id} - deployment identifier
	DeleteDeployment(id string) (*DeploymentID, error)

	// Waits for a deployment to finish for max timeout duration
	WaitForDeployment(id string, timeout time.Duration) error

	// Creates a new group from a file and replaces tokenized variables
	// with resolved environment values
	//
	// {filename} - the group file of type [ json | yaml ]
	// {opts}     - create application options
	CreateGroupFromFile(filename string, opts *CreateOptions) (*Group, error)

	// Creates a new Group
	// {group} - the group structure containing configuration
	// {wait}  - if true will attempt to wait until the new group is running
	// {force} - if true and a group already exists an update will be performed.
	//         - if false and a group exists an error will be returned
	CreateGroup(group *Group, wait, force bool) (*Group, error)

	// List all groups
	ListGroups() (*Groups, error)

	// Get a Group by Id
	// {id} - group identifier
	GetGroup(id string) (*Group, error)

	// Removes a Group by Id and all of it's related resources (application instances)
	// {id} - group identifier
	DestroyGroup(id string) (*DeploymentID, error)

	// List all running tasks
	ListTasks() ([]*Task, error)

	// List all tasks for an application
	// {id} - the application identifier
	GetTasks(id string) ([]*Task, error)

	// Kills application tasks for the app identifier
	// {id} - the application identifier
	// {host} - host to kill tasks on or empty (default)
	// {scale} - Scale the app down (i.e. decrement its instances setting by the number of tasks killed), false is default
	KillAppTasks(id string, host string, scale bool) ([]*Task, error)

	// Kill the task with ID taskId that belongs to an application
	// {taskId} - the task id
	// {scale}  - Scale the app down (ie. decrement it's instances setting by the number of tasks killed). Default: false
	KillAppTask(taskId string, scale bool) (*Task, error)

	// Kill the specified task IDs and scale
	// {ids} - one or more task identifiers to kill and scale
	KillTasksAndScale(ids ...string) error

	// List Queue - tasks currently pending
	ListQueue() (*Queue, error)

	// Pings the Marathon host via the /ping endpoint
	Ping() (*MarathonPing, error)

	// Get info about the Marathon Instance
	GetMarathonInfo() (*MarathonInfo, error)

	// Get the current Marathon leader
	GetCurrentLeader() (*LeaderInfo, error)

	// Abdicates the current leader
	AbdicateLeader() (*Message, error)
}

func NewMarathonClient

func NewMarathonClient(host, username, password string) Marathon

func NewMarathonClientWithOpts

func NewMarathonClientWithOpts(host, username, password string, opts *MarathonOptions) Marathon

type MarathonClient

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

func (*MarathonClient) AbdicateLeader

func (c *MarathonClient) AbdicateLeader() (*Message, error)

func (*MarathonClient) CreateApplication

func (c *MarathonClient) CreateApplication(app *Application, wait, force bool) (*Application, error)

func (*MarathonClient) CreateApplicationFromFile

func (c *MarathonClient) CreateApplicationFromFile(filename string, opts *CreateOptions) (*Application, error)

func (*MarathonClient) CreateGroup

func (c *MarathonClient) CreateGroup(group *Group, wait, force bool) (*Group, error)

func (*MarathonClient) CreateGroupFromFile

func (c *MarathonClient) CreateGroupFromFile(filename string, opts *CreateOptions) (*Group, error)

func (*MarathonClient) DeleteDeployment

func (c *MarathonClient) DeleteDeployment(id string) (*DeploymentID, error)

func (*MarathonClient) DestroyApplication

func (c *MarathonClient) DestroyApplication(id string) (*DeploymentID, error)

func (*MarathonClient) DestroyGroup

func (c *MarathonClient) DestroyGroup(id string) (*DeploymentID, error)

func (*MarathonClient) GetApplication

func (c *MarathonClient) GetApplication(id string) (*Application, error)

func (*MarathonClient) GetCurrentLeader

func (c *MarathonClient) GetCurrentLeader() (*LeaderInfo, error)

func (*MarathonClient) GetGroup

func (c *MarathonClient) GetGroup(id string) (*Group, error)

func (*MarathonClient) GetMarathonInfo

func (c *MarathonClient) GetMarathonInfo() (*MarathonInfo, error)

func (*MarathonClient) GetTasks

func (c *MarathonClient) GetTasks(id string) ([]*Task, error)

func (*MarathonClient) HasApplication

func (c *MarathonClient) HasApplication(id string) (bool, error)

func (*MarathonClient) HasDeployment

func (c *MarathonClient) HasDeployment(id string) (bool, error)

func (*MarathonClient) KillAppTask

func (c *MarathonClient) KillAppTask(taskId string, scale bool) (*Task, error)

func (*MarathonClient) KillAppTasks

func (c *MarathonClient) KillAppTasks(id string, host string, scale bool) ([]*Task, error)

func (*MarathonClient) KillTasksAndScale added in v0.8.3

func (c *MarathonClient) KillTasksAndScale(ids ...string) error

func (*MarathonClient) ListApplications

func (c *MarathonClient) ListApplications() (*Applications, error)

func (*MarathonClient) ListDeployments

func (c *MarathonClient) ListDeployments() ([]*Deploy, error)

func (*MarathonClient) ListGroups

func (c *MarathonClient) ListGroups() (*Groups, error)

func (*MarathonClient) ListQueue

func (c *MarathonClient) ListQueue() (*Queue, error)

func (*MarathonClient) ListTasks

func (c *MarathonClient) ListTasks() ([]*Task, error)

func (*MarathonClient) ListVersions

func (c *MarathonClient) ListVersions(id string) (*Versions, error)

func (*MarathonClient) ParseApplicationFromFile added in v0.8.3

func (c *MarathonClient) ParseApplicationFromFile(filename string, opts *CreateOptions) (*Application, *CreateOptions, error)

func (*MarathonClient) Ping

func (c *MarathonClient) Ping() (*MarathonPing, error)

func (*MarathonClient) RestartApplication

func (c *MarathonClient) RestartApplication(id string, force bool) (*DeploymentID, error)

func (*MarathonClient) ScaleApplication

func (c *MarathonClient) ScaleApplication(id string, instances int) (*DeploymentID, error)

func (*MarathonClient) UpdateApplication

func (c *MarathonClient) UpdateApplication(app *Application, wait bool) (*Application, error)

func (*MarathonClient) UpdateGroup

func (c *MarathonClient) UpdateGroup(group *Group, wait bool) (*Group, error)

func (*MarathonClient) WaitForApplication

func (c *MarathonClient) WaitForApplication(id string, timeout time.Duration) error

func (*MarathonClient) WaitForApplicationHealthy

func (c *MarathonClient) WaitForApplicationHealthy(id string, timeout time.Duration) error

func (*MarathonClient) WaitForDeployment

func (c *MarathonClient) WaitForDeployment(id string, timeout time.Duration) error

type MarathonInfo

type MarathonInfo struct {
	EventSubscriber struct {
		HttpEndpoints []string `json:"http_endpoints"`
		Type          string   `json:"type"`
	} `json:"event_subscriber"`
	FrameworkId string `json:"frameworkId"`
	HttpConfig  struct {
		AssetsPath interface{} `json:"assets_path"`
		HttpPort   float64     `json:"http_port"`
		HttpsPort  float64     `json:"https_port"`
	} `json:"http_config"`
	Leader         string `json:"leader"`
	MarathonConfig struct {
		Checkpoint                 bool    `json:"checkpoint"`
		Executor                   string  `json:"executor"`
		FailoverTimeout            float64 `json:"failover_timeout"`
		Ha                         bool    `json:"ha"`
		Hostname                   string  `json:"hostname"`
		LocalPortMax               float64 `json:"local_port_max"`
		LocalPortMin               float64 `json:"local_port_min"`
		Master                     string  `json:"master"`
		MesosRole                  string  `json:"mesos_role"`
		MesosUser                  string  `json:"mesos_user"`
		ReconciliationInitialDelay float64 `json:"reconciliation_initial_delay"`
		ReconciliationInterval     float64 `json:"reconciliation_interval"`
		TaskLaunchTimeout          float64 `json:"task_launch_timeout"`
	} `json:"marathon_config"`
	Name            string `json:"name"`
	Version         string `json:"version"`
	ZookeeperConfig struct {
		Zk              string `json:"zk"`
		ZkFutureTimeout struct {
			Duration float64 `json:"duration"`
		} `json:"zk_future_timeout"`
		ZkHosts   string  `json:"zk_hosts"`
		ZkPath    string  `json:"zk_path"`
		ZkState   string  `json:"zk_state"`
		ZkTimeout float64 `json:"zk_timeout"`
	} `json:"zookeeper_config"`
}

type MarathonOptions

type MarathonOptions struct {
	WaitTimeout      time.Duration
	TLSAllowInsecure bool
}

type MarathonPing

type MarathonPing struct {
	Host    string
	Elapsed time.Duration
}

type Message

type Message struct {
	Message string `json:"message"`
}

type Parameters

type Parameters struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

type PortMapping

type PortMapping struct {
	ContainerPort int    `json:"containerPort,omitempty"`
	HostPort      int    `json:"hostPort"`
	ServicePort   int    `json:"servicePort,omitempty"`
	Protocol      string `json:"protocol"`
}

type Queue

type Queue struct {
	Queue []QueuedTask `json:"queue"`
}

type QueuedTask

type QueuedTask struct {
	App   *Application    `json:"app"`
	Delay map[string]bool `json:"delay"`
}

type Step

type Step struct {
	Action string `json:"action"`
	App    string `json:"app"`
}

type Task

type Task struct {
	AppID             string               `json:"appId"`
	Host              string               `json:"host"`
	ID                string               `json:"id"`
	HealthCheckResult []*HealthCheckResult `json:"healthCheckResults"`
	Ports             []int                `json:"ports"`
	ServicePorts      []int                `json:"servicePorts"`
	StagedAt          string               `json:"stagedAt"`
	StartedAt         string               `json:"startedAt"`
	Version           string               `json:"version"`
}

type Tasks

type Tasks struct {
	Tasks []*Task `json:"tasks"`
}

type UpgradeStrategy

type UpgradeStrategy struct {
	MinimumHealthCapacity float64 `json:"minimumHealthCapacity,omitempty"`
	MaximumOverCapacity   float64 `json:"maximumOverCapacity,omitempty"`
}

type Versions

type Versions struct {
	Versions []string
}

type Volume

type Volume struct {
	ContainerPath string `json:"containerPath,omitempty"`
	HostPath      string `json:"hostPath,omitempty"`
	Mode          string `json:"mode,omitempty"`
}

type Which

type Which struct {
	Leader string `json:"leader"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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