github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/cf/models/application.go (about) 1 package models 2 3 import ( 4 "reflect" 5 "strings" 6 "time" 7 ) 8 9 type Application struct { 10 ApplicationFields 11 Stack *Stack 12 Routes []RouteSummary 13 Services []ServicePlanSummary 14 } 15 16 func (model Application) HasRoute(route Route) bool { 17 for _, boundRoute := range model.Routes { 18 if boundRoute.GUID == route.GUID { 19 return true 20 } 21 } 22 return false 23 } 24 25 func (model Application) ToParams() AppParams { 26 state := strings.ToUpper(model.State) 27 params := AppParams{ 28 GUID: &model.GUID, 29 Name: &model.Name, 30 BuildpackURL: &model.BuildpackURL, 31 Command: &model.Command, 32 DiskQuota: &model.DiskQuota, 33 InstanceCount: &model.InstanceCount, 34 HealthCheckType: &model.HealthCheckType, 35 HealthCheckHTTPEndpoint: &model.HealthCheckHTTPEndpoint, 36 Memory: &model.Memory, 37 State: &state, 38 SpaceGUID: &model.SpaceGUID, 39 EnvironmentVars: &model.EnvironmentVars, 40 DockerImage: &model.DockerImage, 41 } 42 43 if model.Stack != nil { 44 params.StackGUID = &model.Stack.GUID 45 } 46 47 return params 48 } 49 50 type ApplicationFields struct { 51 GUID string 52 Name string 53 BuildpackURL string 54 Command string 55 Diego bool 56 DetectedStartCommand string 57 DiskQuota int64 // in Megabytes 58 EnvironmentVars map[string]interface{} 59 InstanceCount int 60 Memory int64 // in Megabytes 61 RunningInstances int 62 HealthCheckType string 63 HealthCheckHTTPEndpoint string 64 HealthCheckTimeout int 65 State string 66 SpaceGUID string 67 StackGUID string 68 PackageUpdatedAt *time.Time 69 PackageState string 70 StagingFailedReason string 71 Buildpack string 72 DetectedBuildpack string 73 DockerImage string 74 EnableSSH bool 75 AppPorts []int 76 } 77 78 const ( 79 ApplicationStateStopped = "stopped" 80 ApplicationStateStarted = "started" 81 ApplicationStateRunning = "running" 82 ApplicationStateCrashed = "crashed" 83 ApplicationStateFlapping = "flapping" 84 ApplicationStateDown = "down" 85 ApplicationStateStarting = "starting" 86 ) 87 88 type AppParams struct { 89 BuildpackURL *string 90 Command *string 91 DiskQuota *int64 92 Domains []string 93 EnvironmentVars *map[string]interface{} 94 GUID *string 95 HealthCheckType *string 96 HealthCheckHTTPEndpoint *string 97 HealthCheckTimeout *int 98 DockerImage *string 99 DockerUsername *string 100 DockerPassword *string 101 Diego *bool 102 EnableSSH *bool 103 Hosts []string 104 RoutePath *string 105 InstanceCount *int 106 Memory *int64 107 Name *string 108 NoHostname *bool 109 NoRoute bool 110 UseRandomRoute bool 111 UseRandomPort bool 112 Path *string 113 ServicesToBind []string 114 SpaceGUID *string 115 StackGUID *string 116 StackName *string 117 State *string 118 PackageUpdatedAt *time.Time 119 AppPorts *[]int 120 Routes []ManifestRoute 121 } 122 123 func (app *AppParams) Merge(other *AppParams) { 124 if other.AppPorts != nil { 125 app.AppPorts = other.AppPorts 126 } 127 if other.BuildpackURL != nil { 128 app.BuildpackURL = other.BuildpackURL 129 } 130 if other.Command != nil { 131 app.Command = other.Command 132 } 133 if other.DiskQuota != nil { 134 app.DiskQuota = other.DiskQuota 135 } 136 if other.DockerImage != nil { 137 app.DockerImage = other.DockerImage 138 } 139 if other.DockerUsername != nil { 140 app.DockerUsername = other.DockerUsername 141 } 142 if other.DockerPassword != nil { 143 app.DockerPassword = other.DockerPassword 144 } 145 if other.Domains != nil { 146 app.Domains = other.Domains 147 } 148 if other.EnableSSH != nil { 149 app.EnableSSH = other.EnableSSH 150 } 151 if other.EnvironmentVars != nil { 152 app.EnvironmentVars = other.EnvironmentVars 153 } 154 if other.GUID != nil { 155 app.GUID = other.GUID 156 } 157 if other.HealthCheckType != nil { 158 app.HealthCheckType = other.HealthCheckType 159 } 160 if other.HealthCheckHTTPEndpoint != nil { 161 app.HealthCheckHTTPEndpoint = other.HealthCheckHTTPEndpoint 162 } 163 if other.HealthCheckTimeout != nil { 164 app.HealthCheckTimeout = other.HealthCheckTimeout 165 } 166 if other.Hosts != nil { 167 app.Hosts = other.Hosts 168 } 169 if other.InstanceCount != nil { 170 app.InstanceCount = other.InstanceCount 171 } 172 if other.Memory != nil { 173 app.Memory = other.Memory 174 } 175 if other.Name != nil { 176 app.Name = other.Name 177 } 178 if other.Path != nil { 179 app.Path = other.Path 180 } 181 if other.RoutePath != nil { 182 app.RoutePath = other.RoutePath 183 } 184 if other.ServicesToBind != nil { 185 app.ServicesToBind = other.ServicesToBind 186 } 187 if other.SpaceGUID != nil { 188 app.SpaceGUID = other.SpaceGUID 189 } 190 if other.StackGUID != nil { 191 app.StackGUID = other.StackGUID 192 } 193 if other.StackName != nil { 194 app.StackName = other.StackName 195 } 196 if other.State != nil { 197 app.State = other.State 198 } 199 200 app.NoRoute = app.NoRoute || other.NoRoute 201 noHostBool := app.IsNoHostnameTrue() || other.IsNoHostnameTrue() 202 app.NoHostname = &noHostBool 203 app.UseRandomRoute = app.UseRandomRoute || other.UseRandomRoute 204 } 205 206 func (app *AppParams) IsEmpty() bool { 207 noHostBool := false 208 return reflect.DeepEqual(*app, AppParams{NoHostname: &noHostBool}) 209 } 210 211 func (app *AppParams) IsHostEmpty() bool { 212 return app.Hosts == nil || len(app.Hosts) == 0 213 } 214 215 func (app *AppParams) IsNoHostnameTrue() bool { 216 if app.NoHostname == nil { 217 return false 218 } 219 return *app.NoHostname 220 }