From 1c06d5b88210c79d44848e0db1249f12f3a077f4 Mon Sep 17 00:00:00 2001 From: Akilan Date: Tue, 14 Feb 2023 19:33:22 +0000 Subject: [PATCH 1/5] changed module name --- artwork/.DS_Store | Bin 0 -> 6148 bytes client/GroupTrackContainer.go | 55 +-- client/GroupTrackContainer_test.go | 26 +- client/ServerSpecs.go | 2 +- client/TrackContainers.go | 58 +-- client/TrackContianers_test.go | 18 +- client/clientIPTable/Iptable.go | 4 +- client/container.go | 4 +- cmd/action.go | 14 +- generate/generate.go | 20 +- generate/generate_test.go | 10 +- go.mod | 2 +- main.go | 6 +- p2p/frp/client.go | 2 +- p2p/iptable.go | 2 +- p2p/testingMetrics.go | 2 +- plugin/packageManager.go | 9 +- plugin/plugin.go | 764 ++++++++++++++--------------- plugin/plugin_test.go | 440 ++++++++--------- server/docker/docker.go | 92 ++-- server/rpc.go | 9 +- server/server.go | 10 +- 22 files changed, 771 insertions(+), 778 deletions(-) create mode 100644 artwork/.DS_Store diff --git a/artwork/.DS_Store b/artwork/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..af1b6902af325dcb849451e840057751bba2312c GIT binary patch literal 6148 zcmeHK&x_MQ6n@jKHn9jjDC|WDc&#;CMO?hZ+CA*S%SQB|Qky1pgR_~^q+6jBa@Ie_ ztAC0Aj(%@uR<>IUo#lO?|V87ob1KuauI>MSYyS&a>sHbLWLBs&QUqb4|$83?c8{g=yp{e!37pdW_oZm>G+huz@uqbKXN@7=xs@Y%`eqdY6rXBG+{2EGh! zw=G@(&vb_-X*rPzo|Z#*gq+9oLaJhl2)=<&Cv=1~4e2GYhjgS@guRET%PBGjLZovMiy&>7=Z~x z1sbZbM+{-;=nrgMWU)4A=p^jnL)beDdqNTV?zn!S!%0L2UFj5X3T!H{XPO<}|BrT` z|2Ijl: - - host, _, err := net.SplitHostPort(ContainerInformation.IpAddress) - if err != nil { - return err - } - // IP address of the container - ExecuteIP.IPAddress = host - // Set container ID to ExecutorIP - ExecuteIP.ContainerID = ContainerInformation.Id - // Append IP to list of executor IP - ExecuteIPs = append(ExecuteIPs, &ExecuteIP) - // Run plugin to execute plugin - _, err = RunPlugin(PluginName, ExecuteIPs) - if err != nil { - return err - } - - return nil + // Gets container information based on container ID + ContainerInformation, err := client.GetContainerInformation(ContainerID) + if err != nil { + return err + } + + // Setting Up IP's for which the plugins will be executed + var ExecuteIPs []*ExecuteIP + var ExecuteIP ExecuteIP + // Getting port no of SSH port + for _, port := range ContainerInformation.Container.Ports.PortSet { + if port.PortName == "SSH" { + ExecuteIP.SSHPortNo = fmt.Sprint(port.ExternalPort) + break + } + } + // Handle error if SSH port is not provided + if ExecuteIP.SSHPortNo == "" { + return errors.New("SSH port not found") + } + // Split the port no from ip address since current the IP address + // field is populated as + // : + + host, _, err := net.SplitHostPort(ContainerInformation.IpAddress) + if err != nil { + return err + } + // IP address of the container + ExecuteIP.IPAddress = host + // Set container ID to ExecutorIP + ExecuteIP.ContainerID = ContainerInformation.Id + // Append IP to list of executor IP + ExecuteIPs = append(ExecuteIPs, &ExecuteIP) + // Run plugin to execute plugin + _, err = RunPlugin(PluginName, ExecuteIPs) + if err != nil { + return err + } + + return nil } // CheckRunPlugin Checks if the ID belongs to the group or container // calls the plugin function the appropriate amount of times func CheckRunPlugin(PluginName string, ID string) error { - // Check if the ID belongs to the group or container ID - id, err := client.CheckID(ID) - if err != nil { - return err - } - // When the ID belongs to a group - if id == "group" { - // gets the group information - group, err := client.GetGroup(ID) - if err != nil { - return err - } - // Iterate through each container information in the group - // and run the plugin in each of them - for _, container := range group.TrackContainerList { - // runs plugin for each container - err := RunPluginContainer(PluginName, container.Id) - if err != nil { - return err - } - } - } else { // This means the following ID is a container ID - err := RunPluginContainer(PluginName, ID) - if err != nil { - return err - } - } - - return nil + // Check if the ID belongs to the group or container ID + id, err := client.CheckID(ID) + if err != nil { + return err + } + // When the ID belongs to a group + if id == "group" { + // gets the group information + group, err := client.GetGroup(ID) + if err != nil { + return err + } + // Iterate through each container information in the group + // and run the plugin in each of them + for _, container := range group.TrackContainerList { + // runs plugin for each container + err := RunPluginContainer(PluginName, container.Id) + if err != nil { + return err + } + } + } else { // This means the following ID is a container ID + err := RunPluginContainer(PluginName, ID) + if err != nil { + return err + } + } + + return nil } // CopyToTmpPlugin This function would ensure that we create a copy of the @@ -364,101 +364,101 @@ func CheckRunPlugin(PluginName string, ID string) error { // from there. This due to the reason of automating port allocation // when running plugins func (p *Plugin) CopyToTmpPlugin() error { - // generate rand to UUID this is debug the ansible file if needed - id := uuid.New() - // copies the plugin to the tmp directory - err := copy.Copy(p.path+"/"+p.FolderName, "/tmp/"+id.String()+"_"+p.FolderName) - if err != nil { - return err - } - - // Set the plugin execution to the tmp location - p.path = "/tmp" - p.FolderName = id.String() + "_" + p.FolderName - - return nil + // generate rand to UUID this is debug the ansible file if needed + id := uuid.New() + // copies the plugin to the tmp directory + err := copy.Copy(p.path+"/"+p.FolderName, "/tmp/"+id.String()+"_"+p.FolderName) + if err != nil { + return err + } + + // Set the plugin execution to the tmp location + p.path = "/tmp" + p.FolderName = id.String() + "_" + p.FolderName + + return nil } // AutoSetPorts Automatically maps free ports to site.yml file func (p *Plugin) AutoSetPorts(containerID string) error { - container, err := client.GetContainerInformation(containerID) - if err != nil { - return err - } - // variable that would have a list of ports - // to be allocated to the plugin system - var ports []int - // Counted that increments when a port is taken - PortTaken := 0 - // setting all external ports available in an array - for i, port := range container.Container.Ports.PortSet { - if port.IsUsed == false { - // Ensuring we break outside the loop once the ports - // are set. - if PortTaken >= p.NumOfPorts { - break - } - // Setting the following port flag to true - container.Container.Ports.PortSet[i].IsUsed = true - // Incrementing the variable PortTaken - PortTaken++ - // Maps to internal since - // Inside the machine - // internal port -> (maps) same internal port - // TURN (i.e FRP) based approach (internal port -> maps to different external port) - ports = append(ports, port.InternalPort) - } - } - - // parses the site.yml file in the tmp directory - t, err := template.ParseFiles(p.path + "/" + p.FolderName + "/site.yml") - if err != nil { - return err - } - // opens the output file - f, err := os.Create(p.path + "/" + p.FolderName + "/site.yml") - if err != nil { - return err - } - // sends the ports to the site.yml file to populate them - err = t.Execute(f, ports) - if err != nil { - return err - } - // Once the following is done set port to taken - // n tracked container list - err = container.ModifyContainerInformation() - if err != nil { - return err - } - // Once the following is done set port to taken - // I(Groups) - err = container.ModifyContainerGroups() - if err != nil { - return err - } - - return nil + container, err := client.GetContainerInformation(containerID) + if err != nil { + return err + } + // variable that would have a list of ports + // to be allocated to the plugin system + var ports []int + // Counted that increments when a port is taken + PortTaken := 0 + // setting all external ports available in an array + for i, port := range container.Container.Ports.PortSet { + if port.IsUsed == false { + // Ensuring we break outside the loop once the ports + // are set. + if PortTaken >= p.NumOfPorts { + break + } + // Setting the following port flag to true + container.Container.Ports.PortSet[i].IsUsed = true + // Incrementing the variable PortTaken + PortTaken++ + // Maps to internal since + // Inside the machine + // internal port -> (maps) same internal port + // TURN (i.e FRP) based approach (internal port -> maps to different external port) + ports = append(ports, port.InternalPort) + } + } + + // parses the site.yml file in the tmp directory + t, err := template.ParseFiles(p.path + "/" + p.FolderName + "/site.yml") + if err != nil { + return err + } + // opens the output file + f, err := os.Create(p.path + "/" + p.FolderName + "/site.yml") + if err != nil { + return err + } + // sends the ports to the site.yml file to populate them + err = t.Execute(f, ports) + if err != nil { + return err + } + // Once the following is done set port to taken + // n tracked container list + err = container.ModifyContainerInformation() + if err != nil { + return err + } + // Once the following is done set port to taken + // I(Groups) + err = container.ModifyContainerGroups() + if err != nil { + return err + } + + return nil } // NumPorts Gets the Number the ports the // plugin requires func (p *Plugin) NumPorts() error { - jsonFile, err := os.Open(p.path + "/ports.json") - // if we os.Open returns an error then handle it - if err != nil { - return err - } + jsonFile, err := os.Open(p.path + "/ports.json") + // if we os.Open returns an error then handle it + if err != nil { + return err + } - // defer the closing of our jsonFile so that we can parse it later on - defer jsonFile.Close() + // defer the closing of our jsonFile so that we can parse it later on + defer jsonFile.Close() - // read our opened xmlFile as a byte array. - byteValue, _ := ioutil.ReadAll(jsonFile) + // read our opened xmlFile as a byte array. + byteValue, _ := ioutil.ReadAll(jsonFile) - // we unmarshal our byteArray which contains our - // jsonFile's content into 'users' which we defined above - json.Unmarshal(byteValue, &p) + // we unmarshal our byteArray which contains our + // jsonFile's content into 'users' which we defined above + json.Unmarshal(byteValue, &p) - return nil + return nil } diff --git a/plugin/plugin_test.go b/plugin/plugin_test.go index 01c29ff..a95073d 100644 --- a/plugin/plugin_test.go +++ b/plugin/plugin_test.go @@ -1,257 +1,257 @@ package plugin import ( - "fmt" - "git.sr.ht/~akilan1999/p2p-rendering-computation/client" - "git.sr.ht/~akilan1999/p2p-rendering-computation/config" - "git.sr.ht/~akilan1999/p2p-rendering-computation/server/docker" - "net" - "strconv" - "testing" + "fmt" + "github.com/Akilan1999/p2p-rendering-computation/client" + "github.com/Akilan1999/p2p-rendering-computation/config" + "github.com/Akilan1999/p2p-rendering-computation/server/docker" + "net" + "strconv" + "testing" ) // Test if the dummy plugin added is detected func TestDetectPlugins(t *testing.T) { - _, err := DetectPlugins() - if err != nil { - t.Fail() - } + _, err := DetectPlugins() + if err != nil { + t.Fail() + } } // Test ensures that the ansible are executed inside local containers func TestRunPlugin(t *testing.T) { - var testips []*ExecuteIP - var testip1, testip2 ExecuteIP - - // Create docker container and get SSH port - container1, err := docker.BuildRunContainer(0, "false", "") - if err != nil { - fmt.Println(err) - t.Fail() - } - - //Test IP 1 configuration - testip1.IPAddress = "0.0.0.0" - testip1.SSHPortNo = strconv.Itoa(container1.Ports.PortSet[0].ExternalPort) - - // Create docker container and get SSH port - container2, err := docker.BuildRunContainer(0, "false", "") - if err != nil { - fmt.Println(err) - t.Fail() - } - //Test IP 2 configuration - testip2.IPAddress = "0.0.0.0" - testip2.SSHPortNo = strconv.Itoa(container2.Ports.PortSet[0].ExternalPort) - - testips = append(testips, &testip1) - testips = append(testips, &testip2) - - _, err = RunPlugin("TestAnsible", testips) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Removing container1 after Ansible is executed - err = docker.StopAndRemoveContainer(container1.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - err = docker.StopAndRemoveContainer(container2.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } + var testips []*ExecuteIP + var testip1, testip2 ExecuteIP + + // Create docker container and get SSH port + container1, err := docker.BuildRunContainer(0, "false", "") + if err != nil { + fmt.Println(err) + t.Fail() + } + + //Test IP 1 configuration + testip1.IPAddress = "0.0.0.0" + testip1.SSHPortNo = strconv.Itoa(container1.Ports.PortSet[0].ExternalPort) + + // Create docker container and get SSH port + container2, err := docker.BuildRunContainer(0, "false", "") + if err != nil { + fmt.Println(err) + t.Fail() + } + //Test IP 2 configuration + testip2.IPAddress = "0.0.0.0" + testip2.SSHPortNo = strconv.Itoa(container2.Ports.PortSet[0].ExternalPort) + + testips = append(testips, &testip1) + testips = append(testips, &testip2) + + _, err = RunPlugin("TestAnsible", testips) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Removing container1 after Ansible is executed + err = docker.StopAndRemoveContainer(container1.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + err = docker.StopAndRemoveContainer(container2.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } } // Test to ensure that the ansible host file is modified to // the appropriate IP func TestExecuteIP_ModifyHost(t *testing.T) { - var plugin Plugin - var testip ExecuteIP - - // Get plugin path from config file - Config, err := config.ConfigInit() - if err != nil { - fmt.Println(err) - t.Fail() - } - //Set plugin name - plugin.FolderName = "TestAnsible" - plugin.path = Config.PluginPath - - //Test IP 1 configuration - testip.IPAddress = "0.0.0.0" - testip.SSHPortNo = "41289" - - err = testip.ModifyHost(&plugin) - if err != nil { - fmt.Println(err) - t.Fail() - } + var plugin Plugin + var testip ExecuteIP + + // Get plugin path from config file + Config, err := config.ConfigInit() + if err != nil { + fmt.Println(err) + t.Fail() + } + //Set plugin name + plugin.FolderName = "TestAnsible" + plugin.path = Config.PluginPath + + //Test IP 1 configuration + testip.IPAddress = "0.0.0.0" + testip.SSHPortNo = "41289" + + err = testip.ModifyHost(&plugin) + if err != nil { + fmt.Println(err) + t.Fail() + } } // Test to ensure the cli function runs as intended and executes // the test ansible script func TestRunPluginContainer(t *testing.T) { - // Create docker container and get SSH port - container1, err := docker.BuildRunContainer(0, "false", "") - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Ensuring created container is the added to the tracked list - err = client.AddTrackContainer(container1, "0.0.0.0") - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Running test Ansible script - err = RunPluginContainer("TestAnsible", container1.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Removes container information from the tracker IP addresses - err = client.RemoveTrackedContainer(container1.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Removing container1 after Ansible is executed - err = docker.StopAndRemoveContainer(container1.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } + // Create docker container and get SSH port + container1, err := docker.BuildRunContainer(0, "false", "") + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Ensuring created container is the added to the tracked list + err = client.AddTrackContainer(container1, "0.0.0.0") + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Running test Ansible script + err = RunPluginContainer("TestAnsible", container1.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Removes container information from the tracker IP addresses + err = client.RemoveTrackedContainer(container1.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Removing container1 after Ansible is executed + err = docker.StopAndRemoveContainer(container1.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } } // Testing the function can plugin can run with // group ID and container ID func TestCheckRunPlugin(t *testing.T) { - // Create docker container and get SSH port - container1, err := docker.BuildRunContainer(0, "false", "") - if err != nil { - fmt.Println(err) - t.Fail() - } - // Create docker container and get SSH port - container2, err := docker.BuildRunContainer(0, "false", "") - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Ensuring created container1 is the added to the tracked list - err = client.AddTrackContainer(container1, "0.0.0.0") - if err != nil { - fmt.Println(err) - t.Fail() - } - // Ensuring created container2 is the added to the tracked list - err = client.AddTrackContainer(container2, "0.0.0.0") - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Create group to add created containers - group, err := client.CreateGroup() - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Add container 1 to the group - _, err = client.AddContainerToGroup(container1.ID, group.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Add container 2 to the group - _, err = client.AddContainerToGroup(container2.ID, group.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // -------------------------- Main test cases ------------------------------- - - // Checking function against container ID - err = CheckRunPlugin("TestAnsible", container1.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Checking function against group ID - err = CheckRunPlugin("TestAnsible", group.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // ---------------------------------------------------------------------------- - - // Remove created group - err = client.RemoveGroup(group.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Removes container1 information from the tracker IP addresses - err = client.RemoveTrackedContainer(container1.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Removing container1 after Ansible is executed - err = docker.StopAndRemoveContainer(container1.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Removes container2 information from the tracker IP addresses - err = client.RemoveTrackedContainer(container2.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } - - // Removing container2 after Ansible is executed - err = docker.StopAndRemoveContainer(container2.ID) - if err != nil { - fmt.Println(err) - t.Fail() - } + // Create docker container and get SSH port + container1, err := docker.BuildRunContainer(0, "false", "") + if err != nil { + fmt.Println(err) + t.Fail() + } + // Create docker container and get SSH port + container2, err := docker.BuildRunContainer(0, "false", "") + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Ensuring created container1 is the added to the tracked list + err = client.AddTrackContainer(container1, "0.0.0.0") + if err != nil { + fmt.Println(err) + t.Fail() + } + // Ensuring created container2 is the added to the tracked list + err = client.AddTrackContainer(container2, "0.0.0.0") + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Create group to add created containers + group, err := client.CreateGroup() + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Add container 1 to the group + _, err = client.AddContainerToGroup(container1.ID, group.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Add container 2 to the group + _, err = client.AddContainerToGroup(container2.ID, group.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // -------------------------- Main test cases ------------------------------- + + // Checking function against container ID + err = CheckRunPlugin("TestAnsible", container1.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Checking function against group ID + err = CheckRunPlugin("TestAnsible", group.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // ---------------------------------------------------------------------------- + + // Remove created group + err = client.RemoveGroup(group.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Removes container1 information from the tracker IP addresses + err = client.RemoveTrackedContainer(container1.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Removing container1 after Ansible is executed + err = docker.StopAndRemoveContainer(container1.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Removes container2 information from the tracker IP addresses + err = client.RemoveTrackedContainer(container2.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } + + // Removing container2 after Ansible is executed + err = docker.StopAndRemoveContainer(container2.ID) + if err != nil { + fmt.Println(err) + t.Fail() + } } func TestDownloadPlugin(t *testing.T) { - err := DownloadPlugin("https://github.com/Akilan1999/laplace/") - if err != nil { + err := DownloadPlugin("https://github.com/Akilan1999/laplace/") + if err != nil { - } + } } // Simple test case implemented to the test if // the port no can be extracted from the IP address. func TestParseIP(t *testing.T) { - host, port, err := net.SplitHostPort("12.34.23.13:5432") - if err != nil { - fmt.Printf("Error: %v\n", err) - } else { - fmt.Printf("Host: %s\nPort: %s\n", host, port) - } + host, port, err := net.SplitHostPort("12.34.23.13:5432") + if err != nil { + fmt.Printf("Error: %v\n", err) + } else { + fmt.Printf("Host: %s\nPort: %s\n", host, port) + } } diff --git a/server/docker/docker.go b/server/docker/docker.go index e101e15..a60def8 100644 --- a/server/docker/docker.go +++ b/server/docker/docker.go @@ -7,7 +7,7 @@ import ( "encoding/json" "errors" "fmt" - "git.sr.ht/~akilan1999/p2p-rendering-computation/config" + "github.com/Akilan1999/p2p-rendering-computation/config" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" @@ -22,21 +22,21 @@ import ( ) type DockerVM struct { - SSHUsername string `json:"SSHUsername"` - SSHPassword string `json:"SSHPassword"` - ID string `json:"ID"` - TagName string `json:"TagName"` - ImagePath string `json:"ImagePath"` - Ports Ports `json:"Ports"` - GPU string `json:"GPU"` + SSHUsername string `json:"SSHUsername"` + SSHPassword string `json:"SSHPassword"` + ID string `json:"ID"` + TagName string `json:"TagName"` + ImagePath string `json:"ImagePath"` + Ports Ports `json:"Ports"` + GPU string `json:"GPU"` } type DockerContainers struct { - DockerContainer []DockerContainer `json:"DockerContainer"` + DockerContainer []DockerContainer `json:"DockerContainer"` } type DockerContainer struct { - ContainerName string `json:"DockerContainerName"` + ContainerName string `json:"DockerContainerName"` ContainerDescription string `json:"ContainerDescription"` } @@ -44,11 +44,11 @@ type Ports struct { PortSet []Port `json:"Port"` } type Port struct { - PortName string `json:"PortName"` - InternalPort int `json:"InternalPort"` - Type string `json:"Type"` - ExternalPort int `json:"ExternalPort"` - IsUsed bool `json:"IsUsed"` + PortName string `json:"PortName"` + InternalPort int `json:"InternalPort"` + Type string `json:"Type"` + ExternalPort int `json:"ExternalPort"` + IsUsed bool `json:"IsUsed"` Description string `json:"Description"` } @@ -65,7 +65,7 @@ var dockerRegistryUserID = "" // BuildRunContainer Function is incharge to invoke building and running contianer and also allocating external // ports -func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerVM,error) { +func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerVM, error) { //Docker Struct Variable var RespDocker *DockerVM = new(DockerVM) @@ -86,7 +86,7 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV // Get Path from config config, err := config.ConfigInit() if err != nil { - return nil,err + return nil, err } RespDocker.ImagePath = config.DefaultDockerFile @@ -95,7 +95,7 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV if ContainerName != "" && ContainerName != "docker-ubuntu-sshd" { Containers, err := ViewAllContainers() if err != nil { - return nil,err + return nil, err } for _, dockerContainer := range Containers.DockerContainer { @@ -106,7 +106,7 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV } } if RespDocker.ImagePath == config.DefaultDockerFile { - return nil, errors.New("Container " + ContainerName + " does not exist in the server") + return nil, errors.New("Container " + ContainerName + " does not exist in the server") } } @@ -121,7 +121,7 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV // Creates number of ports OpenPorts, err := freeport.GetFreePorts(count) if err != nil { - return nil,err + return nil, err } // Allocate external ports to ports available in the ports.json file for i := range PortsInformation.PortSet { @@ -136,8 +136,8 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV var TempPort Port TempPort.PortName = "AutoGen Port" TempPort.Type = "tcp" - TempPort.InternalPort = OpenPorts[portFileLength + i] - TempPort.ExternalPort = OpenPorts[portFileLength + i] + TempPort.InternalPort = OpenPorts[portFileLength+i] + TempPort.ExternalPort = OpenPorts[portFileLength+i] TempPort.Description = "Auto generated TCP port" TempPort.IsUsed = false //Append temp port to port information @@ -149,29 +149,28 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV // Gets docker information from env variables cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) if err != nil { - return nil,err + return nil, err } // Builds docker image err = RespDocker.imageBuild(cli) if err != nil { - return nil,err + return nil, err } // Runs docker contianer err = RespDocker.runContainer(cli) if err != nil { - return nil,err + return nil, err } - - return RespDocker,nil + return RespDocker, nil } -//Builds docker image (TODO: relative path for Dockerfile deploy) -func (d *DockerVM)imageBuild(dockerClient *client.Client) error { +// Builds docker image (TODO: relative path for Dockerfile deploy) +func (d *DockerVM) imageBuild(dockerClient *client.Client) error { ctx, _ := context.WithTimeout(context.Background(), time.Second*2000) //defer cancel() @@ -203,16 +202,15 @@ func (d *DockerVM)imageBuild(dockerClient *client.Client) error { // Starts container and assigns port numbers // Sample Docker run Command // docker run -d=true --name=Test123 --restart=always --gpus all -//-p 3443:6901 -p 3453:22 -p 3434:3434 -p 3245:3245 -v=/opt/data:/data -//p2p-ubuntu /start > /dev/null -func (d *DockerVM)runContainer(dockerClient *client.Client) error{ +// -p 3443:6901 -p 3453:22 -p 3434:3434 -p 3245:3245 -v=/opt/data:/data +// p2p-ubuntu /start > /dev/null +func (d *DockerVM) runContainer(dockerClient *client.Client) error { ctx, _ := context.WithTimeout(context.Background(), time.Second*2000) - // The first mode runs using the Docker Api. As the API supports using // CPU and uses a shell script for GPU call because till this point of // implementation docker api does not support the flag "--gpu all" - if d.GPU != "true" { + if d.GPU != "true" { //Exposed ports for docker config file var ExposedPort nat.PortSet @@ -239,7 +237,7 @@ func (d *DockerVM)runContainer(dockerClient *client.Client) error{ for i := range d.Ports.PortSet { // Parameters "tcp or udp", external port - Port, err := nat.NewPort(d.Ports.PortSet[i].Type,fmt.Sprint(d.Ports.PortSet[i].InternalPort)) + Port, err := nat.NewPort(d.Ports.PortSet[i].Type, fmt.Sprint(d.Ports.PortSet[i].InternalPort)) if err != nil { return err } @@ -249,7 +247,7 @@ func (d *DockerVM)runContainer(dockerClient *client.Client) error{ PortForwarding[Port] = []nat.PortBinding{ { - HostIP: "0.0.0.0", + HostIP: "0.0.0.0", HostPort: fmt.Sprint(d.Ports.PortSet[i].ExternalPort), }, } @@ -286,11 +284,11 @@ func (d *DockerVM)runContainer(dockerClient *client.Client) error{ d.ID = id var cmd bytes.Buffer - cmd.WriteString("docker run -d=true --name="+ id +" --restart=always --gpus all ") + cmd.WriteString("docker run -d=true --name=" + id + " --restart=always --gpus all ") for i := range d.Ports.PortSet { cmd.WriteString("-p " + fmt.Sprint(d.Ports.PortSet[i].ExternalPort) + ":" + fmt.Sprint(d.Ports.PortSet[i].InternalPort) + " ") } - cmd.WriteString("-v=/opt/data:/data "+ d.TagName +" /start > /dev/null") + cmd.WriteString("-v=/opt/data:/data " + d.TagName + " /start > /dev/null") //"-v=/opt/data:/data p2p-ubuntu /start > /dev/null" cmdStr := cmd.String() _, err := exec.Command("/bin/sh", "-c", cmdStr).Output() @@ -301,7 +299,7 @@ func (d *DockerVM)runContainer(dockerClient *client.Client) error{ return nil } -// StopAndRemoveContainer +// StopAndRemoveContainer // Stop and remove a container // Reference (https://gist.github.com/frikky/e2efcea6c733ea8d8d015b7fe8a91bf6) func StopAndRemoveContainer(containername string) error { @@ -330,11 +328,11 @@ func StopAndRemoveContainer(containername string) error { } // ViewAllContainers returns all containers runnable and which can be built -func ViewAllContainers() (*DockerContainers, error){ +func ViewAllContainers() (*DockerContainers, error) { // Traverse the deploy path as per given in the config file config, err := config.ConfigInit() if err != nil { - return nil,err + return nil, err } folders, err := ioutil.ReadDir(config.DockerContainers) @@ -348,11 +346,11 @@ func ViewAllContainers() (*DockerContainers, error){ for _, f := range folders { if f.IsDir() { //Declare variable DockerContainer of type struct - var Container DockerContainer + var Container DockerContainer - // Setting container name to deploy name - Container.ContainerName = f.Name() - // Getting Description from file description.txt + // Setting container name to deploy name + Container.ContainerName = f.Name() + // Getting Description from file description.txt Description, err := ioutil.ReadFile(config.DockerContainers + "/" + Container.ContainerName + "/description.txt") // if we os.Open returns an error then handle it if err != nil { @@ -366,7 +364,7 @@ func ViewAllContainers() (*DockerContainers, error){ } } - return Containers,nil + return Containers, nil } func print(rd io.Reader) error { @@ -403,4 +401,4 @@ func OpenPortsFile(filename string) (*Ports, error) { } return c, nil -} \ No newline at end of file +} diff --git a/server/rpc.go b/server/rpc.go index cdd21f4..7619a13 100644 --- a/server/rpc.go +++ b/server/rpc.go @@ -2,7 +2,7 @@ package server import ( "fmt" - "git.sr.ht/~akilan1999/p2p-rendering-computation/server/docker" + "github.com/Akilan1999/p2p-rendering-computation/server/docker" "net" "net/rpc" ) @@ -18,8 +18,8 @@ type Docker struct { } // Starts container using RPC calls -func (l *Listener) StartContainer( reply *Docker) error { - vm, err := docker.BuildRunContainer(3,"false","") +func (l *Listener) StartContainer(reply *Docker) error { + vm, err := docker.BuildRunContainer(3, "false", "") if err != nil { return err } @@ -28,8 +28,6 @@ func (l *Listener) StartContainer( reply *Docker) error { return nil } - - func Rpc() { rpcServer, err := net.ResolveTCPAddr("tcp", "0.0.0.0:"+port) if err != nil { @@ -43,4 +41,3 @@ func Rpc() { rpc.Register(listener) rpc.Accept(inbound) } - diff --git a/server/server.go b/server/server.go index edced7b..b046765 100644 --- a/server/server.go +++ b/server/server.go @@ -3,11 +3,11 @@ package server import ( "encoding/json" "fmt" - "git.sr.ht/~akilan1999/p2p-rendering-computation/client/clientIPTable" - "git.sr.ht/~akilan1999/p2p-rendering-computation/config" - "git.sr.ht/~akilan1999/p2p-rendering-computation/p2p" - "git.sr.ht/~akilan1999/p2p-rendering-computation/p2p/frp" - "git.sr.ht/~akilan1999/p2p-rendering-computation/server/docker" + "github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable" + "github.com/Akilan1999/p2p-rendering-computation/config" + "github.com/Akilan1999/p2p-rendering-computation/p2p" + "github.com/Akilan1999/p2p-rendering-computation/p2p/frp" + "github.com/Akilan1999/p2p-rendering-computation/server/docker" "github.com/gin-gonic/gin" "io/ioutil" "net/http" From c7be50d3b78bfc4de230c01376bc612bcca33e56 Mon Sep 17 00:00:00 2001 From: Akilan Date: Tue, 14 Feb 2023 19:34:30 +0000 Subject: [PATCH 2/5] fixed untracked files --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 3 +++ artwork/.DS_Store | Bin 6148 -> 0 bytes artwork/p2prc-logos/.DS_Store | Bin 6148 -> 0 bytes client/trackcontainers/.gitkeep | 0 generate/Test/.gitkeep | 0 p2p/iptable/.gitkeep | 0 7 files changed, 3 insertions(+) delete mode 100644 .DS_Store delete mode 100644 artwork/.DS_Store delete mode 100644 artwork/p2prc-logos/.DS_Store delete mode 100644 client/trackcontainers/.gitkeep delete mode 100644 generate/Test/.gitkeep delete mode 100644 p2p/iptable/.gitkeep diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 987eb7eacc19e9e205575d2c0c29c58a0428c6b2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyKVwO473RnNNFf3_ZRqs6(V224$K60*xi_+}fU9 z-4y4ui0J&do{3CEWDGZyA6xondGnqPGGeHHMk_nntoN(tv+Y&i4j6YNAK)G2Th91x zgCnm~r{!+jwA(LaEK8#TRDcRl0V+TR?p7dM==k++CJ9u43Ou_4_I)UD!Sprxr0IZ2!AR;ggDln*;BZdYY@sf2lu?q~ksNalp@@CBmMg4ZfiIUo#lO?|V87ob1KuauI>MSYyS&a>sHbLWLBs&QUqb4|$83?c8{g=yp{e!37pdW_oZm>G+huz@uqbKXN@7=xs@Y%`eqdY6rXBG+{2EGh! zw=G@(&vb_-X*rPzo|Z#*gq+9oLaJhl2)=<&Cv=1~4e2GYhjgS@guRET%PBGjLZovMiy&>7=Z~x z1sbZbM+{-;=nrgMWU)4A=p^jnL)beDdqNTV?zn!S!%0L2UFj5X3T!H{XPO<}|BrT` z|2IjlH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Tue, 14 Feb 2023 19:35:57 +0000 Subject: [PATCH 3/5] fixed untracked files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 823d825..b594f45 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ dist/ #MACOS .idea file .DS_Store +!.gitKeep From 888ad8acb73e0795c35c11533e4b3eb8c7c26da8 Mon Sep 17 00:00:00 2001 From: Akilan Date: Tue, 14 Feb 2023 19:40:53 +0000 Subject: [PATCH 4/5] fixed untracked files --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b594f45..4bda950 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,4 @@ dist/ #MACOS .idea file .DS_Store -!.gitKeep +!.gitkeep From d2d1b5bc9fe718b48a28f66b2bdfb710273593a3 Mon Sep 17 00:00:00 2001 From: Akilan Date: Tue, 14 Feb 2023 19:44:24 +0000 Subject: [PATCH 5/5] fixed untracked files --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4bda950..b1b6576 100644 --- a/.gitignore +++ b/.gitignore @@ -11,17 +11,23 @@ config.json #ignore generated iptables p2p/iptable/ +!p2p/iptable/.gitkeep #ignore plugins added plugin/deploy/ +!plugin/deploy/.gitkeep #ignore track container file client/trackcontainers/ +!client/trackcontainers/.gitkeep # Test generated files generate/p2prctest +!generate/p2prctest/.gitkeep generate/Test +!generate/Test/.gitkeep + #ignore windows exe files *.exe dist/ #MACOS .idea file .DS_Store -!.gitkeep +.gitkeep