Esempio n. 1
0
func createApp(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, 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)
	options := &marathon.CreateOptions{Wait: wait, Force: force, ErrorOnMissingParams: !ignore}

	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]
			}
		}
	}

	result, e := client(cmd).CreateApplicationFromFile(args[0], options)
	if e != nil && e == marathon.ErrorAppExists {
		cli.Output(nil, errors.New(fmt.Sprintf("%s, consider using the --force flag to update when an application exists", e.Error())))
		return
	}
	cli.Output(Application{result}, e)
}
Esempio n. 2
0
func createGroup(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, 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)
	options := &marathon.CreateOptions{Wait: wait, Force: force, ErrorOnMissingParams: !ignore}

	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
	}

	result, e := client(cmd).CreateGroupFromFile(args[0], options)
	if e != nil && e == marathon.ErrorGroupExists {
		cli.Output(nil, fmt.Errorf("%s, consider using the --force flag to update when group exists", e.Error()))
		return
	}
	cli.Output(AppGroup{result}, e)
}
Esempio n. 3
0
func scaleApp(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 2) {
		return
	}

	instances, err := strconv.Atoi(args[1])
	if err != nil {
		cli.Output(nil, err)
		return
	}
	v, e := client(cmd).ScaleApplication(args[0], instances)
	cli.Output(DeploymentId{v}, e)
	waitForDeploymentIfFlagged(cmd, v.DeploymentID)
}
Esempio n. 4
0
func destroyGroup(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 1) {
		return
	}
	v, e := client(cmd).DestroyGroup(args[0])
	cli.Output(DeploymentId{v}, e)
}
Esempio n. 5
0
func updateAppMemory(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 2) {
		return
	}

	wait, _ := cmd.Flags().GetBool(WAIT_FLAG)
	mem, err := strconv.ParseFloat(args[1], 64)

	if err != nil {
		cli.Output(nil, err)
		return
	}
	update := marathon.NewApplication(args[0]).Memory(mem)
	v, e := client(cmd).UpdateApplication(update, wait)
	cli.Output(Application{v}, e)
}
Esempio n. 6
0
func getGroup(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 1) {
		return
	}

	v, e := client(cmd).GetGroup(args[0])
	cli.Output(AppGroup{v}, e)
}
Esempio n. 7
0
func appKillTask(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 1) {
		return
	}
	scale, _ := cmd.Flags().GetBool(SCALE_FLAG)
	v, e := client(cmd).KillAppTask(args[0], scale)
	cli.Output(Task{v}, e)
}
Esempio n. 8
0
func destroyApp(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 1) {
		return
	}

	v, e := client(cmd).DestroyApplication(args[0])
	cli.Output(DeploymentId{v}, e)
	waitForDeploymentIfFlagged(cmd, v.DeploymentID)
}
Esempio n. 9
0
func convertFile(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 2) {
		return
	}
	if err := encoding.ConvertFile(args[0], args[1], &marathon.Application{}); err != nil {
		cli.Output(nil, err)
		return
	}
	fmt.Printf("Source file %s has been re-written into new format in %s\n\n", args[0], args[1])
}
Esempio n. 10
0
func appTasks(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, 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(&Task{t}, e)
		}
	} else {
		cli.Output(&Tasks{Tasks: v}, e)
	}

}
Esempio n. 11
0
func appKillAllTasks(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 1) {
		return
	}

	host, _ := cmd.Flags().GetString(HOST_FLAG)
	scale, _ := cmd.Flags().GetBool(SCALE_FLAG)

	v, e := client(cmd).KillAppTasks(args[0], host, scale)
	cli.Output(&Tasks{Tasks: v}, e)
}
Esempio n. 12
0
func rollbackAppVersion(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 2) {
		return
	}

	wait, _ := cmd.Flags().GetBool(WAIT_FLAG)

	update := marathon.NewApplication(args[0]).RollbackVersion(args[1])
	v, e := client(cmd).UpdateApplication(update, wait)
	cli.Output(Application{v}, e)
}
Esempio n. 13
0
func restartApp(cmd *cobra.Command, args []string) {
	if cli.EvalPrintUsage(cmd.Usage, args, 1) {
		return
	}

	force, _ := cmd.Flags().GetBool(FORCE_FLAG)

	v, e := client(cmd).RestartApplication(args[0], force)
	cli.Output(DeploymentId{v}, e)
	waitForDeploymentIfFlagged(cmd, v.DeploymentID)
}
Esempio n. 14
0
func execActionWithPreHook(action ComposeAction, preHook ComposePreHook) func(cmd *cobra.Command, args []string) {
	return func(cmd *cobra.Command, args []string) {
		composeFile, _ := cmd.Flags().GetString(COMPOSE_FILE_FLAG)
		projName, _ := cmd.Flags().GetString(PROJECT_NAME_FLAG)

		compose := preHook(composeFile, projName, cmd)
		err := action(compose, cmd, args)

		if err != nil {
			cli.Output(nil, err)
		}
	}
}
Esempio n. 15
0
func listGroups(cmd *cobra.Command, args []string) {
	v, e := client(cmd).ListGroups()
	cli.Output(AppGroups{v}, e)
}
Esempio n. 16
0
)

var deployCmd = &cobra.Command{
	Use:   "deploy",
	Short: "Marathon deployment management",
	Long: `Manage deployments in a marathon cluster (eg. creating, listing, monitoring)

    See deploy's subcommands for available choices`,
}

var deployListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all deployments",
	Run: func(cmd *cobra.Command, args []string) {
		v, e := client(cmd).ListDeployments()
		cli.Output(&Deployments{Deploys: v}, e)
	},
}

var deployDeleteCmd = &cobra.Command{
	Use:   "delete [deploymentId]",
	Short: "Delete a deployment by [deploymentID]",
	Run: func(cmd *cobra.Command, args []string) {
		if cli.EvalPrintUsage(cmd.Usage, args, 1) {
			return
		}
		v, e := client(cmd).DeleteDeployment(args[0])
		cli.Output(&DeploymentId{v}, e)
	},
}
Esempio n. 17
0
	Short: "Updates [applicationId] to have [cpu_shares]",
	Run:   updateAppCPU,
}

var appUpdateMemoryCmd = &cobra.Command{
	Use:   "mem [applicationId] [amount]",
	Short: "Updates [applicationId] to have [amount] of memory in MB",
	Run:   updateAppMemory,
}

var appListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all applications",
	Run: func(cmd *cobra.Command, args []string) {
		v, e := client(cmd).ListApplications()
		cli.Output(Applications{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(cmd.Usage, args, 1) {
			return
		}
		v, e := client(cmd).GetApplication(args[0])
		cli.Output(Application{v}, e)
	},
}
Esempio n. 18
0
)

var taskCmd = &cobra.Command{
	Use:   "task",
	Short: "Marathon task management",
	Long: `Manage tasks in a marathon cluster (eg. creating, listing, monitoring, kill)

    See tasks's subcommands for available choices`,
}

var taskListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all tasks",
	Run: func(cmd *cobra.Command, args []string) {
		v, e := client(cmd).ListTasks()
		cli.Output(&Tasks{Tasks: v}, e)
	},
}

var taskQueueCmd = &cobra.Command{
	Use:   "queue",
	Short: "List all queued tasks",
	Run: func(cmd *cobra.Command, args []string) {
		v, e := client(cmd).ListQueue()
		cli.Output(&QueuedTasks{v}, e)
	},
}

var appTaskGetCmd = &cobra.Command{
	Use:   "get [applicationId]",
	Short: "List tasks for the application [applicationId]",
Esempio n. 19
0
	Short: "Configuration environments define remote Marathon and other supported services by a name. ",
	Long: `Manage configuration environments (eg. default, list, adding and removing of environments)

See env's subcommands for available choices`,
}

var configRemoveCmd = &cobra.Command{
	Use:   "delete [name]",
	Short: "Remove a defined environment by it's [name]",
	Run: func(cmd *cobra.Command, args []string) {
		if cli.EvalPrintUsage(cmd.Usage, args, 1) {
			return
		}
		_, err := configFile.GetEnvironment(args[0])
		if err != nil {
			cli.Output(nil, err)
		} else {
			err := configFile.RemoveEnvironment(args[0], false)
			if err != nil {
				cli.Output(nil, err)
			}
		}
	},
}

var configAddCmd = &cobra.Command{
	Use:   "add",
	Short: "Adds a new environment",
	Run: func(cmd *cobra.Command, args []string) {
		configFile.AddEnvironment()
	},
Esempio n. 20
0
)

var serverCmd = &cobra.Command{
	Use:   "server",
	Short: "Marathon server information",
	Long: `View Marathon server information and current leader

    See server's subcommands for available choices`,
}

var serverInfoCmd = &cobra.Command{
	Use:   "info",
	Short: "Get info about the Marathon Instance",
	Run: func(cmd *cobra.Command, args []string) {
		v, e := client(cmd).GetMarathonInfo()
		cli.Output(MarInfo{v}, e)
	},
}

var serverLeaderCmd = &cobra.Command{
	Use:   "leader",
	Short: "Marathon leader management",
}

var serverLeaderGetCmd = &cobra.Command{
	Use:   "get",
	Short: "Show the current leader",
	Run: func(cmd *cobra.Command, args []string) {
		v, e := client(cmd).GetCurrentLeader()
		cli.Output(MarLeaderInfo{v}, e)
	},