Skip to content

Plan and apply

madbot-cli works in two steps, like many infrastructure tools:

  • plan compares the file with what madbot holds, and says what should be created or changed. It writes nothing.
  • apply does what plan announces, and nothing else. It never deletes anything: what is in madbot without being in the file stays in place.

So the file describes a desired state, not a list of actions: you can run apply as many times as you like, it only creates what is missing. That is what lets a platform run it after each production, without keeping track of what it already sent.

  1. See what will change:

    Fenêtre de terminal
    madbot-cli plan depot.yaml
    = workspace 'madbot CLI workshop': unchanged
    = source zenodo (url=https://zenodo.org/): uses the connection 'Zenodo (zenodo.org)' — without credentials: public data only
    + node 'Stream water quality': create
    source zenodo
    + link README.md [24343971/README.md]
    + link stations.csv [24343971/stations.csv]
    + link mesures.csv [24343971/mesures.csv]
    apply never deletes: what is not in the file is left as it is.
    Plan: 4 to create, 0 to update, 2 unchanged.
    Nothing written.

    Each line starts with a sign: + to create, ~ to change, = unchanged, ! to look at. The workspace and the connection to Zenodo already exist: browse --connect created them in the previous block, and plan says it reuses this connection.

  2. Apply:

    Fenêtre de terminal
    madbot-cli apply depot.yaml

    madbot-cli creates the node, links the three files, then waits until madbot has read them on Zenodo. It says so at each step, and ends with a summary:

    Done: 4 changes, 0 failures, 0 submissions sent.
    node 'Stream water quality': 3 data read
  3. Run plan again:

    Fenêtre de terminal
    madbot-cli plan depot.yaml

    This time, everything is =: madbot holds what the file describes.

Optional See it in the interface

Open the madbot interface: the workspace madbot CLI workshop holds the node Stream water quality, and its Datalinks tab the three files. They are the same objects as those created by hand: a person can take over in the interface what a platform created, and the other way round.

Optional What the command does, on the API side

plan only reads: workspaces, nodes, connections, linked data, and GET /api/connections/{id}/external_data to find the files named in the folder. apply then writes:

  • POST /api/nodes for the node;
  • POST /api/nodes/{id}/datalinks/batch to link the three files in one request;
  • GET /api/tasks/{id} to wait until madbot has read them.

A node is found again by its title, under its parent: changing the title in the file creates another node. A data is found again by its source and its external_id.

  • plan shows a ! line “nodes in the workspace, not in the file”: your workspace holds other nodes, created in the interface or by another file. It is not an error: apply leaves them in place.
  • “! error: … not in the folder: readme.md (close to it: README.md); nothing of this entry is linked”: a name in names matches no file of the record, and madbot-cli offers the close names. Names are written exactly as browse gives them, case included. apply links nothing of this entry as long as it is wrong.
  • apply stops on a network error, then goes on: madbot-cli replays by itself the requests that allow it, up to five times. If it stops anyway, run apply again: it goes on where it was, without creating anything twice.
  • “1 failed to read” in the summary: madbot could not read a file on Zenodo, often because Zenodo limits the number of reads. Wait a minute, then run madbot-cli apply depot.yaml --retry-failed.
  • A second node with the same name in the interface: the title in the file changed between two apply runs. Put the original title back, and delete the extra node in the interface.