Skip to content

Commit

Permalink
Merge 8137449 into 4c9bbbf
Browse files Browse the repository at this point in the history
  • Loading branch information
Shruthi-1MN committed May 20, 2019
2 parents 4c9bbbf + 8137449 commit d0d1f8f
Show file tree
Hide file tree
Showing 16 changed files with 470 additions and 460 deletions.
3 changes: 3 additions & 0 deletions client/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestGetPool(t *testing.T) {
},
Name: "sample-pool-01",
Description: "This is the first sample storage pool for testing",
StorageType: "block",
TotalCapacity: int64(100),
FreeCapacity: int64(90),
DockId: "b7602e18-771e-11e7-8f38-dbd6d291f4e0",
Expand Down Expand Up @@ -71,6 +72,7 @@ func TestListPools(t *testing.T) {
},
Name: "sample-pool-01",
Description: "This is the first sample storage pool for testing",
StorageType: "block",
TotalCapacity: int64(100),
FreeCapacity: int64(90),
DockId: "b7602e18-771e-11e7-8f38-dbd6d291f4e0",
Expand All @@ -96,6 +98,7 @@ func TestListPools(t *testing.T) {
},
Name: "sample-pool-02",
Description: "This is the second sample storage pool for testing",
StorageType: "block",
TotalCapacity: int64(200),
FreeCapacity: int64(170),
DockId: "b7602e18-771e-11e7-8f38-dbd6d291f4e0",
Expand Down
1 change: 1 addition & 0 deletions install/devsds/lib/lvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pool:
diskType: NL-SAS
availabilityZone: default
multiAttach: true
storageType: block
extras:
dataStorage:
provisioningPolicy: Thin
Expand Down
21 changes: 13 additions & 8 deletions pkg/api/controllers/fileshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,20 @@ func (f *FileSharePortal) CreateFileShare() {
var err error
if fileshare.ProfileId == "" {
log.Warning("Use default profile when user doesn't specify profile.")
prf, err = db.C.GetDefaultProfile(ctx)
prf, err = db.C.GetDefaultProfileFileShare(ctx)
if err != nil {
errMsg := fmt.Sprintf("get profile failed: %s", err.Error())
f.ErrorHandle(model.ErrorBadRequest, errMsg)
return
}
fileshare.ProfileId = prf.Id
} else {
prf, err = db.C.GetProfile(ctx, fileshare.ProfileId)
}
if err != nil {
errMsg := fmt.Sprintf("get profile failed: %s", err.Error())
f.ErrorHandle(model.ErrorBadRequest, errMsg)
return
if err != nil {
errMsg := fmt.Sprintf("get profile failed: %s", err.Error())
f.ErrorHandle(model.ErrorBadRequest, errMsg)
return
}
}

// NOTE: It will create a file share entry into the database and initialize its status
Expand Down Expand Up @@ -309,10 +314,9 @@ func (f *FileSharePortal) DeleteFileShare() {
if err := db.C.DeleteFileShare(ctx, fileshare.Id); err != nil {
errMsg := fmt.Sprintf("delete file share failed: %v", err.Error())
f.ErrorHandle(model.ErrorInternalServer, errMsg)
f.SuccessHandle(StatusAccepted, nil)
return
}
f.SuccessHandle(StatusAccepted, nil)
return
}

// NOTE: It will update the the status of the file share waiting for deletion in
Expand All @@ -322,6 +326,7 @@ func (f *FileSharePortal) DeleteFileShare() {
f.ErrorHandle(model.ErrorBadRequest, errMsg)
return
}

prf, err := db.C.GetProfile(ctx, fileshare.ProfileId)
if err != nil {
errMsg := fmt.Sprintf("delete file share failed: %v", err.Error())
Expand Down
28 changes: 13 additions & 15 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"errors"
"fmt"
"net"

log "github.com/golang/glog"
"github.com/opensds/opensds/contrib/drivers/utils/config"
osdsCtx "github.com/opensds/opensds/pkg/context"
Expand Down Expand Up @@ -154,6 +153,8 @@ func (c *Controller) CreateVolume(contx context.Context, opt *pb.CreateVolumeOpt
opt.PoolId = polInfo.Id
opt.PoolName = polInfo.Name

log.V(8).Infof("select pool %v and poolinfo : %v for volume %+v", opt.PoolId, opt.PoolName, vol)

dockInfo, err := db.C.GetDock(ctx, polInfo.DockId)
if err != nil {
db.UpdateVolumeStatus(ctx, db.C, opt.Id, model.VolumeError)
Expand All @@ -163,6 +164,8 @@ func (c *Controller) CreateVolume(contx context.Context, opt *pb.CreateVolumeOpt
c.volumeController.SetDock(dockInfo)
opt.DriverName = dockInfo.DriverName

log.V(8).Infof("selected driver name for create volume %+v", opt.DriverName)

result, err := c.volumeController.CreateVolume(opt)
if err != nil {
// Change the status of the volume to error when the creation faild
Expand Down Expand Up @@ -870,23 +873,11 @@ func (c *Controller) DeleteVolumeGroup(contx context.Context, opt *pb.DeleteVolu
// CreateFileShare implements pb.ControllerServer.CreateFileShare
func (c *Controller) CreateFileShare(contx context.Context, opt *pb.CreateFileShareOpts) (*pb.GenericResponse, error) {
var err error
var prf *model.ProfileSpec

log.Info("Controller server receive create file share request, vr =", opt)

ctx := osdsCtx.NewContextFromJson(opt.GetContext())
if opt.Profile == "" {
log.Warning("Use default profile when user doesn't specify profile.")
prf, err = db.C.GetDefaultProfile(ctx)
opt.Profile = prf.Id
} else {
prf, err = db.C.GetProfile(ctx, opt.Profile)
}
if err != nil {
db.UpdateFileShareStatus(ctx, db.C, opt.Id, model.FileShareError)
log.Error("get profile failed: ", err)
return pb.GenericResponseError(err), err
}
prf := model.NewProfileFromJson(opt.Profile)

// This file share structure is currently fetched from database, but eventually
// it will be removed after SelectSupportedPoolForFileShare method in selector
Expand All @@ -896,11 +887,16 @@ func (c *Controller) CreateFileShare(contx context.Context, opt *pb.CreateFileSh
db.UpdateFileShareStatus(ctx, db.C, opt.Id, model.FileShareError)
return pb.GenericResponseError(err), err
}

log.V(5).Infof("controller create fleshare: get fileshare from db %+v", fileshare)

polInfo, err := c.selector.SelectSupportedPoolForFileShare(fileshare)
if err != nil {
db.UpdateFileShareStatus(ctx, db.C, opt.Id, model.FileShareError)
return pb.GenericResponseError(err), err
}

log.V(5).Infof("controller create fleshare: selected poolInfo %+v", polInfo)
// whether specify a pool or not, opt's poolid and pool name should be
// assigned by polInfo
opt.PoolId = polInfo.Id
Expand All @@ -915,14 +911,16 @@ func (c *Controller) CreateFileShare(contx context.Context, opt *pb.CreateFileSh
c.fileshareController.SetDock(dockInfo)
opt.DriverName = dockInfo.DriverName

log.V(5).Infof("controller create fleshare: selected Driver name %+v", opt.DriverName)

result, err := c.fileshareController.CreateFileShare((*pb.CreateFileShareOpts)(opt))
if err != nil {
// Change the status of the file share to error when the creation faild
defer db.UpdateFileShareStatus(ctx, db.C, opt.Id, model.FileShareError)
log.Error("when create file share:", err.Error())
return pb.GenericResponseError(err), err
}
result.PoolId, result.ProfileId = opt.GetPoolId(), opt.GetProfile()
result.PoolId, result.ProfileId = opt.GetPoolId(), prf.Id

// Update the file share data in database.
db.C.UpdateStatus(ctx, result, model.FileShareAvailable)
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/fileshare/filesharecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ func (c *controller) CreateFileShare(opt *pb.CreateFileShareOpts) (*model.FileSh
return nil, err
}

log.V(8).Infof("dock create fleshare: connected to dock endpoint : %+v", c.DockInfo.Endpoint)

response, err := c.Client.CreateFileShare(context.Background(), (opt))
if err != nil {
log.Error("create file share failed in file share controller:", err)
return nil, err
}
defer c.Client.Close()

log.V(8).Infof("dock create fleshare: Sent to driver : %+v", c.DockInfo.DriverName)

if errorMsg := response.GetError(); errorMsg != nil {
return nil,
fmt.Errorf("failed to create file share in file share controller, code: %v, message: %v",
Expand Down
21 changes: 14 additions & 7 deletions pkg/controller/selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func NewSelector() Selector {
func (s *selector) SelectSupportedPoolForVolume(vol *model.VolumeSpec) (*model.StoragePoolSpec, error) {
var prf *model.ProfileSpec
var err error

if vol.ProfileId == "" {
log.Warning("Use default profile when user doesn't specify profile.")
prf, err = db.C.GetDefaultProfile(c.NewAdminContext())
Expand Down Expand Up @@ -85,7 +84,7 @@ func (s *selector) SelectSupportedPoolForVolume(vol *model.VolumeSpec) (*model.S
if vol.PoolId != "" {
filterRequest["id"] = vol.PoolId
}

filterRequest["storageType"] = prf.StorageType
// Insert some rules of provisioning properties.
if pp := prf.ProvisioningProperties; !pp.IsEmpty() {
if ds := pp.DataStorage; !ds.IsEmpty() {
Expand Down Expand Up @@ -194,14 +193,19 @@ func (s *selector) SelectSupportedPoolForFileShare(in *model.FileShareSpec) (*mo

if in.ProfileId == "" {
log.Warning("use default profile when user doesn't specify profile.")
prf, err = db.C.GetDefaultProfile(c.NewAdminContext())
prf, err = db.C.GetDefaultProfileFileShare(c.NewAdminContext())
if err != nil {
log.Error("get profile failed: ", err)
return nil, err
}
} else {
prf, err = db.C.GetProfile(c.NewAdminContext(), in.ProfileId)
if err != nil {
log.Error("get profile failed: ", err)
return nil, err
}
}
if err != nil {
log.Error("get profile failed: ", err)
return nil, err
}

pools, err := db.C.ListPools(c.NewAdminContext())
if err != nil {
log.Error("when list pools in resources SelectSupportedPool: ", err)
Expand All @@ -226,6 +230,9 @@ func (s *selector) SelectSupportedPoolForFileShare(in *model.FileShareSpec) (*mo
if in.PoolId != "" {
filterRequest["id"] = in.PoolId
}

filterRequest["storageType"] = prf.StorageType

// Insert some rules of provisioning properties.
if pp := prf.ProvisioningProperties; !pp.IsEmpty() {
if ds := pp.DataStorage; !ds.IsEmpty() {
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/selector/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ var (
},
Name: "default",
Description: "default policy",
StorageType: "block",
},
{
BaseModel: &model.BaseModel{
Id: "2f9c0a04-66ef-11e7-ade2-43158893e017",
},
Name: "profile-01",
Description: "silver policy",
StorageType: "block",
ProvisioningProperties: model.ProvisioningPropertiesSpec{
DataStorage: model.DataStorageLoS{
ProvisioningPolicy: "Thin",
Expand Down Expand Up @@ -118,6 +120,7 @@ var (
},
Name: "profile-02",
Description: "silver policy",
StorageType: "block",
ProvisioningProperties: model.ProvisioningPropertiesSpec{
DataStorage: model.DataStorageLoS{
ProvisioningPolicy: "Thin",
Expand Down Expand Up @@ -158,6 +161,7 @@ var (
Description: "fake pool for testing",
Status: "available",
AvailabilityZone: "az1",
StorageType: "block",
TotalCapacity: 99999,
FreeCapacity: 5000,
DockId: "ccac4f33-e603-425a-8813-371bbe10566e",
Expand Down Expand Up @@ -187,6 +191,7 @@ var (
Name: "fakePool",
Description: "fake pool for testing",
Status: "available",
StorageType: "block",
AvailabilityZone: "az1",
TotalCapacity: 99999,
FreeCapacity: 6999,
Expand Down
4 changes: 3 additions & 1 deletion pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type Client interface {

GetDefaultProfile(ctx *c.Context) (*model.ProfileSpec, error)

GetDefaultProfileFileShare(ctx *c.Context) (*model.ProfileSpec, error)

ListProfiles(ctx *c.Context) ([]*model.ProfileSpec, error)

ListProfilesWithFilter(ctx *c.Context, m map[string][]string) ([]*model.ProfileSpec, error)
Expand Down Expand Up @@ -213,7 +215,7 @@ type Client interface {
}

func UpdateFileShareStatus(ctx *c.Context, client Client, fileID, status string) error {
file, _ := client.GetVolume(ctx, fileID)
file, _ := client.GetFileShare(ctx, fileID)
return client.UpdateStatus(ctx, file, status)
}

Expand Down
18 changes: 17 additions & 1 deletion pkg/db/drivers/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,23 @@ func (c *Client) GetDefaultProfile(ctx *c.Context) (*model.ProfileSpec, error) {
}

for _, profile := range profiles {
if profile.Name == "default" {
if profile.Name == "default" && profile.StorageType == "block"{
return profile, nil
}
}
return nil, errors.New("No default profile in db.")
}

// GetDefaultProfileFileShare
func (c *Client) GetDefaultProfileFileShare(ctx *c.Context) (*model.ProfileSpec, error) {
profiles, err := c.ListProfiles(ctx)
if err != nil {
log.Error("Get default profile failed in db: ", err)
return nil, err
}

for _, profile := range profiles {
if profile.Name == "default" && profile.StorageType == "file" {
return profile, nil
}
}
Expand Down
42 changes: 29 additions & 13 deletions pkg/dock/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ import (
log "github.com/golang/glog"
"github.com/opensds/opensds/contrib/connector"
"github.com/opensds/opensds/contrib/drivers"
fd "github.com/opensds/opensds/contrib/drivers/filesharedrivers"
c "github.com/opensds/opensds/pkg/context"
"github.com/opensds/opensds/pkg/db"
"github.com/opensds/opensds/pkg/model"
. "github.com/opensds/opensds/pkg/utils/config"
"github.com/opensds/opensds/contrib/drivers/utils/config"
"github.com/opensds/opensds/pkg/utils"
uuid "github.com/satori/go.uuid"
)

Expand Down Expand Up @@ -126,12 +129,37 @@ func (pdd *provisionDockDiscoverer) Init() error {
return nil
}

var filesharedrivers = []string{config.NFSDriverType}

func (pdd *provisionDockDiscoverer) Discover() error {
// Clear existing pool info
pdd.pols = pdd.pols[:0]
var pols []*model.StoragePoolSpec
var err error
for _, dck := range pdd.dcks {
// Call function of StorageDrivers configured by storage drivers.
pols, err := drivers.Init(dck.DriverName).ListPools()
if utils.Contains(filesharedrivers, dck.DriverName) {
pols, err = fd.Init(dck.DriverName).ListPools()
for _, pol := range pols {
log.Infof("Backend %s discovered pool %s", dck.DriverName, pol.Name)
pol.DockId = dck.Id
}
} else {
pols, err = drivers.Init(dck.DriverName).ListPools()

replicationDriverName := dck.Metadata["HostReplicationDriver"]
replicationType := model.ReplicationTypeHost
if drivers.IsSupportHostBasedReplication(dck.DriverName) {
replicationType = model.ReplicationTypeArray
replicationDriverName = dck.DriverName
}
for _, pol := range pols {
log.Infof("Backend %s discovered pool %s", dck.DriverName, pol.Name)
pol.DockId = dck.Id
pol.ReplicationType = replicationType
pol.ReplicationDriverName = replicationDriverName
}
}
if err != nil {
log.Error("Call driver to list pools failed:", err)
continue
Expand All @@ -141,18 +169,6 @@ func (pdd *provisionDockDiscoverer) Discover() error {
log.Warningf("The pool of dock %s is empty!\n", dck.Id)
}

replicationDriverName := dck.Metadata["HostReplicationDriver"]
replicationType := model.ReplicationTypeHost
if drivers.IsSupportHostBasedReplication(dck.DriverName) {
replicationType = model.ReplicationTypeArray
replicationDriverName = dck.DriverName
}
for _, pol := range pols {
log.Infof("Backend %s discovered pool %s", dck.DriverName, pol.Name)
pol.DockId = dck.Id
pol.ReplicationType = replicationType
pol.ReplicationDriverName = replicationDriverName
}
pdd.pols = append(pdd.pols, pols...)
}
if len(pdd.pols) == 0 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/dock/dock.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ func (ds *dockServer) CreateFileShare(ctx context.Context, opt *pb.CreateFileSha

log.Info("Dock server receive create file share request, vr =", opt)

log.V(8).Infof("Dock server create fleshare: sent to Driver %+v", opt.GetDriverName())

fileshare, err := ds.FileShareDriver.CreateFileShare(opt)
if err != nil {
log.Error("when create file share in dock module:", err)
Expand Down
Loading

0 comments on commit d0d1f8f

Please sign in to comment.