-
Notifications
You must be signed in to change notification settings - Fork 8
/
cbstore.go
76 lines (67 loc) · 2.01 KB
/
cbstore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// CB-Store is a common repository for managing Meta Info of Cloud-Barista.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
//
// by powerkim@etri.re.kr, 2019.08.
package cbstore
import (
"fmt"
"github.com/cloud-barista/cb-store/config"
icbs "github.com/cloud-barista/cb-store/interfaces"
etcddrv "github.com/cloud-barista/cb-store/store-drivers/etcd-driver"
nutsdrv "github.com/cloud-barista/cb-store/store-drivers/nutsdb-driver"
)
var configInfo *config.CBSTORECONFIG
func init() {
//config.Cblogger.Info("calling!")
configInfo = config.GetConfigInfos()
}
// initialize db
func InitStore() error {
// NUTSDB: If InitDB will be done online by other process, this is not effective until restart.
if configInfo.STORETYPE == "NUTSDB" {
// 1. remove path: rm -rf ./meta_store/*
// init nutsdb metainfo
store := nutsdrv.NUTSDBDriver{}
return store.InitDB()
}
if configInfo.STORETYPE == "ETCD" {
// init etcd metainfo
store := etcddrv.ETCDDriver{}
return store.InitDB()
}
return fmt.Errorf("STORETYPE:" + configInfo.STORETYPE + " is not supported!!")
}
// clean all
func InitData() error {
// NUTSDB: If InitDB will be done online by other process, this is not effective until restart.
if configInfo.STORETYPE == "NUTSDB" {
// 1. remove path: rm -rf ./meta_store/*
// init nutsdb metainfo
store := nutsdrv.NUTSDBDriver{}
return store.InitData()
}
if configInfo.STORETYPE == "ETCD" {
// init etcd metainfo
store := etcddrv.ETCDDriver{}
return store.InitData()
}
return fmt.Errorf("STORETYPE:" + configInfo.STORETYPE + " is not supported!!")
}
func GetStore() icbs.Store {
if configInfo.STORETYPE == "NUTSDB" {
// NutsDB 드라이버 초기화 호출
nutsdrv.InitializeDriver()
store := nutsdrv.NUTSDBDriver{}
return &store
}
if configInfo.STORETYPE == "ETCD" {
// ETCD 드라이버 초기화 호출
etcddrv.InitializeDriver()
store := etcddrv.ETCDDriver{}
return &store
}
config.Cblogger.Errorf("STORETYPE:" + configInfo.STORETYPE + " is not supported!!")
return nil
}