2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
24 httptransport "github.com/go-openapi/runtime/client"
25 "github.com/go-openapi/strfmt"
27 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
28 apiclient "gerrit.oran-osc.org/r/ric-plt/o1mediator/pkg/appmgrclient"
29 apixapp "gerrit.oran-osc.org/r/ric-plt/o1mediator/pkg/appmgrclient/xapp"
30 apimodel "gerrit.oran-osc.org/r/ric-plt/o1mediator/pkg/appmgrmodel"
35 func NewSBIClient(host, baseUrl string, prot []string, timo int) *SBIClient {
36 return &SBIClient{host, baseUrl, prot, time.Duration(timo) * time.Second}
39 func (s *SBIClient) CreateTransport() *apiclient.RICAppmgr {
40 return apiclient.New(httptransport.New(s.host, s.baseUrl, s.prot), strfmt.Default)
43 func (s *SBIClient) BuildXappDescriptor(name, namespace, release, version string) *apimodel.XappDescriptor {
44 return &apimodel.XappDescriptor{
52 func (s *SBIClient) DeployXapp(xappDesc *apimodel.XappDescriptor) error {
53 params := apixapp.NewDeployXappParamsWithTimeout(s.timeout).WithXappDescriptor(xappDesc)
54 log.Info("SBI: DeployXapp=%v", params)
56 result, err := s.CreateTransport().Xapp.DeployXapp(params)
58 log.Error("SBI: DeployXapp unsuccessful: %v", err)
60 log.Info("SBI: DeployXapp successful: payload=%v", result.Payload)
65 func (s *SBIClient) UndeployXapp(xappDesc *apimodel.XappDescriptor) error {
66 name := *xappDesc.XappName
67 if xappDesc.ReleaseName != "" {
68 name = xappDesc.ReleaseName
71 params := apixapp.NewUndeployXappParamsWithTimeout(s.timeout).WithXAppName(name)
72 log.Info("SBI: UndeployXapp=%v", params)
74 result, err := s.CreateTransport().Xapp.UndeployXapp(params)
76 log.Error("SBI: UndeployXapp unsuccessful: %v", err)
78 log.Info("SBI: UndeployXapp successful: payload=%v", result)
83 func (s *SBIClient) GetDeployedXapps() error {
84 params := apixapp.NewGetAllXappsParamsWithTimeout(s.timeout)
85 result, err := s.CreateTransport().Xapp.GetAllXapps(params)
87 log.Error("GET unsuccessful: %v", err)
89 log.Info("GET successful: payload=%v", result.Payload)
94 func (s *SBIClient) BuildXappConfig(name, namespace string, configData interface{}) *apimodel.XAppConfig {
95 metadata := &apimodel.ConfigMetadata{
97 Namespace: &namespace,
100 return &apimodel.XAppConfig{
106 func (s *SBIClient) ModifyXappConfig(xappConfig *apimodel.XAppConfig) error {
107 params := apixapp.NewModifyXappConfigParamsWithTimeout(s.timeout).WithXAppConfig(xappConfig)
108 result, err := s.CreateTransport().Xapp.ModifyXappConfig(params)
110 log.Error("SBI: ModifyXappConfig unsuccessful: %v", err)
112 log.Info("SBI: ModifyXappConfig successful: payload=%v", result.Payload)