forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.go
143 lines (132 loc) · 3.12 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
package models
import (
"reflect"
"strings"
)
type Application struct {
ApplicationFields
Stack *Stack
Routes []RouteSummary
}
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() (params 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,
Memory: &model.Memory,
State: &state,
SpaceGuid: &model.SpaceGuid,
EnvironmentVars: &model.EnvironmentVars,
}
if model.Stack != nil {
params.StackGuid = &model.Stack.Guid
}
return
}
type ApplicationFields struct {
Guid string
Name string
BuildpackUrl string
Command string
DiskQuota int64 // in Megabytes
EnvironmentVars map[string]string
InstanceCount int
Memory int64 // in Megabytes
RunningInstances int
State string
SpaceGuid string
}
type AppParams struct {
BuildpackUrl *string
Command *string
DiskQuota *int64
Domain *string
EnvironmentVars *map[string]string
Guid *string
HealthCheckTimeout *int
Host *string
InstanceCount *int
Memory *int64
Name *string
NoRoute bool
UseRandomHostname bool
Path *string
ServicesToBind *[]string
SpaceGuid *string
StackGuid *string
StackName *string
State *string
}
func (app *AppParams) Merge(other *AppParams) {
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.Domain != nil {
app.Domain = other.Domain
}
if other.EnvironmentVars != nil {
app.EnvironmentVars = other.EnvironmentVars
}
if other.Guid != nil {
app.Guid = other.Guid
}
if other.HealthCheckTimeout != nil {
app.HealthCheckTimeout = other.HealthCheckTimeout
}
if other.Host != nil {
app.Host = other.Host
}
if other.InstanceCount != nil {
app.InstanceCount = other.InstanceCount
}
if other.DiskQuota != nil {
app.DiskQuota = other.DiskQuota
}
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.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
app.UseRandomHostname = app.UseRandomHostname || other.UseRandomHostname
}
func (app *AppParams) IsEmpty() bool {
return reflect.DeepEqual(*app, AppParams{})
}