-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmain.go
More file actions
114 lines (97 loc) · 4.46 KB
/
main.go
File metadata and controls
114 lines (97 loc) · 4.46 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* === This file is part of ALICE O² ===
*
* Copyright 2019 CERN and copyright holders of ALICE O².
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In applying this license CERN does not waive the privileges and
* immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*/
package main
import (
"flag"
"fmt"
"os"
"github.com/AliceO2Group/Control/occ/peanut"
)
func main() {
fs := flag.NewFlagSet("peanut", flag.ExitOnError)
addr := fs.String("addr", "", "OCC gRPC address (host:port); if empty, OCC_CONTROL_PORT env var is used in direct mode")
mode := fs.String("mode", "direct", "control mode: direct (default), fmq, or fmq-step")
fs.Usage = func() {
fmt.Fprint(os.Stderr, `peanut — process execution and control utility for OCC / FairMQ processes
TUI mode (interactive, launched when no command is given):
peanut direct mode via OCC_CONTROL_PORT env var
peanut -addr host:port direct mode (OCC protobuf, one button per transition)
peanut -addr host:port -mode fmq fmq batched mode (drives full FairMQ sequence per transition)
peanut -addr host:port -mode fmq-step fmq single-step mode (one button per raw FairMQ event)
CLI mode (non-interactive, launched when a command is given):
peanut [flags] <command> [args]
TUI Flags:
-addr string gRPC address (host:port); if empty, uses OCC_CONTROL_PORT env var in direct mode
-mode string direct (default), fmq, or fmq-step
CLI Flags:
-addr string gRPC address (default "localhost:47100")
-mode string fmq (default) or direct
-timeout duration unary call timeout (default 30s)
-config string path to YAML/JSON file with arguments to push (inline key=val args take precedence)
CLI Commands:
get-state
Print the current FSM state.
transition <fromState> <toState> [key=val ...]
High-level OCC transition. In fmq mode drives the full multi-step FairMQ sequence:
STANDBY→CONFIGURED runs INIT DEVICE, COMPLETE INIT, BIND, CONNECT, INIT TASK
CONFIGURED→RUNNING runs RUN
RUNNING→CONFIGURED runs STOP
CONFIGURED→STANDBY runs RESET TASK, RESET DEVICE
In direct mode sends a single OCC protobuf Transition RPC.
key=val pairs are forwarded as ConfigEntry arguments.
direct-step <srcState> <event> [key=val ...]
Low-level: send a single raw OCC protobuf Transition RPC regardless of -mode.
Events: CONFIGURE, RESET, START, STOP, RECOVER, EXIT
fmq-step <srcFMQState> <fmqEvent> [key=val ...]
Low-level: send a single raw FairMQ gRPC Transition call regardless of -mode.
FairMQ state/event names that contain spaces must be quoted.
state-stream
Subscribe to StateStream; print updates until interrupted (ctrl-c to stop).
event-stream
Subscribe to EventStream; print events until interrupted (ctrl-c to stop).
Examples:
peanut -addr localhost:47100 get-state
peanut -addr localhost:47100 transition STANDBY CONFIGURED chans.x.0.address=ipc://@foo
peanut -addr localhost:47100 -config args.yaml transition STANDBY CONFIGURED
peanut -addr localhost:47100 fmq-step IDLE "INIT DEVICE" chans.x.0.address=ipc://@foo
peanut -addr localhost:47100 direct-step STANDBY CONFIGURE key=val
peanut -addr localhost:47100 state-stream
peanut -addr localhost:47100 -mode direct transition STANDBY CONFIGURED
`)
}
_ = fs.Parse(os.Args[1:])
if fs.NArg() > 0 {
// CLI mode — pass all original args so RunCLI can re-parse its own flags
if err := peanut.RunCLI(os.Args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "peanut: %v\n", err)
os.Exit(1)
}
return
}
// TUI mode
if err := peanut.Run(peanut.Options{Addr: *addr, Mode: *mode}); err != nil {
fmt.Fprintf(os.Stderr, "peanut: %v\n", err)
os.Exit(1)
}
}