X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/dbbb649c9b797da8f6805af3a7e74e57b075d294..a3d2b8e1de5b8c785846ddc57ae9a4c02bc51adc:/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go index 300e923640..84105e1fc7 100644 --- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go +++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go @@ -7,7 +7,6 @@ package main // Dispatcher service for Crunch that submits containers to the slurm queue. import ( - "bytes" "context" "flag" "fmt" @@ -18,11 +17,12 @@ import ( "strings" "time" - "git.curoverse.com/arvados.git/lib/config" - "git.curoverse.com/arvados.git/lib/dispatchcloud" - "git.curoverse.com/arvados.git/sdk/go/arvados" - "git.curoverse.com/arvados.git/sdk/go/arvadosclient" - "git.curoverse.com/arvados.git/sdk/go/dispatch" + "git.arvados.org/arvados.git/lib/cmd" + "git.arvados.org/arvados.git/lib/config" + "git.arvados.org/arvados.git/lib/dispatchcloud" + "git.arvados.org/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/sdk/go/arvadosclient" + "git.arvados.org/arvados.git/sdk/go/dispatch" "github.com/coreos/go-systemd/daemon" "github.com/ghodss/yaml" "github.com/sirupsen/logrus" @@ -77,7 +77,7 @@ func (disp *Dispatcher) configure(prog string, args []string) error { if disp.logger == nil { disp.logger = logrus.StandardLogger() } - flags := flag.NewFlagSet(prog, flag.ExitOnError) + flags := flag.NewFlagSet(prog, flag.ContinueOnError) flags.Usage = func() { usage(flags) } loader := config.NewLoader(nil, disp.logger) @@ -92,13 +92,9 @@ func (disp *Dispatcher) configure(prog string, args []string) error { false, "Print version information and exit.") - args = loader.MungeLegacyConfigArgs(logrus.StandardLogger(), args, "-legacy-crunch-dispatch-slurm-config") - - // Parse args; omit the first arg which is the command name - err := flags.Parse(args) - - if err == flag.ErrHelp { - return nil + args = loader.MungeLegacyConfigArgs(disp.logger, args, "-legacy-crunch-dispatch-slurm-config") + if ok, code := cmd.ParseFlags(flags, prog, args, "", os.Stderr); !ok { + os.Exit(code) } // Print version information if requested @@ -118,6 +114,8 @@ func (disp *Dispatcher) configure(prog string, args []string) error { return fmt.Errorf("config error: %s", err) } + disp.logger = disp.logger.WithField("ClusterID", disp.cluster.ClusterID) + disp.Client.APIHost = disp.cluster.Services.Controller.ExternalURL.Host disp.Client.AuthToken = disp.cluster.SystemRootToken disp.Client.Insecure = disp.cluster.TLS.Insecure @@ -132,17 +130,10 @@ func (disp *Dispatcher) configure(prog string, args []string) error { if disp.Client.Insecure { os.Setenv("ARVADOS_API_HOST_INSECURE", "1") } - ks := "" - if length(disp.cluster.Containers.SLURM.KeepServices) > 0 { - for _, svc := range disp.cluster.Containers.SLURM.KeepServices { - for k, _ := range svc.InternalURLs { - ks += k - ks += " " - } - } - } - os.Setenv("ARVADOS_KEEP_SERVICES", ks) os.Setenv("ARVADOS_EXTERNAL_CLIENT", "") + for k, v := range disp.cluster.Containers.SLURM.SbatchEnvironmentVariables { + os.Setenv(k, v) + } } else { disp.logger.Warnf("Client credentials missing from config, so falling back on environment variables (deprecated).") } @@ -209,7 +200,7 @@ var containerUuidPattern = regexp.MustCompile(`^[a-z0-9]{5}-dz642-[a-z0-9]{15}$` // Cancelled or Complete. See https://dev.arvados.org/issues/10979 func (disp *Dispatcher) checkSqueueForOrphans() { for _, uuid := range disp.sqCheck.All() { - if !containerUuidPattern.MatchString(uuid) { + if !containerUuidPattern.MatchString(uuid) || !strings.HasPrefix(uuid, disp.cluster.ClusterID) { continue } err := disp.TrackContainer(uuid) @@ -262,6 +253,7 @@ func (disp *Dispatcher) submit(container arvados.Container, crunchRunCommand []s // append() here avoids modifying crunchRunCommand's // underlying array, which is shared with other goroutines. crArgs := append([]string(nil), crunchRunCommand...) + crArgs = append(crArgs, "--runtime-engine="+disp.cluster.Containers.RuntimeEngine) crArgs = append(crArgs, container.UUID) crScript := strings.NewReader(execScript(crArgs)) @@ -277,7 +269,7 @@ func (disp *Dispatcher) submit(container arvados.Container, crunchRunCommand []s // already in the queue). Cancel the slurm job if the container's // priority changes to zero or its state indicates it's no longer // running. -func (disp *Dispatcher) runContainer(_ *dispatch.Dispatcher, ctr arvados.Container, status <-chan arvados.Container) { +func (disp *Dispatcher) runContainer(_ *dispatch.Dispatcher, ctr arvados.Container, status <-chan arvados.Container) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -285,37 +277,9 @@ func (disp *Dispatcher) runContainer(_ *dispatch.Dispatcher, ctr arvados.Contain log.Printf("Submitting container %s to slurm", ctr.UUID) cmd := []string{disp.cluster.Containers.CrunchRunCommand} cmd = append(cmd, disp.cluster.Containers.CrunchRunArgumentsList...) - if err := disp.submit(ctr, cmd); err != nil { - var text string - if err, ok := err.(dispatchcloud.ConstraintsNotSatisfiableError); ok { - var logBuf bytes.Buffer - fmt.Fprintf(&logBuf, "cannot run container %s: %s\n", ctr.UUID, err) - if len(err.AvailableTypes) == 0 { - fmt.Fprint(&logBuf, "No instance types are configured.\n") - } else { - fmt.Fprint(&logBuf, "Available instance types:\n") - for _, t := range err.AvailableTypes { - fmt.Fprintf(&logBuf, - "Type %q: %d VCPUs, %d RAM, %d Scratch, %f Price\n", - t.Name, t.VCPUs, t.RAM, t.Scratch, t.Price, - ) - } - } - text = logBuf.String() - disp.UpdateState(ctr.UUID, dispatch.Cancelled) - } else { - text = fmt.Sprintf("Error submitting container %s to slurm: %s", ctr.UUID, err) - } - log.Print(text) - - lr := arvadosclient.Dict{"log": arvadosclient.Dict{ - "object_uuid": ctr.UUID, - "event_type": "dispatch", - "properties": map[string]string{"text": text}}} - disp.Arv.Create("logs", lr, nil) - - disp.Unlock(ctr.UUID) - return + err := disp.submit(ctr, cmd) + if err != nil { + return err } } @@ -344,7 +308,7 @@ func (disp *Dispatcher) runContainer(_ *dispatch.Dispatcher, ctr arvados.Contain case dispatch.Locked: disp.Unlock(ctr.UUID) } - return + return nil case updated, ok := <-status: if !ok { log.Printf("container %s is done: cancel slurm job", ctr.UUID)