Minor refactorings to fix build.

Signed-off-by: Victor Marmol <vmarmol@google.com>
This commit is contained in:
Victor Marmol 2014-12-05 17:02:49 -08:00
parent e5636543cc
commit 646ca2ba11
5 changed files with 36 additions and 56 deletions

30
cgroup_manager.go Normal file
View File

@ -0,0 +1,30 @@
package libcontainer
import (
"github.com/docker/libcontainer/cgroups"
)
// TODO(vmarmol): Move this to cgroups and rename to Manager.
type CgroupManager interface {
GetPids() ([]int, error)
GetStats() (*cgroups.Stats, error)
}
func NewCgroupManager() CgroupManager {
return &fsManager{}
}
type fsManager struct {
}
func (m *fsManager) GetPids() ([]int, error) {
// TODO(vmarmol): Implement
//return fs.GetPids(config)
panic("not implemented")
}
func (m *fsManager) GetStats() (*cgroups.Stats, error) {
// TODO(vmarmol): Implement
//return fs.GetStats(config)
panic("not implemented")
}

View File

@ -1,50 +0,0 @@
package libcontainer
import (
"github.com/docker/libcontainer/cgroups"
"github.com/docker/libcontainer/cgroups/fs"
"github.com/docker/libcontainer/cgroups/systemd"
)
type CgroupManager interface {
String() string
GetPids(*cgroups.Cgroup) ([]int, error)
GetStats(*cgroups.Cgroup) (*cgroups.Stats, error)
}
func newCgroupsManager() CgroupManager {
if systemd.UseSystemd() {
return &systemdCgroupManager{}
}
return &fsCgroupsManager{}
}
type systemdCgroupManager struct {
}
func (m *systemdCgroupManager) GetPids(config *cgroups.Cgroup) ([]int, error) {
return systemd.GetPids(config)
}
func (m *systemdCgroupManager) GetStats(config *cgroups.Cgroup) (*cgroups.Stats, error) {
return systemd.GetStats(config)
}
func (m *systemdCgroupManager) String() string {
return "systemd"
}
type fsCgroupsManager struct {
}
func (m *fsCgroupsManager) GetPids(config *cgroups.Cgroup) ([]int, error) {
return fs.GetPids(config)
}
func (m *fsCgroupsManager) GetStats(config *cgroups.Cgroup) (*cgroups.Stats, error) {
return fs.GetStats(config)
}
func (m *fsCgroupsManager) String() string {
return "fs"
}

View File

@ -3,8 +3,8 @@
package libcontainer
import (
"github.com/Sirupsen/logrus"
"github.com/docker/libcontainer/network"
"github.com/golang/glog"
)
type linuxContainer struct {
@ -29,7 +29,7 @@ func (c *linuxContainer) RunState() (RunState, error) {
func (c *linuxContainer) Processes() ([]int, error) {
glog.Info("fetch container processes")
pids, err := c.cgroupManager.GetPids(c.config.Cgroups)
pids, err := c.cgroupManager.GetPids()
if err != nil {
return nil, newGenericError(err, SystemError)
}
@ -43,7 +43,7 @@ func (c *linuxContainer) Stats() (*ContainerStats, error) {
stats = &ContainerStats{}
)
if stats.CgroupStats, err = c.cgroupManager.GetStats(c.config.Cgroups); err != nil {
if stats.CgroupStats, err = c.cgroupManager.GetStats(); err != nil {
return stats, newGenericError(err, SystemError)
}
if stats.NetworkStats, err = network.GetStats(&c.state.NetworkState); err != nil {

View File

@ -13,11 +13,11 @@ type mockCgroupManager struct {
stats *cgroups.Stats
}
func (m *mockCgroupManager) GetPids(config *cgroups.Cgroup) ([]int, error) {
func (m *mockCgroupManager) GetPids() ([]int, error) {
return m.pids, nil
}
func (m *mockCgroupManager) GetStats(config *cgroups.Cgroup) (*cgroups.Stats, error) {
func (m *mockCgroupManager) GetStats() (*cgroups.Stats, error) {
return m.stats, nil
}

View File

@ -73,7 +73,7 @@ func (l *linuxFactory) Load(id string) (Container, error) {
return nil, err
}
cgroupManager := newCgroupsManager()
cgroupManager := NewCgroupManager()
glog.Infof("using %s as cgroup manager", cgroupManager)
return &linuxContainer{
id: id,