Class: Pangea::Magma::Distribution
- Defined in:
- lib/pangea/magma/distribution.rb
Overview
Strategy for distributing architecture pieces across workspaces. Per theory/PANGEA-MAGMA-ORCHESTRATION.md §III.4. The distribution doesn’t change WHAT is deployed — only WHERE it lives in state organization.
Authors:
dist = Pangea::Magma::Distribution.declare(
strategy: :tier_separation,
tiers: {
network: [vpc_ws, dns_ws, lb_ws],
cluster: [iam_ws, k3s_ws, kms_ws],
workload: [fluxcd_ws, observability_ws],
},
edges: { network: :cluster, cluster: :workload },
placement: {
network: { region: 'us-east-1' },
cluster: { region: 'us-east-1' },
workload: { region: 'us-east-1' },
},
)
chain = dist.to_chain
Operators migrate between Distribution strategies via Pangea::Magma::Migration (M0.2).
Constant Summary collapse
- STRATEGIES =
%i[tier_separation single_workspace per_provider custom].freeze
Instance Attribute Summary collapse
-
#edges ⇒ Object
readonly
Returns the value of attribute edges.
-
#placement ⇒ Object
readonly
Returns the value of attribute placement.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#tiers ⇒ Object
readonly
Returns the value of attribute tiers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(strategy:, tiers:, edges:, placement:) ⇒ Distribution
constructor
A new instance of Distribution.
-
#to_chain ⇒ Object
Convert the distribution to a Pangea::Magma::Chain.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(strategy:, tiers:, edges:, placement:) ⇒ Distribution
Returns a new instance of Distribution.
49 50 51 52 53 54 |
# File 'lib/pangea/magma/distribution.rb', line 49 def initialize(strategy:, tiers:, edges:, placement:) @strategy = strategy @tiers = tiers @edges = edges @placement = placement end |
Instance Attribute Details
#edges ⇒ Object (readonly)
Returns the value of attribute edges.
47 48 49 |
# File 'lib/pangea/magma/distribution.rb', line 47 def edges @edges end |
#placement ⇒ Object (readonly)
Returns the value of attribute placement.
47 48 49 |
# File 'lib/pangea/magma/distribution.rb', line 47 def placement @placement end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
47 48 49 |
# File 'lib/pangea/magma/distribution.rb', line 47 def strategy @strategy end |
#tiers ⇒ Object (readonly)
Returns the value of attribute tiers.
47 48 49 |
# File 'lib/pangea/magma/distribution.rb', line 47 def tiers @tiers end |
Class Method Details
.declare(strategy:, tiers: {}, edges: {}, placement: {}) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/pangea/magma/distribution.rb', line 38 def declare(strategy:, tiers: {}, edges: {}, placement: {}) unless STRATEGIES.include?(strategy) raise ArgumentError, "unknown strategy #{strategy.inspect}; expected one of #{STRATEGIES.inspect}" end new(strategy: strategy, tiers: tiers, edges: edges, placement: placement) end |
Instance Method Details
#to_chain ⇒ Object
Convert the distribution to a Pangea::Magma::Chain. For :tier_separation: build a chain with tier-level edges; each workspace in a tier links to every workspace in the depending tier via the canonical outputs.
For M0.1 this is a structural conversion — full typed-output wiring per tier requires the workspaces to declare their I/O slots, which is the M0.1 Workspace.declare path.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pangea/magma/distribution.rb', line 64 def to_chain case @strategy when :tier_separation tier_separation_chain when :single_workspace single_workspace_chain when :per_provider, :custom raise NotImplementedError, "Distribution.to_chain(strategy=#{@strategy}) — M0.3" end end |
#to_h ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/pangea/magma/distribution.rb', line 76 def to_h { strategy: @strategy.to_s, tiers: @tiers.transform_values { |ws_list| ws_list.map { |w| w.name.to_s } }, edges: @edges.transform_keys(&:to_s).transform_values(&:to_s), placement: @placement.transform_keys(&:to_s), } end |
#to_json(*args) ⇒ Object
85 86 87 |
# File 'lib/pangea/magma/distribution.rb', line 85 def to_json(*args) to_h.to_json(*args) end |