forked from cloudfoundry-community/cloudfoundry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
73 lines (59 loc) · 1.88 KB
/
build.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
package v3action
import (
"errors"
"time"
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
)
func (actor Actor) StagePackage(packageGUID string, appName string) (<-chan Droplet, <-chan Warnings, <-chan error) {
dropletStream := make(chan Droplet)
warningsStream := make(chan Warnings)
errorStream := make(chan error)
go func() {
defer close(dropletStream)
defer close(warningsStream)
defer close(errorStream)
build := ccv3.Build{PackageGUID: packageGUID}
build, allWarnings, err := actor.CloudControllerClient.CreateBuild(build)
warningsStream <- Warnings(allWarnings)
if err != nil {
errorStream <- err
return
}
timeout := time.Now().Add(actor.Config.StagingTimeout())
for time.Now().Before(timeout) {
var warnings ccv3.Warnings
build, warnings, err = actor.CloudControllerClient.GetBuild(build.GUID)
warningsStream <- Warnings(warnings)
if err != nil {
errorStream <- err
return
}
switch build.State {
case constant.BuildFailed:
errorStream <- errors.New(build.Error)
return
case constant.BuildStaging:
time.Sleep(actor.Config.PollingInterval())
default:
//TODO: uncommend after #150569020
// ccv3Droplet, warnings, err := actor.CloudControllerClient.GetDroplet(build.DropletGUID)
// warningsStream <- Warnings(warnings)
// if err != nil {
// errorStream <- err
// return
// }
ccv3Droplet := ccv3.Droplet{
GUID: build.DropletGUID,
State: constant.DropletState(build.State),
CreatedAt: build.CreatedAt,
}
dropletStream <- actor.convertCCToActorDroplet(ccv3Droplet)
return
}
}
errorStream <- actionerror.StagingTimeoutError{AppName: appName, Timeout: actor.Config.StagingTimeout()}
}()
return dropletStream, warningsStream, errorStream
}