X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Frestful%2Frestful.go;h=b17c7ad17b475838c6158ee1f03d1a1000148ca4;hb=c1e4374fb522f55e9263dd2deca3d244e709ebdf;hp=2670fb6c4b74524b8b5c470a9b7dfdde0a21f49f;hpb=04897e6ba579f0cfd11453f589fc1fb24be4e820;p=ric-plt%2Fricdms.git diff --git a/pkg/restful/restful.go b/pkg/restful/restful.go index 2670fb6..b17c7ad 100644 --- a/pkg/restful/restful.go +++ b/pkg/restful/restful.go @@ -20,18 +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" ) @@ -40,6 +48,8 @@ func NewRestful() *Restful { rh: resthooks.NewResthook( ph.NewHealthChecker(), po.NewOnboarder(), + ch.NewChartmgr(), + dm.NewDeploymentManager(), ), } r.setupHandler() @@ -60,12 +70,67 @@ func (r *Restful) setupHandler() { return resp }) + api.HealthGetHealthcheckXAppXAppNameNamespaceNamespaceHandler = health.GetHealthcheckXAppXAppNameNamespaceNamespaceHandlerFunc(func(param health.GetHealthcheckXAppXAppNameNamespaceNamespaceParams) middleware.Responder { + ricdms.Logger.Debug("==> Healthcheck for xApp is invoked") + resp := r.rh.GetxAppHealth(param.XAppName, param.Namespace) + return resp + }) + api.OnboardPostOnboardxAppsHandler = onboard.PostOnboardxAppsHandlerFunc(func(poap onboard.PostOnboardxAppsParams) middleware.Responder { ricdms.Logger.Debug("==> onboard API invoked.") resp := r.rh.OnBoard(poap.Body) return resp }) + api.ChartsGetChartsListHandler = charts.GetChartsListHandlerFunc(func(param charts.GetChartsListParams) middleware.Responder { + ricdms.Logger.Debug("==> GetChartList") + resp := r.rh.GetCharts() + return resp + }) + + api.ChartsDownloadHelmChartHandler = charts.DownloadHelmChartHandlerFunc(func(param charts.DownloadHelmChartParams) middleware.Responder { + ricdms.Logger.Debug("==> Download helm chart") + resp := r.rh.DownloadChart(param.XAppName, param.Version) + return resp + }) + + api.ChartsGetChartHandler = charts.GetChartHandlerFunc(func(param charts.GetChartParams) middleware.Responder { + ricdms.Logger.Debug("==> Get Charts by name is invoked") + resp := r.rh.GetChartsByName(param.XAppName) + return resp + }) + + api.ChartsGetChartsFetcherHandler = charts.GetChartsFetcherHandlerFunc(func(param charts.GetChartsFetcherParams) middleware.Responder { + ricdms.Logger.Debug("==> Get Charts by name and version is invoked") + resp := r.rh.GetChartByNameAndVersion(param.XAppName, param.Version) + 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 }