plan

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package plan derives a migration's target model from its source model.

BuildTargetDataMigrationModel takes what was discovered about the source — filesystems, buckets, databases — together with the destination connections and any TargetMapping the caller supplied, and produces the TargetDataMigrationModel the migration executes. Where the caller named nothing, it fills in defaults: destination paths, bucket and database names, and PostgreSQL schema mappings.

Building a plan also validates it. A request that cannot describe a workable migration — mismatched source and target kinds, an incompatible engine pair, a target database that neither exists nor can be created — yields a *ValidationError, which the controller reports as 400. An unreachable cm-honeybee or cm-beetle is a plain error instead, reported as 500.

Connections are resolved through pkg/core/migration rather than by duplicating that logic, so a plan describes exactly what the migration will do.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignMissingEntryIDs

func AssignMissingEntryIDs(p *targetmodel.TargetDataMigrationModel)

AssignMissingEntryIDs fills in the PlanEntryID of every entry that has none, in place.

POST /plans/target names every entry it builds, so this is a no-op for a plan used as it was issued. It is not one for a plan that was edited or written by hand, which CreateMigration accepts on purpose — naming those entries before the record is stored means execution, logging and retry all read one thing, and the plan the caller can fetch back says what its logs point at.

func BuildTargetDataMigrationModel

func BuildTargetDataMigrationModel(req model.TargetPlanReq) (targetmodel.TargetDataMigrationModel, error)

BuildTargetDataMigrationModel validates the plan request and builds the TargetDataMigrationModel from it.

One plan entry produces one target model entry. The request selects entries of the source model and pairs each with its own destination and its own filter, so a group-level source model — several connections discovered under one source group — describes several migrations rather than several sources crowding onto one destination. A source entry no plan entry names is not migrated.

Validation errors (→ 400 in the controller):

  • a srcConnection naming no entry of the source model
  • a filter or strategy that the entry's source domain gives no meaning to
  • unsupported source/target type combination (DBMS is same-type only; filesystem↔objectstorage cross-storage is allowed)
  • a targetMapping.srcName matching nothing in the source entry it applies to
  • DBMS engine mismatch, or a target older than the source
  • a target database that neither exists nor can be created
  • filesystem→objectstorage with an rsync-incompatible size filter
  • two entries writing to the same destination
  • a file system entry migrating "/" to "/"

External-system errors (→ 500 in the controller) are wrapped and returned as-is.

func DuplicateDestination

func DuplicateDestination(p targetmodel.TargetDataMigrationModel) string

DuplicateDestination returns a description of the first destination two entries of p share, or "" when every one of them is distinct.

Sharing a destination is how a multi-source plan quietly loses data. The entries run one after another, so the second overwrites what the first wrote; the validation that follows reads the destination back against one source at a time and reports the other source's files as not belonging there; and for DBMS a failure in the second entry can roll back or drop a database the first one filled.

The destination is the connection and the path together, not the connection alone: a file system or object storage filter selects a single folder or bucket, so two entries naming the same source and destination with different paths are how one connection migrates more than one of them.

func DuplicateEntryID

func DuplicateEntryID(p targetmodel.TargetDataMigrationModel) string

DuplicateEntryID returns the first PlanEntryID carried by more than one entry of p, or "" when they are all distinct.

Two entries under one name put their log lines, validation details and retry decisions on top of each other, which is the whole thing the name exists to prevent. Ids this server generates never collide; a hand-written plan that copied an entry can.

func RootToRoot

RootToRoot returns a description of the first file system entry of p that migrates "/" to "/", or "" when none does.

That pair copies the source host's whole tree over the target's, /etc, /usr and /boot included, and leaves a target that no longer matches its own kernel, disks or network. There is no rollback for it, so it is refused rather than run.

func SrcConnKey

func SrcConnKey(ref commonmodel.ConnectionRef) string

SrcConnKey returns the value a source ConnectionRef is matched by.

The source model is produced by cm-honeybee, so a source ref is always a honeybee ref and the connection id identifies it completely. Matching is by this key alone — never by comparing the structs, whose other sub-fields are rejected on a source ref and would only add ways for an equal connection to compare unequal: a port left at zero rather than 22, a tlsMode spelled "" rather than "disable", a password with a typo in it.

A ref that is not a honeybee one yields "", which matches no source entry. The controller rejects those before they reach here, so this returning "" means the plan was built without that check rather than that "" is a key.

Types

type ValidationError

type ValidationError struct {
	// contains filtered or unexported fields
}

ValidationError is returned for logical plan validation failures (400). External-system errors (honeybee/beetle unreachable) are returned as plain errors (500).

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL