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

Commit

Permalink
chore:validate go mod files
Browse files Browse the repository at this point in the history
Signed-off-by: santong <[email protected]>
  • Loading branch information
244372610 committed Jun 29, 2021
1 parent c4e6718 commit be03cce
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 145 deletions.
34 changes: 12 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,35 @@ go 1.12

require (
github.com/HuKeping/rbtree v0.0.0-20200208030951-29f0b79e84ed
github.com/PuerkitoBio/purell v0.0.0-20170829232023-f619812e3caf // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/asaskevich/govalidator v0.0.0-20170903095215-73945b6115bf // indirect
github.com/cpuguy83/go-md2man v1.0.7 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/emirpasic/gods v1.12.0
github.com/go-check/check v0.0.0-20161208181325-20d25e280405
github.com/go-openapi/analysis v0.0.0-20170813233457-8ed83f2ea9f0 // indirect
github.com/go-openapi/errors v0.0.0-20170426151106-03cfca65330d
github.com/go-openapi/jsonpointer v0.0.0-20170102174223-779f45308c19 // indirect
github.com/go-openapi/jsonreference v0.0.0-20161105162150-36d33bfe519e // indirect
github.com/go-openapi/loads v0.0.0-20170520182102-a80dea3052f0 // indirect
github.com/go-openapi/runtime v0.0.0-20170901133030-bf2ff8f71507 // indirect
github.com/go-openapi/spec v0.0.0-20170811033243-3faa0055dbbf // indirect
github.com/go-openapi/strfmt v0.0.0-20171222154016-4dd3d302e100
github.com/go-openapi/swag v0.0.0-20170606142751-f3f9494671f9
github.com/go-openapi/validate v0.0.0-20170705144413-8a82927c942c
github.com/go-openapi/analysis v0.20.1 // indirect
github.com/go-openapi/errors v0.19.9
github.com/go-openapi/runtime v0.19.29 // indirect
github.com/go-openapi/strfmt v0.20.0
github.com/go-openapi/swag v0.19.14
github.com/go-openapi/validate v0.20.1
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
github.com/golang/mock v1.5.0
github.com/gorilla/context v0.0.0-20181012153548-51ce91d2eadd // indirect
github.com/gorilla/mux v1.5.0
github.com/gorilla/schema v1.1.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mailru/easyjson v0.0.0-20170902151237-2a92e673c9a6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.4.1
github.com/openacid/low v0.1.10
github.com/pborman/uuid v0.0.0-20180122190007-c65b2f87fee3
github.com/pkg/errors v0.8.1
github.com/pborman/uuid v1.2.0
github.com/pkg/errors v0.9.1
github.com/prashantv/gostub v1.0.0
github.com/prometheus/client_golang v0.9.3
github.com/russross/blackfriday v0.0.0-20171011182219-6d1ef893fcb0 // indirect
github.com/sirupsen/logrus v1.2.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/afero v1.6.0
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.8.1
github.com/stretchr/testify v1.7.0
github.com/valyala/fasthttp v1.3.0
github.com/willf/bitset v0.0.0-20190228212526-18bd95f470f9
gopkg.in/gcfg.v1 v1.2.3
gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/warnings.v0 v0.1.2
gopkg.in/yaml.v2 v2.4.0
Expand Down
294 changes: 226 additions & 68 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions supernode/daemon/mgr/preheat/base_preaheater.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var _ Preheater = &BasePreheater{}

type BasePreheater struct {}
type BasePreheater struct{}

/**
* The type of this preheater
Expand All @@ -35,7 +35,7 @@ func (p *BasePreheater) Type() string {
/**
* Create a worker to preheat the task.
*/
func (p *BasePreheater) NewWorker(task *mgr.PreheatTask , service *PreheatService) IWorker {
func (p *BasePreheater) NewWorker(task *mgr.PreheatTask, service *PreheatService) IWorker {
panic("not implement")
}

Expand Down Expand Up @@ -65,4 +65,4 @@ func (p *BasePreheater) addWorker(id string, worker IWorker) {
workerMap.Store(id, worker)
}

var workerMap = new(sync.Map)
var workerMap = new(sync.Map)
24 changes: 12 additions & 12 deletions supernode/daemon/mgr/preheat/base_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const TIMEOUT = 30 * 60

var _ IWorker = &BaseWorker{}

type IWorker interface{
type IWorker interface {
Run()
Stop()
query() chan error
Expand All @@ -38,35 +38,35 @@ type IWorker interface{
}

type BaseWorker struct {
Task *mgr.PreheatTask
Preheater Preheater
Task *mgr.PreheatTask
Preheater Preheater
PreheatService *PreheatService
stop *atomic.Value
worker IWorker
stop *atomic.Value
worker IWorker
}

func newBaseWorker(task *mgr.PreheatTask, preheater Preheater, preheatService *PreheatService) *BaseWorker {
worker := &BaseWorker{
Task: task,
Preheater: preheater,
Task: task,
Preheater: preheater,
PreheatService: preheatService,
stop: new(atomic.Value),
stop: new(atomic.Value),
}
worker.worker = worker
return worker
}

func (w *BaseWorker) Run() {
go func() {
defer func(){
defer func() {
e := recover()
if e != nil {
debug.PrintStack()
}
}()

if w.worker.preRun() {
timer := time.NewTimer(time.Second*TIMEOUT)
timer := time.NewTimer(time.Second * TIMEOUT)
ch := w.worker.query()
select {
case <-timer.C:
Expand Down Expand Up @@ -102,13 +102,13 @@ func (w *BaseWorker) query() chan error {
}

func (w *BaseWorker) succeed() {
w.Task.FinishTime = time.Now().UnixNano()/int64(time.Millisecond)
w.Task.FinishTime = time.Now().UnixNano() / int64(time.Millisecond)
w.Task.Status = types.PreheatStatusSUCCESS
w.PreheatService.Update(w.Task.ID, w.Task)
}

func (w *BaseWorker) failed(errMsg string) {
w.Task.FinishTime = time.Now().UnixNano()/int64(time.Millisecond)
w.Task.FinishTime = time.Now().UnixNano() / int64(time.Millisecond)
w.Task.Status = types.PreheatStatusFAILED
w.Task.ErrorMsg = errMsg
w.PreheatService.Update(w.Task.ID, w.Task)
Expand Down
13 changes: 6 additions & 7 deletions supernode/daemon/mgr/preheat/file_preaheater.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

func init() {
RegisterPreheater("file", &FilePreheat{BasePreheater:new(BasePreheater)})
RegisterPreheater("file", &FilePreheat{BasePreheater: new(BasePreheater)})
}

type FilePreheat struct {
Expand All @@ -39,7 +39,7 @@ func (p *FilePreheat) Type() string {
/**
* Create a worker to preheat the task.
*/
func (p *FilePreheat) NewWorker(task *mgr.PreheatTask , service *PreheatService) IWorker {
func (p *FilePreheat) NewWorker(task *mgr.PreheatTask, service *PreheatService) IWorker {
worker := &FileWorker{BaseWorker: newBaseWorker(task, p, service)}
worker.worker = worker
p.addWorker(task.ID, worker)
Expand Down Expand Up @@ -72,8 +72,8 @@ func (w *FileWorker) afterRun() {

func (w *FileWorker) query() chan error {
result := make(chan error, 1)
go func(){
time.Sleep(time.Second*2)
go func() {
time.Sleep(time.Second * 2)
for w.isRunning() {
if w.Task.FinishTime > 0 {
w.Preheater.Cancel(w.Task.ID)
Expand All @@ -86,7 +86,7 @@ func (w *FileWorker) query() chan error {
status := w.progress.cmd.ProcessState
if status != nil && status.Exited() {
if !status.Success() {
errMsg := fmt.Sprintf("dfget failed: %s err: %s", status.String(), w.progress.errmsg.String())
errMsg := fmt.Sprintf("dfget failed: %s err: %s", status.String(), w.progress.errmsg.String())
w.failed(errMsg)
w.Preheater.Cancel(w.Task.ID)
result <- errors.New(errMsg)
Expand All @@ -99,9 +99,8 @@ func (w *FileWorker) query() chan error {
}
}

time.Sleep(time.Second*10)
time.Sleep(time.Second * 10)
}
}()
return result
}

4 changes: 2 additions & 2 deletions supernode/daemon/mgr/preheat/image_preaheater.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func init() {
RegisterPreheater("image", &ImagePreheat{BasePreheater:new(BasePreheater)})
RegisterPreheater("image", &ImagePreheat{BasePreheater: new(BasePreheater)})
}

var IMAGE_MANIFESTS_PATTERN, _ = regexp.Compile("^(.*)://(.*)/v2/(.*)/manifests/(.*)")
Expand Down Expand Up @@ -183,7 +183,7 @@ func (w *ImageWorker) getAuthToken(header http.Header) (token string) {
}
var values []string
for k, v := range header {
if strings.ToLower(k) == "www-authenticate" {
if strings.ToLower(k) == "www-authenticate" {
values = v
}
}
Expand Down
2 changes: 1 addition & 1 deletion supernode/daemon/mgr/preheat/image_preheater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func TestParseLayers(t *testing.T) {
task := &mgr.PreheatTask{
URL: "https://registry.cn-zhangjiakou.aliyuncs.com/v2/acs/alpine/manifests/3.6",
URL: "https://registry.cn-zhangjiakou.aliyuncs.com/v2/acs/alpine/manifests/3.6",
Headers: map[string]string{},
}
worker := &ImageWorker{BaseWorker: newBaseWorker(task, nil, nil)}
Expand Down
6 changes: 3 additions & 3 deletions supernode/daemon/mgr/preheat/preheat_progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import (

type PreheatProgress struct {
output string
cmd *exec.Cmd
cmd *exec.Cmd
errmsg *bytes.Buffer
}

func NewPreheatProgress(output string, cmd *exec.Cmd) *PreheatProgress {
p := &PreheatProgress{
output: output,
cmd: cmd,
cmd: cmd,
errmsg: bytes.NewBuffer(make([]byte, 0, 128)),
}
cmd.Stderr = p.errmsg
cmd.Stdout = p.errmsg
return p
}
}
26 changes: 13 additions & 13 deletions supernode/daemon/mgr/preheat/preheat_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,37 @@ import (
)

const (
key = ">I$pg-~AS~sP'rqu_`Oh&lz#9]\"=;nE%"
key = ">I$pg-~AS~sP'rqu_`Oh&lz#9]\"=;nE%"
dfgetPath = "/usr/local/bin/dfget"
)

type PreheatService struct {
PreheatPath string
repository *PreheatTaskRepository
repository *PreheatTaskRepository
}

func NewPreheatService(homeDir string) *PreheatService {
return &PreheatService{
repository: NewPreheatTaskRepository(),
repository: NewPreheatTaskRepository(),
PreheatPath: filepath.Join(homeDir, "repo", "preheat"),
}
}

// Get detailed preheat task information
func (svc *PreheatService) Get(id string) *mgr.PreheatTask {
func (svc *PreheatService) Get(id string) *mgr.PreheatTask {
if id == "" {
return nil
}
return svc.repository.Get(id)
}

// Get all preheat tasks
func (svc *PreheatService) GetAll() []*mgr.PreheatTask {
func (svc *PreheatService) GetAll() []*mgr.PreheatTask {
return svc.repository.GetAll()
}

// Delete a preheat task.
func (svc *PreheatService) Delete(id string) {
func (svc *PreheatService) Delete(id string) {
task := svc.repository.Get(id)
if task != nil && len(task.Children) > 0 {
for _, childId := range task.Children {
Expand All @@ -75,29 +75,29 @@ func (svc *PreheatService) Delete(id string) {
}

// update a preheat task
func (svc *PreheatService) Update(id string, task *mgr.PreheatTask) bool {
func (svc *PreheatService) Update(id string, task *mgr.PreheatTask) bool {
return svc.repository.Update(id, task)
}

// create a preheat task
func (svc *PreheatService) Create(task *mgr.PreheatTask) (string, error) {
func (svc *PreheatService) Create(task *mgr.PreheatTask) (string, error) {
preheater := GetPreheater(strings.ToLower(task.Type))
if preheater == nil {
return "", dferr.New(400, task.Type + " isn't supported")
return "", dferr.New(400, task.Type+" isn't supported")
}
task.ID = svc.createTaskID(task.URL, task.Filter, task.Identifier, task.Headers)
task.StartTime = time.Now().UnixNano() / int64(time.Millisecond)
task.Status = types.PreheatStatusWAITING
previous, _ := svc.repository.Add(task)
if previous != nil && previous.FinishTime > 0 {
return "", dferr.New(http.StatusAlreadyReported, "preheat task already exists, id:" + task.ID)
return "", dferr.New(http.StatusAlreadyReported, "preheat task already exists, id:"+task.ID)
}
preheater.NewWorker(task, svc).Run()
return task.ID, nil
}

// execute preheat task
func (svc *PreheatService) ExecutePreheat(task *mgr.PreheatTask) (progress *PreheatProgress, err error) {
func (svc *PreheatService) ExecutePreheat(task *mgr.PreheatTask) (progress *PreheatProgress, err error) {
targetName := uuid.New()
targetPath := filepath.Join(svc.PreheatPath, targetName)
cmd := svc.createCommand(task.URL, task.Headers, task.Filter, task.Identifier, targetPath)
Expand Down Expand Up @@ -126,10 +126,10 @@ func (svc *PreheatService) createTaskID(url, filter, identifier string, header m

func (svc *PreheatService) createCommand(url string, header map[string]string, filter, identifier, tmpTarget string) *exec.Cmd {
netRate := 50
rate := fmt.Sprintf("%dM", netRate / 2)
rate := fmt.Sprintf("%dM", netRate/2)

args := []string{"-u", url, "-o", tmpTarget, "--callsystem", "dragonfly_preheat", "--totallimit", rate, "-s", rate}
if (header != nil) {
if header != nil {
for k, v := range header {
args = append(args, []string{"--header", fmt.Sprintf("%s:%s", k, v)}...)
}
Expand Down
Loading

0 comments on commit be03cce

Please sign in to comment.