Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

refactor: define api register of supernode #1346

Merged
merged 1 commit into from
May 28, 2020

Conversation

lowzj
Copy link
Member

@lowzj lowzj commented May 15, 2020

Signed-off-by: lowzj [email protected]

Ⅰ. Describe what this PR did

define and expose the api register of supernode to make it possible to add APIs outside.

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@lowzj lowzj changed the title refactor: define api register of supernode to add api refactor: define api register of supernode May 15, 2020
@codecov-io
Copy link

Codecov Report

Merging #1346 into master will decrease coverage by 0.00%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1346      +/-   ##
==========================================
- Coverage   51.35%   51.35%   -0.01%     
==========================================
  Files         130      130              
  Lines        8576     8578       +2     
==========================================
+ Hits         4404     4405       +1     
- Misses       3804     3806       +2     
+ Partials      368      367       -1     
Impacted Files Coverage Δ
dfget/locator/locator.go 100.00% <ø> (ø)
dfget/locator/static_locator.go 68.49% <0.00%> (-1.93%) ⬇️
supernode/server/router.go 67.21% <ø> (ø)
supernode/daemon/mgr/scheduler/manager.go 22.60% <0.00%> (+0.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d499c51...82fd0ea. Read the comment docs.

registerAPI(LegacyCategory, h)
}

func registerAPI(c *Category, h *HandlerSpec) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about to allow register user-defined Category, may be we want to register more than one groups of API.

Copy link
Member Author

@lowzj lowzj May 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think about it again, it's better to provide an extension category with prefix /api/ext for users to register APIs. Users can group their own customized APIs in this extension category, not in Dragonfly core APIs category, like /api/ext/groupA, /api/ext/b.
WDYT?

Copy link
Member Author

@lowzj lowzj May 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET /api/ext

And supernode provides the above API to list the current registered extension APIs.


// ParseJSONRequest parses the request parameter formed by JSON to a object.
func ParseJSONRequest(body io.Reader, request interface{}, validator ValidateFunc) error {
if err := json.NewDecoder(body).Decode(request); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add validation of "body == nil " and "request == nil" ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should return 400 response in this case.

"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/dragonflyoss/Dragonfly/apis/types"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self-project import path may be better in second part.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@lowzj lowzj force-pushed the api-register branch 2 times, most recently from 214e875 to 552ded5 Compare May 22, 2020 10:43
@codecov-commenter
Copy link

codecov-commenter commented May 22, 2020

Codecov Report

Merging #1346 into master will increase coverage by 0.33%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1346      +/-   ##
==========================================
+ Coverage   51.46%   51.80%   +0.33%     
==========================================
  Files         133      135       +2     
  Lines        8744     8803      +59     
==========================================
+ Hits         4500     4560      +60     
  Misses       3866     3866              
+ Partials      378      377       -1     
Impacted Files Coverage Δ
supernode/server/router.go 67.21% <ø> (ø)
supernode/server/api/api.go 100.00% <100.00%> (ø)
supernode/server/api/utils.go 100.00% <100.00%> (ø)
supernode/daemon/mgr/scheduler/manager.go 22.60% <0.00%> (+0.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3945cdb...71bde95. Read the comment docs.

"net/http"
)

// HandlerSpec describes a HTTP api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/a/an


const (
// VersionedPrefix is recommended, any new API should start with this prefix.
VersionedPrefix = "/api/v1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/VersionedPrefix/V1VersionedPrefix
Maybe we will add v2,v3 API version in the future. 😄

@lowzj lowzj force-pushed the api-register branch 2 times, most recently from 57b5cac to 72e1efc Compare May 26, 2020 09:01
@lowzj lowzj force-pushed the api-register branch 5 times, most recently from b25637a to c84f55b Compare May 26, 2020 09:38
@starnop
Copy link
Contributor

starnop commented May 28, 2020

LGTM.

@starnop starnop merged commit f1bd6e8 into dragonflyoss:master May 28, 2020
@lowzj lowzj deleted the api-register branch May 28, 2020 06:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants