X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=pkg%2Fonboard%2Fonboarder.go;fp=pkg%2Fonboard%2Fonboarder.go;h=a06f043c14fdd6e162af7671d1c54e3d7803e301;hb=04897e6ba579f0cfd11453f589fc1fb24be4e820;hp=0000000000000000000000000000000000000000;hpb=d349bbcc5736a3f09091788cbe6afe9cdef116cd;p=ric-plt%2Fricdms.git diff --git a/pkg/onboard/onboarder.go b/pkg/onboard/onboarder.go new file mode 100644 index 0000000..a06f043 --- /dev/null +++ b/pkg/onboard/onboarder.go @@ -0,0 +1,69 @@ +//================================================================================== +// 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() +}