X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fonboard%2Fonboarder.go;h=42f5bab13c7ccca372281968b4fa53cc01596c2d;hb=a9156ec5f40039b97f97dfd3d3bae255a44c6333;hp=a06f043c14fdd6e162af7671d1c54e3d7803e301;hpb=04897e6ba579f0cfd11453f589fc1fb24be4e820;p=ric-plt%2Fricdms.git diff --git a/pkg/onboard/onboarder.go b/pkg/onboard/onboarder.go index a06f043..42f5bab 100644 --- a/pkg/onboard/onboarder.go +++ b/pkg/onboard/onboarder.go @@ -1,30 +1,34 @@ -//================================================================================== -// 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" @@ -32,6 +36,7 @@ import ( type IOnboarder interface { Onboard(descriptor *models.Descriptor) middleware.Responder + CustomOnboard(reader io.Reader) middleware.Responder } type Onboarder struct { @@ -65,5 +70,33 @@ func (o *Onboarder) Onboard(descriptor *models.Descriptor) middleware.Responder } 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{} }