Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
use cluster-options for host volume configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Oshank Kumar <okumar@redhat.com>
  • Loading branch information
Oshank Kumar authored and aravindavk committed Jan 24, 2019
1 parent 13757cf commit ca3d113
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 28 deletions.
6 changes: 0 additions & 6 deletions glusterd2.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ clientaddress = ":24007"
#restauth enables/disables REST authentication in glusterd2
#restauth = true

#[block-hosting-vol-options]
block-hosting-volume-size = 5368709120 #5GiB
auto-create-block-hosting-volumes = true
block-hosting-volume-replica-count = 3
#block-hosting-volume-type = "Replicate"

#[gluster-block-client-config]
gluster-block-hostaddr = "192.168.122.16:8081"
#gluster-block-cacert = "/path/to/ca.crt"
Expand Down
5 changes: 5 additions & 0 deletions glusterd2/options/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ var ClusterOptMap = map[string]*ClusterOption{
"cluster.brick-multiplex": {"cluster.brick-multiplex", "off", OptionTypeBool, nil},
"cluster.max-bricks-per-process": {"cluster.max-bricks-per-process", "250", OptionTypeInt, nil},
"cluster.localtime-logging": {"cluster.localtime-logging", "off", OptionTypeBool, nil},
// setting cluster options for block hosting volume
"block-hosting-volume-size": {"block-hosting-volume-size", "5GiB", OptionTypeSizeList, nil},
"auto-create-block-hosting-volumes": {"auto-create-block-hosting-volumes", "true", OptionTypeBool, nil},
"block-hosting-volume-replica-count": {"block-hosting-volume-replica-count", "3", OptionTypeInt, nil},
"block-hosting-volume-type": {"block-hosting-volume-type", "Replicate", OptionTypeStr, nil},
}

// RegisterClusterOpValidationFunc registers a validation function for provided
Expand Down
12 changes: 5 additions & 7 deletions plugins/blockvolume/hostvol_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/gluster/glusterd2/plugins/blockvolume/utils"

log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

const (
Expand All @@ -34,13 +33,10 @@ type glusterVolManager struct {

// newGlusterVolManager returns a glusterVolManager instance
func newGlusterVolManager() *glusterVolManager {
var (
g = &glusterVolManager{}
hostVolOpts = &HostingVolumeOptions{}
)
g := &glusterVolManager{
hostVolOpts: newHostingVolumeOptions(),
}

hostVolOpts.ApplyFromConfig(viper.GetViper())
g.hostVolOpts = hostVolOpts
return g
}

Expand Down Expand Up @@ -71,6 +67,8 @@ func (g *glusterVolManager) GetOrCreateHostingVolume(name string, minSizeLimit u
}
defer clusterLocks.UnLock(context.Background())

g.hostVolOpts.SetFromClusterOptions()

// ERROR if If HostingVolume is not specified and auto-create-block-hosting-volumes is false
if name == "" && !g.hostVolOpts.AutoCreate {
err := errors.New("host volume is not provided and auto creation is not enabled")
Expand Down
62 changes: 47 additions & 15 deletions plugins/blockvolume/hostvol_opts.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
package blockvolume

import (
"strconv"

"github.com/gluster/glusterd2/glusterd2/options"
"github.com/gluster/glusterd2/pkg/api"
"github.com/gluster/glusterd2/pkg/size"

"github.com/pborman/uuid"
"github.com/spf13/viper"
)

// VolumeType represents a volume type
type VolumeType string

const (
// Replica represents a replica volume type
Replica VolumeType = "Replica"
defaultHostVolsize = size.GiB * 5
defaultHostVolType = "Replicate"
defaultHostVolReplicaCount = 3
hostVolautoCreate = true
)

// HostingVolumeOptions holds various information which will be used in creating hosting volume
type HostingVolumeOptions struct {
Size int64
Type VolumeType
Size size.Size
Type string
ReplicaCount int
AutoCreate bool
}

// ApplyFromConfig sets HostingVolumeOptions member values from given config source
func (h *HostingVolumeOptions) ApplyFromConfig(conf *viper.Viper) {
h.Size = conf.GetInt64("block-hosting-volume-size")
h.Type = VolumeType(conf.GetString("block-hosting-volume-type"))
h.ReplicaCount = conf.GetInt("block-hosting-volume-replica-count")
h.AutoCreate = conf.GetBool("auto-create-block-hosting-volumes")
func newHostingVolumeOptions() *HostingVolumeOptions {
return &HostingVolumeOptions{
Size: defaultHostVolsize,
Type: defaultHostVolType,
ReplicaCount: defaultHostVolReplicaCount,
AutoCreate: hostVolautoCreate,
}
}

// PrepareVolumeCreateReq will create a request body to be use for creating a gluster volume
Expand All @@ -40,8 +43,37 @@ func (h *HostingVolumeOptions) PrepareVolumeCreateReq() *api.VolCreateReq {
Transport: "tcp",
Size: uint64(h.Size),
ReplicaCount: h.ReplicaCount,
SubvolType: string(h.Type),
SubvolType: h.Type,
}

return req
}

// SetFromClusterOptions will configure HostingVolumeOptions using cluster options
func (h *HostingVolumeOptions) SetFromClusterOptions() {
volType, err := options.GetClusterOption("block-hosting-volume-type")
if err == nil {
h.Type = volType
}

volSize, err := options.GetClusterOption("block-hosting-volume-size")
if err == nil {
if hostVolSize, err := size.Parse(volSize); err == nil {
h.Size = hostVolSize
}
}

count, err := options.GetClusterOption("block-hosting-volume-replica-count")
if err == nil {
if replicaCount, err := strconv.Atoi(count); err == nil {
h.ReplicaCount = replicaCount
}
}

autoCreate, err := options.GetClusterOption("auto-create-block-hosting-volumes")
if err == nil {
if val, err := strconv.ParseBool(autoCreate); err == nil {
h.AutoCreate = val
}
}
}

0 comments on commit ca3d113

Please sign in to comment.