func (cmd *ShowApp) ShowApp(app models.Application, orgName, spaceName string) { cmd.ui.Say(T("Showing health and status for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(orgName), "SpaceName": terminal.EntityNameColor(spaceName), "Username": 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 } if apiErr != nil && !appIsStopped { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() cmd.ui.Say("\n%s %s", terminal.HeaderColor(T("requested state:")), ui_helpers.ColoredAppState(application.ApplicationFields)) cmd.ui.Say("%s %s", terminal.HeaderColor(T("instances:")), ui_helpers.ColoredAppInstances(application.ApplicationFields)) cmd.ui.Say(T("{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances", map[string]interface{}{ "Usage": terminal.HeaderColor(T("usage:")), "FormattedMemory": formatters.ByteSize(application.Memory * formatters.MEGABYTE), "InstanceCount": application.InstanceCount})) var urls []string for _, route := range application.Routes { urls = append(urls, route.URL()) } cmd.ui.Say("%s %s", terminal.HeaderColor(T("urls:")), strings.Join(urls, ", ")) var lastUpdated string if application.PackageUpdatedAt != nil { lastUpdated = application.PackageUpdatedAt.Format("Mon Jan 2 15:04:05 MST 2006") } else { lastUpdated = "unknown" } cmd.ui.Say("%s %s", terminal.HeaderColor(T("last uploaded:")), lastUpdated) if app.Stack != nil { cmd.ui.Say("%s %s", terminal.HeaderColor(T("stack:")), app.Stack.Name) } else { cmd.ui.Say("%s %s", terminal.HeaderColor(T("stack:")), "unknown") } if app.Buildpack != "" { cmd.ui.Say("%s %s\n", terminal.HeaderColor(T("buildpack:")), app.Buildpack) } else if app.DetectedBuildpack != "" { cmd.ui.Say("%s %s\n", terminal.HeaderColor(T("buildpack:")), app.DetectedBuildpack) } else { cmd.ui.Say("%s %s\n", terminal.HeaderColor(T("buildpack:")), "unknown") } if appIsStopped { cmd.ui.Say(T("There are no running instances of this app.")) return } table := terminal.NewTable(cmd.ui, []string{"", T("state"), T("since"), T("cpu"), T("memory"), T("disk"), T("details")}) for index, instance := range instances { table.Add( 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(T("{{.MemUsage}} of {{.MemQuota}}", map[string]interface{}{ "MemUsage": formatters.ByteSize(instance.MemUsage), "MemQuota": formatters.ByteSize(instance.MemQuota)})), fmt.Sprintf(T("{{.DiskUsage}} of {{.DiskQuota}}", map[string]interface{}{ "DiskUsage": formatters.ByteSize(instance.DiskUsage), "DiskQuota": formatters.ByteSize(instance.DiskQuota)})), fmt.Sprintf("%s", instance.Details), ) if cmd.pluginCall { i := plugin_models.GetApp_AppInstanceFields{} i.State = fmt.Sprintf("%s", instance.State) i.Details = instance.Details i.Since = instance.Since i.CpuUsage = instance.CpuUsage i.DiskQuota = instance.DiskQuota i.DiskUsage = instance.DiskUsage i.MemQuota = instance.MemQuota i.MemUsage = instance.MemUsage cmd.pluginAppModel.Instances = append(cmd.pluginAppModel.Instances, i) } } table.Print() }
func (cmd *ShowApp) ShowApp(app models.Application) { cmd.ui.Say(T("Showing health and status for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "Username": 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(T("requested state:")), ui_helpers.ColoredAppState(application.ApplicationFields)) cmd.ui.Say("%s %s", terminal.HeaderColor(T("instances:")), ui_helpers.ColoredAppInstances(application.ApplicationFields)) cmd.ui.Say(T("{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances", map[string]interface{}{ "Usage": terminal.HeaderColor(T("usage:")), "FormattedMemory": formatters.ByteSize(application.Memory * formatters.MEGABYTE), "InstanceCount": application.InstanceCount})) var urls []string for _, route := range application.Routes { urls = append(urls, route.URL()) } cmd.ui.Say("%s %s\n", terminal.HeaderColor(T("urls:")), strings.Join(urls, ", ")) if appIsStopped { cmd.ui.Say(T("There are no running instances of this app.")) return } table := terminal.NewTable(cmd.ui, []string{"", T("state"), T("since"), T("cpu"), T("memory"), T("disk")}) for index, instance := range instances { table.Add([]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(T("{{.MemUsage}} of {{.MemQuota}}", map[string]interface{}{ "MemUsage": formatters.ByteSize(instance.MemUsage), "MemQuota": formatters.ByteSize(instance.MemQuota)})), fmt.Sprintf(T("{{.DiskUsage}} of {{.DiskQuota}}", map[string]interface{}{ "DiskUsage": formatters.ByteSize(instance.DiskUsage), "DiskQuota": formatters.ByteSize(instance.DiskQuota)})), }) } table.Print() }