// Version returns the version url as a type of string.
func Version() string { return "/ver" }
+
+// Preparation returns the package url as s type of string.
+func Preparation() string { return "/preparation" }
"gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/v1/deployment"
"gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/v1/healthcheck"
"gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/v1/info"
+ "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/v1/preparation"
"gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/v1/revision"
"gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/v1/status"
"gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger"
revisionExecutor revision.Command
statusExecutor status.Command
infoExecutor info.Command
+ preparationExecutor preparation.Command
)
func init() {
revisionExecutor = revision.Executor{}
statusExecutor = status.Executor{}
infoExecutor = info.Executor{}
+ preparationExecutor = preparation.Executor{}
}
func setupRouter() (router *gin.Engine) {
info.GET("", infoExecutor.Get)
}
- _, _, _, _ = healthcheck, revision, status, info
+ preparation := v1.Group(url.IPS() + url.Preparation())
+ {
+ preparation.POST("", preparationExecutor.Post)
+ }
+ _, _, _, _, _ = healthcheck, revision, status, info, preparation
}
return
--- /dev/null
+/*
+==================================================================================
+
+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 preparation
+
+import (
+ "encoding/json"
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+ "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/commons/utils"
+ "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/errors"
+ "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger"
+ "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/helm"
+)
+
+type Command interface {
+ Post(c *gin.Context)
+}
+
+type Executor struct {
+ Command
+}
+
+func init() {
+}
+
+func (Executor) Post(c *gin.Context) {
+ logger.Logging(logger.DEBUG, "IN")
+ defer logger.Logging(logger.DEBUG, "OUT")
+
+ configFile := c.Query("configfile")
+ schemaFile := c.Query("schemafile")
+
+ chartBuilder := helm.NewChartBuilder(configFile, schemaFile)
+ chartPath, err := chartBuilder.PackageChart()
+
+ if err != nil {
+ utils.WriteError(c.Writer, errors.InternalServerError{Message: err.Error()})
+ return
+ }
+
+ data, err := json.Marshal(chartPath)
+ if err != nil {
+ utils.WriteError(c.Writer, err)
+ return
+ }
+ utils.WriteSuccess(c.Writer, http.StatusAccepted, data)
+}
)
type HelmChartBuilder interface {
- PackageChart() (err error)
+ PackageChart() (helmChartPath string, err error)
}
type ChartBuilder struct {
return
}
-func (c *ChartBuilder) PackageChart() (err error) {
+func (c *ChartBuilder) PackageChart() (chartPath string, err error) {
err = c.appendConfigToValuesYaml()
if err != nil {
return
return
}
logger.Logging(logger.INFO, "result of helm lint : %s", string(output))
+ slice := strings.Split(string(output), " ")
+ chartPath = slice[len(slice)-1]
return
}
}
func (c *ChartBuilder) changeChartNameVersion() (err error) {
- return errors.New("not yet implemented")
+ chartYamlPath := os.Getenv(ENV_CHART_WORKSPACE_PATH) + "/" + c.chartName + "/" + CHART_YAML
+ yamlFile, err := ioutil.ReadFile(chartYamlPath)
+ data := make(map[interface{}]interface{})
+ err = yaml.Unmarshal(yamlFile, &data)
+ if err != nil {
+ return
+ }
+ data["version"] = c.chartVersion
+ data["name"] = c.chartName
+ return
}
func (c *ChartBuilder) ValidateChartMaterials() (err error) {
os.Setenv("CHART_WORKSPACE_PATH", "./data")
chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
- err := chartBuilder.PackageChart()
+ chartPath, err := chartBuilder.PackageChart()
assert.Nil(t, err)
+ assert.Contains(t, chartPath, "data/sample-xapp-2.2.0/inference-service-1.0.0.tgz")
assert.FileExists(t, "./data/sample-xapp-2.2.0/inference-service-1.0.0.tgz")
defer os.RemoveAll("./data/sample-xapp-2.2.0/inference-service-1.0.0.tgz")
}
}
}
+func TestValidateChartMaterials(t *testing.T) {
+ os.Setenv("CHART_WORKSPACE_PATH", ".")
+ chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
+ err := chartBuilder.ValidateChartMaterials()
+ defer os.RemoveAll(os.Getenv("CHART_WORKSPACE_PATH") + "/" + chartBuilder.chartName + "-" + chartBuilder.chartVersion)
+ assert.Nil(t, err)
+}
Version string `json:"version"`
SaName string `json:"sa_name"`
InferenceService InferenceService `json:"inferenceservice"`
+ configFile string
}
type InferenceService struct {
Title string `json:"title"`
Required []string `json:"required"`
Properties Properties `json:"properties"`
+ schemaFile string
}
type Definitions struct {
}
type Properties struct {
- ServicePort ServicePort `json:"service_ports"`
- Rmr Rmr `json:"rmr"`
- Envs Envs `json:"envs"`
+ InferenceService InferenceServiceSchema `json:"inferenceservice"`
}
-type Envs struct {
- Id string `json:"$id"`
- Type string `json:"type"`
- Title string `json:"title"`
- Required []string `json:"required"`
- Properties EnvProperties `json:"properties"`
+type InferenceServiceSchema struct {
+ Id string `json:"$id"`
+ Type string `json:"type"`
+ Title string `json:"title"`
+ Required []string `json:"required"`
+ Properties InferenceServiceProperty `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 InferenceServiceProperty struct {
+ Engine StringProperty `json:"engine"`
+ StorageURI StringProperty `json:"storage_uri"`
+ ApiVersion StringProperty `json:"api_version"`
+ MinReplicas IntegerProperty `json:"min_replicas"`
+ MaxReplicas IntegerProperty `json:"max_replicas"`
}
-type EnvPropertyTemplate struct {
+type StringProperty 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 {
+type IntegerProperty 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"`
-}