github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+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 Diego *bool 100 EnableSSH *bool 101 Hosts []string 102 RoutePath *string 103 InstanceCount *int 104 Memory *int64 105 Name *string 106 NoHostname *bool 107 NoRoute bool 108 UseRandomRoute bool 109 UseRandomPort bool 110 Path *string 111 ServicesToBind []string 112 SpaceGUID *string 113 StackGUID *string 114 StackName *string 115 State *string 116 PackageUpdatedAt *time.Time 117 AppPorts *[]int 118 Routes []ManifestRoute 119 } 120 121 func (app *AppParams) Merge(other *AppParams) { 122 if other.AppPorts != nil { 123 app.AppPorts = other.AppPorts 124 } 125 if other.BuildpackURL != nil { 126 app.BuildpackURL = other.BuildpackURL 127 } 128 if other.Command != nil { 129 app.Command = other.Command 130 } 131 if other.DiskQuota != nil { 132 app.DiskQuota = other.DiskQuota 133 } 134 if other.DockerImage != nil { 135 app.DockerImage = other.DockerImage 136 } 137 if other.Domains != nil { 138 app.Domains = other.Domains 139 } 140 if other.EnableSSH != nil { 141 app.EnableSSH = other.EnableSSH 142 } 143 if other.EnvironmentVars != nil { 144 app.EnvironmentVars = other.EnvironmentVars 145 } 146 if other.GUID != nil { 147 app.GUID = other.GUID 148 } 149 if other.HealthCheckType != nil { 150 app.HealthCheckType = other.HealthCheckType 151 } 152 if other.HealthCheckHTTPEndpoint != nil { 153 app.HealthCheckHTTPEndpoint = other.HealthCheckHTTPEndpoint 154 } 155 if other.HealthCheckTimeout != nil { 156 app.HealthCheckTimeout = other.HealthCheckTimeout 157 } 158 if other.Hosts != nil { 159 app.Hosts = other.Hosts 160 } 161 if other.InstanceCount != nil { 162 app.InstanceCount = other.InstanceCount 163 } 164 if other.Memory != nil { 165 app.Memory = other.Memory 166 } 167 if other.Name != nil { 168 app.Name = other.Name 169 } 170 if other.Path != nil { 171 app.Path = other.Path 172 } 173 if other.RoutePath != nil { 174 app.RoutePath = other.RoutePath 175 } 176 if other.ServicesToBind != nil { 177 app.ServicesToBind = other.ServicesToBind 178 } 179 if other.SpaceGUID != nil { 180 app.SpaceGUID = other.SpaceGUID 181 } 182 if other.StackGUID != nil { 183 app.StackGUID = other.StackGUID 184 } 185 if other.StackName != nil { 186 app.StackName = other.StackName 187 } 188 if other.State != nil { 189 app.State = other.State 190 } 191 192 app.NoRoute = app.NoRoute || other.NoRoute 193 noHostBool := app.IsNoHostnameTrue() || other.IsNoHostnameTrue() 194 app.NoHostname = &noHostBool 195 app.UseRandomRoute = app.UseRandomRoute || other.UseRandomRoute 196 } 197 198 func (app *AppParams) IsEmpty() bool { 199 noHostBool := false 200 return reflect.DeepEqual(*app, AppParams{NoHostname: &noHostBool}) 201 } 202 203 func (app *AppParams) IsHostEmpty() bool { 204 return app.Hosts == nil || len(app.Hosts) == 0 205 } 206 207 func (app *AppParams) IsNoHostnameTrue() bool { 208 if app.NoHostname == nil { 209 return false 210 } 211 return *app.NoHostname 212 }