From b418a291676d5fef1cb64d8f7d9c6eb82b95ea61 Mon Sep 17 00:00:00 2001 From: Yongjun Zhang Date: Thu, 31 Aug 2023 10:56:34 -0700 Subject: [PATCH 1/3] [YUNIKORN-1948] Introduce a command to validate the content of a given queue config file --- Makefile | 7 +++- cmd/queueconfigchecker/queueconfigchecker.go | 44 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 cmd/queueconfigchecker/queueconfigchecker.go diff --git a/Makefile b/Makefile index 4431e0606..02d26cad4 100644 --- a/Makefile +++ b/Makefile @@ -177,7 +177,7 @@ pseudo: # Build the example binaries for dev and test .PHONY: commands -commands: build/simplescheduler build/schedulerclient +commands: build/simplescheduler build/schedulerclient build/queueconfigchecker build/simplescheduler: go.mod go.sum cmd @echo "building example scheduler" @@ -189,6 +189,11 @@ build/schedulerclient: @mkdir -p build "$(GO)" build $(RACE) -a -ldflags '-extldflags "-static"' -o build/schedulerclient ./cmd/schedulerclient +build/queueconfigchecker: + @echo "building queueconfigchecker" + @mkdir -p build + "$(GO)" build $(RACE) -a -ldflags '-extldflags "-static"' -o build/queueconfigchecker ./cmd/queueconfigchecker + # Build binaries for dev and test .PHONY: build build: commands diff --git a/cmd/queueconfigchecker/queueconfigchecker.go b/cmd/queueconfigchecker/queueconfigchecker.go new file mode 100644 index 000000000..256df1c99 --- /dev/null +++ b/cmd/queueconfigchecker/queueconfigchecker.go @@ -0,0 +1,44 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package main + +import ( + "log" + "os" + + "github.com/apache/yunikorn-core/pkg/common/configs" +) + +/* + A utility command to load queue configuration file and check its validity + */ +func main() { + if len(os.Args) != 2 { + log.Println("Error: queue config file is not provided") + log.Println("Usage: " + os.Args[0] + " ") + os.Exit(1) + } + queueFile := os.Args[1] + iv, err := os.ReadFile(queueFile) + if err != nil { + log.Println(err) + os.Exit(1) + } + configs.LoadSchedulerConfigFromByteArray(iv) +} From b100090f5e45990b908322410d10299ad3bcc029 Mon Sep 17 00:00:00 2001 From: Yongjun Zhang Date: Thu, 31 Aug 2023 13:05:21 -0700 Subject: [PATCH 2/3] fix lint issue --- cmd/queueconfigchecker/queueconfigchecker.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/queueconfigchecker/queueconfigchecker.go b/cmd/queueconfigchecker/queueconfigchecker.go index 256df1c99..12d9089cd 100644 --- a/cmd/queueconfigchecker/queueconfigchecker.go +++ b/cmd/queueconfigchecker/queueconfigchecker.go @@ -26,11 +26,10 @@ import ( ) /* - A utility command to load queue configuration file and check its validity - */ +A utility command to load queue configuration file and check its validity +*/ func main() { if len(os.Args) != 2 { - log.Println("Error: queue config file is not provided") log.Println("Usage: " + os.Args[0] + " ") os.Exit(1) } @@ -38,7 +37,11 @@ func main() { iv, err := os.ReadFile(queueFile) if err != nil { log.Println(err) - os.Exit(1) + os.Exit(2) + } + _, err1 := configs.LoadSchedulerConfigFromByteArray(iv) + if err1 != nil { + log.Println(err1) + os.Exit(3) } - configs.LoadSchedulerConfigFromByteArray(iv) } From 09a1e2ef496683b9164fee45e6a4d2134b259c2a Mon Sep 17 00:00:00 2001 From: Yongjun Zhang Date: Tue, 5 Sep 2023 09:53:04 -0700 Subject: [PATCH 3/3] Address review comments --- cmd/queueconfigchecker/queueconfigchecker.go | 10 +++++----- pkg/common/configs/config.go | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/queueconfigchecker/queueconfigchecker.go b/cmd/queueconfigchecker/queueconfigchecker.go index 12d9089cd..dead2ef5f 100644 --- a/cmd/queueconfigchecker/queueconfigchecker.go +++ b/cmd/queueconfigchecker/queueconfigchecker.go @@ -34,14 +34,14 @@ func main() { os.Exit(1) } queueFile := os.Args[1] - iv, err := os.ReadFile(queueFile) + conf, err := os.ReadFile(queueFile) if err != nil { - log.Println(err) + log.Printf("Could not read file: %v", err) os.Exit(2) } - _, err1 := configs.LoadSchedulerConfigFromByteArray(iv) - if err1 != nil { - log.Println(err1) + _, err = configs.LoadSchedulerConfigFromByteArray(conf) + if err != nil { + log.Printf("Config validation failed: %v", err) os.Exit(3) } } diff --git a/pkg/common/configs/config.go b/pkg/common/configs/config.go index bb6c31299..8f34a0445 100644 --- a/pkg/common/configs/config.go +++ b/pkg/common/configs/config.go @@ -149,7 +149,6 @@ type NodeSortingPolicy struct { ResourceWeights map[string]float64 `yaml:",omitempty" json:",omitempty"` } -// Visible by tests func LoadSchedulerConfigFromByteArray(content []byte) (*SchedulerConfig, error) { conf, err := ParseAndValidateConfig(content) if err != nil {