10666: Added version number to go sdk and go tools & services
[arvados.git] / services / crunch-dispatch-slurm / crunch-dispatch-slurm.go
index 71852bffa7f38eb13ced6ffdebc683290c5b1b0f..e743fa585451b732734e2a3e10ec6d1c60298221 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 // Dispatcher service for Crunch that submits containers to the slurm queue.
@@ -19,6 +23,7 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
        "git.curoverse.com/arvados.git/sdk/go/config"
        "git.curoverse.com/arvados.git/sdk/go/dispatch"
+       arvadosVersion "git.curoverse.com/arvados.git/sdk/go/version"
        "github.com/coreos/go-systemd/daemon"
 )
 
@@ -65,10 +70,21 @@ func doMain() error {
                "dump-config",
                false,
                "write current configuration to stdout and exit")
-
+       getVersion := flags.Bool(
+               "version",
+               false,
+               "Print version information and exit.")
        // Parse args; omit the first arg which is the command name
        flags.Parse(os.Args[1:])
 
+       // Print version information if requested
+       if *getVersion {
+               fmt.Printf("Version: %s\n", arvadosVersion.GetVersion())
+               os.Exit(0)
+       }
+
+       log.Printf("crunch-dispatch-slurm %q started", arvadosVersion.GetVersion())
+
        err := readConfig(&theConfig, *configPath)
        if err != nil {
                return err
@@ -153,7 +169,9 @@ func sbatchFunc(container arvados.Container) *exec.Cmd {
 
        var disk int64
        for _, m := range container.Mounts {
-               disk += m.Capacity
+               if m.Kind == "tmp" {
+                       disk += m.Capacity
+               }
        }
        disk = int64(math.Ceil(float64(disk) / float64(1048576)))
 
@@ -224,13 +242,21 @@ func run(disp *dispatch.Dispatcher, ctr arvados.Container, status <-chan arvados
        if ctr.State == dispatch.Locked && !sqCheck.HasUUID(ctr.UUID) {
                log.Printf("Submitting container %s to slurm", ctr.UUID)
                if err := submit(disp, ctr, theConfig.CrunchRunCommand); err != nil {
-                       log.Printf("Error submitting container %s to slurm: %s", ctr.UUID, err)
+                       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
                }
        }
 
-       log.Printf("Start monitoring container %s", ctr.UUID)
+       log.Printf("Start monitoring container %v in state %q", ctr.UUID, ctr.State)
        defer log.Printf("Done monitoring container %s", ctr.UUID)
 
        // If the container disappears from the slurm queue, there is