@@ -28,129 +28,42 @@ func (actor Actor) Actualize(state PushState, progressBar ProgressBar) (
28
28
defer close (warningsStream )
29
29
defer close (errorStream )
30
30
31
- if state .Application .GUID != "" {
32
- log .WithField ("Name" , state .Application .Name ).Info ("skipping app creation as it has a GUID" )
33
- eventStream <- SkippingApplicationCreation
34
- application , warnings , err := actor .V7Actor .UpdateApplication (state .Application )
35
- state .Application = application
36
- warningsStream <- Warnings (warnings )
37
- if err != nil {
38
- errorStream <- err
39
- return
40
- }
41
- eventStream <- UpdatedApplication
42
-
43
- } else {
44
- log .WithField ("Name" , state .Application .Name ).Info ("creating app" )
45
- createdApp , createWarnings , err := actor .V7Actor .CreateApplicationInSpace (state .Application , state .SpaceGUID )
46
- warningsStream <- Warnings (createWarnings )
47
- if err != nil {
48
- errorStream <- err
49
- return
50
- }
51
-
52
- state .Application = createdApp
53
- eventStream <- CreatedApplication
54
- }
55
- stateStream <- state
31
+ var err error
56
32
57
- if state .Overrides .Memory .IsSet {
58
- log .Info ("Scaling Web Process" )
59
- eventStream <- ScaleWebProcess
60
- process := v7action.Process {Type : constant .ProcessTypeWeb , MemoryInMB : state .Overrides .Memory }
61
- scaleWarnings , err := actor .V7Actor .ScaleProcessByApplication (state .Application .GUID , process )
62
- warningsStream <- Warnings (scaleWarnings )
63
- if err != nil {
64
- errorStream <- err
65
- return
66
- }
67
- eventStream <- ScaleWebProcessComplete
68
- }
69
-
70
- if state .Overrides .StartCommand .IsSet || state .Overrides .HealthCheckType != "" {
71
- log .Info ("Setting Web Process's Configuration" )
72
- eventStream <- SetProcessConfiguration
73
-
74
- var process v7action.Process
75
- if state .Overrides .StartCommand .IsSet {
76
- process .Command = state .Overrides .StartCommand
77
- }
78
- if state .Overrides .HealthCheckType != "" {
79
- process .HealthCheckType = state .Overrides .HealthCheckType
80
- process .HealthCheckEndpoint = constant .ProcessHealthCheckEndpointDefault
81
- }
82
-
83
- log .WithField ("Process" , process ).Debug ("Update process" )
84
- warnings , err := actor .V7Actor .UpdateProcessByTypeAndApplication (constant .ProcessTypeWeb , state .Application .GUID , process )
85
- warningsStream <- Warnings (warnings )
86
- if err != nil {
87
- errorStream <- err
88
- return
89
- }
90
- eventStream <- SetProcessConfigurationComplete
91
- }
92
-
93
- eventStream <- CreatingAndMappingRoutes
94
- routeWarnings , routeErr := actor .CreateAndMapDefaultApplicationRoute (state .OrgGUID , state .SpaceGUID , state .Application )
95
- warningsStream <- Warnings (routeWarnings )
96
- if routeErr != nil {
97
- errorStream <- routeErr
33
+ state , err = actor .CreateOrUpdateApplication (state , warningsStream , eventStream )
34
+ if err != nil {
35
+ errorStream <- err
98
36
return
99
37
}
100
- eventStream <- CreatedRoutes
101
-
102
- log .WithField ("Path" , state .BitsPath ).Info (string (CreatingArchive ))
38
+ stateStream <- state
103
39
104
- eventStream <- CreatingArchive
105
- archivePath , err := actor .SharedActor .ZipDirectoryResources (state .BitsPath , state .AllResources )
40
+ err = actor .ScaleProcess (state , warningsStream , eventStream )
106
41
if err != nil {
107
42
errorStream <- err
108
43
return
109
44
}
110
- defer os .RemoveAll (archivePath )
111
45
112
- eventStream <- CreatingPackage
113
- log .WithField ("GUID" , state .Application .GUID ).Info ("creating package" )
114
- pkg , warnings , err := actor .V7Actor .CreateBitsPackageByApplication (state .Application .GUID )
115
- warningsStream <- Warnings (warnings )
46
+ err = actor .UpdateProcess (state , warningsStream , eventStream )
116
47
if err != nil {
117
48
errorStream <- err
118
49
return
119
50
}
120
51
121
- for count := 0 ; count < PushRetries ; count ++ {
122
- eventStream <- ReadingArchive
123
- log .WithField ("GUID" , state .Application .GUID ).Info ("creating package" )
124
- file , size , readErr := actor .SharedActor .ReadArchive (archivePath )
125
- if readErr != nil {
126
- errorStream <- readErr
127
- return
128
- }
129
- defer file .Close ()
130
-
131
- eventStream <- UploadingApplicationWithArchive
132
- progressReader := progressBar .NewProgressBarWrapper (file , size )
133
- pkg , warnings , err = actor .V7Actor .UploadBitsPackage (pkg , state .MatchedResources , progressReader , size )
134
- warningsStream <- Warnings (warnings )
135
-
136
- if _ , ok := err .(ccerror.PipeSeekError ); ok {
137
- eventStream <- RetryUpload
138
- continue
139
- }
140
- break
52
+ eventStream <- CreatingAndMappingRoutes
53
+ routeWarnings , routeErr := actor .CreateAndMapDefaultApplicationRoute (state .OrgGUID , state .SpaceGUID , state .Application )
54
+ warningsStream <- Warnings (routeWarnings )
55
+ if routeErr != nil {
56
+ errorStream <- routeErr
57
+ return
141
58
}
59
+ eventStream <- CreatedRoutes
142
60
61
+ pkg , err := actor .CreatePackage (state , progressBar , warningsStream , eventStream )
143
62
if err != nil {
144
- if e , ok := err .(ccerror.PipeSeekError ); ok {
145
- errorStream <- actionerror.UploadFailedError {Err : e .Err }
146
- return
147
- }
148
63
errorStream <- err
149
64
return
150
65
}
151
66
152
- eventStream <- UploadWithArchiveComplete
153
-
154
67
polledPackage , warnings , err := actor .V7Actor .PollPackage (pkg )
155
68
warningsStream <- Warnings (warnings )
156
69
if err != nil {
@@ -193,3 +106,149 @@ func (actor Actor) Actualize(state PushState, progressBar ProgressBar) (
193
106
}()
194
107
return stateStream , eventStream , warningsStream , errorStream
195
108
}
109
+
110
+ func (actor Actor ) CreateAndUploadApplicationBits (state PushState , progressBar ProgressBar , warningsStream chan Warnings , eventStream chan Event ) (v7action.Package , error ) {
111
+ log .WithField ("Path" , state .BitsPath ).Info (string (CreatingArchive ))
112
+
113
+ eventStream <- CreatingArchive
114
+ archivePath , err := actor .SharedActor .ZipDirectoryResources (state .BitsPath , state .AllResources )
115
+ if err != nil {
116
+ return v7action.Package {}, err
117
+ }
118
+ defer os .RemoveAll (archivePath )
119
+
120
+ eventStream <- CreatingPackage
121
+ log .WithField ("GUID" , state .Application .GUID ).Info ("creating package" )
122
+ pkg , warnings , err := actor .V7Actor .CreateBitsPackageByApplication (state .Application .GUID )
123
+ warningsStream <- Warnings (warnings )
124
+ if err != nil {
125
+ return v7action.Package {}, err
126
+ }
127
+
128
+ // Uploading package/app bits
129
+ for count := 0 ; count < PushRetries ; count ++ {
130
+ eventStream <- ReadingArchive
131
+ log .WithField ("GUID" , state .Application .GUID ).Info ("reading archive" )
132
+ file , size , readErr := actor .SharedActor .ReadArchive (archivePath )
133
+ if readErr != nil {
134
+ return v7action.Package {}, readErr
135
+ }
136
+ defer file .Close ()
137
+
138
+ eventStream <- UploadingApplicationWithArchive
139
+ progressReader := progressBar .NewProgressBarWrapper (file , size )
140
+ pkg , warnings , err = actor .V7Actor .UploadBitsPackage (pkg , state .MatchedResources , progressReader , size )
141
+ warningsStream <- Warnings (warnings )
142
+
143
+ if _ , ok := err .(ccerror.PipeSeekError ); ok {
144
+ eventStream <- RetryUpload
145
+ continue
146
+ }
147
+ break
148
+ }
149
+
150
+ if err != nil {
151
+ if e , ok := err .(ccerror.PipeSeekError ); ok {
152
+ return v7action.Package {}, actionerror.UploadFailedError {Err : e .Err }
153
+ }
154
+ return v7action.Package {}, err
155
+ }
156
+
157
+ eventStream <- UploadWithArchiveComplete
158
+ return pkg , nil
159
+ }
160
+
161
+ func (actor Actor ) CreateOrUpdateApplication (state PushState , warningsStream chan Warnings , eventStream chan Event ) (PushState , error ) {
162
+ if state .Application .GUID == "" { // Create
163
+ log .WithField ("Name" , state .Application .Name ).Info ("creating app" )
164
+ eventStream <- CreatingApplication
165
+
166
+ createdApp , warnings , err := actor .V7Actor .CreateApplicationInSpace (state .Application , state .SpaceGUID )
167
+ state .Application = createdApp
168
+ warningsStream <- Warnings (warnings )
169
+ if err != nil {
170
+ return state , err
171
+ }
172
+
173
+ eventStream <- CreatedApplication
174
+ } else { // Update
175
+ log .WithField ("Name" , state .Application .Name ).Info ("skipping app creation as it has a GUID" )
176
+ eventStream <- SkippingApplicationCreation
177
+
178
+ application , warnings , err := actor .V7Actor .UpdateApplication (state .Application )
179
+ state .Application = application
180
+ warningsStream <- Warnings (warnings )
181
+ if err != nil {
182
+ return state , err
183
+ }
184
+
185
+ eventStream <- UpdatedApplication
186
+ }
187
+
188
+ return state , nil
189
+ }
190
+
191
+ func (actor Actor ) CreatePackage (state PushState , progressBar ProgressBar , warningsStream chan Warnings , eventStream chan Event ) (v7action.Package , error ) {
192
+ if state .Application .LifecycleType == constant .AppLifecycleTypeDocker {
193
+ eventStream <- SetDockerImage
194
+ pkg , warnings , err := actor .V7Actor .CreateDockerPackageByApplication (state .Application .GUID , v7action.DockerImageCredentials {
195
+ Path : state .Overrides .DockerImage ,
196
+ Username : state .Overrides .DockerUsername ,
197
+ Password : state .Overrides .DockerPassword ,
198
+ })
199
+ warningsStream <- Warnings (warnings )
200
+ if err != nil {
201
+ return v7action.Package {}, err
202
+ }
203
+ eventStream <- SetDockerImageComplete
204
+ return pkg , nil
205
+ }
206
+
207
+ return actor .CreateAndUploadApplicationBits (state , progressBar , warningsStream , eventStream )
208
+ }
209
+
210
+ func (actor Actor ) ScaleProcess (state PushState , warningsStream chan Warnings , eventStream chan Event ) error {
211
+ if state .Overrides .Memory .IsSet {
212
+ log .Info ("Scaling Web Process" )
213
+ eventStream <- ScaleWebProcess
214
+
215
+ process := v7action.Process {
216
+ Type : constant .ProcessTypeWeb ,
217
+ MemoryInMB : state .Overrides .Memory ,
218
+ }
219
+ scaleWarnings , err := actor .V7Actor .ScaleProcessByApplication (state .Application .GUID , process )
220
+ warningsStream <- Warnings (scaleWarnings )
221
+ if err != nil {
222
+ return err
223
+ }
224
+ eventStream <- ScaleWebProcessComplete
225
+ }
226
+
227
+ return nil
228
+ }
229
+
230
+ func (actor Actor ) UpdateProcess (state PushState , warningsStream chan Warnings , eventStream chan Event ) error {
231
+ if state .Overrides .StartCommand .IsSet || state .Overrides .HealthCheckType != "" {
232
+ log .Info ("Setting Web Process's Configuration" )
233
+ eventStream <- SetProcessConfiguration
234
+
235
+ var process v7action.Process
236
+ if state .Overrides .StartCommand .IsSet {
237
+ process .Command = state .Overrides .StartCommand
238
+ }
239
+ if state .Overrides .HealthCheckType != "" {
240
+ process .HealthCheckType = state .Overrides .HealthCheckType
241
+ process .HealthCheckEndpoint = constant .ProcessHealthCheckEndpointDefault
242
+ }
243
+
244
+ log .WithField ("Process" , process ).Debug ("Update process" )
245
+ warnings , err := actor .V7Actor .UpdateProcessByTypeAndApplication (constant .ProcessTypeWeb , state .Application .GUID , process )
246
+ warningsStream <- Warnings (warnings )
247
+ if err != nil {
248
+ return err
249
+ }
250
+ eventStream <- SetProcessConfigurationComplete
251
+ }
252
+
253
+ return nil
254
+ }
0 commit comments