Minor refactorings to fix build.
Signed-off-by: Victor Marmol <vmarmol@google.com>
This commit is contained in:
parent
e5636543cc
commit
646ca2ba11
|
@ -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")
|
||||
}
|
50
cgroups.go
50
cgroups.go
|
@ -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"
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue