gomarathon

package
v0.0.0-...-b457bc4 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: MIT, Apache-2.0 Imports: 9 Imported by: 0

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/gomarathon"
    "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{
            Image:   "docker://jbaptiste/envspitter",
            Options: []string{"-p", "1314: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 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"`
	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"`
	BackoffFactor float32           `json:"backoffFactor,omitempty"`
	TasksRunning  int               `json:"tasksRunning,omitempty"`
	TasksStaged   int               `json:"tasksStaged,omitempty"`
	Uris          []string          `json:"uris,omitempty"`
	Version       string            `json:"version,omitempty"`
	Dependencies  []string          `json:"dependencies,omitempty"`
}

Application marathon application see : https://mesosphere.github.io/marathon/docs/rest-api.html#apps

type Client

type Client struct {
	Host       *url.URL
	HTTPClient *http.Client
}

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

func NewClient

func NewClient(host string, 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) CreateGroup

func (c *Client) CreateGroup(group *Group) (*Response, error)

CreateGroup Create a new Application

func (*Client) DeleteApp

func (c *Client) DeleteApp(appID string) (*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) DeleteGroup

func (c *Client) DeleteGroup(groupID string) (*Response, error)

DeleteGroup delete this group from the cluster. Returns with version but when completed will respond with an event because this operation can take a long time.

func (*Client) GetApp

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

GetApp gets a single app with production version

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) GetGroup

func (c *Client) GetGroup(groupID string) (*Response, error)

GetGroup gets a single group

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) ListGroups

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

ListGroups is listing all groups

func (*Client) ListGroupsByCmd

func (c *Client) ListGroupsByCmd(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) 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

func (*Client) UpdateGroup

func (c *Client) UpdateGroup(groupID string, group *Group) (*Response, error)

UpdateGroup update the group

type Container

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

Container is docker parameters options are passed to container, if you want your options to be passed at the end of your docker run add // in front of the parameters you want to pass Example: docker run -ti -p 4343:4343 mysql --listen 0.0.0.0:4343 options := [ "-p", "4343", "//", "--listen", "0.0.0.0:4343" ]

type Docker

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

Docker

type EventSubscription

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

EventSubscription are described here : https://mesosphere.github.io/marathon/docs/rest-api.html#event-subscriptions

type Group

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

Group marathon group see: https://mesosphere.github.io/marathon/docs/rest-api.html#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"`
	TimeoutSeconds     int    `json:"timeoutSeconds,omitempty"`
}

HealthCheck is described here: https://mesosphere.github.io/marathon/docs/health-checks.html

type Parameters

type Parameters struct {
	Cmd         string
	Host        string
	Scale       bool
	CallbackURL string
}

Parameters to build url query

type PortMapping

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

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"`
	Dependencies []string       `json:"dependencies,omitempty"`
	Groups       []*Group       `json:"groups,omitempty"`
	ID           string         `json:"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"`
	ID        string `json:"id"`
	Ports     []int  `json:"ports"`
	StagedAt  string `json:"stagedAt"`
	StartedAt string `json:"startedAt"`
	Version   string `json:"version"`
}

Task is described here: https://mesosphere.github.io/marathon/docs/rest-api.html#tasks

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