diff --git a/cgroup_manager.go b/cgroup_manager.go new file mode 100644 index 00000000..1bcb1bc4 --- /dev/null +++ b/cgroup_manager.go @@ -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") +} diff --git a/cgroups.go b/cgroups.go deleted file mode 100644 index 68754b06..00000000 --- a/cgroups.go +++ /dev/null @@ -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" -} diff --git a/linux_container.go b/linux_container.go index f69db34c..0ba92a60 100644 --- a/linux_container.go +++ b/linux_container.go @@ -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 { diff --git a/linux_container_test.go b/linux_container_test.go index 85a01cd3..cd8d33d0 100644 --- a/linux_container_test.go +++ b/linux_container_test.go @@ -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 } diff --git a/linux_factory.go b/linux_factory.go index c7c359db..772c89ef 100644 --- a/linux_factory.go +++ b/linux_factory.go @@ -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,