OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 ui | 5 package ui |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "net/http" | 9 "net/http" |
10 "strconv" | 10 "strconv" |
11 "sync" | 11 "sync" |
12 | 12 |
13 "github.com/luci/luci-go/server/auth" | 13 "github.com/luci/luci-go/server/auth" |
14 "github.com/luci/luci-go/server/router" | 14 "github.com/luci/luci-go/server/router" |
15 "github.com/luci/luci-go/server/templates" | 15 "github.com/luci/luci-go/server/templates" |
16 | 16 |
17 "github.com/luci/luci-go/scheduler/appengine/engine" | 17 "github.com/luci/luci-go/scheduler/appengine/engine" |
| 18 "github.com/luci/luci-go/scheduler/appengine/presentation" |
18 ) | 19 ) |
19 | 20 |
20 func invocationPage(c *router.Context) { | 21 func invocationPage(c *router.Context) { |
21 projectID := c.Params.ByName("ProjectID") | 22 projectID := c.Params.ByName("ProjectID") |
22 » jobID := c.Params.ByName("JobID") | 23 » jobName := c.Params.ByName("JobName") |
23 invID, err := strconv.ParseInt(c.Params.ByName("InvID"), 10, 64) | 24 invID, err := strconv.ParseInt(c.Params.ByName("InvID"), 10, 64) |
24 if err != nil { | 25 if err != nil { |
25 http.Error(c.Writer, "No such invocation", http.StatusNotFound) | 26 http.Error(c.Writer, "No such invocation", http.StatusNotFound) |
26 return | 27 return |
27 } | 28 } |
28 | 29 |
29 var inv *engine.Invocation | 30 var inv *engine.Invocation |
30 var job *engine.Job | 31 var job *engine.Job |
31 var err1, err2 error | 32 var err1, err2 error |
32 | 33 |
33 eng := config(c.Context).Engine | 34 eng := config(c.Context).Engine |
34 | 35 |
35 wg := sync.WaitGroup{} | 36 wg := sync.WaitGroup{} |
36 wg.Add(1) | 37 wg.Add(1) |
37 go func() { | 38 go func() { |
38 defer wg.Done() | 39 defer wg.Done() |
39 » » inv, err1 = eng.GetInvocation(c.Context, projectID+"/"+jobID, in
vID) | 40 » » inv, err1 = eng.GetInvocation(c.Context, projectID+"/"+jobName,
invID) |
40 }() | 41 }() |
41 wg.Add(1) | 42 wg.Add(1) |
42 go func() { | 43 go func() { |
43 defer wg.Done() | 44 defer wg.Done() |
44 » » job, err2 = eng.GetJob(c.Context, projectID+"/"+jobID) | 45 » » job, err2 = eng.GetJob(c.Context, projectID+"/"+jobName) |
45 }() | 46 }() |
46 wg.Wait() | 47 wg.Wait() |
47 | 48 |
48 // panic on internal datastore errors to trigger HTTP 500. | 49 // panic on internal datastore errors to trigger HTTP 500. |
49 switch { | 50 switch { |
50 case err1 != nil: | 51 case err1 != nil: |
51 panic(err1) | 52 panic(err1) |
52 case err2 != nil: | 53 case err2 != nil: |
53 panic(err2) | 54 panic(err2) |
54 case inv == nil: | 55 case inv == nil: |
(...skipping 16 matching lines...) Expand all Loading... |
71 | 72 |
72 func abortInvocationAction(c *router.Context) { | 73 func abortInvocationAction(c *router.Context) { |
73 handleInvAction(c, func(jobID string, invID int64) error { | 74 handleInvAction(c, func(jobID string, invID int64) error { |
74 who := auth.CurrentIdentity(c.Context) | 75 who := auth.CurrentIdentity(c.Context) |
75 return config(c.Context).Engine.AbortInvocation(c.Context, jobID
, invID, who) | 76 return config(c.Context).Engine.AbortInvocation(c.Context, jobID
, invID, who) |
76 }) | 77 }) |
77 } | 78 } |
78 | 79 |
79 func handleInvAction(c *router.Context, cb func(string, int64) error) { | 80 func handleInvAction(c *router.Context, cb func(string, int64) error) { |
80 projectID := c.Params.ByName("ProjectID") | 81 projectID := c.Params.ByName("ProjectID") |
81 » jobID := c.Params.ByName("JobID") | 82 » jobName := c.Params.ByName("JobName") |
82 invID := c.Params.ByName("InvID") | 83 invID := c.Params.ByName("InvID") |
83 » if !isJobOwner(c.Context, projectID, jobID) { | 84 » if !presentation.IsJobOwner(c.Context, projectID, jobName) { |
84 http.Error(c.Writer, "Forbidden", 403) | 85 http.Error(c.Writer, "Forbidden", 403) |
85 return | 86 return |
86 } | 87 } |
87 invIDAsInt, err := strconv.ParseInt(invID, 10, 64) | 88 invIDAsInt, err := strconv.ParseInt(invID, 10, 64) |
88 if err != nil { | 89 if err != nil { |
89 http.Error(c.Writer, "Bad invocation ID", 400) | 90 http.Error(c.Writer, "Bad invocation ID", 400) |
90 return | 91 return |
91 } | 92 } |
92 » if err := cb(projectID+"/"+jobID, invIDAsInt); err != nil { | 93 » if err := cb(projectID+"/"+jobName, invIDAsInt); err != nil { |
93 panic(err) | 94 panic(err) |
94 } | 95 } |
95 » http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s/%s", project
ID, jobID, invID), http.StatusFound) | 96 » http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s/%s", project
ID, jobName, invID), http.StatusFound) |
96 } | 97 } |
OLD | NEW |