-//==================================================================================
-// Copyright (c) 2022 Samsung
+// ==================================================================================
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Copyright (c) 2022 Samsung
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// This source code is part of the near-RT RIC (RAN Intelligent Controller)
-// platform project (RICP).
-//==================================================================================
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
//
+// This source code is part of the near-RT RIC (RAN Intelligent Controller)
+// platform project (RICP).
+//
+// ==================================================================================
package onboard
import (
"bytes"
"encoding/json"
+ "fmt"
+ "io"
"net/http"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/experiment"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/onboard"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
"github.com/go-openapi/runtime/middleware"
type IOnboarder interface {
Onboard(descriptor *models.Descriptor) middleware.Responder
+ CustomOnboard(reader io.Reader) middleware.Responder
}
type Onboarder struct {
} else {
ricdms.Logger.Error("err : (%v)", err)
}
- return onboard.NewPostOnboardxAppsCreated()
+ return experiment.NewPostCustomOnboardOK()
+}
+
+// onboard provided helm chart
+func (o *Onboarder) CustomOnboard(reader io.Reader) middleware.Responder {
+ ricdms.Logger.Debug("onboarder received req to onboard")
+ resp, err := http.Post(ricdms.Config.CustomOnboardURL, "application/x-www-form-urlencoded", reader)
+ if err != nil {
+ ricdms.Logger.Error("err received while onboarding chart to chartmuseum: %v", err)
+ errmsg := err.Error()
+ resp := experiment.NewPostCustomOnboardInternalServerError()
+ resp.SetPayload(&models.ErrorMessage{
+ ErrorMessage: &errmsg,
+ })
+ return resp
+ }
+
+ defer resp.Body.Close()
+ if resp.StatusCode < 200 || resp.StatusCode >= 300 {
+ // TODO: return error code in response
+ ricdms.Logger.Error("chartmuseum returned bad status code(%d): %+v", resp.StatusCode, resp)
+ errmsg := fmt.Sprintf("chartmuseum returns status code :%d", resp.StatusCode)
+ resp := experiment.NewPostCustomOnboardInternalServerError()
+ resp.SetPayload(&models.ErrorMessage{
+ ErrorMessage: &errmsg,
+ })
+ return resp
+ }
+ return &experiment.PostCustomOnboardOK{}
}