Class ChaosProfileLibrary

java.lang.Object
org.mockserver.mock.action.http.ChaosProfileLibrary

public class ChaosProfileLibrary extends Object
Persisted, named library of reusable chaos experiment profiles.

A "profile" here is simply a saved chaos experiment definition — the exact same JSON shape that PUT /mockserver/chaosExperiment accepts — stored under a human-chosen name so it can be re-applied later without re-authoring the JSON. The library is a template store, not the active-experiment store: saving a profile does not start it; apply(name) starts it.

Storage: profiles live in the StateBackend's crudEntities("chaos-profiles") key-value store, keyed by profile name. This gives two properties for free:

  • Survives server resetHttpState.reset() clears active chaos (registries, the running experiment) but intentionally does NOT clear this template store, so saved profiles outlive a reset. Unlike the chaos registries (which only attach a backend when clustered), the library always uses the backend store, so the single-node default backend persists profiles across resets too.
  • Cluster-correct — when the backend is clustered, profile saves/deletes replicate across the fleet via the same CRUD-entity replication used by the chaos registries.

Each stored value is the raw experiment-definition ObjectNode; the profile name (the store key) overrides any name inside the body so the saved-under name and the experiment name stay consistent.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    CRUD-entity namespace under which saved profiles are stored.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    delete(String name)
    Removes the saved profile name.
    Optional<com.fasterxml.jackson.databind.node.ObjectNode>
    get(String name)
    Returns the saved profile definition for name, or Optional.empty() if no such profile exists.
    static boolean
    Validates a profile name.
    Returns the names of all saved profiles, in ascending name order.
    void
    save(String name, com.fasterxml.jackson.databind.JsonNode definition)
    Saves (or replaces) a profile under name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BACKEND_NAMESPACE

      public static final String BACKEND_NAMESPACE
      CRUD-entity namespace under which saved profiles are stored.
      See Also:
  • Constructor Details

    • ChaosProfileLibrary

      public ChaosProfileLibrary(StateBackend backend)
  • Method Details

    • isValidName

      public static boolean isValidName(String name)
      Validates a profile name. Returns true when the name is non-null and made up only of letters, digits, space, dot, underscore and hyphen (1–128 characters), with no leading or trailing space.
    • save

      public void save(String name, com.fasterxml.jackson.databind.JsonNode definition)
      Saves (or replaces) a profile under name. The definition is the experiment-definition JSON — the same shape accepted by PUT /mockserver/chaosExperiment. The stored copy's name field is normalised to name so the saved-under name wins.
      Throws:
      IllegalArgumentException - if the name is invalid or the definition is null
    • get

      public Optional<com.fasterxml.jackson.databind.node.ObjectNode> get(String name)
      Returns the saved profile definition for name, or Optional.empty() if no such profile exists.
    • list

      public List<String> list()
      Returns the names of all saved profiles, in ascending name order.
    • delete

      public boolean delete(String name)
      Removes the saved profile name. Returns true if a profile was present and removed, false if no such profile existed.