github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/command/v7/get_health_check_command.go (about) 1 package v7 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/actor/sharedaction" 7 "code.cloudfoundry.org/cli/actor/v7action" 8 "code.cloudfoundry.org/cli/command" 9 "code.cloudfoundry.org/cli/command/flag" 10 "code.cloudfoundry.org/cli/command/v7/shared" 11 "code.cloudfoundry.org/cli/util/ui" 12 ) 13 14 //go:generate counterfeiter . GetHealthCheckActor 15 16 type GetHealthCheckActor interface { 17 CloudControllerAPIVersion() string 18 GetApplicationProcessHealthChecksByNameAndSpace(appName string, spaceGUID string) ([]v7action.ProcessHealthCheck, v7action.Warnings, error) 19 } 20 21 type GetHealthCheckCommand struct { 22 RequiredArgs flag.AppName `positional-args:"yes"` 23 usage interface{} `usage:"CF_NAME get-health-check APP_NAME"` 24 25 UI command.UI 26 Config command.Config 27 SharedActor command.SharedActor 28 Actor GetHealthCheckActor 29 } 30 31 func (cmd *GetHealthCheckCommand) Setup(config command.Config, ui command.UI) error { 32 cmd.UI = ui 33 cmd.Config = config 34 cmd.SharedActor = sharedaction.NewActor(config) 35 36 ccClient, _, err := shared.NewClients(config, ui, true, "") 37 if err != nil { 38 return err 39 } 40 cmd.Actor = v7action.NewActor(ccClient, config, nil, nil) 41 42 return nil 43 } 44 45 func (cmd GetHealthCheckCommand) Execute(args []string) error { 46 err := cmd.SharedActor.CheckTarget(true, true) 47 if err != nil { 48 return err 49 } 50 51 user, err := cmd.Config.CurrentUser() 52 if err != nil { 53 return err 54 } 55 56 cmd.UI.DisplayTextWithFlavor("Getting health check type for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ 57 "AppName": cmd.RequiredArgs.AppName, 58 "OrgName": cmd.Config.TargetedOrganization().Name, 59 "SpaceName": cmd.Config.TargetedSpace().Name, 60 "Username": user.Name, 61 }) 62 63 processHealthChecks, warnings, err := cmd.Actor.GetApplicationProcessHealthChecksByNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID) 64 cmd.UI.DisplayWarnings(warnings) 65 if err != nil { 66 return err 67 } 68 69 cmd.UI.DisplayNewline() 70 71 if len(processHealthChecks) == 0 { 72 cmd.UI.DisplayText("App has no processes") 73 return nil 74 } 75 76 return cmd.DisplayProcessTable(processHealthChecks) 77 } 78 79 func (cmd GetHealthCheckCommand) DisplayProcessTable(processHealthChecks []v7action.ProcessHealthCheck) error { 80 table := [][]string{ 81 { 82 cmd.UI.TranslateText("process"), 83 cmd.UI.TranslateText("health check"), 84 cmd.UI.TranslateText("endpoint (for http)"), 85 cmd.UI.TranslateText("invocation timeout"), 86 }, 87 } 88 89 for _, healthCheck := range processHealthChecks { 90 invocationTimeout := healthCheck.InvocationTimeout 91 if invocationTimeout == 0 { 92 invocationTimeout = 1 93 } 94 95 table = append(table, []string{ 96 healthCheck.ProcessType, 97 string(healthCheck.HealthCheckType), 98 healthCheck.Endpoint, 99 fmt.Sprint(invocationTimeout), 100 }) 101 } 102 103 cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding) 104 105 return nil 106 }