Skip to content

Commit

Permalink
feat: dynconfig add object storage (dragonflyoss#1369)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Jun 10, 2022
1 parent 0e07a28 commit 60d78c6
Show file tree
Hide file tree
Showing 18 changed files with 2,215 additions and 312 deletions.
66 changes: 62 additions & 4 deletions client/config/dynconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"path/filepath"
"time"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

logger "d7y.io/dragonfly/v2/internal/dflog"
internaldynconfig "d7y.io/dragonfly/v2/internal/dynconfig"
"d7y.io/dragonfly/v2/manager/searcher"
Expand All @@ -37,13 +40,21 @@ var (
)

type DynconfigData struct {
Schedulers []*manager.Scheduler
Schedulers []*manager.Scheduler
ObjectStorage *manager.ObjectStorage
Buckets []*manager.Bucket
}

type Dynconfig interface {
// Get the dynamic config from manager.
// Get the dynamic schedulers config from manager.
GetSchedulers() ([]*manager.Scheduler, error)

// Get the dynamic object storage config from manager.
GetObjectStorage() (*manager.ObjectStorage, error)

// Get the dynamic buckets config from manager.
GetBuckets() ([]*manager.Bucket, error)

// Get the dynamic config from manager.
Get() (*DynconfigData, error)

Expand Down Expand Up @@ -104,6 +115,24 @@ func (d *dynconfig) GetSchedulers() ([]*manager.Scheduler, error) {
return data.Schedulers, nil
}

func (d *dynconfig) GetObjectStorage() (*manager.ObjectStorage, error) {
data, err := d.Get()
if err != nil {
return nil, err
}

return data.ObjectStorage, nil
}

func (d *dynconfig) GetBuckets() ([]*manager.Bucket, error) {
data, err := d.Get()
if err != nil {
return nil, err
}

return data.Buckets, nil
}

func (d *dynconfig) Get() (*DynconfigData, error) {
var data DynconfigData
if err := d.Unmarshal(&data); err != nil {
Expand Down Expand Up @@ -182,7 +211,7 @@ func newManagerClient(client managerclient.Client, hostOption HostOption) intern
}

func (mc *managerClient) Get() (interface{}, error) {
schedulers, err := mc.ListSchedulers(&manager.ListSchedulersRequest{
listSchedulersResp, err := mc.ListSchedulers(&manager.ListSchedulersRequest{
SourceType: manager.SourceType_PEER_SOURCE,
HostName: mc.hostOption.Hostname,
Ip: mc.hostOption.AdvertiseIP,
Expand All @@ -197,5 +226,34 @@ func (mc *managerClient) Get() (interface{}, error) {
return nil, err
}

return schedulers, nil
getObjectStorageResp, err := mc.GetObjectStorage(&manager.GetObjectStorageRequest{
SourceType: manager.SourceType_PEER_SOURCE,
HostName: mc.hostOption.Hostname,
Ip: mc.hostOption.AdvertiseIP,
})
if err != nil {
if s, ok := status.FromError(err); ok &&
(s.Code() == codes.NotFound || s.Code() == codes.Unimplemented) {
return DynconfigData{
Schedulers: listSchedulersResp.Schedulers,
}, nil
}

return nil, err
}

listBucketsResp, err := mc.ListBuckets(&manager.ListBucketsRequest{
SourceType: manager.SourceType_PEER_SOURCE,
HostName: mc.hostOption.Hostname,
Ip: mc.hostOption.AdvertiseIP,
})
if err != nil {
return nil, err
}

return DynconfigData{
Schedulers: listSchedulersResp.Schedulers,
ObjectStorage: getObjectStorageResp,
Buckets: listBucketsResp.Buckets,
}, nil
}
Loading

0 comments on commit 60d78c6

Please sign in to comment.