Skip to content

Commit

Permalink
serverMux renames
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>
  • Loading branch information
ncdc committed Jun 14, 2018
1 parent f4c86c6 commit f6a3dee
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func newPodBackupItemAction(logger logrus.FieldLogger) (interface{}, error) {
return backup.NewPodAction(logger), nil
}

func newServiceAccountBackupItemAction(f client.Factory) arkplugin.ServerInitializer {
func newServiceAccountBackupItemAction(f client.Factory) arkplugin.HandlerInitializer {
return func(logger logrus.FieldLogger) (interface{}, error) {
// TODO(ncdc): consider a k8s style WantsKubernetesClientSet initialization approach
clientset, err := f.KubeClient()
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/backup_item_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type BackupItemActionGRPCServer struct {
}

func (s *BackupItemActionGRPCServer) getImpl(name string) (arkbackup.ItemAction, error) {
impl, err := s.mux.getInstance(name)
impl, err := s.mux.getHandler(name)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/backup_item_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestBackupItemActionGRPCServerExecute(t *testing.T) {

s := &BackupItemActionGRPCServer{mux: &serverMux{
serverLog: arktest.NewLogger(),
instances: map[string]interface{}{
handlers: map[string]interface{}{
"xyz": itemAction,
},
}}
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/block_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ type BlockStoreGRPCServer struct {
}

func (s *BlockStoreGRPCServer) getImpl(name string) (cloudprovider.BlockStore, error) {
impl, err := s.mux.getInstance(name)
impl, err := s.mux.getHandler(name)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ type ObjectStoreGRPCServer struct {
}

func (s *ObjectStoreGRPCServer) getImpl(name string) (cloudprovider.ObjectStore, error) {
impl, err := s.mux.getInstance(name)
impl, err := s.mux.getHandler(name)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/restore_item_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ type RestoreItemActionGRPCServer struct {
}

func (s *RestoreItemActionGRPCServer) getImpl(name string) (restore.ItemAction, error) {
impl, err := s.mux.getInstance(name)
impl, err := s.mux.getHandler(name)
if err != nil {
return nil, err
}
Expand Down
40 changes: 20 additions & 20 deletions pkg/plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ var Handshake = plugin.HandshakeConfig{
// Server serves registered plugin implementations.
type Server interface {
// RegisterBackupItemAction registers a backup item action.
RegisterBackupItemAction(name string, factory ServerInitializer) Server
RegisterBackupItemAction(name string, initializer HandlerInitializer) Server

// RegisterBackupItemActions registers multiple backup item actions.
RegisterBackupItemActions(map[string]ServerInitializer) Server
RegisterBackupItemActions(map[string]HandlerInitializer) Server

// RegisterBlockStore registers a block store.
RegisterBlockStore(name string, factory ServerInitializer) Server
RegisterBlockStore(name string, initializer HandlerInitializer) Server

// RegisterBlockStores registers multiple block stores.
RegisterBlockStores(map[string]ServerInitializer) Server
RegisterBlockStores(map[string]HandlerInitializer) Server

// RegisterObjectStore registers an object store.
RegisterObjectStore(name string, factory ServerInitializer) Server
RegisterObjectStore(name string, initializer HandlerInitializer) Server

// RegisterObjectStores registers multiple object stores.
RegisterObjectStores(map[string]ServerInitializer) Server
RegisterObjectStores(map[string]HandlerInitializer) Server

// RegisterRestoreItemAction registers a restore item action.
RegisterRestoreItemAction(name string, factory ServerInitializer) Server
RegisterRestoreItemAction(name string, initializer HandlerInitializer) Server

// RegisterRestoreItemActions registers multiple restore item actions.
RegisterRestoreItemActions(map[string]ServerInitializer) Server
RegisterRestoreItemActions(map[string]HandlerInitializer) Server

// Server runs the plugin server.
Serve()
Expand Down Expand Up @@ -95,48 +95,48 @@ func NewServer(log logrus.FieldLogger) Server {
}
}

func (s *server) RegisterBackupItemAction(name string, factory ServerInitializer) Server {
s.backupItemAction.register(name, factory)
func (s *server) RegisterBackupItemAction(name string, initializer HandlerInitializer) Server {
s.backupItemAction.register(name, initializer)
return s
}

func (s *server) RegisterBackupItemActions(m map[string]ServerInitializer) Server {
func (s *server) RegisterBackupItemActions(m map[string]HandlerInitializer) Server {
for name := range m {
s.RegisterBackupItemAction(name, m[name])
}
return s
}

func (s *server) RegisterBlockStore(name string, factory ServerInitializer) Server {
s.blockStore.register(name, factory)
func (s *server) RegisterBlockStore(name string, initializer HandlerInitializer) Server {
s.blockStore.register(name, initializer)
return s
}

func (s *server) RegisterBlockStores(m map[string]ServerInitializer) Server {
func (s *server) RegisterBlockStores(m map[string]HandlerInitializer) Server {
for name := range m {
s.RegisterBlockStore(name, m[name])
}
return s
}

func (s *server) RegisterObjectStore(name string, factory ServerInitializer) Server {
s.objectStore.register(name, factory)
func (s *server) RegisterObjectStore(name string, initializer HandlerInitializer) Server {
s.objectStore.register(name, initializer)
return s
}

func (s *server) RegisterObjectStores(m map[string]ServerInitializer) Server {
func (s *server) RegisterObjectStores(m map[string]HandlerInitializer) Server {
for name := range m {
s.RegisterObjectStore(name, m[name])
}
return s
}

func (s *server) RegisterRestoreItemAction(name string, factory ServerInitializer) Server {
s.restoreItemAction.register(name, factory)
func (s *server) RegisterRestoreItemAction(name string, initializer HandlerInitializer) Server {
s.restoreItemAction.register(name, initializer)
return s
}

func (s *server) RegisterRestoreItemActions(m map[string]ServerInitializer) Server {
func (s *server) RegisterRestoreItemActions(m map[string]HandlerInitializer) Server {
for name := range m {
s.RegisterRestoreItemAction(name, m[name])
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/plugin/server_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
)

// ServerInitializer is a function that initializes and returns a new instance of one of Ark's plugin interfaces
// HandlerInitializer is a function that initializes and returns a new instance of one of Ark's plugin interfaces
// (ObjectStore, BlockStore, BackupItemAction, RestoreItemAction).
type ServerInitializer func(logger logrus.FieldLogger) (interface{}, error)
type HandlerInitializer func(logger logrus.FieldLogger) (interface{}, error)

// serverMux manages multiple implementations of a single plugin kind, such as pod and pvc BackupItemActions.
type serverMux struct {
kind PluginKind
initializers map[string]ServerInitializer
instances map[string]interface{}
initializers map[string]HandlerInitializer
handlers map[string]interface{}
serverLog logrus.FieldLogger
}

// newServerMux returns a new serverMux.
func newServerMux() *serverMux {
return &serverMux{
initializers: make(map[string]ServerInitializer),
instances: make(map[string]interface{}),
initializers: make(map[string]HandlerInitializer),
handlers: make(map[string]interface{}),
}
}

// register registers the initializer for name.
func (m *serverMux) register(name string, f ServerInitializer) {
func (m *serverMux) register(name string, f HandlerInitializer) {
// TODO(ncdc): return an error on duplicate registrations for the same name.
m.initializers[name] = f
}
Expand All @@ -42,10 +42,10 @@ func (m *serverMux) setServerLog(log logrus.FieldLogger) {
m.serverLog = log
}

// getInstance returns the instance for a plugin with the given name. If an instance has already been initialized,
// getHandler returns the instance for a plugin with the given name. If an instance has already been initialized,
// that is returned. Otherwise, the instance is initialized by calling its initialization function.
func (m *serverMux) getInstance(name string) (interface{}, error) {
if instance, found := m.instances[name]; found {
func (m *serverMux) getHandler(name string) (interface{}, error) {
if instance, found := m.handlers[name]; found {
return instance, nil
}

Expand All @@ -59,7 +59,7 @@ func (m *serverMux) getInstance(name string) (interface{}, error) {
return nil, err
}

m.instances[name] = instance
m.handlers[name] = instance

return m.instances[name], nil
return m.handlers[name], nil
}

0 comments on commit f6a3dee

Please sign in to comment.