Ejemplo n.º 1
0
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)
}
Ejemplo n.º 2
0
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)
	}
}
Ejemplo n.º 3
0
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)
}
Ejemplo n.º 4
0
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)
}
Ejemplo n.º 5
0
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)
}
Ejemplo n.º 6
0
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)
}
Ejemplo n.º 7
0
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])
}
Ejemplo n.º 8
0
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)
}
Ejemplo n.º 9
0
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)
}
Ejemplo n.º 10
0
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)
}
Ejemplo n.º 11
0
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)
}
Ejemplo n.º 12
0
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)
		}
	}
}
Ejemplo n.º 13
0
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)
}
Ejemplo n.º 14
0
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)
	}

}
Ejemplo n.º 15
0
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)
}
Ejemplo n.º 16
0
		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
		}