github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v7/set_health_check_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/sharedaction"
     5  	"code.cloudfoundry.org/cli/actor/v7action"
     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/v7/shared"
    10  	"code.cloudfoundry.org/clock"
    11  )
    12  
    13  //go:generate counterfeiter . SetHealthCheckActor
    14  
    15  type SetHealthCheckActor interface {
    16  	CloudControllerAPIVersion() string
    17  	SetApplicationProcessHealthCheckTypeByNameAndSpace(appName string, spaceGUID string, healthCheckType constant.HealthCheckType, httpEndpoint string, processType string, invocationTimeout int64) (v7action.Application, v7action.Warnings, error)
    18  }
    19  
    20  type SetHealthCheckCommand 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 set-health-check APP_NAME (process | port | http [--endpoint PATH]) [--process PROCESS] [--invocation-timeout INVOCATION_TIMEOUT]\n\nEXAMPLES:\n   cf set-health-check worker-app process --process worker\n   cf set-health-check my-web-app http --endpoint /foo\n   cf 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       SetHealthCheckActor
    31  }
    32  
    33  func (cmd *SetHealthCheckCommand) 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.GetNewClientsAndConnectToCF(config, ui, "")
    39  	if err != nil {
    40  		return err
    41  	}
    42  	cmd.Actor = v7action.NewActor(ccClient, config, nil, nil, clock.NewClock())
    43  
    44  	return nil
    45  }
    46  
    47  func (cmd SetHealthCheckCommand) Execute(args []string) error {
    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.DisplayText("TIP: An app restart is required for the change to take effect.")
    85  	}
    86  
    87  	return nil
    88  }