diff --git a/apis/swagger.yml b/apis/swagger.yml index 660ea81d8..73b1c33fc 100644 --- a/apis/swagger.yml +++ b/apis/swagger.yml @@ -219,7 +219,7 @@ paths: 500: $ref: "#/responses/500ErrorResponse" - /peers: + /api/v1/peers: post: summary: "register dfget in Supernode as a peer node" description: "dfget sends request to register in Supernode as a peer node" @@ -280,7 +280,7 @@ paths: 500: $ref: "#/responses/500ErrorResponse" - /peers/{id}: + /api/v1/peers/{id}: get: summary: "get a peer in supernode" description: "return low-level information of a peer in supernode." @@ -324,7 +324,7 @@ paths: 500: $ref: "#/responses/500ErrorResponse" - /tasks: + /api/v1/tasks: post: summary: "create a task" description: | @@ -347,7 +347,7 @@ paths: 500: $ref: "#/responses/500ErrorResponse" - /tasks/{id}: + /api/v1/tasks/{id}: get: summary: "get a task" description: | @@ -431,7 +431,7 @@ paths: 500: $ref: "#/responses/500ErrorResponse" - /tasks/{id}/pieces: + /api/v1/tasks/{id}/pieces: get: summary: "Get pieces in task" description: | @@ -481,7 +481,7 @@ paths: 500: $ref: "#/responses/500ErrorResponse" - /tasks/{id}/pieces/{pieceRange}: + /api/v1/tasks/{id}/pieces/{pieceRange}: put: summary: "Update a piece" description: | @@ -520,7 +520,7 @@ paths: 500: $ref: "#/responses/500ErrorResponse" - /tasks/{id}/pieces/{pieceRange}/error: + /api/v1/tasks/{id}/pieces/{pieceRange}/error: post: summary: "report a piece error" description: | @@ -557,7 +557,7 @@ paths: 500: $ref: "#/responses/500ErrorResponse" - /preheats: + /api/v1/preheats: post: summary: "Create a Preheat Task" description: | @@ -603,7 +603,7 @@ paths: 500: $ref: "#/responses/500ErrorResponse" - /preheats/{id}: + /api/v1/preheats/{id}: get: summary: "Get a preheat task" description: | diff --git a/supernode/server/router.go b/supernode/server/router.go index 0f770fed4..cb4121135 100644 --- a/supernode/server/router.go +++ b/supernode/server/router.go @@ -51,16 +51,17 @@ func initRoute(s *Server) *mux.Router { // v1 // peer - {Method: http.MethodPost, Path: "/peers", HandlerFunc: s.registerPeer}, - {Method: http.MethodDelete, Path: "/peers/{id}", HandlerFunc: s.deRegisterPeer}, - {Method: http.MethodGet, Path: "/peers/{id}", HandlerFunc: s.getPeer}, - {Method: http.MethodGet, Path: "/peers", HandlerFunc: s.listPeers}, + {Method: http.MethodPost, Path: "/api/v1/peers", HandlerFunc: s.registerPeer}, + {Method: http.MethodDelete, Path: "/api/v1/peers/{id}", HandlerFunc: s.deRegisterPeer}, + {Method: http.MethodGet, Path: "/api/v1/peers/{id}", HandlerFunc: s.getPeer}, + {Method: http.MethodGet, Path: "/api/v1/peers", HandlerFunc: s.listPeers}, + {Method: http.MethodGet, Path: "/api/v1/tasks/{id}", HandlerFunc: s.getTaskInfo}, // task - {Method: http.MethodDelete, Path: "/tasks/{id}", HandlerFunc: s.deleteTask}, + {Method: http.MethodDelete, Path: "/api/v1/tasks/{id}", HandlerFunc: s.deleteTask}, // piece - {Method: http.MethodGet, Path: "/tasks/{id}/pieces/{pieceRange}/error", HandlerFunc: s.handlePieceError}, + {Method: http.MethodGet, Path: "/api/v1/tasks/{id}/pieces/{pieceRange}/error", HandlerFunc: s.handlePieceError}, // metrics {Method: http.MethodGet, Path: "/metrics", HandlerFunc: handleMetrics}, diff --git a/supernode/server/task_bridge.go b/supernode/server/task_bridge.go index 23fe49414..3d990cbaa 100644 --- a/supernode/server/task_bridge.go +++ b/supernode/server/task_bridge.go @@ -34,3 +34,13 @@ func (s *Server) deleteTask(ctx context.Context, rw http.ResponseWriter, req *ht rw.WriteHeader(http.StatusOK) return nil } + +func (s *Server) getTaskInfo(ctx context.Context, rw http.ResponseWriter, req *http.Request) (err error) { + id := mux.Vars(req)["id"] + task, err := s.TaskMgr.Get(ctx, id) + if err != nil { + return err + } + return EncodeResponse(rw, http.StatusOK, task) + +}