github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/command/v3/v3_set_health_check_command.go (about) 1 package v3 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/actor/sharedaction" 7 "code.cloudfoundry.org/cli/actor/v3action" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 10 "code.cloudfoundry.org/cli/command" 11 "code.cloudfoundry.org/cli/command/flag" 12 "code.cloudfoundry.org/cli/command/translatableerror" 13 "code.cloudfoundry.org/cli/command/v3/shared" 14 ) 15 16 //go:generate counterfeiter . V3SetHealthCheckActor 17 18 type V3SetHealthCheckActor interface { 19 CloudControllerAPIVersion() string 20 SetApplicationProcessHealthCheckTypeByNameAndSpace(appName string, spaceGUID string, healthCheckType string, httpEndpoint string, processType string, invocationTimeout int) (v3action.Application, v3action.Warnings, error) 21 } 22 23 type V3SetHealthCheckCommand struct { 24 RequiredArgs flag.SetHealthCheckArgs `positional-args:"yes"` 25 HTTPEndpoint string `long:"endpoint" default:"/" description:"Path on the app"` 26 InvocationTimeout flag.PositiveInteger `long:"invocation-timeout" description:"Time (in seconds) that controls individual health check invocations"` 27 ProcessType string `long:"process" default:"web" description:"App process to update"` 28 usage interface{} `usage:"CF_NAME v3-set-health-check APP_NAME (process | port | http [--endpoint PATH]) [--process PROCESS] [--invocation-timeout INVOCATION_TIMEOUT]\n\nEXAMPLES:\n cf v3-set-health-check worker-app process --process worker\n cf v3-set-health-check my-web-app http --endpoint /foo\n cf v3-set-health-check my-web-app http --invocation-timeout 10"` 29 30 UI command.UI 31 Config command.Config 32 SharedActor command.SharedActor 33 Actor V3SetHealthCheckActor 34 } 35 36 func (cmd *V3SetHealthCheckCommand) Setup(config command.Config, ui command.UI) error { 37 cmd.UI = ui 38 cmd.Config = config 39 cmd.SharedActor = sharedaction.NewActor(config) 40 41 ccClient, _, err := shared.NewClients(config, ui, true) 42 if err != nil { 43 if v3Err, ok := err.(ccerror.V3UnexpectedResponseError); ok && v3Err.ResponseCode == http.StatusNotFound { 44 return translatableerror.MinimumAPIVersionNotMetError{MinimumVersion: ccversion.MinVersionV3} 45 } 46 47 return err 48 } 49 cmd.Actor = v3action.NewActor(ccClient, config, nil, nil) 50 51 return nil 52 } 53 54 func (cmd V3SetHealthCheckCommand) Execute(args []string) error { 55 cmd.UI.DisplayWarning(command.ExperimentalWarning) 56 57 err := command.MinimumAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionV3) 58 if err != nil { 59 return err 60 } 61 62 err = cmd.SharedActor.CheckTarget(true, true) 63 if err != nil { 64 return err 65 } 66 67 user, err := cmd.Config.CurrentUser() 68 if err != nil { 69 return err 70 } 71 72 cmd.UI.DisplayTextWithFlavor("Updating health check type for app {{.AppName}} process {{.ProcessType}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ 73 "AppName": cmd.RequiredArgs.AppName, 74 "ProcessType": cmd.ProcessType, 75 "OrgName": cmd.Config.TargetedOrganization().Name, 76 "SpaceName": cmd.Config.TargetedSpace().Name, 77 "Username": user.Name, 78 }) 79 cmd.UI.DisplayNewline() 80 81 app, warnings, err := cmd.Actor.SetApplicationProcessHealthCheckTypeByNameAndSpace( 82 cmd.RequiredArgs.AppName, 83 cmd.Config.TargetedSpace().GUID, 84 cmd.RequiredArgs.HealthCheck.Type, 85 cmd.HTTPEndpoint, 86 cmd.ProcessType, 87 cmd.InvocationTimeout.Value, 88 ) 89 90 cmd.UI.DisplayWarnings(warnings) 91 if err != nil { 92 return err 93 } 94 95 cmd.UI.DisplayOK() 96 97 if app.Started() { 98 cmd.UI.DisplayNewline() 99 cmd.UI.DisplayText("TIP: An app restart is required for the change to take effect.") 100 } 101 102 return nil 103 }