marathon

package module
v0.0.0-...-37fdb32 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2015 License: Apache-2.0 Imports: 14 Imported by: 0

README

Build Status GoDoc

Go-Marathon


Go-marathon is a API library for working with Marathon. It currently supports

  • Application and group deployment
  • Helper filters for pulling the status, configuration and tasks
  • Multiple Endpoint support for HA deployments
  • Marathon Subscriptions and Event callbacks

Note: the library still under active development; requires >= Go 1.3

Code Examples


There is also a examples directory in the source, which show hints and snippets of code of how to use it - which is probably the best place to start.

Creating a client

import (
    "flag"

    marathon "github.com/gambol99/go-marathon"
    "github.com/golang/glog"
    "time"
)

marathon_url := http://10.241.1.71:8080
  config := marathon.NewDefaultConfig()
  config.URL = marathon_url
  config.LogOutput = os.Stdout
  if client, err := marathon.NewClient(config); err != nil {
  	glog.Fatalf("Failed to create a client for marathon, error: %s", err)
  } else {
  	applications, err := client.Applications()
  	...

Note, you can also specify multiple endpoint for Marathon (i.e. you have setup Marathon in HA mode and having multiple running)

marathon := "http://10.241.1.71:8080,10.241.1.72:8080,10.241.1.73:8080"

The first one specified will be used, if that goes offline the member is marked as "unavailable" and a background process will continue to ping the member until it's back online.

Listing the applications

if applications, err := client.Applications(); err != nil
	glog.Errorf("Failed to list applications")
} else {
	glog.Infof("Found %d application running", len(applications.Apps))
	for _, application := range applications.Apps {
		glog.Infof("Application: %s", application)
		details, err := client.Application(application.ID)
		Assert(err)
		if details.Tasks != nil && len(details.Tasks) > 0 {
			for _, task := range details.Tasks {
				glog.Infof("task: %s", task)
			}
			// check the health of the application
			health, err := client.ApplicationOK(details.ID)
			glog.Infof("Application: %s, healthy: %t", details.ID, health)
		}
	}

Creating a new application

glog.Infof("Deploying a new application")
application := marathon.NewDockerApplication()
application.Name("/product/name/frontend")
application.CPU(0.1).Memory(64).Storage(0.0).Count(2)
application.Arg("/usr/sbin/apache2ctl").Arg("-D").Arg("FOREGROUND")
application.AddEnv("NAME", "frontend_http")
application.AddEnv("SERVICE_80_NAME", "test_http")
// add the docker container
application.Container.Docker.Container("quay.io/gambol99/apache-php:latest").Expose(80).Expose(443)
application.CheckHTTP("/health", 10, 5)

if _, err := client.CreateApplication(application, true); err != nil {
	glog.Errorf("Failed to create application: %s, error: %s", application, err)
} else {
	glog.Infof("Created the application: %s", application)
}

Scale Application

Change the number of instance of the application to 4

glog.Infof("Scale to 4 instances")
if err := client.ScaleApplicationInstances(application.ID, 10); err != nil {
	glog.Errorf("Failed to delete the application: %s, error: %s", application, err)
} else {
	client.WaitOnApplication(application.ID, 0)
	glog.Infof("Successfully scaled the application")
}

Subscription & Events

Request to listen to events related to applications - namely status updates, health checks changes and failures

/* step: lets register for events */
update := make(marathon.EventsChannel,5)
if err := client.AddEventsListener(update, marathon.EVENTS_APPLICATIONS); err != nil {
	glog.Fatalf("Failed to register for subscriptions, %s", err)
} else {
	for {
	    event := <-update
	    glog.Infof("EVENT: %s", event )
	}
}

# A full list of the events

const (
    EVENT_API_REQUEST = 1 << iota
    EVENT_STATUS_UPDATE
    EVENT_FRAMEWORK_MESSAGE
    EVENT_SUBSCRIPTION
    EVENT_UNSUBSCRIBED
    EVENT_ADD_HEALTH_CHECK
    EVENT_REMOVE_HEALTH_CHECK
    EVENT_FAILED_HEALTH_CHECK
    EVENT_CHANGED_HEALTH_CHECK
    EVENT_GROUP_CHANGE_SUCCESS
    EVENT_GROUP_CHANGE_FAILED
    EVENT_DEPLOYMENT_SUCCESS
    EVENT_DEPLOYMENT_FAILED
    EVENT_DEPLOYMENT_INFO
    EVENT_DEPLOYMENT_STEP_SUCCESS
    EVENT_DEPLOYMENT_STEP_FAILED
)

const (
    EVENTS_APPLICATIONS  = EVENT_STATUS_UPDATE | EVENT_CHANGED_HEALTH_CHECK | EVENT_FAILED_HEALTH_CHECK
    EVENTS_SUBSCRIPTIONS = EVENT_SUBSCRIPTION | EVENT_UNSUBSCRIBED
)

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request
  • If applicable, update the README.md

Documentation

Index

Constants

View Source
const (
	HTTP_GET    = "GET"
	HTTP_PUT    = "PUT"
	HTTP_DELETE = "DELETE"
	HTTP_POST   = "POST"
)
View Source
const (
	MEMBER_AVAILABLE   = 0
	MEMBER_UNAVAILABLE = 1
)
View Source
const (
	DEFAULT_EVENTS_URL = "/event"

	/* --- api related constants --- */
	MARATHON_API_VERSION      = "v2"
	MARATHON_API_SUBSCRIPTION = MARATHON_API_VERSION + "/eventSubscriptions"
	MARATHON_API_APPS         = MARATHON_API_VERSION + "/apps"
	MARATHON_API_TASKS        = MARATHON_API_VERSION + "/tasks"
	MARATHON_API_DEPLOYMENTS  = MARATHON_API_VERSION + "/deployments"
	MARATHON_API_GROUPS       = MARATHON_API_VERSION + "/groups"
	MARATHON_API_QUEUE        = MARATHON_API_VERSION + "/queue"
	MARATHON_API_INFO         = MARATHON_API_VERSION + "/info"
	MARATHON_API_LEADER       = MARATHON_API_VERSION + "/leader"
	MARATHON_API_PING         = "/ping"
	MARATHON_API_LOGGING      = "/logging"
	MARATHON_API_HELP         = "/help"
	MARATHON_API_METRICS      = "/metrics"
)
View Source
const (
	EVENT_API_REQUEST = 1 << iota
	EVENT_STATUS_UPDATE
	EVENT_FRAMEWORK_MESSAGE
	EVENT_SUBSCRIPTION
	EVENT_UNSUBSCRIBED
	EVENT_ADD_HEALTH_CHECK
	EVENT_REMOVE_HEALTH_CHECK
	EVENT_FAILED_HEALTH_CHECK
	EVENT_CHANGED_HEALTH_CHECK
	EVENT_GROUP_CHANGE_SUCCESS
	EVENT_GROUP_CHANGE_FAILED
	EVENT_DEPLOYMENT_SUCCESS
	EVENT_DEPLOYMENT_FAILED
	EVENT_DEPLOYMENT_INFO
	EVENT_DEPLOYMENT_STEP_SUCCESS
	EVENT_DEPLOYMENT_STEP_FAILED
	EVENT_APP_TERMINATED
)
View Source
const VERSION = "0.0.2"

Variables

View Source
var (
	ErrApplicationExists = errors.New("The application already exists in marathon, you must update")
	/* no container has been specified yet */
	ErrNoApplicationContainer = errors.New("You have not specified a docker container yet")
)
View Source
var (
	/* the url specified was invalid */
	ErrInvalidEndpoint = errors.New("Invalid Marathon endpoint specified")
	/* invalid or error response from marathon */
	ErrInvalidResponse = errors.New("Invalid response from Marathon")
	/* some resource does not exists */
	ErrDoesNotExist = errors.New("The resource does not exist")
	/* all the marathon endpoints are down */
	ErrMarathonDown = errors.New("All the Marathon hosts are presently down")
	/* unable to decode the response */
	ErrInvalidResult = errors.New("Unable to decode the response from Marathon")
	/* invalid argument */
	ErrInvalidArgument = errors.New("The argument passed is invalid")
	/* error return by marathon */
	ErrMarathonError = errors.New("Marathon error")
	/* the operation has timed out */
	ErrTimeoutError = errors.New("The operation has timed out")
)
View Source
var (
	Events map[string]int
)

Functions

This section is empty.

Types

type Application

type Application struct {
	ID                    string              `json:"id",omitempty`
	Cmd                   string              `json:"cmd,omitempty"`
	Args                  []string            `json:"args,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"`
	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"`
	RequirePorts          bool                `json:"requirePorts,omitempty"`
	BackoffSeconds        float64             `json:"backoffSeconds,omitempty"`
	BackoffFactor         float64             `json:"backoffFactor,omitempty"`
	MaxLaunchDelaySeconds float64             `json:"maxLaunchDelaySeconds,omitempty"`
	DeploymentID          []map[string]string `json:"deployments,omitempty"`
	Dependencies          []string            `json:"dependencies,omitempty"`
	TasksRunning          int                 `json:"tasksRunning,omitempty"`
	TasksStaged           int                 `json:"tasksStaged,omitempty"`
	User                  string              `json:"user,omitempty"`
	UpgradeStrategy       *UpgradeStrategy    `json:"upgradeStrategy,omitempty"`
	Uris                  []string            `json:"uris,omitempty"`
	Version               string              `json:"version,omitempty"`
	Labels                map[string]string   `json:"labels,omitempty"`
	AcceptedResourceRoles []string            `json:"acceptedResourceRoles,omitempty"`
	LastTaskFailure       *LastTaskFailure    `json:"lastTaskFailure,omitempty"`
}

func NewDockerApplication

func NewDockerApplication() *Application

func (*Application) AddEnv

func (application *Application) AddEnv(name, value string) *Application

Add an environment variable to the application

name:	the name of the variable
value:	go figure, the value associated to the above

func (*Application) AllTaskRunning

func (application *Application) AllTaskRunning() bool

Check to see if all the application tasks are running, i.e. the instances is equal to the number of running tasks

func (*Application) Arg

func (application *Application) Arg(argument string) *Application

Add an argument to the applications

argument:	the argument you are adding

func (*Application) CPU

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

The amount of CPU shares per instance which is assigned to the application

cpu:	the CPU shared (check Docker docs) per instance

func (*Application) CheckHTTP

func (application *Application) CheckHTTP(uri string, port, interval int) (*Application, error)

Add an HTTP check to an application

port: 		the port the check should be checking
interval:	the interval in seconds the check should be performed

func (*Application) CheckTCP

func (application *Application) CheckTCP(port, interval int) (*Application, error)

Add a TCP check to an application; note the port mapping must already exist, or an error will thrown

port: 		the port the check should, err, check
interval:	the interval in seconds the check should be performed

func (*Application) Count

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

Set the number of instances of the application to run

count:	the number of instances to run

func (*Application) DependsOn

func (application *Application) DependsOn(name string) *Application

Adds a dependency for this application. Note, if you want to wait for an application dependency to actually be UP, i.e. not just deployed, you need a health check on the dependant app.

name:	the application id which this application depends on

func (*Application) Deployments

func (application *Application) Deployments() []*DeploymentID

Retrieve the application deployments ID

func (*Application) HasHealthChecks

func (application *Application) HasHealthChecks() bool

More of a helper method, used to check if an application has healtchecks

func (*Application) Memory

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

The amount of memory the application can consume per instance

memory:	the amount of MB to assign

func (*Application) Name

func (application *Application) Name(id string) *Application

The name of the application i.e. the identifier for this application

func (*Application) Storage

func (application *Application) Storage(disk float64) *Application

The amount of disk space the application is assigned, which for docker application I don't believe is relevant

disk:	the disk space in MB

type ApplicationVersion

type ApplicationVersion struct {
	Version string `json:"version"`
}

type ApplicationVersions

type ApplicationVersions struct {
	Versions []string `json:"versions"`
}

type ApplicationWrap

type ApplicationWrap struct {
	Application Application `json:"app"`
}

type Applications

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

type AtomicSwitch

type AtomicSwitch int64

func (*AtomicSwitch) IsSwitched

func (p *AtomicSwitch) IsSwitched() bool

func (*AtomicSwitch) SwitchOn

func (p *AtomicSwitch) SwitchOn()

func (*AtomicSwitch) SwitchedOff

func (p *AtomicSwitch) SwitchedOff()

type Client

type Client struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Client) AbdicateLeader

func (client *Client) AbdicateLeader() (string, error)

func (*Client) AddEventsListener

func (client *Client) AddEventsListener(channel EventsChannel, filter int) error

Add your self as a listener to events from Marathon

channel:	a EventsChannel used to receive event on

func (*Client) AllTasks

func (client *Client) AllTasks() (*Tasks, error)

Retrieve all the tasks currently running

func (*Client) Application

func (client *Client) Application(name string) (*Application, error)

Retrieve the application configuration from marathon

name: 		the id used to identify the application

func (*Client) ApplicationDeployments

func (client *Client) ApplicationDeployments(name string) ([]*DeploymentID, error)

Retrieve an array of Deployment IDs for an application

name:       the id used to identify the application

func (*Client) ApplicationOK

func (client *Client) ApplicationOK(name string) (bool, error)

Validates that the application, or more appropriately it's tasks have passed all the health checks. If no health checks exist, we simply return true

name: 		the id used to identify the application

func (*Client) ApplicationVersions

func (client *Client) ApplicationVersions(name string) (*ApplicationVersions, error)

A list of versions which has been deployed with marathon for a specific application

name:		the id used to identify the application

func (*Client) Applications

func (client *Client) Applications(v url.Values) (*Applications, error)

Retrieve an array of all the applications which are running in marathon

func (*Client) CreateApplication

func (client *Client) CreateApplication(application *Application, wait_on_running bool) (*Application, error)

Creates a new application in Marathon

application: 		the structure holding the application configuration
wait_on_running:	waits on the application deploying, i.e. the instances arre all running (note health checks are excluded)

func (*Client) CreateGroup

func (client *Client) CreateGroup(group *Group, wait_on_running bool) error

Create a new group in marathon

group:	a pointer the Group structure defining the group

func (*Client) DeleteApplication

func (client *Client) DeleteApplication(name string) (*DeploymentID, error)

Deletes an application from marathon

name: 		the id used to identify the application

func (*Client) DeleteDeployment

func (client *Client) DeleteDeployment(id string, force bool) (*DeploymentID, error)

Delete a current deployment from marathon

id:		the deployment id you wish to delete
force:	whether or not to force the deletion

func (*Client) DeleteGroup

func (client *Client) DeleteGroup(name string) (*DeploymentID, error)

Delete a group from marathon

name:	the identifier for the group

func (*Client) Deployments

func (client *Client) Deployments() ([]*Deployment, error)

Retrieve a list of current deployments

func (*Client) GetEvent

func (client *Client) GetEvent(name string) (*Event, error)

func (*Client) GetMarathonURL

func (client *Client) GetMarathonURL() string

func (*Client) Group

func (client *Client) Group(name string) (*Group, error)

Retrieve the configuration of a specific group from marathon

name:	the identifier for the group

func (*Client) Groups

func (client *Client) Groups() (*Groups, error)

Retrieve a list of all the groups from marathon

func (*Client) HandleMarathonEvent

func (client *Client) HandleMarathonEvent(writer http.ResponseWriter, request *http.Request)

func (*Client) HasApplication

func (client *Client) HasApplication(name string) (bool, error)

Checks to see if the application exists in marathon

name: 		the id used to identify the application

func (*Client) HasApplicationVersion

func (client *Client) HasApplicationVersion(name, version string) (bool, error)

Checks to see if the application version exists in Marathon

name: 		the id used to identify the application
version: 	the version (normally a timestamp) your looking for

func (*Client) HasDeployment

func (client *Client) HasDeployment(id string) (bool, error)

Check to see if a deployment exists

id:		the deployment id you are looking for

func (*Client) HasGroup

func (client *Client) HasGroup(name string) (bool, error)

Check if the group exists in marathon

name:	the identifier for the group

func (*Client) HasSubscription

func (client *Client) HasSubscription(callback string) (bool, error)

Check to see a subscription already exists with Marathon

callback:	the url of the callback

func (*Client) Info

func (client *Client) Info() (*Info, error)

func (*Client) KillApplicationTasks

func (client *Client) KillApplicationTasks(id, hostname string, scale bool) (*Tasks, error)

Kill all tasks relating to an application

		application_id:		the id for the application
     host:				kill only those tasks on a specific host (optional)
		scale:              Scale the app down (i.e. decrement its instances setting by the number of tasks killed) after killing the specified tasks

func (*Client) KillTask

func (client *Client) KillTask(taskId string, scale bool) (*Task, error)

Kill the task associated with a given ID

task_id:		the id for the task
scale:		Scale the app down

func (*Client) KillTasks

func (client *Client) KillTasks(tasks []string, scale bool) error

Kill tasks associated with given array of ids

tasks: 	the array of task ids
scale: 	Scale the app down

func (*Client) Leader

func (client *Client) Leader() (string, error)

func (*Client) ListApplications

func (client *Client) ListApplications(v url.Values) ([]string, error)

Retrieve an array of the application names currently running in marathon

func (*Client) ListTasks

func (client *Client) ListTasks() ([]string, error)

Retrieve an array of task ids currently running in marathon

func (*Client) Ping

func (client *Client) Ping() (bool, error)

Pings the current marathon endpoint (note, this is not a ICMP ping, but a rest api call)

func (*Client) RegisterSubscription

func (client *Client) RegisterSubscription() error

Register ourselves with Marathon to receive events from it's callback facility

func (*Client) RemoveEventsListener

func (client *Client) RemoveEventsListener(channel EventsChannel)

Remove the channel from the events listeners

channel:	the channel you are removing

func (*Client) RestartApplication

func (client *Client) RestartApplication(name string, force bool) (*DeploymentID, error)

Performs a rolling restart of marathon application

name: 		the id used to identify the application

func (*Client) ScaleApplicationInstances

func (client *Client) ScaleApplicationInstances(name string, instances int, force bool) (*DeploymentID, error)

Change the number of instance an application is running

		name: 		the id used to identify the application
		instances:	the number of instances you wish to change to
   force: used to force the scale operation in case of blocked deployment

func (*Client) SetApplicationVersion

func (client *Client) SetApplicationVersion(name string, version *ApplicationVersion) (*DeploymentID, error)

Change / Revert the version of the application

name: 		the id used to identify the application
version: 	the version (normally a timestamp) you wish to change to

func (*Client) SubscriptionURL

func (client *Client) SubscriptionURL() string

Retrieve the subscription call back URL used when registering

func (*Client) Subscriptions

func (client *Client) Subscriptions() (*Subscriptions, error)

Retrieve a list of registered subscriptions

func (*Client) TaskEndpoints

func (client *Client) TaskEndpoints(name string, port int, health_check bool) ([]string, error)

name: the identifier for the application port: the container port you are interested in health: whether to check the health or not

func (*Client) Tasks

func (client *Client) Tasks(id string) (*Tasks, error)

Retrieve a list of tasks for an application

application_id:		the id for the application

func (*Client) UnSubscribe

func (client *Client) UnSubscribe() error

Remove ourselves from Marathon's callback facility

func (*Client) UpdateApplication

func (client *Client) UpdateApplication(application *Application, wait_on_running bool) (*Application, error)

Updates a new application in Marathon

application: 		the structure holding the application configuration
wait_on_running:	waits on the application deploying, i.e. the instances arre all running (note health checks are excluded)

func (*Client) UpdateGroup

func (client *Client) UpdateGroup(name string, group *Group) (*DeploymentID, error)

Update the parameters of a groups

		name:	the identifier for the group
     group:  the group structure with the new params

func (*Client) WaitOnApplication

func (client *Client) WaitOnApplication(name string, timeout time.Duration) error

Wait for an application to be deployed

name:		the id of the application
timeout:	a duration of time to wait for an application to deploy

func (*Client) WaitOnDeployment

func (client *Client) WaitOnDeployment(id string, timeout time.Duration) error

Wait of a deployment to finish

 version:    the version of the application
	timeout:	the timeout to wait for the deployment to take, otherwise return an error

func (*Client) WaitOnGroup

func (client *Client) WaitOnGroup(name string, timeout time.Duration) error

Waits for all the applications in a group to be deployed

group:		the identifier for the group
timeout: 	a duration of time to wait before considering it failed (all tasks in all apps running defined as deployed)

type Cluster

type Cluster interface {
	Url() string
	/* retrieve a member from the cluster */
	GetMember() (string, error)
	/* make the last member as down */
	MarkDown()
	/* the size of the cluster */
	Size() int
	/* the members which are available */
	Active() []string
	/* the members which are NOT available */
	NonActive() []string
}

func NewMarathonCluster

func NewMarathonCluster(marathon_url string) (Cluster, error)

type Command

type Command struct {
	Value string `json:"value"`
}

type Config

type Config struct {
	/* the url for marathon */
	URL string
	/* event handler port */
	EventsPort int
	/* the interface we should be listening on for events */
	EventsInterface string
	/* the output for logging */
	LogOutput io.Writer
	/* the timeout for requests */
	RequestTimeout int
	/* the default timeout for deployments */
	DefaultDeploymentTimeout time.Duration
	/* http basic auth */
	HttpBasicAuthUser string
	/* http basic password */
	HttpBasicPassword string
}

func NewDefaultConfig

func NewDefaultConfig() Config

type Container

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

func NewDockerContainer

func NewDockerContainer() *Container

func (*Container) Volume

func (container *Container) Volume(host_path, container_path, mode string) *Container

type Deployment

type Deployment struct {
	ID             string              `json:"id"`
	Version        string              `json:"version"`
	CurrentStep    int                 `json:"currentStep"`
	TotalSteps     int                 `json:"totalSteps"`
	AffectedApps   []string            `json:"affectedApps"`
	Steps          [][]*DeploymentStep `json:"steps"`
	CurrentActions []*DeploymentStep   `json:"currentActions"`
}

type DeploymentID

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

type DeploymentPlan

type DeploymentPlan struct {
	ID       string `json:"id"`
	Version  string `json:"version"`
	Original struct {
		Apps         []*Application `json:"apps"`
		Dependencies []string       `json:"dependencies"`
		Groups       []*Group       `json:"groups"`
		ID           string         `json:"id"`
		Version      string         `json:"version"`
	} `json:"original"`
	Steps  []*DeploymentStep `json:"steps"`
	Target struct {
		Apps         []*Application `json:"apps"`
		Dependencies []string       `json:"dependencies"`
		Groups       []*Group       `json:"groups"`
		ID           string         `json:"id"`
		Version      string         `json:"version"`
	} `json:"target"`
}

type DeploymentStep

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

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"`
}

func (*Docker) Bridged

func (docker *Docker) Bridged() *Docker

func (*Docker) Container

func (docker *Docker) Container(image string) *Docker

func (*Docker) Expose

func (docker *Docker) Expose(port int) *Docker

func (*Docker) ExposePort

func (docker *Docker) ExposePort(container_port, host_port, service_port int, protocol string) *Docker

func (*Docker) ExposeUDP

func (docker *Docker) ExposeUDP(port int) *Docker

func (*Docker) Parameter

func (docker *Docker) Parameter(key string, value string) *Docker

func (*Docker) ServicePortIndex

func (docker *Docker) ServicePortIndex(port int) (int, error)

type Event

type Event struct {
	ID    int
	Name  string
	Event interface{}
}

func (*Event) String

func (event *Event) String() string

type EventAPIRequest

type EventAPIRequest struct {
	EventType     string       `json:"eventType"`
	ClientIp      string       `json:"clientIp"`
	Timestamp     string       `json:"timestamp"`
	Uri           string       `json:"uri"`
	AppDefinition *Application `json:"appDefinition"`
}

type EventAddHealthCheck

type EventAddHealthCheck struct {
	AppId       string `json:"appId"`
	EventType   string `json:"eventType"`
	HealthCheck struct {
		GracePeriodSeconds     float64 `json:"gracePeriodSeconds"`
		IntervalSeconds        float64 `json:"intervalSeconds"`
		MaxConsecutiveFailures float64 `json:"maxConsecutiveFailures"`
		Path                   string  `json:"path"`
		PortIndex              float64 `json:"portIndex"`
		Protocol               string  `json:"protocol"`
		TimeoutSeconds         float64 `json:"timeoutSeconds"`
	} `json:"healthCheck"`
	Timestamp string `json:"timestamp"`
}

type EventAppTerminated

type EventAppTerminated struct {
	EventType string `json:"eventType"`
	Timestamp string `json:"timestamp,omitempty"`
	AppID     string `json:"appId"`
}

type EventDeploymentFailed

type EventDeploymentFailed struct {
	ID        string `json:"id"`
	EventType string `json:"eventType"`
	Timestamp string `json:"timestamp"`
}

type EventDeploymentInfo

type EventDeploymentInfo struct {
	EventType   string          `json:"eventType"`
	CurrentStep *DeploymentStep `json:"currentStep"`
	Timestamp   string          `json:"timestamp"`
	Plan        *DeploymentPlan `json:"plan"`
}

type EventDeploymentStepFailure

type EventDeploymentStepFailure struct {
	EventType   string          `json:"eventType"`
	CurrentStep *DeploymentStep `json:"currentStep"`
	Timestamp   string          `json:"timestamp"`
	Plan        *DeploymentPlan `json:"plan"`
}

type EventDeploymentStepSuccess

type EventDeploymentStepSuccess struct {
	EventType   string          `json:"eventType"`
	CurrentStep *DeploymentStep `json:"currentStep"`
	Timestamp   string          `json:"timestamp"`
	Plan        *DeploymentPlan `json:"plan"`
}

type EventDeploymentSuccess

type EventDeploymentSuccess struct {
	ID        string `json:"id"`
	EventType string `json:"eventType"`
	Timestamp string `json:"timestamp"`
}

type EventFailedHealthCheck

type EventFailedHealthCheck struct {
	AppId       string `json:"appId"`
	EventType   string `json:"eventType"`
	HealthCheck struct {
		GracePeriodSeconds     float64 `json:"gracePeriodSeconds"`
		IntervalSeconds        float64 `json:"intervalSeconds"`
		MaxConsecutiveFailures float64 `json:"maxConsecutiveFailures"`
		Path                   string  `json:"path"`
		PortIndex              float64 `json:"portIndex"`
		Protocol               string  `json:"protocol"`
		TimeoutSeconds         float64 `json:"timeoutSeconds"`
	} `json:"healthCheck"`
	Timestamp string `json:"timestamp"`
}

type EventFrameworkMessage

type EventFrameworkMessage struct {
	EventType  string `json:"eventType"`
	ExecutorId string `json:"executorId"`
	Message    string `json:"message"`
	SlaveId    string `json:"slaveId"`
	Timestamp  string `json:"timestamp"`
}

type EventGroupChangeFailed

type EventGroupChangeFailed struct {
	EventType string `json:"eventType"`
	GroupId   string `json:"groupId"`
	Timestamp string `json:"timestamp"`
	Version   string `json:"version"`
	Reason    string `json:"reason"`
}

type EventGroupChangeSuccess

type EventGroupChangeSuccess struct {
	EventType string `json:"eventType"`
	GroupId   string `json:"groupId"`
	Timestamp string `json:"timestamp"`
	Version   string `json:"version"`
}

type EventHealthCheckChanged

type EventHealthCheckChanged struct {
	EventType string `json:"eventType"`
	Timestamp string `json:"timestamp,omitempty"`
	AppID     string `json:"appId"`
	TaskID    string `json:"taskId"`
	Version   string `json:"version,omitempty"`
	Alive     bool   `json:"alive"`
}

type EventRemoveHealthCheck

type EventRemoveHealthCheck struct {
	AppId       string `json:"appId"`
	EventType   string `json:"eventType"`
	HealthCheck struct {
		GracePeriodSeconds     float64 `json:"gracePeriodSeconds"`
		IntervalSeconds        float64 `json:"intervalSeconds"`
		MaxConsecutiveFailures float64 `json:"maxConsecutiveFailures"`
		Path                   string  `json:"path"`
		PortIndex              float64 `json:"portIndex"`
		Protocol               string  `json:"protocol"`
		TimeoutSeconds         float64 `json:"timeoutSeconds"`
	} `json:"healthCheck"`
	Timestamp string `json:"timestamp"`
}

type EventStatusUpdate

type EventStatusUpdate struct {
	EventType  string `json:"eventType"`
	Timestamp  string `json:"timestamp,omitempty"`
	SlaveID    string `json:"slaveId,omitempty"`
	TaskID     string `json:"taskId"`
	TaskStatus string `json:"taskStatus"`
	AppID      string `json:"appId"`
	Host       string `json:"host"`
	Ports      []int  `json:"ports,omitempty"`
	Version    string `json:"version,omitempty"`
}

type EventSubscription

type EventSubscription struct {
	CallbackUrl string `json:"callbackUrl"`
	ClientIp    string `json:"clientIp"`
	EventType   string `json:"eventType"`
	Timestamp   string `json:"timestamp"`
}

type EventType

type EventType struct {
	EventType string `json:"eventType"`
}

type EventUnsubscription

type EventUnsubscription struct {
	CallbackUrl string `json:"callbackUrl"`
	ClientIp    string `json:"clientIp"`
	EventType   string `json:"eventType"`
	Timestamp   string `json:"timestamp"`
}

type EventsChannel

type EventsChannel chan *Event

type Group

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

func NewApplicationGroup

func NewApplicationGroup(name string) *Group

Create a new Application Group

name:	the name of the group

func (*Group) App

func (group *Group) App(application *Application) *Group

Add a application to the group in question

application:	a pointer to the Application

func (*Group) Name

func (group *Group) Name(name string) *Group

Specify the name of the group

name:	the name of the group

type Groups

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

type HealthCheck

type HealthCheck struct {
	Command                *Command `json:"command,omitempty"`
	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"`
}

func NewDefaultHealthCheck

func NewDefaultHealthCheck() *HealthCheck

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 Info

type Info 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 LastTaskFailure

type LastTaskFailure struct {
	AppId     string `json:"appId,omitempty"`
	Host      string `json:"host,omitempty"`
	Message   string `json:"message,omitempty"`
	State     string `json:"state,omitempty"`
	TaskId    string `json:"taskId,omitempty"`
	Timestamp string `json:"timestamp,omitempty"`
	Version   string `json:"version,omitempty"`
}

type Marathon

type Marathon interface {

	/* check it see if a application exists */
	HasApplication(name string) (bool, error)
	/* get a listing of the application ids */
	ListApplications(url.Values) ([]string, error)
	/* a list of application versions */
	ApplicationVersions(name string) (*ApplicationVersions, error)
	/* check a application version exists */
	HasApplicationVersion(name, version string) (bool, error)
	/* change an application to a different version */
	SetApplicationVersion(name string, version *ApplicationVersion) (*DeploymentID, error)
	/* check if an application is ok */
	ApplicationOK(name string) (bool, error)
	/* create an application in marathon */
	CreateApplication(application *Application, wait_on_running bool) (*Application, error)
	/* delete an application */
	DeleteApplication(name string) (*DeploymentID, error)
	/* update an application in marathon */
	UpdateApplication(application *Application, wait_on_running bool) (*Application, error)
	/* a list of deployments on a application */
	ApplicationDeployments(name string) ([]*DeploymentID, error)
	/* scale a application */
	ScaleApplicationInstances(name string, instances int, force bool) (*DeploymentID, error)
	/* restart an application */
	RestartApplication(name string, force bool) (*DeploymentID, error)
	/* get a list of applications from marathon */
	Applications(url.Values) (*Applications, error)
	/* get a specific application */
	Application(name string) (*Application, error)
	/* wait of application */
	WaitOnApplication(name string, timeout time.Duration) error

	/* get a list of tasks for a specific application */
	Tasks(application string) (*Tasks, error)
	/* get a list of all tasks */
	AllTasks() (*Tasks, error)
	/* get a listing of the task ids */
	ListTasks() ([]string, error)
	/* get the endpoints for a service on a application */
	TaskEndpoints(name string, port int, health_check bool) ([]string, error)
	/* kill all the tasks for any application */
	KillApplicationTasks(application_id, hostname string, scale bool) (*Tasks, error)
	/* kill a single task */
	KillTask(task_id string, scale bool) (*Task, error)
	/* kill the given array of tasks */
	KillTasks(task_ids []string, scale bool) error

	/* list all the groups in the system */
	Groups() (*Groups, error)
	/* retrieve a specific group from marathon */
	Group(name string) (*Group, error)
	/* create a group deployment */
	CreateGroup(group *Group, wait_on_running bool) error
	/* delete a group */
	DeleteGroup(name string) (*DeploymentID, error)
	/* update a groups */
	UpdateGroup(id string, group *Group) (*DeploymentID, error)
	/* check if a group exists */
	HasGroup(name string) (bool, error)
	/* wait for an group to be deployed */
	WaitOnGroup(name string, timeout time.Duration) error

	/* get a list of the deployments */
	Deployments() ([]*Deployment, error)
	/* delete a deployment */
	DeleteDeployment(id string, force bool) (*DeploymentID, error)
	/* check to see if a deployment exists */
	HasDeployment(id string) (bool, error)
	/* wait of a deployment to finish */
	WaitOnDeployment(version string, timeout time.Duration) error

	/* a list of current subscriptions */
	Subscriptions() (*Subscriptions, error)
	/* add a events listener */
	AddEventsListener(channel EventsChannel, filter int) error
	/* remove a events listener */
	RemoveEventsListener(channel EventsChannel)
	/* remove our self from subscriptions */
	UnSubscribe() error

	/* get the marathon url */
	GetMarathonURL() string
	/* ping the marathon */
	Ping() (bool, error)
	/* grab the marathon server info */
	Info() (*Info, error)
	/* retrieve the leader info */
	Leader() (string, error)
	/* cause the current leader to abdicate */
	AbdicateLeader() (string, error)
}

func NewClient

func NewClient(config Config) (Marathon, error)

type MarathonCluster

type MarathonCluster struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*MarathonCluster) Active

func (cluster *MarathonCluster) Active() []string

Retrieve a list of active members

func (*MarathonCluster) ClusterState

func (cluster *MarathonCluster) ClusterState() []string

func (*MarathonCluster) GetMarathonURL

func (cluster *MarathonCluster) GetMarathonURL(member *Member) string

Retrieves the current marathon url

func (*MarathonCluster) GetMember

func (cluster *MarathonCluster) GetMember() (string, error)

Retrieve the current member, i.e. the current endpoint in use

func (*MarathonCluster) MarkDown

func (cluster *MarathonCluster) MarkDown()

Marks the current endpoint as down and waits for it to come back only

func (*MarathonCluster) NonActive

func (cluster *MarathonCluster) NonActive() []string

Retrieve a list of endpoints which are non-active

func (*MarathonCluster) Size

func (cluster *MarathonCluster) Size() int

Retrieve the size of the cluster

func (MarathonCluster) String

func (cluster MarathonCluster) String() string

func (*MarathonCluster) Url

func (cluster *MarathonCluster) Url() string

type Member

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

func (Member) String

func (member Member) String() string

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 Subscriptions

type Subscriptions struct {
	CallbackURLs []string `json:"callbackUrls"`
}

type Task

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

func (*Task) HasHealthCheckResults

func (task *Task) HasHealthCheckResults() bool

Check if the task has any health checks

func (Task) String

func (task Task) String() string

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 Volume

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

Directories

Path Synopsis
examples
tests

Jump to

Keyboard shortcuts

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