Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
nolouch committed May 16, 2017
1 parent 5b6b0ad commit d13a80e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions server/api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ package api
import (
"net/http"

"github.com/gorilla/mux"
"github.com/juju/errors"
"github.com/pingcap/pd/server"
"github.com/unrolled/render"
)

var errUnknownStatusOption = errors.New("unKnown status option")

type clusterHandler struct {
svr *server.Server
rd *render.Render
Expand All @@ -37,10 +41,16 @@ func (h *clusterHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

func (h *clusterHandler) GetRaftClusterBootstrapTime(w http.ResponseWriter, r *http.Request) {
data, err := h.svr.GetRaftClusterBootstrapTime()
if err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
option := mux.Vars(r)["bootstrap_time"]
switch option {
case option:
data, err := h.svr.GetRaftClusterBootstrapTime()
if err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
h.rd.JSON(w, http.StatusOK, data)
default:
h.rd.JSON(w, http.StatusInternalServerError, errUnknownStatusOption.Error())
}
h.rd.JSON(w, http.StatusOK, data)
}
2 changes: 1 addition & 1 deletion server/api/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *testClusterInfo) TestCluster(c *C) {
}

func (s *testClusterInfo) TestGetBootstrapTime(c *C) {
url := fmt.Sprintf("%s/raft/bootstrap/time", s.urlPrefix)
url := fmt.Sprintf("%s/cluster/raft/status/bootstrap_time", s.urlPrefix)
var t, now time.Time
err := readJSONWithURL(url, t)
c.Assert(err, NotNil)
Expand Down
2 changes: 1 addition & 1 deletion server/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func createRouter(prefix string, svr *server.Server) *mux.Router {
router.HandleFunc("/api/v1/schedulers/{name}", schedulerHandler.Delete).Methods("DELETE")

router.Handle("/api/v1/cluster", newClusterHandler(svr, rd)).Methods("GET")
router.HandleFunc("/api/v1/raft/bootstrap/time", newClusterHandler(svr, rd).GetRaftClusterBootstrapTime).Methods("GET")
router.HandleFunc("/api/v1/cluster/raft/status/{option}", newClusterHandler(svr, rd).GetRaftClusterBootstrapTime).Methods("GET")

confHandler := newConfHandler(svr, rd)
router.HandleFunc("/api/v1/config", confHandler.Get).Methods("GET")
Expand Down

0 comments on commit d13a80e

Please sign in to comment.