github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7pushaction/create_droplet_for_application.go (about) 1 package v7pushaction 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/actor/v7action" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 7 ) 8 9 const UploadRetries = 3 10 11 func (actor Actor) CreateDropletForApplication(pushPlan PushPlan, eventStream chan<- *PushEvent, progressBar ProgressBar) (PushPlan, Warnings, error) { 12 var allWarnings Warnings 13 14 eventStream <- &PushEvent{Plan: pushPlan, Event: CreatingDroplet} 15 droplet, warnings, err := actor.V7Actor.CreateApplicationDroplet(pushPlan.Application.GUID) 16 allWarnings = append(allWarnings, warnings...) 17 if err != nil { 18 return pushPlan, allWarnings, err 19 } 20 21 for count := 0; count < UploadRetries; count++ { 22 eventStream <- &PushEvent{Plan: pushPlan, Event: ReadingArchive} 23 file, size, readErr := actor.SharedActor.ReadArchive(pushPlan.DropletPath) 24 if readErr != nil { 25 return pushPlan, allWarnings, readErr 26 } 27 defer file.Close() 28 29 eventStream <- &PushEvent{Plan: pushPlan, Event: UploadingDroplet} 30 progressReader := progressBar.NewProgressBarWrapper(file, size) 31 var uploadWarnings v7action.Warnings 32 uploadWarnings, err = actor.V7Actor.UploadDroplet(droplet.GUID, pushPlan.DropletPath, progressReader, size) 33 allWarnings = append(allWarnings, uploadWarnings...) 34 35 if _, ok := err.(ccerror.PipeSeekError); ok { 36 eventStream <- &PushEvent{Plan: pushPlan, Event: RetryUpload} 37 continue 38 } 39 40 break 41 } 42 43 if err != nil { 44 if e, ok := err.(ccerror.PipeSeekError); ok { 45 return pushPlan, allWarnings, actionerror.UploadFailedError{Err: e.Err} 46 } 47 eventStream <- &PushEvent{Plan: pushPlan, Event: UploadDropletComplete} 48 49 return pushPlan, allWarnings, err 50 } 51 52 eventStream <- &PushEvent{Plan: pushPlan, Event: UploadDropletComplete} 53 pushPlan.DropletGUID = droplet.GUID 54 55 return pushPlan, allWarnings, err 56 }