1 // SPDX-License-Identifier: Apache-2.0
\r
2 // Copyright (c) 2020 Intel Corporation
\r
7 "github.com/open-ness/EMCO/src/orchestrator/pkg/infra/config"
\r
8 pkgerrors "github.com/pkg/errors"
\r
11 // Db interface used to talk a concrete Database connection
\r
14 // ContextDb is an interface for accessing the context database
\r
15 type ContextDb interface {
\r
16 // Returns nil if db health is good
\r
18 // Puts Json Struct in db with key
\r
19 Put(key string, value interface{}) error
\r
21 Delete(key string) error
\r
22 // Delete all keys in heirarchy
\r
23 DeleteAll(key string) error
\r
24 // Gets Json Struct from db
\r
25 Get(key string, value interface{}) error
\r
26 // Returns all keys with a prefix
\r
27 GetAllKeys(path string) ([]string, error)
\r
30 // createContextDBClient creates the DB client
\r
31 func createContextDBClient(dbType string) error {
\r
36 Endpoint: config.GetConfiguration().EtcdIP,
\r
37 CertFile: config.GetConfiguration().EtcdCert,
\r
38 KeyFile: config.GetConfiguration().EtcdKey,
\r
39 CAFile: config.GetConfiguration().EtcdCAFile,
\r
41 Db, err = NewEtcdClient(nil, c)
\r
43 pkgerrors.Wrap(err, "Etcd Client Initialization failed with error")
\r
46 return pkgerrors.New(dbType + "DB not supported")
\r
51 // InitializeContextDatabase sets up the connection to the
\r
52 // configured database to allow the application to talk to it.
\r
53 func InitializeContextDatabase() error {
\r
54 // Only support Etcd for now
\r
55 err := createContextDBClient("etcd")
\r
57 return pkgerrors.Cause(err)
\r
59 err = Db.HealthCheck()
\r
61 return pkgerrors.Cause(err)
\r