forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actualize.go
137 lines (114 loc) · 3.68 KB
/
actualize.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package pushaction
import (
"os"
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
log "github.com/sirupsen/logrus"
)
func (actor Actor) Actualize(state PushPlan, progressBar ProgressBar) (
<-chan PushPlan, <-chan Event, <-chan Warnings, <-chan error,
) {
log.Debugf("Starting to Actualize Push plan: %#v\n", state)
stateStream := make(chan PushPlan)
eventStream := make(chan Event)
warningsStream := make(chan Warnings)
errorStream := make(chan error)
go func() {
log.Debug("starting actualize go routine")
defer close(stateStream)
defer close(eventStream)
defer close(warningsStream)
defer close(errorStream)
if state.Application.GUID != "" {
log.WithField("Name", state.Application.Name).Info("skipping app creation as it has a GUID")
eventStream <- SkippingApplicationCreation
} else {
log.WithField("Name", state.Application.Name).Info("creating app")
createdApp, createWarnings, err := actor.V3Actor.CreateApplicationInSpace(state.Application, state.SpaceGUID)
warningsStream <- Warnings(createWarnings)
if err != nil {
errorStream <- err
return
}
state.Application = createdApp
eventStream <- CreatedApplication
}
stateStream <- state
log.WithField("Path", state.BitsPath).Info(string(CreatingArchive))
eventStream <- CreatingArchive
archivePath, err := actor.SharedActor.ZipDirectoryResources(state.BitsPath, state.AllResources)
if err != nil {
errorStream <- err
return
}
defer os.RemoveAll(archivePath)
eventStream <- CreatingPackage
log.WithField("GUID", state.Application.GUID).Info("creating package")
pkg, warnings, err := actor.V3Actor.CreateBitsPackageByApplication(state.Application.GUID)
warningsStream <- Warnings(warnings)
if err != nil {
errorStream <- err
return
}
for count := 0; count < PushRetries; count++ {
eventStream <- ReadingArchive
log.WithField("GUID", state.Application.GUID).Info("creating package")
file, size, readErr := actor.SharedActor.ReadArchive(archivePath)
if readErr != nil {
errorStream <- readErr
return
}
defer file.Close()
eventStream <- UploadingApplicationWithArchive
progressReader := progressBar.NewProgressBarWrapper(file, size)
pkg, warnings, err = actor.V3Actor.UploadBitsPackage(pkg, state.MatchedResources, progressReader, size)
warningsStream <- Warnings(warnings)
if _, ok := err.(ccerror.PipeSeekError); ok {
eventStream <- RetryUpload
continue
}
break
}
if err != nil {
if e, ok := err.(ccerror.PipeSeekError); ok {
errorStream <- actionerror.UploadFailedError{Err: e.Err}
return
}
errorStream <- err
return
}
eventStream <- UploadWithArchiveComplete
polledPackage, warnings, err := actor.V3Actor.PollPackage(pkg)
warningsStream <- Warnings(warnings)
if err != nil {
errorStream <- err
return
}
eventStream <- StartingStaging
build, warnings, err := actor.V3Actor.StageApplicationPackage(polledPackage.GUID)
warningsStream <- Warnings(warnings)
if err != nil {
errorStream <- err
return
}
eventStream <- PollingBuild
droplet, warnings, err := actor.V3Actor.PollBuild(build.GUID, state.Application.Name)
warningsStream <- Warnings(warnings)
if err != nil {
errorStream <- err
return
}
eventStream <- StagingComplete
eventStream <- SettingDroplet
warnings, err = actor.V3Actor.SetApplicationDroplet(state.Application.GUID, droplet.GUID)
warningsStream <- Warnings(warnings)
if err != nil {
errorStream <- err
return
}
eventStream <- SetDropletComplete
log.Debug("completed apply")
eventStream <- Complete
}()
return stateStream, eventStream, warningsStream, errorStream
}