Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Feel free to hack.
* Tests like everywhere
* Params building might be much more clean

## NOTE

This repo is no longer being maintained. Users are welcome to fork it, but we make no warranty of its functionality.

## Usage example
================

Expand Down
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ func (c *Client) request(options *RequestOptions) (*Response, error) {
if err != nil {
return nil, err
}


resp := &Response{
Code: code,
}
Expand All @@ -130,3 +132,5 @@ func (c *Client) request(options *RequestOptions) (*Response, error) {
}
return resp, nil
}


99 changes: 99 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package gomarathon

import (
"fmt"
)

/*
* Group requests
*/

// ListGroups is listing all groups
func (c *Client) ListGroups() (*Response, error) {
return c.ListGroupsByCmd("")
}

// ListAppsByCmd list all apps by cmd filter
func (c *Client) ListGroupsByCmd(filter string) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("groups"),
Params: &Parameters{
Cmd: filter,
},
}
r, err := c.request(options)
if err != nil {
return nil, err
}
return r, nil
}

// GetGroup gets a single group
func (c *Client) GetGroup(groupID string) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("groups/%s", groupID),
}
r, err := c.request(options)
if err != nil {
return nil, err
}
if r.Code != 200 {
return nil, fmt.Errorf("request error")
}
return r, nil
}

// CreateGroup Create a new Application
func (c *Client) CreateGroup(group *Group) (*Response, error) {
fmt.Println("Creating Group")

// TODO : VALIDATE DATAS
options := &RequestOptions{
Path: "groups",
Datas: group,
Method: "POST",
}
r, err := c.request(options)
if r != nil {
if r.Code == 201 {
return r, nil
}
}

fmt.Println("Error: ", err)

return nil, err
}

// UpdateGroup update the group
func (c *Client) UpdateGroup(groupID string, group *Group) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("groups/%s", groupID),
Datas: group,
Method: "PUT",
}
r, err := c.request(options)
if r != nil {
if r.Code == 204 {
return r, nil
}
}
return nil, err

}

// 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 (c *Client) DeleteGroup(groupID string) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("groups/%s", groupID),
Method: "DELETE",
}
r, err := c.request(options)
if r != nil {
if r.Code == 204 {
return r, nil
}
}
return nil, err
}
54 changes: 47 additions & 7 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,25 @@ type Parameters struct {

// Response representation of a full marathon 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"`
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"`
}

// Group marathon group see:
// https://mesosphere.github.io/marathon/docs/rest-api.html#groups
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"`
}

// Application marathon application see :
Expand All @@ -45,6 +59,7 @@ type Application struct {
TasksStaged int `json:"tasksStaged,omitempty"`
Uris []string `json:"uris,omitempty"`
Version string `json:"version,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
}

// Container is docker parameters
Expand All @@ -55,8 +70,33 @@ type Application struct {
// docker run -ti -p 4343:4343 mysql --listen 0.0.0.0:4343
// options := [ "-p", "4343", "//", "--listen", "0.0.0.0:4343" ]
type Container struct {
Image string `json:"image,omitempty"`
Options []string `json:"options,omitempty"`
Type string `json:"type"`
Docker *Docker `json:"docker"`
Volumes []*Volume `json:"volumes,omitempty"`
Options []string `json:"options,omitempty"`
}

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

// Volume is used for mounting a host directory as a container volume
type Volume struct {
ContainerPath string `json:"containerPath,omitempty"`
HostPath string `json:"hostPath,omitempty"`
Mode string `json:"mode,omitempty"`
}

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

// HealthCheck is described here:
Expand Down