Skip to content

Commit b8351b6

Browse files
committed
use NullByteSizeInMb for Disk Quota and Memory
[#151060145]
1 parent 05836b4 commit b8351b6

16 files changed

+83
-79
lines changed

actor/pushaction/application_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ func (Actor) overrideApplicationProperties(application Application, manifest man
238238
}
239239

240240
if manifest.DiskQuota.IsSet {
241-
application.DiskQuota = manifest.DiskQuota.Value
241+
application.DiskQuota = manifest.DiskQuota
242242
}
243243

244244
if manifest.Memory.IsSet {
245-
application.Memory = manifest.Memory.Value
245+
application.Memory = manifest.Memory
246246
}
247247

248248
if manifest.HealthCheckTimeout != 0 {

actor/pushaction/application_config_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ var _ = Describe("Application Config", func() {
463463
}))
464464
Expect(firstConfig.DesiredApplication.HealthCheckTimeout).To(Equal(5))
465465
Expect(firstConfig.DesiredApplication.Instances).To(Equal(types.NullInt{Value: 1, IsSet: true}))
466-
Expect(firstConfig.DesiredApplication.DiskQuota).To(BeNumerically("==", 2))
467-
Expect(firstConfig.DesiredApplication.Memory).To(BeNumerically("==", 3))
466+
Expect(firstConfig.DesiredApplication.DiskQuota).To(Equal(types.NullByteSizeInMb{IsSet: true, Value: 2}))
467+
Expect(firstConfig.DesiredApplication.Memory).To(Equal(types.NullByteSizeInMb{IsSet: true, Value: 3}))
468468
Expect(firstConfig.DesiredApplication.StackGUID).To(Equal("some-stack-guid"))
469469
Expect(firstConfig.DesiredApplication.Stack).To(Equal(stack))
470470

@@ -489,7 +489,7 @@ var _ = Describe("Application Config", func() {
489489
Password: "some-docker-password",
490490
},
491491
DockerImage: "some-docker-image",
492-
DiskQuota: 2,
492+
DiskQuota: types.NullByteSizeInMb{IsSet: true, Value: 2},
493493
EnvironmentVariables: map[string]string{
494494
"env2": "2",
495495
"env3": "9",
@@ -499,7 +499,7 @@ var _ = Describe("Application Config", func() {
499499
HealthCheckTimeout: 5,
500500
HealthCheckType: "port",
501501
Instances: types.NullInt{Value: 3, IsSet: true},
502-
Memory: 3,
502+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 3},
503503
Name: appName,
504504
StackGUID: stack.GUID,
505505
}
@@ -520,8 +520,8 @@ var _ = Describe("Application Config", func() {
520520
Expect(firstConfig.DesiredApplication.HealthCheckTimeout).To(Equal(5))
521521
Expect(firstConfig.DesiredApplication.HealthCheckType).To(Equal(constant.ApplicationHealthCheckPort))
522522
Expect(firstConfig.DesiredApplication.Instances).To(Equal(types.NullInt{Value: 3, IsSet: true}))
523-
Expect(firstConfig.DesiredApplication.DiskQuota).To(BeNumerically("==", 2))
524-
Expect(firstConfig.DesiredApplication.Memory).To(BeNumerically("==", 3))
523+
Expect(firstConfig.DesiredApplication.DiskQuota).To(Equal(types.NullByteSizeInMb{IsSet: true, Value: 2}))
524+
Expect(firstConfig.DesiredApplication.Memory).To(Equal(types.NullByteSizeInMb{IsSet: true, Value: 3}))
525525
Expect(firstConfig.DesiredApplication.StackGUID).To(Equal("some-stack-guid"))
526526
Expect(firstConfig.DesiredApplication.Stack).To(Equal(stack))
527527
})

actor/v2action/application.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ func (application Application) String() string {
9797
application.DetectedBuildpack.Value,
9898
application.DetectedStartCommand.IsSet,
9999
application.DetectedStartCommand.Value,
100-
application.DiskQuota,
100+
application.DiskQuota.Value,
101101
application.DockerImage,
102102
application.HealthCheckHTTPEndpoint,
103103
application.HealthCheckTimeout,
104104
application.HealthCheckType,
105105
application.Instances.IsSet,
106106
application.Instances.Value,
107-
application.Memory,
107+
application.Memory.Value,
108108
application.SpaceGUID,
109109
application.StackGUID,
110110
application.State,

actor/v2action/manifest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ func (actor Actor) CreateApplicationManifestByNameAndSpace(appName string, space
3333
manifestApp := manifest.Application{
3434
Buildpack: applicationSummary.Buildpack,
3535
Command: applicationSummary.Command,
36+
DiskQuota: applicationSummary.DiskQuota,
3637
DockerImage: applicationSummary.DockerImage,
3738
DockerUsername: applicationSummary.DockerCredentials.Username,
3839
EnvironmentVariables: applicationSummary.EnvironmentVariables,
3940
HealthCheckTimeout: applicationSummary.HealthCheckTimeout,
4041
Instances: applicationSummary.Instances,
42+
Memory: applicationSummary.Memory,
4143
Name: applicationSummary.Name,
4244
Routes: routes,
4345
Services: services,
4446
StackName: applicationSummary.Stack.Name,
4547
}
46-
manifestApp.DiskQuota.ParseUint64Value(&applicationSummary.DiskQuota)
47-
manifestApp.Memory.ParseUint64Value(&applicationSummary.Memory)
4848
if len(routes) < 1 {
4949
manifestApp.NoRoute = true
5050
}

actor/v2action/manifest_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var _ = Describe("Manifest Actions", func() {
6262
IsSet: true,
6363
Value: "some-detected-buildpack",
6464
},
65+
DiskQuota: types.NullByteSizeInMb{IsSet: true, Value: 1024},
6566
DockerImage: "some-docker-image",
6667
DockerCredentials: ccv2.DockerCredentials{
6768
Username: "some-docker-username",
@@ -88,8 +89,7 @@ var _ = Describe("Manifest Actions", func() {
8889
Value: 10,
8990
IsSet: true,
9091
},
91-
DiskQuota: 1024,
92-
Memory: 200,
92+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 200},
9393
StackGUID: "some-stack-guid",
9494
}
9595

api/cloudcontroller/ccv2/application.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Application struct {
4646
DetectedStartCommand types.FilteredString
4747

4848
// DiskQuota is the disk given to each instance, in megabytes.
49-
DiskQuota uint64
49+
DiskQuota types.NullByteSizeInMb
5050

5151
// DockerCredentials is the authentication information for the provided
5252
// DockerImage.
@@ -75,7 +75,7 @@ type Application struct {
7575
Instances types.NullInt
7676

7777
// Memory is the memory given to each instance, in megabytes.
78-
Memory uint64
78+
Memory types.NullByteSizeInMb
7979

8080
// Name is the name given to the application.
8181
Name string
@@ -119,26 +119,24 @@ func (application Application) MarshalJSON() ([]byte, error) {
119119
ccApp := struct {
120120
Buildpack *string `json:"buildpack,omitempty"`
121121
Command *string `json:"command,omitempty"`
122-
DiskQuota uint64 `json:"disk_quota,omitempty"`
122+
DiskQuota *uint64 `json:"disk_quota,omitempty"`
123123
DockerCredentials *DockerCredentials `json:"docker_credentials,omitempty"`
124124
DockerImage string `json:"docker_image,omitempty"`
125125
EnvironmentVariables map[string]string `json:"environment_json,omitempty"`
126126
HealthCheckHTTPEndpoint *string `json:"health_check_http_endpoint,omitempty"`
127127
HealthCheckTimeout int `json:"health_check_timeout,omitempty"`
128128
HealthCheckType constant.ApplicationHealthCheckType `json:"health_check_type,omitempty"`
129129
Instances *int `json:"instances,omitempty"`
130-
Memory uint64 `json:"memory,omitempty"`
130+
Memory *uint64 `json:"memory,omitempty"`
131131
Name string `json:"name,omitempty"`
132132
SpaceGUID string `json:"space_guid,omitempty"`
133133
StackGUID string `json:"stack_guid,omitempty"`
134134
State ApplicationState `json:"state,omitempty"`
135135
}{
136-
DiskQuota: application.DiskQuota,
137136
DockerImage: application.DockerImage,
138137
EnvironmentVariables: application.EnvironmentVariables,
139138
HealthCheckTimeout: application.HealthCheckTimeout,
140139
HealthCheckType: application.HealthCheckType,
141-
Memory: application.Memory,
142140
Name: application.Name,
143141
SpaceGUID: application.SpaceGUID,
144142
StackGUID: application.StackGUID,
@@ -153,6 +151,10 @@ func (application Application) MarshalJSON() ([]byte, error) {
153151
ccApp.Command = &application.Command.Value
154152
}
155153

154+
if application.DiskQuota.IsSet {
155+
ccApp.DiskQuota = &application.DiskQuota.Value
156+
}
157+
156158
if application.DockerCredentials.Username != "" || application.DockerCredentials.Password != "" {
157159
ccApp.DockerCredentials = &DockerCredentials{
158160
Username: application.DockerCredentials.Username,
@@ -168,6 +170,10 @@ func (application Application) MarshalJSON() ([]byte, error) {
168170
ccApp.HealthCheckHTTPEndpoint = &application.HealthCheckHTTPEndpoint
169171
}
170172

173+
if application.Memory.IsSet {
174+
ccApp.Memory = &application.Memory.Value
175+
}
176+
171177
return json.Marshal(ccApp)
172178
}
173179

@@ -180,7 +186,7 @@ func (application *Application) UnmarshalJSON(data []byte) error {
180186
Command string `json:"command"`
181187
DetectedBuildpack string `json:"detected_buildpack"`
182188
DetectedStartCommand string `json:"detected_start_command"`
183-
DiskQuota uint64 `json:"disk_quota"`
189+
DiskQuota *uint64 `json:"disk_quota"`
184190
DockerImage string `json:"docker_image"`
185191
DockerCredentials DockerCredentials `json:"docker_credentials"`
186192
// EnvironmentVariables' values can be any type, so we must accept
@@ -190,7 +196,7 @@ func (application *Application) UnmarshalJSON(data []byte) error {
190196
HealthCheckTimeout int `json:"health_check_timeout"`
191197
HealthCheckType string `json:"health_check_type"`
192198
Instances json.Number `json:"instances"`
193-
Memory uint64 `json:"memory"`
199+
Memory *uint64 `json:"memory"`
194200
Name string `json:"name"`
195201
PackageState string `json:"package_state"`
196202
PackageUpdatedAt *time.Time `json:"package_updated_at"`
@@ -208,27 +214,25 @@ func (application *Application) UnmarshalJSON(data []byte) error {
208214
return err
209215
}
210216

211-
application.DiskQuota = ccApp.Entity.DiskQuota
212-
application.DockerImage = ccApp.Entity.DockerImage
217+
application.Buildpack.ParseValue(ccApp.Entity.Buildpack)
218+
application.Command.ParseValue(ccApp.Entity.Command)
219+
application.DetectedBuildpack.ParseValue(ccApp.Entity.DetectedBuildpack)
220+
application.DetectedStartCommand.ParseValue(ccApp.Entity.DetectedStartCommand)
221+
application.DiskQuota.ParseUint64Value(ccApp.Entity.DiskQuota)
213222
application.DockerCredentials = ccApp.Entity.DockerCredentials
223+
application.DockerImage = ccApp.Entity.DockerImage
214224
application.GUID = ccApp.Metadata.GUID
215225
application.HealthCheckHTTPEndpoint = ccApp.Entity.HealthCheckHTTPEndpoint
216226
application.HealthCheckTimeout = ccApp.Entity.HealthCheckTimeout
217227
application.HealthCheckType = constant.ApplicationHealthCheckType(ccApp.Entity.HealthCheckType)
218-
application.Memory = ccApp.Entity.Memory
228+
application.Memory.ParseUint64Value(ccApp.Entity.Memory)
219229
application.Name = ccApp.Entity.Name
220230
application.PackageState = ApplicationPackageState(ccApp.Entity.PackageState)
221231
application.StackGUID = ccApp.Entity.StackGUID
222232
application.StagingFailedDescription = ccApp.Entity.StagingFailedDescription
223233
application.StagingFailedReason = ccApp.Entity.StagingFailedReason
224234
application.State = ApplicationState(ccApp.Entity.State)
225235

226-
application.Buildpack.ParseValue(ccApp.Entity.Buildpack)
227-
application.DetectedBuildpack.ParseValue(ccApp.Entity.DetectedBuildpack)
228-
229-
application.Command.ParseValue(ccApp.Entity.Command)
230-
application.DetectedStartCommand.ParseValue(ccApp.Entity.DetectedStartCommand)
231-
232236
if len(ccApp.Entity.EnvironmentVariables) > 0 {
233237
envVariableValues := map[string]string{}
234238
for key, value := range ccApp.Entity.EnvironmentVariables {

api/cloudcontroller/ccv2/application_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ var _ = Describe("Application", func() {
146146
Command: types.FilteredString{IsSet: true, Value: "some-command"},
147147
DetectedBuildpack: types.FilteredString{},
148148
DetectedStartCommand: types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
149-
DiskQuota: 586,
149+
DiskQuota: types.NullByteSizeInMb{IsSet: true, Value: 586},
150150
DockerCredentials: DockerCredentials{
151151
Username: "docker-username",
152152
Password: "docker-password",
@@ -163,7 +163,7 @@ var _ = Describe("Application", func() {
163163
HealthCheckType: "port",
164164
HealthCheckHTTPEndpoint: "/",
165165
Instances: types.NullInt{Value: 13, IsSet: true},
166-
Memory: 1024,
166+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 1024},
167167
Name: "app-name-1",
168168
PackageState: ApplicationPackageFailed,
169169
PackageUpdatedAt: updatedAt,
@@ -271,12 +271,12 @@ var _ = Describe("Application", func() {
271271
Buildpack: types.FilteredString{IsSet: true, Value: "ruby 1.6.29"},
272272
DetectedBuildpack: types.FilteredString{},
273273
DetectedStartCommand: types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
274-
DiskQuota: 586,
274+
DiskQuota: types.NullByteSizeInMb{IsSet: true, Value: 586},
275275
GUID: "app-guid-1",
276276
HealthCheckType: "port",
277277
HealthCheckHTTPEndpoint: "/",
278278
Instances: types.NullInt{Value: 13, IsSet: true},
279-
Memory: 1024,
279+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 1024},
280280
Name: "app-name-1",
281281
PackageState: ApplicationPackageFailed,
282282
PackageUpdatedAt: updatedAt,
@@ -335,7 +335,7 @@ var _ = Describe("Application", func() {
335335
expectedBody := map[string]interface{}{
336336
"buildpack": "",
337337
"command": "",
338-
"disk_quota": 586,
338+
"disk_quota": 0,
339339
"docker_credentials": map[string]string{
340340
"username": "docker-username",
341341
"password": "docker-password",
@@ -350,7 +350,7 @@ var _ = Describe("Application", func() {
350350
"health_check_http_endpoint": "/anything",
351351
"health_check_type": "some-health-check-type",
352352
"instances": 0,
353-
"memory": 1024,
353+
"memory": 0,
354354
"stack_guid": "some-stack-guid",
355355
"state": "STARTED",
356356
}
@@ -368,7 +368,7 @@ var _ = Describe("Application", func() {
368368
app, warnings, err := client.UpdateApplication(Application{
369369
Buildpack: types.FilteredString{IsSet: true, Value: ""},
370370
Command: types.FilteredString{IsSet: true, Value: ""},
371-
DiskQuota: 586,
371+
DiskQuota: types.NullByteSizeInMb{IsSet: true},
372372
DockerCredentials: DockerCredentials{
373373
Username: "docker-username",
374374
Password: "docker-password",
@@ -384,7 +384,7 @@ var _ = Describe("Application", func() {
384384
HealthCheckHTTPEndpoint: "/anything",
385385
HealthCheckType: "some-health-check-type",
386386
Instances: types.NullInt{Value: 0, IsSet: true},
387-
Memory: 1024,
387+
Memory: types.NullByteSizeInMb{IsSet: true},
388388
StackGUID: "some-stack-guid",
389389
State: ApplicationStarted,
390390
})
@@ -396,7 +396,7 @@ var _ = Describe("Application", func() {
396396
Expect(app).To(Equal(Application{
397397
DetectedBuildpack: types.FilteredString{},
398398
DetectedStartCommand: types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
399-
DiskQuota: 586,
399+
DiskQuota: types.NullByteSizeInMb{IsSet: true, Value: 586},
400400
DockerCredentials: DockerCredentials{
401401
Username: "docker-username",
402402
Password: "docker-password",
@@ -413,7 +413,7 @@ var _ = Describe("Application", func() {
413413
HealthCheckTimeout: 120,
414414
HealthCheckType: "some-health-check-type",
415415
Instances: types.NullInt{Value: 0, IsSet: true},
416-
Memory: 1024,
416+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 1024},
417417
Name: "app-name-1",
418418
PackageUpdatedAt: updatedAt,
419419
StackGUID: "some-stack-guid",
@@ -468,12 +468,12 @@ var _ = Describe("Application", func() {
468468
Buildpack: types.FilteredString{IsSet: true, Value: "ruby 1.6.29"},
469469
DetectedBuildpack: types.FilteredString{},
470470
DetectedStartCommand: types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
471-
DiskQuota: 586,
471+
DiskQuota: types.NullByteSizeInMb{IsSet: true, Value: 586},
472472
GUID: "some-app-guid",
473473
HealthCheckType: "some-health-check-type",
474474
HealthCheckHTTPEndpoint: "/",
475475
Instances: types.NullInt{Value: 7, IsSet: true},
476-
Memory: 1024,
476+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 1024},
477477
Name: "app-name-1",
478478
PackageUpdatedAt: updatedAt,
479479
StackGUID: "some-stack-guid",
@@ -563,13 +563,13 @@ var _ = Describe("Application", func() {
563563
Buildpack: types.FilteredString{IsSet: true, Value: "ruby 1.6.29"},
564564
DetectedBuildpack: types.FilteredString{},
565565
DetectedStartCommand: types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
566-
DiskQuota: 586,
566+
DiskQuota: types.NullByteSizeInMb{IsSet: true, Value: 586},
567567
DockerImage: "some-docker-path",
568568
GUID: "some-app-guid",
569569
HealthCheckType: "some-health-check-type",
570570
HealthCheckHTTPEndpoint: "/anything",
571571
Instances: types.NullInt{Value: 13, IsSet: true},
572-
Memory: 1024,
572+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 1024},
573573
Name: "app-name-1",
574574
PackageUpdatedAt: updatedAt,
575575
StackGUID: "some-stack-guid",

command/v2/app_command_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ var _ = Describe("App Command", func() {
174174
Name: "some-app",
175175
GUID: "some-app-guid",
176176
Instances: types.NullInt{Value: 3, IsSet: true},
177-
Memory: 128,
177+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 128},
178178
PackageUpdatedAt: time.Unix(0, 0),
179179
DetectedBuildpack: types.FilteredString{IsSet: true, Value: "some-buildpack"},
180180
State: "STARTED",
@@ -368,7 +368,7 @@ var _ = Describe("App Command", func() {
368368
Name: "some-app",
369369
GUID: "some-app-guid",
370370
Instances: types.NullInt{Value: 3, IsSet: true},
371-
Memory: 128,
371+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 128},
372372
PackageUpdatedAt: time.Unix(0, 0),
373373
State: "STARTED",
374374
DockerImage: "some-docker-image",

command/v2/restage_command_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ var _ = Describe("Restage Command", func() {
258258
Name: "some-app",
259259
GUID: "some-app-guid",
260260
Instances: types.NullInt{Value: 3, IsSet: true},
261-
Memory: 128,
261+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 128},
262262
PackageUpdatedAt: time.Unix(0, 0),
263263
DetectedBuildpack: types.FilteredString{IsSet: true, Value: "some-buildpack"},
264264
State: "STARTED",
@@ -497,7 +497,7 @@ var _ = Describe("Restage Command", func() {
497497
Name: "some-app",
498498
GUID: "some-app-guid",
499499
Instances: types.NullInt{Value: 3, IsSet: true},
500-
Memory: 128,
500+
Memory: types.NullByteSizeInMb{IsSet: true, Value: 128},
501501
PackageUpdatedAt: time.Unix(0, 0),
502502
DetectedBuildpack: types.FilteredString{IsSet: true, Value: "some-buildpack"},
503503
State: "STARTED",

0 commit comments

Comments
 (0)