Skip to content

Commit

Permalink
remove all unnecessary named imports, clean up cluster/database.go
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev committed Dec 16, 2015
1 parent 803a2df commit 4541a8d
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 235 deletions.
4 changes: 2 additions & 2 deletions api/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/libopenstorage/openstorage/api"
apiserver "github.com/libopenstorage/openstorage/api/server"
"github.com/libopenstorage/openstorage/api/server"
"github.com/libopenstorage/openstorage/config"
"github.com/libopenstorage/openstorage/volume"
"github.com/libopenstorage/openstorage/volume/drivers/nfs"
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestAll(t *testing.T) {
if err != nil {
t.Fatalf("Failed to initialize Driver: %v", err)
}
apiserver.StartServerAPI(nfs.Name, 9003, config.DriverAPIBase)
server.StartServerAPI(nfs.Name, 9003, config.DriverAPIBase)
time.Sleep(time.Second * 2)
c, err := NewDriverClient(nfs.Name)
if err != nil {
Expand Down
38 changes: 19 additions & 19 deletions api/server/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path"
"strconv"

types "github.com/libopenstorage/openstorage/api"
"github.com/libopenstorage/openstorage/api"
"github.com/libopenstorage/openstorage/config"
"github.com/libopenstorage/openstorage/volume"
)
Expand Down Expand Up @@ -42,7 +42,7 @@ type volumePathResponse struct {
}

type volumeInfo struct {
vol *types.Volume
vol *api.Volume
}

func newVolumePlugin(name string) restServer {
Expand Down Expand Up @@ -90,11 +90,11 @@ func (d *driver) volFromName(name string) (*volumeInfo, error) {
if err != nil {
return nil, fmt.Errorf("Cannot locate volume driver for %s: %s", d.name, err.Error())
}
vols, err := v.Inspect([]types.VolumeID{types.VolumeID(name)})
vols, err := v.Inspect([]api.VolumeID{api.VolumeID(name)})
if err == nil && len(vols) == 1 {
return &volumeInfo{vol: &vols[0]}, nil
}
vols, err = v.Enumerate(types.VolumeLocator{Name: name}, nil)
vols, err = v.Enumerate(api.VolumeLocator{Name: name}, nil)
if err == nil && len(vols) == 1 {
return &volumeInfo{vol: &vols[0]}, nil
}
Expand Down Expand Up @@ -128,28 +128,28 @@ func (d *driver) status(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, fmt.Sprintln("osd plugin", d.version))
}

func (d *driver) specFromOpts(Opts map[string]string) *types.VolumeSpec {
var spec types.VolumeSpec
func (d *driver) specFromOpts(Opts map[string]string) *api.VolumeSpec {
var spec api.VolumeSpec
for k, v := range Opts {
switch k {
case types.SpecEphemeral:
case api.SpecEphemeral:
spec.Ephemeral, _ = strconv.ParseBool(v)
case types.SpecSize:
case api.SpecSize:
spec.Size, _ = strconv.ParseUint(v, 10, 64)
case types.SpecFilesystem:
spec.Format = types.Filesystem(v)
case types.SpecBlockSize:
case api.SpecFilesystem:
spec.Format = api.Filesystem(v)
case api.SpecBlockSize:
blockSize, _ := strconv.ParseInt(v, 10, 64)
spec.BlockSize = int(blockSize)
case types.SpecHaLevel:
case api.SpecHaLevel:
haLevel, _ := strconv.ParseInt(v, 10, 64)
spec.HALevel = int(haLevel)
case types.SpecCos:
case api.SpecCos:
cos, _ := strconv.ParseInt(v, 10, 64)
spec.Cos = types.VolumeCos(cos)
case types.SpecDedupe:
spec.Cos = api.VolumeCos(cos)
case api.SpecDedupe:
spec.Dedupe, _ = strconv.ParseBool(v)
case types.SpecSnapshotInterval:
case api.SpecSnapshotInterval:
snapshotInterval, _ := strconv.ParseInt(v, 10, 64)
spec.SnapshotInterval = int(snapshotInterval)
}
Expand All @@ -175,7 +175,7 @@ func (d *driver) create(w http.ResponseWriter, r *http.Request) {
return
}
spec := d.specFromOpts(request.Opts)
_, err = v.Create(types.VolumeLocator{Name: request.Name}, nil, spec)
_, err = v.Create(api.VolumeLocator{Name: request.Name}, nil, spec)
if err != nil {
json.NewEncoder(w).Encode(&volumeResponse{Err: err})
return
Expand Down Expand Up @@ -232,7 +232,7 @@ func (d *driver) mount(w http.ResponseWriter, r *http.Request) {
}

// If this is a block driver, first attach the volume.
if v.Type()&types.Block != 0 {
if v.Type()&api.Block != 0 {
attachPath, err := v.Attach(volInfo.vol.ID)
if err != nil {
d.logReq(method, request.Name).Warnf("Cannot attach volume: %v", err.Error())
Expand Down Expand Up @@ -321,7 +321,7 @@ func (d *driver) unmount(w http.ResponseWriter, r *http.Request) {
return
}

if v.Type()&types.Block != 0 {
if v.Type()&api.Block != 0 {
_ = v.Detach(volInfo.vol.ID)
}
d.emptyResponse(w)
Expand Down
52 changes: 20 additions & 32 deletions cluster/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,48 @@ import (
"encoding/json"
"strings"

"github.com/Sirupsen/logrus"
"github.com/libopenstorage/openstorage/api"

log "github.com/Sirupsen/logrus"

kv "github.com/portworx/kvdb"
"github.com/portworx/kvdb"
)

func readDatabase() (Database, error) {
kvdb := kv.Instance()
kvdb := kvdb.Instance()

db := Database{Status: api.StatusInit,
NodeEntries: make(map[string]NodeEntry)}

kv, err := kvdb.Get("cluster/database")
if err != nil && !strings.Contains(err.Error(), "Key not found") {
log.Warn("Warning, could not read cluster database")
goto done
logrus.Warn("Warning, could not read cluster database")
return db, err
}

if kv == nil || bytes.Compare(kv.Value, []byte("{}")) == 0 {
log.Info("Cluster is uninitialized...")
err = nil
goto done
} else {
err = json.Unmarshal(kv.Value, &db)
if err != nil {
log.Warn("Fatal, Could not parse cluster database ", kv)
goto done
}
logrus.Info("Cluster is uninitialized...")
return db, nil
}
if err := json.Unmarshal(kv.Value, &db); err != nil {
logrus.Warn("Fatal, Could not parse cluster database ", kv)
return db, err
}

done:
return db, err
return db, nil
}

func writeDatabase(db *Database) error {
kvdb := kv.Instance()
kvdb := kvdb.Instance()
b, err := json.Marshal(db)
if err != nil {
log.Warn("Fatal, Could not marshal cluster database to JSON")
goto done
logrus.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
return err
}

_, err = kvdb.Put("cluster/database", b, 0)
if err != nil {
log.Warn("Fatal, Could not marshal cluster database to JSON")
goto done
if _, err := kvdb.Put("cluster/database", b, 0); err != nil {
logrus.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
return err
}

log.Info("Cluster database updated.")

done:
if err != nil {
log.Println(err)
}
return err
logrus.Info("Cluster database updated.")
return nil
}
Loading

0 comments on commit 4541a8d

Please sign in to comment.