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