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

Commit 1361dcd

Browse files
committed
Updating the endpoints documentation
1 parent 9d7681f commit 1361dcd

File tree

4 files changed

+63
-38
lines changed

4 files changed

+63
-38
lines changed

doc/endpoints.md

Lines changed: 19 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package volumecommands
2+
3+
import (
4+
"github.com/gluster/glusterd2/glusterd2/daemon"
5+
"github.com/gluster/glusterd2/glusterd2/transaction"
6+
rebalance "github.com/gluster/glusterd2/plugins/rebalance"
7+
rebalanceapi "github.com/gluster/glusterd2/plugins/rebalance/api"
8+
)
9+
10+
func startRebalance(c transaction.TxnCtx) error {
11+
var rinfo rebalanceapi.RebalInfo
12+
err := c.Get("rinfo", &rinfo)
13+
if err != nil {
14+
return err
15+
}
16+
17+
rebalanceProcess, err := rebalance.NewRebalanceProcess(rinfo)
18+
if err != nil {
19+
return err
20+
}
21+
22+
err = daemon.Start(rebalanceProcess, true, c.Logger())
23+
24+
return err
25+
}

glusterd2/commands/volumes/volume-shrink.go

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"path/filepath"
77
"strings"
88

9-
"github.com/gluster/glusterd2/glusterd2/daemon"
9+
"github.com/gluster/glusterd2/glusterd2/events"
1010
"github.com/gluster/glusterd2/glusterd2/gdctx"
1111
restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils"
1212
"github.com/gluster/glusterd2/glusterd2/transaction"
@@ -26,23 +26,6 @@ func registerVolShrinkStepFuncs() {
2626
transaction.RegisterStepFunc(startRebalance, "vol-shrink.StartRebalance")
2727
}
2828

29-
func startRebalance(c transaction.TxnCtx) error {
30-
var rinfo rebalanceapi.RebalInfo
31-
err := c.Get("rinfo", &rinfo)
32-
if err != nil {
33-
return err
34-
}
35-
36-
rebalanceProcess, err := rebalance.NewRebalanceProcess(rinfo)
37-
if err != nil {
38-
return err
39-
}
40-
41-
err = daemon.Start(rebalanceProcess, true)
42-
43-
return err
44-
}
45-
4629
func validateVolumeShrinkReq(req api.VolShrinkReq) error {
4730
dupEntry := map[string]bool{}
4831

@@ -100,7 +83,7 @@ func volumeShrinkHandler(w http.ResponseWriter, r *http.Request) {
10083
}
10184
}
10285
if !isPresent {
103-
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "One or more brick is not part of given volume")
86+
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "One or more bricks is not part of given volume")
10487
return
10588
}
10689
}
@@ -148,19 +131,20 @@ func volumeShrinkHandler(w http.ResponseWriter, r *http.Request) {
148131
if err != nil {
149132
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
150133
return
151-
152134
}
153135

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

158-
var rinfo rebalanceapi.RebalInfo
159-
rinfo.Volname = volname
160-
rinfo.RebalanceID = uuid.NewRandom()
161-
rinfo.Cmd = rebalanceapi.CmdStartForce
162-
rinfo.State = rebalanceapi.NotStarted
163-
rinfo.CommitHash = rebalance.SetCommitHash()
139+
rinfo := rebalanceapi.RebalInfo{
140+
Volname: volname,
141+
RebalanceID: uuid.NewRandom(),
142+
Cmd: rebalanceapi.CmdStartForce,
143+
State: rebalanceapi.NotStarted,
144+
CommitHash: rebalance.SetCommitHash(),
145+
RebalStats: []rebalanceapi.RebalNodeStatus{},
146+
}
147+
164148
if err := txn.Ctx.Set("rinfo", rinfo); err != nil {
165149
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
166150
return
@@ -173,19 +157,18 @@ func volumeShrinkHandler(w http.ResponseWriter, r *http.Request) {
173157

174158
if err = txn.Do(); err != nil {
175159
logger.WithError(err).Error("remove bricks start transaction failed")
176-
if err == transaction.ErrLockTimeout {
177-
restutils.SendHTTPError(ctx, w, http.StatusConflict, err)
178-
} else {
179-
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
180-
}
160+
status, err := restutils.ErrToStatusCode(err)
161+
restutils.SendHTTPError(ctx, w, status, err)
181162
return
182163
}
183-
164+
logger.WithField("volume-name", volinfo.Name).Info("volume shrink successful")
165+
events.Broadcast(volume.NewEvent(volume.EventVolumeShrink, volinfo))
184166
restutils.SendHTTPResponse(ctx, w, http.StatusOK, decommissionedSubvols)
185167

186168
}
187169

188170
func findDecommissioned(bricks []api.BrickReq, volinfo *volume.Volinfo) (string, error) {
171+
189172
brickSet := make(map[string]bool)
190173
for _, brick := range bricks {
191174
u := uuid.Parse(brick.PeerID)
@@ -209,7 +192,6 @@ func findDecommissioned(bricks []api.BrickReq, volinfo *volume.Volinfo) (string,
209192
subvolMap[subvol.Name] = count + 1
210193
}
211194
}
212-
213195
}
214196
}
215197

glusterd2/volume/events.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const (
1313
EventVolumeCreated Event = "volume.created"
1414
// EventVolumeExpanded represents Volume Expand event
1515
EventVolumeExpanded = "volume.expanded"
16+
// EventVolumeShrink represents Volume Shrink event
17+
EventVolumeShrink = "volume.shrink"
1618
// EventVolumeStarted represents Volume Start event
1719
EventVolumeStarted = "volume.started"
1820
// EventVolumeStopped represents Volume Stop event

0 commit comments

Comments
 (0)