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

View File

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