gomarathon

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

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

Go to latest
Published: Aug 23, 2016 License: MIT Imports: 10 Imported by: 1

README

Go client for marathon

GoDoc

Versions:

  • 2014/08/30 Tag V0.1.0: Fixed version compatible with marathon 0.6

Dev :

  • Branch marathon-0.7: Dev version for marathon 0.7

_ This is a BETA_*

This is a small go client to use with Marathon api v2. All endpoints are handled (EventSubscriptions have not yet been tested).

Feel free to hack.

TODO
  • Tests like everywhere
  • Params building might be much more clean

Usage example

================

package main

import (
    "encoding/json"
    "github.com/jbdalido/go-marathon"
    "log"
)

func main() {

    c, err := gomarathon.NewClient("http://example.io:8080", nil)
    if err != nil {
        log.Fatal(err)
    }

    // Update app
    a := &gomarathon.Application{
        ID:  "test_app",
        Mem: 515,
        Container: &gomarathon.Container{
            Docker: &gomarathon.Docker{
                Image: "docker://jbaptiste/envspitter",
                PortMappings: []*gomarathon.PortMapping{
                    {
                        ContainerPort: 80,
                        HostPort:      8080,
                    },
                },
            },
        },
    }
    r, err := c.CreateApp(a)
    if err != nil {
        log.Fatal(err)
    }
    v, _ := json.Marshal(r)
    log.Printf("%s", v)

    // List all apps
    r, err = c.ListApps()
    if err != nil {
        log.Fatal(err)
    }
    v, _ = json.Marshal(r)
    log.Printf("%s", v)

    // List one app
    r, err = c.GetApp("test_app")
    if err != nil {
        log.Fatal(err)
    }
    v, _ = json.Marshal(r)
    log.Printf("%s", v)

    // List Versions
    r, err = c.ListAppVersions("test_app")
    if err != nil {
        log.Fatal(err)
    }
    v, _ = json.Marshal(r)
    log.Printf("%s", v)

    // Update app
    a = &gomarathon.Application{
        Mem:       515,
        Instances: 2,
    }
    r, err = c.UpdateApp("test_app", a)
    if err != nil {
        log.Fatal(err)
    }
    v, _ = json.Marshal(r)
    log.Printf("%s", v)

    // Get all tasks
    r, err = c.ListTasks()
    if err != nil {
        log.Fatal(err)
    }
    v, _ = json.Marshal(r)
    log.Printf("%s", v)

    // Delete app
    r, err = c.DeleteApp("test_app")
    if err != nil {
        log.Fatal(err)
    }
    v, _ = json.Marshal(r)
    log.Printf("%s", v)

}

Authors

==========

Documentation

Overview

Package gomarathon provIDes a client to interact with a marathon api. on http or https

Index

Constants

View Source
const (
	APIVersion = "/v2"
)

Actual version of the marathon api

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application struct {
	ID                    string            `json:"id"`
	Cmd                   string            `json:"cmd,omitempty"`
	Constraints           [][]string        `json:"constraints,omitempty"`
	Container             *Container        `json:"container,omitempty"`
	CPUs                  float32           `json:"cpus,omitempty"`
	Dependencies          []string          `json:"dependencies,omitempty"`
	Deployments           []*Deployment     `json:"deployments,omitempty"`
	Env                   map[string]string `json:"env,omitempty"`
	Executor              string            `json:"executor,omitempty"`
	HealthChecks          []*HealthCheck    `json:"healthChecks,omitempty"`
	Instances             int               `json:"instances,omitemptys"`
	Mem                   float32           `json:"mem,omitempty"`
	Tasks                 []*Task           `json:"tasks,omitempty"`
	Ports                 []int             `json:"ports,omitempty"`
	RequirePorts          bool              `json:"requirePorts,omitempty"`
	BackoffSeconds        int               `json:"backoffSeconds,omitempty"`
	BackoffFactor         float32           `json:"backoffFactor,omitempty"`
	MaxLaunchDelaySeconds float32           `json:"maxLaunchDelaySeconds,omitempty"`
	TasksHealthy          int               `json:"tasksHealthy,omitempty"`
	TasksUnhealthy        int               `json:"tasksUnhealthy,omitempty"`
	TasksRunning          int               `json:"tasksRunning,omitempty"`
	TasksStaged           int               `json:"tasksStaged,omitempty"`
	UpgradeStrategy       *UpgradeStrategy  `json:"upgradeStrategy,omitempty"`
	Uris                  []string          `json:"uris,omitempty"`
	Version               string            `json:"version,omitempty"`
	Labels                map[string]string `json:"labels,omitempty"`
	TaskStats             *TaskStats        `json:"taskStats,omitempty"`
}

Application marathon application see : https://github.com/mesosphere/marathon/blob/master/REST.md#apps

type Client

type Client struct {
	Url        string
	HTTPClient *http.Client
	Auth       *HttpBasicAuth
}

func NewClient

func NewClient(host string, auth *HttpBasicAuth, tlsConfig *tls.Config) (*Client, error)

NewClient return a pointer to the new client

func (*Client) CreateApp

func (c *Client) CreateApp(app *Application) (*Response, error)

CreateApp Create a new Application

func (*Client) DeleteApp

func (c *Client) DeleteApp(appID string, force bool) (*Response, error)

DeleteApp delete this app from the cluster

func (*Client) DeleteCallbackURL

func (c *Client) DeleteCallbackURL(uri string) (*Response, error)

DeleteCallbackURL delete a particular callback url

func (*Client) DeleteDeployment

func (c *Client) DeleteDeployment(deploymentID string) (*Response, error)

func (*Client) GetApp

func (c *Client) GetApp(appID string) (*Response, error)

GetApp gets a single app with production version

func (*Client) GetAppByFilter

func (c *Client) GetAppByFilter(filter string) (*Response, error)

GetAppByFilter gets a list of apps based on a query string, e.g. "label=project_id==1234"

func (*Client) GetAppTasks

func (c *Client) GetAppTasks(appID string) (*Response, error)

GetAppTasks get the tasks across the cluster from the appid

func (*Client) GetAppVersion

func (c *Client) GetAppVersion(appID string, version string) (*Response, error)

GetAppVersion get a single version from a single app

func (*Client) GetEventSubscriptions

func (c *Client) GetEventSubscriptions() (*Response, error)

GetEventSubscriptions gets all registered callback url

func (*Client) KillTask

func (c *Client) KillTask(appID string, taskID string, scale bool) (*Response, error)

KillTask kill a particular taskid

func (*Client) KillTasks

func (c *Client) KillTasks(appID string, host string, scale bool) (*Response, error)

KillTasks will kill the tasks from the host for the appid

func (*Client) ListAppVersions

func (c *Client) ListAppVersions(appID string) (*Response, error)

ListAppVersions list app versions from a define appid

func (*Client) ListApps

func (c *Client) ListApps() (*Response, error)

ListApps is listing all apps

func (*Client) ListAppsByCmd

func (c *Client) ListAppsByCmd(filter string) (*Response, error)

ListAppsByCmd list all apps by cmd filter

func (*Client) ListTasks

func (c *Client) ListTasks() (*Response, error)

ListTasks get all the tasks running on the cluster

func (*Client) RegisterCallbackURL

func (c *Client) RegisterCallbackURL(uri string) (*Response, error)

RegisterCallbackURL register a new callback url

func (*Client) RestartApp

func (c *Client) RestartApp(appID string) (*Response, error)

func (*Client) UpdateApp

func (c *Client) UpdateApp(appID string, app *Application) (*Response, error)

UpdateApp update the app but thoses changes are made for the next running app and does not shut down the production applications

type Container

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

Container is docker parameters

type Deployment

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

Deployment is described here: https://mesosphere.github.io/marathon/docs/rest-api.html#get-/v2/deployments

type DeploymentStep

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

Deployment steps

type Docker

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

Docker options

type DockerParam

type DockerParam struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type EventSubscription

type EventSubscription struct {
	CallbackURL  string   `json:"CallbackUrl"`
	ClientIP     string   `json:"ClientIp"`
	EventType    string   `json:"eventType"`
	CallbackURLs []string `json:"CallbackUrls"`
}

EventSubscription is described here: https://github.com/mesosphere/marathon/blob/master/REST.md#event-subscriptions

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"`
	TimeoutSeconds         int    `json:"timeoutSeconds,omitempty"`
	MaxConsecutiveFailures int    `json:"maxConsecutiveFailures"`
}

HealthCheck is described here: https://github.com/mesosphere/marathon/blob/master/REST.md#healthchecks

type HealthCheckResult

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

type HttpBasicAuth

type HttpBasicAuth struct {
	User string
	Pass string
}

Client is containing the configured http.Client and the host url

type Parameters

type Parameters struct {
	Cmd         string
	Host        string
	Scale       bool
	CallbackURL string
	Embed       string
	Label       string
	Force       bool
}

Parameters to build url query

type PortMapping

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

Container PortMappings

type RemoteError

type RemoteError interface {
	Code() int
	Error() string
}

type RequestOptions

type RequestOptions struct {
	Method string
	Path   string
	Datas  interface{}
	Params *Parameters
}

RequestOptions passed for query api

type Response

type Response struct {
	Code         int
	Apps         []*Application `json:"apps,omitempty"`
	App          *Application   `json:"app,omitempty"`
	Versions     []string       `json:",omitempty"`
	Tasks        []*Task        `json:"tasks,omitempty"`
	DeploymentId string         `json:"deployment_id,omitempty"`
	Version      string         `json:"version,omitempty"`
}

Response representation of a full marathon response

type Task

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

Task is described here: https://github.com/mesosphere/marathon/blob/master/REST.md#tasks

type TaskCounts

type TaskCounts struct {
	Staged    int `json:"staged"`
	Running   int `json:"running"`
	Healthy   int `json:"healthy"`
	Unhealthy int `json:"unhealthy"`
}

type TaskLifetime

type TaskLifetime struct {
	AverageSeconds float32 `json:"averageSeconds"`
	MedianSeconds  float32 `json:"medianSeconds"`
}

type TaskStat

type TaskStat struct {
	Counts   *TaskCounts   `json:"counts"`
	LifeTime *TaskLifetime `json:"lifeTime"`
}

type TaskStatWrapper

type TaskStatWrapper struct {
	Stats *TaskStat `json:"stats"`
}

type TaskStats

type TaskStats struct {
	StartedAfterLastScaling *TaskStatWrapper `json:"startedAfterLastScaling"`
	WithLatestConfig        *TaskStatWrapper `json:"withLatestConfig"`
	// contains filtered or unexported fields
}

type UpdateResp

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

type UpgradeStrategy

type UpgradeStrategy struct {
	MinimumHealthCapacity float32 `json:"minimumHealthCapacity,omitempty"`
}

UpgradeStrategy has a minimumHealthCapacity which defines the minimum number of healty nodes

type Volume

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

Volume is used for mounting a host directory as a container volume

Jump to

Keyboard shortcuts

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