skip to content
==> include/mesh/fleet_edit.h <==
1/* @ajax/mesh-fleet-edit: a change to the desired state, as the control port asks for it (any member
2 * forwards it to the leader as this text), and the next document it makes (fleet.rs Req, edit,
3 * revert). Refusals are the control port's reasons. */
4#ifndef MESH_FLEET_EDIT_H
5#define MESH_FLEET_EDIT_H
6
7#include "mesh/fleet_doc.h"
8#include "mesh/member_list.h"
9#include "mesh/sched_needs.h"
10
11#include <stdbool.h>
12#include <stdint.h>
13
14typedef enum {
15    MFE_LOAD,        /* name = the catalog dir */
16    MFE_UPGRADE,     /* name, dir (NULL: its own dir) */
17    MFE_ROLLBACK,
18    MFE_UNLOAD,
19    MFE_RUN,         /* name, on */
20    MFE_RESET,
21    MFE_TASK,        /* name, op, arg: a lockstep program's task, run by every member at the same step */
22    MFE_PLACE,       /* name, words */
23    MFE_REFORM,      /* group name: a new epoch over every eligible up member */
24    MFE_ON_LOSS,     /* group name, on_loss, ms */
25    MFE_PIN,         /* name, pin (none: unpin) */
26    MFE_SCHED_PAUSE, /* on */
27    MFE_AUTOREFORM,  /* on */
28    MFE_CORDON,      /* k, on */
29} mfe_kind;
30
31typedef struct {
32    mfe_kind kind;
33    char *name;
34    char *dir;
35    bool on;
36    uint32_t op, arg, k, ms;
37    mfd_onloss on_loss;
38    mt_strs words;
39    ml_opt pin;
40} mfe_req;
41
42bool mfe_parse(const char *line, mfe_req *out, char **err);
43void mfe_req_free(mfe_req *r);
44
45/* A catalog image as the leader sees it (its own catalog). */
46typedef struct {
47    char *dir, *name;
48    uint64_t hash;
49    bool lockstep;
50    mt_strs backends;
51    bool autostart;
52    bool placeable;      /* the manifest's `place` capability and fanout */
53    uint32_t place_cap, place_fanout;
54    mesh_needs needs;
55} mfe_image;
56
57void mfe_image_free(mfe_image *im);
58
59/* What the leader needs to edit the document. */
60typedef struct {
61    /* Its catalog: the image of dir, or false with *err. */
62    bool (*catalog)(void *ctx, const char *dir, mfe_image *out, char **err);
63    /* The up members (in system order) whose backend runs a program listing these backends. */
64    ml_list (*eligible_up)(void *ctx, const mt_strs *backends);
65    void *ctx;
66    uint32_t n; /* the fleet's size */
67} mfe_ctx;
68
69/* The next document for req (version and term are the proposer's) and a line saying what it does;
70 * or false with *err. */
71bool mfe_edit(const mfd_doc *doc, const mfe_req *req, const mfe_ctx *cx, mfd_doc *out, char **what, char **err);
72
73/* cur with what the change from before to after did undone (a change that failed on every member):
74 * the programs, groups and placement requests it changed get their before value back (or go), its
75 * switches theirs; what other changes committed since is kept. */
76mfd_doc mfe_revert(const mfd_doc *cur, const mfd_doc *before, const mfd_doc *after);
77
78#endif