Exemplo n.º 1
0
Arquivo: show_app.go Projeto: nsnt/cli
func (cmd *ShowApp) ShowApp(app cf.Application) {

	cmd.ui.Say("Showing health and status for app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields.Name),
		terminal.EntityNameColor(cmd.config.SpaceFields.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	appSummary, apiResponse := cmd.appSummaryRepo.GetSummary(app.Guid)
	appIsStopped := apiResponse.ErrorCode == cf.APP_STOPPED ||
		apiResponse.ErrorCode == cf.APP_NOT_STAGED ||
		appSummary.State == "stopped"

	if apiResponse.IsNotSuccessful() && !appIsStopped {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	var instances []cf.AppInstanceFields
	instances, apiResponse = cmd.appInstancesRepo.GetInstances(app.Guid)
	if apiResponse.IsNotSuccessful() && !appIsStopped {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("\n%s %s", terminal.HeaderColor("requested state:"), coloredAppState(appSummary.ApplicationFields))
	cmd.ui.Say("%s %s", terminal.HeaderColor("instances:"), coloredAppInstances(appSummary.ApplicationFields))
	cmd.ui.Say("%s %s x %d instances", terminal.HeaderColor("usage:"), formatters.ByteSize(appSummary.Memory*formatters.MEGABYTE), appSummary.InstanceCount)

	var urls []string
	for _, route := range appSummary.RouteSummaries {
		urls = append(urls, route.URL())
	}

	cmd.ui.Say("%s %s\n", terminal.HeaderColor("urls:"), strings.Join(urls, ", "))

	if appIsStopped {
		cmd.ui.Say("There are no running instances of this app.")
		return
	}

	table := [][]string{
		[]string{"", "state", "since", "cpu", "memory", "disk"},
	}

	for index, instance := range instances {
		table = append(table, []string{
			fmt.Sprintf("#%d", index),
			coloredInstanceState(instance),
			instance.Since.Format("2006-01-02 03:04:05 PM"),
			fmt.Sprintf("%.1f%%", instance.CpuUsage*100),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.MemUsage), formatters.ByteSize(instance.MemQuota)),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.DiskUsage), formatters.ByteSize(instance.DiskQuota)),
		})
	}

	cmd.ui.DisplayTable(table)
}
Exemplo n.º 2
0
Arquivo: apps.go Projeto: nota-ja/cli
func (cmd ListApps) Run(c *cli.Context) {
	cmd.ui.Say("Getting apps in org %s / space %s as %s...",
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	apps, apiErr := cmd.appSummaryRepo.GetSummariesInCurrentSpace()

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	if len(apps) == 0 {
		cmd.ui.Say("No apps found")
		return
	}

	table := terminal.NewTable(cmd.ui, []string{
		"name",
		"requested state",
		"instances",
		"memory",
		"disk",
		"urls",
	})

	rows := [][]string{}

	for _, application := range apps {
		var urls []string
		for _, route := range application.Routes {
			urls = append(urls, route.URL())
		}

		rows = append(rows, []string{
			application.Name,
			ui_helpers.ColoredAppState(application.ApplicationFields),
			ui_helpers.ColoredAppInstances(application.ApplicationFields),
			formatters.ByteSize(application.Memory * formatters.MEGABYTE),
			formatters.ByteSize(application.DiskQuota * formatters.MEGABYTE),
			strings.Join(urls, ", "),
		})
	}

	table.Print(rows)
}
Exemplo n.º 3
0
func (cmd *ShowApp) Run(c *cli.Context) {
	app := cmd.appReq.GetApplication()
	cmd.ui.Say("Showing health and status for app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.Organization.Name),
		terminal.EntityNameColor(cmd.config.Space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	summary, apiResponse := cmd.appSummaryRepo.GetSummary(app)
	appIsStopped := apiResponse.ErrorCode == cf.APP_STOPPED || apiResponse.ErrorCode == cf.APP_NOT_STAGED

	if apiResponse.IsNotSuccessful() && !appIsStopped {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("\n%s %s", terminal.HeaderColor("state:"), coloredAppState(summary.App))
	cmd.ui.Say("%s %s", terminal.HeaderColor("instances:"), coloredAppInstaces(summary.App))
	cmd.ui.Say("%s %s x %d instances", terminal.HeaderColor("usage:"), formatters.ByteSize(summary.App.Memory*formatters.MEGABYTE), summary.App.Instances)

	var urls []string
	for _, route := range summary.App.Routes {
		urls = append(urls, route.URL())
	}
	cmd.ui.Say("%s %s\n", terminal.HeaderColor("urls:"), strings.Join(urls, ", "))

	if appIsStopped {
		return
	}

	table := [][]string{
		[]string{"", "status", "since", "cpu", "memory", "disk"},
	}

	for index, instance := range summary.Instances {
		table = append(table, []string{
			fmt.Sprintf("#%d", index),
			coloredInstanceState(instance),
			instance.Since.Format("2006-01-02 03:04:05 PM"),
			fmt.Sprintf("%.1f%%", instance.CpuUsage),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.MemUsage), formatters.ByteSize(instance.MemQuota)),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.DiskUsage), formatters.ByteSize(instance.DiskQuota)),
		})
	}

	cmd.ui.DisplayTable(table)
}
Exemplo n.º 4
0
func (cmd *ListQuotas) Run(c *cli.Context) {
	cmd.ui.Say("Getting quotas as %s...", terminal.EntityNameColor(cmd.config.Username()))

	quotas, apiErr := cmd.quotaRepo.FindAll()

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}
	cmd.ui.Ok()
	cmd.ui.Say("")

	table := [][]string{
		[]string{"name", "memory limit"},
	}

	for _, quota := range quotas {
		table = append(table, []string{
			quota.Name,
			formatters.ByteSize(quota.MemoryLimit * formatters.MEGABYTE),
		})
	}

	cmd.ui.DisplayTable(table)
}
Exemplo n.º 5
0
func (cmd *ListQuotas) Run(c *cli.Context) {
	cmd.ui.Say("Getting quotas as %s...", terminal.EntityNameColor(cmd.config.Username()))

	quotas, apiErr := cmd.quotaRepo.FindAll()

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}
	cmd.ui.Ok()
	cmd.ui.Say("")

	table := terminal.NewTable(cmd.ui, []string{"name", "memory limit", "routes", "service instances", "paid service plans"})
	rows := [][]string{}

	for _, quota := range quotas {
		rows = append(rows, []string{
			quota.Name,
			formatters.ByteSize(quota.MemoryLimit * formatters.MEGABYTE),
			fmt.Sprintf("%d", quota.RoutesLimit),
			fmt.Sprintf("%d", quota.ServicesLimit),
			formatters.Allowed(quota.NonBasicServicesAllowed),
		})
	}

	table.Print(rows)
}
Exemplo n.º 6
0
Arquivo: push.go Projeto: nota-ja/cli
func (cmd *Push) describeUploadOperation(path string, zipFileBytes, fileCount uint64) {
	if fileCount > 0 {
		cmd.ui.Say("Uploading app files from: %s", path)
		cmd.ui.Say("Uploading %s, %d files", formatters.ByteSize(zipFileBytes), fileCount)
	} else {
		cmd.ui.Warn("None of your application files have changed. Nothing will be uploaded.")
	}
}
Exemplo n.º 7
0
func (cmd ListApps) Run(c *cli.Context) {
	cmd.ui.Say("Getting apps in org %s / space %s as %s...",
		terminal.EntityNameColor(cmd.config.OrganizationFields.Name),
		terminal.EntityNameColor(cmd.config.SpaceFields.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	apps, apiResponse := cmd.appSummaryRepo.GetSummariesInCurrentSpace()

	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	if len(apps) == 0 {
		cmd.ui.Say("No apps found")
		return
	}

	table := [][]string{
		[]string{"name", "requested state", "instances", "memory", "disk", "urls"},
	}

	for _, appSummary := range apps {
		var urls []string
		for _, route := range appSummary.RouteSummaries {
			urls = append(urls, route.URL())
		}

		table = append(table, []string{
			appSummary.Name,
			coloredAppState(appSummary.ApplicationFields),
			coloredAppInstances(appSummary.ApplicationFields),
			formatters.ByteSize(appSummary.Memory * formatters.MEGABYTE),
			formatters.ByteSize(appSummary.DiskQuota * formatters.MEGABYTE),
			strings.Join(urls, ", "),
		})
	}

	cmd.ui.DisplayTable(table)
}
Exemplo n.º 8
0
Arquivo: quota.go Projeto: nota-ja/cli
func (cmd *showQuota) Run(context *cli.Context) {
	quotaName := context.Args()[0]
	cmd.ui.Say("Getting quota %s info as %s...", quotaName, cmd.config.Username())

	quota, err := cmd.quotaRepo.FindByName(quotaName)
	if err != nil {
		cmd.ui.Failed(err.Error())
	}

	cmd.ui.Ok()

	table := terminal.NewTable(cmd.ui, []string{"", ""})
	table.Print([][]string{
		[]string{"Memory", formatters.ByteSize(quota.MemoryLimit * formatters.MEGABYTE)},
		[]string{"Routes", fmt.Sprintf("%d", quota.RoutesLimit)},
		[]string{"Services", fmt.Sprintf("%d", quota.ServicesLimit)},
		[]string{"Paid service plans", formatters.Allowed(quota.NonBasicServicesAllowed)},
	})
}
Exemplo n.º 9
0
func (cmd *Push) describeUploadOperation(path string, zipFileBytes, fileCount uint64) {
	humanReadableBytes := formatters.ByteSize(zipFileBytes)
	cmd.ui.Say("Uploading from: %s\n%s, %d files", path, humanReadableBytes, fileCount)
}
Exemplo n.º 10
0
Arquivo: push.go Projeto: nsnt/cli
func (cmd *Push) describeUploadOperation(zipFileBytes, fileCount uint64) {
	humanReadableBytes := formatters.ByteSize(zipFileBytes)
	cmd.ui.Say("Uploading app: %s, %d files", humanReadableBytes, fileCount)
}
Exemplo n.º 11
0
Arquivo: scale.go Projeto: julz/cli
func (cmd *Scale) Run(c *cli.Context) {
	currentApp := cmd.appReq.GetApplication()
	if !anyFlagsSet(c) {
		cmd.ui.Say("Showing current scale of app %s in org %s / space %s as %s...",
			terminal.EntityNameColor(currentApp.Name),
			terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
			terminal.EntityNameColor(cmd.config.SpaceFields().Name),
			terminal.EntityNameColor(cmd.config.Username()),
		)
		cmd.ui.Ok()
		cmd.ui.Say("")

		cmd.ui.Say("%s %s", terminal.HeaderColor("memory:"), formatters.ByteSize(currentApp.Memory*bytesInAMegabyte))
		cmd.ui.Say("%s %s", terminal.HeaderColor("disk:"), formatters.ByteSize(currentApp.DiskQuota*bytesInAMegabyte))
		cmd.ui.Say("%s %d", terminal.HeaderColor("instances:"), currentApp.InstanceCount)

		return
	}

	params := models.AppParams{}
	shouldRestart := false

	if c.String("m") != "" {
		memory, err := formatters.ToMegabytes(c.String("m"))
		if err != nil {
			cmd.ui.Failed("Invalid memory limit: %s\n%s", c.String("m"), err)
		}
		params.Memory = &memory
		shouldRestart = true
	}

	if c.String("k") != "" {
		diskQuota, err := formatters.ToMegabytes(c.String("k"))
		if err != nil {
			cmd.ui.Failed("Invalid disk quota: %s\n%s", c.String("k"), err)
		}
		params.DiskQuota = &diskQuota
		shouldRestart = true
	}

	if c.IsSet("i") {
		instances := c.Int("i")
		if instances > 0 {
			params.InstanceCount = &instances
		} else {
			cmd.ui.Failed("Invalid instance count: %d\nInstance count must be a positive integer", instances)
		}
	}

	if shouldRestart && !cmd.confirmRestart(c, currentApp.Name) {
		return
	}

	cmd.ui.Say("Scaling app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(currentApp.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	updatedApp, apiErr := cmd.appRepo.Update(currentApp.Guid, params)
	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()

	if shouldRestart {
		cmd.restarter.ApplicationRestart(updatedApp)
	}
}
Exemplo n.º 12
0
Arquivo: app.go Projeto: nota-ja/cli
func (cmd *ShowApp) ShowApp(app models.Application) {

	cmd.ui.Say("Showing health and status for app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	application, apiErr := cmd.appSummaryRepo.GetSummary(app.Guid)

	appIsStopped := (application.State == "stopped")
	if err, ok := apiErr.(errors.HttpError); ok {
		if err.ErrorCode() == errors.APP_STOPPED || err.ErrorCode() == errors.APP_NOT_STAGED {
			appIsStopped = true
		}
	}

	if apiErr != nil && !appIsStopped {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	var instances []models.AppInstanceFields
	instances, apiErr = cmd.appInstancesRepo.GetInstances(app.Guid)
	if apiErr != nil && !appIsStopped {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("\n%s %s", terminal.HeaderColor("requested state:"), ui_helpers.ColoredAppState(application.ApplicationFields))
	cmd.ui.Say("%s %s", terminal.HeaderColor("instances:"), ui_helpers.ColoredAppInstances(application.ApplicationFields))
	cmd.ui.Say("%s %s x %d instances", terminal.HeaderColor("usage:"), formatters.ByteSize(application.Memory*formatters.MEGABYTE), application.InstanceCount)

	var urls []string
	for _, route := range application.Routes {
		urls = append(urls, route.URL())
	}

	cmd.ui.Say("%s %s\n", terminal.HeaderColor("urls:"), strings.Join(urls, ", "))

	if appIsStopped {
		cmd.ui.Say("There are no running instances of this app.")
		return
	}

	table := terminal.NewTable(cmd.ui, []string{"", "state", "since", "cpu", "memory", "disk"})
	rows := [][]string{}

	for index, instance := range instances {
		rows = append(rows, []string{
			fmt.Sprintf("#%d", index),
			ui_helpers.ColoredInstanceState(instance),
			instance.Since.Format("2006-01-02 03:04:05 PM"),
			fmt.Sprintf("%.1f%%", instance.CpuUsage*100),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.MemUsage), formatters.ByteSize(instance.MemQuota)),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.DiskUsage), formatters.ByteSize(instance.DiskQuota)),
		})
	}

	table.Print(rows)
}