Added package edgeapps

loop_loop_execution
Paulo Truta 2021-02-16 17:30:01 +01:00
parent ad28e1a505
commit 97182602c4
5 changed files with 63 additions and 16 deletions

5
go.mod
View File

@ -2,14 +2,15 @@ module github.com/edgebox-iot/sysctl
go 1.15
replace github.com/edgebix-iot/sysctl/internal/edgeapps => ./internal/edgeapps
replace github.com/edgebox-iot/sysctl/internal/utils => ./internal/utils
replace github.com/edgebox-iot/sysctl/internal/tasks => ./internal/tasks
replace github.com/edgebix-iot/sysctl/internal/edgeapps => ./internal/edgeapps
require (
github.com/edgebox-iot/sysctl/internal/tasks v0.0.0-00010101000000-000000000000
github.com/edgebox-iot/sysctl/internal/utils v0.0.0-00010101000000-000000000000 // indirect
github.com/go-sql-driver/mysql v1.5.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

View File

@ -5,16 +5,17 @@ import (
"io/ioutil"
"log"
"os"
"gopkg.in/yaml.v2"
)
// EdgeApp : Struct representing an EdgeApp in the system
type EdgeApp struct {
ID string `json:"id"`
Name string `json:"name"`
Status EdgeAppStatus `json:"status"`
InternetAccessible bool `json:"internet_accessible"`
InternetURL string `json:"internet_url"`
NetworkURL string `json:"network_url"`
ID string `json:"id"`
Name string `json:"name"`
Status EdgeAppStatus `json:"status"`
Services []EdgeAppService `json:"services"`
NetworkURL []string `json:"network_url"`
}
// EdgeAppStatus : Struct representing possible EdgeApp statuses (code + description)
@ -23,17 +24,21 @@ type EdgeAppStatus struct {
Description string `json:"description"`
}
// GetEdgeApps : Returns a list of EdgeApp struct filled with information
func GetEdgeApps() []EdgeApp {
// EdgeAppService : Struct representing a single container that can be part of an EdgeApp package
type EdgeAppService struct {
ID string `json:"id"`
Name string `json:"name"`
Isrunning bool `json:"is_running"`
}
var edgeApps []EdgeApp
// GetEdgeApps : Returns a list of EdgeApp struct filled with information
func GetEdgeApps() string { // []EdgeApp {
// var edgeApps []EdgeApp
// Building list of available edgeapps in the system.
configFilename := "edgebox-compose.yml"
// envFilename := "edgebox.env"
// postinstallFilename := "edgebox-postinstall.txt"
edgeAppsPath := "/home/system/components/apps"
var edgeAppsList []string
files, err := ioutil.ReadDir(edgeAppsPath)
if err != nil {
@ -48,7 +53,9 @@ func GetEdgeApps() []EdgeApp {
_, err := os.Stat("/home/system/components/apps/" + f.Name() + "/" + configFilename)
if !os.IsNotExist(err) {
// File exists. Start digging!
edgeAppsList = append(edgeAppsList, f.Name())
// edgeApp := EdgeApp{ID: f.Name(), Status: GetEdgeAppStatus(f.Name())}
// edgeApps = append(edgeApps, edgeApp)
GetEdgeAppServices(f.Name())
}
}
@ -59,6 +66,39 @@ func GetEdgeApps() []EdgeApp {
// executeCommand("docker", cmdargs)
// (...)
return edgeApps
// return edgeApps
return "OK"
}
// GetEdgeAppStatus : Returns a struct representing the current status of the EdgeApp
// func GetEdgeAppStatus(ID string) EdgeAppStatus {
// // Possible states of an EdgeApp:
// // - All services running = EdgeApp running
// // - Some services running = Problem detected, needs restart
// // - No service running = EdgeApp is off
// services := GetEdgeAppServices(ID)
// return status
// }
// GetEdgeAppServices : Returns a
func GetEdgeAppServices(ID string) string {
data, err := ioutil.ReadFile("/home/system/components/apps/" + ID + "/edgebox-compose.yml")
// If this happens it means that no EdgeApp exists for the given ID. This func should not be called in that case.
if err != nil {
log.Fatal(err)
}
// Is application running?
t := make(map[string]interface{})
yaml.Unmarshal([]byte(data), &t)
fmt.Println(t["services"])
return "OK"
}

View File

@ -1,3 +1,5 @@
module github.com/edgebox-iot/sysctl/internal/edgeapps
go 1.15
require gopkg.in/yaml.v2 v2.4.0

View File

@ -1,3 +1,5 @@
module github.com/edgebox-iot/sysctl/internal/tasks
go 1.15
require github.com/go-sql-driver/mysql v1.5.0

View File

@ -8,6 +8,7 @@ import (
"strconv"
"github.com/edgebox-iot/sysctl/internal/diagnostics"
"github.com/edgebox-iot/sysctl/internal/edgeapps"
"github.com/edgebox-iot/sysctl/internal/utils"
_ "github.com/go-sql-driver/mysql" // Mysql Driver
)
@ -191,6 +192,7 @@ func taskSetupTunnel(args taskSetupTunnelArgs) string {
func taskGetEdgeApps() string {
fmt.Println("Executing taskGetEdgeApps")
edgeapps.GetEdgeApps()
// Saving information in the "options" table.
return "OK"