Skip to content

Commit

Permalink
Merge pull request #14 from cyverse-de/fix-overage-check
Browse files Browse the repository at this point in the history
Fix the overage check
  • Loading branch information
johnworth authored Dec 6, 2022
2 parents b2faa7a + 56def3d commit 64dda7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/cockroachdb/apd"
Expand Down Expand Up @@ -92,7 +92,17 @@ func (a *AMQPMessenger) validateLaunch(ctx context.Context, job *model.Job) erro
}

if overages != nil && len(overages.Overages) != 0 {
return fmt.Errorf("%s has resource overages", job.Submitter)
var inOverage bool

for _, ov := range overages.Overages {
if ov.Usage >= ov.Quota && ov.ResourceName == "cpu.hours" {
inOverage = true
}
}

if inOverage {
return fmt.Errorf("%s has resource overages", job.Submitter)
}
}

return nil
Expand Down Expand Up @@ -272,7 +282,7 @@ func (j *JEXAdapter) LaunchHandler(c echo.Context) error {
log := log.WithFields(logrus.Fields{"context": "app launch"})

log.Debug("reading request body")
bodyBytes, err := ioutil.ReadAll(request.Body)
bodyBytes, err := io.ReadAll(request.Body)
if err != nil {
log.Error(err)
return err
Expand Down
4 changes: 2 additions & 2 deletions previewer/previewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package previewer

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"

"github.com/cyverse-de/jex-adapter/logging"
Expand All @@ -28,7 +28,7 @@ func (p *Previewer) Routes(router types.Router) {
func (p *Previewer) PreviewHandler(c echo.Context) error {
body := c.Request().Body

bodyBytes, err := ioutil.ReadAll(body)
bodyBytes, err := io.ReadAll(body)
if err != nil {
log.Error(err)
return err
Expand Down

0 comments on commit 64dda7f

Please sign in to comment.