wip: update store. references to storage. in server.go

This commit is contained in:
Michael Hohn
2024-05-21 11:45:47 -07:00
committed by =Michael Hohn
parent 873339ff06
commit 4269bacf2a
2 changed files with 15 additions and 17 deletions

View File

@@ -21,7 +21,6 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/hohn/ghes-mirva-server/api" "github.com/hohn/ghes-mirva-server/api"
co "github.com/hohn/ghes-mirva-server/common" co "github.com/hohn/ghes-mirva-server/common"
"github.com/hohn/ghes-mirva-server/store"
) )
func (c *CommanderSingle) Run() { func (c *CommanderSingle) Run() {
@@ -279,14 +278,12 @@ func (c *CommanderSingle) MirvaRequestID(w http.ResponseWriter, r *http.Request)
func (c *CommanderSingle) MirvaRequest(w http.ResponseWriter, r *http.Request) { func (c *CommanderSingle) MirvaRequest(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
slog.Info("New mrva run ", "owner", vars["owner"], "repo", vars["repo"]) slog.Info("New mrva run ", "owner", vars["owner"], "repo", vars["repo"])
// session := new(MirvaSession)
session_id := c.st.Storage.NextID() session_id := c.st.Storage.NextID()
session_owner := vars["owner"] session_owner := vars["owner"]
session_controller_repo := vars["repo"] session_controller_repo := vars["repo"]
slog.Info("new run", "id: ", fmt.Sprint(session_id), session_owner, session_controller_repo) slog.Info("new run", "id: ", fmt.Sprint(session_id), session_owner, session_controller_repo)
session_language, session_repositories, session_tgz_ref, err := c.collectRequestInfo(w, r, session_id) session_language, session_repositories, session_tgz_ref, err := c.collectRequestInfo(w, r, session_id)
if err != nil { if err != nil {
return return
} }
@@ -312,7 +309,8 @@ func (c *CommanderSingle) MirvaRequest(w http.ResponseWriter, r *http.Request) {
AnalysisRepos: analysisRepos, AnalysisRepos: analysisRepos,
} }
submit_response, err := c.submit_response(si) slog.Debug("Forming and sending response for submitted analysis job", "id", si.ID)
submit_response, err := submit_response(si)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
@@ -320,10 +318,6 @@ func (c *CommanderSingle) MirvaRequest(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.Write(submit_response) w.Write(submit_response)
// TODO into Storage
// session_save()
} }
func ORToArr(aor []co.OwnerRepo) ([]string, int) { func ORToArr(aor []co.OwnerRepo) ([]string, int) {
@@ -335,10 +329,7 @@ func ORToArr(aor []co.OwnerRepo) ([]string, int) {
return repos, count return repos, count
} }
func (c *CommanderSingle) submit_response(sn SessionInfo) ([]byte, error) { func submit_response(sn SessionInfo) ([]byte, error) {
slog.Debug("Forming and sending response for submitted analysis job", "id", sn.ID)
// Construct the response bottom-up // Construct the response bottom-up
var m_cr api.ControllerRepo var m_cr api.ControllerRepo
var m_ac api.Actor var m_ac api.Actor
@@ -378,7 +369,7 @@ func (c *CommanderSingle) submit_response(sn SessionInfo) ([]byte, error) {
joblist := storage.GetJobList(sn.ID) joblist := storage.GetJobList(sn.ID)
for _, job := range joblist { for _, job := range joblist {
store.SetJobInfo(co.JobSpec{ storage.SetJobInfo(co.JobSpec{
ID: sn.ID, ID: sn.ID,
OwnerRepo: job.ORL, OwnerRepo: job.ORL,
}, co.JobInfo{ }, co.JobInfo{
@@ -404,7 +395,7 @@ func (c *CommanderSingle) collectRequestInfo(w http.ResponseWriter, r *http.Requ
slog.Debug("Collecting session info") slog.Debug("Collecting session info")
if r.Body == nil { if r.Body == nil {
err := errors.New("Missing request body") err := errors.New("missing request body")
log.Println(err) log.Println(err)
http.Error(w, err.Error(), http.StatusNoContent) http.Error(w, err.Error(), http.StatusNoContent)
return "", []co.OwnerRepo{}, "", err return "", []co.OwnerRepo{}, "", err
@@ -447,8 +438,9 @@ func (c *CommanderSingle) collectRequestInfo(w http.ResponseWriter, r *http.Requ
for _, v := range msg.Repositories { for _, v := range msg.Repositories {
t := strings.Split(v, "/") t := strings.Split(v, "/")
if len(t) != 2 { if len(t) != 2 {
slog.Error("Invalid owner / repository entry", "entry", t) err := "Invalid owner / repository entry"
http.Error(w, err.Error(), http.StatusBadRequest) slog.Error(err, "entry", t)
http.Error(w, err, http.StatusBadRequest)
} }
session_repositories = append(session_repositories, session_repositories = append(session_repositories,
co.OwnerRepo{Owner: t[0], Repo: t[1]}) co.OwnerRepo{Owner: t[0], Repo: t[1]})

View File

@@ -190,6 +190,12 @@ func GetJobInfo(js co.JobSpec) co.JobInfo {
return info[js] return info[js]
} }
func SetJobInfo(js co.JobSpec, ji co.JobInfo) {
mutex.Lock()
defer mutex.Unlock()
info[js] = ji
}
func GetStatus(sessionid int, orl co.OwnerRepo) co.Status { func GetStatus(sessionid int, orl co.OwnerRepo) co.Status {
mutex.Lock() mutex.Lock()
defer mutex.Unlock() defer mutex.Unlock()