Skip to content

Commit

Permalink
Add API recommended_deployment field in storage (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
seaneganx authored Feb 7, 2022
1 parent 398cce1 commit 4b320fc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 45 deletions.
42 changes: 23 additions & 19 deletions server/registry/actions_apis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ func TestCreateApi(t *testing.T) {
Parent: "projects/my-project/locations/global",
ApiId: "my-api",
Api: &rpc.Api{
DisplayName: "My Display Name",
Description: "My Description",
Availability: "My Availability",
RecommendedVersion: "My Version",
DisplayName: "My Display Name",
Description: "My Description",
Availability: "My Availability",
RecommendedVersion: "apis/my-api/versions/my-version",
RecommendedDeployment: "apis/my-api/deployments/my-deployment",
Labels: map[string]string{
"label-key": "label-value",
},
Expand All @@ -58,11 +59,12 @@ func TestCreateApi(t *testing.T) {
},
},
want: &rpc.Api{
Name: "projects/my-project/locations/global/apis/my-api",
DisplayName: "My Display Name",
Description: "My Description",
Availability: "My Availability",
RecommendedVersion: "My Version",
Name: "projects/my-project/locations/global/apis/my-api",
DisplayName: "My Display Name",
Description: "My Description",
Availability: "My Availability",
RecommendedVersion: "apis/my-api/versions/my-version",
RecommendedDeployment: "apis/my-api/deployments/my-deployment",
Labels: map[string]string{
"label-key": "label-value",
},
Expand Down Expand Up @@ -288,11 +290,12 @@ func TestGetApi(t *testing.T) {
{
desc: "fully populated resource",
seed: &rpc.Api{
Name: "projects/my-project/locations/global/apis/my-api",
DisplayName: "My Display Name",
Description: "My Description",
Availability: "My Availability",
RecommendedVersion: "My Version",
Name: "projects/my-project/locations/global/apis/my-api",
DisplayName: "My Display Name",
Description: "My Description",
Availability: "My Availability",
RecommendedVersion: "apis/my-api/versions/my-version",
RecommendedDeployment: "apis/my-api/deployments/my-deployment",
Labels: map[string]string{
"label-key": "label-value",
},
Expand All @@ -304,11 +307,12 @@ func TestGetApi(t *testing.T) {
Name: "projects/my-project/locations/global/apis/my-api",
},
want: &rpc.Api{
Name: "projects/my-project/locations/global/apis/my-api",
DisplayName: "My Display Name",
Description: "My Description",
Availability: "My Availability",
RecommendedVersion: "My Version",
Name: "projects/my-project/locations/global/apis/my-api",
DisplayName: "My Display Name",
Description: "My Description",
Availability: "My Availability",
RecommendedVersion: "apis/my-api/versions/my-version",
RecommendedDeployment: "apis/my-api/deployments/my-deployment",
Labels: map[string]string{
"label-key": "label-value",
},
Expand Down
1 change: 1 addition & 0 deletions server/registry/internal/storage/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ var apiFields = []filtering.Field{
{Name: "update_time", Type: filtering.Timestamp},
{Name: "availability", Type: filtering.String},
{Name: "recommended_version", Type: filtering.String},
{Name: "recommended_deployment", Type: filtering.String},
{Name: "labels", Type: filtering.StringMap},
}

Expand Down
57 changes: 31 additions & 26 deletions server/registry/internal/storage/models/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,33 @@ import (

// Api is the storage-side representation of an API.
type Api struct {
Key string `gorm:"primaryKey"`
ProjectID string // Uniquely identifies a project.
ApiID string // Uniquely identifies an api within a project.
DisplayName string // A human-friendly name.
Description string // A detailed description.
CreateTime time.Time // Creation time.
UpdateTime time.Time // Time of last change.
Availability string // Availability of the API.
RecommendedVersion string // Recommended API version.
Labels []byte // Serialized labels.
Annotations []byte // Serialized annotations.
Key string `gorm:"primaryKey"`
ProjectID string // Uniquely identifies a project.
ApiID string // Uniquely identifies an api within a project.
DisplayName string // A human-friendly name.
Description string // A detailed description.
CreateTime time.Time // Creation time.
UpdateTime time.Time // Time of last change.
Availability string // Availability of the API.
RecommendedVersion string // Recommended API version.
RecommendedDeployment string // Recommended API deployment.
Labels []byte // Serialized labels.
Annotations []byte // Serialized annotations.
}

// NewApi initializes a new resource.
func NewApi(name names.Api, body *rpc.Api) (api *Api, err error) {
now := time.Now().Round(time.Microsecond)
api = &Api{
ProjectID: name.ProjectID,
ApiID: name.ApiID,
Description: body.GetDescription(),
DisplayName: body.GetDisplayName(),
Availability: body.GetAvailability(),
RecommendedVersion: body.GetRecommendedVersion(),
CreateTime: now,
UpdateTime: now,
ProjectID: name.ProjectID,
ApiID: name.ApiID,
Description: body.GetDescription(),
DisplayName: body.GetDisplayName(),
Availability: body.GetAvailability(),
RecommendedVersion: body.GetRecommendedVersion(),
RecommendedDeployment: body.GetRecommendedDeployment(),
CreateTime: now,
UpdateTime: now,
}

api.Labels, err = bytesForMap(body.GetLabels())
Expand All @@ -76,13 +78,14 @@ func (api *Api) Name() string {
// Message returns a message representing an api.
func (api *Api) Message() (message *rpc.Api, err error) {
message = &rpc.Api{
Name: api.Name(),
DisplayName: api.DisplayName,
Description: api.Description,
Availability: api.Availability,
RecommendedVersion: api.RecommendedVersion,
CreateTime: timestamppb.New(api.CreateTime),
UpdateTime: timestamppb.New(api.UpdateTime),
Name: api.Name(),
DisplayName: api.DisplayName,
Description: api.Description,
Availability: api.Availability,
RecommendedVersion: api.RecommendedVersion,
RecommendedDeployment: api.RecommendedDeployment,
CreateTime: timestamppb.New(api.CreateTime),
UpdateTime: timestamppb.New(api.UpdateTime),
}

message.Labels, err = api.LabelsMap()
Expand Down Expand Up @@ -111,6 +114,8 @@ func (api *Api) Update(message *rpc.Api, mask *fieldmaskpb.FieldMask) error {
api.Availability = message.GetAvailability()
case "recommended_version":
api.RecommendedVersion = message.GetRecommendedVersion()
case "recommended_deployment":
api.RecommendedDeployment = message.GetRecommendedDeployment()
case "labels":
var err error
if api.Labels, err = bytesForMap(message.GetLabels()); err != nil {
Expand Down

0 comments on commit 4b320fc

Please sign in to comment.