From 2fdf1c14be88946ffefca4eea789967e588a4007 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Tue, 20 Sep 2022 10:27:23 +0200 Subject: [PATCH] Fix broken schema and add tests --- pkg/schema/schemas/cluster.schema.json | 8 +- pkg/schema/schemas/config.schema.json | 2 +- pkg/schema/schemas/job-data.schema.json | 132 +++++++++--------- pkg/schema/schemas/job-meta.schema.json | 66 ++++----- .../schemas/job-metric-data.schema.json | 4 +- .../schemas/job-metric-statistics.schema.json | 4 +- pkg/schema/schemas/unit.schema.json | 2 +- pkg/schema/validate.go | 28 ++-- pkg/schema/validate_test.go | 80 +++++++++++ 9 files changed, 200 insertions(+), 126 deletions(-) create mode 100644 pkg/schema/validate_test.go diff --git a/pkg/schema/schemas/cluster.schema.json b/pkg/schema/schemas/cluster.schema.json index 97a4f4c..5dfb92e 100644 --- a/pkg/schema/schemas/cluster.schema.json +++ b/pkg/schema/schemas/cluster.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft/2020-12/schema", - "$id": "embedFS://schemas/cluster.schema.json", + "$id": "embedfs://cluster.schema.json", "title": "HPC cluster description", "description": "Meta data information of a HPC cluster", "type": "object", @@ -78,7 +78,8 @@ "scope", "timestep" ] - } + }, + "minItems": 1 }, "subClusters": { "description": "Array of cluster hardware partitions", @@ -223,7 +224,8 @@ "flopRateSimd", "memoryBandwidth" ] - } + }, + "minItems": 1 } }, "required":[ diff --git a/pkg/schema/schemas/config.schema.json b/pkg/schema/schemas/config.schema.json index 4ad7c1c..d4e993b 100644 --- a/pkg/schema/schemas/config.schema.json +++ b/pkg/schema/schemas/config.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft/2020-12/schema", - "$id": "embedFS://schemas/config.schema.json", + "$id": "embedfs://config.schema.json", "title": "cc-backend configuration file schema", "type": "object", "properties":{ diff --git a/pkg/schema/schemas/job-data.schema.json b/pkg/schema/schemas/job-data.schema.json index b32d9b3..d1ad1f1 100644 --- a/pkg/schema/schemas/job-data.schema.json +++ b/pkg/schema/schemas/job-data.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft/2020-12/schema", - "$id": "embedFS://schemas/job-data.schema.json", + "$id": "embedfs://job-data.schema.json", "title": "Job metric data list", "description": "Collection of metric data of a HPC job", "type": "object", @@ -10,7 +10,7 @@ "type": "object", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -21,19 +21,19 @@ "description": "Total flop rate with DP flops scaled up", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "memoryDomain": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "core": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "hwthread": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -42,13 +42,13 @@ "description": "Main memory bandwidth", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "memoryDomain": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -58,7 +58,7 @@ "type": "object", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -69,19 +69,19 @@ "description": "Instructions executed per cycle", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "memoryDomain": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "core": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "hwthread": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -90,19 +90,19 @@ "description": "CPU active core utilization", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "memoryDomain": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "core": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "hwthread": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -111,7 +111,7 @@ "description": "CPU requested core utilization (load 1m)", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -122,19 +122,19 @@ "description": "Double precision flop rate", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "memoryDomain": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "core": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "hwthread": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -143,19 +143,19 @@ "description": "Single precision flops rate", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "memoryDomain": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "core": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "hwthread": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -164,19 +164,19 @@ "description": "Fraction of arithmetic instructions using SIMD instructions", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "memoryDomain": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "core": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "hwthread": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -185,10 +185,10 @@ "description": "CPU power consumption", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -197,10 +197,10 @@ "description": "Memory power consumption", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -209,7 +209,7 @@ "description": "GPU utilization", "properties": { "accelerator": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -220,7 +220,7 @@ "description": "GPU memory capacity used", "properties": { "accelerator": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -231,7 +231,7 @@ "description": "GPU power consumption", "properties": { "accelerator": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -242,19 +242,19 @@ "description": "Average core frequency", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "socket": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "memoryDomain": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "core": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" }, "hwthread": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "minProperties": 1 @@ -263,7 +263,7 @@ "description": "Ethernet read bandwidth", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -274,7 +274,7 @@ "description": "Ethernet write bandwidth", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -306,7 +306,7 @@ "description": "File system read bandwidth", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -317,7 +317,7 @@ "description": "File system write bandwidth", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -328,7 +328,7 @@ "description": "File system read requests", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -339,7 +339,7 @@ "description": "File system write requests", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -350,7 +350,7 @@ "description": "File system write requests", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -361,7 +361,7 @@ "description": "File system open and close", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -372,7 +372,7 @@ "description": "File system fsync", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -383,7 +383,7 @@ "description": "File system create", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -394,7 +394,7 @@ "description": "File system open", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -405,7 +405,7 @@ "description": "File system close", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -416,7 +416,7 @@ "description": "File system seek", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -438,7 +438,7 @@ "description": "Network interconnect read packets", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -449,7 +449,7 @@ "description": "Network interconnect send packet", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -460,7 +460,7 @@ "description": "Network interconnect read bandwidth", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ @@ -471,7 +471,7 @@ "description": "Network interconnect write bandwidth", "properties": { "node": { - "$ref": "embedFS://schemas/job-metric-data.schema.json" + "$ref": "embedfs://job-metric-data.schema.json" } }, "required": [ diff --git a/pkg/schema/schemas/job-meta.schema.json b/pkg/schema/schemas/job-meta.schema.json index c530beb..c2c17ed 100644 --- a/pkg/schema/schemas/job-meta.schema.json +++ b/pkg/schema/schemas/job-meta.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft/2020-12/schema", - "$id": "embedFS://schemas/job-meta.schema.json", + "$id": "embedfs://job-meta.schema.json", "title": "Job meta data", "description": "Meta data information of a HPC job", "type": "object", @@ -172,87 +172,87 @@ "properties": { "mem_used": { "description": "Memory capacity used (required)", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "cpu_load": { "description": "CPU requested core utilization (load 1m) (required)", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "flops_any": { "description": "Total flop rate with DP flops scaled up (required)", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "mem_bw": { "description": "Main memory bandwidth (required)", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "net_bw": { "description": "Total fast interconnect network bandwidth (required)", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "file_bw": { "description": "Total file IO bandwidth (required)", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "ipc": { "description": "Instructions executed per cycle", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "cpu_used": { "description": "CPU active core utilization", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "flops_dp": { "description": "Double precision flop rate", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "flops_sp": { "description": "Single precision flops rate", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "rapl_power": { "description": "CPU power consumption", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "gpu_used": { "description": "GPU utilization", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "gpu_mem_used": { "description": "GPU memory capacity used", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "gpu_power": { "description": "GPU power consumption", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "clock": { "description": "Average core frequency", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "eth_read_bw": { "description": "Ethernet read bandwidth", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "eth_write_bw": { "description": "Ethernet write bandwidth", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "ic_rcv_packets": { "description": "Network interconnect read packets", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "ic_send_packets": { "description": "Network interconnect send packet", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "ic_read_bw": { "description": "Network interconnect read bandwidth", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "ic_write_bw": { "description": "Network interconnect write bandwidth", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "filesystems": { "description": "Array of filesystems", @@ -277,47 +277,47 @@ }, "read_bw": { "description": "File system read bandwidth", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "write_bw": { "description": "File system write bandwidth", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "read_req": { "description": "File system read requests", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "write_req": { "description": "File system write requests", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "inodes": { "description": "File system write requests", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "accesses": { "description": "File system open and close", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "fsync": { "description": "File system fsync", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "create": { "description": "File system create", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "open": { "description": "File system open", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "close": { "description": "File system close", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" }, "seek": { "description": "File system seek", - "$ref": "embedFS://schemas/job-metric-statistics.schema.json" + "$ref": "embedfs://job-metric-statistics.schema.json" } }, "required": [ diff --git a/pkg/schema/schemas/job-metric-data.schema.json b/pkg/schema/schemas/job-metric-data.schema.json index 88bde81..07ef25e 100644 --- a/pkg/schema/schemas/job-metric-data.schema.json +++ b/pkg/schema/schemas/job-metric-data.schema.json @@ -1,13 +1,13 @@ { "$schema": "http://json-schema.org/draft/2020-12/schema", - "$id": "embedFS://schemas/job-metric-data.schema.json", + "$id": "embedfs://job-metric-data.schema.json", "title": "Job metric data", "description": "Metric data of a HPC job", "type": "object", "properties": { "unit": { "description": "Metric unit", - "$ref": "embedFS://schemas/unit.schema.json" + "$ref": "embedfs://unit.schema.json" }, "timestep": { "description": "Measurement interval in seconds", diff --git a/pkg/schema/schemas/job-metric-statistics.schema.json b/pkg/schema/schemas/job-metric-statistics.schema.json index fb14521..8f14f72 100644 --- a/pkg/schema/schemas/job-metric-statistics.schema.json +++ b/pkg/schema/schemas/job-metric-statistics.schema.json @@ -1,13 +1,13 @@ { "$schema": "http://json-schema.org/draft/2020-12/schema", - "$id": "schemaFS://schemas/job-metric-statistics.schema.json", + "$id": "schemafs://job-metric-statistics.schema.json", "title": "Job statistics", "description": "Format specification for job metric statistics", "type": "object", "properties": { "unit": { "description": "Metric unit", - "$ref": "embedFS://schemas/unit.schema.json" + "$ref": "embedfs://unit.schema.json" }, "avg": { "description": "Job metric average", diff --git a/pkg/schema/schemas/unit.schema.json b/pkg/schema/schemas/unit.schema.json index 6a6526e..e3921a6 100644 --- a/pkg/schema/schemas/unit.schema.json +++ b/pkg/schema/schemas/unit.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft/2020-12/schema", - "$id": "embedFS://schemas/unit.schema.json", + "$id": "embedfs://unit.schema.json", "title": "Metric unit", "description": "Format specification for job metric units", "type": "object", diff --git a/pkg/schema/validate.go b/pkg/schema/validate.go index 63a2042..7201c9a 100644 --- a/pkg/schema/validate.go +++ b/pkg/schema/validate.go @@ -9,7 +9,8 @@ import ( "encoding/json" "fmt" "io" - "net/url" + "path/filepath" + "strings" "github.com/ClusterCockpit/cc-backend/pkg/log" "github.com/santhosh-tekuri/jsonschema/v5" @@ -27,31 +28,22 @@ const ( //go:embed schemas/* var schemaFiles embed.FS -func Load(s string) (io.ReadCloser, error) { - u, err := url.Parse(s) - if err != nil { - return nil, err - } - f := u.Path - return schemaFiles.Open(f) -} - -func init() { - jsonschema.Loaders["embedFS"] = Load -} - func Validate(k Kind, r io.Reader) (err error) { + jsonschema.Loaders["embedfs"] = func(s string) (io.ReadCloser, error) { + f := filepath.Join("schemas", strings.Split(s, "//")[1]) + return schemaFiles.Open(f) + } var s *jsonschema.Schema switch k { case Meta: - s, err = jsonschema.Compile("embedFS://schemas/job-meta.schema.json") + s, err = jsonschema.Compile("embedfs://job-meta.schema.json") case Data: - s, err = jsonschema.Compile("embedFS://schemas/job-data.schema.json") + s, err = jsonschema.Compile("embedfs://job-data.schema.json") case ClusterCfg: - s, err = jsonschema.Compile("embedFS://schemas/cluster.schema.json") + s, err = jsonschema.Compile("embedfs://cluster.schema.json") case Config: - s, err = jsonschema.Compile("embedFS://schemas/config.schema.json") + s, err = jsonschema.Compile("embedfs://config.schema.json") default: return fmt.Errorf("unkown schema kind ") } diff --git a/pkg/schema/validate_test.go b/pkg/schema/validate_test.go new file mode 100644 index 0000000..a3c1ee8 --- /dev/null +++ b/pkg/schema/validate_test.go @@ -0,0 +1,80 @@ +// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. +// All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. +package schema + +import ( + "bytes" + "testing" +) + +func TestValidateConfig(t *testing.T) { + json := []byte(`{ + "clusters": [ + { + "name": "testcluster", + "metricDataRepository": { + "kind": "cc-metric-store", + "url": "localhost:8082"}, + "filterRanges": { + "numNodes": { "from": 1, "to": 64 }, + "duration": { "from": 0, "to": 86400 }, + "startTime": { "from": "2022-01-01T00:00:00Z", "to": null } + } + } + ] +}`) + + if err := Validate(Config, bytes.NewReader(json)); err != nil { + t.Errorf("Error is not nil! %v", err) + } +} + +func TestValidateJobMeta(t *testing.T) { + +} + +func TestValidateCluster(t *testing.T) { + json := []byte(`{ + "name": "emmy", + "subClusters": [ + { + "name": "main", + "processorType": "Intel IvyBridge", + "socketsPerNode": 2, + "coresPerSocket": 10, + "threadsPerCore": 2, + "flopRateScalar": 44, + "flopRateSimd": 704, + "memoryBandwidth": 80, + "topology": { + "node": [0,20,1,21,2,22,3,23,4,24,5,25,6,26,7,27,8,28,9,29,10,30,11,31,12,32,13,33,14,34,15,35,16,36,17,37,18,38,19,39], + "socket": [ + [0,20,1,21,2,22,3,23,4,24,5,25,6,26,7,27,8,28,9,29], + [10,30,11,31,12,32,13,33,14,34,15,35,16,36,17,37,18,38,19,39] + ], + "memoryDomain": [ + [0,20,1,21,2,22,3,23,4,24,5,25,6,26,7,27,8,28,9,29], + [10,30,11,31,12,32,13,33,14,34,15,35,16,36,17,37,18,38,19,39] + ], + "core": [ + [0,20],[1,21],[2,22],[3,23],[4,24],[5,25],[6,26],[7,27],[8,28],[9,29],[10,30],[11,31],[12,32],[13,33],[14,34],[15,35],[16,36],[17,37],[18,38],[19,39] + ] + } + } + ], + "metricConfig": [ + { + "name": "cpu_load", + "scope": "hwthread", + "unit": "load", + "timestep": 60 + } + ] +}`) + + if err := Validate(ClusterCfg, bytes.NewReader(json)); err != nil { + t.Errorf("Error is not nil! %v", err) + } +}