7 "git.curoverse.com/arvados.git/sdk/go/keepclient"
15 Keepstore initiates pull worker channel goroutine.
16 The channel will process pull list.
17 For each (next) pull request:
18 For each locator listed, execute Pull on the server(s) listed
19 Skip the rest of the servers if no errors
22 func RunPullWorker(pullq *WorkQueue, keepClient *keepclient.KeepClient) {
23 nextItem := pullq.NextItem
24 for item := range nextItem {
25 pullRequest := item.(PullRequest)
26 err := PullItemAndProcess(item.(PullRequest), GenerateRandomApiToken(), keepClient)
28 log.Printf("Pull %s success", pullRequest)
30 log.Printf("Pull %s error: %s", pullRequest, err)
36 For each Pull request:
37 Generate a random API token.
38 Generate a permission signature using this token, timestamp ~60 seconds in the future, and desired block hash.
39 Using this token & signature, retrieve the given block.
42 func PullItemAndProcess(pullRequest PullRequest, token string, keepClient *keepclient.KeepClient) (err error) {
43 keepClient.Arvados.ApiToken = token
45 service_roots := make(map[string]string)
46 for _, addr := range pullRequest.Servers {
47 service_roots[addr] = addr
49 keepClient.SetServiceRoots(service_roots, nil)
51 // Generate signature with a random token
52 expires_at := time.Now().Add(60 * time.Second)
53 signedLocator := SignLocator(pullRequest.Locator, token, expires_at)
55 reader, contentLen, _, err := GetContent(signedLocator, keepClient)
60 return errors.New(fmt.Sprintf("No reader found for : %s", signedLocator))
64 read_content, err := ioutil.ReadAll(reader)
69 if (read_content == nil) || (int64(len(read_content)) != contentLen) {
70 return errors.New(fmt.Sprintf("Content not found for: %s", signedLocator))
73 err = PutContent(read_content, pullRequest.Locator)
77 // Fetch the content for the given locator using keepclient.
78 var GetContent = func(signedLocator string, keepClient *keepclient.KeepClient) (
79 reader io.ReadCloser, contentLength int64, url string, err error) {
80 reader, blocklen, url, err := keepClient.Get(signedLocator)
81 return reader, blocklen, url, err
84 const ALPHA_NUMERIC = "0123456789abcdefghijklmnopqrstuvwxyz"
86 func GenerateRandomApiToken() string {
87 var bytes = make([]byte, 36)
89 for i, b := range bytes {
90 bytes[i] = ALPHA_NUMERIC[b%byte(len(ALPHA_NUMERIC))]
92 return (string(bytes))
96 var PutContent = func(content []byte, locator string) (err error) {
97 err = PutBlock(content, locator)