1 //==================================================================================
2 // Copyright (c) 2022 Samsung
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 // platform project (RICP).
18 //==================================================================================
29 ch "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/charts"
30 ph "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
31 po "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/onboard"
32 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi"
33 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations"
34 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/charts"
35 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health"
36 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/onboard"
37 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/resthooks"
38 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
39 "github.com/go-openapi/loads"
40 "github.com/go-openapi/runtime"
41 "github.com/go-openapi/runtime/middleware"
44 func NewRestful() *Restful {
46 rh: resthooks.NewResthook(
47 ph.NewHealthChecker(),
56 func (r *Restful) setupHandler() {
57 swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
62 api := operations.NewRICDMSAPI(swaggerSpec)
64 api.HealthGetHealthCheckHandler = health.GetHealthCheckHandlerFunc(func(ghcp health.GetHealthCheckParams) middleware.Responder {
65 ricdms.Logger.Debug("==> HealthCheck API invoked.")
66 resp := r.rh.GetDMSHealth()
70 api.OnboardPostOnboardxAppsHandler = onboard.PostOnboardxAppsHandlerFunc(func(poap onboard.PostOnboardxAppsParams) middleware.Responder {
71 ricdms.Logger.Debug("==> onboard API invoked.")
72 resp := r.rh.OnBoard(poap.Body)
76 api.ChartsGetChartsListHandler = charts.GetChartsListHandlerFunc(func(param charts.GetChartsListParams) middleware.Responder {
77 ricdms.Logger.Debug("==> GetChartList")
78 resp := r.rh.GetCharts()
82 api.ChartsDownloadHelmChartHandler = charts.DownloadHelmChartHandlerFunc(func(param charts.DownloadHelmChartParams) middleware.Responder {
83 ricdms.Logger.Debug("==> Download helm chart")
84 resp := r.rh.DownloadChart(param.XAppName, param.Version)
88 api.ChartsGetChartHandler = charts.GetChartHandlerFunc(func(param charts.GetChartParams) middleware.Responder {
89 ricdms.Logger.Debug("==> Get Charts by name is invoked")
90 resp := r.rh.GetChartsByName(param.XAppName)
94 api.ChartsGetChartsFetcherHandler = charts.GetChartsFetcherHandlerFunc(func(param charts.GetChartsFetcherParams) middleware.Responder {
95 ricdms.Logger.Debug("==> Get Charts by name and version is invoked")
96 resp := r.rh.GetChartByNameAndVersion(param.XAppName, param.Version)
100 api.ApplicationZipProducer = runtime.ProducerFunc(func(w io.Writer, data interface{}) error {
101 if zp, ok := data.(io.ReadCloser); ok {
103 b, err := ioutil.ReadAll(zp)
106 ricdms.Logger.Error("error: %v", err)
112 ricdms.Logger.Error("error: %v", err)
117 return fmt.Errorf("not support")
122 func (r *Restful) Run() {
123 server := restapi.NewServer(r.api)
124 defer server.Shutdown()
126 server.Host = "0.0.0.0"
127 ricdms.Logger.Info("Starting server at : %s:%d", server.Host, server.Port)
128 if err := server.Serve(); err != nil {
129 log.Fatal(err.Error())