Skip to content

Commit

Permalink
Merge branch 'dev' into fix/UB-624_Flex_should_not_write_log_into_fle…
Browse files Browse the repository at this point in the history
…x_driver_directory
  • Loading branch information
hfeish committed May 24, 2018
2 parents 25a2866 + aa56b12 commit 4c14050
Show file tree
Hide file tree
Showing 68 changed files with 13,799 additions and 6,788 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


The Ubiquity project enables persistent storage for the Kubernetes and Docker container frameworks. It is a pluggable framework available for different storage systems. The framework interfaces with the storage systems, using their plugins. Different container frameworks can use Ubiquity concurrently, allowing access to different storage systems.
Ubiquity supports the Kubernetes and Docker frameworks, using the following plugins:

Ubiquity supports the Kubernetes and Docker frameworks, using the following plugins:

Expand All @@ -17,7 +16,7 @@ Ubiquity supports the Kubernetes and Docker frameworks, using the following plug
Currently, the following storage systems use Ubiquity:
* IBM block storage.

The IBM block storage is supported for Kubernetes via IBM Spectrum Connect (3.4.0), previously known as IBM Spectrum Control Base Edition (3.3.0). Ubiquity communicates with the IBM storage systems through Spectrum Connect. Spectrum Connect creates a storage profile (for example, gold, silver or bronze) and makes it available for Kubernetes. For details about supported storage systems, refer to the latest Spectrum Connect release notes.
The IBM block storage is supported for Kubernetes via IBM Spectrum Connect (3.4.0), previously known as IBM Spectrum Control Base Edition. Ubiquity communicates with the IBM storage systems through Spectrum Connect. Spectrum Connect creates a storage profile (for example, gold, silver or bronze) and makes it available for Kubernetes. For details about supported storage systems, refer to the latest Spectrum Connect release notes.

The IBM official solution for Kubernetes, based on the Ubiquity project, is referred to as IBM Storage Enabler for Containers. You can download the installation package and its documentation from [IBM Fix Central](https://www.ibm.com/support/fixcentral/swg/selectFixes?parent=Software%2Bdefined%2Bstorage&product=ibm/StorageSoftware/IBM+Spectrum+Connect&release=All&platform=Linux&function=all). For details on the IBM Storage Enabler for Containers, see the relevant sections in the Spectrum Connect user guide.

Expand All @@ -42,7 +41,7 @@ To contribute, follow the guidelines in [Contribution guide](contribution-guide.


## Support
For any questions, suggestions, or issues, use github.
For any questions, suggestions, or issues, use Github.

## Licensing

Expand Down
114 changes: 57 additions & 57 deletions database/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,107 +17,107 @@
package database

import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/IBM/ubiquity/utils/logs"
"errors"
"errors"
"github.com/IBM/ubiquity/utils/logs"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)

var globalConnectionFactory ConnectionFactory = nil

func initConnectionFactory(connectionFactory ConnectionFactory) func() {
if globalConnectionFactory != nil {
panic("globalConnectionFactory already initialized")
}
globalConnectionFactory = connectionFactory
return func() { globalConnectionFactory = nil }
if globalConnectionFactory != nil {
panic("globalConnectionFactory already initialized")
}
globalConnectionFactory = connectionFactory
return func() { globalConnectionFactory = nil }
}

type ConnectionFactory interface {
newConnection() (*gorm.DB, error)
newConnection() (*gorm.DB, error)
}

type postgresFactory struct {
psql string
psqlLog string
psql string
psqlLog string
}

type sqliteFactory struct {
path string
path string
}

type testErrorFactory struct {
}

func (f *postgresFactory) newConnection() (*gorm.DB, error) {
logger := logs.GetLogger()
logger.Debug("", logs.Args{{"psql", f.psqlLog}})
return gorm.Open("postgres", f.psql)
logger := logs.GetLogger()
logger.Debug("", logs.Args{{"psql", f.psqlLog}})
return gorm.Open("postgres", f.psql)
}

func (f *sqliteFactory) newConnection() (*gorm.DB, error) {
return gorm.Open("sqlite3", f.path)
return gorm.Open("sqlite3", f.path)
}

func (f *testErrorFactory) newConnection() (*gorm.DB, error) {
return nil, errors.New("testErrorFactory")
return nil, errors.New("testErrorFactory")
}

type Connection struct {
factory ConnectionFactory
logger logs.Logger
db *gorm.DB
factory ConnectionFactory
logger logs.Logger
db *gorm.DB
}

func NewConnection() Connection {
return Connection{logger: logs.GetLogger(), factory: globalConnectionFactory}
return Connection{logger: logs.GetLogger(), factory: globalConnectionFactory}
}

func (c *Connection) Open() (error) {
defer c.logger.Trace(logs.DEBUG)()
var err error
func (c *Connection) Open() error {
defer c.logger.Trace(logs.DEBUG)()
var err error

// sanity
if c.db != nil {
return c.logger.ErrorRet(errors.New("Connection already open"), "failed")
}
// sanity
if c.db != nil {
return c.logger.ErrorRet(errors.New("Connection already open"), "failed")
}

// open db connection
if c.db, err = c.factory.newConnection(); err != nil {
return c.logger.ErrorRet(err, "failed")
}
// open db connection
if c.db, err = c.factory.newConnection(); err != nil {
return c.logger.ErrorRet(err, "failed")
}

// do migrations
if err = doMigrations(*c); err != nil {
defer c.Close()
return c.logger.ErrorRet(err, "doMigrations failed")
}
// do migrations
if err = doMigrations(*c); err != nil {
defer c.Close()
return c.logger.ErrorRet(err, "doMigrations failed")
}

return nil
return nil
}

func (c *Connection) Close() (error) {
defer c.logger.Trace(logs.DEBUG)()
var err error
func (c *Connection) Close() error {
defer c.logger.Trace(logs.DEBUG)()
var err error

// sanity
if c.db == nil {
return c.logger.ErrorRet(errors.New("Connection already closed"), "failed")
}
// sanity
if c.db == nil {
return c.logger.ErrorRet(errors.New("Connection already closed"), "failed")
}

// close db connection
err = c.db.Close()
c.db = nil
if err != nil {
return c.logger.ErrorRet(err, "failed")
}
// close db connection
err = c.db.Close()
c.db = nil
if err != nil {
return c.logger.ErrorRet(err, "failed")
}

return nil
return nil
}

func (c *Connection) GetDb() (*gorm.DB) {
defer c.logger.Trace(logs.DEBUG)()
func (c *Connection) GetDb() *gorm.DB {
defer c.logger.Trace(logs.DEBUG)()

return c.db
return c.db
}
78 changes: 38 additions & 40 deletions database/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,47 @@

package database_test


import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/IBM/ubiquity/database"
"github.com/IBM/ubiquity/database"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)


var _ = Describe("Connection", func() {
var (
err error
)
BeforeEach(func() {
})
var (
err error
)
BeforeEach(func() {
})

Context(".Open and Close", func() {
It("open and close success", func() {
dbConnection := database.NewConnection()
Expect(dbConnection.GetDb()).To(BeNil())
err = dbConnection.Open()
Expect(err).To(Not(HaveOccurred()))
Expect(dbConnection.GetDb()).To(Not(BeNil()))
err = dbConnection.Close()
Expect(err).To(Not(HaveOccurred()))
Expect(dbConnection.GetDb()).To(BeNil())
})
It("open fail", func() {
dbConnection := database.NewConnection()
Expect(dbConnection.GetDb()).To(BeNil())
err = dbConnection.Open()
Expect(err).To(Not(HaveOccurred()))
Expect(dbConnection.GetDb()).To(Not(BeNil()))
err = dbConnection.Open()
Expect(err).To(HaveOccurred())
err = dbConnection.Close()
Expect(err).To(Not(HaveOccurred()))
Expect(dbConnection.GetDb()).To(BeNil())
})
It("close fail", func() {
dbConnection := database.NewConnection()
Expect(dbConnection.GetDb()).To(BeNil())
err = dbConnection.Close()
Expect(err).To(HaveOccurred())
})
})
Context(".Open and Close", func() {
It("open and close success", func() {
dbConnection := database.NewConnection()
Expect(dbConnection.GetDb()).To(BeNil())
err = dbConnection.Open()
Expect(err).To(Not(HaveOccurred()))
Expect(dbConnection.GetDb()).To(Not(BeNil()))
err = dbConnection.Close()
Expect(err).To(Not(HaveOccurred()))
Expect(dbConnection.GetDb()).To(BeNil())
})
It("open fail", func() {
dbConnection := database.NewConnection()
Expect(dbConnection.GetDb()).To(BeNil())
err = dbConnection.Open()
Expect(err).To(Not(HaveOccurred()))
Expect(dbConnection.GetDb()).To(Not(BeNil()))
err = dbConnection.Open()
Expect(err).To(HaveOccurred())
err = dbConnection.Close()
Expect(err).To(Not(HaveOccurred()))
Expect(dbConnection.GetDb()).To(BeNil())
})
It("close fail", func() {
dbConnection := database.NewConnection()
Expect(dbConnection.GetDb()).To(BeNil())
err = dbConnection.Close()
Expect(err).To(HaveOccurred())
})
})
})

0 comments on commit 4c14050

Please sign in to comment.