preparation := v1.Group(url.IPS() + url.Preparation())
{
- preparation.POST("", preparationExecutor.Post)
+ preparation.POST("", preparationExecutor.Preperation)
}
_, _, _, _, _ = healthcheck, revision, status, info, preparation
}
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"
+ "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/controller/v1/adapter"
+ "github.com/gin-gonic/gin"
)
type Command interface {
- Post(c *gin.Context)
+ Preperation(c *gin.Context)
}
type Executor struct {
Command
}
+var ipsAdapter adapter.Command
+
func init() {
+ ipsAdapter = adapter.Executor{}
}
-func (Executor) Post(c *gin.Context) {
+func (Executor) Preperation(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 configFile == "" {
+ utils.WriteError(c.Writer, errors.InvalidConfigFile{Message: "Empty Query"})
+ return
+ }
- if err != nil {
- utils.WriteError(c.Writer, errors.InternalServerError{Message: err.Error()})
+ schemaFile := c.Query("schemafile")
+ if schemaFile == "" {
+ utils.WriteError(c.Writer, errors.InvalidSchemaFile{Message: "Empty Query"})
return
}
- data, err := json.Marshal(chartPath)
+ chartPath, err := ipsAdapter.Preperation(configFile, schemaFile)
if err != nil {
utils.WriteError(c.Writer, err)
return
}
- utils.WriteSuccess(c.Writer, http.StatusAccepted, data)
+ utils.WriteSuccess(c.Writer, http.StatusCreated, []byte(chartPath))
}
func (e InternalServerError) Error() string {
return "internal server error: " + e.Message
}
+
+type InvalidConfigFile struct {
+ Message string `json:"message" example:"invalid config file: {reason}" format:"string"`
+}
+
+func (e InvalidConfigFile) Error() string {
+ return "invalid Config file: " + e.Message
+}
+
+type InvalidSchemaFile struct {
+ Message string `json:"message" example:"invalid schema file: {reason}" format:"string"`
+}
+
+func (e InvalidSchemaFile) Error() string {
+ return "invalid Schema file: " + e.Message
+}
"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/commons/types"
+ "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/helm"
)
//go:generate mockgen -source=controller.go -destination=./mock/mock_controller.go -package=mock
Revision(name string) (revisionList types.Revision, err error)
Status(name string) (types.Status, error)
Info(name string) (types.Info, error)
+ Preperation(configFile string, schemaFile string) (chartPath string, err error)
}
type Executor struct {
result, err = kserveClient.Info(name)
return
}
+
+func (Executor) Preperation(configFile string, schemaFile string) (chartPath string, err error) {
+ logger.Logging(logger.DEBUG, "IN")
+ defer logger.Logging(logger.DEBUG, "OUT")
+
+ chartBuilder := helm.NewChartBuilder(configFile, schemaFile)
+ chartPath, err = chartBuilder.PackageChart()
+
+ if err != nil {
+ return
+ }
+
+ return
+}
chartBuilder.chartVersion = chartBuilder.config.Version
chartBuilder.chartWorkspacePath = os.Getenv(ENV_CHART_WORKSPACE_PATH) + "/" + chartBuilder.chartName + "-" + chartBuilder.chartVersion
+ logger.Logging(logger.INFO, "chartBuilder.chartWorkspacePath", chartBuilder.chartWorkspacePath)
_, err = os.Stat(chartBuilder.chartWorkspacePath)
if err != nil {
if !os.IsNotExist(err) {
apiVersion := chartBuilder.config.InferenceService.ApiVersion
resource := resourceVersionMap[apiVersion]
- err = chartBuilder.copyDirectory("data/"+resource, chartBuilder.chartWorkspacePath+"/"+chartBuilder.chartName)
+ err = chartBuilder.copyDirectory(chartBuilder.chartWorkspacePath+"/../../data/"+resource, chartBuilder.chartWorkspacePath+"/"+chartBuilder.chartName)
if err != nil {
logger.Logging(logger.ERROR, err.Error())
return nil
}
}
func TestValidateChartMaterials(t *testing.T) {
- os.Setenv("CHART_WORKSPACE_PATH", ".")
+ os.Setenv("CHART_WORKSPACE_PATH", "./data")
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)
+ defer os.RemoveAll(chartBuilder.chartWorkspacePath)
assert.Nil(t, err)
}