Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #245 from IBM/release_v1.2.0
Browse files Browse the repository at this point in the history
Release v1.2.0
  • Loading branch information
shay-berman authored Sep 16, 2018
2 parents 05e861a + de2fb2a commit eef6f1d
Show file tree
Hide file tree
Showing 96 changed files with 6,179 additions and 4,390 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM golang:1.9.1
WORKDIR /go/src/github.com/IBM/ubiquity/
COPY . .
RUN go get -v github.com/Masterminds/glide
ADD glide.yaml .
RUN glide up
COPY . .
RUN CGO_ENABLED=1 GOOS=linux go build -tags netgo -v -a --ldflags '-w -linkmode external -extldflags "-static"' -installsuffix cgo -o ubiquity main.go


FROM alpine:3.7
RUN apk --no-cache add ca-certificates=20171114-r0 openssl=1.0.2o-r0
RUN apk --no-cache add ca-certificates=20171114-r0 openssl=1.0.2o-r1
WORKDIR /root/
COPY --from=0 /go/src/github.com/IBM/ubiquity/ubiquity .
COPY --from=0 /go/src/github.com/IBM/ubiquity/LICENSE .
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,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. 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. 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 Down
113 changes: 56 additions & 57 deletions database/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,105 +19,104 @@ 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"
)

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
type testErrorFactory struct {
}

type testErrorFactory struct {
type testCorrectFactory 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)
func (f *testErrorFactory) newConnection() (*gorm.DB, error) {
return nil, errors.New("testErrorFactory")
}

func (f *testErrorFactory) newConnection() (*gorm.DB, error) {
return nil, errors.New("testErrorFactory")
func (f *testCorrectFactory) newConnection() (*gorm.DB, error) {
db := new(*gorm.DB)
return *db, nil
}

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
}
40 changes: 12 additions & 28 deletions database/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,29 @@

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() {
Context(".Open", func() {
It("open success", func() {
defer database.InitTestCorrect()()
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() {
defer database.InitTestCorrect()()
dbConnection := database.NewConnection()
Expect(dbConnection.GetDb()).To(BeNil())
err = dbConnection.Close()
Expand Down
Loading

0 comments on commit eef6f1d

Please sign in to comment.