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 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/utils => ./internal/utils
replace github.com/edgebox-iot/sysctl/internal/tasks => ./internal/tasks replace github.com/edgebox-iot/sysctl/internal/tasks => ./internal/tasks
replace github.com/edgebix-iot/sysctl/internal/edgeapps => ./internal/edgeapps
require ( require (
github.com/edgebox-iot/sysctl/internal/tasks v0.0.0-00010101000000-000000000000 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/edgebox-iot/sysctl/internal/utils v0.0.0-00010101000000-000000000000 // indirect
github.com/go-sql-driver/mysql v1.5.0 // 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" "io/ioutil"
"log" "log"
"os" "os"
"gopkg.in/yaml.v2"
) )
// EdgeApp : Struct representing an EdgeApp in the system // EdgeApp : Struct representing an EdgeApp in the system
type EdgeApp struct { type EdgeApp struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Status EdgeAppStatus `json:"status"` Status EdgeAppStatus `json:"status"`
InternetAccessible bool `json:"internet_accessible"` Services []EdgeAppService `json:"services"`
InternetURL string `json:"internet_url"` NetworkURL []string `json:"network_url"`
NetworkURL string `json:"network_url"`
} }
// EdgeAppStatus : Struct representing possible EdgeApp statuses (code + description) // EdgeAppStatus : Struct representing possible EdgeApp statuses (code + description)
@ -23,17 +24,21 @@ type EdgeAppStatus struct {
Description string `json:"description"` Description string `json:"description"`
} }
// GetEdgeApps : Returns a list of EdgeApp struct filled with information // EdgeAppService : Struct representing a single container that can be part of an EdgeApp package
func GetEdgeApps() []EdgeApp { 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. // Building list of available edgeapps in the system.
configFilename := "edgebox-compose.yml" configFilename := "edgebox-compose.yml"
// envFilename := "edgebox.env"
// postinstallFilename := "edgebox-postinstall.txt"
edgeAppsPath := "/home/system/components/apps" edgeAppsPath := "/home/system/components/apps"
var edgeAppsList []string
files, err := ioutil.ReadDir(edgeAppsPath) files, err := ioutil.ReadDir(edgeAppsPath)
if err != nil { if err != nil {
@ -48,7 +53,9 @@ func GetEdgeApps() []EdgeApp {
_, err := os.Stat("/home/system/components/apps/" + f.Name() + "/" + configFilename) _, err := os.Stat("/home/system/components/apps/" + f.Name() + "/" + configFilename)
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
// File exists. Start digging! // 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) // 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 module github.com/edgebox-iot/sysctl/internal/edgeapps
go 1.15 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 module github.com/edgebox-iot/sysctl/internal/tasks
go 1.15 go 1.15
require github.com/go-sql-driver/mysql v1.5.0

View File

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