Skip to content

Commit d4253ee

Browse files
authored
Add CurrentDropletGUID attribute to application resource [v8] (#3353)
* add current_droplet relationships to application resource * always set application Relationships in application resource
1 parent f2fda72 commit d4253ee

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

api/cloudcontroller/ccv3/constant/relationships.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ const (
2121

2222
// RelationshipTypeQuota is a relationship with a Cloud Controller quota (org quota or space quota).
2323
RelationshipTypeQuota RelationshipType = "quota"
24+
25+
// RelationshipTypeCurrentDroplet is a relationship with a Droplet.
26+
RelationshipTypeCurrentDroplet RelationshipType = "current_droplet"
2427
)

resources/application_resource.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type Application struct {
2727
State constant.ApplicationState
2828
// Credentials are used by Cloud Native Buildpacks lifecycle to pull buildpacks
2929
Credentials map[string]interface{}
30+
// CurrentDropletGUID is the unique identifier of the droplet currently attached to the application.
31+
CurrentDropletGUID string
3032
}
3133

3234
// ApplicationNameOnly represents only the name field of a Cloud Controller V3 Application
@@ -42,10 +44,14 @@ func (a Application) MarshalJSON() ([]byte, error) {
4244
Metadata: a.Metadata,
4345
}
4446

47+
ccApp.Relationships = Relationships{}
48+
4549
if a.SpaceGUID != "" {
46-
ccApp.Relationships = Relationships{
47-
constant.RelationshipTypeSpace: Relationship{GUID: a.SpaceGUID},
48-
}
50+
ccApp.Relationships[constant.RelationshipTypeSpace] = Relationship{GUID: a.SpaceGUID}
51+
}
52+
53+
if a.CurrentDropletGUID != "" {
54+
ccApp.Relationships[constant.RelationshipTypeCurrentDroplet] = Relationship{GUID: a.CurrentDropletGUID}
4955
}
5056

5157
if a.LifecycleType == constant.AppLifecycleTypeDocker {
@@ -81,6 +87,9 @@ func (a *Application) UnmarshalJSON(data []byte) error {
8187
a.LifecycleType = lifecycle.Type
8288
a.Name = ccApp.Name
8389
a.SpaceGUID = ccApp.Relationships[constant.RelationshipTypeSpace].GUID
90+
if _, ok := ccApp.Relationships[constant.RelationshipTypeCurrentDroplet]; ok {
91+
a.CurrentDropletGUID = ccApp.Relationships[constant.RelationshipTypeCurrentDroplet].GUID
92+
}
8493
a.State = ccApp.State
8594
a.Metadata = ccApp.Metadata
8695

0 commit comments

Comments
 (0)