github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/command/v3/v3_get_health_check_command.go (about) 1 package v3 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/actor/sharedaction" 7 "code.cloudfoundry.org/cli/actor/v3action" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 10 "code.cloudfoundry.org/cli/command" 11 "code.cloudfoundry.org/cli/command/flag" 12 "code.cloudfoundry.org/cli/command/translatableerror" 13 "code.cloudfoundry.org/cli/command/v3/shared" 14 "code.cloudfoundry.org/cli/util/ui" 15 ) 16 17 //go:generate counterfeiter . V3GetHealthCheckActor 18 19 type V3GetHealthCheckActor interface { 20 CloudControllerAPIVersion() string 21 GetApplicationProcessHealthChecksByNameAndSpace(appName string, spaceGUID string) ([]v3action.ProcessHealthCheck, v3action.Warnings, error) 22 } 23 24 type V3GetHealthCheckCommand struct { 25 RequiredArgs flag.AppName `positional-args:"yes"` 26 usage interface{} `usage:"CF_NAME v3-get-health-check APP_NAME"` 27 28 UI command.UI 29 Config command.Config 30 SharedActor command.SharedActor 31 Actor V3GetHealthCheckActor 32 } 33 34 func (cmd *V3GetHealthCheckCommand) Setup(config command.Config, ui command.UI) error { 35 cmd.UI = ui 36 cmd.Config = config 37 cmd.SharedActor = sharedaction.NewActor(config) 38 39 ccClient, _, err := shared.NewClients(config, ui, true) 40 if err != nil { 41 if v3Err, ok := err.(ccerror.V3UnexpectedResponseError); ok && v3Err.ResponseCode == http.StatusNotFound { 42 return translatableerror.MinimumAPIVersionNotMetError{MinimumVersion: ccversion.MinVersionV3} 43 } 44 45 return err 46 } 47 cmd.Actor = v3action.NewActor(nil, ccClient, config) 48 49 return nil 50 } 51 52 func (cmd V3GetHealthCheckCommand) Execute(args []string) error { 53 cmd.UI.DisplayText(command.ExperimentalWarning) 54 cmd.UI.DisplayNewline() 55 56 err := command.MinimumAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionV3) 57 if err != nil { 58 return err 59 } 60 61 err = cmd.SharedActor.CheckTarget(cmd.Config, true, true) 62 if err != nil { 63 return shared.HandleError(err) 64 } 65 66 user, err := cmd.Config.CurrentUser() 67 if err != nil { 68 return shared.HandleError(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 shared.HandleError(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 }, 97 } 98 99 for _, healthCheck := range processHealthChecks { 100 table = append(table, []string{ 101 healthCheck.ProcessType, 102 healthCheck.HealthCheckType, 103 healthCheck.Endpoint, 104 }) 105 } 106 107 cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding) 108 109 return nil 110 }