Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: dm/appengine/distributor/swarming/v1/isolate.go

Issue 2347973003: Refactor distributor API so that methods always get the Quest_Desc too. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package swarming 5 package swarming
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "encoding/json" 9 "encoding/json"
10 "strings" 10 "strings"
11 11
12 "github.com/golang/protobuf/jsonpb" 12 "github.com/golang/protobuf/jsonpb"
13 "github.com/golang/protobuf/proto" 13 "github.com/golang/protobuf/proto"
14 "github.com/luci/gae/service/info" 14 "github.com/luci/gae/service/info"
15 "github.com/luci/luci-go/common/api/isolate/isolateservice/v1" 15 "github.com/luci/luci-go/common/api/isolate/isolateservice/v1"
16 swarm "github.com/luci/luci-go/common/api/swarming/swarming/v1" 16 swarm "github.com/luci/luci-go/common/api/swarming/swarming/v1"
17 "github.com/luci/luci-go/common/errors" 17 "github.com/luci/luci-go/common/errors"
18 "github.com/luci/luci-go/common/isolated" 18 "github.com/luci/luci-go/common/isolated"
19 "github.com/luci/luci-go/common/isolatedclient" 19 "github.com/luci/luci-go/common/isolatedclient"
20 "github.com/luci/luci-go/common/sync/parallel" 20 "github.com/luci/luci-go/common/sync/parallel"
21 sv1 "github.com/luci/luci-go/dm/api/distributor/swarming/v1" 21 sv1 "github.com/luci/luci-go/dm/api/distributor/swarming/v1"
22 » "github.com/luci/luci-go/dm/appengine/distributor" 22 » dm "github.com/luci/luci-go/dm/api/service/v1"
23 "golang.org/x/net/context" 23 "golang.org/x/net/context"
24 ) 24 )
25 25
26 const prevPath = ".dm/previous_execution.json" 26 const prevPath = ".dm/previous_execution.json"
27 const exAuthPath = ".dm/execution_auth.json" 27 const exAuthPath = ".dm/execution_auth.json"
28 const descPath = ".dm/quest_description.json" 28 const descPath = ".dm/quest_description.json"
29 29
30 func mkFile(data []byte) *isolated.File { 30 func mkFile(data []byte) *isolated.File {
31 mode := 0444 31 mode := 0444
32 size := int64(len(data)) 32 size := int64(len(data))
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 if st != nil { 108 if st != nil {
109 i, st := i, st 109 i, st := i, st
110 ch <- func() error { 110 ch <- func() error {
111 return isoClient.Push(c, st, isolatedcli ent.NewBytesSource(chunks[i].data)) 111 return isoClient.Push(c, st, isolatedcli ent.NewBytesSource(chunks[i].data))
112 } 112 }
113 } 113 }
114 } 114 }
115 }) 115 })
116 } 116 }
117 117
118 func prepIsolate(c context.Context, isolateURL string, tsk *distributor.TaskDesc ription, params *sv1.Parameters) (*swarm.SwarmingRpcsFilesRef, error) { 118 func prepIsolate(c context.Context, isolateURL string, desc *dm.Quest_Desc, auth *dm.Execution_Auth, prev *dm.JsonResult, params *sv1.Parameters) (*swarm.Swarmi ngRpcsFilesRef, error) {
119 prevData := []byte("{}") 119 prevData := []byte("{}")
120 » if tsk.PreviousResult() != nil { 120 » if prev != nil {
121 » » prevData = []byte(tsk.PreviousResult().Object) 121 » » prevData = []byte(prev.Object)
122 } 122 }
123 prevFile := mkFile(prevData) 123 prevFile := mkFile(prevData)
124 » authData, authFile := mkMsgFile(tsk.ExecutionAuth()) 124 » authData, authFile := mkMsgFile(auth)
125 » descData, descFile := mkMsgFile(tsk.Payload()) 125 » descData, descFile := mkMsgFile(desc)
126 isoData, isoFile := mkIsolated(c, params, prevFile, descFile, authFile) 126 isoData, isoFile := mkIsolated(c, params, prevFile, descFile, authFile)
127 127
128 err := pushIsolate(c, isolateURL, []isoChunk{ 128 err := pushIsolate(c, isolateURL, []isoChunk{
129 {data: prevData, file: prevFile}, 129 {data: prevData, file: prevFile},
130 {data: authData, file: authFile}, 130 {data: authData, file: authFile},
131 {data: descData, file: descFile}, 131 {data: descData, file: descFile},
132 {data: isoData, file: isoFile, isIso: true}, 132 {data: isoData, file: isoFile, isIso: true},
133 }) 133 })
134 if err != nil { 134 if err != nil {
135 err = errors.Annotate(err).Reason("pushing new Isolated").Err() 135 err = errors.Annotate(err).Reason("pushing new Isolated").Err()
136 return nil, err 136 return nil, err
137 } 137 }
138 138
139 return &swarm.SwarmingRpcsFilesRef{ 139 return &swarm.SwarmingRpcsFilesRef{
140 Isolated: string(isoFile.Digest), 140 Isolated: string(isoFile.Digest),
141 Isolatedserver: isolateURL, 141 Isolatedserver: isolateURL,
142 Namespace: isolatedclient.DefaultNamespace, 142 Namespace: isolatedclient.DefaultNamespace,
143 }, nil 143 }, nil
144 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698