add helm chart 01/10901/1
authorhoejoo.lee <hoejoo.lee@samsung.com>
Fri, 14 Apr 2023 05:36:44 +0000 (01:36 -0400)
committerhoejoo.lee <hoejoo.lee@samsung.com>
Fri, 14 Apr 2023 05:36:44 +0000 (01:36 -0400)
Change-Id: I35b507fdb2adde70f31fd44da1bbd6681a3c841b
Signed-off-by: hoejoo.lee <hoejoo.lee@samsung.com>
go.mod
go.sum [new file with mode: 0755]
pkg/helm/chart_builder.go [new file with mode: 0755]
pkg/helm/chart_builder_test.go [new file with mode: 0755]
pkg/helm/config.go [new file with mode: 0755]
pkg/helm/data/sample_config.json [new file with mode: 0755]
pkg/helm/data/sample_schema.json [new file with mode: 0755]
pkg/helm/schema.go [new file with mode: 0755]

diff --git a/go.mod b/go.mod
index 59f1cb7..9f40bc8 100755 (executable)
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,11 @@
 module gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter\r
 \r
 go 1.18\r
+\r
+require github.com/stretchr/testify v1.8.1\r
+\r
+require (\r
+       github.com/davecgh/go-spew v1.1.1 // indirect\r
+       github.com/pmezard/go-difflib v1.0.0 // indirect\r
+       gopkg.in/yaml.v3 v3.0.1 // indirect\r
+)\r
diff --git a/go.sum b/go.sum
new file mode 100755 (executable)
index 0000000..2ec90f7
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,17 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
+github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
+github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
+github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/pkg/helm/chart_builder.go b/pkg/helm/chart_builder.go
new file mode 100755 (executable)
index 0000000..6ff96b6
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+==================================================================================
+  Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.
+
+  Licensed 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 helm
+
+import (
+       "encoding/json"
+       "io/ioutil"
+       "os"
+
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger"
+)
+
+type ChartBuilder struct {
+}
+
+func NewChartBuilder() ChartBuilder {
+       return ChartBuilder{}
+}
+
+func (c *ChartBuilder) parseConfigFile(configFile string) (config Config, err error) {
+       data, err := os.Open(configFile)
+       if err != nil {
+               logger.Logging(logger.ERROR, err.Error())
+               return
+       }
+       byteValue, _ := ioutil.ReadAll(data)
+
+       err = json.Unmarshal(byteValue, &config)
+       if err != nil {
+               logger.Logging(logger.ERROR, err.Error())
+               return
+       }
+       return
+}
+
+func (c *ChartBuilder) parseSchemaFile(schemaFile string) (schema Schema, err error) {
+       data, err := os.Open(schemaFile)
+       if err != nil {
+               logger.Logging(logger.ERROR, err.Error())
+               return
+       }
+       byteValue, _ := ioutil.ReadAll(data)
+
+       err = json.Unmarshal(byteValue, &schema)
+       if err != nil {
+               logger.Logging(logger.ERROR, err.Error())
+               return
+       }
+       return
+}
diff --git a/pkg/helm/chart_builder_test.go b/pkg/helm/chart_builder_test.go
new file mode 100755 (executable)
index 0000000..f4448a8
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+==================================================================================
+  Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.
+
+  Licensed 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 helm
+
+import (
+       "testing"
+
+       "github.com/stretchr/testify/assert"
+)
+
+func TestParseConfigFile(t *testing.T) {
+       chartBuilder := NewChartBuilder()
+       config, err := chartBuilder.parseConfigFile("data/sample_config.json")
+
+       assert.Nil(t, err)
+       assert.NotEmpty(t, config)
+}
+
+func TestParseSchemaFile(t *testing.T) {
+       chartBuilder := NewChartBuilder()
+       schema, err := chartBuilder.parseSchemaFile("data/sample_schema.json")
+
+       assert.Nil(t, err)
+       assert.NotEmpty(t, schema)
+}
diff --git a/pkg/helm/config.go b/pkg/helm/config.go
new file mode 100755 (executable)
index 0000000..67ae960
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+==================================================================================
+      Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.
+
+  Licensed 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 helm
+
+type Config struct {
+       XappName         string           `json:"xapp_name"`
+       XappType         string           `json:"xapp_type"`
+       Version          string           `json:"version"`
+       SaName           string           `json:"sa_name"`
+       InferenceService InferenceService `json:"inferenceservice"`
+}
+
+type InferenceService struct {
+       Engine      string `json:"engine"`
+       StorageURI  string `json:"storage_uri"`
+       ApiVersion  string `json:"api_version"`
+       MinReplicas int32  `json:"min_replicas"`
+       MaxReplicas int32  `json:"max_replicas"`
+}
diff --git a/pkg/helm/data/sample_config.json b/pkg/helm/data/sample_config.json
new file mode 100755 (executable)
index 0000000..746e35d
--- /dev/null
@@ -0,0 +1,13 @@
+{
+    "xapp_name": "sample_xapp",
+    "xapp_type": "inferenceservice",
+    "version": "2.2.0",
+    "sa_name": "default",
+    "inferenceservice": {
+        "engine": "tensorflow",
+        "storage_uri": "s3://mlpipeline/artifacts/sample-rl-pipeline-bbzh4/sample-rl-pipeline-bbzh4-949264085/sample-training-saved-model.tgz",
+        "api_version": "serving.kubeflow.org/v1beta1",
+        "min_replicas": 1,
+        "max_replicas": 1
+    }
+}
\ No newline at end of file
diff --git a/pkg/helm/data/sample_schema.json b/pkg/helm/data/sample_schema.json
new file mode 100755 (executable)
index 0000000..3d8f476
--- /dev/null
@@ -0,0 +1,229 @@
+{
+  "definitions": {},
+  "$schema": "http://json-schema.org/draft-07/schema#",
+  "$id": "http://example.com/root.json",
+  "type": "object",
+  "title": "The Root Schema",
+  "required": [
+    "service_ports",
+    "rmr",
+    "envs"
+  ],
+  "properties": {
+    "service_ports": {
+      "$id": "#/properties/service_ports",
+      "type": "object",
+      "title": "The Service_ports Schema",
+      "required": [
+        "xapp_port",
+        "rmr_port"
+      ],
+      "properties": {
+        "xapp_port": {
+          "$id": "#/properties/service_ports/properties/xapp_port",
+          "type": "integer",
+          "title": "The Xapp_port Schema",
+          "default": 0,
+          "examples": [
+            4560
+          ]
+        },
+        "rmr_port": {
+          "$id": "#/properties/service_ports/properties/rmr_port",
+          "type": "integer",
+          "title": "The Rmr_port Schema",
+          "default": 0,
+          "examples": [
+            4561
+          ]
+        }
+      }
+    },
+    "rmr": {
+      "$id": "#/properties/rmr",
+      "type": "object",
+      "title": "The Rmr Schema",
+      "required": [
+        "protPort",
+        "maxSize",
+        "numWorkers",
+        "txMessages",
+        "rxMessages",
+        "file_path",
+        "contents"
+      ],
+      "properties": {
+        "protPort": {
+          "$id": "#/properties/rmr/properties/protPort",
+          "type": "string",
+          "title": "The Protport Schema",
+          "default": "",
+          "examples": [
+            "tcp:4560"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "maxSize": {
+          "$id": "#/properties/rmr/properties/maxSize",
+          "type": "integer",
+          "title": "The Maxsize Schema",
+          "default": 0,
+          "examples": [
+            2072
+          ]
+        },
+        "numWorkers": {
+          "$id": "#/properties/rmr/properties/numWorkers",
+          "type": "integer",
+          "title": "The Numworkers Schema",
+          "default": 0,
+          "examples": [
+            1
+          ]
+        },
+        "txMessages": {
+          "$id": "#/properties/rmr/properties/txMessages",
+          "type": "array",
+          "title": "The Txmessages Schema",
+          "items": {
+            "$id": "#/properties/rmr/properties/txMessages/items",
+            "type": "string",
+            "title": "The Items Schema",
+            "default": "",
+            "examples": [
+              "RIC_SUB_REQ",
+              "RIC_SUB_DEL_REQ"
+            ],
+            "pattern": "^(.*)$"
+          }
+        },
+        "rxMessages": {
+          "$id": "#/properties/rmr/properties/rxMessages",
+          "type": "array",
+          "title": "The Rxmessages Schema",
+          "items": {
+            "$id": "#/properties/rmr/properties/rxMessages/items",
+            "type": "string",
+            "title": "The Items Schema",
+            "default": "",
+            "examples": [
+              "RIC_SUB_RESP",
+              "RIC_SUB_FAILURE",
+              "RIC_SUB_DEL_RESP",
+              "RIC_SUB_DEL_FAILURE",
+              "RIC_INDICATION"
+            ],
+            "pattern": "^(.*)$"
+          }
+        },
+        "file_path": {
+          "$id": "#/properties/rmr/properties/file_path",
+          "type": "string",
+          "title": "The File_path Schema",
+          "default": "",
+          "examples": [
+            "/tmp/routeinfo/routes.txt"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "contents": {
+          "$id": "#/properties/rmr/properties/contents",
+          "type": "string",
+          "title": "The Contents Schema",
+          "default": "",
+          "examples": [
+            "newrt|start\nrte|0|localhost:4560\nrte|2|localhost:4591\nrte|10002|localhost:4560\nrte|10005|localhost:4560\nrte|10003|localhost:4591\nrte|12010|localhost:4591\nrte|12020|localhost:4591\nrte|12011|localhost:4560\nrte|12012|localhost:4560\nrte|12021|localhost:4560\nrte|12022|localhost:4560\nrte|20000|localhost:4560\nrte|20001|localhost:4566\nnewrt|end "
+          ],
+          "pattern": "^(.*)$"
+        }
+      }
+    },
+    "envs": {
+      "$id": "#/properties/envs",
+      "type": "object",
+      "title": "The Envs Schema",
+      "required": [
+        "gNodeB",
+        "THREADS",
+        "A1_SCHEMA_FILE",
+        "VES_SCHEMA_FILE",
+        "SAMPLE_FILE",
+        "VES_COLLECTOR_URL",
+        "VES_MEAUSUREMENT_INTERVAL"
+      ],
+      "properties": {
+        "gNodeB": {
+          "$id": "#/properties/envs/properties/gNodeB",
+          "type": "string",
+          "title": "The Gnodeb Schema",
+          "default": "",
+          "examples": [
+            "NYC123"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "THREADS": {
+          "$id": "#/properties/envs/properties/THREADS",
+          "type": "string",
+          "title": "The Threads Schema",
+          "default": "",
+          "examples": [
+            "1"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "A1_SCHEMA_FILE": {
+          "$id": "#/properties/envs/properties/A1_SCHEMA_FILE",
+          "type": "string",
+          "title": "The A1_schema_file Schema",
+          "default": "",
+          "examples": [
+            "/etc/xapp/adm-ctrl-xapp-schema.json"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "VES_SCHEMA_FILE": {
+          "$id": "#/properties/envs/properties/VES_SCHEMA_FILE",
+          "type": "string",
+          "title": "The Ves_schema_file Schema",
+          "default": "",
+          "examples": [
+            "/etc/xapp/ves_schema.json"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "SAMPLE_FILE": {
+          "$id": "#/properties/envs/properties/SAMPLE_FILE",
+          "type": "string",
+          "title": "The Sample_file Schema",
+          "default": "",
+          "examples": [
+            "/etc/xapp/samples.json"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "VES_COLLECTOR_URL": {
+          "$id": "#/properties/envs/properties/VES_COLLECTOR_URL",
+          "type": "string",
+          "title": "The Ves_collector_url Schema",
+          "default": "",
+          "examples": [
+            "127.0.0.1:6350"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "VES_MEAUSUREMENT_INTERVAL": {
+          "$id": "#/properties/envs/properties/VES_MEAUSUREMENT_INTERVAL",
+          "type": "string",
+          "title": "The Ves_meausurement_interval Schema",
+          "default": "",
+          "examples": [
+            "10"
+          ],
+          "pattern": "^(.*)$"
+        }
+      }
+    }
+  }
+}
+
diff --git a/pkg/helm/schema.go b/pkg/helm/schema.go
new file mode 100755 (executable)
index 0000000..40355be
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+==================================================================================
+      Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.
+
+  Licensed 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 helm
+
+type Schema struct {
+       Definitions Definitions `json:"definitions"`
+       Schema      string      `json:"$schema"`
+       Id          string      `json:"$id"`
+       Type        string      `json:"type"`
+       Title       string      `json:"title"`
+       Required    []string    `json:"required"`
+       Properties  Properties  `json:"properties"`
+}
+
+type Definitions struct {
+}
+
+type Properties struct {
+       ServicePort ServicePort `json:"service_ports"`
+       Rmr         Rmr         `json:"rmr"`
+       Envs        Envs        `json:"envs"`
+}
+
+type Envs struct {
+       Id         string        `json:"$id"`
+       Type       string        `json:"type"`
+       Title      string        `json:"title"`
+       Required   []string      `json:"required"`
+       Properties EnvProperties `json:"properties"`
+}
+
+type EnvProperties struct {
+       GNodeB                 EnvPropertyTemplate `json:"gNodeB"`
+       Threads                EnvPropertyTemplate `json:"THREADS"`
+       A1SchemaFile           EnvPropertyTemplate `json:"A1_SCHEMA_FILE"`
+       VesSchemaFile          EnvPropertyTemplate `json:"VES_SCHEMA_FILE"`
+       SampleFile             EnvPropertyTemplate `json:"SAMPLE_FILE"`
+       VesCollectorURL        EnvPropertyTemplate `json:"VES_COLLECTOR_URL"`
+       VesMeasurementInterval EnvPropertyTemplate `json:"VES_MEASUREMENT_INTERVAL"`
+}
+
+type EnvPropertyTemplate struct {
+       Id       string   `json:"$id"`
+       Type     string   `json:"type"`
+       Title    string   `json:"title"`
+       Default  string   `json:"default"`
+       Examples []string `json:"examples"`
+       Pattern  string   `json:"pattern"`
+}
+
+type Rmr struct {
+       Id            string        `json:"$id"`
+       Type          string        `json:"type"`
+       Title         string        `json:"title"`
+       Required      []string      `json:"required"`
+       RmrProperties RmrProperties `json:"properties"`
+}
+
+type RmrProperties struct {
+       ProtPort   ProtPort       `json:"protPort"`
+       MaxSize    RmrSubProperty `json:"maxSize"`
+       NumWorkers RmrSubProperty `json:"numWorkers"`
+       TxMessages RmrMessage     `json:"txMessages"`
+       RxMessages RmrMessage     `json:"rxMessages"`
+       FilePath   FilePath       `json:"file_path"`
+       Contents   Contents       `json:"contents"`
+}
+
+type FilePath struct {
+       Id       string   `json:"$id"`
+       Type     string   `json:"type"`
+       Title    string   `json:"title"`
+       Default  string   `json:"default"`
+       Examples []string `json:"examples"`
+       Pattern  string   `json:"pattern"`
+}
+
+type Contents struct {
+       Id       string   `json:"$id"`
+       Type     string   `json:"type"`
+       Title    string   `json:"title"`
+       Default  string   `json:"default"`
+       Examples []string `json:"examples"`
+       Pattern  string   `json:"pattern"`
+}
+
+type RmrMessage struct {
+       Id    string          `json:"$id"`
+       Type  string          `json:"type"`
+       Title string          `json:"title"`
+       Items RmrMessageItems `json:"items"`
+}
+
+type RmrMessageItems struct {
+       Id       string   `json:"$id"`
+       Type     string   `json:"type"`
+       Title    string   `json:"title"`
+       Default  string   `json:"default"`
+       Examples []string `json:"examples"`
+       Pattern  string   `json:"pattern"`
+}
+
+type RmrSubProperty struct {
+       Id       string  `json:"$id"`
+       Type     string  `json:"type"`
+       Title    string  `json:"title"`
+       Default  int32   `json:"default"`
+       Examples []int32 `json:"examples"`
+}
+
+type ProtPort struct {
+       Id       string   `json:"$id"`
+       Type     string   `json:"type"`
+       Title    string   `json:"title"`
+       Default  string   `json:"default"`
+       Examples []string `json:"examples"`
+       Pattern  string   `json:"pattern"`
+}
+
+type ServicePort struct {
+       Id                    string                `json:"$id"`
+       Type                  string                `json:"type"`
+       Title                 string                `json:"title"`
+       Required              []string              `json:"required"`
+       ServicePortProperties ServicePortProperties `json:"properties"`
+}
+
+type ServicePortProperties struct {
+       XappPort XappPort `json:"xapp_port"`
+       RmrPort  RmrPort  `json:"rmr_port"`
+}
+type RmrPort struct {
+       Id       string   `json:"$id"`
+       Type     string   `json:"type"`
+       Title    string   `json:"title"`
+       Default  uint32   `json:"default"`
+       Examples []uint32 `json:"examples"`
+}
+
+type XappPort struct {
+       Id       string   `json:"$id"`
+       Type     string   `json:"type"`
+       Title    string   `json:"title"`
+       Default  uint32   `json:"default"`
+       Examples []uint32 `json:"examples"`
+}