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