[ARVADOS] created: 1.1.1-117-g1099363

Git user git at public.curoverse.com
Fri Dec 1 12:03:32 EST 2017


        at  10993634c308dc62dd5e60f7d8d8ebf0391dd050 (commit)


commit 10993634c308dc62dd5e60f7d8d8ebf0391dd050
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Fri Dec 1 12:01:39 2017 -0500

    12573: Ensure priority is set on container requests created by other containers.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index 178c156..68885d7 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -274,7 +274,10 @@ class ContainerRequest < ArvadosModel
 
     token_uuid = current_api_client_authorization.andand.uuid
     container = Container.where('auth_uuid=?', token_uuid).order('created_at desc').first
-    self.requesting_container_uuid = container.uuid if container
+    if container
+      self.requesting_container_uuid = container.uuid
+      self.priority = container.priority
+    end
     true
   end
 end
diff --git a/services/api/test/fixtures/containers.yml b/services/api/test/fixtures/containers.yml
index a7ad6f0..7e2de6d 100644
--- a/services/api/test/fixtures/containers.yml
+++ b/services/api/test/fixtures/containers.yml
@@ -28,7 +28,7 @@ running:
   uuid: zzzzz-dz642-runningcontainr
   owner_uuid: zzzzz-tpzed-000000000000000
   state: Running
-  priority: 1
+  priority: 12
   created_at: <%= 1.minute.ago.to_s(:db) %>
   updated_at: <%= 1.minute.ago.to_s(:db) %>
   started_at: <%= 1.minute.ago.to_s(:db) %>
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index 68f5da0..8a1b7d3 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -324,14 +324,15 @@ class ContainerRequestTest < ActiveSupport::TestCase
   end
 
   [
-    ['running_container_auth', 'zzzzz-dz642-runningcontainr'],
-    ['active_no_prefs', nil],
-  ].each do |token, expected|
+    ['running_container_auth', 'zzzzz-dz642-runningcontainr', containers(:running).priority],
+    ['active_no_prefs', nil, 500],
+  ].each do |token, expected, expected_priority|
     test "create as #{token} and expect requesting_container_uuid to be #{expected}" do
       set_user_from_auth token
       cr = ContainerRequest.create(container_image: "img", output_path: "/tmp", command: ["echo", "foo"])
       assert_not_nil cr.uuid, 'uuid should be set for newly created container_request'
       assert_equal expected, cr.requesting_container_uuid
+      assert_equal expected_priority, cr.priority
     end
   end
 

commit 28560112303491b46c46377bc051e605e36a0927
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Fri Dec 1 10:01:37 2017 -0500

    12573: Fix scontrol Nice (due of error in scontrol man page).
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
index 2f30ebf..c6ef47c 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
@@ -194,7 +194,7 @@ func scancelFunc(container arvados.Container) *exec.Cmd {
 
 // scontrolCmd
 func scontrolFunc(container arvados.Container) *exec.Cmd {
-	return exec.Command("scontrol", "update", "JobName="+container.UUID, fmt.Sprintf("--nice=%d", niceness(container.Priority)))
+	return exec.Command("scontrol", "update", "JobName="+container.UUID, fmt.Sprintf("Nice=%d", niceness(container.Priority)))
 }
 
 // Wrap these so that they can be overridden by tests
diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
index 052cdfb..33cfdfc 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
@@ -453,5 +453,5 @@ func (s *TestSuite) TestIntegrationChangePriority(c *C) {
 			dispatcher.UpdateState(container.UUID, dispatch.Complete)
 		})
 	c.Check(container.State, Equals, arvados.ContainerStateComplete)
-	c.Check(scontrolCmdLine, DeepEquals, []string{"scontrol", "update", "JobName=zzzzz-dz642-queuedcontainer", "--nice=400000"})
+	c.Check(scontrolCmdLine, DeepEquals, []string{"scontrol", "update", "JobName=zzzzz-dz642-queuedcontainer", "Nice=400000"})
 }

commit 0bc641e077a050b3f86957514fae0e4d8ba1770b
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Thu Nov 30 16:54:27 2017 -0500

    12573: Add test for dynamic priority adjustment.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
index f379099..2f30ebf 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
@@ -294,7 +294,7 @@ func run(disp *dispatch.Dispatcher, ctr arvados.Container, status <-chan arvados
 			} else if updated.Priority == 0 {
 				log.Printf("Container %s has state %q, priority %d: cancel slurm job", ctr.UUID, updated.State, updated.Priority)
 				scancel(ctr)
-			} else if niceness(updated.Priority) != sqCheck.GetNiceness(ctr.UUID) {
+			} else if niceness(updated.Priority) != sqCheck.GetNiceness(ctr.UUID) && sqCheck.GetNiceness(ctr.UUID) != -1 {
 				// dynamically adjust priority
 				scontrolUpdate(updated)
 			}
diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
index 58af4a3..052cdfb 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
@@ -64,6 +64,101 @@ func (s *MockArvadosServerSuite) TearDownTest(c *C) {
 	arvadostest.ResetEnv()
 }
 
+func (s *TestSuite) integrationTest(c *C,
+	newSqueueCmd func() *exec.Cmd,
+	newScancelCmd func(arvados.Container) *exec.Cmd,
+	newSbatchCmd func(arvados.Container) *exec.Cmd,
+	newScontrolCmd func(arvados.Container) *exec.Cmd,
+	sbatchCmdComps []string,
+	runContainer func(*dispatch.Dispatcher, arvados.Container)) arvados.Container {
+	arvadostest.ResetEnv()
+
+	arv, err := arvadosclient.MakeArvadosClient()
+	c.Assert(err, IsNil)
+
+	var sbatchCmdLine []string
+
+	// Override sbatchCmd
+	defer func(orig func(arvados.Container) *exec.Cmd) {
+		sbatchCmd = orig
+	}(sbatchCmd)
+
+	if newSbatchCmd != nil {
+		sbatchCmd = newSbatchCmd
+	} else {
+		sbatchCmd = func(container arvados.Container) *exec.Cmd {
+			sbatchCmdLine = sbatchFunc(container).Args
+			return exec.Command("sh")
+		}
+	}
+
+	// Override squeueCmd
+	defer func(orig func() *exec.Cmd) {
+		squeueCmd = orig
+	}(squeueCmd)
+	squeueCmd = newSqueueCmd
+
+	// Override scancel
+	defer func(orig func(arvados.Container) *exec.Cmd) {
+		scancelCmd = orig
+	}(scancelCmd)
+	scancelCmd = newScancelCmd
+
+	// Override scontrol
+	defer func(orig func(arvados.Container) *exec.Cmd) {
+		scontrolCmd = orig
+	}(scontrolCmd)
+	scontrolCmd = newScontrolCmd
+
+	// There should be one queued container
+	params := arvadosclient.Dict{
+		"filters": [][]string{{"state", "=", "Queued"}},
+	}
+	var containers arvados.ContainerList
+	err = arv.List("containers", params, &containers)
+	c.Check(err, IsNil)
+	c.Check(len(containers.Items), Equals, 1)
+
+	theConfig.CrunchRunCommand = []string{"echo"}
+
+	ctx, cancel := context.WithCancel(context.Background())
+	doneRun := make(chan struct{})
+
+	dispatcher := dispatch.Dispatcher{
+		Arv:        arv,
+		PollPeriod: time.Duration(1) * time.Second,
+		RunContainer: func(disp *dispatch.Dispatcher, ctr arvados.Container, status <-chan arvados.Container) {
+			go func() {
+				runContainer(disp, ctr)
+				doneRun <- struct{}{}
+			}()
+			run(disp, ctr, status)
+			cancel()
+		},
+	}
+
+	sqCheck = &SqueueChecker{Period: 500 * time.Millisecond}
+
+	err = dispatcher.Run(ctx)
+	<-doneRun
+	c.Assert(err, Equals, context.Canceled)
+
+	sqCheck.Stop()
+
+	c.Check(sbatchCmdLine, DeepEquals, sbatchCmdComps)
+
+	// There should be no queued containers now
+	err = arv.List("containers", params, &containers)
+	c.Check(err, IsNil)
+	c.Check(len(containers.Items), Equals, 0)
+
+	// Previously "Queued" container should now be in "Complete" state
+	var container arvados.Container
+	err = arv.Get("containers", "zzzzz-dz642-queuedcontainer", nil, &container)
+	c.Check(err, IsNil)
+	return container
+}
+
 func (s *TestSuite) TestIntegrationNormal(c *C) {
 	done := false
 	container := s.integrationTest(c,
@@ -76,6 +171,7 @@ func (s *TestSuite) TestIntegrationNormal(c *C) {
 		},
 		nil,
 		nil,
+		nil,
 		[]string(nil),
 		func(dispatcher *dispatch.Dispatcher, container arvados.Container) {
 			dispatcher.UpdateState(container.UUID, dispatch.Running)
@@ -109,6 +205,7 @@ func (s *TestSuite) TestIntegrationCancel(c *C) {
 			}
 		},
 		nil,
+		nil,
 		[]string(nil),
 		func(dispatcher *dispatch.Dispatcher, container arvados.Container) {
 			dispatcher.UpdateState(container.UUID, dispatch.Running)
@@ -127,6 +224,7 @@ func (s *TestSuite) TestIntegrationMissingFromSqueue(c *C) {
 		func() *exec.Cmd { return exec.Command("echo") },
 		nil,
 		nil,
+		nil,
 		[]string{"sbatch",
 			fmt.Sprintf("--job-name=%s", "zzzzz-dz642-queuedcontainer"),
 			fmt.Sprintf("--mem=%d", 11445),
@@ -148,6 +246,7 @@ func (s *TestSuite) TestSbatchFail(c *C) {
 		func(container arvados.Container) *exec.Cmd {
 			return exec.Command("false")
 		},
+		nil,
 		[]string(nil),
 		func(dispatcher *dispatch.Dispatcher, container arvados.Container) {
 			dispatcher.UpdateState(container.UUID, dispatch.Running)
@@ -166,102 +265,6 @@ func (s *TestSuite) TestSbatchFail(c *C) {
 	c.Assert(len(ll.Items), Equals, 1)
 }
 
-func (s *TestSuite) integrationTest(c *C,
-	newSqueueCmd func() *exec.Cmd,
-	newScancelCmd func(arvados.Container) *exec.Cmd,
-	newSbatchCmd func(arvados.Container) *exec.Cmd,
-	sbatchCmdComps []string,
-	runContainer func(*dispatch.Dispatcher, arvados.Container)) arvados.Container {
-	arvadostest.ResetEnv()
-
-	arv, err := arvadosclient.MakeArvadosClient()
-	c.Assert(err, IsNil)
-
-	var sbatchCmdLine []string
-
-	// Override sbatchCmd
-	defer func(orig func(arvados.Container) *exec.Cmd) {
-		sbatchCmd = orig
-	}(sbatchCmd)
-
-	if newSbatchCmd != nil {
-		sbatchCmd = newSbatchCmd
-	} else {
-		sbatchCmd = func(container arvados.Container) *exec.Cmd {
-			sbatchCmdLine = sbatchFunc(container).Args
-			return exec.Command("sh")
-		}
-	}
-
-	// Override squeueCmd
-	defer func(orig func() *exec.Cmd) {
-		squeueCmd = orig
-	}(squeueCmd)
-	squeueCmd = newSqueueCmd
-
-	// Override scancel
-	defer func(orig func(arvados.Container) *exec.Cmd) {
-		scancelCmd = orig
-	}(scancelCmd)
-	scancelCmd = newScancelCmd
-
-	// Override scontrol
-	defer func(orig func(arvados.Container) *exec.Cmd) {
-		scontrolCmd = orig
-	}(scontrolCmd)
-	scontrolCmd = func(container arvados.Container) *exec.Cmd {
-		return exec.Command("true")
-	}
-
-	// There should be one queued container
-	params := arvadosclient.Dict{
-		"filters": [][]string{{"state", "=", "Queued"}},
-	}
-	var containers arvados.ContainerList
-	err = arv.List("containers", params, &containers)
-	c.Check(err, IsNil)
-	c.Check(len(containers.Items), Equals, 1)
-
-	theConfig.CrunchRunCommand = []string{"echo"}
-
-	ctx, cancel := context.WithCancel(context.Background())
-	doneRun := make(chan struct{})
-
-	dispatcher := dispatch.Dispatcher{
-		Arv:        arv,
-		PollPeriod: time.Duration(1) * time.Second,
-		RunContainer: func(disp *dispatch.Dispatcher, ctr arvados.Container, status <-chan arvados.Container) {
-			go func() {
-				runContainer(disp, ctr)
-				doneRun <- struct{}{}
-			}()
-			run(disp, ctr, status)
-			cancel()
-		},
-	}
-
-	sqCheck = &SqueueChecker{Period: 500 * time.Millisecond}
-
-	err = dispatcher.Run(ctx)
-	<-doneRun
-	c.Assert(err, Equals, context.Canceled)
-
-	sqCheck.Stop()
-
-	c.Check(sbatchCmdLine, DeepEquals, sbatchCmdComps)
-
-	// There should be no queued containers now
-	err = arv.List("containers", params, &containers)
-	c.Check(err, IsNil)
-	c.Check(len(containers.Items), Equals, 0)
-
-	// Previously "Queued" container should now be in "Complete" state
-	var container arvados.Container
-	err = arv.Get("containers", "zzzzz-dz642-queuedcontainer", nil, &container)
-	c.Check(err, IsNil)
-	return container
-}
-
 func (s *MockArvadosServerSuite) TestAPIErrorGettingContainers(c *C) {
 	apiStubResponses := make(map[string]arvadostest.StubResponse)
 	apiStubResponses["/arvados/v1/api_client_authorizations/current"] = arvadostest.StubResponse{200, `{"uuid":"` + arvadostest.Dispatch1AuthUUID + `"}`}
@@ -415,3 +418,40 @@ func (s *MockArvadosServerSuite) TestSbatchPartition(c *C) {
 
 	c.Check(sbatchCmd.Args, DeepEquals, expected)
 }
+
+func (s *TestSuite) TestIntegrationChangePriority(c *C) {
+	var scontrolCmdLine []string
+	step := 0
+
+	container := s.integrationTest(c,
+		func() *exec.Cmd {
+			if step == 0 {
+				return exec.Command("echo", "zzzzz-dz642-queuedcontainer 999000")
+			} else if step == 1 {
+				return exec.Command("echo", "zzzzz-dz642-queuedcontainer 400000")
+			} else {
+				return exec.Command("echo")
+			}
+		},
+		func(arvados.Container) *exec.Cmd { return exec.Command("true") },
+		nil,
+		func(container arvados.Container) *exec.Cmd {
+			scontrolCmdLine = scontrolFunc(container).Args
+			step = 1
+			return exec.Command("true")
+		},
+		[]string(nil),
+		func(dispatcher *dispatch.Dispatcher, container arvados.Container) {
+			dispatcher.UpdateState(container.UUID, dispatch.Running)
+			time.Sleep(1 * time.Second)
+			dispatcher.Arv.Update("containers", container.UUID,
+				arvadosclient.Dict{
+					"container": arvadosclient.Dict{"priority": 600}},
+				nil)
+			time.Sleep(1 * time.Second)
+			step = 2
+			dispatcher.UpdateState(container.UUID, dispatch.Complete)
+		})
+	c.Check(container.State, Equals, arvados.ContainerStateComplete)
+	c.Check(scontrolCmdLine, DeepEquals, []string{"scontrol", "update", "JobName=zzzzz-dz642-queuedcontainer", "--nice=400000"})
+}

commit ab3d39a8fdbc76425f48988c27187f3b54967ff9
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Thu Nov 30 15:45:25 2017 -0500

    12573: Translate Arvados priority to slurm niceness.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
index 30cbb79..f379099 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
@@ -151,6 +151,16 @@ func checkSqueueForOrphans(dispatcher *dispatch.Dispatcher, sqCheck *SqueueCheck
 	}
 }
 
+func niceness(priority int) int {
+	if priority > 1000 {
+		priority = 1000
+	}
+	if priority < 0 {
+		priority = 0
+	}
+	return (1000 - priority) * 1000
+}
+
 // sbatchCmd
 func sbatchFunc(container arvados.Container) *exec.Cmd {
 	mem := int64(math.Ceil(float64(container.RuntimeConstraints.RAM+container.RuntimeConstraints.KeepCacheRAM) / float64(1048576)))
@@ -169,6 +179,7 @@ func sbatchFunc(container arvados.Container) *exec.Cmd {
 	sbatchArgs = append(sbatchArgs, fmt.Sprintf("--mem=%d", mem))
 	sbatchArgs = append(sbatchArgs, fmt.Sprintf("--cpus-per-task=%d", container.RuntimeConstraints.VCPUs))
 	sbatchArgs = append(sbatchArgs, fmt.Sprintf("--tmp=%d", disk))
+	sbatchArgs = append(sbatchArgs, fmt.Sprintf("--nice=%d", niceness(container.Priority)))
 	if len(container.SchedulingParameters.Partitions) > 0 {
 		sbatchArgs = append(sbatchArgs, fmt.Sprintf("--partition=%s", strings.Join(container.SchedulingParameters.Partitions, ",")))
 	}
@@ -181,9 +192,15 @@ func scancelFunc(container arvados.Container) *exec.Cmd {
 	return exec.Command("scancel", "--name="+container.UUID)
 }
 
+// scontrolCmd
+func scontrolFunc(container arvados.Container) *exec.Cmd {
+	return exec.Command("scontrol", "update", "JobName="+container.UUID, fmt.Sprintf("--nice=%d", niceness(container.Priority)))
+}
+
 // Wrap these so that they can be overridden by tests
 var sbatchCmd = sbatchFunc
 var scancelCmd = scancelFunc
+var scontrolCmd = scontrolFunc
 
 // Submit job to slurm using sbatch.
 func submit(dispatcher *dispatch.Dispatcher, container arvados.Container, crunchRunCommand []string) error {
@@ -277,6 +294,9 @@ func run(disp *dispatch.Dispatcher, ctr arvados.Container, status <-chan arvados
 			} else if updated.Priority == 0 {
 				log.Printf("Container %s has state %q, priority %d: cancel slurm job", ctr.UUID, updated.State, updated.Priority)
 				scancel(ctr)
+			} else if niceness(updated.Priority) != sqCheck.GetNiceness(ctr.UUID) {
+				// dynamically adjust priority
+				scontrolUpdate(updated)
 			}
 		}
 	}
@@ -297,6 +317,21 @@ func scancel(ctr arvados.Container) {
 	}
 }
 
+func scontrolUpdate(ctr arvados.Container) {
+	sqCheck.L.Lock()
+	cmd := scontrolCmd(ctr)
+	msg, err := cmd.CombinedOutput()
+	sqCheck.L.Unlock()
+
+	if err != nil {
+		log.Printf("%q %q: %s %q", cmd.Path, cmd.Args, err, msg)
+		time.Sleep(time.Second)
+	} else if sqCheck.HasUUID(ctr.UUID) {
+		log.Printf("Container %s priority is now %v, niceness is now %v",
+			ctr.UUID, ctr.Priority, sqCheck.GetNiceness(ctr.UUID))
+	}
+}
+
 func readConfig(dst interface{}, path string) error {
 	err := config.LoadFile(dst, path)
 	if err != nil && os.IsNotExist(err) && path == defaultConfigPath {
diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
index 5879f84..58af4a3 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
@@ -71,7 +71,7 @@ func (s *TestSuite) TestIntegrationNormal(c *C) {
 			if done {
 				return exec.Command("true")
 			} else {
-				return exec.Command("echo", "zzzzz-dz642-queuedcontainer")
+				return exec.Command("echo", "zzzzz-dz642-queuedcontainer 999000")
 			}
 		},
 		nil,
@@ -96,7 +96,7 @@ func (s *TestSuite) TestIntegrationCancel(c *C) {
 			if cmd != nil && cmd.ProcessState != nil {
 				return exec.Command("true")
 			} else {
-				return exec.Command("echo", "zzzzz-dz642-queuedcontainer")
+				return exec.Command("echo", "zzzzz-dz642-queuedcontainer 999000")
 			}
 		},
 		func(container arvados.Container) *exec.Cmd {
@@ -131,7 +131,8 @@ func (s *TestSuite) TestIntegrationMissingFromSqueue(c *C) {
 			fmt.Sprintf("--job-name=%s", "zzzzz-dz642-queuedcontainer"),
 			fmt.Sprintf("--mem=%d", 11445),
 			fmt.Sprintf("--cpus-per-task=%d", 4),
-			fmt.Sprintf("--tmp=%d", 45777)},
+			fmt.Sprintf("--tmp=%d", 45777),
+			fmt.Sprintf("--nice=%d", 999000)},
 		func(dispatcher *dispatch.Dispatcher, container arvados.Container) {
 			dispatcher.UpdateState(container.UUID, dispatch.Running)
 			time.Sleep(3 * time.Second)
@@ -204,6 +205,14 @@ func (s *TestSuite) integrationTest(c *C,
 	}(scancelCmd)
 	scancelCmd = newScancelCmd
 
+	// Override scontrol
+	defer func(orig func(arvados.Container) *exec.Cmd) {
+		scontrolCmd = orig
+	}(scontrolCmd)
+	scontrolCmd = func(container arvados.Container) *exec.Cmd {
+		return exec.Command("true")
+	}
+
 	// There should be one queued container
 	params := arvadosclient.Dict{
 		"filters": [][]string{{"state", "=", "Queued"}},
@@ -377,25 +386,32 @@ func (s *MockArvadosServerSuite) TestSbatchFuncWithConfigArgs(c *C) {
 func testSbatchFuncWithArgs(c *C, args []string) {
 	theConfig.SbatchArguments = append(theConfig.SbatchArguments, args...)
 
-	container := arvados.Container{UUID: "123", RuntimeConstraints: arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 2}}
+	container := arvados.Container{
+		UUID:               "123",
+		RuntimeConstraints: arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 2},
+		Priority:           1}
 	sbatchCmd := sbatchFunc(container)
 
 	var expected []string
 	expected = append(expected, "sbatch")
 	expected = append(expected, theConfig.SbatchArguments...)
-	expected = append(expected, "--job-name=123", "--mem=239", "--cpus-per-task=2", "--tmp=0")
+	expected = append(expected, "--job-name=123", "--mem=239", "--cpus-per-task=2", "--tmp=0", "--nice=999000")
 
 	c.Check(sbatchCmd.Args, DeepEquals, expected)
 }
 
 func (s *MockArvadosServerSuite) TestSbatchPartition(c *C) {
 	theConfig.SbatchArguments = nil
-	container := arvados.Container{UUID: "123", RuntimeConstraints: arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 1}, SchedulingParameters: arvados.SchedulingParameters{Partitions: []string{"blurb", "b2"}}}
+	container := arvados.Container{
+		UUID:                 "123",
+		RuntimeConstraints:   arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 1},
+		SchedulingParameters: arvados.SchedulingParameters{Partitions: []string{"blurb", "b2"}},
+		Priority:             1}
 	sbatchCmd := sbatchFunc(container)
 
 	var expected []string
 	expected = append(expected, "sbatch")
-	expected = append(expected, "--job-name=123", "--mem=239", "--cpus-per-task=1", "--tmp=0", "--partition=blurb,b2")
+	expected = append(expected, "--job-name=123", "--mem=239", "--cpus-per-task=1", "--tmp=0", "--nice=999000", "--partition=blurb,b2")
 
 	c.Check(sbatchCmd.Args, DeepEquals, expected)
 }
diff --git a/services/crunch-dispatch-slurm/squeue.go b/services/crunch-dispatch-slurm/squeue.go
index d22e025..3f73b3c 100644
--- a/services/crunch-dispatch-slurm/squeue.go
+++ b/services/crunch-dispatch-slurm/squeue.go
@@ -6,6 +6,7 @@ package main
 
 import (
 	"bytes"
+	"fmt"
 	"log"
 	"os/exec"
 	"strings"
@@ -17,14 +18,14 @@ import (
 // command 'squeue'.
 type SqueueChecker struct {
 	Period    time.Duration
-	uuids     map[string]bool
+	uuids     map[string]int
 	startOnce sync.Once
 	done      chan struct{}
 	sync.Cond
 }
 
 func squeueFunc() *exec.Cmd {
-	return exec.Command("squeue", "--all", "--format=%j")
+	return exec.Command("squeue", "--all", "--format=%j %y")
 }
 
 var squeueCmd = squeueFunc
@@ -40,7 +41,23 @@ func (sqc *SqueueChecker) HasUUID(uuid string) bool {
 
 	// block until next squeue broadcast signaling an update.
 	sqc.Wait()
-	return sqc.uuids[uuid]
+	_, exists := sqc.uuids[uuid]
+	return exists
+}
+
+// GetNiceness returns the niceness of a given uuid, or -1 if it doesn't exist.
+func (sqc *SqueueChecker) GetNiceness(uuid string) int {
+	sqc.startOnce.Do(sqc.start)
+
+	sqc.L.Lock()
+	defer sqc.L.Unlock()
+
+	n, exists := sqc.uuids[uuid]
+	if exists {
+		return n
+	} else {
+		return -1
+	}
 }
 
 // Stop stops the squeue monitoring goroutine. Do not call HasUUID
@@ -70,10 +87,15 @@ func (sqc *SqueueChecker) check() {
 		return
 	}
 
-	uuids := strings.Split(stdout.String(), "\n")
-	sqc.uuids = make(map[string]bool, len(uuids))
-	for _, uuid := range uuids {
-		sqc.uuids[uuid] = true
+	lines := strings.Split(stdout.String(), "\n")
+	sqc.uuids = make(map[string]int, len(lines))
+	for _, line := range lines {
+		var uuid string
+		var nice int
+		fmt.Sscan(line, &uuid, &nice)
+		if uuid != "" {
+			sqc.uuids[uuid] = nice
+		}
 	}
 	sqc.Broadcast()
 }

commit c108a18d477c34c7f89d9a27af34751133329786
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Thu Nov 30 14:39:41 2017 -0500

    12573: Clamp range of priority to [0,1000] for container & container request.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 466adc0..98e5233 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -24,6 +24,7 @@ class Container < ArvadosModel
   before_validation :fill_field_defaults, :if => :new_record?
   before_validation :set_timestamps
   validates :command, :container_image, :output_path, :cwd, :priority, :presence => true
+  validates :priority, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 1000 }
   validate :validate_state_change
   validate :validate_change
   validate :validate_lock
diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index 94e4e1f..178c156 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -23,6 +23,7 @@ class ContainerRequest < ArvadosModel
   before_validation :set_container
   validates :command, :container_image, :output_path, :cwd, :presence => true
   validates :output_ttl, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
+  validates :priority, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 1000 }
   validate :validate_state_change
   validate :check_update_whitelist
   after_save :update_priority
@@ -158,6 +159,7 @@ class ContainerRequest < ArvadosModel
     self.container_count_max ||= Rails.configuration.container_count_max
     self.scheduling_parameters ||= {}
     self.output_ttl ||= 0
+    self.priority ||= 500
   end
 
   def set_container
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index cecf7b8..68f5da0 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -41,7 +41,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
     cr = create_minimal_req!
 
     assert_nil cr.container_uuid
-    assert_nil cr.priority
+    assert_equal 500, cr.priority
 
     check_bogus_states cr
 
@@ -109,6 +109,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
   test "Container request priority must be non-nil" do
     set_user_from_auth :active
     cr = create_minimal_req!(priority: nil)
+    cr.priority = nil
     cr.state = "Committed"
     assert_raises(ActiveRecord::RecordInvalid) do
       cr.save!
@@ -803,4 +804,35 @@ class ContainerRequestTest < ActiveSupport::TestCase
       assert_nothing_raised {cr.destroy}
     end
   end
+
+  test "Container request valid priority" do
+    set_user_from_auth :active
+    cr = create_minimal_req!
+
+    assert_raises(ActiveRecord::RecordInvalid) do
+      cr.priority = -1
+      cr.save!
+    end
+
+    cr.priority = 0
+    cr.save!
+
+    cr.priority = 1
+    cr.save!
+
+    cr.priority = 500
+    cr.save!
+
+    cr.priority = 999
+    cr.save!
+
+    cr.priority = 1000
+    cr.save!
+
+    assert_raises(ActiveRecord::RecordInvalid) do
+      cr.priority = 1001
+      cr.save!
+    end
+  end
+
 end
diff --git a/services/api/test/unit/container_test.rb b/services/api/test/unit/container_test.rb
index 09373fd..ab53240 100644
--- a/services/api/test/unit/container_test.rb
+++ b/services/api/test/unit/container_test.rb
@@ -95,6 +95,42 @@ class ContainerTest < ActiveSupport::TestCase
     end
   end
 
+  test "Container request valid priority" do
+    act_as_system_user do
+      cr, _ = minimal_new(environment: {},
+                      mounts: {"BAR" => "FOO"},
+                      output_path: "/tmp",
+                      priority: 1,
+                      runtime_constraints: {"vcpus" => 1, "ram" => 1})
+
+      assert_raises(ActiveRecord::RecordInvalid) do
+        cr.priority = -1
+        cr.save!
+      end
+
+      cr.priority = 0
+      cr.save!
+
+      cr.priority = 1
+      cr.save!
+
+      cr.priority = 500
+      cr.save!
+
+      cr.priority = 999
+      cr.save!
+
+      cr.priority = 1000
+      cr.save!
+
+      assert_raises(ActiveRecord::RecordInvalid) do
+        cr.priority = 1001
+        cr.save!
+      end
+    end
+  end
+
+
   test "Container serialized hash attributes sorted before save" do
     env = {"C" => 3, "B" => 2, "A" => 1}
     m = {"F" => {"kind" => 3}, "E" => {"kind" => 2}, "D" => {"kind" => 1}}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list