|
@@ -13,7 +13,7 @@ import (
|
|
|
|
|
|
|
|
// Get all the current logs
|
|
// Get all the current logs
|
|
|
func GetLogHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
func GetLogHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
- debug("[recv] GET http://%v/log", raftServer.Name())
|
|
|
|
|
|
|
+ debug("[recv] GET %s/log", raftTransporter.scheme+raftServer.Name())
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
json.NewEncoder(w).Encode(raftServer.LogEntries())
|
|
json.NewEncoder(w).Encode(raftServer.LogEntries())
|
|
@@ -24,7 +24,7 @@ func VoteHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
rvreq := &raft.RequestVoteRequest{}
|
|
rvreq := &raft.RequestVoteRequest{}
|
|
|
err := decodeJsonRequest(req, rvreq)
|
|
err := decodeJsonRequest(req, rvreq)
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
- debug("[recv] POST http://%v/vote [%s]", raftServer.Name(), rvreq.CandidateName)
|
|
|
|
|
|
|
+ debug("[recv] POST %s/vote [%s]", raftTransporter.scheme+raftServer.Name(), rvreq.CandidateName)
|
|
|
if resp := raftServer.RequestVote(rvreq); resp != nil {
|
|
if resp := raftServer.RequestVote(rvreq); resp != nil {
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
json.NewEncoder(w).Encode(resp)
|
|
json.NewEncoder(w).Encode(resp)
|
|
@@ -41,7 +41,7 @@ func AppendEntriesHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
err := decodeJsonRequest(req, aereq)
|
|
err := decodeJsonRequest(req, aereq)
|
|
|
|
|
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
- debug("[recv] POST http://%s/log/append [%d]", raftServer.Name(), len(aereq.Entries))
|
|
|
|
|
|
|
+ debug("[recv] POST %s/log/append [%d]", raftTransporter.scheme+raftServer.Name(), len(aereq.Entries))
|
|
|
if resp := raftServer.AppendEntries(aereq); resp != nil {
|
|
if resp := raftServer.AppendEntries(aereq); resp != nil {
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
json.NewEncoder(w).Encode(resp)
|
|
json.NewEncoder(w).Encode(resp)
|
|
@@ -60,7 +60,7 @@ func SnapshotHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
aereq := &raft.SnapshotRequest{}
|
|
aereq := &raft.SnapshotRequest{}
|
|
|
err := decodeJsonRequest(req, aereq)
|
|
err := decodeJsonRequest(req, aereq)
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
- debug("[recv] POST http://%s/snapshot/ ", raftServer.Name())
|
|
|
|
|
|
|
+ debug("[recv] POST %s/snapshot/ ", raftTransporter.scheme+raftServer.Name())
|
|
|
if resp := raftServer.RequestSnapshot(aereq); resp != nil {
|
|
if resp := raftServer.RequestSnapshot(aereq); resp != nil {
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
json.NewEncoder(w).Encode(resp)
|
|
json.NewEncoder(w).Encode(resp)
|
|
@@ -76,7 +76,7 @@ func SnapshotRecoveryHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
aereq := &raft.SnapshotRecoveryRequest{}
|
|
aereq := &raft.SnapshotRecoveryRequest{}
|
|
|
err := decodeJsonRequest(req, aereq)
|
|
err := decodeJsonRequest(req, aereq)
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
- debug("[recv] POST http://%s/snapshotRecovery/ ", raftServer.Name())
|
|
|
|
|
|
|
+ debug("[recv] POST %s/snapshotRecovery/ ", raftTransporter.scheme+raftServer.Name())
|
|
|
if resp := raftServer.SnapshotRecoveryRequest(aereq); resp != nil {
|
|
if resp := raftServer.SnapshotRecoveryRequest(aereq); resp != nil {
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
json.NewEncoder(w).Encode(resp)
|
|
json.NewEncoder(w).Encode(resp)
|
|
@@ -89,7 +89,7 @@ func SnapshotRecoveryHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
|
|
|
// Get the port that listening for client connecting of the server
|
|
// Get the port that listening for client connecting of the server
|
|
|
func ClientHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
func ClientHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
- debug("[recv] Get http://%v/client/ ", raftServer.Name())
|
|
|
|
|
|
|
+ debug("[recv] Get %s/client/ ", raftTransporter.scheme+raftServer.Name())
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
client := hostname + ":" + strconv.Itoa(clientPort)
|
|
client := hostname + ":" + strconv.Itoa(clientPort)
|
|
|
w.Write([]byte(client))
|
|
w.Write([]byte(client))
|