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

Commit

Permalink
Merge pull request #225 from kshlm/suture-supervisor-trees
Browse files Browse the repository at this point in the history
Refactor all the servers/listeners
  • Loading branch information
kshlm authored Jan 31, 2017
2 parents d557683 + 3e91d19 commit 5ed497a
Show file tree
Hide file tree
Showing 41 changed files with 568 additions and 375 deletions.
4 changes: 2 additions & 2 deletions commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"github.com/gluster/glusterd2/commands/peers"
"github.com/gluster/glusterd2/commands/version"
"github.com/gluster/glusterd2/commands/volumes"
"github.com/gluster/glusterd2/rest"
"github.com/gluster/glusterd2/servers/rest/route"
)

// Command is the interface that needs to be implemented by the GlusterD commands
type Command interface {
// Routes should return a table of REST API endpoints and handlers for the command
Routes() rest.Routes
Routes() route.Routes
// RegisterStepFuncs will register the transaction StepFuncs for the command
RegisterStepFuncs()
}
Expand Down
22 changes: 11 additions & 11 deletions commands/peers/addpeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gluster/glusterd2/errors"
"github.com/gluster/glusterd2/etcdmgmt"
"github.com/gluster/glusterd2/peer"
"github.com/gluster/glusterd2/rest"
restutils "github.com/gluster/glusterd2/servers/rest/utils"
"github.com/gluster/glusterd2/utils"

log "github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -39,12 +39,12 @@ func addPeerHandler(w http.ResponseWriter, r *http.Request) {

var req PeerAddReq
if e := utils.GetJSONFromRequest(r, &req); e != nil {
rest.SendHTTPError(w, http.StatusBadRequest, e.Error())
restutils.SendHTTPError(w, http.StatusBadRequest, e.Error())
return
}

if len(req.Addresses) < 1 {
rest.SendHTTPError(w, http.StatusBadRequest, errors.ErrNoHostnamesPresent.Error())
restutils.SendHTTPError(w, http.StatusBadRequest, errors.ErrNoHostnamesPresent.Error())
return
}

Expand All @@ -53,21 +53,21 @@ func addPeerHandler(w http.ResponseWriter, r *http.Request) {

remotePeerAddress, err := utils.FormRemotePeerAddress(req.Addresses[0])
if err != nil {
rest.SendHTTPError(w, http.StatusBadRequest, err.Error())
restutils.SendHTTPError(w, http.StatusBadRequest, err.Error())
return
}

// This remote call will return the remote peer's ID (UUID), name
// and etcd peer url.
remotePeer, e := ValidateAddPeer(remotePeerAddress, &req)
if e != nil {
rest.SendHTTPError(w, http.StatusInternalServerError, remotePeer.OpError)
restutils.SendHTTPError(w, http.StatusInternalServerError, remotePeer.OpError)
return
}

// TODO: Parse addresses considering ports to figure this out.
if isPeerInCluster(remotePeer.UUID) {
rest.SendHTTPError(w, http.StatusInternalServerError, "Peer already in cluster")
restutils.SendHTTPError(w, http.StatusInternalServerError, "Peer already in cluster")
return
}

Expand All @@ -93,7 +93,7 @@ func addPeerHandler(w http.ResponseWriter, r *http.Request) {
"name": req.Name,
"address": remotePeer.EtcdPeerAddress,
}).Error("Failed to add member to etcd cluster.")
rest.SendHTTPError(w, http.StatusInternalServerError, e.Error())
restutils.SendHTTPError(w, http.StatusInternalServerError, e.Error())
return
}

Expand All @@ -102,7 +102,7 @@ func addPeerHandler(w http.ResponseWriter, r *http.Request) {
mlist, e := etcdmgmt.EtcdMemberList()
if e != nil {
log.WithField("error", e).Error("Failed to list members in etcd cluster")
rest.SendHTTPError(w, http.StatusInternalServerError, e.Error())
restutils.SendHTTPError(w, http.StatusInternalServerError, e.Error())
return
}

Expand All @@ -128,7 +128,7 @@ func addPeerHandler(w http.ResponseWriter, r *http.Request) {
etcdrsp, e := ConfigureRemoteETCD(remotePeerAddress, &etcdConf)
if e != nil {
log.WithField("err", e).Error("Failed to configure remote etcd")
rest.SendHTTPError(w, http.StatusInternalServerError, etcdrsp.OpError)
restutils.SendHTTPError(w, http.StatusInternalServerError, etcdrsp.OpError)
return
}

Expand All @@ -144,10 +144,10 @@ func addPeerHandler(w http.ResponseWriter, r *http.Request) {
"error": e,
"peer/node": p.Name,
}).Error("Failed to add peer into the etcd store")
rest.SendHTTPError(w, http.StatusInternalServerError, e.Error())
restutils.SendHTTPError(w, http.StatusInternalServerError, e.Error())
return
}

body := map[string]uuid.UUID{"id": p.ID}
rest.SendHTTPResponse(w, http.StatusCreated, body)
restutils.SendHTTPResponse(w, http.StatusCreated, body)
}
14 changes: 7 additions & 7 deletions commands/peers/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@
package peercommands

import (
"github.com/gluster/glusterd2/rest"
"github.com/gluster/glusterd2/servers/rest/route"
)

// Command is a holding struct used to implement the GlusterD Command interface
type Command struct {
}

// Routes returns command routes. Required for the Command interface.
func (c *Command) Routes() rest.Routes {
return rest.Routes{
rest.Route{
func (c *Command) Routes() route.Routes {
return route.Routes{
route.Route{
Name: "GetPeer",
Method: "GET",
Pattern: "/peers/{peerid}",
Version: 1,
HandlerFunc: getPeerHandler,
},
rest.Route{
route.Route{
Name: "GetPeers",
Method: "GET",
Pattern: "/peers",
Version: 1,
HandlerFunc: getPeersHandler,
},
rest.Route{
route.Route{
Name: "DeletePeer",
Method: "DELETE",
Pattern: "/peers/{peerid}",
Version: 1,
HandlerFunc: deletePeerHandler,
},
rest.Route{
route.Route{
Name: "AddPeer",
Method: "POST",
Pattern: "/peers",
Expand Down
20 changes: 10 additions & 10 deletions commands/peers/deletepeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/gluster/glusterd2/etcdmgmt"
"github.com/gluster/glusterd2/gdctx"
"github.com/gluster/glusterd2/peer"
"github.com/gluster/glusterd2/rest"
restutils "github.com/gluster/glusterd2/servers/rest/utils"
"github.com/gluster/glusterd2/utils"

log "github.com/Sirupsen/logrus"
Expand All @@ -22,32 +22,32 @@ func deletePeerHandler(w http.ResponseWriter, r *http.Request) {

id := peerReq["peerid"]
if id == "" {
rest.SendHTTPError(w, http.StatusBadRequest, "peerid not present in the request")
restutils.SendHTTPError(w, http.StatusBadRequest, "peerid not present in the request")
return
}
// Check whether the member exists
p, e := peer.GetPeerF(id)
if e != nil || p == nil {
rest.SendHTTPError(w, http.StatusNotFound, "peer not found in cluster")
restutils.SendHTTPError(w, http.StatusNotFound, "peer not found in cluster")
return
}

// Removing self should be disallowed (like in glusterd1)
if id == gdctx.MyUUID.String() {
rest.SendHTTPError(w, http.StatusBadRequest, "Removing self is disallowed.")
restutils.SendHTTPError(w, http.StatusBadRequest, "Removing self is disallowed.")
return
}

remotePeerAddress, err := utils.FormRemotePeerAddress(p.Addresses[0])
if err != nil {
rest.SendHTTPError(w, http.StatusBadRequest, err.Error())
restutils.SendHTTPError(w, http.StatusBadRequest, err.Error())
return
}

// Validate whether the peer can be deleted
rsp, e := ValidateDeletePeer(remotePeerAddress, id)
if e != nil {
rest.SendHTTPError(w, http.StatusInternalServerError, rsp.OpError)
restutils.SendHTTPError(w, http.StatusInternalServerError, rsp.OpError)
return
}

Expand All @@ -57,9 +57,9 @@ func deletePeerHandler(w http.ResponseWriter, r *http.Request) {
"er": e,
"peer": id,
}).Error("Failed to remove peer from the store")
rest.SendHTTPError(w, http.StatusInternalServerError, e.Error())
restutils.SendHTTPError(w, http.StatusInternalServerError, e.Error())
} else {
rest.SendHTTPResponse(w, http.StatusNoContent, nil)
restutils.SendHTTPResponse(w, http.StatusNoContent, nil)
}

// Delete member from etcd cluster
Expand All @@ -70,7 +70,7 @@ func deletePeerHandler(w http.ResponseWriter, r *http.Request) {
"peer": id,
}).Error("Failed to remove member from etcd cluster")

rest.SendHTTPError(w, http.StatusInternalServerError, e.Error())
restutils.SendHTTPError(w, http.StatusInternalServerError, e.Error())
return
}

Expand All @@ -81,7 +81,7 @@ func deletePeerHandler(w http.ResponseWriter, r *http.Request) {
etcdrsp, e := ConfigureRemoteETCD(remotePeerAddress, &etcdConf)
if e != nil {
log.WithField("err", e).Error("Failed to configure remote etcd.")
rest.SendHTTPError(w, http.StatusInternalServerError, etcdrsp.OpError)
restutils.SendHTTPError(w, http.StatusInternalServerError, etcdrsp.OpError)
return
}
}
8 changes: 4 additions & 4 deletions commands/peers/getpeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/gluster/glusterd2/peer"
"github.com/gluster/glusterd2/rest"
restutils "github.com/gluster/glusterd2/servers/rest/utils"

"github.com/gorilla/mux"
)
Expand All @@ -14,13 +14,13 @@ func getPeerHandler(w http.ResponseWriter, r *http.Request) {

id := p["peerid"]
if id == "" {
rest.SendHTTPError(w, http.StatusBadRequest, "peerid not present in request")
restutils.SendHTTPError(w, http.StatusBadRequest, "peerid not present in request")
return
}

if peer, err := peer.GetPeerF(id); err != nil {
rest.SendHTTPError(w, http.StatusNotFound, err.Error())
restutils.SendHTTPError(w, http.StatusNotFound, err.Error())
} else {
rest.SendHTTPResponse(w, http.StatusOK, peer)
restutils.SendHTTPResponse(w, http.StatusOK, peer)
}
}
6 changes: 3 additions & 3 deletions commands/peers/getpeers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"net/http"

"github.com/gluster/glusterd2/peer"
"github.com/gluster/glusterd2/rest"
restutils "github.com/gluster/glusterd2/servers/rest/utils"
)

func getPeersHandler(w http.ResponseWriter, r *http.Request) {
if peers, err := peer.GetPeersF(); err != nil {
rest.SendHTTPError(w, http.StatusNotFound, err.Error())
restutils.SendHTTPError(w, http.StatusNotFound, err.Error())
} else {
rest.SendHTTPResponse(w, http.StatusOK, peers)
restutils.SendHTTPResponse(w, http.StatusOK, peers)
}
}
4 changes: 2 additions & 2 deletions commands/peers/peer-rpc-svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/gluster/glusterd2/etcdmgmt"
"github.com/gluster/glusterd2/gdctx"
"github.com/gluster/glusterd2/peer"
"github.com/gluster/glusterd2/rpc/server"
"github.com/gluster/glusterd2/servers/peerrpc"
"github.com/gluster/glusterd2/volume"

log "github.com/Sirupsen/logrus"
Expand All @@ -19,7 +19,7 @@ import (
type PeerService int

func init() {
server.Register(new(PeerService))
peerrpc.Register(new(PeerService))
}

// RegisterService registers a service
Expand Down
8 changes: 4 additions & 4 deletions commands/version/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
package versioncommands

import (
"github.com/gluster/glusterd2/rest"
"github.com/gluster/glusterd2/servers/rest/route"
)

// Command is a holding struct used to implement the GlusterD Command interface
type Command struct {
}

// Routes returns command routes. Required for the Command interface.
func (c *Command) Routes() rest.Routes {
return rest.Routes{
rest.Route{
func (c *Command) Routes() route.Routes {
return route.Routes{
route.Route{
Name: "GetVersion",
Method: "GET",
Pattern: "/version",
Expand Down
4 changes: 2 additions & 2 deletions commands/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/gluster/glusterd2/gdctx"
"github.com/gluster/glusterd2/rest"
restutils "github.com/gluster/glusterd2/servers/rest/utils"
)

// Response represents the structure of the response object for /version
Expand All @@ -19,5 +19,5 @@ func getVersionHandler(w http.ResponseWriter, r *http.Request) {
var v Response
v.GlusterdVersion = gdctx.GlusterdVersion
v.APIVersion = gdctx.APIVersion
rest.SendHTTPResponse(w, http.StatusOK, v)
restutils.SendHTTPResponse(w, http.StatusOK, v)
}
20 changes: 10 additions & 10 deletions commands/volumes/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@
package volumecommands

import (
"github.com/gluster/glusterd2/rest"
"github.com/gluster/glusterd2/servers/rest/route"
)

// Command is a holding struct used to implement the GlusterD Command interface
type Command struct {
}

// Routes returns command routes. Required for the Command interface.
func (c *Command) Routes() rest.Routes {
return rest.Routes{
rest.Route{
func (c *Command) Routes() route.Routes {
return route.Routes{
route.Route{
Name: "VolumeCreate",
Method: "POST",
Pattern: "/volumes",
Version: 1,
HandlerFunc: volumeCreateHandler},
rest.Route{
route.Route{
Name: "VolumeDelete",
Method: "DELETE",
Pattern: "/volumes/{volname}",
Version: 1,
HandlerFunc: volumeDeleteHandler},
rest.Route{
route.Route{
Name: "VolumeInfo",
Method: "GET",
Pattern: "/volumes/{volname}",
Version: 1,
HandlerFunc: volumeInfoHandler},
rest.Route{
route.Route{
Name: "VolumeStatus",
Method: "GET",
Pattern: "/volumes/{volname}/status",
Version: 1,
HandlerFunc: volumeStatusHandler},
rest.Route{
route.Route{
Name: "VolumeList",
Method: "GET",
Pattern: "/volumes",
Version: 1,
HandlerFunc: volumeListHandler},
rest.Route{
route.Route{
Name: "VolumeStart",
Method: "POST",
Pattern: "/volumes/{volname}/start",
Version: 1,
HandlerFunc: volumeStartHandler},
rest.Route{
route.Route{
Name: "VolumeStop",
Method: "POST",
Pattern: "/volumes/{volname}/stop",
Expand Down
Loading

0 comments on commit 5ed497a

Please sign in to comment.