github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/command/v7/set_health_check_command.go (about) 1 package v7 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v7action" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 7 "code.cloudfoundry.org/cli/command" 8 "code.cloudfoundry.org/cli/command/flag" 9 "code.cloudfoundry.org/cli/command/v7/shared" 10 ) 11 12 //go:generate counterfeiter . SetHealthCheckActor 13 14 type SetHealthCheckActor interface { 15 CloudControllerAPIVersion() string 16 SetApplicationProcessHealthCheckTypeByNameAndSpace(appName string, spaceGUID string, healthCheckType constant.HealthCheckType, httpEndpoint string, processType string, invocationTimeout int64) (v7action.Application, v7action.Warnings, error) 17 } 18 19 type SetHealthCheckCommand struct { 20 RequiredArgs flag.SetHealthCheckArgs `positional-args:"yes"` 21 HTTPEndpoint string `long:"endpoint" default:"/" description:"Path on the app"` 22 InvocationTimeout flag.PositiveInteger `long:"invocation-timeout" description:"Time (in seconds) that controls individual health check invocations"` 23 ProcessType string `long:"process" default:"web" description:"App process to update"` 24 usage interface{} `usage:"CF_NAME set-health-check APP_NAME (process | port | http [--endpoint PATH]) [--process PROCESS] [--invocation-timeout INVOCATION_TIMEOUT]\n\nEXAMPLES:\n cf set-health-check worker-app process --process worker\n cf set-health-check my-web-app http --endpoint /foo\n cf set-health-check my-web-app http --invocation-timeout 10"` 25 26 UI command.UI 27 Config command.Config 28 SharedActor command.SharedActor 29 Actor SetHealthCheckActor 30 } 31 32 func (cmd *SetHealthCheckCommand) 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.NewClients(config, ui, true, "") 38 if err != nil { 39 return err 40 } 41 cmd.Actor = v7action.NewActor(ccClient, config, nil, nil) 42 43 return nil 44 } 45 46 func (cmd SetHealthCheckCommand) Execute(args []string) error { 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("Updating health check type for app {{.AppName}} process {{.ProcessType}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ 58 "AppName": cmd.RequiredArgs.AppName, 59 "ProcessType": cmd.ProcessType, 60 "OrgName": cmd.Config.TargetedOrganization().Name, 61 "SpaceName": cmd.Config.TargetedSpace().Name, 62 "Username": user.Name, 63 }) 64 cmd.UI.DisplayNewline() 65 66 app, warnings, err := cmd.Actor.SetApplicationProcessHealthCheckTypeByNameAndSpace( 67 cmd.RequiredArgs.AppName, 68 cmd.Config.TargetedSpace().GUID, 69 cmd.RequiredArgs.HealthCheck.Type, 70 cmd.HTTPEndpoint, 71 cmd.ProcessType, 72 cmd.InvocationTimeout.Value, 73 ) 74 75 cmd.UI.DisplayWarnings(warnings) 76 if err != nil { 77 return err 78 } 79 80 cmd.UI.DisplayOK() 81 82 if app.Started() { 83 cmd.UI.DisplayText("TIP: An app restart is required for the change to take effect.") 84 } 85 86 return nil 87 }