X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=cmd%2Fappmgr%2Fdb.go;fp=cmd%2Fappmgr%2Fdb.go;h=0000000000000000000000000000000000000000;hb=34e4383c438f87023bc411d9b0baa4a828a7e306;hp=97865c28acb964bdb9134b609c272274d97c5de0;hpb=4703b1a7457cf072640adbc0f5487a0675f5b6d3;p=ric-plt%2Fappmgr.git diff --git a/cmd/appmgr/db.go b/cmd/appmgr/db.go deleted file mode 100755 index 97865c2..0000000 --- a/cmd/appmgr/db.go +++ /dev/null @@ -1,91 +0,0 @@ -/* -================================================================================== - 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. -================================================================================== -*/ - -package main - -import ( - "encoding/json" - sdl "gerrit.oran-osc.org/r/ric-plt/sdlgo" - cmap "github.com/orcaman/concurrent-map" - "github.com/spf13/viper" - "time" -) - -type DB struct { - session *sdl.SdlInstance -} - -func (d *DB) Create() { - ns := viper.GetString("db.sessionNamespace") - d.session = sdl.NewSdlInstance(ns, sdl.NewDatabase()) - - // Test DB connection, and wait until ready! - for { - if _, err := d.session.GetAll(); err == nil { - return - } - Logger.Error("Database connection not ready, waiting ...") - time.Sleep(time.Duration(5 * time.Second)) - } -} - -func (d *DB) StoreSubscriptions(m cmap.ConcurrentMap) { - for v := range m.Iter() { - s := v.Val.(Subscription) - - data, err := json.Marshal(s.req) - if err != nil { - Logger.Error("json.marshal failed: %v ", err.Error()) - return - } - - if err := d.session.Set(s.req.Id, data); err != nil { - Logger.Error("DB.session.Set failed: %v ", err.Error()) - } - } -} - -func (d *DB) RestoreSubscriptions() (m cmap.ConcurrentMap) { - m = cmap.New() - - keys, err := d.session.GetAll() - if err != nil { - Logger.Error("DB.session.GetAll failed: %v ", err.Error()) - return - } - - for _, key := range keys { - value, err := d.session.Get([]string{key}) - if err != nil { - Logger.Error("DB.session.Get failed: %v ", err.Error()) - return - } - - var item SubscriptionReq - if err = json.Unmarshal([]byte(value[key].(string)), &item); err != nil { - Logger.Error("json.Unmarshal failed: %v ", err.Error()) - return - } - - resp := SubscriptionResp{key, 0, item.EventType} - m.Set(key, Subscription{item, resp}) - } - - return m -}