/
operator_raft_logs.go
77 lines (59 loc) · 1.61 KB
/
operator_raft_logs.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 command
import (
"encoding/json"
"fmt"
"os"
"strings"
"github.com/hashicorp/nomad/helper/raftutil"
"github.com/posener/complete"
)
type OperatorRaftLogsCommand struct {
Meta
}
func (c *OperatorRaftLogsCommand) Help() string {
helpText := `
Usage: nomad operator raft _logs <path to nomad data dir>
Display the log entries persisted in data dir in json form.
This is a low-level debugging tool and not subject to Nomad's usual backward
compatibility guarantees.
If ACLs are enabled, this command requires a management token.
`
return strings.TrimSpace(helpText)
}
func (c *OperatorRaftLogsCommand) AutocompleteFlags() complete.Flags {
return complete.Flags{}
}
func (c *OperatorRaftLogsCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *OperatorRaftLogsCommand) Synopsis() string {
return "Display raft log content"
}
func (c *OperatorRaftLogsCommand) Name() string { return "operator raft _info" }
func (c *OperatorRaftLogsCommand) Run(args []string) int {
if len(args) != 1 {
c.Ui.Error("This command takes one argument: <path>")
c.Ui.Error(commandErrorText(c))
return 1
}
raftPath, err := raftutil.FindRaftFile(args[0])
if err != nil {
c.Ui.Error(err.Error())
return 1
}
logs, warnings, err := raftutil.LogEntries(raftPath)
if err != nil {
c.Ui.Error(err.Error())
return 1
}
for _, warning := range warnings {
c.Ui.Error(warning.Error())
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
if err := enc.Encode(logs); err != nil {
c.Ui.Error(fmt.Sprintf("failed to encode output: %v", err))
return 1
}
return 0
}