mirror of
https://github.com/gluster/glusterd2.git
synced 2026-02-05 12:45:38 +01:00
store peer address provided during
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>
This commit is contained in:
@@ -3,6 +3,7 @@ package peercommands
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/gluster/glusterd2/glusterd2/events"
|
||||
@@ -99,10 +100,22 @@ 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...)
|
||||
} else {
|
||||
index := sort.StringSlice(newpeer.PeerAddresses).Search(remotePeerAddress)
|
||||
//swap peer address to index 0
|
||||
sort.StringSlice(newpeer.PeerAddresses).Swap(0, index)
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -47,6 +48,7 @@ func AddSelfDetails() error {
|
||||
Name: gdctx.HostName,
|
||||
PeerAddresses: []string{config.GetString("peeraddress")},
|
||||
}
|
||||
|
||||
p.ClientAddresses, err = normalizeAddrs()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user