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

Commit

Permalink
store peer address provided during
Browse files Browse the repository at this point in the history
peer add in ETCD.

if peer address already present in store
update configuration on startup

this allows the users to use peer address
provided during peer add, for any other
operations(ex:- volume create,expand)

Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>
  • Loading branch information
Madhu-1 committed May 23, 2018
1 parent 199dcb8 commit b55d6a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions glusterd2/commands/peers/addpeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,18 @@ func addPeerHandler(w http.ResponseWriter, r *http.Request) {
newpeer.Metadata[key] = value
}

//check if remotePeerAddress already present
found := utils.StringInSlice(remotePeerAddress, newpeer.PeerAddresses)
//if not found prepend the remotePeerAddress to peer details
if !found {
newpeer.PeerAddresses = append([]string{remotePeerAddress}, newpeer.PeerAddresses...)
}

err = peer.AddOrUpdatePeer(newpeer)
if err != nil {
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "Fail to add metadata to peer")
}

resp := createPeerAddResp(newpeer)
restutils.SendHTTPResponse(ctx, w, http.StatusCreated, resp)

Expand Down
11 changes: 11 additions & 0 deletions glusterd2/peer/self.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/gluster/glusterd2/glusterd2/gdctx"
"github.com/gluster/glusterd2/pkg/errors"
"github.com/gluster/glusterd2/pkg/utils"

config "github.com/spf13/viper"
)
Expand Down Expand Up @@ -47,6 +48,7 @@ func AddSelfDetails() error {
Name: gdctx.HostName,
PeerAddresses: []string{config.GetString("peeraddress")},
}

p.ClientAddresses, err = normalizeAddrs()
if err != nil {
return err
Expand All @@ -56,8 +58,17 @@ func AddSelfDetails() error {
if err == errors.ErrPeerNotFound {
p.Metadata = make(map[string]string)
p.Metadata["_zone"] = p.ID.String()

} else if err == nil && peerInfo != nil {
p.Metadata = peerInfo.Metadata

found := utils.StringInSlice(p.PeerAddresses[0], peerInfo.PeerAddresses)
if !found {
p.PeerAddresses = append(peerInfo.PeerAddresses, p.PeerAddresses...)
} else {
p.PeerAddresses = peerInfo.PeerAddresses
}

} else {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/peerutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// FormRemotePeerAddress will check and validate peeraddress provided. It will
// return an address of the form <ip:port>
// return an address of the form <host:port>
func FormRemotePeerAddress(peeraddress string) (string, error) {

host, port, err := net.SplitHostPort(peeraddress)
Expand Down

0 comments on commit b55d6a7

Please sign in to comment.