-
Notifications
You must be signed in to change notification settings - Fork 0
/
restart.go
81 lines (69 loc) · 2.14 KB
/
restart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package application
import (
"github.com/cloudfoundry/cli/cf/command_metadata"
"github.com/cloudfoundry/cli/cf/configuration/core_config"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/codegangsta/cli"
)
type Restart struct {
ui terminal.UI
config core_config.Reader
starter ApplicationStarter
stopper ApplicationStopper
appReq requirements.ApplicationRequirement
}
type ApplicationRestarter interface {
ApplicationRestart(app models.Application, orgName string, spaceName string)
}
func NewRestart(ui terminal.UI, config core_config.Reader, starter ApplicationStarter, stopper ApplicationStopper) (cmd *Restart) {
cmd = new(Restart)
cmd.ui = ui
cmd.config = config
cmd.starter = starter
cmd.stopper = stopper
return
}
func (cmd *Restart) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
Name: "restart",
ShortName: "rs",
Description: T("Restart an app"),
Usage: T("CF_NAME restart APP_NAME"),
}
}
func (cmd *Restart) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 1 {
cmd.ui.FailWithUsage(c)
}
if cmd.appReq == nil {
cmd.appReq = requirementsFactory.NewApplicationRequirement(c.Args()[0])
} else {
cmd.appReq.SetApplicationName(c.Args()[0])
}
reqs = []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedSpaceRequirement(),
cmd.appReq,
}
return
}
func (cmd *Restart) Run(c *cli.Context) {
app := cmd.appReq.GetApplication()
cmd.ApplicationRestart(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name)
}
func (cmd *Restart) ApplicationRestart(app models.Application, orgName, spaceName string) {
stoppedApp, err := cmd.stopper.ApplicationStop(app, orgName, spaceName)
if err != nil {
cmd.ui.Failed(err.Error())
return
}
cmd.ui.Say("")
_, err = cmd.starter.ApplicationStart(stoppedApp, orgName, spaceName)
if err != nil {
cmd.ui.Failed(err.Error())
return
}
}