Skip to content

Commit

Permalink
Merge pull request #299 from ClusterCockpit/dev
Browse files Browse the repository at this point in the history
feat: Add buffered channel with worker thread for job start API
  • Loading branch information
moebiusband73 authored Nov 27, 2024
2 parents 16b11db + 00a5786 commit ab284ed
Show file tree
Hide file tree
Showing 29 changed files with 637 additions and 659 deletions.
239 changes: 83 additions & 156 deletions api/swagger.json

Large diffs are not rendered by default.

194 changes: 58 additions & 136 deletions api/swagger.yaml

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions cmd/cc-backend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ClusterCockpit/cc-backend/internal/config"
"github.com/ClusterCockpit/cc-backend/internal/graph"
"github.com/ClusterCockpit/cc-backend/internal/graph/generated"
"github.com/ClusterCockpit/cc-backend/internal/repository"
"github.com/ClusterCockpit/cc-backend/internal/routerConfig"
"github.com/ClusterCockpit/cc-backend/pkg/log"
"github.com/ClusterCockpit/cc-backend/pkg/runtimeEnv"
Expand Down Expand Up @@ -109,9 +110,7 @@ func serverInit() {

if !config.Keys.DisableAuthentication {
router.Handle("/login", authHandle.Login(
// On success:
http.RedirectHandler("/", http.StatusTemporaryRedirect),

// On success: Handled within Login()
// On failure:
func(rw http.ResponseWriter, r *http.Request, err error) {
rw.Header().Add("Content-Type", "text/html; charset=utf-8")
Expand All @@ -126,9 +125,7 @@ func serverInit() {
})).Methods(http.MethodPost)

router.Handle("/jwt-login", authHandle.Login(
// On success:
http.RedirectHandler("/", http.StatusTemporaryRedirect),

// On success: Handled within Login()
// On failure:
func(rw http.ResponseWriter, r *http.Request, err error) {
rw.Header().Add("Content-Type", "text/html; charset=utf-8")
Expand Down Expand Up @@ -164,11 +161,12 @@ func serverInit() {
func(rw http.ResponseWriter, r *http.Request, err error) {
rw.WriteHeader(http.StatusUnauthorized)
web.RenderTemplate(rw, "login.tmpl", &web.Page{
Title: "Authentication failed - ClusterCockpit",
MsgType: "alert-danger",
Message: err.Error(),
Build: buildInfo,
Infos: info,
Title: "Authentication failed - ClusterCockpit",
MsgType: "alert-danger",
Message: err.Error(),
Build: buildInfo,
Infos: info,
Redirect: r.RequestURI,
})
})
})
Expand Down Expand Up @@ -316,6 +314,9 @@ func serverShutdown() {
// First shut down the server gracefully (waiting for all ongoing requests)
server.Shutdown(context.Background())

// Then, wait for any async jobStarts still pending...
repository.WaitForJobStart()

// Then, wait for any async archivings still pending...
archiver.WaitForArchiving()
}
23 changes: 11 additions & 12 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
"testing"
"time"

"github.com/ClusterCockpit/cc-backend/internal/api"
"github.com/ClusterCockpit/cc-backend/internal/archiver"
Expand Down Expand Up @@ -200,6 +200,10 @@ func TestRestApi(t *testing.T) {
r.StrictSlash(true)
restapi.MountApiRoutes(r)

var TestJobId int64 = 123
var TestClusterName string = "testcluster"
var TestStartTime int64 = 123456789

const startJobBody string = `{
"jobId": 123,
"user": "testuser",
Expand All @@ -225,7 +229,6 @@ func TestRestApi(t *testing.T) {
"startTime": 123456789
}`

var dbid int64
const contextUserKey repository.ContextKey = "user"
contextUserValue := &schema.User{
Username: "testuser",
Expand All @@ -247,13 +250,10 @@ func TestRestApi(t *testing.T) {
t.Fatal(response.Status, recorder.Body.String())
}

var res api.StartJobApiResponse
if err := json.Unmarshal(recorder.Body.Bytes(), &res); err != nil {
t.Fatal(err)
}
time.Sleep(1 * time.Second)

resolver := graph.GetResolverInstance()
job, err := resolver.Query().Job(ctx, strconv.Itoa(int(res.DBID)))
job, err := restapi.JobRepository.Find(&TestJobId, &TestClusterName, &TestStartTime)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -285,8 +285,6 @@ func TestRestApi(t *testing.T) {
if len(job.Tags) != 1 || job.Tags[0].Type != "testTagType" || job.Tags[0].Name != "testTagName" || job.Tags[0].Scope != "testuser" {
t.Fatalf("unexpected tags: %#v", job.Tags)
}

dbid = res.DBID
}); !ok {
return
}
Expand Down Expand Up @@ -314,8 +312,7 @@ func TestRestApi(t *testing.T) {
}

archiver.WaitForArchiving()
resolver := graph.GetResolverInstance()
job, err := resolver.Query().Job(ctx, strconv.Itoa(int(dbid)))
job, err := restapi.JobRepository.Find(&TestJobId, &TestClusterName, &TestStartTime)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -404,8 +401,10 @@ func TestRestApi(t *testing.T) {
t.Fatal("subtest failed")
}

time.Sleep(1 * time.Second)

const stopJobBodyFailed string = `{
"jobId": 12345,
"jobId": 12345,
"cluster": "testcluster",
"jobState": "failed",
Expand Down
Loading

0 comments on commit ab284ed

Please sign in to comment.