1 // ==================================================================================
3 // Copyright (c) 2022 Samsung
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
20 // ==================================================================================
29 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
30 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/experiment"
31 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/onboard"
32 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
33 "github.com/go-openapi/runtime/middleware"
36 type IOnboarder interface {
37 Onboard(descriptor *models.Descriptor) middleware.Responder
38 CustomOnboard(reader io.Reader) middleware.Responder
41 type Onboarder struct {
44 func NewOnboarder() IOnboarder {
48 func (o *Onboarder) Onboard(descriptor *models.Descriptor) middleware.Responder {
49 ricdms.Logger.Debug("onboarder invoked : %+v", descriptor)
51 // validate if the required patameter is available
52 if descriptor.Schema == nil || descriptor.Config == nil {
53 return onboard.NewPostOnboardxAppsBadRequest()
56 body := map[string]interface{}{
57 "config-file.json": descriptor.Config,
58 "controls-schema.json": descriptor.Schema,
61 bodyBytes, _ := json.Marshal(body)
63 // resp, err := http.Post("http://172.17.0.1:8888/api/v1/onboard", "application/json", bytes.NewReader(bodyBytes))
64 ricdms.Logger.Info("config : %+v", ricdms.Config)
65 resp, err := http.Post(ricdms.Config.OnboardURL, "application/json", bytes.NewReader(bodyBytes))
68 ricdms.Logger.Info("no error response: %+v", resp)
70 ricdms.Logger.Error("err : (%v)", err)
72 return onboard.NewPostOnboardxAppsCreated()
75 // onboard provided helm chart
76 func (o *Onboarder) CustomOnboard(reader io.Reader) middleware.Responder {
77 ricdms.Logger.Debug("onboarder received req to onboard")
78 resp, err := http.Post(ricdms.Config.CustomOnboardURL, "application/x-www-form-urlencoded", reader)
80 ricdms.Logger.Error("err received while onboarding chart to chartmuseum: %v", err)
81 // TODO: introcuce error in in swagger to handle the error cases.
85 defer resp.Body.Close()
86 if resp.StatusCode < 200 || resp.StatusCode >= 300 {
87 // TODO: return error code in response
88 ricdms.Logger.Error("chartmuseum returned bad status code(%d): %+v", resp.StatusCode, resp)
91 return &experiment.PostCustomOnboardOK{}