Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "crypto/sha256" | 8 "crypto/sha256" |
| 9 "errors" | 9 "errors" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 // If the task is created successfully, this will return nil. If the LogStream | 51 // If the task is created successfully, this will return nil. If the LogStream |
| 52 // already had a task dispatched, it will return ErrArchiveTasked. | 52 // already had a task dispatched, it will return ErrArchiveTasked. |
| 53 func (p *ArchivalParams) PublishTask(c context.Context, ap ArchivalPublisher, ls *LogStream) error { | 53 func (p *ArchivalParams) PublishTask(c context.Context, ap ArchivalPublisher, ls *LogStream) error { |
| 54 if ls.State >= LSArchiveTasked { | 54 if ls.State >= LSArchiveTasked { |
| 55 // An archival task has already been dispatched for this log str eam. | 55 // An archival task has already been dispatched for this log str eam. |
| 56 return ErrArchiveTasked | 56 return ErrArchiveTasked |
| 57 } | 57 } |
| 58 | 58 |
| 59 path := string(ls.Path()) | 59 path := string(ls.Path()) |
| 60 msg := logdog.ArchiveTask{ | 60 msg := logdog.ArchiveTask{ |
| 61 » » Path: path, | 61 » » Project: string(Project(c)), |
|
iannucci
2016/04/29 20:09:42
it's unfortunate that "Project" (as in: working on
dnj
2016/04/29 23:04:20
Hah yeah, acknowledged.
| |
| 62 » » Key: p.createArchivalKey(path), | 62 » » Path: path, |
| 63 » » Key: p.createArchivalKey(path), | |
| 63 } | 64 } |
| 64 if p.SettleDelay > 0 { | 65 if p.SettleDelay > 0 { |
| 65 msg.SettleDelay = google.NewDuration(p.SettleDelay) | 66 msg.SettleDelay = google.NewDuration(p.SettleDelay) |
| 66 } | 67 } |
| 67 if p.CompletePeriod > 0 { | 68 if p.CompletePeriod > 0 { |
| 68 msg.CompletePeriod = google.NewDuration(p.CompletePeriod) | 69 msg.CompletePeriod = google.NewDuration(p.CompletePeriod) |
| 69 } | 70 } |
| 70 | 71 |
| 71 // Publish an archival request. | 72 // Publish an archival request. |
| 72 if err := ap.Publish(c, &msg); err != nil { | 73 if err := ap.Publish(c, &msg); err != nil { |
| 73 return err | 74 return err |
| 74 } | 75 } |
| 75 | 76 |
| 76 // Update our LogStream's ArchiveState to reflect that an archival task has | 77 // Update our LogStream's ArchiveState to reflect that an archival task has |
| 77 // been dispatched. | 78 // been dispatched. |
| 78 ls.State = LSArchiveTasked | 79 ls.State = LSArchiveTasked |
| 79 ls.ArchivalKey = msg.Key | 80 ls.ArchivalKey = msg.Key |
| 80 return nil | 81 return nil |
| 81 } | 82 } |
| 82 | 83 |
| 83 // createArchivalKey returns a unique archival request key | 84 // createArchivalKey returns a unique archival request key |
| 84 func (p *ArchivalParams) createArchivalKey(path string) []byte { | 85 func (p *ArchivalParams) createArchivalKey(path string) []byte { |
| 85 index := atomic.AddInt32(&p.keyIndex, 1) | 86 index := atomic.AddInt32(&p.keyIndex, 1) |
| 86 hash := sha256.Sum256([]byte(fmt.Sprintf("%s-%s-%d", p.RequestID, path, index))) | 87 hash := sha256.Sum256([]byte(fmt.Sprintf("%s-%s-%d", p.RequestID, path, index))) |
| 87 return hash[:] | 88 return hash[:] |
| 88 } | 89 } |
| OLD | NEW |