8017: pass ram and vcpus runtime_constraints from Container to sbatch command.
authorradhika <radhika@curoverse.com>
Tue, 3 May 2016 19:09:54 +0000 (15:09 -0400)
committerradhika <radhika@curoverse.com>
Tue, 3 May 2016 19:09:54 +0000 (15:09 -0400)
services/api/test/fixtures/containers.yml
services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go

index 22004b401720366e8ab61d15cdd414b802d683b5..aa7ad314ff0c8712de4f0c31692cb0d304768cfd 100644 (file)
@@ -10,6 +10,9 @@ queued:
   output: test
   output_path: test
   command: ["echo", "hello"]
+  runtime_constraints:
+    ram: 12000000000
+    vcpus: 4
 
 completed:
   uuid: zzzzz-dz642-compltcontainer
@@ -23,3 +26,6 @@ completed:
   output: test
   output_path: test
   command: ["echo", "hello"]
+  runtime_constraints:
+    ram: 12000000000
+    vcpus: 4
index 8fbc0fa8b63810bd6a06fadab097836dfd06b113..07653b1de1668e404f9cd0ec1b086edae00951cd 100644 (file)
@@ -9,6 +9,7 @@ import (
        "os"
        "os/exec"
        "os/signal"
+       "strconv"
        "sync"
        "syscall"
        "time"
@@ -106,9 +107,10 @@ func runQueuedContainers(pollInterval, priorityPollInterval int, crunchRunComman
 
 // Container data
 type Container struct {
-       UUID     string `json:"uuid"`
-       State    string `json:"state"`
-       Priority int    `json:"priority"`
+       UUID               string         `json:"uuid"`
+       State              string         `json:"state"`
+       Priority           int            `json:"priority"`
+       RuntimeConstraints map[string]int `json:"runtime_constraints"`
 }
 
 // ContainerList is a list of the containers from api
@@ -137,8 +139,11 @@ func dispatchSlurm(priorityPollInterval int, crunchRunCommand, finishCommand str
 }
 
 // sbatchCmd
-func sbatchFunc(uuid string) *exec.Cmd {
-       return exec.Command("sbatch", "--job-name="+uuid, "--share", "--parsable")
+func sbatchFunc(container Container) *exec.Cmd {
+       return exec.Command("sbatch", "--share", "--parsable",
+               "--job-name="+container.UUID,
+               "--mem="+strconv.Itoa(container.RuntimeConstraints["ram"]),
+               "--cpus-per-task="+strconv.Itoa(container.RuntimeConstraints["vcpus"]))
 }
 
 var sbatchCmd = sbatchFunc
@@ -170,7 +175,7 @@ func submit(container Container, crunchRunCommand string) (jobid string, submitE
        }()
 
        // Create the command and attach to stdin/stdout
-       cmd := sbatchCmd(container.UUID)
+       cmd := sbatchCmd(container)
        stdinWriter, stdinerr := cmd.StdinPipe()
        if stdinerr != nil {
                submitErr = fmt.Errorf("Error creating stdin pipe %v: %q", container.UUID, stdinerr)
index 7355cff9d99cbbc0883a833b8f96a8c31902f271..82675b26b29ab4b3c1331d5fc207e5c08f28d897 100644 (file)
@@ -4,12 +4,14 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
        "git.curoverse.com/arvados.git/sdk/go/arvadostest"
 
+       "fmt"
        "io/ioutil"
        "log"
        "net/http"
        "net/http/httptest"
        "os"
        "os/exec"
+       "strconv"
        "strings"
        "syscall"
        "testing"
@@ -68,12 +70,12 @@ func (s *TestSuite) Test_doMain(c *C) {
        var striggerCmdLine []string
 
        // Override sbatchCmd
-       defer func(orig func(string) *exec.Cmd) {
+       defer func(orig func(Container) *exec.Cmd) {
                sbatchCmd = orig
        }(sbatchCmd)
-       sbatchCmd = func(uuid string) *exec.Cmd {
-               sbatchCmdLine = sbatchFunc(uuid).Args
-               return exec.Command("echo", uuid)
+       sbatchCmd = func(container Container) *exec.Cmd {
+               sbatchCmdLine = sbatchFunc(container).Args
+               return exec.Command("echo", container.UUID)
        }
 
        // Override striggerCmd
@@ -111,7 +113,12 @@ func (s *TestSuite) Test_doMain(c *C) {
        err = doMain()
        c.Check(err, IsNil)
 
-       c.Check(sbatchCmdLine, DeepEquals, []string{"sbatch", "--job-name=zzzzz-dz642-queuedcontainer", "--share", "--parsable"})
+       sbatchCmdComps := []string{"sbatch", "--share", "--parsable",
+               fmt.Sprintf("--job-name=%s", containers.Items[0].UUID),
+               fmt.Sprintf("--mem=%s", strconv.Itoa(containers.Items[0].RuntimeConstraints["ram"])),
+               fmt.Sprintf("--cpus-per-task=%s", strconv.Itoa(containers.Items[0].RuntimeConstraints["vcpus"]))}
+       c.Check(sbatchCmdLine, DeepEquals, sbatchCmdComps)
+
        c.Check(striggerCmdLine, DeepEquals, []string{"strigger", "--set", "--jobid=zzzzz-dz642-queuedcontainer\n", "--fini",
                "--program=/usr/bin/crunch-finish-slurm.sh " + os.Getenv("ARVADOS_API_HOST") + " 4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h 1 zzzzz-dz642-queuedcontainer"})