18487: Adds vocabulary check to 'arvados-server config-check'
authorLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 17 Jan 2022 19:20:01 +0000 (16:20 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 18 Jan 2022 20:23:39 +0000 (17:23 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

lib/config/cmd.go

index eeab6ac8cd0dfad10f82f97880db0187f3e412bd..e532a7e32a09e1f04a4b93c319fefc8b7bdd21d6 100644 (file)
@@ -6,6 +6,7 @@ package config
 
 import (
        "bytes"
+       "errors"
        "flag"
        "fmt"
        "io"
@@ -13,6 +14,7 @@ import (
        "os/exec"
 
        "git.arvados.org/arvados.git/lib/cmd"
+       "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/ctxlog"
        "github.com/ghodss/yaml"
        "github.com/sirupsen/logrus"
@@ -142,6 +144,36 @@ func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdo
                        return 1
                }
        }
+       for id, cc := range withDepr.Clusters {
+               if cc.API.VocabularyPath == "" {
+                       continue
+               }
+               _, err = os.Stat(cc.API.VocabularyPath)
+               if err != nil {
+                       if errors.Is(err, os.ErrNotExist) {
+                               // If the vocabulary path doesn't exist, it might mean that
+                               // the current node isn't the controller; so it's not an
+                               // error.
+                               continue
+                       }
+                       fmt.Fprintf(stderr, "Error checking vocabulary path %q for cluster %s: %s\n", cc.API.VocabularyPath, id, err)
+                       return 1
+               }
+               vd, err := os.ReadFile(cc.API.VocabularyPath)
+               if err != nil {
+                       fmt.Fprintf(stderr, "Error reading vocabulary file %q for cluster %s: %s\n", cc.API.VocabularyPath, id, err)
+                       return 1
+               }
+               mk := make([]string, 0, len(cc.Collections.ManagedProperties))
+               for k := range cc.Collections.ManagedProperties {
+                       mk = append(mk, k)
+               }
+               _, err = arvados.NewVocabulary(vd, mk)
+               if err != nil {
+                       fmt.Fprintf(stderr, "Error loading vocabulary file %q for cluster %s: %s\n", cc.API.VocabularyPath, id, err)
+                       return 1
+               }
+       }
        return 0
 }