func getPeerHandler(w http.ResponseWriter, r *http.Request) { p := mux.Vars(r) id := p["peerid"] if id == "" { rest.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()) } else { rest.SendHTTPResponse(w, http.StatusOK, peer) } }
// NewBrickEntries creates the brick list func NewBrickEntries(bricks []string) ([]brick.Brickinfo, error) { var brickInfos []brick.Brickinfo var binfo brick.Brickinfo for _, b := range bricks { host, path, e := utils.ParseHostAndBrickPath(b) if e != nil { return nil, e } binfo.Path, e = absFilePath(path) if e != nil { log.Error("Failed to convert the brickpath to absolute path") return nil, e } u := uuid.Parse(host) if u != nil { // Host specified is UUID binfo.ID = u p, e := peer.GetPeerF(host) if e != nil { return nil, e } binfo.Hostname = p.Addresses[0] } else { binfo.ID, e = peer.GetPeerIDByAddrF(host) if e != nil { return nil, e } binfo.Hostname = host } brickInfos = append(brickInfos, binfo) } return brickInfos, nil }
func deletePeerHandler(w http.ResponseWriter, r *http.Request) { // FIXME: This is not txn based, yet. Behaviour when multiple simultaneous // delete peer requests are sent to same node is unknown. peerReq := mux.Vars(r) id := peerReq["peerid"] if id == "" { rest.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") return } // Removing self should be disallowed (like in glusterd1) if id == gdctx.MyUUID.String() { rest.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()) return } // Validate whether the peer can be deleted rsp, e := ValidateDeletePeer(remotePeerAddress, id) if e != nil { rest.SendHTTPError(w, http.StatusInternalServerError, rsp.OpError) return } // Remove the peer from the store if e := peer.DeletePeer(id); e != nil { log.WithFields(log.Fields{ "er": e, "peer": id, }).Error("Failed to remove peer from the store") rest.SendHTTPError(w, http.StatusInternalServerError, e.Error()) } else { rest.SendHTTPResponse(w, http.StatusNoContent, nil) } // Delete member from etcd cluster e = etcdmgmt.EtcdMemberRemove(p.MemberID) if e != nil { log.WithFields(log.Fields{ "er": e, "peer": id, }).Error("Failed to remove member from etcd cluster") rest.SendHTTPError(w, http.StatusInternalServerError, e.Error()) return } // Remove data dir of etcd on remote machine. Restart etcd on remote machine // in standalone (single cluster) mode. var etcdConf EtcdConfigReq etcdConf.DeletePeer = true 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) return } }
// RunStepOn will run the step on the specified node func RunStepOn(step string, node uuid.UUID, c TxnCtx) (TxnCtx, error) { // TODO: I'm creating connections on demand. This should be changed so that // we have long term connections. p, err := peer.GetPeerF(node.String()) if err != nil { c.Logger().WithFields(log.Fields{ "peerid": node.String(), "error": err, }).Error("peer not found") return nil, err } logger := c.Logger().WithField("remotepeer", p.ID.String()+"("+p.Name+")") var conn *grpc.ClientConn remote, err := utils.FormRemotePeerAddress(p.Addresses[0]) if err != nil { return nil, err } conn, err = grpc.Dial(remote, grpc.WithInsecure()) if err == nil && conn != nil { logger.WithFields(log.Fields{ "remote": remote, }).Debug("connected to remote") } if conn == nil { logger.WithFields(log.Fields{ "error": err, "remote": p.Addresses, }).Error("failed to grpc.Dial remote") return nil, err } defer conn.Close() client := NewTxnSvcClient(conn) req := &TxnStepReq{ StepFunc: step, } data, err := json.Marshal(c) if err != nil { logger.WithError(err).Error("failed to JSON marshal transaction context") return nil, err } req.Context = data var rsp *TxnStepResp rsp, err = client.RunStep(netctx.TODO(), req) if err != nil { logger.WithFields(log.Fields{ "error": err, "rpc": "TxnSvc.RunStep", }).Error("failed RPC call") return nil, err } if rsp.Error != "" { logger.WithError(errors.New(rsp.Error)).Error("TxnSvc.Runstep failed on peer") return nil, errors.New(rsp.Error) } rspCtx := new(Tctx) err = json.Unmarshal(rsp.Resp, rspCtx) if err != nil { logger.WithError(err).Error("failed to JSON unmarhsal transaction context") } return rspCtx, err }