runservice api: get run from readdb
This commit is contained in:
parent
3139ef38d9
commit
a590c21127
|
@ -335,6 +335,7 @@ func (h *ChangeGroupsUpdateTokensHandler) ServeHTTP(w http.ResponseWriter, r *ht
|
|||
type RunResponse struct {
|
||||
Run *types.Run `json:"run"`
|
||||
RunConfig *types.RunConfig `json:"run_config"`
|
||||
ChangeGroupsUpdateToken string `json:"change_groups_update_tokens"`
|
||||
}
|
||||
|
||||
type RunHandler struct {
|
||||
|
@ -354,26 +355,36 @@ func NewRunHandler(logger *zap.Logger, e *etcd.Store, dm *datamanager.DataManage
|
|||
}
|
||||
|
||||
func (h *RunHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
vars := mux.Vars(r)
|
||||
runID := vars["runid"]
|
||||
|
||||
run, _, err := store.GetRun(ctx, h.e, runID)
|
||||
if err != nil && err != etcd.ErrKeyNotFound {
|
||||
query := r.URL.Query()
|
||||
changeGroups := query["changegroup"]
|
||||
|
||||
var run *types.Run
|
||||
var cgt *types.ChangeGroupsUpdateToken
|
||||
|
||||
err := h.readDB.Do(func(tx *db.Tx) error {
|
||||
var err error
|
||||
run, err = h.readDB.GetRun(tx, runID)
|
||||
if err != nil {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
cgt, err = h.readDB.GetChangeGroupsUpdateTokens(tx, changeGroups)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if run == nil {
|
||||
run, err = store.OSTGetRun(h.dm, runID)
|
||||
if err != nil && err != objectstorage.ErrNotExist {
|
||||
|
||||
cgts, err := types.MarshalChangeGroupsUpdateToken(cgt)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
if run == nil {
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
rc, err := store.OSTGetRunConfig(h.dm, run.ID)
|
||||
if err != nil {
|
||||
|
@ -384,6 +395,7 @@ func (h *RunHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
res := &RunResponse{
|
||||
Run: run,
|
||||
RunConfig: rc,
|
||||
ChangeGroupsUpdateToken: cgts,
|
||||
}
|
||||
|
||||
if err := httpResponse(w, http.StatusOK, res); err != nil {
|
||||
|
|
Loading…
Reference in New Issue