-
Notifications
You must be signed in to change notification settings - Fork 17
/
apps_states.go
77 lines (71 loc) · 1.95 KB
/
apps_states.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package devices
import (
"fmt"
"strings"
"github.com/foundriesio/fioctl/client"
"github.com/foundriesio/fioctl/subcommands"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
asListLimit int
)
func init() {
appsStatesCmd := &cobra.Command{
Use: "apps-states <name>",
Short: "List states of Apps reported by a device",
Run: doListStates,
Args: cobra.ExactArgs(1),
}
cmd.AddCommand(appsStatesCmd)
appsStatesCmd.Flags().IntVarP(&asListLimit, "limit", "n", 1, "Limit the number of Apps states to display.")
}
func doListStates(cmd *cobra.Command, args []string) {
factory := viper.GetString("factory")
states, err := api.DeviceGetAppsStates(factory, args[0])
subcommands.DieNotNil(err)
printAppsState := func(appsState map[string]client.AppState, stateFilter string, filterIn bool) {
for name, state := range appsState {
if len(stateFilter) > 0 {
if filterIn && state.State != stateFilter {
continue
}
if !filterIn && state.State == stateFilter {
continue
}
}
if len(state.Uri) > 0 {
fmt.Printf("\t%s\t%s\n", name, state.Uri)
} else {
fmt.Printf("\t%s\n", name)
}
for _, srv := range state.Services {
fmt.Printf("\t\t%s:\n", srv.Name)
fmt.Printf("\t\t\tURI:\t%s\n", srv.ImageUri)
fmt.Printf("\t\t\tHash:\t%s\n", srv.Hash)
fmt.Printf("\t\t\tHealth:\t%s\n", srv.Health)
fmt.Printf("\t\t\tState:\t%s\n", srv.State)
fmt.Printf("\t\t\tStatus:\t%s\n", srv.Status)
if len(srv.Logs) > 0 {
fmt.Println("\t\t\tLogs:")
for _, line := range strings.Split(srv.Logs, "\n") {
fmt.Printf("\t\t\t | %s\n", line)
}
}
}
fmt.Println()
}
}
for indx, s := range states.States {
if indx >= asListLimit {
break
}
fmt.Printf("Time:\t%s\n", s.DeviceTime)
fmt.Printf("Hash:\t%s\n", s.Ostree)
fmt.Println("Unhealthy Apps:")
printAppsState(s.Apps, "healthy", false)
fmt.Println("Healthy Apps:")
printAppsState(s.Apps, "healthy", true)
fmt.Println()
}
}