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