| 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 "crypto/sha1" | 8 "crypto/sha1" |
| 9 "encoding/base64" | 9 "encoding/base64" |
| 10 "fmt" | 10 "fmt" |
| 11 "net/http" | 11 "net/http" |
| 12 "time" | 12 "time" |
| 13 | 13 |
| 14 "github.com/julienschmidt/httprouter" | |
| 15 "golang.org/x/net/context" | |
| 16 | |
| 17 "github.com/luci/gae/service/memcache" | 14 "github.com/luci/gae/service/memcache" |
| 18 "github.com/luci/luci-go/common/clock" | 15 "github.com/luci/luci-go/common/clock" |
| 19 "github.com/luci/luci-go/server/auth" | 16 "github.com/luci/luci-go/server/auth" |
| 17 "github.com/luci/luci-go/server/router" |
| 20 "github.com/luci/luci-go/server/templates" | 18 "github.com/luci/luci-go/server/templates" |
| 21 ) | 19 ) |
| 22 | 20 |
| 23 func jobPage(c context.Context, w http.ResponseWriter, r *http.Request, p httpro
uter.Params) { | 21 func jobPage(ctx *router.Context) { |
| 22 » c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params |
| 23 |
| 24 projectID := p.ByName("ProjectID") | 24 projectID := p.ByName("ProjectID") |
| 25 jobID := p.ByName("JobID") | 25 jobID := p.ByName("JobID") |
| 26 cursor := r.URL.Query().Get("c") | 26 cursor := r.URL.Query().Get("c") |
| 27 | 27 |
| 28 // Grab the job from the datastore. | 28 // Grab the job from the datastore. |
| 29 job, err := config(c).Engine.GetCronJob(c, projectID+"/"+jobID) | 29 job, err := config(c).Engine.GetCronJob(c, projectID+"/"+jobID) |
| 30 if err != nil { | 30 if err != nil { |
| 31 panic(err) | 31 panic(err) |
| 32 } | 32 } |
| 33 if job == nil { | 33 if job == nil { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 "Job": makeCronJob(job, now), | 76 "Job": makeCronJob(job, now), |
| 77 "Invocations": convertToInvocations(job.ProjectID, job.JobID, in
vs, now), | 77 "Invocations": convertToInvocations(job.ProjectID, job.JobID, in
vs, now), |
| 78 "PrevCursor": prevCursor, | 78 "PrevCursor": prevCursor, |
| 79 "NextCursor": nextCursor, | 79 "NextCursor": nextCursor, |
| 80 }) | 80 }) |
| 81 } | 81 } |
| 82 | 82 |
| 83 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
| 84 // Actions. | 84 // Actions. |
| 85 | 85 |
| 86 func runJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p h
ttprouter.Params) { | 86 func runJobAction(ctx *router.Context) { |
| 87 » c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params |
| 88 |
| 87 projectID := p.ByName("ProjectID") | 89 projectID := p.ByName("ProjectID") |
| 88 jobID := p.ByName("JobID") | 90 jobID := p.ByName("JobID") |
| 89 if !isJobOwner(c, projectID, jobID) { | 91 if !isJobOwner(c, projectID, jobID) { |
| 90 http.Error(w, "Forbidden", 403) | 92 http.Error(w, "Forbidden", 403) |
| 91 return | 93 return |
| 92 } | 94 } |
| 93 | 95 |
| 94 // genericReply renders "we did something (or we failed to do something)
" | 96 // genericReply renders "we did something (or we failed to do something)
" |
| 95 // page, shown on error or if invocation is starting for too long. | 97 // page, shown on error or if invocation is starting for too long. |
| 96 genericReply := func(err error) { | 98 genericReply := func(err error) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 135 } |
| 134 } | 136 } |
| 135 | 137 |
| 136 if invID != 0 { | 138 if invID != 0 { |
| 137 http.Redirect(w, r, fmt.Sprintf("/jobs/%s/%s/%d", projectID, job
ID, invID), http.StatusFound) | 139 http.Redirect(w, r, fmt.Sprintf("/jobs/%s/%s/%d", projectID, job
ID, invID), http.StatusFound) |
| 138 } else { | 140 } else { |
| 139 genericReply(nil) // deadline | 141 genericReply(nil) // deadline |
| 140 } | 142 } |
| 141 } | 143 } |
| 142 | 144 |
| 143 func pauseJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p
httprouter.Params) { | 145 func pauseJobAction(c *router.Context) { |
| 144 » handleJobAction(c, w, r, p, func(jobID string) error { | 146 » handleJobAction(c, func(jobID string) error { |
| 145 » » who := auth.CurrentIdentity(c) | 147 » » who := auth.CurrentIdentity(c.Context) |
| 146 » » return config(c).Engine.PauseJob(c, jobID, who) | 148 » » return config(c.Context).Engine.PauseJob(c.Context, jobID, who) |
| 147 }) | 149 }) |
| 148 } | 150 } |
| 149 | 151 |
| 150 func resumeJobAction(c context.Context, w http.ResponseWriter, r *http.Request,
p httprouter.Params) { | 152 func resumeJobAction(c *router.Context) { |
| 151 » handleJobAction(c, w, r, p, func(jobID string) error { | 153 » handleJobAction(c, func(jobID string) error { |
| 152 » » who := auth.CurrentIdentity(c) | 154 » » who := auth.CurrentIdentity(c.Context) |
| 153 » » return config(c).Engine.ResumeJob(c, jobID, who) | 155 » » return config(c.Context).Engine.ResumeJob(c.Context, jobID, who) |
| 154 }) | 156 }) |
| 155 } | 157 } |
| 156 | 158 |
| 157 func handleJobAction(c context.Context, w http.ResponseWriter, r *http.Request,
p httprouter.Params, cb func(string) error) { | 159 func handleJobAction(c *router.Context, cb func(string) error) { |
| 158 » projectID := p.ByName("ProjectID") | 160 » projectID := c.Params.ByName("ProjectID") |
| 159 » jobID := p.ByName("JobID") | 161 » jobID := c.Params.ByName("JobID") |
| 160 » if !isJobOwner(c, projectID, jobID) { | 162 » if !isJobOwner(c.Context, projectID, jobID) { |
| 161 » » http.Error(w, "Forbidden", 403) | 163 » » http.Error(c.Writer, "Forbidden", 403) |
| 162 return | 164 return |
| 163 } | 165 } |
| 164 if err := cb(projectID + "/" + jobID); err != nil { | 166 if err := cb(projectID + "/" + jobID); err != nil { |
| 165 panic(err) | 167 panic(err) |
| 166 } | 168 } |
| 167 » http.Redirect(w, r, fmt.Sprintf("/jobs/%s/%s", projectID, jobID), http.S
tatusFound) | 169 » http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s", projectID,
jobID), http.StatusFound) |
| 168 } | 170 } |
| OLD | NEW |