TopologyDocument

@Serializable
data class TopologyDocument(val root: String, val children: List<TopologyDocument.Node>)

The fair-share tree exactly as an admin wrote it, before anything is checked.

This is the form a config file decodes into, in whatever format the consumer reads. It checks no values, so a wrong value — an empty or repeated name, bad weight text, an empty group — never fails the decode. A config page reads one, hands it to Topology.from, and gets either a checked Topology or every problem at once, each with an address it can point at.

Weights are text, as written: a whole number ("3") or a ratio ("3/2"). Keeping them as text here is what lets a bad weight be reported beside the other problems instead of aborting the decode.

Whether a document of the wrong shape decodes is up to the consumer's format, not to heddle. Under a default Json, a weight written as a bare number ("weight": 3) and a misspelt key ("weigth") both throw before Topology.from runs. In JSON, quote weights, or decode with Json { isLenient = true }, which reads a bare 3 as the text "3".

Samples

// As decoded from the file: names and weight text, nothing checked yet.
val written = TopologyDocument(
    root = "pool",
    children = listOf(
        TopologyDocument.Group(
            name = "acme",
            weight = "3",
            children = listOf(
                TopologyDocument.Lane("interactive", weight = "3/2"),
                TopologyDocument.Lane("batch"),
            ),
        ),
        // A template: the app attaches children here while running, each at weight 1.
        TopologyDocument.Group(name = "tenants", template = TopologyDocument.ChildTemplate()),
    ),
)
val parsed = Topology.from(written)
check(parsed is TopologyParse.Valid)
check(parsed.topology.children.first().weight == Weight.of(3))

// A typo is reported, not thrown: the second child of `acme` reuses a name.
val typo = written.copy(
    children = listOf(
        TopologyDocument.Group("acme", children = listOf(TopologyDocument.Lane("batch"), TopologyDocument.Lane("batch"))),
    ),
)
val problem = (Topology.from(typo) as TopologyParse.Invalid).problems.single()
// Addressed by child indices: the root's first child, then that child's second.
check(problem.path == listOf(0, 1) && problem.names == listOf("pool", "acme", "batch"))
check(problem.kind == TopologyProblem.Kind.DUPLICATE_NAME)

Constructors

Link copied to clipboard
constructor(root: String, children: List<TopologyDocument.Node>)

Types

Link copied to clipboard
@Serializable
data class ChildTemplate(val weight: String = "1", val maxConcurrent: Long? = null, @IntroducedAt(version = "0.7.7") val template: TopologyDocument.ChildTemplate? = null)

A group's template for its attached children, as written; see Topology.ChildTemplate.

Link copied to clipboard
@Serializable
@SerialName(value = "group")
data class Group(val name: String, val weight: String = "1", val children: List<TopologyDocument.Node> = emptyList(), val template: TopologyDocument.ChildTemplate? = null, val maxConcurrent: Long? = null) : TopologyDocument.Node

A group of children that share its slice between them.

Link copied to clipboard
@Serializable
@SerialName(value = "lane")
data class Lane(val name: String, val weight: String = "1", @IntroducedAt(version = "0.7.5") val maxConcurrent: Long? = null) : TopologyDocument.Node

A leaf of the tree: work is charged here.

Link copied to clipboard
@Serializable
sealed interface Node

A child of a group: another Group, or a Lane that work is charged to.

Properties

Link copied to clipboard

the root's children, in the order written.

Link copied to clipboard

the name of the group at the top of the tree.

Functions

Link copied to clipboard

Adds child, a TopologyDocument.Group with anything beneath it or a TopologyDocument.Lane, as the last child of the group at parent; [] adds it to the root. Every existing address is unchanged, and TopologyEdit.Edited.path is the new child's.

Link copied to clipboard

Moves the child at path, with everything beneath it, to be the last child of the group at parent; [] is the root. parent is an address in this document, before the move, and TopologyEdit.Edited.path is where the child lands after it.

Link copied to clipboard

Removes the child at path, with everything beneath it. Later siblings move up one index, and TopologyEdit.Edited.path is the parent's. A group left with no children and no template is a problem Topology.from reports.

Link copied to clipboard

Renames the node at path to name, keeping everything else about it and everything beneath it. [] renames the root. The name is not checked here; Topology.from reports an empty one.

Link copied to clipboard

Sets the maxConcurrent ceiling of the child at path: a count, 0 to pause it, or null to clear the ceiling. Not checked here; Topology.from reports a negative one. A group's template ceiling is not this one: it is on TopologyDocument.ChildTemplate.

Link copied to clipboard

Sets the template of the group at path to template, replacing the whole of the old one, nested templates included; null removes it. A template is what lets the app attach children to the group while it runs, and says what each one gets (see TopologyDocument.ChildTemplate). To change one field, pass a copy of the group's own. Nothing in template is checked here; Topology.from reports a bad weight or a negative ceiling at the group's path.

Link copied to clipboard

Sets the weight of the child at path to weight, written as text the way a file writes it: "3" or "3/2". The text is not checked here; Topology.from reports a bad one.