20457: Implement MaxDispatchAttempts in test stub.
authorTom Clegg <tom@curii.com>
Mon, 1 May 2023 15:53:34 +0000 (11:53 -0400)
committerTom Clegg <tom@curii.com>
Mon, 1 May 2023 15:53:34 +0000 (11:53 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/dispatchcloud/dispatcher_test.go
lib/dispatchcloud/test/queue.go
sdk/go/arvados/container.go

index 7454b5784e54a8be36b5c4b027460b3bf72e3d08..15e545f8a85ddcac8dd10467482f21e3f959cdba 100644 (file)
@@ -151,6 +151,7 @@ func (s *DispatcherSuite) TestDispatchToStubDriver(c *check.C) {
        Drivers["test"] = s.stubDriver
        s.disp.setupOnce.Do(s.disp.initialize)
        queue := &test.Queue{
+               MaxDispatchAttempts: 5,
                ChooseType: func(ctr *arvados.Container) (arvados.InstanceType, error) {
                        return ChooseInstanceType(s.cluster, ctr)
                },
index fcb2cfb33b31627ca85ccadc2c5705c18f1e055e..e347338bf07f0ab74917e42815c0c524b3dc24a7 100644 (file)
@@ -24,6 +24,9 @@ type Queue struct {
        // must not be nil.
        ChooseType func(*arvados.Container) (arvados.InstanceType, error)
 
+       // Mimic railsapi implementation of MaxDispatchAttempts config
+       MaxDispatchAttempts int
+
        Logger logrus.FieldLogger
 
        entries      map[string]container.QueueEnt
@@ -133,7 +136,15 @@ func (q *Queue) changeState(uuid string, from, to arvados.ContainerState) error
        q.entries[uuid] = ent
        for i, ctr := range q.Containers {
                if ctr.UUID == uuid {
-                       q.Containers[i].State = to
+                       if max := q.MaxDispatchAttempts; max > 0 && ctr.LockCount >= max && to == arvados.ContainerStateQueued {
+                               q.Containers[i].State = arvados.ContainerStateCancelled
+                               q.Containers[i].RuntimeStatus = map[string]interface{}{"error": fmt.Sprintf("Failed to start: lock_count == %d", ctr.LockCount)}
+                       } else {
+                               q.Containers[i].State = to
+                               if to == arvados.ContainerStateLocked {
+                                       q.Containers[i].LockCount++
+                               }
+                       }
                        break
                }
        }
index 7b31726aa06f1d2fcd46eae82f51e6aec97cf290..2467e807a1253e2764ae657bb0ce78ee10399ee1 100644 (file)
@@ -19,6 +19,7 @@ type Container struct {
        Cwd                       string                 `json:"cwd"`
        Environment               map[string]string      `json:"environment"`
        LockedByUUID              string                 `json:"locked_by_uuid"`
+       LockCount                 int                    `json:"lock_count"`
        Mounts                    map[string]Mount       `json:"mounts"`
        Output                    string                 `json:"output"`
        OutputPath                string                 `json:"output_path"`