The operator read every step of main.417 as passed and took it for delivered while it had failed on one step and no want was written: the page listed a pipeline's steps flat, with no tier, no stage and no delivery. One pipeline now shows a header (outcome, first failure's why, how many movers run their build on every node they are placed on), then a block per tier with a row per mover, a cell per stage (the worst outcome over its artifacts, waited, ran and why on hover) and a cell per node its module is placed on (no want written, wanted, applying, running the pipeline's build, held with why), in the web page and the terminal view. The page reloads on the runner's events and on the wants', haves' and assignments' changes the view already hears. Builds: design 47 H2 H-A-531, H-A-531 addendum (hq 7dc6592b, f870d24b)
202 lines
6.7 KiB
Go
202 lines
6.7 KiB
Go
// Command mesh-delivery-cli is the operator's command for the delivery view (novox/hq ADR 0429 §3). It asks the
|
|
// view's local socket for the rows and prints them; it holds no credential. `answer <ask key> <option> [words]` asks the view
|
|
// to write the operator's answer to an ask that needs no proof of who answered (the view refuses the merge's Approve). `holds`
|
|
// lists every fingerprint the assigner holds with its node, cause and answer; `hold-release <module> <fingerprint> [words]` and
|
|
// `hold-keep <module> <fingerprint> [words]` answer its hold ask, again when the operator changes their mind (issue 1906).
|
|
// `pipelines [branch]` and `pipeline <pipeline> [mover]` are the pipelines page (design 47 H2 H-A-467): a branch's newest
|
|
// pipelines, one pipeline's mover rows or one mover's steps; with -follow printed again at each change the runner's events say.
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
"text/tabwriter"
|
|
"time"
|
|
|
|
"mesh-delivery-view/internal/view"
|
|
)
|
|
|
|
const defaultSocket = "/var/lib/mesh-delivery-view-cli/cli.sock"
|
|
|
|
func main() {
|
|
socket := os.Getenv("MESH_DELIVERY_SOCKET")
|
|
if socket == "" {
|
|
socket = defaultSocket
|
|
}
|
|
os.Exit(run(os.Args[1:], socket, os.Stdout, os.Stderr))
|
|
}
|
|
|
|
func run(args []string, socket string, out, errOut io.Writer) int {
|
|
fs := flag.NewFlagSet("mesh-delivery-cli", flag.ContinueOnError)
|
|
fs.SetOutput(errOut)
|
|
asJSON := fs.Bool("json", false, "print the rows as JSON")
|
|
follow := fs.Bool("follow", false, "pipelines and pipeline: print again at each change the runner's events say, until interrupted")
|
|
next := fs.String("next", "", "pipeline: the cursor of the next page a pipeline's answer named")
|
|
limit := fs.Int("limit", view.DefaultPipelinesLimit, "pipelines: the newest this many pipelines of the branch")
|
|
if err := fs.Parse(args); err != nil {
|
|
return 2
|
|
}
|
|
if fs.NArg() > 0 && (fs.Arg(0) == "pipelines" || fs.Arg(0) == "pipeline") {
|
|
if *limit < 1 {
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli: -limit is a number of at least one")
|
|
return 2
|
|
}
|
|
return pipelines(socket, fs.Args(), *next, *limit, *follow, *asJSON, out, errOut)
|
|
}
|
|
if fs.NArg() > 0 && fs.Arg(0) == "holds" {
|
|
return holds(socket, *asJSON, out, errOut)
|
|
}
|
|
if fs.NArg() > 0 && (fs.Arg(0) == "hold-release" || fs.Arg(0) == "hold-keep") {
|
|
if fs.NArg() < 3 {
|
|
fmt.Fprintf(errOut, "mesh-delivery-cli %s <module> <fingerprint> [words]\n", fs.Arg(0))
|
|
return 2
|
|
}
|
|
option := strings.TrimPrefix(fs.Arg(0), "hold-")
|
|
r, err := view.AnswerHoldOn(socket, fs.Arg(1), fs.Arg(2), option, strings.Join(fs.Args()[3:], " "))
|
|
if err != nil {
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli:", err)
|
|
return 1
|
|
}
|
|
fmt.Fprintf(out, "answered the hold of %s at %s with %s; the teller fills the ask from it and the assigner reads it\n", r.Module, r.FP, option)
|
|
return 0
|
|
}
|
|
if fs.NArg() > 0 {
|
|
if fs.Arg(0) != "answer" || fs.NArg() < 3 {
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli shows the rows, or answers: mesh-delivery-cli answer <ask key> <option> [words]; holds; hold-release|hold-keep <module> <fingerprint> [words]; [-follow] [-limit <n>] pipelines [branch]; [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
|
|
return 2
|
|
}
|
|
key, option := fs.Arg(1), fs.Arg(2)
|
|
if err := view.AnswerAsk(socket, key, option, strings.Join(fs.Args()[3:], " ")); err != nil {
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli:", err)
|
|
return 1
|
|
}
|
|
fmt.Fprintf(out, "answered %s with %s; the teller fills the ask from it\n", key, option)
|
|
return 0
|
|
}
|
|
s, err := view.Ask(socket)
|
|
if err != nil {
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli:", err)
|
|
return 1
|
|
}
|
|
if *asJSON {
|
|
enc := json.NewEncoder(out)
|
|
enc.SetIndent("", " ")
|
|
if err := enc.Encode(s); err != nil {
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli:", err)
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
view.Table(out, s)
|
|
return 0
|
|
}
|
|
|
|
// pipelines prints the pipelines page (design 47 H2 H-A-467): `pipelines [branch]` the newest pipelines of a branch (main by
|
|
// default), `pipeline <pipeline> [mover]` one pipeline's mover rows or one mover's steps; with -follow again at each change.
|
|
func pipelines(socket string, args []string, next string, limit int, follow, asJSON bool, out, errOut io.Writer) int {
|
|
var branch, pipeline, mover string
|
|
switch {
|
|
case args[0] == "pipelines" && len(args) <= 2:
|
|
if len(args) == 2 {
|
|
branch = args[1]
|
|
}
|
|
case args[0] == "pipeline" && (len(args) == 2 || len(args) == 3):
|
|
pipeline = args[1]
|
|
if len(args) == 3 {
|
|
mover = args[2]
|
|
}
|
|
default:
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli [-follow] [-limit <n>] pipelines [branch]; mesh-delivery-cli [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
|
|
return 2
|
|
}
|
|
var failed error
|
|
err := view.AskPipelines(socket, branch, limit, pipeline, mover, next, follow, func(page view.PipelinesPage, show *seatShow) bool {
|
|
if follow {
|
|
fmt.Fprintf(out, "--- %s ---\n", time.Now().Format("15:04:05"))
|
|
}
|
|
if asJSON {
|
|
enc := json.NewEncoder(out)
|
|
enc.SetIndent("", " ")
|
|
var v any = page
|
|
if show != nil {
|
|
v = show
|
|
}
|
|
if failed = enc.Encode(v); failed != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
if show != nil {
|
|
view.PipelineTable(out, *show, mover)
|
|
} else {
|
|
view.PipelinesTable(out, page)
|
|
}
|
|
return true
|
|
})
|
|
if err == nil {
|
|
err = failed
|
|
}
|
|
if err != nil {
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli:", err)
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// seatShow is the view's answer of one pipeline: show's, with the pipeline's page by tier and stage naming no mover.
|
|
type seatShow = view.PipelineAnswer
|
|
|
|
// holds prints every hold: module, fingerprint, node, since, answer, words.
|
|
func holds(socket string, asJSON bool, out, errOut io.Writer) int {
|
|
rows, err := view.AskHolds(socket)
|
|
if err != nil {
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli:", err)
|
|
return 1
|
|
}
|
|
if asJSON {
|
|
enc := json.NewEncoder(out)
|
|
enc.SetIndent("", " ")
|
|
if err := enc.Encode(rows); err != nil {
|
|
fmt.Fprintln(errOut, "mesh-delivery-cli:", err)
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
if len(rows) == 0 {
|
|
fmt.Fprintln(out, "the assigner holds nothing")
|
|
return 0
|
|
}
|
|
tw := tabwriter.NewWriter(out, 0, 2, 2, ' ', 0)
|
|
fmt.Fprintln(tw, "MODULE\tFINGERPRINT\tNODE\tSINCE\tANSWER\tWORDS")
|
|
for _, r := range rows {
|
|
answer := r.Answer
|
|
switch {
|
|
case r.AskKey == "":
|
|
answer = "no ask"
|
|
case r.Pending != "":
|
|
answer = r.Pending + " (from the view, the teller fills it)"
|
|
case answer == "":
|
|
answer = "not answered"
|
|
}
|
|
fp := strings.TrimPrefix(r.FP, "src2:")
|
|
if len(fp) > 12 {
|
|
fp = fp[:12]
|
|
}
|
|
since := ""
|
|
if !r.Since.IsZero() {
|
|
since = r.Since.Local().Format("2006-01-02 15:04")
|
|
}
|
|
words := r.Words
|
|
if r.Error != "" {
|
|
words = "unreadable: " + r.Error
|
|
}
|
|
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\t%s\n", r.Module, fp, r.Node, since, answer, words)
|
|
}
|
|
tw.Flush()
|
|
return 0
|
|
}
|