Class PlanJson

java.lang.Object
com.eqixiac.equinix.design.plan.PlanJson

public final class PlanJson extends Object
Reads and writes a DeploymentPlan as JSON and computes its content identity.

The document holds everything needed to diff, reconcile and resume the plan: every planned resource with its logical key, the native multicloud links and Interconnects, pricing, the validation state, the design-spec fingerprint, the deployment name, the name prefix and the project. It does not hold the source OptimizationResult (a loaded plan's dryRun() therefore skips the checks that need the optimizer's recommendations, and says so) nor the Fabric client (bind one with DeploymentPlan.withFabric).

Plan id. planId(DeploymentPlan) is the first 16 hex characters of the SHA-256 of the plan's desired state in canonical JSON (properties and map entries sorted): the planned resources, Interconnects, native links, deployment name, name prefix, project and spec fingerprint. Pricing and validation results are not part of it, so repricing or re-validating keeps the id; any change to what would be built changes it. The id is written into the document, and fromJson(String) refuses a document whose stored id does not match its content (an edited or corrupt file).

  • Field Details

    • SCHEMA_VERSION

      public static final String SCHEMA_VERSION
      The document format version this release reads and writes.
      See Also:
  • Method Details

    • mapper

      public static com.fasterxml.jackson.databind.ObjectMapper mapper()
      The shared mapper for plan documents, checkpoints and live-state snapshots.
      Returns:
      the configured mapper (do not reconfigure it)
    • toJson

      public static String toJson(DeploymentPlan plan)
      Serializes a plan, including its planId.
      Parameters:
      plan - the plan
      Returns:
      indented JSON
    • fromJson

      public static DeploymentPlan fromJson(String json)
      Parses a plan document and checks its integrity.
      Parameters:
      json - the document
      Returns:
      the plan, without a Fabric client bound
      Throws:
      IllegalArgumentException - when the document is unreadable, of another schema version, or its stored planId does not match its content
    • save

      public static void save(DeploymentPlan plan, Path file)
      Writes a plan document atomically (a temporary file in the same directory, then a rename).
      Parameters:
      plan - the plan
      file - the destination, replaced if present
      Throws:
      UncheckedIOException - when the file cannot be written
    • load

      public static DeploymentPlan load(Path file)
      Reads a plan document.
      Parameters:
      file - the file (UTF-8 JSON)
      Returns:
      the plan, without a Fabric client bound
      Throws:
      UncheckedIOException - when the file cannot be read
      IllegalArgumentException - when the content is not a valid plan document
    • planId

      public static String planId(DeploymentPlan plan)
      The plan's content identity; see the class description.
      Parameters:
      plan - the plan
      Returns:
      16 lowercase hex characters, equal for plans that would build the same thing