Skip to content

Commit

Permalink
feat: add interface of the persistent cache resource (#3602)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Oct 22, 2024
1 parent 2e1a6b5 commit eb4e101
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 11 deletions.
2 changes: 0 additions & 2 deletions scheduler/resource/persistentcache/host_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ type hostManager struct {
rdb redis.UniversalClient
}

// TODO: Use newTaskManager for resource management.
// New host manager interface.
// nolint
func newHostManager(cfg *config.Config, rdb redis.UniversalClient) HostManager {
return &hostManager{config: cfg, rdb: rdb}
}
Expand Down
8 changes: 4 additions & 4 deletions scheduler/resource/persistentcache/peer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

//go:generate mockgen -destination peer_manager_mock.go -source peer_manager.go -package persistentcache

package persistentcache

import (
Expand Down Expand Up @@ -61,11 +63,9 @@ type peerManager struct {
rdb redis.UniversalClient
}

// TODO: Use newPeerManager for resource management.
// New peer manager interface.
// nolint
func newPeerManager(cfg *config.Config, taskManager TaskManager, hostManager HostManager, rdb redis.UniversalClient) PeerManager {
return &peerManager{config: cfg, taskManager: taskManager, hostManager: hostManager, rdb: rdb}
func newPeerManager(cfg *config.Config, rdb redis.UniversalClient, taskManager TaskManager, hostManager HostManager) PeerManager {
return &peerManager{config: cfg, rdb: rdb, taskManager: taskManager, hostManager: hostManager}
}

// Load returns persistent cache peer by a key.
Expand Down
98 changes: 98 additions & 0 deletions scheduler/resource/persistentcache/peer_manager_mock.go

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

72 changes: 72 additions & 0 deletions scheduler/resource/persistentcache/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2024 The Dragonfly Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//go:generate mockgen -destination resource_mock.go -source resource.go -package persistentcache

package persistentcache

import (
"github.com/redis/go-redis/v9"

"d7y.io/dragonfly/v2/scheduler/config"
)

// Resource is the interface used for resource.
type Resource interface {
// Host manager interface.
HostManager() HostManager

// Peer manager interface.
PeerManager() PeerManager

// Task manager interface.
TaskManager() TaskManager
}

// resource contains content for resource.
type resource struct {
// Peer manager interface.
peerManager PeerManager

// Task manager interface.
taskManager TaskManager

// Host manager interface.
hostManager HostManager
}

// New returns Resource interface.
func New(cfg *config.Config, rdb redis.UniversalClient) Resource {
taskManager := newTaskManager(cfg, rdb)
hostManager := newHostManager(cfg, rdb)
peerManager := newPeerManager(cfg, rdb, taskManager, hostManager)
return &resource{peerManager, taskManager, hostManager}
}

// Host manager interface.
func (r *resource) HostManager() HostManager {
return r.hostManager
}

// Peer manager interface.
func (r *resource) PeerManager() PeerManager {
return r.peerManager
}

// Task manager interface.
func (r *resource) TaskManager() TaskManager {
return r.taskManager
}
81 changes: 81 additions & 0 deletions scheduler/resource/persistentcache/resource_mock.go

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

2 changes: 0 additions & 2 deletions scheduler/resource/persistentcache/task_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ type taskManager struct {
rdb redis.UniversalClient
}

// TODO: Use newTaskManager for resource management.
// New persistent cache task manager interface.
// nolint
func newTaskManager(cfg *config.Config, rdb redis.UniversalClient) TaskManager {
return &taskManager{config: cfg, rdb: rdb}
}
Expand Down
13 changes: 10 additions & 3 deletions scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import (
"d7y.io/dragonfly/v2/scheduler/config"
"d7y.io/dragonfly/v2/scheduler/job"
"d7y.io/dragonfly/v2/scheduler/metrics"
resource "d7y.io/dragonfly/v2/scheduler/resource/standard"
persistentcache "d7y.io/dragonfly/v2/scheduler/resource/persistentcache"
standard "d7y.io/dragonfly/v2/scheduler/resource/standard"
"d7y.io/dragonfly/v2/scheduler/rpcserver"
"d7y.io/dragonfly/v2/scheduler/scheduling"
"d7y.io/dragonfly/v2/scheduler/storage"
Expand All @@ -69,7 +70,10 @@ type Server struct {
managerClient managerclient.V2

// Resource interface.
resource resource.Resource
resource standard.Resource

// Persistent cache resource interface.
persistentCacheResource persistentcache.Resource

// Dynamic config.
dynconfig config.DynconfigInterface
Expand Down Expand Up @@ -172,12 +176,15 @@ func New(ctx context.Context, cfg *config.Config, d dfpath.Dfpath) (*Server, err
s.dynconfig = dynconfig

// Initialize resource.
resource, err := resource.New(cfg, s.gc, dynconfig, clientTransportCredentials)
resource, err := standard.New(cfg, s.gc, dynconfig, clientTransportCredentials)
if err != nil {
return nil, err
}
s.resource = resource

// Initialize persistent cache resource.
s.persistentCacheResource = persistentcache.New(cfg, rdb)

// Initialize job service.
if cfg.Job.Enable && rdb != nil {
s.job, err = job.New(cfg, resource)
Expand Down

0 comments on commit eb4e101

Please sign in to comment.