github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v6/set_health_check_command.go (about) 1 package v6 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v2action" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 7 8 "code.cloudfoundry.org/cli/command" 9 "code.cloudfoundry.org/cli/command/flag" 10 "code.cloudfoundry.org/cli/command/v6/shared" 11 ) 12 13 //go:generate counterfeiter . SetHealthCheckActor 14 15 type SetHealthCheckActor interface { 16 SetApplicationHealthCheckTypeByNameAndSpace(name string, spaceGUID string, healthCheckType constant.ApplicationHealthCheckType, httpEndpoint string) (v2action.Application, v2action.Warnings, error) 17 } 18 19 type SetHealthCheckCommand struct { 20 RequiredArgs flag.V6SetHealthCheckArgs `positional-args:"yes"` 21 HTTPEndpoint string `long:"endpoint" default:"/" description:"Path on the app"` 22 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"` 23 24 UI command.UI 25 Config command.Config 26 SharedActor command.SharedActor 27 Actor SetHealthCheckActor 28 } 29 30 func (cmd *SetHealthCheckCommand) Setup(config command.Config, ui command.UI) error { 31 cmd.Config = config 32 cmd.UI = ui 33 cmd.SharedActor = sharedaction.NewActor(config) 34 35 ccClient, uaaClient, err := shared.GetNewClientsAndConnectToCF(config, ui) 36 if err != nil { 37 return err 38 } 39 cmd.Actor = v2action.NewActor(ccClient, uaaClient, config) 40 41 return nil 42 } 43 44 func (cmd *SetHealthCheckCommand) Execute(args []string) error { 45 var err error 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("Updating health check type for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", 58 map[string]interface{}{ 59 "AppName": cmd.RequiredArgs.AppName, 60 "OrgName": cmd.Config.TargetedOrganization().Name, 61 "SpaceName": cmd.Config.TargetedSpace().Name, 62 "Username": user.Name, 63 }) 64 65 app, warnings, err := cmd.Actor.SetApplicationHealthCheckTypeByNameAndSpace( 66 cmd.RequiredArgs.AppName, 67 cmd.Config.TargetedSpace().GUID, 68 constant.ApplicationHealthCheckType(cmd.RequiredArgs.HealthCheck.Type), 69 cmd.HTTPEndpoint, 70 ) 71 cmd.UI.DisplayWarnings(warnings) 72 if err != nil { 73 return err 74 } 75 76 cmd.UI.DisplayOK() 77 78 if app.Started() { 79 cmd.UI.DisplayNewline() 80 cmd.UI.DisplayText("TIP: An app restart is required for the change to take effect.") 81 } 82 83 return nil 84 }