From b005c4f93790b93b46687561cdc2f7c31cf08640 Mon Sep 17 00:00:00 2001 From: Gary Paige Date: Mon, 12 Jan 2015 12:15:29 -0600 Subject: [PATCH 1/2] added types --- client.go | 4 +++ group.go | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ types.go | 54 ++++++++++++++++++++++++++---- 3 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 group.go diff --git a/client.go b/client.go index d24ff23..426ede7 100644 --- a/client.go +++ b/client.go @@ -120,6 +120,8 @@ func (c *Client) request(options *RequestOptions) (*Response, error) { if err != nil { return nil, err } + + resp := &Response{ Code: code, } @@ -130,3 +132,5 @@ func (c *Client) request(options *RequestOptions) (*Response, error) { } return resp, nil } + + diff --git a/group.go b/group.go new file mode 100644 index 0000000..5011215 --- /dev/null +++ b/group.go @@ -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 +} diff --git a/types.go b/types.go index a0ce680..afcf45e 100644 --- a/types.go +++ b/types.go @@ -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 : @@ -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 @@ -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: From 36af995cab5766f470d2f1234b4b6671af512b87 Mon Sep 17 00:00:00 2001 From: Andre Anokhin Date: Fri, 24 Jan 2020 11:35:39 -0600 Subject: [PATCH 2/2] note for readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9be9f49..d3ce49f 100644 --- a/README.md +++ b/README.md @@ -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 ================