Skip to content

Commit

Permalink
misc enhancements and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gondor committed Jul 9, 2016
1 parent b90a019 commit 5513ccc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 0.8.9
VERSION = 0.9.0

GO_FMT = gofmt -s -w -l .
GO_XC = goxc -os="linux darwin windows" -tasks-="rmbin"
Expand Down
3 changes: 2 additions & 1 deletion commands/marathon/app_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
SCALE_FLAG = "scale"
FORMAT_FLAG = "format"
TEMPLATE_CTX_FLAG = "tempctx"
DEFAULT_CTX = "template-context.json"
STOP_DEPLOYS_FLAG = "stop-deploys"
)

Expand Down Expand Up @@ -179,7 +180,7 @@ func createApp(cmd *cobra.Command, args []string) {
var result *marathon.Application = nil
var e error

if len(tempctx) > 0 {
if TemplateExists(tempctx) {
b := &bytes.Buffer{}

r, err := LoadTemplateContext(tempctx)
Expand Down
13 changes: 11 additions & 2 deletions commands/marathon/deploy_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io/ioutil"
"os"
"strings"
"time"
)

var deployCmd = &cobra.Command{
Expand Down Expand Up @@ -79,7 +80,7 @@ the other for delegation to the origin (app or group)
func init() {

deployCreateCmd.Flags().BoolP(WAIT_FLAG, "w", false, "Wait for group to become healthy")
deployCreateCmd.Flags().String(TEMPLATE_CTX_FLAG, "", "Provides data per environment in JSON form to do a first pass parse of descriptor as template")
deployCreateCmd.Flags().String(TEMPLATE_CTX_FLAG, DEFAULT_CTX, "Provides data per environment in JSON form to do a first pass parse of descriptor as template")
deployCreateCmd.Flags().BoolP(FORCE_FLAG, "f", false, "Force deployment (updates application if it already exists)")
deployCreateCmd.Flags().Bool(STOP_DEPLOYS_FLAG, false, "Stop an existing deployment for this app (if exists) and use this revision")
deployCreateCmd.Flags().BoolP(IGNORE_MISSING, "i", false, `Ignore missing ${PARAMS} that are declared in app config that could not be resolved
Expand All @@ -90,6 +91,7 @@ func init() {
eg. -p MYVAR=value would replace ${MYVAR} with "value" in the application file.
These take precidence over env vars`)

deployCreateCmd.Flags().DurationP(TIMEOUT_FLAG, "t", time.Duration(0), "Max duration to wait for application health (ex. 90s | 2m). See docs for ordering")
deployDeleteCmd.Flags().BoolP(FORCE_FLAG, "f", false, "If set to true, then the deployment is still canceled but no rollback deployment is created.")
deployCmd.AddCommand(deployCreateCmd, deployListCmd, deployDeleteCmd, deleteIfDeployingCmd)
}
Expand Down Expand Up @@ -137,13 +139,20 @@ func deployAppOrGroup(cmd *cobra.Command, args []string) {
}
}

log.Debug("Composed Descriptor: %s", descriptor)

if ag.IsApplication() {
result, e := client(cmd).CreateApplicationFromString(filename, descriptor, options)
outputDeployment(result, e)
cli.Output(templateFor(T_APPLICATION, result), e)
} else {
result, e := client(cmd).CreateGroupFromString(filename, descriptor, options)
outputDeployment(result, e)

if e != nil {
cli.Output(nil, e)
}

arr := flattenGroup(result, []*marathon.Group{})
cli.Output(templateFor(T_GROUPS, arr), e)
}
Expand All @@ -163,7 +172,7 @@ func outputDeployment(result interface{}, e error) {
}

func parseDescriptor(tempctx, filename string) string {
if len(tempctx) > 0 {
if TemplateExists(tempctx) {
b := &bytes.Buffer{}

r, err := LoadTemplateContext(tempctx)
Expand Down
7 changes: 5 additions & 2 deletions commands/marathon/group_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"
"os"
"strings"
"time"
)

var groupCmd = &cobra.Command{
Expand Down Expand Up @@ -55,10 +56,12 @@ func init() {
// Destroy Flags
groupDestroyCmd.Flags().BoolP(WAIT_FLAG, "w", false, "Wait for destroy to complete")
// Create Flags
groupCreateCmd.Flags().String(TEMPLATE_CTX_FLAG, "", "Provides data per environment in JSON form to do a first pass parse of descriptor as template")
groupCreateCmd.Flags().String(TEMPLATE_CTX_FLAG, DEFAULT_CTX, "Provides data per environment in JSON form to do a first pass parse of descriptor as template")
groupCreateCmd.Flags().BoolP(WAIT_FLAG, "w", false, "Wait for group to become healthy")
groupCreateCmd.Flags().Bool(STOP_DEPLOYS_FLAG, false, "Stop an existing deployment for this group (if exists) and use this revision")
groupCreateCmd.Flags().BoolP(FORCE_FLAG, "f", false, "Force deployment (updates group if it already exists)")
groupCreateCmd.Flags().DurationP(TIMEOUT_FLAG, "t", time.Duration(0), "Max duration to wait for application health (ex. 90s | 2m). See docs for ordering")

groupCreateCmd.Flags().BoolP(IGNORE_MISSING, "i", false, `Ignore missing ${PARAMS} that are declared in app config that could not be resolved
CAUTION: This can be dangerous if some params define versions or other required information.`)
groupCreateCmd.Flags().StringSliceP(PARAMS_FLAG, "p", nil, `Adds a param(s) that can be used for substitution.
Expand Down Expand Up @@ -124,7 +127,7 @@ func createGroup(cmd *cobra.Command, args []string) {
var result *marathon.Group = nil
var e error

if len(tempctx) > 0 {
if TemplateExists(tempctx) {
b := &bytes.Buffer{}

r, err := LoadTemplateContext(tempctx)
Expand Down
10 changes: 10 additions & 0 deletions commands/marathon/templatectx.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ func recovery() {
recover()
}

func TemplateExists(filename string) bool {

if len(filename) > 0 {
if _, err := os.Stat(filename); err == nil {
return true
}
}
return false
}

func LoadTemplateContext(filename string) (*TemplateContext, error) {
ctx, err := os.Open(filename)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions marathon/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ func (c *MarathonClient) ListApplicationsWithFilters(filter string) (*Applicatio

url := c.marathonUrl(API_APPS)
if len(filter) > 0 {
if strings.Contains(filter, "=") == false {
filter = fmt.Sprintf("id=%s", filter)
}
url = fmt.Sprintf("%s?%s", url, filter)
}
resp := c.http.HttpGet(url, apps)
Expand Down

0 comments on commit 5513ccc

Please sign in to comment.