func destroyGroup(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } v, e := client(cmd).DestroyGroup(args[0]) cli.Output(templateFor(T_DEPLOYMENT_ID, v), e) }
func deployAppOrGroup(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } filename := args[0] wait, _ := cmd.Flags().GetBool(WAIT_FLAG) force, _ := cmd.Flags().GetBool(FORCE_FLAG) paramsFile, _ := cmd.Flags().GetString(ENV_FILE_FLAG) params, _ := cmd.Flags().GetStringSlice(PARAMS_FLAG) ignore, _ := cmd.Flags().GetBool(IGNORE_MISSING) stop_deploy, _ := cmd.Flags().GetBool(STOP_DEPLOYS_FLAG) tempctx, _ := cmd.Flags().GetString(TEMPLATE_CTX_FLAG) dryrun, _ := cmd.Flags().GetBool(DRYRUN_FLAG) options := &marathon.CreateOptions{Wait: wait, Force: force, ErrorOnMissingParams: !ignore, StopDeploy: stop_deploy, DryRun: dryrun} descriptor := parseDescriptor(tempctx, filename) et, err := encoding.NewEncoderFromFileExt(filename) if err != nil { exitWithError(err) } ag := &marathon.AppOrGroup{} if err := et.UnMarshalStr(descriptor, ag); err != nil { exitWithError(err) } if paramsFile != "" { envParams, _ := parseParamsFile(paramsFile) options.EnvParams = envParams } else { options.EnvParams = make(map[string]string) } if params != nil { for _, p := range params { if strings.Contains(p, "=") { v := strings.Split(p, "=") options.EnvParams[v[0]] = v[1] } } } 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) } }
func appKillTask(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } scale, _ := cmd.Flags().GetBool(SCALE_FLAG) v, e := client(cmd).KillAppTask(args[0], scale) cli.Output(templateFor(T_TASK, v), e) }
func destroyApp(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { os.Exit(1) } v, e := client(cmd).DestroyApplication(args[0]) cli.Output(templateFor(T_DEPLOYMENT_ID, v), e) waitForDeploymentIfFlagged(cmd, v.DeploymentID) }
func getGroup(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } v, e := client(cmd).GetGroup(args[0]) arr := flattenGroup(v, []*marathon.Group{}) cli.Output(templateFor(T_GROUPS, arr), e) }
func createGroup(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } wait, _ := cmd.Flags().GetBool(WAIT_FLAG) force, _ := cmd.Flags().GetBool(FORCE_FLAG) params, _ := cmd.Flags().GetStringSlice(PARAMS_FLAG) ignore, _ := cmd.Flags().GetBool(IGNORE_MISSING) stop_deploy, _ := cmd.Flags().GetBool(STOP_DEPLOYS_FLAG) dryrun, _ := cmd.Flags().GetBool(DRYRUN_FLAG) tempctx, _ := cmd.Flags().GetString(TEMPLATE_CTX_FLAG) options := &marathon.CreateOptions{Wait: wait, Force: force, ErrorOnMissingParams: !ignore, StopDeploy: stop_deploy, DryRun: dryrun} if params != nil { envmap := make(map[string]string) for _, p := range params { if strings.Contains(p, "=") { v := strings.Split(p, "=") envmap[v[0]] = v[1] } } options.EnvParams = envmap } var result *marathon.Group = nil var e error if TemplateExists(tempctx) { b := &bytes.Buffer{} r, err := LoadTemplateContext(tempctx) if err != nil { exitWithError(err) } if err := r.Transform(b, args[0]); err != nil { exitWithError(err) } result, e = client(cmd).CreateGroupFromString(args[0], b.String(), options) } else { result, e = client(cmd).CreateGroupFromFile(args[0], options) } if e != nil { if e == marathon.ErrorGroupExists { cli.Output(nil, fmt.Errorf("%s, consider using the --force flag to update when group exists", e.Error())) } else { cli.Output(nil, e) } return } arr := flattenGroup(result, []*marathon.Group{}) cli.Output(templateFor(T_GROUPS, arr), e) }
func convertFile(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 2) { os.Exit(1) } if err := encoding.ConvertFile(args[0], args[1], &marathon.Application{}); err != nil { cli.Output(nil, err) os.Exit(1) } fmt.Printf("Source file %s has been re-written into new format in %s\n\n", args[0], args[1]) }
func restartApp(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { os.Exit(1) } force, _ := cmd.Flags().GetBool(FORCE_FLAG) v, e := client(cmd).RestartApplication(args[0], force) cli.Output(templateFor(T_DEPLOYMENT_ID, v), e) waitForDeploymentIfFlagged(cmd, v.DeploymentID) }
func deployBlueGreenCmd(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } a, err := bgc(cmd).DeployBlueGreenFromFile(args[0]) if err != nil { cli.Output(nil, err) os.Exit(1) } cli.Output(templateFor(T_APPLICATION, a), err) }
func scaleApp(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 2) { os.Exit(1) } instances, err := strconv.Atoi(args[1]) if err != nil { cli.Output(nil, err) os.Exit(1) } v, e := client(cmd).ScaleApplication(args[0], instances) cli.Output(templateFor(T_DEPLOYMENT_ID, v), e) waitForDeploymentIfFlagged(cmd, v.DeploymentID) }
func updateAppMemory(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 2) { os.Exit(1) } wait, _ := cmd.Flags().GetBool(WAIT_FLAG) mem, err := strconv.ParseFloat(args[1], 64) if err != nil { cli.Output(nil, err) os.Exit(1) } update := marathon.NewApplication(args[0]).Memory(mem) v, e := client(cmd).UpdateApplication(update, wait) cli.Output(templateFor(T_APPLICATION, v), e) }
func showLogCmd(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } host := getMesosHost() logType := ml.STDOUT if stderr, _ := cmd.Flags().GetBool(STDERR_FLAG); stderr { logType = ml.STDERR } c, _ := ml.NewMesosClient(host, 5050) appId := getMesosAppIdentifier(cmd, c, args[0]) if follow, _ := cmd.Flags().GetBool(FOLLOW_FLAG); follow { duration, _ := cmd.Flags().GetInt(POLL_FLAG) if duration < 1 { duration = 5 } if err := c.TailLog(appId, logType, duration); err != nil { log.Fatal(err) } return } logs, err := c.GetLog(appId, logType, "") if err != nil { log.Fatal(err) } showBreaks := len(logs) > 1 for _, log := range logs { if showBreaks { fmt.Printf("\n::: [ %s - Logs For: %s ] ::: \n", args[0], log.TaskID) } fmt.Printf("%s\n", log.Log) if showBreaks { fmt.Printf("\n!!! [ %s - End Logs For: %s ] !!! \n", args[0], log.TaskID) } } }
func rollbackAppVersion(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { os.Exit(1) } wait, _ := cmd.Flags().GetBool(WAIT_FLAG) version := "" if len(args) > 1 { version = args[1] } else { versions, e := client(cmd).ListVersions(args[0]) if e == nil && len(versions.Versions) > 1 { version = versions.Versions[1] } } update := marathon.NewApplication(args[0]).RollbackVersion(version) v, e := client(cmd).UpdateApplication(update, wait) cli.Output(templateFor(T_APPLICATION, v), e) }
func appTasks(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } detailed, _ := cmd.Flags().GetBool(DETAIL_FLAG) v, e := client(cmd).GetTasks(args[0]) if detailed && e == nil { fmt.Println("") for _, t := range v { fmt.Printf("::: Task: %s\n\n", t.ID) cli.Output(templateFor(T_TASKS, v), e) } } else { cli.Output(templateFor(T_TASKS, v), e) } }
func createApp(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } wait, _ := cmd.Flags().GetBool(WAIT_FLAG) force, _ := cmd.Flags().GetBool(FORCE_FLAG) paramsFile, _ := cmd.Flags().GetString(ENV_FILE_FLAG) params, _ := cmd.Flags().GetStringSlice(PARAMS_FLAG) ignore, _ := cmd.Flags().GetBool(IGNORE_MISSING) stop_deploy, _ := cmd.Flags().GetBool(STOP_DEPLOYS_FLAG) tempctx, _ := cmd.Flags().GetString(TEMPLATE_CTX_FLAG) dryrun, _ := cmd.Flags().GetBool(DRYRUN_FLAG) options := &marathon.CreateOptions{Wait: wait, Force: force, ErrorOnMissingParams: !ignore, StopDeploy: stop_deploy, DryRun: dryrun} if paramsFile != "" { envParams, _ := parseParamsFile(paramsFile) options.EnvParams = envParams } else { options.EnvParams = make(map[string]string) } if params != nil { for _, p := range params { if strings.Contains(p, "=") { v := strings.Split(p, "=") options.EnvParams[v[0]] = v[1] } } } var result *marathon.Application = nil var e error if TemplateExists(tempctx) { b := &bytes.Buffer{} r, err := LoadTemplateContext(tempctx) if err != nil { exitWithError(err) } if err := r.Transform(b, args[0]); err != nil { exitWithError(err) } result, e = client(cmd).CreateApplicationFromString(args[0], b.String(), options) } else { result, e = client(cmd).CreateApplicationFromFile(args[0], options) } if e != nil && e == marathon.ErrorAppExists { exitWithError(errors.New(fmt.Sprintf("%s, consider using the --force flag to update when an application exists", e.Error()))) } if result == nil { if e != nil { fmt.Printf("[ERROR] %s\n", e.Error()) } os.Exit(1) } cli.Output(templateFor(T_APPLICATION, result), e) }
filter := "" if len(args) > 0 { filter = args[0] } v, e := client(cmd).ListApplicationsWithFilters(filter) cli.Output(templateFor(templateFormat(T_APPLICATIONS, cmd), v), e) }, } var appGetCmd = &cobra.Command{ Use: "get [applicationId]", Short: "Gets an application details by Id", Long: `Retrieves the specified [appliationId] application`, Run: func(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } v, e := client(cmd).GetApplication(args[0]) cli.Output(templateFor(templateFormat(T_APPLICATION, cmd), v), e) }, } var appVersionsCmd = &cobra.Command{ Use: "versions [applicationId]", Short: "Gets the versions that have been deployed with Marathon for [applicationId]", Long: `Retrieves the list of versions for [appliationId] application`, Run: func(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return }