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