forked from cloud-barista/cb-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbstore.go
74 lines (63 loc) · 2 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
// CB-Store is a common repository for managing Meta Info of Cloud-Barista.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
//
// by [email protected], 2019.08.
package cbstore
import (
"fmt"
"github.com/cloud-barista/cb-store/config"
icbs "github.com/cloud-barista/cb-store/interfaces"
nutsdrv "github.com/cloud-barista/cb-store/store-drivers/nutsdb-driver"
etcddrv "github.com/cloud-barista/cb-store/store-drivers/etcd-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" {
store := nutsdrv.NUTSDBDriver{}
return &store
}
if configInfo.STORETYPE == "ETCD" {
store := etcddrv.ETCDDriver{}
return &store
}
config.Cblogger.Errorf("STORETYPE:" + configInfo.STORETYPE +" is not supported!!")
return nil
}