Added an optional parameter to send config during xapp registration to 57/5457/2
authorwahidw <abdulwahid.w@nokia.com>
Mon, 18 Jan 2021 13:00:57 +0000 (13:00 +0000)
committerwahidw <abdulwahid.w@nokia.com>
Sun, 24 Jan 2021 11:03:08 +0000 (11:03 +0000)
RIC.

Signed-off-by: wahidw <abdulwahid.w@nokia.com>
Change-Id: If08e30cec580bf9ac0b107cf6a173060879ee2ac

api/appmgr_rest_api.yaml
container-tag.yaml
pkg/restful/restful.go
pkg/resthooks/resthooks.go

index 1e6e1fa..15d530f 100755 (executable)
@@ -1,3 +1,19 @@
+#==================================================================================
+#  Copyright (c) 2019 AT&T Intellectual Property.
+#  Copyright (c) 2019 Nokia
+#
+#   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.
+#==================================================================================
 swagger: '2.0'
 info:
   description: This is a draft API for RIC appmgr
@@ -596,6 +612,9 @@ definitions:
         type: string
       rmrEndpoint:
         type: string
+      config:
+        type: string
+        description: Configuration in JSON string format
   deregisterRequest:
     type: object
     required:
index 7d8248c..b768677 100755 (executable)
@@ -1,4 +1,4 @@
 # The Jenkins job uses this string for the tag in the image name
 # for example nexus3.o-ran-sc.org:10004/my-image-name:my-tag
 ---
-tag: '0.5.2'
+tag: '0.5.3'
index 077eea0..86f2cf0 100755 (executable)
@@ -45,15 +45,16 @@ import (
 )
 
 type XappData struct {
-       httpendpoint   string
-       rmrendpoint    string
-       rmrserviceep   string
-       status         string
-       xappname       string
-       xappinstname   string
-       xappversion    string
-       xappconfigpath string
-       xappInstance   *models.XappInstance
+       httpendpoint     string
+       rmrendpoint      string
+       rmrserviceep     string
+       status           string
+       xappname         string
+       xappinstname     string
+       xappversion      string
+       xappconfigpath   string
+       xappdynamiconfig bool
+       xappInstance     *models.XappInstance
 }
 
 var xappmap = map[string]map[string]*XappData{}
@@ -303,10 +304,18 @@ func (r *Restful) DeregisterXapp(params models.DeregisterRequest) (xapp *models.
 
 func (r *Restful) PrepareConfig(params models.RegisterRequest, updateflag bool) (xapp *models.Xapp, err error) {
        maxRetries := 5
-       //tmpString := strings.Split(*params.HTTPEndpoint, "//")
+       configPresent := false
+       var xappconfig *string
        appmgr.Logger.Info("http endpoint is %s", *params.HTTPEndpoint)
        for i := 1; i <= maxRetries; i++ {
-               xappconfig := httpGetXAppsconfig(fmt.Sprintf("http://%s%s", *params.HTTPEndpoint, params.ConfigPath))
+               if params.Config != "" {
+                       appmgr.Logger.Info("Getting config during xapp register: %v", params.Config)
+                       xappconfig = &params.Config
+                       configPresent = true
+               } else {
+                       appmgr.Logger.Info("Getting config from xapp:")
+                       xappconfig = httpGetXAppsconfig(fmt.Sprintf("http://%s%s", *params.HTTPEndpoint, params.ConfigPath))
+               }
 
                if xappconfig != nil {
                        data := parseConfig(xappconfig)
@@ -319,10 +328,13 @@ func (r *Restful) PrepareConfig(params models.RegisterRequest, updateflag bool)
                                //xapp.Status = params.Status
 
                                r.rh.UpdateAppData(params, updateflag)
-                               return r.FillInstanceData(params, &xapp, *data)
+                               return r.FillInstanceData(params, &xapp, *data, configPresent)
                                break
                        } else {
-                               appmgr.Logger.Error("Couldn't get data due to" + err.Error())
+                               appmgr.Logger.Error("No Data from xapp")
+                       }
+                       if configPresent == true {
+                               break
                        }
                        time.Sleep(2 * time.Second)
                }
@@ -330,9 +342,8 @@ func (r *Restful) PrepareConfig(params models.RegisterRequest, updateflag bool)
        return nil, errors.New("Unable to get configmap after 5 retries")
 }
 
-func (r *Restful) FillInstanceData(params models.RegisterRequest, xapp *models.Xapp, rtData appmgr.RtmData) (xapps *models.Xapp, err error) {
+func (r *Restful) FillInstanceData(params models.RegisterRequest, xapp *models.Xapp, rtData appmgr.RtmData, configFlag bool) (xapps *models.Xapp, err error) {
 
-       //tmpString := strings.Split(*params.RmrEndpoint, "//")
        endPointStr := strings.Split(*params.RmrEndpoint, ":")
        var x models.XappInstance
        x.Name = params.AppInstanceName
@@ -348,14 +359,15 @@ func (r *Restful) FillInstanceData(params models.RegisterRequest, xapp *models.X
        rmrsrvname := fmt.Sprintf("service-ricxapp-%s-rmr.ricxapp:%s", *params.AppInstanceName, x.Port)
 
        a := &XappData{httpendpoint: *params.HTTPEndpoint,
-               rmrendpoint:    *params.RmrEndpoint,
-               rmrserviceep:   rmrsrvname,
-               status:         "deployed",
-               xappname:       *params.AppName,
-               xappversion:    params.AppVersion,
-               xappinstname:   *params.AppInstanceName,
-               xappconfigpath: params.ConfigPath,
-               xappInstance:   &x}
+               rmrendpoint:      *params.RmrEndpoint,
+               rmrserviceep:     rmrsrvname,
+               status:           "deployed",
+               xappname:         *params.AppName,
+               xappversion:      params.AppVersion,
+               xappinstname:     *params.AppInstanceName,
+               xappconfigpath:   params.ConfigPath,
+               xappdynamiconfig: configFlag,
+               xappInstance:     &x}
 
        if _, ok := xappmap[*params.AppName]; ok {
                xappmap[*params.AppName][*params.AppInstanceName] = a
@@ -390,9 +402,12 @@ func (r *Restful) GetApps() (xapps models.AllDeployedXapps, err error) {
 
 func (r *Restful) getAppConfig() (configList models.AllXappConfig) {
        for _, v := range xappmap {
-               namespace := "ricxapp" //Namespace hardcode, to be removed later
+               namespace := "ricxapp" //Namespace hardcoded, to be removed later
                for _, j := range v {
                        var activeConfig interface{}
+                       if j.xappdynamiconfig {
+                               continue
+                       }
                        xappconfig := httpGetXAppsconfig(fmt.Sprintf("http://%s%s", j.httpendpoint, j.xappconfigpath))
 
                        if xappconfig == nil {
index 6b405fc..1bc7925 100755 (executable)
@@ -35,14 +35,14 @@ import (
 )
 
 func NewResthook(restoreData bool) *Resthook {
-       return createResthook(restoreData, sdl.NewSdlInstance("appmgr", sdl.NewDatabase()),sdl.NewSdlInstance("appdb", sdl.NewDatabase()))
+       return createResthook(restoreData, sdl.NewSdlInstance("appmgr", sdl.NewDatabase()), sdl.NewSdlInstance("appdb", sdl.NewDatabase()))
 }
 
 func createResthook(restoreData bool, sdlInst iSdl, sdlInst2 iSdl) *Resthook {
        rh := &Resthook{
                client: &http.Client{},
                db:     sdlInst,
-               db2:    sdlInst2,
+               db2:    sdlInst2,
        }
 
        if restoreData {
@@ -247,6 +247,11 @@ func (rh *Resthook) UpdateAppData(params models.RegisterRequest, updateflag bool
                return
        }
 
+       //Ensure config is empty string, as we dont want to store config in DB
+       if params.Config != "" {
+               params.Config = ""
+       }
+
        value, err := rh.db2.Get([]string{"endpoints"})
        if err != nil {
                appmgr.Logger.Error("DB.session.Get failed: %v ", err.Error())