Browse Source
util: http Post auto make url
util: http Post auto make url
util: add RemoteApiCall *: add store task client store task: auto clean task when finishpull/279/head
17 changed files with 159 additions and 52 deletions
-
2go/filer/client_operations.go
-
2go/operation/assign_file_id.go
-
2go/operation/delete_content.go
-
2go/operation/list_masters.go
-
6go/operation/lookup.go
-
2go/operation/sync_volume.go
-
2go/storage/store.go
-
43go/storage/store_task.go
-
69go/storage/store_task_cli.go
-
2go/storage/store_task_replication.go
-
2go/topology/allocate_volume.go
-
2go/topology/topology_replicate.go
-
6go/topology/topology_vacuum.go
-
47go/util/http_util.go
-
13go/util/url_util.go
-
5go/weed/benchmark.go
-
4go/weed/weed_server/master_server_handlers_admin.go
@ -0,0 +1,69 @@ |
|||||
|
package storage |
||||
|
|
||||
|
import ( |
||||
|
"errors" |
||||
|
"fmt" |
||||
|
"net/url" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/chrislusf/seaweedfs/go/util" |
||||
|
) |
||||
|
|
||||
|
type TaskParams map[string]string |
||||
|
|
||||
|
var ( |
||||
|
ErrTaskTimeout = errors.New("TaskTimeout") |
||||
|
) |
||||
|
|
||||
|
type TaskCli struct { |
||||
|
TID string |
||||
|
DataNode string |
||||
|
} |
||||
|
|
||||
|
func NewTaskCli(dataNode string, task TaskType, params TaskParams) (*TaskCli, error) { |
||||
|
args := url.Values{} |
||||
|
args.Set("task", string(task)) |
||||
|
for k, v := range params { |
||||
|
args.Set(k, v) |
||||
|
} |
||||
|
m, e := util.RemoteApiCall(dataNode, "/admin/task/new", args) |
||||
|
if e != nil { |
||||
|
return nil, e |
||||
|
} |
||||
|
tid := m["tid"].(string) |
||||
|
if tid == "" { |
||||
|
return nil, fmt.Errorf("Empty %s task", task) |
||||
|
} |
||||
|
return &TaskCli{ |
||||
|
TID: tid, |
||||
|
DataNode: dataNode, |
||||
|
}, nil |
||||
|
} |
||||
|
|
||||
|
func (c *TaskCli) WaitAndQueryResult(timeout time.Duration) error { |
||||
|
startTime := time.Now() |
||||
|
args := url.Values{} |
||||
|
args.Set("task", c.TID) |
||||
|
for time.Since(startTime) < timeout { |
||||
|
_, e := util.RemoteApiCall(c.DataNode, "/admin/task/query", args) |
||||
|
if e.Error() == ErrTaskNotFinish.Error() { |
||||
|
continue |
||||
|
} |
||||
|
return e |
||||
|
} |
||||
|
return ErrTaskTimeout |
||||
|
} |
||||
|
|
||||
|
func (c *TaskCli) Commit() error { |
||||
|
args := url.Values{} |
||||
|
args.Set("task", c.TID) |
||||
|
_, e := util.RemoteApiCall(c.DataNode, "/admin/task/commit", args) |
||||
|
return e |
||||
|
} |
||||
|
|
||||
|
func (c *TaskCli) Clean() error { |
||||
|
args := url.Values{} |
||||
|
args.Set("task", c.TID) |
||||
|
_, e := util.RemoteApiCall(c.DataNode, "/admin/task/clean", args) |
||||
|
return e |
||||
|
} |
||||
@ -1,13 +0,0 @@ |
|||||
package util |
|
||||
|
|
||||
import "net/url" |
|
||||
|
|
||||
func MkUrl(host, path string, args url.Values) string { |
|
||||
u := url.URL{ |
|
||||
Scheme: "http", |
|
||||
Host: host, |
|
||||
Path: path, |
|
||||
} |
|
||||
u.RawQuery = args.Encode() |
|
||||
return u.String() |
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue