github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+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 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 8 9 "code.cloudfoundry.org/cli/command" 10 "code.cloudfoundry.org/cli/command/flag" 11 "code.cloudfoundry.org/cli/command/translatableerror" 12 "code.cloudfoundry.org/cli/command/v2/shared" 13 ) 14 15 //go:generate counterfeiter . SetHealthCheckActor 16 17 type SetHealthCheckActor interface { 18 SetApplicationHealthCheckTypeByNameAndSpace(name string, spaceGUID string, healthCheckType constant.ApplicationHealthCheckType, httpEndpoint string) (v2action.Application, v2action.Warnings, error) 19 CloudControllerAPIVersion() string 20 } 21 22 type SetHealthCheckCommand struct { 23 RequiredArgs flag.SetHealthCheckArgs `positional-args:"yes"` 24 HTTPEndpoint string `long:"endpoint" default:"/" description:"Path on the app"` 25 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"` 26 27 UI command.UI 28 Config command.Config 29 SharedActor command.SharedActor 30 Actor SetHealthCheckActor 31 } 32 33 func (cmd *SetHealthCheckCommand) Setup(config command.Config, ui command.UI) error { 34 cmd.Config = config 35 cmd.UI = ui 36 cmd.SharedActor = sharedaction.NewActor(config) 37 38 ccClient, uaaClient, err := shared.NewClients(config, ui, true) 39 if err != nil { 40 return err 41 } 42 cmd.Actor = v2action.NewActor(ccClient, uaaClient, config) 43 44 return nil 45 } 46 47 func (cmd *SetHealthCheckCommand) Execute(args []string) error { 48 var err error 49 50 switch cmd.RequiredArgs.HealthCheck.Type { 51 case "http": 52 err = command.MinimumAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionProcessHealthCheckV2) 53 if err != nil { 54 return translatableerror.HealthCheckTypeUnsupportedError{SupportedTypes: []string{"port", "none"}} 55 } 56 err = command.MinimumAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionHTTPEndpointHealthCheckV2) 57 if err != nil { 58 return translatableerror.HealthCheckTypeUnsupportedError{SupportedTypes: []string{"port", "none", "process"}} 59 } 60 case "process": 61 err = command.MinimumAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionProcessHealthCheckV2) 62 if err != nil { 63 return translatableerror.HealthCheckTypeUnsupportedError{SupportedTypes: []string{"port", "none"}} 64 } 65 } 66 67 err = cmd.SharedActor.CheckTarget(true, true) 68 if err != nil { 69 return err 70 } 71 72 user, err := cmd.Config.CurrentUser() 73 if err != nil { 74 return err 75 } 76 77 cmd.UI.DisplayTextWithFlavor("Updating health check type for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", 78 map[string]interface{}{ 79 "AppName": cmd.RequiredArgs.AppName, 80 "OrgName": cmd.Config.TargetedOrganization().Name, 81 "SpaceName": cmd.Config.TargetedSpace().Name, 82 "Username": user.Name, 83 }) 84 85 app, warnings, err := cmd.Actor.SetApplicationHealthCheckTypeByNameAndSpace( 86 cmd.RequiredArgs.AppName, 87 cmd.Config.TargetedSpace().GUID, 88 constant.ApplicationHealthCheckType(cmd.RequiredArgs.HealthCheck.Type), 89 cmd.HTTPEndpoint, 90 ) 91 cmd.UI.DisplayWarnings(warnings) 92 if err != nil { 93 return err 94 } 95 96 cmd.UI.DisplayOK() 97 98 if app.Started() { 99 cmd.UI.DisplayNewline() 100 cmd.UI.DisplayText("TIP: An app restart is required for the change to take effect.") 101 } 102 103 return nil 104 }