Skip to content

Commit

Permalink
feat: add manager v2 api (#1990)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Jan 10, 2023
1 parent da0cf8d commit 6c7e8bf
Show file tree
Hide file tree
Showing 44 changed files with 3,548 additions and 1,405 deletions.
4 changes: 2 additions & 2 deletions client/config/dynconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type Dynconfig interface {

type dynconfig struct {
sourceType SourceType
managerClient managerclient.Client
managerClient managerclient.V1
cacheDir string
expire time.Duration
transportCredentials credentials.TransportCredentials
Expand All @@ -97,7 +97,7 @@ type Observer interface {
type DynconfigOption func(d *dynconfig) error

// WithManagerClient set the manager client.
func WithManagerClient(c managerclient.Client) DynconfigOption {
func WithManagerClient(c managerclient.V1) DynconfigOption {
return func(d *dynconfig) error {
d.managerClient = c
return nil
Expand Down
16 changes: 8 additions & 8 deletions client/config/dynconfig_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type dynconfigManager struct {
}

// newDynconfigManager returns a new manager dynconfig instence.
func newDynconfigManager(cfg *DaemonOption, rawManagerClient managerclient.Client, cacheDir string, expire time.Duration, creds credentials.TransportCredentials) (Dynconfig, error) {
func newDynconfigManager(cfg *DaemonOption, rawManagerClient managerclient.V1, cacheDir string, expire time.Duration, creds credentials.TransportCredentials) (Dynconfig, error) {
cachePath := filepath.Join(cacheDir, cacheFileName)
d, err := internaldynconfig.New[DynconfigData](
newManagerClient(rawManagerClient, cfg),
Expand Down Expand Up @@ -238,20 +238,20 @@ func (d *dynconfigManager) Stop() error {
}

type managerClient struct {
managerclient.Client
config *DaemonOption
managerClient managerclient.V1
config *DaemonOption
}

// New the manager client used by dynconfig.
func newManagerClient(client managerclient.Client, cfg *DaemonOption) internaldynconfig.ManagerClient {
func newManagerClient(client managerclient.V1, cfg *DaemonOption) internaldynconfig.ManagerClient {
return &managerClient{
Client: client,
config: cfg,
managerClient: client,
config: cfg,
}
}

func (mc *managerClient) Get() (any, error) {
listSchedulersResp, err := mc.ListSchedulers(context.Background(), &managerv1.ListSchedulersRequest{
listSchedulersResp, err := mc.managerClient.ListSchedulers(context.Background(), &managerv1.ListSchedulersRequest{
SourceType: managerv1.SourceType_PEER_SOURCE,
HostName: mc.config.Host.Hostname,
Ip: mc.config.Host.AdvertiseIP.String(),
Expand All @@ -269,7 +269,7 @@ func (mc *managerClient) Get() (any, error) {
}

if mc.config.ObjectStorage.Enable {
getObjectStorageResp, err := mc.GetObjectStorage(context.Background(), &managerv1.GetObjectStorageRequest{
getObjectStorageResp, err := mc.managerClient.GetObjectStorage(context.Background(), &managerv1.GetObjectStorageRequest{
SourceType: managerv1.SourceType_PEER_SOURCE,
HostName: mc.config.Host.Hostname,
Ip: mc.config.Host.AdvertiseIP.String(),
Expand Down
60 changes: 30 additions & 30 deletions client/config/dynconfig_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestDynconfigGetResolveSchedulerAddrs_ManagerSourceType(t *testing.T) {
data *DynconfigData
sleep func()
cleanFileCache func(t *testing.T)
mock func(m *mocks.MockClientMockRecorder, data *DynconfigData)
mock func(m *mocks.MockV1MockRecorder, data *DynconfigData)
expect func(t *testing.T, dynconfig Dynconfig, data *DynconfigData)
}{
{
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestDynconfigGetResolveSchedulerAddrs_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{
Schedulers: []*managerv1.Scheduler{
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestDynconfigGetResolveSchedulerAddrs_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestDynconfigGetResolveSchedulerAddrs_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestDynconfigGetResolveSchedulerAddrs_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestDynconfigGetResolveSchedulerAddrs_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{
Schedulers: []*managerv1.Scheduler{
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestDynconfigGetResolveSchedulerAddrs_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand All @@ -352,7 +352,7 @@ func TestDynconfigGetResolveSchedulerAddrs_ManagerSourceType(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()

mockManagerClient := mocks.NewMockClient(ctl)
mockManagerClient := mocks.NewMockV1(ctl)
tc.mock(mockManagerClient.EXPECT(), tc.data)
dynconfig, err := NewDynconfig(
ManagerSourceType, tc.config,
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestDynconfigGet_ManagerSourceType(t *testing.T) {
data *DynconfigData
sleep func()
cleanFileCache func(t *testing.T)
mock func(m *mocks.MockClientMockRecorder, data *DynconfigData)
mock func(m *mocks.MockV1MockRecorder, data *DynconfigData)
expect func(t *testing.T, dynconfig Dynconfig, data *DynconfigData)
}{
{
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestDynconfigGet_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{
Schedulers: []*managerv1.Scheduler{
Expand Down Expand Up @@ -461,7 +461,7 @@ func TestDynconfigGet_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand Down Expand Up @@ -510,7 +510,7 @@ func TestDynconfigGet_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{
Expand Down Expand Up @@ -558,7 +558,7 @@ func TestDynconfigGet_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{
Schedulers: []*managerv1.Scheduler{
Expand Down Expand Up @@ -609,7 +609,7 @@ func TestDynconfigGet_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{
Schedulers: []*managerv1.Scheduler{
Expand Down Expand Up @@ -661,7 +661,7 @@ func TestDynconfigGet_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{
Schedulers: []*managerv1.Scheduler{
Expand Down Expand Up @@ -722,7 +722,7 @@ func TestDynconfigGet_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand All @@ -744,7 +744,7 @@ func TestDynconfigGet_ManagerSourceType(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()

mockManagerClient := mocks.NewMockClient(ctl)
mockManagerClient := mocks.NewMockV1(ctl)
tc.mock(mockManagerClient.EXPECT(), tc.data)
dynconfig, err := NewDynconfig(
ManagerSourceType, tc.config,
Expand Down Expand Up @@ -773,7 +773,7 @@ func TestDynconfigGetSchedulers_ManagerSourceType(t *testing.T) {
data *DynconfigData
sleep func()
cleanFileCache func(t *testing.T)
mock func(m *mocks.MockClientMockRecorder, data *DynconfigData)
mock func(m *mocks.MockV1MockRecorder, data *DynconfigData)
expect func(t *testing.T, dynconfig Dynconfig, data *DynconfigData)
}{
{
Expand All @@ -800,7 +800,7 @@ func TestDynconfigGetSchedulers_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{
Schedulers: []*managerv1.Scheduler{
Expand Down Expand Up @@ -845,7 +845,7 @@ func TestDynconfigGetSchedulers_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand Down Expand Up @@ -892,7 +892,7 @@ func TestDynconfigGetSchedulers_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{
Schedulers: []*managerv1.Scheduler{
Expand Down Expand Up @@ -934,7 +934,7 @@ func TestDynconfigGetSchedulers_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand All @@ -955,7 +955,7 @@ func TestDynconfigGetSchedulers_ManagerSourceType(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()

mockManagerClient := mocks.NewMockClient(ctl)
mockManagerClient := mocks.NewMockV1(ctl)
tc.mock(mockManagerClient.EXPECT(), tc.data)
dynconfig, err := NewDynconfig(
ManagerSourceType, tc.config,
Expand Down Expand Up @@ -984,7 +984,7 @@ func TestDynconfigGetObjectStorage_ManagerSourceType(t *testing.T) {
data *DynconfigData
sleep func()
cleanFileCache func(t *testing.T)
mock func(m *mocks.MockClientMockRecorder, data *DynconfigData)
mock func(m *mocks.MockV1MockRecorder, data *DynconfigData)
expect func(t *testing.T, dynconfig Dynconfig, data *DynconfigData)
}{
{
Expand All @@ -1009,7 +1009,7 @@ func TestDynconfigGetObjectStorage_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{
Expand Down Expand Up @@ -1048,7 +1048,7 @@ func TestDynconfigGetObjectStorage_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand Down Expand Up @@ -1089,7 +1089,7 @@ func TestDynconfigGetObjectStorage_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{
Expand Down Expand Up @@ -1130,7 +1130,7 @@ func TestDynconfigGetObjectStorage_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{
Expand Down Expand Up @@ -1171,7 +1171,7 @@ func TestDynconfigGetObjectStorage_ManagerSourceType(t *testing.T) {
t.Fatal(err)
}
},
mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
mock: func(m *mocks.MockV1MockRecorder, data *DynconfigData) {
gomock.InOrder(
m.ListSchedulers(gomock.Any(), gomock.Any()).Return(&managerv1.ListSchedulersResponse{}, nil).Times(1),
m.GetObjectStorage(gomock.Any(), gomock.Any()).Return(&managerv1.ObjectStorage{}, nil).Times(1),
Expand All @@ -1193,7 +1193,7 @@ func TestDynconfigGetObjectStorage_ManagerSourceType(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()

mockManagerClient := mocks.NewMockClient(ctl)
mockManagerClient := mocks.NewMockV1(ctl)
tc.mock(mockManagerClient.EXPECT(), tc.data)
dynconfig, err := NewDynconfig(
ManagerSourceType, tc.config,
Expand Down
Loading

0 comments on commit 6c7e8bf

Please sign in to comment.