Skip to content

Commit 22f4d8c

Browse files
sweinstein22reidmit
authored andcommitted
Revert "Remove dead code (cloudfoundry#1987)"
This reverts commit 2861621.
1 parent c5238a0 commit 22f4d8c

File tree

646 files changed

+115797
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

646 files changed

+115797
-2
lines changed

actor/pushaction/actor.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Package pushaction contains the business logic for orchestrating a V2 app
2+
// push.
3+
package pushaction
4+
5+
import (
6+
"regexp"
7+
8+
"code.cloudfoundry.org/cli/util/randomword"
9+
)
10+
11+
// Warnings is a list of warnings returned back from the cloud controller
12+
type Warnings []string
13+
14+
// Actor handles all business logic for Cloud Controller v2 operations.
15+
type Actor struct {
16+
SharedActor SharedActor
17+
V2Actor V2Actor
18+
V3Actor V3Actor
19+
WordGenerator RandomWordGenerator
20+
21+
startWithProtocol *regexp.Regexp
22+
urlValidator *regexp.Regexp
23+
}
24+
25+
const ProtocolRegexp = "^https?://|^tcp://"
26+
const URLRegexp = "^(?:https?://|tcp://)?(?:(?:[\\w-]+\\.)|(?:[*]\\.))+\\w+(?:\\:\\d+)?(?:/.*)*(?:\\.\\w+)?$"
27+
28+
// NewActor returns a new actor.
29+
func NewActor(v2Actor V2Actor, v3Actor V3Actor, sharedActor SharedActor) *Actor {
30+
return &Actor{
31+
SharedActor: sharedActor,
32+
V2Actor: v2Actor,
33+
V3Actor: v3Actor,
34+
WordGenerator: randomword.NewGenerator(),
35+
36+
startWithProtocol: regexp.MustCompile(ProtocolRegexp),
37+
urlValidator: regexp.MustCompile(URLRegexp),
38+
}
39+
}

actor/pushaction/actualize.go

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package pushaction
2+
3+
import (
4+
"os"
5+
6+
"code.cloudfoundry.org/cli/actor/actionerror"
7+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
8+
log "github.com/sirupsen/logrus"
9+
)
10+
11+
func (actor Actor) Actualize(state PushPlan, progressBar ProgressBar) (
12+
<-chan PushPlan, <-chan Event, <-chan Warnings, <-chan error,
13+
) {
14+
log.Debugf("Starting to Actualize Push plan: %#v\n", state)
15+
stateStream := make(chan PushPlan)
16+
eventStream := make(chan Event)
17+
warningsStream := make(chan Warnings)
18+
errorStream := make(chan error)
19+
20+
go func() {
21+
log.Debug("starting actualize go routine")
22+
defer close(stateStream)
23+
defer close(eventStream)
24+
defer close(warningsStream)
25+
defer close(errorStream)
26+
27+
if state.Application.GUID != "" {
28+
log.WithField("Name", state.Application.Name).Info("skipping app creation as it has a GUID")
29+
eventStream <- SkippingApplicationCreation
30+
} else {
31+
log.WithField("Name", state.Application.Name).Info("creating app")
32+
createdApp, createWarnings, err := actor.V3Actor.CreateApplicationInSpace(state.Application, state.SpaceGUID)
33+
warningsStream <- Warnings(createWarnings)
34+
if err != nil {
35+
errorStream <- err
36+
return
37+
}
38+
39+
state.Application = createdApp
40+
eventStream <- CreatedApplication
41+
}
42+
stateStream <- state
43+
44+
log.WithField("Path", state.BitsPath).Info(string(CreatingArchive))
45+
46+
eventStream <- CreatingArchive
47+
archivePath, err := actor.SharedActor.ZipDirectoryResources(state.BitsPath, state.AllResources)
48+
if err != nil {
49+
errorStream <- err
50+
return
51+
}
52+
defer os.RemoveAll(archivePath)
53+
54+
eventStream <- CreatingPackage
55+
log.WithField("GUID", state.Application.GUID).Info("creating package")
56+
pkg, warnings, err := actor.V3Actor.CreateBitsPackageByApplication(state.Application.GUID)
57+
warningsStream <- Warnings(warnings)
58+
if err != nil {
59+
errorStream <- err
60+
return
61+
}
62+
63+
for count := 0; count < PushRetries; count++ {
64+
eventStream <- ReadingArchive
65+
log.WithField("GUID", state.Application.GUID).Info("creating package")
66+
file, size, readErr := actor.SharedActor.ReadArchive(archivePath)
67+
if readErr != nil {
68+
errorStream <- readErr
69+
return
70+
}
71+
defer file.Close()
72+
73+
eventStream <- UploadingApplicationWithArchive
74+
progressReader := progressBar.NewProgressBarWrapper(file, size)
75+
pkg, warnings, err = actor.V3Actor.UploadBitsPackage(pkg, state.MatchedResources, progressReader, size)
76+
warningsStream <- Warnings(warnings)
77+
78+
if _, ok := err.(ccerror.PipeSeekError); ok {
79+
eventStream <- RetryUpload
80+
continue
81+
}
82+
break
83+
}
84+
85+
if err != nil {
86+
if e, ok := err.(ccerror.PipeSeekError); ok {
87+
errorStream <- actionerror.UploadFailedError{Err: e.Err}
88+
return
89+
}
90+
errorStream <- err
91+
return
92+
}
93+
94+
eventStream <- UploadWithArchiveComplete
95+
96+
polledPackage, warnings, err := actor.V3Actor.PollPackage(pkg)
97+
warningsStream <- Warnings(warnings)
98+
if err != nil {
99+
errorStream <- err
100+
return
101+
}
102+
103+
eventStream <- StartingStaging
104+
105+
build, warnings, err := actor.V3Actor.StageApplicationPackage(polledPackage.GUID)
106+
warningsStream <- Warnings(warnings)
107+
if err != nil {
108+
errorStream <- err
109+
return
110+
}
111+
112+
eventStream <- PollingBuild
113+
114+
droplet, warnings, err := actor.V3Actor.PollBuild(build.GUID, state.Application.Name)
115+
warningsStream <- Warnings(warnings)
116+
if err != nil {
117+
errorStream <- err
118+
return
119+
}
120+
121+
eventStream <- StagingComplete
122+
eventStream <- SettingDroplet
123+
124+
warnings, err = actor.V3Actor.SetApplicationDroplet(state.Application.GUID, droplet.GUID)
125+
warningsStream <- Warnings(warnings)
126+
if err != nil {
127+
errorStream <- err
128+
return
129+
}
130+
131+
eventStream <- SetDropletComplete
132+
133+
log.Debug("completed apply")
134+
eventStream <- Complete
135+
}()
136+
return stateStream, eventStream, warningsStream, errorStream
137+
}

0 commit comments

Comments
 (0)