forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage_package_command.go
113 lines (90 loc) · 3.22 KB
/
stage_package_command.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package v7
import (
"strings"
"time"
"code.cloudfoundry.org/cli/actor/sharedaction"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/command/v7/shared"
"code.cloudfoundry.org/cli/resources"
)
type StagePackageCommand struct {
BaseCommand
RequiredArgs flag.AppName `positional-args:"yes"`
PackageGUID string `long:"package-guid" description:"The guid of the package to stage (default: latest ready package)"`
usage interface{} `usage:"CF_NAME stage-package APP_NAME [--package-guid PACKAGE_GUID]"`
relatedCommands interface{} `related_commands:"app, create-package, droplets, packages, push, set-droplet"`
envCFStagingTimeout interface{} `environmentName:"CF_STAGING_TIMEOUT" environmentDescription:"Max wait time for staging, in minutes" environmentDefault:"15"`
LogCacheClient sharedaction.LogCacheClient
}
func (cmd *StagePackageCommand) Setup(config command.Config, ui command.UI) error {
err := cmd.BaseCommand.Setup(config, ui)
if err != nil {
return err
}
logCacheEndpoint, _, err := cmd.Actor.GetLogCacheEndpoint()
if err != nil {
return err
}
cmd.LogCacheClient = command.NewLogCacheClient(logCacheEndpoint, config, ui)
return nil
}
func (cmd StagePackageCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, true)
if err != nil {
return err
}
user, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Staging package for {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
"AppName": cmd.RequiredArgs.AppName,
"OrgName": cmd.Config.TargetedOrganization().Name,
"SpaceName": cmd.Config.TargetedSpace().Name,
"Username": user.Name,
})
packageGUID := cmd.PackageGUID
if packageGUID == "" {
app, warnings, err := cmd.Actor.GetApplicationByNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
pkg, warnings, err := cmd.Actor.GetNewestReadyPackageForApplication(app)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
packageGUID = pkg.GUID
}
logStream, logErrStream, stopLogStreamFunc, logWarnings, logErr := cmd.Actor.GetStreamingLogsForApplicationByNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID, cmd.LogCacheClient)
cmd.UI.DisplayWarnings(logWarnings)
if logErr != nil {
return logErr
}
defer stopLogStreamFunc()
dropletStream, warningsStream, errStream := cmd.Actor.StagePackage(
packageGUID,
cmd.RequiredArgs.AppName,
cmd.Config.TargetedSpace().GUID,
)
var droplet resources.Droplet
droplet, err = shared.PollStage(dropletStream, warningsStream, errStream, logStream, logErrStream, cmd.UI)
if err != nil {
return err
}
cmd.UI.DisplayNewline()
cmd.UI.DisplayText("Package staged")
t, err := time.Parse(time.RFC3339, droplet.CreatedAt)
if err != nil {
return err
}
table := [][]string{
{cmd.UI.TranslateText("droplet guid:"), droplet.GUID},
{cmd.UI.TranslateText("state:"), strings.ToLower(string(droplet.State))},
{cmd.UI.TranslateText("created:"), cmd.UI.UserFriendlyDate(t)},
}
cmd.UI.DisplayKeyValueTable("", table, 3)
return nil
}