9898: update crunch-dispatch to use lock and unlock apis instead of setting state...
authorradhika <radhika@curoverse.com>
Fri, 2 Sep 2016 15:42:35 +0000 (11:42 -0400)
committerradhika <radhika@curoverse.com>
Fri, 2 Sep 2016 15:42:35 +0000 (11:42 -0400)
sdk/go/dispatch/dispatch.go
services/crunch-dispatch-slurm/crunch-dispatch-slurm.go

index ce536de47a07be129d7f9e1f9ed730bdf30f6918..53f41d29d0bfe4b518817d2227cf38f394b8a765 100644 (file)
@@ -193,6 +193,21 @@ func (dispatcher *Dispatcher) handleUpdate(container arvados.Container) {
 
 // UpdateState makes an API call to change the state of a container.
 func (dispatcher *Dispatcher) UpdateState(uuid string, newState arvados.ContainerState) error {
+       if newState == Locked {
+               err := dispatcher.Arv.Call("POST", "containers", uuid, "lock", nil, nil)
+               if err != nil {
+                       log.Printf("Error locking container %s: %q", uuid, err)
+               }
+               return err
+       } else if newState == Queued {
+               err := dispatcher.Arv.Call("POST", "containers", uuid, "unlock", nil, nil)
+               if err != nil {
+                       log.Printf("Error unlocking container %s: %q", uuid, err)
+               }
+               return err
+       }
+
+       // All other states
        err := dispatcher.Arv.Update("containers", uuid,
                arvadosclient.Dict{
                        "container": arvadosclient.Dict{"state": newState}},
index ef08f4583a6232e245a8375602c8b438bcb5a368..fa77e70ea5667705ab15abe61278d668071e4d14 100644 (file)
@@ -151,10 +151,7 @@ func submit(dispatcher *dispatch.Dispatcher,
                        // OK, no cleanup needed
                        return
                }
-               err := dispatcher.Arv.Update("containers", container.UUID,
-                       arvadosclient.Dict{
-                               "container": arvadosclient.Dict{"state": "Queued"}},
-                       nil)
+               err := dispatcher.UpdateState(container.UUID, dispatch.Queued)
                if err != nil {
                        log.Printf("Error unlocking container %s: %v", container.UUID, err)
                }