Commit e4f35675 authored by Anatoly Stansler's avatar Anatoly Stansler 🎯

Merge branch 'rename-managers' into 'master'

feat: rename VolumeManager to ThinCloneManager

See merge request !84
parents 4031df96 a746a38e
Pipeline #121967345 canceled with stages
in 1 minute and 50 seconds
......@@ -18,10 +18,12 @@ provision:
# "Local" mode related parameters.
local:
# Which volume manager to use. Available options: "zfs", "lvm".
volumeManager: "zfs"
# Which thin-clone managing module to use.
# Available options: "zfs", "lvm".
thinCloneManager: "zfs"
# Name of your pool or volume group with logic volume name (e.g. "dblab_vg/pg1_lv").
# Name of your pool (in the case of ZFS) or volume group
# with logic volume name (e.g. "dblab_vg/pg_lv", in the case of LVM).
pool: "dblab_pool"
# Pool of ports for Postgres clones.
......
......@@ -22,7 +22,7 @@ import (
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/docker"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/resources"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/runners"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/volumemanagers"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/thinclones"
"gitlab.com/postgres-ai/database-lab/pkg/util/pglog"
)
......@@ -64,17 +64,17 @@ type ModeLocalConfig struct {
DockerImage string `yaml:"dockerImage"`
UseSudo bool `yaml:"useSudo"`
// Logical volume manager.
VolumeManager string `yaml:"volumeManager"`
// Thin-clone manager.
ThinCloneManager string `yaml:"thinCloneManager"`
}
type provisionModeLocal struct {
provision
dockerClient *client.Client
runner runners.Runner
ports []bool
sessionCounter uint
volumeManager volumemanagers.VolumeManager
dockerClient *client.Client
runner runners.Runner
ports []bool
sessionCounter uint
thinCloneManager thinclones.Manager
}
// NewProvisionModeLocal creates a new Provision instance of ModeLocal.
......@@ -89,8 +89,8 @@ func NewProvisionModeLocal(ctx context.Context, config Config, dockerClient *cli
},
}
volumeManager, err := volumemanagers.NewVolumeManager(p.config.ModeLocal.VolumeManager,
p.runner, volumemanagers.VolumeManagerConfig{
thinCloneManager, err := thinclones.NewManager(p.config.ModeLocal.ThinCloneManager,
p.runner, thinclones.ManagerConfig{
Pool: p.config.ModeLocal.ClonePool,
SnapshotFilterSuffix: p.config.ModeLocal.SnapshotFilterSuffix,
MountDir: p.config.ModeLocal.MountDir,
......@@ -99,10 +99,10 @@ func NewProvisionModeLocal(ctx context.Context, config Config, dockerClient *cli
})
if err != nil {
return nil, errors.Wrap(err, "failed to initialize volume manager")
return nil, errors.Wrap(err, "failed to initialize thin-clone manager")
}
p.volumeManager = volumeManager
p.thinCloneManager = thinCloneManager
if len(p.config.ModeLocal.MountDir) == 0 {
p.config.ModeLocal.MountDir = "/var/lib/dblab/clones/"
......@@ -212,7 +212,7 @@ func (j *provisionModeLocal) StartSession(username, password, snapshotID string)
}
}()
err = j.volumeManager.CreateClone(name, snapshotID)
err = j.thinCloneManager.CreateClone(name, snapshotID)
if err != nil {
return nil, errors.Wrap(err, "failed to create a clone")
}
......@@ -258,7 +258,7 @@ func (j *provisionModeLocal) StopSession(session *resources.Session) error {
return errors.Wrap(err, "failed to stop a container")
}
err = j.volumeManager.DestroyClone(name)
err = j.thinCloneManager.DestroyClone(name)
if err != nil {
return errors.Wrap(err, "failed to destroy a clone")
}
......@@ -290,12 +290,12 @@ func (j *provisionModeLocal) ResetSession(session *resources.Session, snapshotID
return errors.Wrap(err, "failed to stop a container")
}
err = j.volumeManager.DestroyClone(name)
err = j.thinCloneManager.DestroyClone(name)
if err != nil {
return errors.Wrap(err, "failed to destroy clone")
}
err = j.volumeManager.CreateClone(name, snapshotID)
err = j.thinCloneManager.CreateClone(name, snapshotID)
if err != nil {
return errors.Wrap(err, "failed to create a clone")
}
......@@ -320,15 +320,15 @@ func (j *provisionModeLocal) CreateSnapshot(name string) error {
}
func (j *provisionModeLocal) GetSnapshots() ([]resources.Snapshot, error) {
return j.volumeManager.GetSnapshots()
return j.thinCloneManager.GetSnapshots()
}
func (j *provisionModeLocal) GetDiskState() (*resources.Disk, error) {
return j.volumeManager.GetDiskState()
return j.thinCloneManager.GetDiskState()
}
func (j *provisionModeLocal) GetSessionState(s *resources.Session) (*resources.SessionState, error) {
return j.volumeManager.GetSessionState(j.getName(s.Port))
return j.thinCloneManager.GetSessionState(j.getName(s.Port))
}
// Other methods.
......@@ -339,7 +339,7 @@ func (j *provisionModeLocal) revertSession(name string) {
log.Err(`Revert:`, runnerErr)
}
if runnerErr := j.volumeManager.DestroyClone(name); runnerErr != nil {
if runnerErr := j.thinCloneManager.DestroyClone(name); runnerErr != nil {
log.Err(`Revert:`, runnerErr)
}
}
......@@ -414,7 +414,7 @@ func (j *provisionModeLocal) stopAllSessions() error {
}
}
clones, err := j.volumeManager.ListClonesNames()
clones, err := j.thinCloneManager.ListClonesNames()
if err != nil {
return err
}
......@@ -422,7 +422,7 @@ func (j *provisionModeLocal) stopAllSessions() error {
log.Dbg("VM clones:", clones)
for _, clone := range clones {
err = j.volumeManager.DestroyClone(clone)
err = j.thinCloneManager.DestroyClone(clone)
if err != nil {
return err
}
......
......@@ -2,8 +2,8 @@
2020 © Postgres.ai
*/
// Package volumemanagers provides an interface to work different volume managers.
package volumemanagers
// Package thinclones provides an interface to work different thin-clone managers.
package thinclones
import (
"fmt"
......@@ -16,15 +16,15 @@ import (
)
const (
// VolumeManagerZFS defines "VolumeManager" option value for ZFS.
VolumeManagerZFS = "zfs"
// ManagerZFS defines "Manager" option value for ZFS.
ManagerZFS = "zfs"
// VolumeManagerLVM defines "VolumeManager" option value for LVM.
VolumeManagerLVM = "lvm"
// ManagerLVM defines "Manager" option value for LVM.
ManagerLVM = "lvm"
)
// VolumeManager defines an interface to work different volume managers.
type VolumeManager interface {
// Manager defines an interface to work different thin-clone managers.
type Manager interface {
CreateClone(name, snapshotID string) error
DestroyClone(name string) error
ListClonesNames() ([]string, error)
......@@ -34,8 +34,8 @@ type VolumeManager interface {
GetSnapshots() ([]resources.Snapshot, error)
}
// VolumeManagerConfig defines volume manager config.
type VolumeManagerConfig struct {
// ManagerConfig defines thin-clone manager config.
type ManagerConfig struct {
Pool string
SnapshotFilterSuffix string
MountDir string
......@@ -43,25 +43,25 @@ type VolumeManagerConfig struct {
ClonePrefix string
}
// NewVolumeManager defines constructor for volume managers.
func NewVolumeManager(mode string, runner runners.Runner, config VolumeManagerConfig) (VolumeManager, error) {
// NewManager defines constructor for thin-clone managers.
func NewManager(mode string, runner runners.Runner, config ManagerConfig) (Manager, error) {
var (
manager VolumeManager
manager Manager
err error
)
switch mode {
case VolumeManagerZFS:
manager = newVolumeManagerZFS(runner, config)
case VolumeManagerLVM:
if manager, err = newVolumeManagerLVM(runner, config); err != nil {
return nil, errors.Wrap(err, "failed to initialize LVM volume manager")
case ManagerZFS:
manager = newManagerZFS(runner, config)
case ManagerLVM:
if manager, err = newManagerLVM(runner, config); err != nil {
return nil, errors.Wrap(err, "failed to initialize LVM thin-clone manager")
}
default:
return nil, errors.New(fmt.Sprintf(`unsupported mode specified: "%s"`, mode))
return nil, errors.New(fmt.Sprintf(`unsupported thin-clone manager specified: "%s"`, mode))
}
log.Dbg(fmt.Sprintf(`Using "%s" mode.`, mode))
log.Dbg(fmt.Sprintf(`Using "%s" thin-clone manager.`, mode))
return manager, nil
}
......@@ -2,7 +2,7 @@
2019 © Postgres.ai
*/
package volumemanagers
package thinclones
import (
"strings"
......@@ -11,23 +11,23 @@ import (
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/resources"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/runners"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/volumemanagers/lvm"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/thinclones/lvm"
)
const (
poolPartsLen = 2
)
type volumeManagerLVM struct {
type managerLVM struct {
runner runners.Runner
config VolumeManagerConfig
config ManagerConfig
volumeGroup string
logicVolume string
}
// newVolumeManagerLVM creates a new VolumeManager instance for LVM.
func newVolumeManagerLVM(runner runners.Runner, config VolumeManagerConfig) (*volumeManagerLVM, error) {
m := volumeManagerLVM{}
// newManagerLVM creates a new Manager instance for LVM.
func newManagerLVM(runner runners.Runner, config ManagerConfig) (*managerLVM, error) {
m := managerLVM{}
m.runner = runner
m.config = config
......@@ -39,15 +39,15 @@ func newVolumeManagerLVM(runner runners.Runner, config VolumeManagerConfig) (*vo
return &m, nil
}
func (m *volumeManagerLVM) CreateClone(name, snapshotID string) error {
func (m *managerLVM) CreateClone(name, snapshotID string) error {
return lvm.CreateVolume(m.runner, m.volumeGroup, m.logicVolume, name, m.config.MountDir)
}
func (m *volumeManagerLVM) DestroyClone(name string) error {
func (m *managerLVM) DestroyClone(name string) error {
return lvm.RemoveVolume(m.runner, m.volumeGroup, m.logicVolume, name, m.config.MountDir)
}
func (m *volumeManagerLVM) ListClonesNames() ([]string, error) {
func (m *managerLVM) ListClonesNames() ([]string, error) {
volumes, err := lvm.ListVolumes(m.runner, m.volumeGroup)
if err != nil {
return nil, errors.Wrap(err, "failed to list LVM volumes")
......@@ -62,24 +62,24 @@ func (m *volumeManagerLVM) ListClonesNames() ([]string, error) {
return volumesNames, nil
}
func (m *volumeManagerLVM) GetSessionState(name string) (*resources.SessionState, error) {
func (m *managerLVM) GetSessionState(name string) (*resources.SessionState, error) {
// TODO(anatoly): Implement.
return &resources.SessionState{}, nil
}
func (m *volumeManagerLVM) GetDiskState() (*resources.Disk, error) {
func (m *managerLVM) GetDiskState() (*resources.Disk, error) {
// TODO(anatoly): Implement.
return &resources.Disk{}, nil
}
func (m *volumeManagerLVM) GetSnapshots() ([]resources.Snapshot, error) {
func (m *managerLVM) GetSnapshots() ([]resources.Snapshot, error) {
// TODO(anatoly): Not supported in LVM mode warning.
return []resources.Snapshot{resources.Snapshot{
ID: "default",
}}, nil
}
func (m *volumeManagerLVM) parsePool() error {
func (m *managerLVM) parsePool() error {
parts := strings.SplitN(m.config.Pool, "/", poolPartsLen)
if len(parts) < poolPartsLen {
return errors.Errorf(`failed to parse "pool" value from config`)
......
......@@ -2,7 +2,7 @@
2019 © Postgres.ai
*/
package volumemanagers
package thinclones
import (
"strings"
......@@ -11,21 +11,21 @@ import (
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/resources"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/runners"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/volumemanagers/zfs"
"gitlab.com/postgres-ai/database-lab/pkg/services/provision/thinclones/zfs"
)
const (
defaultSessionCloneSize = 10
)
type volumeManagerZFS struct {
type managerZFS struct {
runner runners.Runner
config VolumeManagerConfig
config ManagerConfig
}
// newVolumeManagerZFS creates a new VolumeManager instance for ZFS.
func newVolumeManagerZFS(runner runners.Runner, config VolumeManagerConfig) *volumeManagerZFS {
m := volumeManagerZFS{}
// newManagerZFS creates a new Manager instance for ZFS.
func newManagerZFS(runner runners.Runner, config ManagerConfig) *managerZFS {
m := managerZFS{}
m.runner = runner
m.config = config
......@@ -33,19 +33,19 @@ func newVolumeManagerZFS(runner runners.Runner, config VolumeManagerConfig) *vol
return &m
}
func (m *volumeManagerZFS) CreateClone(name, snapshotID string) error {
func (m *managerZFS) CreateClone(name, snapshotID string) error {
return zfs.CreateClone(m.runner, m.config.Pool, name, snapshotID, m.config.MountDir, m.config.OSUsername)
}
func (m *volumeManagerZFS) DestroyClone(name string) error {
func (m *managerZFS) DestroyClone(name string) error {
return zfs.DestroyClone(m.runner, m.config.Pool, name)
}
func (m *volumeManagerZFS) ListClonesNames() ([]string, error) {
func (m *managerZFS) ListClonesNames() ([]string, error) {
return zfs.ListClones(m.runner, m.config.ClonePrefix)
}
func (m *volumeManagerZFS) GetSessionState(name string) (*resources.SessionState, error) {
func (m *managerZFS) GetSessionState(name string) (*resources.SessionState, error) {
state := &resources.SessionState{
CloneSize: defaultSessionCloneSize,
}
......@@ -75,7 +75,7 @@ func (m *volumeManagerZFS) GetSessionState(name string) (*resources.SessionState
return state, nil
}
func (m *volumeManagerZFS) GetDiskState() (*resources.Disk, error) {
func (m *managerZFS) GetDiskState() (*resources.Disk, error) {
parts := strings.SplitN(m.config.Pool, "/", 2)
parentPool := parts[0]
......@@ -113,7 +113,7 @@ func (m *volumeManagerZFS) GetDiskState() (*resources.Disk, error) {
return disk, nil
}
func (m *volumeManagerZFS) GetSnapshots() ([]resources.Snapshot, error) {
func (m *managerZFS) GetSnapshots() ([]resources.Snapshot, error) {
entries, err := zfs.ListSnapshots(m.runner, m.config.Pool)
if err != nil {
return nil, errors.Wrap(err, "failed to list snapshots")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment