github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/v3_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/v3action" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 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 . V3SetHealthCheckActor 14 15 type V3SetHealthCheckActor interface { 16 CloudControllerAPIVersion() string 17 SetApplicationProcessHealthCheckTypeByNameAndSpace(appName string, spaceGUID string, healthCheckType constant.HealthCheckType, httpEndpoint string, processType string, invocationTimeout int) (v3action.Application, v3action.Warnings, error) 18 } 19 20 type V3SetHealthCheckCommand struct { 21 RequiredArgs flag.SetHealthCheckArgs `positional-args:"yes"` 22 HTTPEndpoint string `long:"endpoint" default:"/" description:"Path on the app"` 23 InvocationTimeout flag.PositiveInteger `long:"invocation-timeout" description:"Time (in seconds) that controls individual health check invocations"` 24 ProcessType string `long:"process" default:"web" description:"App process to update"` 25 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"` 26 27 UI command.UI 28 Config command.Config 29 SharedActor command.SharedActor 30 Actor V3SetHealthCheckActor 31 } 32 33 func (cmd *V3SetHealthCheckCommand) Setup(config command.Config, ui command.UI) error { 34 cmd.UI = ui 35 cmd.Config = config 36 cmd.SharedActor = sharedaction.NewActor(config) 37 38 ccClient, _, err := shared.NewV3BasedClients(config, ui, true, "") 39 if err != nil { 40 return err 41 } 42 cmd.Actor = v3action.NewActor(ccClient, config, nil, nil) 43 44 return nil 45 } 46 47 func (cmd V3SetHealthCheckCommand) Execute(args []string) error { 48 cmd.UI.DisplayWarning(command.ExperimentalWarning) 49 50 err := command.MinimumCCAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionApplicationFlowV3) 51 if err != nil { 52 return err 53 } 54 55 err = cmd.SharedActor.CheckTarget(true, true) 56 if err != nil { 57 return err 58 } 59 60 user, err := cmd.Config.CurrentUser() 61 if err != nil { 62 return err 63 } 64 65 cmd.UI.DisplayTextWithFlavor("Updating health check type for app {{.AppName}} process {{.ProcessType}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ 66 "AppName": cmd.RequiredArgs.AppName, 67 "ProcessType": cmd.ProcessType, 68 "OrgName": cmd.Config.TargetedOrganization().Name, 69 "SpaceName": cmd.Config.TargetedSpace().Name, 70 "Username": user.Name, 71 }) 72 cmd.UI.DisplayNewline() 73 74 app, warnings, err := cmd.Actor.SetApplicationProcessHealthCheckTypeByNameAndSpace( 75 cmd.RequiredArgs.AppName, 76 cmd.Config.TargetedSpace().GUID, 77 cmd.RequiredArgs.HealthCheck.Type, 78 cmd.HTTPEndpoint, 79 cmd.ProcessType, 80 cmd.InvocationTimeout.Value, 81 ) 82 83 cmd.UI.DisplayWarnings(warnings) 84 if err != nil { 85 return err 86 } 87 88 cmd.UI.DisplayOK() 89 90 if app.Started() { 91 cmd.UI.DisplayNewline() 92 cmd.UI.DisplayText("TIP: An app restart is required for the change to take effect.") 93 } 94 95 return nil 96 }