Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
modify 1.0 bridge
Browse files Browse the repository at this point in the history
Signed-off-by: yunfeiyangbuaa <[email protected]>
  • Loading branch information
yunfeiyanggzq committed Dec 15, 2019
1 parent e77febc commit 5f45806
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
18 changes: 9 additions & 9 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -324,7 +324,7 @@ paths:
500:
$ref: "#/responses/500ErrorResponse"

/tasks:
/api/v1/tasks:
post:
summary: "create a task"
description: |
Expand All @@ -347,7 +347,7 @@ paths:
500:
$ref: "#/responses/500ErrorResponse"

/tasks/{id}:
/api/v1/tasks/{id}:
get:
summary: "get a task"
description: |
Expand Down Expand Up @@ -431,7 +431,7 @@ paths:
500:
$ref: "#/responses/500ErrorResponse"

/tasks/{id}/pieces:
/api/v1/tasks/{id}/pieces:
get:
summary: "Get pieces in task"
description: |
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -557,7 +557,7 @@ paths:
500:
$ref: "#/responses/500ErrorResponse"

/preheats:
/api/v1/preheats:
post:
summary: "Create a Preheat Task"
description: |
Expand Down Expand Up @@ -603,7 +603,7 @@ paths:
500:
$ref: "#/responses/500ErrorResponse"

/preheats/{id}:
/api/v1/preheats/{id}:
get:
summary: "Get a preheat task"
description: |
Expand Down
13 changes: 7 additions & 6 deletions supernode/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
10 changes: 10 additions & 0 deletions supernode/server/task_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

0 comments on commit 5f45806

Please sign in to comment.