Implement custom onboard functionality 23/11223/1
authorsubhash kumar singh <subh.singh@samsung.com>
Thu, 25 May 2023 12:14:38 +0000 (12:14 +0000)
committersubhash kumar singh <subh.singh@samsung.com>
Thu, 25 May 2023 12:14:38 +0000 (12:14 +0000)
Implemented custom onbaording functionality to push helm
chart to chartmuseum.

Issue-ID: RIC-955
Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
Change-Id: I7ea16b00c86bdbaeb18197397605bd67efa90db2

pkg/onboard/onboarder.go
pkg/restful/restful.go

index a06f043..64b15f6 100644 (file)
@@ -1,30 +1,33 @@
-//==================================================================================
-//  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"
+       "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"
@@ -32,6 +35,7 @@ import (
 
 type IOnboarder interface {
        Onboard(descriptor *models.Descriptor) middleware.Responder
+       CustomOnboard(reader io.Reader) middleware.Responder
 }
 
 type Onboarder struct {
@@ -67,3 +71,22 @@ func (o *Onboarder) Onboard(descriptor *models.Descriptor) middleware.Responder
        }
        return onboard.NewPostOnboardxAppsCreated()
 }
+
+// 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("http://service-ricplt-xapp-onboarder-http.ricplt:8080/api/charts", "application/x-www-form-urlencoded", reader)
+       if err != nil {
+               ricdms.Logger.Error("err received while onboarding chart to chartmuseum: %v", err)
+               // TODO: introcuce error in in swagger to handle the error cases.
+               return nil
+       }
+
+       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)
+               return nil
+       }
+       return &experiment.PostCustomOnboardOK{}
+}
index 72dcea1..4e91b09 100644 (file)
@@ -122,8 +122,8 @@ func (r *Restful) setupHandler() {
 
        api.ExperimentPostCustomOnboardHandler = experiment.PostCustomOnboardHandlerFunc(func(pcop experiment.PostCustomOnboardParams) middleware.Responder {
                ricdms.Logger.Debug("==> invoked custom onboarding")
-               // TODO: provide implementatoin
-               return &experiment.PostCustomOnboardOK{}
+               defer pcop.Upfile.Close()
+               return r.rh.Onboarder.CustomOnboard(pcop.Upfile)
        })
 
        api.ApplicationZipProducer = runtime.ProducerFunc(func(w io.Writer, data interface{}) error {