Skip to content

Commit

Permalink
Implement GSP-111 Add System Metadata in Storage Metadata (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
JinnyYi authored Jun 23, 2021
1 parent cb9b688 commit 271aed5
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cmd/definitions/bindata.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions cmd/definitions/tests/service.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ description = "set storage features"
type = "string"
description = "is the storage class for this object"

[infos.storage.meta.queries-per-second]
type = "int64"
description = "tests storage system metadata"

[pairs.size]
type = "int64"
description = "tests pair conflict"
Expand Down
36 changes: 36 additions & 0 deletions cmd/definitions/tmpl/service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Type = "{{ .Name }}"
// ObjectMetadata stores service metadata for object.
type ObjectMetadata struct {
{{- range $_, $v := .Infos }}
{{- if eq $v.Scope "object" }}
{{- if not $v.Global }}
{{- $pname := $v.Name | toPascal }}
{{- if $v.DisplayName }}
Expand All @@ -32,6 +33,7 @@ type ObjectMetadata struct {
{{ $v.Description }}
{{ $pname }} {{ $v.Type }}
{{- end }}
{{- end }}
{{- end }}
}

Expand All @@ -54,6 +56,40 @@ func setObjectMetadata(o *Object, om ObjectMetadata) {
o.SetServiceMetadata(om)
}

// StorageSystemMetadata stores system metadata for storage meta.
type StorageSystemMetadata struct {
{{- range $_, $v := .Infos }}
{{- if eq $v.Scope "storage" }}
{{- if not $v.Global }}
{{- $pname := $v.Name | toPascal }}
{{- if $v.DisplayName }}
{{- $pname = $v.DisplayName }}
{{- end }}
{{ $v.Description }}
{{ $pname }} {{ $v.Type }}
{{- end }}
{{- end }}
{{- end }}
}

// GetStorageSystemMetadata will get SystemMetadata from StorageMeta.
//
// - The returning StorageSystemMetadata is read only and should not be modified.
func GetStorageSystemMetadata(s *StorageMeta) StorageSystemMetadata {
sm, ok := s.GetSystemMetadata()
if ok {
return sm.(StorageSystemMetadata)
}
return StorageSystemMetadata{}
}

// setStorageSystemMetadata will set SystemMetadata into StorageMeta.
//
// - This function should only be called once, please make sure all data has been written before set.
func setStorageSystemMetadata(s *StorageMeta, sm StorageSystemMetadata) {
s.SetSystemMetadata(sm)
}

{{- range $_, $v := .Pairs }}
{{- if not $v.Global }}
{{- $pname := $v.Name | toPascal }}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.15

require (
github.com/Xuanwo/templateutils v0.1.0
github.com/beyondstorage/specs/go v0.0.0-20210621052257-46d075c8cee3
github.com/beyondstorage/specs/go v0.0.0-20210623021521-09a4bf58fdb3
github.com/dave/dst v0.26.2
github.com/golang/mock v1.5.0
github.com/google/uuid v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/Xuanwo/templateutils v0.1.0 h1:WpkWOqQtIQ2vAIpJLa727DdN8WtxhUkkbDGa6UhntJY=
github.com/Xuanwo/templateutils v0.1.0/go.mod h1:OdE0DJ+CJxDBq6psX5DPV+gOZi8bhuHuVUpPCG++Wb8=
github.com/beyondstorage/specs/go v0.0.0-20210621052257-46d075c8cee3 h1:ZEite7O0btU34rKsnKptOJ5DyCgMs5hOqpA0H1+kidU=
github.com/beyondstorage/specs/go v0.0.0-20210621052257-46d075c8cee3/go.mod h1:vF/Q0P1tCvhVAUrxg7i6NvrARRMQVTAuQdDNqpSzR1w=
github.com/beyondstorage/specs/go v0.0.0-20210623021521-09a4bf58fdb3 h1:xQr2klNnWs/cCsBjfGhq1dAPNLLZcdODRAiD2sn/zsU=
github.com/beyondstorage/specs/go v0.0.0-20210623021521-09a4bf58fdb3/go.mod h1:vF/Q0P1tCvhVAUrxg7i6NvrARRMQVTAuQdDNqpSzR1w=
github.com/dave/dst v0.26.2 h1:lnxLAKI3tx7MgLNVDirFCsDTlTG9nKTk7GcptKcWSwY=
github.com/dave/dst v0.26.2/go.mod h1:UMDJuIRPfyUCC78eFuB+SV/WI8oDeyFDvM/JR6NI3IU=
github.com/dave/gopackages v0.0.0-20170318123100-46e7023ec56e/go.mod h1:i00+b/gKdIDIxuLDFob7ustLAVqhsZRk2qVZrArELGQ=
Expand Down
26 changes: 24 additions & 2 deletions types/info.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 271aed5

Please sign in to comment.