Merge pull request #13557 from influxdata/bucket_desc
feat(influxdb): add bucket descpull/13590/head
commit
3bc1c49e91
|
@ -521,6 +521,10 @@ func (c *Client) updateBucket(ctx context.Context, tx *bolt.Tx, id platform.ID,
|
|||
b.RetentionPeriod = *upd.RetentionPeriod
|
||||
}
|
||||
|
||||
if upd.Description != nil {
|
||||
b.Description = *upd.Description
|
||||
}
|
||||
|
||||
if upd.Name != nil {
|
||||
b0, err := c.findBucketByName(ctx, tx, b.OrgID, *upd.Name)
|
||||
if err == nil && b0.ID != id {
|
||||
|
|
|
@ -23,6 +23,7 @@ type Bucket struct {
|
|||
ID ID `json:"id,omitempty"`
|
||||
OrgID ID `json:"orgID,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
RetentionPolicyName string `json:"rp,omitempty"` // This to support v1 sources
|
||||
RetentionPeriod time.Duration `json:"retentionPeriod"`
|
||||
}
|
||||
|
@ -64,6 +65,7 @@ type BucketService interface {
|
|||
// Only fields which are set are updated.
|
||||
type BucketUpdate struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
RetentionPeriod *time.Duration `json:"retentionPeriod,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -128,6 +128,7 @@ func NewBucketHandler(b *BucketBackend) *BucketHandler {
|
|||
type bucket struct {
|
||||
ID influxdb.ID `json:"id,omitempty"`
|
||||
OrgID influxdb.ID `json:"orgID,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Name string `json:"name"`
|
||||
RetentionPolicyName string `json:"rp,omitempty"` // This to support v1 sources
|
||||
RetentionRules []retentionRule `json:"retentionRules"`
|
||||
|
@ -160,6 +161,7 @@ func (b *bucket) toInfluxDB() (*influxdb.Bucket, error) {
|
|||
return &influxdb.Bucket{
|
||||
ID: b.ID,
|
||||
OrgID: b.OrgID,
|
||||
Description: b.Description,
|
||||
Name: b.Name,
|
||||
RetentionPolicyName: b.RetentionPolicyName,
|
||||
RetentionPeriod: d,
|
||||
|
@ -184,6 +186,7 @@ func newBucket(pb *influxdb.Bucket) *bucket {
|
|||
ID: pb.ID,
|
||||
OrgID: pb.OrgID,
|
||||
Name: pb.Name,
|
||||
Description: pb.Description,
|
||||
RetentionPolicyName: pb.RetentionPolicyName,
|
||||
RetentionRules: rules,
|
||||
}
|
||||
|
@ -192,6 +195,7 @@ func newBucket(pb *influxdb.Bucket) *bucket {
|
|||
// bucketUpdate is used for serialization/deserialization with retention rules.
|
||||
type bucketUpdate struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
RetentionRules []retentionRule `json:"retentionRules,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -214,6 +218,7 @@ func (b *bucketUpdate) toInfluxDB() (*influxdb.BucketUpdate, error) {
|
|||
|
||||
return &influxdb.BucketUpdate{
|
||||
Name: b.Name,
|
||||
Description: b.Description,
|
||||
RetentionPeriod: &d,
|
||||
}, nil
|
||||
}
|
||||
|
@ -225,6 +230,7 @@ func newBucketUpdate(pb *influxdb.BucketUpdate) *bucketUpdate {
|
|||
|
||||
up := &bucketUpdate{
|
||||
Name: pb.Name,
|
||||
Description: pb.Description,
|
||||
RetentionRules: []retentionRule{},
|
||||
}
|
||||
|
||||
|
|
|
@ -5562,6 +5562,8 @@ components:
|
|||
type: string
|
||||
name:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
organizationID:
|
||||
type: string
|
||||
organization:
|
||||
|
|
|
@ -270,6 +270,10 @@ func (s *Service) UpdateBucket(ctx context.Context, id platform.ID, upd platform
|
|||
b.RetentionPeriod = *upd.RetentionPeriod
|
||||
}
|
||||
|
||||
if upd.Description != nil {
|
||||
b.Description = *upd.Description
|
||||
}
|
||||
|
||||
b0, err := s.FindBucket(ctx, platform.BucketFilter{
|
||||
Name: upd.Name,
|
||||
})
|
||||
|
|
|
@ -589,6 +589,10 @@ func (s *Service) updateBucket(ctx context.Context, tx Tx, id influxdb.ID, upd i
|
|||
b.RetentionPeriod = *upd.RetentionPeriod
|
||||
}
|
||||
|
||||
if upd.Description != nil {
|
||||
b.Description = *upd.Description
|
||||
}
|
||||
|
||||
if upd.Name != nil {
|
||||
b0, err := s.findBucketByName(ctx, tx, b.OrgID, *upd.Name)
|
||||
if err == nil && b0.ID != id {
|
||||
|
|
|
@ -118,16 +118,18 @@ func CreateBucket(
|
|||
},
|
||||
args: args{
|
||||
bucket: &platform.Bucket{
|
||||
Name: "name1",
|
||||
OrgID: MustIDBase16(orgOneID),
|
||||
Name: "name1",
|
||||
OrgID: MustIDBase16(orgOneID),
|
||||
Description: "desc1",
|
||||
},
|
||||
},
|
||||
wants: wants{
|
||||
buckets: []*platform.Bucket{
|
||||
{
|
||||
Name: "name1",
|
||||
ID: MustIDBase16(bucketOneID),
|
||||
OrgID: MustIDBase16(orgOneID),
|
||||
Name: "name1",
|
||||
ID: MustIDBase16(bucketOneID),
|
||||
OrgID: MustIDBase16(orgOneID),
|
||||
Description: "desc1",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -991,9 +993,10 @@ func UpdateBucket(
|
|||
t *testing.T,
|
||||
) {
|
||||
type args struct {
|
||||
name string
|
||||
id platform.ID
|
||||
retention int
|
||||
name string
|
||||
id platform.ID
|
||||
retention int
|
||||
description *string
|
||||
}
|
||||
type wants struct {
|
||||
err error
|
||||
|
@ -1108,6 +1111,41 @@ func UpdateBucket(
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update description",
|
||||
fields: BucketFields{
|
||||
Organizations: []*platform.Organization{
|
||||
{
|
||||
Name: "theorg",
|
||||
ID: MustIDBase16(orgOneID),
|
||||
},
|
||||
},
|
||||
Buckets: []*platform.Bucket{
|
||||
{
|
||||
ID: MustIDBase16(bucketOneID),
|
||||
OrgID: MustIDBase16(orgOneID),
|
||||
Name: "bucket1",
|
||||
},
|
||||
{
|
||||
ID: MustIDBase16(bucketTwoID),
|
||||
OrgID: MustIDBase16(orgOneID),
|
||||
Name: "bucket2",
|
||||
},
|
||||
},
|
||||
},
|
||||
args: args{
|
||||
id: MustIDBase16(bucketOneID),
|
||||
description: stringPtr("desc1"),
|
||||
},
|
||||
wants: wants{
|
||||
bucket: &platform.Bucket{
|
||||
ID: MustIDBase16(bucketOneID),
|
||||
OrgID: MustIDBase16(orgOneID),
|
||||
Name: "bucket1",
|
||||
Description: "desc1",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update retention and name",
|
||||
fields: BucketFields{
|
||||
|
@ -1197,6 +1235,8 @@ func UpdateBucket(
|
|||
upd.RetentionPeriod = &d
|
||||
}
|
||||
|
||||
upd.Description = tt.args.description
|
||||
|
||||
bucket, err := s.UpdateBucket(ctx, tt.args.id, upd)
|
||||
diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t)
|
||||
|
||||
|
|
Loading…
Reference in New Issue