Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ code/
input/
live/

.DS_Store
.DS_Store

# log files
*.log
24 changes: 12 additions & 12 deletions controller/ea.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func CreateEA(res http.ResponseWriter, req *http.Request) {
var logger = util.NewLogger()
logger.Info("CreateEA API called.")
var logger = util.SharedLogger
logger.InfoCtx(req, "CreateEA API called.")

// Comment this out to test the API without authentication.
user, err := modules.Auth(req)
Expand All @@ -22,7 +22,7 @@ func CreateEA(res http.ResponseWriter, req *http.Request) {
}

// User has id, role, userName, email & fullName.
logger.Info(fmt.Sprintf("User: %s", user))
logger.InfoCtx(req, fmt.Sprintf("User: %s", user))

data, err := util.Body(req)
if err != nil {
Expand All @@ -44,7 +44,7 @@ func CreateEA(res http.ResponseWriter, req *http.Request) {

db, err := connection.PoolConn(req.Context())
if err != nil {
logger.Error(fmt.Sprintf("CreateEA: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateEA: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -66,35 +66,35 @@ func CreateEA(res http.ResponseWriter, req *http.Request) {
err = row.Scan(&runID)

if err != nil {
logger.Error(fmt.Sprintf("CreateEA.row.Scan: %s", err.Error()))
logger.Error(fmt.Sprintf("CreateEA.row.Scan: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

logger.Info(fmt.Sprintf("RunID: %s", runID))
logger.InfoCtx(req, fmt.Sprintf("RunID: %s", runID))

_, err = db.Exec(req.Context(), `
INSERT INTO access (runID, userID, mode)
VALUES ($1, $2, $3)
`, runID, user["id"], "write")

if err != nil {
logger.Error(fmt.Sprintf("CreateEA.db.Exec: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateEA.db.Exec: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

inputParams, err := json.Marshal(data)
if err != nil {
logger.Error(fmt.Sprintf("CreateEA.json.Marshal: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateEA.json.Marshal: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

// Save code and upload to minIO.
os.Mkdir("code", 0755)
if err := os.WriteFile(fmt.Sprintf("code/%v.py", runID), []byte(code), 0644); err != nil {
logger.Error(fmt.Sprintf("CreateEA.os.WriteFile: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateEA.os.WriteFile: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -106,7 +106,7 @@ func CreateEA(res http.ResponseWriter, req *http.Request) {
// Save input and upload to minIO.
os.Mkdir("input", 0755)
if err := os.WriteFile(fmt.Sprintf("input/%v.json", runID), inputParams, 0644); err != nil {
logger.Error(fmt.Sprintf("CreateEA.os.WriteFile: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateEA.os.WriteFile: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -117,12 +117,12 @@ func CreateEA(res http.ResponseWriter, req *http.Request) {

// Remove code and input files from local.
if err := os.Remove(fmt.Sprintf("code/%v.py", runID)); err != nil {
logger.Error(fmt.Sprintf("CreateEA.os.Remove: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateEA.os.Remove: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
if err := os.Remove(fmt.Sprintf("input/%v.json", runID)); err != nil {
logger.Error(fmt.Sprintf("CreateEA.os.Remove: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateEA.os.Remove: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand Down
24 changes: 12 additions & 12 deletions controller/gp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func CreateGP(res http.ResponseWriter, req *http.Request) {
var logger = util.NewLogger()
logger.Info("CreateGP API called.")
var logger = util.SharedLogger
logger.InfoCtx(req, "CreateGP API called.")

// Comment this out to test the API without authentication.
user, err := modules.Auth(req)
Expand All @@ -22,7 +22,7 @@ func CreateGP(res http.ResponseWriter, req *http.Request) {
}

// User has id, role, userName, email & fullName.
logger.Info(fmt.Sprintf("User: %s", user))
logger.InfoCtx(req, fmt.Sprintf("User: %s", user))

data, err := util.Body(req)
if err != nil {
Expand All @@ -44,7 +44,7 @@ func CreateGP(res http.ResponseWriter, req *http.Request) {

db, err := connection.PoolConn(req.Context())
if err != nil {
logger.Error(fmt.Sprintf("CreateGP: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateGP: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -59,35 +59,35 @@ func CreateGP(res http.ResponseWriter, req *http.Request) {
err = row.Scan(&runID)

if err != nil {
logger.Error(fmt.Sprintf("CreateGP.row.Scan: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateGP.row.Scan: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

logger.Info(fmt.Sprintf("RunID: %s", runID))
logger.InfoCtx(req, fmt.Sprintf("RunID: %s", runID))

_, err = db.Exec(req.Context(), `
INSERT INTO access (runID, userID, mode)
VALUES ($1, $2, $3)
`, runID, user["id"], "write")

if err != nil {
logger.Error(fmt.Sprintf("CreateGP.db.Exec: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateGP.db.Exec: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

inputParams, err := json.Marshal(data)
if err != nil {
logger.Error(fmt.Sprintf("CreateGP.json.Marshal: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateGP.json.Marshal: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

// Save code and upload to minIO.
os.Mkdir("code", 0755)
if err := os.WriteFile(fmt.Sprintf("code/%v.py", runID), []byte(code), 0644); err != nil {
logger.Error(fmt.Sprintf("CreateGP.os.WriteFile: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateGP.os.WriteFile: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -99,7 +99,7 @@ func CreateGP(res http.ResponseWriter, req *http.Request) {
// Save input and upload to minIO.
os.Mkdir("input", 0755)
if err := os.WriteFile(fmt.Sprintf("input/%v.json", runID), inputParams, 0644); err != nil {
logger.Error(fmt.Sprintf("CreateGP.os.WriteFile: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateGP.os.WriteFile: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -110,12 +110,12 @@ func CreateGP(res http.ResponseWriter, req *http.Request) {

// Remove code and input files from local.
if err := os.Remove(fmt.Sprintf("code/%v.py", runID)); err != nil {
logger.Error(fmt.Sprintf("CreateGP.os.Remove: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateGP.os.Remove: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
if err := os.Remove(fmt.Sprintf("input/%v.json", runID)); err != nil {
logger.Error(fmt.Sprintf("CreateGP.os.Remove: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateGP.os.Remove: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand Down
24 changes: 12 additions & 12 deletions controller/ml.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func CreateML(res http.ResponseWriter, req *http.Request) {
var logger = util.NewLogger()
logger.Info("CreateML API called.")
var logger = util.SharedLogger
logger.InfoCtx(req, "CreateML API called.")

// Comment this out to test the API without authentication.
user, err := modules.Auth(req)
Expand All @@ -22,7 +22,7 @@ func CreateML(res http.ResponseWriter, req *http.Request) {
}

// User has id, role, userName, email & fullName.
logger.Info(fmt.Sprintf("User: %s", user))
logger.InfoCtx(req, fmt.Sprintf("User: %s", user))

data, err := util.Body(req)
if err != nil {
Expand All @@ -44,7 +44,7 @@ func CreateML(res http.ResponseWriter, req *http.Request) {

db, err := connection.PoolConn(req.Context())
if err != nil {
logger.Error(fmt.Sprintf("CreateML: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateML: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -59,35 +59,35 @@ func CreateML(res http.ResponseWriter, req *http.Request) {
err = row.Scan(&runID)

if err != nil {
logger.Error(fmt.Sprintf("CreateML.row.Scan: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateML.row.Scan: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

logger.Info(fmt.Sprintf("RunID: %s", runID))
logger.InfoCtx(req, fmt.Sprintf("RunID: %s", runID))

_, err = db.Exec(req.Context(), `
INSERT INTO access (runID, userID, mode)
VALUES ($1, $2, $3)
`, runID, user["id"], "write")

if err != nil {
logger.Error(fmt.Sprintf("CreateML.db.Exec: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateML.db.Exec: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

inputParams, err := json.Marshal(data)
if err != nil {
logger.Error(fmt.Sprintf("CreateML.json.Marshal: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateML.json.Marshal: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

// Save code and upload to minIO.
os.Mkdir("code", 0755)
if err := os.WriteFile(fmt.Sprintf("code/%v.py", runID), []byte(code), 0644); err != nil {
logger.Error(fmt.Sprintf("CreateML.os.WriteFile: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateML.os.WriteFile: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -99,7 +99,7 @@ func CreateML(res http.ResponseWriter, req *http.Request) {
// Save input and upload to minIO.
os.Mkdir("input", 0755)
if err := os.WriteFile(fmt.Sprintf("input/%v.json", runID), inputParams, 0644); err != nil {
logger.Error(fmt.Sprintf("CreateML.os.WriteFile: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateML.os.WriteFile: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -110,12 +110,12 @@ func CreateML(res http.ResponseWriter, req *http.Request) {

// Remove code and input files from local.
if err := os.Remove(fmt.Sprintf("code/%v.py", runID)); err != nil {
logger.Error(fmt.Sprintf("CreateML.os.Remove: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateML.os.Remove: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
if err := os.Remove(fmt.Sprintf("input/%v.json", runID)); err != nil {
logger.Error(fmt.Sprintf("CreateML.os.Remove: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreateML.os.Remove: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand Down
24 changes: 12 additions & 12 deletions controller/pso.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func CreatePSO(res http.ResponseWriter, req *http.Request) {
var logger = util.NewLogger()
logger.Info("CreatePSO API called.")
var logger = util.SharedLogger
logger.InfoCtx(req, "CreatePSO API called.")

// Comment this out to test the API without authentication.
user, err := modules.Auth(req)
Expand All @@ -22,7 +22,7 @@ func CreatePSO(res http.ResponseWriter, req *http.Request) {
}

// User has id, role, userName, email & fullName.
logger.Info(fmt.Sprintf("User: %s", user))
logger.InfoCtx(req, fmt.Sprintf("User: %s", user))

data, err := util.Body(req)
if err != nil {
Expand All @@ -44,7 +44,7 @@ func CreatePSO(res http.ResponseWriter, req *http.Request) {

db, err := connection.PoolConn(req.Context())
if err != nil {
logger.Error(fmt.Sprintf("CreatePSO: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreatePSO: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -59,35 +59,35 @@ func CreatePSO(res http.ResponseWriter, req *http.Request) {
err = row.Scan(&runID)

if err != nil {
logger.Error(fmt.Sprintf("CreatePSO.row.Scan: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreatePSO.row.Scan: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

logger.Info(fmt.Sprintf("RunID: %s", runID))
logger.InfoCtx(req, fmt.Sprintf("RunID: %s", runID))

_, err = db.Exec(req.Context(), `
INSERT INTO access (runID, userID, mode)
VALUES ($1, $2, $3)
`, runID, user["id"], "write")

if err != nil {
logger.Error(fmt.Sprintf("CreatePSO.db.Exec: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreatePSO.db.Exec: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

inputParams, err := json.Marshal(data)
if err != nil {
logger.Error(fmt.Sprintf("CreatePSO.json.Marshal: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreatePSO.json.Marshal: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}

// Save code and upload to minIO.
os.Mkdir("code", 0755)
if err := os.WriteFile(fmt.Sprintf("code/%v.py", runID), []byte(code), 0644); err != nil {
logger.Error(fmt.Sprintf("CreatePSO.os.WriteFile: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreatePSO.os.WriteFile: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -99,7 +99,7 @@ func CreatePSO(res http.ResponseWriter, req *http.Request) {
// Save input and upload to minIO.
os.Mkdir("input", 0755)
if err := os.WriteFile(fmt.Sprintf("input/%v.json", runID), inputParams, 0644); err != nil {
logger.Error(fmt.Sprintf("CreatePSO.os.WriteFile: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreatePSO.os.WriteFile: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand All @@ -110,12 +110,12 @@ func CreatePSO(res http.ResponseWriter, req *http.Request) {

// Remove code and input files from local.
if err := os.Remove(fmt.Sprintf("code/%v.py", runID)); err != nil {
logger.Error(fmt.Sprintf("CreatePSO.os.Remove: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreatePSO.os.Remove: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
if err := os.Remove(fmt.Sprintf("input/%v.json", runID)); err != nil {
logger.Error(fmt.Sprintf("CreatePSO.os.Remove: %s", err.Error()))
logger.ErrorCtx(req, fmt.Sprintf("CreatePSO.os.Remove: %s", err.Error()), err)
util.JSONResponse(res, http.StatusInternalServerError, "something went wrong", nil)
return
}
Expand Down
Loading