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

refactor: refactor dfget/core with SupernodeLocator #1325

Merged
merged 1 commit into from
May 13, 2020

Conversation

lowzj
Copy link
Member

@lowzj lowzj commented May 6, 2020

Signed-off-by: lowzj [email protected]

Ⅰ. Describe what this PR did

This pull request uses interface SupernodeLocator to refactor the dfget/core to get supernode list instead of configurations.
It also provides a way for users to customized their own SupernodeLocator to replace the default implementation, for example:

package main

import (
    "github.com/dragonflyoss/Dragonfly/cmd/dfget/app"
    "github.com/dragonflyoss/Dragonfly/dfget/config"
    "github.com/dragonflyoss/Dragonfly/dfget/locator"
)

func init() {
    // use customized implementation to replace default one
    // execute it in the `init` function
    // or move it into `main` function, before `app.Execute()`
    locator.RegisterLocator(func(cfg *config.Config) locator.SupernodeLocator {
        return NewDynamicLocator(cfg)
    })
}

// customized implementation of SupernodeLocator

func NewDynamicLocator(cfg *config.Config) *DynamicLocator {
    return &DynamicLocator{}
}

var _ locator.SupernodeLocator = &DynamicLocator{}

type DynamicLocator struct {
}
// implementation the interface SupernodeLocator here

func main() {
    app.Execute()
}

Ⅱ. Does this pull request fix one issue?

fixes: #1293

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

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@lowzj lowzj force-pushed the refactor-dfget-core-with-locator branch from 1bdfa6b to 1d5d7b6 Compare May 6, 2020 13:25
@lowzj lowzj changed the title refactor: refactor dfget/core with SupernodeLocator [WIP] refactor: refactor dfget/core with SupernodeLocator May 6, 2020
@lowzj lowzj force-pushed the refactor-dfget-core-with-locator branch from 1d5d7b6 to e0e8bb5 Compare May 7, 2020 01:02
@pouchrobot pouchrobot added size/L and removed size/XL labels May 7, 2020
@lowzj lowzj force-pushed the refactor-dfget-core-with-locator branch from e0e8bb5 to f7ae939 Compare May 7, 2020 09:43
@pouchrobot pouchrobot added size/XL and removed size/L labels May 7, 2020
@codecov-io
Copy link

codecov-io commented May 7, 2020

Codecov Report

Merging #1325 into master will decrease coverage by 0.46%.
The diff coverage is 53.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1325      +/-   ##
==========================================
- Coverage   51.32%   50.86%   -0.47%     
==========================================
  Files         126      127       +1     
  Lines        8327     8346      +19     
==========================================
- Hits         4274     4245      -29     
- Misses       3709     3755      +46     
- Partials      344      346       +2     
Impacted Files Coverage Δ
dfget/config/config.go 89.28% <ø> (-0.13%) ⬇️
dfget/locator/manager.go 0.00% <0.00%> (ø)
dfget/locator/static_locator.go 70.42% <35.71%> (-10.23%) ⬇️
dfget/core/core.go 44.32% <39.28%> (-0.89%) ⬇️
dfget/core/regist/register.go 82.82% <88.57%> (-5.25%) ⬇️
dfget/locator/locator.go 100.00% <100.00%> (ø)
dfget/config/supernode_value.go 57.54% <0.00%> (-15.10%) ⬇️
supernode/daemon/mgr/scheduler/manager.go 21.91% <0.00%> (-0.69%) ⬇️

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 164e390...d00c4cb. Read the comment docs.

@lowzj lowzj force-pushed the refactor-dfget-core-with-locator branch 3 times, most recently from c2e4c91 to 68ef2c5 Compare May 7, 2020 14:10
@lowzj lowzj changed the title [WIP] refactor: refactor dfget/core with SupernodeLocator refactor: refactor dfget/core with SupernodeLocator May 7, 2020
register = regist.NewSupernodeRegister(cfg, supernodeAPI)
err error
result *regist.RegisterResult
// TODO make it pluggable
Copy link
Contributor

Choose a reason for hiding this comment

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

s/TODO/TODO:

if resp != nil && resp.IsSuccess() {
return
node := locator.Get()
if node != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

return quickly when node equals nil

nLen := len(s.cfg.Nodes)
if nLen <= 0 {
return
func (s *supernodeRegister) nodeHostStr(node *locator.Supernode) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

use locator.Supernode.String() function?

Copy link
Member Author

Choose a reason for hiding this comment

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

the parameter node maybe nil, it will panic

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think nodeHostStr is a function of type supernodeRegister .

Copy link
Contributor

Choose a reason for hiding this comment

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

Except this, LGTM.

@lowzj lowzj force-pushed the refactor-dfget-core-with-locator branch from 68ef2c5 to 2787e16 Compare May 7, 2020 15:56
@lowzj
Copy link
Member Author

lowzj commented May 8, 2020

@starnop PTAL

@lowzj lowzj force-pushed the refactor-dfget-core-with-locator branch 2 times, most recently from 66a7c56 to 5d5733b Compare May 8, 2020 08:51
@@ -188,28 +179,26 @@ func getTaskPath(taskFileName string) string {
}

// NewRegisterResult creates an instance of RegisterResult.
func NewRegisterResult(node string, remainder []string, url string,
func NewRegisterResult(node string, url string,
Copy link
Contributor

Choose a reason for hiding this comment

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

node, url, taskID string

nLen := len(s.cfg.Nodes)
if nLen <= 0 {
return
func (s *supernodeRegister) nodeHostStr(node *locator.Supernode) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Except this, LGTM.

@lowzj lowzj force-pushed the refactor-dfget-core-with-locator branch 2 times, most recently from 97b1ddd to 25d7443 Compare May 9, 2020 06:47
@lowzj
Copy link
Member Author

lowzj commented May 9, 2020

@starnop @allencloud done, PTAL

@lowzj lowzj force-pushed the refactor-dfget-core-with-locator branch 4 times, most recently from ceb881e to d00c4cb Compare May 13, 2020 06:41
@lowzj lowzj force-pushed the refactor-dfget-core-with-locator branch from d00c4cb to 122ac3c Compare May 13, 2020 11:14
@starnop
Copy link
Contributor

starnop commented May 13, 2020

LGTM.

@starnop starnop merged commit 2443cba into dragonflyoss:master May 13, 2020
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.

[feature request] make the dfget to get the list of supernodes more flexible
5 participants