Author: jpgilaberte Date: Sat Jul 21 16:42:17 2018 New Revision: 1836413 URL: http://svn.apache.org/viewvc?rev=1836413&view=rev Log: Initial commit
Added: labs/turbulence/agent.go labs/turbulence/container.go labs/turbulence/docker_container.go labs/turbulence/mesos_container.go labs/turbulence/stat.go labs/turbulence/turbulence.go labs/turbulence/turbulence_test.go Added: labs/turbulence/agent.go URL: http://svn.apache.org/viewvc/labs/turbulence/agent.go?rev=1836413&view=auto ============================================================================== --- labs/turbulence/agent.go (added) +++ labs/turbulence/agent.go Sat Jul 21 16:42:17 2018 @@ -0,0 +1,35 @@ +package main + + +type agent struct{ + cgroupPaths []string + ppidConatiner []string +} + +type process struct{ + id string + pid string + name string +} + +var agentSingletonInstance *agent + +func NewAgent()(*agent){ + if nil == agentSingletonInstance{ + agentSingletonInstance = new(agent) + } + return agentSingletonInstance +} + +func (a *agent) PopulateCgroupPaths()([]string, error){ + var err error + a.cgroupPaths, err = FindCgroupPaths([]string{cgroupFreezerMesosPath, cgroupFreezerDockerPath}) + return a.cgroupPaths, err +} + +func (a *agent) PopulatePPidContainer(paths []string)([]string, error){ + var err error + a.ppidConatiner, err = GetProcessFromCgroupPaths(paths) + return a.ppidConatiner, err +} + Added: labs/turbulence/container.go URL: http://svn.apache.org/viewvc/labs/turbulence/container.go?rev=1836413&view=auto ============================================================================== --- labs/turbulence/container.go (added) +++ labs/turbulence/container.go Sat Jul 21 16:42:17 2018 @@ -0,0 +1,109 @@ +package main + +import ( + "io/ioutil" + "fmt" + "bufio" + "os" + "github.com/pkg/errors" + "bytes" +) + +type Container interface { + FindCgroupPaths(path string)(cgroupPaths []string, err error) +} + +func FindCgroupPaths(paths []string)(cgroupPaths []string, err error){ + var auxCgroupPaths []string + for _, path := range paths { + auxCgroupPaths, _ = FindCgroupPath(path) + for _, auxCgroupPath := range auxCgroupPaths{ + cgroupPaths = append(cgroupPaths, auxCgroupPath) + } + } + return +} + +func FindCgroupPath(path string)(cgroupPaths []string, err error){ + dir, err := ioutil.ReadDir(path) + if err != nil { + fmt.Printf("ERROR - FindCgroupPaths - root path is not present - %v \n", err) + } + for _, f := range dir { + if f.IsDir(){ + fmt.Printf("INFO - FindCgroupPaths - Add new cgroup path - %v \n", fmt.Sprint(cgroupFreezerMesosPath, f.Name())) + cgroupPaths = append(cgroupPaths, fmt.Sprint(cgroupFreezerMesosPath, f.Name())) + } + } + return +} + +func GetProcessFromCgroupPaths(paths []string)(cgroupPaths []string, err error){ + var auxProcessContainer []string + for _, path := range paths { + auxProcessContainer, _ = GetProcessFromCgroupPath(path) + ppidCOnatiner, _ := PpidOfContainer(auxProcessContainer) + cgroupPaths = append(cgroupPaths, ppidCOnatiner) + } + return +} + +func GetProcessFromCgroupPath(path string)(process []string, err error){ + fmt.Printf("INFO - GetProcessFromCgroupPaths - Path: %v \n", path) + file, err := os.Open(path + "/cgroup.procs") + if err != nil { + fmt.Printf("ERROR - GetProcessFromCgroupPath - %v \n", err) + return + } + defer file.Close() + scanner := bufio.NewScanner(file) + scanner.Split(bufio.ScanLines) + for scanner.Scan() { + err = scanner.Err() + if err == nil { + fmt.Printf("INFO - GetProcessFromCgroupPath - Container Pid: %v \n", scanner.Text()) + process = append(process, scanner.Text()) + } + } + return +} + +func PpidOfContainer(tasksContainer []string)(ppidCOntainer string, err error){ + for _, task := range tasksContainer { + ppid, err := getPPID(task) + if err == nil { + if isPpidContainer(ppid, tasksContainer) { + fmt.Printf("INFO - isPpidContainer - Ppid of container: %v \n", task) + return task, err + } + } + } + fmt.Printf("ERROR - PpidOfContainer- Not find Ppid in container with process: %v \n", tasksContainer) + return "", errors.New("Not find Ppid") +} + +func isPpidContainer(pid string, tasks []string)(bool){ + for _, task := range tasks { + if pid == task { + return false + } + } + return true +} + +func getPPID(task string)(ppid string, err error){ + file, err := os.Open(fmt.Sprintf("/proc/%s/stat", task)) + if err != nil { + fmt.Printf("ERROR - getPPID - %v \n", err) + return ppid, err + } + defer file.Close() + data, err := ioutil.ReadAll(file) + if err != nil { + fmt.Printf("ERROR - getPPID - %v \n", err) + return ppid, err + } + _, err = fmt.Fscan(bytes.NewBuffer(data), &ppid, &ppid, &ppid, &ppid) + fmt.Printf("INFO - getPPID - Ppid of task: %v PPid: %v \n", task, ppid) + return ppid, err +} \ No newline at end of file Added: labs/turbulence/docker_container.go URL: http://svn.apache.org/viewvc/labs/turbulence/docker_container.go?rev=1836413&view=auto ============================================================================== --- labs/turbulence/docker_container.go (added) +++ labs/turbulence/docker_container.go Sat Jul 21 16:42:17 2018 @@ -0,0 +1,10 @@ +package main + +const( + cgroupFreezerDockerPath string = "/sys/fs/cgroup/freezer/docker/" +) + +func FindDockerCgroupPaths()(cgroupPaths []string, err error){ + return FindCgroupPath(cgroupFreezerDockerPath) +} + Added: labs/turbulence/mesos_container.go URL: http://svn.apache.org/viewvc/labs/turbulence/mesos_container.go?rev=1836413&view=auto ============================================================================== --- labs/turbulence/mesos_container.go (added) +++ labs/turbulence/mesos_container.go Sat Jul 21 16:42:17 2018 @@ -0,0 +1,9 @@ +package main + +const( + cgroupFreezerMesosPath string = "/tmp/mesos/" +) + +func FindMesosCgroupPaths()(cgroupPaths []string, err error){ + return FindCgroupPath(cgroupFreezerMesosPath) +} Added: labs/turbulence/stat.go URL: http://svn.apache.org/viewvc/labs/turbulence/stat.go?rev=1836413&view=auto ============================================================================== --- labs/turbulence/stat.go (added) +++ labs/turbulence/stat.go Sat Jul 21 16:42:17 2018 @@ -0,0 +1,7 @@ +package main + +type stat struct { + +} + + Added: labs/turbulence/turbulence.go URL: http://svn.apache.org/viewvc/labs/turbulence/turbulence.go?rev=1836413&view=auto ============================================================================== --- labs/turbulence/turbulence.go (added) +++ labs/turbulence/turbulence.go Sat Jul 21 16:42:17 2018 @@ -0,0 +1,14 @@ +package main + +import "fmt" + +func main(){ + + var agent = NewAgent() + agent.PopulateCgroupPaths() + agent.PopulatePPidContainer(agent.cgroupPaths) + fmt.Printf("--- %v", agent.ppidConatiner) + +} + + Added: labs/turbulence/turbulence_test.go URL: http://svn.apache.org/viewvc/labs/turbulence/turbulence_test.go?rev=1836413&view=auto ============================================================================== --- labs/turbulence/turbulence_test.go (added) +++ labs/turbulence/turbulence_test.go Sat Jul 21 16:42:17 2018 @@ -0,0 +1,12 @@ +package main + +import "testing" + +func TestTurbulence(t *testing.T){ + //ppidOfContainer([]string{"245", "285", "1234", "1233", "asd", "12345234", "1"}) +} + +func BenchmarkTurbulence(b *testing.B){ + //ppidOfContainer([]string{"245", "285", "1234", "1233", "asd", "12345234", "1"}) +} + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@labs.apache.org For additional commands, e-mail: commits-h...@labs.apache.org