Implemented Onboarding by using API from onboarder service.
Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
Change-Id: Ib4c0032c4906b3a2f2b3b70c1d6c2a9f6caad540
properties:
config:
description: represents content of config file for xApp onboarding.
- type: string
+ type: object
config-file_url:
description: specify url of config-file.
type: string
schema:
description: represents conent of schema file for xApp onboarding.
- type: string
+ type: object
schema-file_url:
description: specify url of schema-file.
type: string
--- /dev/null
+//==================================================================================
+// 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
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// 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"
+ "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/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
+}
+
+type Onboarder struct {
+}
+
+func NewOnboarder() IOnboarder {
+ return &Onboarder{}
+}
+
+func (o *Onboarder) Onboard(descriptor *models.Descriptor) middleware.Responder {
+ ricdms.Logger.Debug("onboarder invoked : %+v", descriptor)
+
+ // validate if the required patameter is available
+ if descriptor.Schema == nil || descriptor.Config == nil {
+ return onboard.NewPostOnboardxAppsBadRequest()
+ }
+
+ body := map[string]interface{}{
+ "config-file.json": descriptor.Config,
+ "controls-schema.json": descriptor.Schema,
+ }
+
+ bodyBytes, _ := json.Marshal(body)
+
+ // resp, err := http.Post("http://172.17.0.1:8888/api/v1/onboard", "application/json", bytes.NewReader(bodyBytes))
+ ricdms.Logger.Info("config : %+v", ricdms.Config)
+ resp, err := http.Post(ricdms.Config.OnboardURL, "application/json", bytes.NewReader(bodyBytes))
+
+ if err == nil {
+ ricdms.Logger.Info("no error response: %+v", resp)
+ } else {
+ ricdms.Logger.Error("err : (%v)", err)
+ }
+ return onboard.NewPostOnboardxAppsCreated()
+}
"os"
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/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"
r := &Restful{
rh: resthooks.NewResthook(
ph.NewHealthChecker(),
+ po.NewOnboarder(),
),
}
r.setupHandler()
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
+ })
+
r.api = api
}
import (
ph "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/onboard"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
"github.com/go-openapi/runtime/middleware"
)
-func NewResthook(h ph.IHealthChecker) *Resthook {
+func NewResthook(h ph.IHealthChecker, o onboard.IOnboarder) *Resthook {
return &Resthook{
HealthChecker: h,
+ Onboarder: o,
}
}
ricdms.Logger.Debug("healthchecker : %v\n", rh.HealthChecker)
return health.NewGetHealthCheckOK().WithPayload(rh.HealthChecker.GetStatus())
}
+
+func (rh *Resthook) OnBoard(params *models.Descriptor) (resp middleware.Responder) {
+ ricdms.Logger.Debug("onboarder: invoked")
+ return rh.Onboarder.Onboard(params)
+}
package resthooks
import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net"
+ "net/http"
+ "net/http/httptest"
"os"
"testing"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/onboard"
h "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
"github.com/stretchr/testify/assert"
ricdms.Init()
rh = &Resthook{
HealthChecker: HealthCheckerMock{},
+ Onboarder: onboard.NewOnboarder(),
}
code := m.Run()
os.Exit(code)
}
}
+func TestOnboard(t *testing.T) {
+ xApp := &models.Descriptor{
+ Config: "SAMPLE_CONFIGURATION",
+ Schema: "SAMPLE_SCHEMA",
+ }
+
+ svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ var d map[string]interface{}
+ reqBytes, _ := ioutil.ReadAll(r.Body)
+ defer r.Body.Close()
+
+ err := json.Unmarshal(reqBytes, &d)
+
+ ricdms.Logger.Debug("after unmarshal : %+v body: %+v", d, string(reqBytes))
+
+ if err != nil {
+ assert.Fail(t, "Not able to parse the request body")
+ }
+
+ assert.Equal(t, xApp.Config, d["config-file.json"])
+ assert.Equal(t, xApp.Schema, d["controls-schema.json"])
+ fmt.Fprintf(w, "SAMPLE_RESPONSE")
+ }))
+ svr.Listener.Close()
+ svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer)
+
+ svr.Start()
+ defer svr.Close()
+
+ resp := rh.OnBoard(xApp)
+ assert.NotEqual(t, nil, resp)
+}
+
type HealthCheckerMock struct {
mock.Mock
}
import (
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/onboard"
)
type Resthook struct {
HealthChecker health.IHealthChecker
+ Onboarder onboard.IOnboarder
}