forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.go
212 lines (198 loc) · 5.36 KB
/
application.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package models
import (
"reflect"
"strings"
"time"
)
type Application struct {
ApplicationFields
Stack *Stack
Routes []RouteSummary
Services []ServicePlanSummary
}
func (model Application) HasRoute(route Route) bool {
for _, boundRoute := range model.Routes {
if boundRoute.GUID == route.GUID {
return true
}
}
return false
}
func (model Application) ToParams() AppParams {
state := strings.ToUpper(model.State)
params := AppParams{
GUID: &model.GUID,
Name: &model.Name,
BuildpackURL: &model.BuildpackURL,
Command: &model.Command,
DiskQuota: &model.DiskQuota,
InstanceCount: &model.InstanceCount,
HealthCheckType: &model.HealthCheckType,
HealthCheckHTTPEndpoint: &model.HealthCheckHTTPEndpoint,
Memory: &model.Memory,
State: &state,
SpaceGUID: &model.SpaceGUID,
EnvironmentVars: &model.EnvironmentVars,
DockerImage: &model.DockerImage,
}
if model.Stack != nil {
params.StackGUID = &model.Stack.GUID
}
return params
}
type ApplicationFields struct {
GUID string
Name string
BuildpackURL string
Command string
Diego bool
DetectedStartCommand string
DiskQuota int64 // in Megabytes
EnvironmentVars map[string]interface{}
InstanceCount int
Memory int64 // in Megabytes
RunningInstances int
HealthCheckType string
HealthCheckHTTPEndpoint string
HealthCheckTimeout int
State string
SpaceGUID string
StackGUID string
PackageUpdatedAt *time.Time
PackageState string
StagingFailedReason string
Buildpack string
DetectedBuildpack string
DockerImage string
EnableSSH bool
AppPorts []int
}
const (
ApplicationStateStopped = "stopped"
ApplicationStateStarted = "started"
ApplicationStateRunning = "running"
ApplicationStateCrashed = "crashed"
ApplicationStateFlapping = "flapping"
ApplicationStateDown = "down"
ApplicationStateStarting = "starting"
)
type AppParams struct {
BuildpackURL *string
Command *string
DiskQuota *int64
Domains []string
EnvironmentVars *map[string]interface{}
GUID *string
HealthCheckType *string
HealthCheckHTTPEndpoint *string
HealthCheckTimeout *int
DockerImage *string
Diego *bool
EnableSSH *bool
Hosts []string
RoutePath *string
InstanceCount *int
Memory *int64
Name *string
NoHostname *bool
NoRoute bool
UseRandomRoute bool
UseRandomPort bool
Path *string
ServicesToBind []string
SpaceGUID *string
StackGUID *string
StackName *string
State *string
PackageUpdatedAt *time.Time
AppPorts *[]int
Routes []ManifestRoute
}
func (app *AppParams) Merge(other *AppParams) {
if other.AppPorts != nil {
app.AppPorts = other.AppPorts
}
if other.BuildpackURL != nil {
app.BuildpackURL = other.BuildpackURL
}
if other.Command != nil {
app.Command = other.Command
}
if other.DiskQuota != nil {
app.DiskQuota = other.DiskQuota
}
if other.DockerImage != nil {
app.DockerImage = other.DockerImage
}
if other.Domains != nil {
app.Domains = other.Domains
}
if other.EnableSSH != nil {
app.EnableSSH = other.EnableSSH
}
if other.EnvironmentVars != nil {
app.EnvironmentVars = other.EnvironmentVars
}
if other.GUID != nil {
app.GUID = other.GUID
}
if other.HealthCheckType != nil {
app.HealthCheckType = other.HealthCheckType
}
if other.HealthCheckHTTPEndpoint != nil {
app.HealthCheckHTTPEndpoint = other.HealthCheckHTTPEndpoint
}
if other.HealthCheckTimeout != nil {
app.HealthCheckTimeout = other.HealthCheckTimeout
}
if other.Hosts != nil {
app.Hosts = other.Hosts
}
if other.InstanceCount != nil {
app.InstanceCount = other.InstanceCount
}
if other.Memory != nil {
app.Memory = other.Memory
}
if other.Name != nil {
app.Name = other.Name
}
if other.Path != nil {
app.Path = other.Path
}
if other.RoutePath != nil {
app.RoutePath = other.RoutePath
}
if other.ServicesToBind != nil {
app.ServicesToBind = other.ServicesToBind
}
if other.SpaceGUID != nil {
app.SpaceGUID = other.SpaceGUID
}
if other.StackGUID != nil {
app.StackGUID = other.StackGUID
}
if other.StackName != nil {
app.StackName = other.StackName
}
if other.State != nil {
app.State = other.State
}
app.NoRoute = app.NoRoute || other.NoRoute
noHostBool := app.IsNoHostnameTrue() || other.IsNoHostnameTrue()
app.NoHostname = &noHostBool
app.UseRandomRoute = app.UseRandomRoute || other.UseRandomRoute
}
func (app *AppParams) IsEmpty() bool {
noHostBool := false
return reflect.DeepEqual(*app, AppParams{NoHostname: &noHostBool})
}
func (app *AppParams) IsHostEmpty() bool {
return app.Hosts == nil || len(app.Hosts) == 0
}
func (app *AppParams) IsNoHostnameTrue() bool {
if app.NoHostname == nil {
return false
}
return *app.NoHostname
}