github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/command/v2/set_health_check_command.go (about) 1 package v2 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v2action" 6 7 "code.cloudfoundry.org/cli/command" 8 "code.cloudfoundry.org/cli/command/flag" 9 "code.cloudfoundry.org/cli/command/v2/shared" 10 ) 11 12 //go:generate counterfeiter . SetHealthCheckActor 13 type SetHealthCheckActor interface { 14 SetApplicationHealthCheckTypeByNameAndSpace(name string, spaceGUID string, healthCheckType string, httpEndpoint string) (v2action.Application, v2action.Warnings, error) 15 } 16 17 type SetHealthCheckCommand struct { 18 RequiredArgs flag.SetHealthCheckArgs `positional-args:"yes"` 19 HTTPEndpoint string `long:"endpoint" default:"/" description:"Path on the app"` 20 usage interface{} `usage:"CF_NAME set-health-check APP_NAME (process | port | http [--endpoint PATH])\n\nTIP: 'none' has been deprecated but is accepted for 'process'.\n\nEXAMPLES:\n cf set-health-check worker-app process\n cf set-health-check my-web-app http --endpoint /foo"` 21 UI command.UI 22 Config command.Config 23 SharedActor command.SharedActor 24 Actor SetHealthCheckActor 25 } 26 27 func (cmd *SetHealthCheckCommand) Setup(config command.Config, ui command.UI) error { 28 cmd.Config = config 29 cmd.UI = ui 30 cmd.SharedActor = sharedaction.NewActor() 31 32 ccClient, uaaClient, err := shared.NewClients(config, ui) 33 if err != nil { 34 return err 35 } 36 cmd.Actor = v2action.NewActor(ccClient, uaaClient) 37 38 return nil 39 } 40 41 func (cmd *SetHealthCheckCommand) Execute(args []string) error { 42 err := cmd.SharedActor.CheckTarget(cmd.Config, true, true) 43 if err != nil { 44 return shared.HandleError(err) 45 } 46 47 user, err := cmd.Config.CurrentUser() 48 if err != nil { 49 return err 50 } 51 52 cmd.UI.DisplayTextWithFlavor("Updating health check type for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", 53 map[string]interface{}{ 54 "AppName": cmd.RequiredArgs.AppName, 55 "OrgName": cmd.Config.TargetedOrganization().Name, 56 "SpaceName": cmd.Config.TargetedSpace().Name, 57 "Username": user.Name, 58 }) 59 60 app, warnings, err := cmd.Actor.SetApplicationHealthCheckTypeByNameAndSpace( 61 cmd.RequiredArgs.AppName, 62 cmd.Config.TargetedSpace().GUID, 63 cmd.RequiredArgs.HealthCheck.Type, 64 cmd.HTTPEndpoint, 65 ) 66 cmd.UI.DisplayWarnings(warnings) 67 if err != nil { 68 return shared.HandleError(err) 69 } 70 71 cmd.UI.DisplayOK() 72 73 if app.Started() { 74 cmd.UI.DisplayNewline() 75 cmd.UI.DisplayText("TIP: An app restart is required for the change to take affect.") 76 } 77 78 return nil 79 }