diff --git a/api/cloudcontroller/ccv3/constant/relationships.go b/api/cloudcontroller/ccv3/constant/relationships.go index 6a8b3c12796..06e4eb3971e 100644 --- a/api/cloudcontroller/ccv3/constant/relationships.go +++ b/api/cloudcontroller/ccv3/constant/relationships.go @@ -21,4 +21,7 @@ const ( // RelationshipTypeQuota is a relationship with a Cloud Controller quota (org quota or space quota). RelationshipTypeQuota RelationshipType = "quota" + + // RelationshipTypeCurrentDroplet is a relationship with a Droplet. + RelationshipTypeCurrentDroplet RelationshipType = "current_droplet" ) diff --git a/resources/application_resource.go b/resources/application_resource.go index b9794bb81f9..481b12e6fc8 100644 --- a/resources/application_resource.go +++ b/resources/application_resource.go @@ -27,6 +27,8 @@ type Application struct { State constant.ApplicationState // Credentials are used by Cloud Native Buildpacks lifecycle to pull buildpacks Credentials map[string]interface{} + // CurrentDropletGUID is the unique identifier of the droplet currently attached to the application. + CurrentDropletGUID string } // ApplicationNameOnly represents only the name field of a Cloud Controller V3 Application @@ -42,10 +44,18 @@ func (a Application) MarshalJSON() ([]byte, error) { Metadata: a.Metadata, } + relationShips := Relationships{} + if a.SpaceGUID != "" { - ccApp.Relationships = Relationships{ - constant.RelationshipTypeSpace: Relationship{GUID: a.SpaceGUID}, - } + relationShips[constant.RelationshipTypeSpace] = Relationship{GUID: a.SpaceGUID} + } + + if a.CurrentDropletGUID != "" { + relationShips[constant.RelationshipTypeCurrentDroplet] = Relationship{GUID: a.CurrentDropletGUID} + } + + if len(relationShips) > 0 { + ccApp.Relationships = relationShips } if a.LifecycleType == constant.AppLifecycleTypeDocker { @@ -81,6 +91,9 @@ func (a *Application) UnmarshalJSON(data []byte) error { a.LifecycleType = lifecycle.Type a.Name = ccApp.Name a.SpaceGUID = ccApp.Relationships[constant.RelationshipTypeSpace].GUID + if _, ok := ccApp.Relationships[constant.RelationshipTypeCurrentDroplet]; ok { + a.CurrentDropletGUID = ccApp.Relationships[constant.RelationshipTypeCurrentDroplet].GUID + } a.State = ccApp.State a.Metadata = ccApp.Metadata