report error if there's a nil storage driver

This commit is contained in:
Nan Deng 2014-06-17 15:07:41 -07:00
parent e65fc89270
commit e18c7fbf8f
2 changed files with 30 additions and 27 deletions

View File

@ -17,6 +17,7 @@
package manager
import (
"fmt"
"log"
"sync"
"time"
@ -81,6 +82,9 @@ func (c *containerData) GetInfo() (*containerInfo, error) {
}
func NewContainerData(containerName string, driver storage.StorageDriver) (*containerData, error) {
if driver == nil {
return nil, fmt.Errorf("nil storage driver")
}
cont := &containerData{}
handler, err := container.NewContainerHandler(containerName)
if err != nil {
@ -147,7 +151,6 @@ func (c *containerData) updateStats() error {
if stats == nil {
return nil
}
if c.storageDriver != nil {
ref, err := c.handler.ContainerReference()
if err != nil {
return err
@ -156,7 +159,6 @@ func (c *containerData) updateStats() error {
if err != nil {
return err
}
}
return nil
}

View File

@ -40,6 +40,9 @@ type Manager interface {
}
func New(driver storage.StorageDriver) (Manager, error) {
if driver == nil {
return nil, fmt.Errorf("nil storage driver!")
}
newManager := &manager{}
newManager.containers = make(map[string]*containerData)
@ -127,8 +130,7 @@ func (m *manager) GetContainerInfo(containerName string) (*info.ContainerInfo, e
var percentiles *info.ContainerStatsPercentiles
var samples []*info.ContainerStatsSample
var stats []*info.ContainerStats
if m.storageDriver != nil {
// XXX(monnand): These numbers should not be hard coded
// TODO(monnand): These numbers should not be hard coded
percentiles, err = m.storageDriver.Percentiles(
cinfo.Name,
[]int{50, 80, 90, 99},
@ -146,7 +148,6 @@ func (m *manager) GetContainerInfo(containerName string) (*info.ContainerInfo, e
if err != nil {
return nil, err
}
}
// Make a copy of the info for the user.
ret := &info.ContainerInfo{