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

Commit

Permalink
Updating the endpoints documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rishubhjain committed Jun 18, 2018
1 parent 9d7681f commit 1361dcd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 38 deletions.
22 changes: 19 additions & 3 deletions doc/endpoints.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions glusterd2/commands/volumes/volume-shrink-txn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package volumecommands

import (
"github.com/gluster/glusterd2/glusterd2/daemon"
"github.com/gluster/glusterd2/glusterd2/transaction"
rebalance "github.com/gluster/glusterd2/plugins/rebalance"
rebalanceapi "github.com/gluster/glusterd2/plugins/rebalance/api"
)

func startRebalance(c transaction.TxnCtx) error {
var rinfo rebalanceapi.RebalInfo
err := c.Get("rinfo", &rinfo)
if err != nil {
return err
}

rebalanceProcess, err := rebalance.NewRebalanceProcess(rinfo)
if err != nil {
return err
}

err = daemon.Start(rebalanceProcess, true, c.Logger())

return err
}
52 changes: 17 additions & 35 deletions glusterd2/commands/volumes/volume-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"

"github.com/gluster/glusterd2/glusterd2/daemon"
"github.com/gluster/glusterd2/glusterd2/events"
"github.com/gluster/glusterd2/glusterd2/gdctx"
restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils"
"github.com/gluster/glusterd2/glusterd2/transaction"
Expand All @@ -26,23 +26,6 @@ func registerVolShrinkStepFuncs() {
transaction.RegisterStepFunc(startRebalance, "vol-shrink.StartRebalance")
}

func startRebalance(c transaction.TxnCtx) error {
var rinfo rebalanceapi.RebalInfo
err := c.Get("rinfo", &rinfo)
if err != nil {
return err
}

rebalanceProcess, err := rebalance.NewRebalanceProcess(rinfo)
if err != nil {
return err
}

err = daemon.Start(rebalanceProcess, true)

return err
}

func validateVolumeShrinkReq(req api.VolShrinkReq) error {
dupEntry := map[string]bool{}

Expand Down Expand Up @@ -100,7 +83,7 @@ func volumeShrinkHandler(w http.ResponseWriter, r *http.Request) {
}
}
if !isPresent {
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "One or more brick is not part of given volume")
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "One or more bricks is not part of given volume")
return
}
}
Expand Down Expand Up @@ -148,19 +131,20 @@ func volumeShrinkHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
return

}

// The following line is for testing purposes.
// It seems that there is no other way to include this information in the rebalance volfile right now.
// TODO: Find a better wat to store information in the rebalance volfile.
volinfo.Options["distribute.decommissioned-bricks"] = strings.TrimSpace(decommissionedSubvols)

var rinfo rebalanceapi.RebalInfo
rinfo.Volname = volname
rinfo.RebalanceID = uuid.NewRandom()
rinfo.Cmd = rebalanceapi.CmdStartForce
rinfo.State = rebalanceapi.NotStarted
rinfo.CommitHash = rebalance.SetCommitHash()
rinfo := rebalanceapi.RebalInfo{
Volname: volname,
RebalanceID: uuid.NewRandom(),
Cmd: rebalanceapi.CmdStartForce,
State: rebalanceapi.NotStarted,
CommitHash: rebalance.SetCommitHash(),
RebalStats: []rebalanceapi.RebalNodeStatus{},
}

if err := txn.Ctx.Set("rinfo", rinfo); err != nil {
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
return
Expand All @@ -173,19 +157,18 @@ func volumeShrinkHandler(w http.ResponseWriter, r *http.Request) {

if err = txn.Do(); err != nil {
logger.WithError(err).Error("remove bricks start transaction failed")
if err == transaction.ErrLockTimeout {
restutils.SendHTTPError(ctx, w, http.StatusConflict, err)
} else {
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
}
status, err := restutils.ErrToStatusCode(err)
restutils.SendHTTPError(ctx, w, status, err)
return
}

logger.WithField("volume-name", volinfo.Name).Info("volume shrink successful")
events.Broadcast(volume.NewEvent(volume.EventVolumeShrink, volinfo))
restutils.SendHTTPResponse(ctx, w, http.StatusOK, decommissionedSubvols)

}

func findDecommissioned(bricks []api.BrickReq, volinfo *volume.Volinfo) (string, error) {

brickSet := make(map[string]bool)
for _, brick := range bricks {
u := uuid.Parse(brick.PeerID)
Expand All @@ -209,7 +192,6 @@ func findDecommissioned(bricks []api.BrickReq, volinfo *volume.Volinfo) (string,
subvolMap[subvol.Name] = count + 1
}
}

}
}

Expand Down
2 changes: 2 additions & 0 deletions glusterd2/volume/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const (
EventVolumeCreated Event = "volume.created"
// EventVolumeExpanded represents Volume Expand event
EventVolumeExpanded = "volume.expanded"
// EventVolumeShrink represents Volume Shrink event
EventVolumeShrink = "volume.shrink"
// EventVolumeStarted represents Volume Start event
EventVolumeStarted = "volume.started"
// EventVolumeStopped represents Volume Stop event
Expand Down

0 comments on commit 1361dcd

Please sign in to comment.