X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Frestful%2Frestful.go;h=46a4387b11fd7fcd17a978894e1127f12427bfd9;hb=refs%2Fchanges%2F07%2F9607%2F1;hp=9c9e861e47dd0980fd80f548f62a7f029bf7ceda;hpb=d8d204f3ca9ebfd256043f6a0de526887fdcace9;p=ric-plt%2Fricdms.git diff --git a/pkg/restful/restful.go b/pkg/restful/restful.go index 9c9e861..46a4387 100644 --- a/pkg/restful/restful.go +++ b/pkg/restful/restful.go @@ -20,20 +20,26 @@ package restful import ( + "fmt" + "io" + "io/ioutil" "log" "os" ch "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/charts" + dm "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/deploy" ph "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health" po "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/onboard" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/charts" + "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/deploy" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/onboard" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/resthooks" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms" "github.com/go-openapi/loads" + "github.com/go-openapi/runtime" "github.com/go-openapi/runtime/middleware" ) @@ -43,6 +49,7 @@ func NewRestful() *Restful { ph.NewHealthChecker(), po.NewOnboarder(), ch.NewChartmgr(), + dm.NewDeploymentManager(), ), } r.setupHandler() @@ -93,6 +100,31 @@ func (r *Restful) setupHandler() { return resp }) + api.DeployPostDeployHandler = deploy.PostDeployHandlerFunc(func(param deploy.PostDeployParams) middleware.Responder { + ricdms.Logger.Debug("==> deployment of xApp") + resp := r.rh.DownloadAndInstallChart(param.Body.XAppname, param.Body.Version, *param.Body.Namespace) + return resp + }) + + api.ApplicationZipProducer = runtime.ProducerFunc(func(w io.Writer, data interface{}) error { + if zp, ok := data.(io.ReadCloser); ok { + defer zp.Close() + b, err := ioutil.ReadAll(zp) + + if err != nil { + ricdms.Logger.Error("error: %v", err) + return err + } + _, err = w.Write(b) + + if err != nil { + ricdms.Logger.Error("error: %v", err) + return err + } + return nil + } + return fmt.Errorf("not support") + }) r.api = api }