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

feature: define the interface and http api of preheat #1242

Merged
merged 1 commit into from
May 8, 2020

Conversation

lowzj
Copy link
Member

@lowzj lowzj commented Mar 12, 2020

Signed-off-by: lowzj [email protected]

Ⅰ. Describe what this PR did

This pull request defines the interface and http api of preheat.

Ⅱ. Does this pull request fix one issue?

#1115

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

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-io
Copy link

codecov-io commented Mar 12, 2020

Codecov Report

Merging #1242 into master will decrease coverage by 0.26%.
The diff coverage is 23.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1242      +/-   ##
==========================================
- Coverage   51.41%   51.14%   -0.27%     
==========================================
  Files         125      126       +1     
  Lines        8241     8321      +80     
==========================================
+ Hits         4237     4256      +19     
- Misses       3661     3720      +59     
- Partials      343      345       +2     
Impacted Files Coverage Δ
supernode/server/preheat_bridge.go 21.33% <21.33%> (ø)
supernode/server/server.go 43.07% <50.00%> (+0.45%) ⬆️
supernode/server/router.go 66.10% <100.00%> (+0.58%) ⬆️

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 0d3e9b2...435eb38. Read the comment docs.

@lowzj lowzj force-pushed the preheat branch 2 times, most recently from e5b326b to ced0538 Compare March 18, 2020 07:04

"github.com/dragonflyoss/Dragonfly/apis/types"
"github.com/dragonflyoss/Dragonfly/pkg/errortypes"
"github.com/go-openapi/strfmt"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a blank line here.

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

id := mux.Vars(req)["id"]
task, err := s.PreheatMgr.Get(ctx, id)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

You defined a code of StatusNotFound, while I am wondering if the code here could return the code of 404?

Copy link
Member Author

Choose a reason for hiding this comment

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

PreheatMgr returns the error with a proper code and methodhandlePreheatErrorResponse convert the error to error response and send to user.

Get(ctx context.Context, id string) (task *PreheatTask, err error)

// Delete deletes a preheat task by id.
Delete(ctx context.Context, id string) (err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add the Delete endpoint if the swagger.yml? Since I have not found that.
I am afraid that we should define the API in swagger.yml first, and then implement that in code.

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

// Handle error if request handling fails.
handlePreheatErrorResponse(w, err)
}
logrus.Debugf("%v err:%v", req.URL, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not print this line if err is equal to nil. But the code here would print that no matter what value the err is.

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's a debug level log that indicates a request has been processed and what result is. It represents the process is success if the err is nil.

@lowzj lowzj force-pushed the preheat branch 2 times, most recently from 4a37394 to 20a39ed Compare March 18, 2020 12:07
@lowzj lowzj changed the title [WIP] feature: define the interface and http api of preheat feature: define the interface and http api of preheat Mar 18, 2020
@lowzj lowzj force-pushed the preheat branch 2 times, most recently from da7adf1 to 7a31b77 Compare March 24, 2020 14:41
@lowzj
Copy link
Member Author

lowzj commented Mar 25, 2020

@allencloud PTAL

return (string)(ps)
}

// PreheatTask store the detailed preheat task information.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/store/stores

)

// PreheatStatus
type PreheatStatus string
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 defining it with go-swager?

@lowzj lowzj force-pushed the preheat branch 2 times, most recently from 157bb4b to a4a4e07 Compare April 8, 2020 07:12
@lowzj
Copy link
Member Author

lowzj commented Apr 8, 2020

@starnop @allencloud PTAL

@lowzj lowzj force-pushed the preheat branch 3 times, most recently from 80304d1 to 4fbbaa1 Compare April 10, 2020 01:18
@starnop
Copy link
Contributor

starnop commented Apr 15, 2020

@starnop @allencloud PTAL

Sorry for the late reply. I will finish the review today.

Delete(ctx context.Context, id string) (err error)

// GetAll gets all preheat tasks that unexpired.
GetAll(ctx context.Context) (task []*PreheatTask, err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

update "task" to "preheatTask" in order to avoid ambiguity.

}
resp := types.PreheatInfo{
ID: task.ID,
FinishTime: strfmt.DateTime{},
Copy link
Contributor

Choose a reason for hiding this comment

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

use strfmt .NewDateTime() instead?

Identifier string
Headers map[string]string

ParentID string
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the fields "ParentID" and "Children" for? And how about add comments here?

@lowzj lowzj force-pushed the preheat branch 3 times, most recently from 64e65f2 to 99918a7 Compare April 22, 2020 15:49
@lowzj
Copy link
Member Author

lowzj commented Apr 22, 2020

@allencloud @starnop PTAL

@allencloud
Copy link
Contributor

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label May 8, 2020
@allencloud allencloud merged commit 0ca3333 into dragonflyoss:master May 8, 2020
sungjunyoung pushed a commit to sungjunyoung/Dragonfly that referenced this pull request May 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants