Skip to content

Commit 0df10eb

Browse files
committed
#49 — consumer-aliases name the upstream related resource
Convention refinement across PRs 1-3: aliases on assignments and on PRI's owns relationships now identify the related resource each consumer is part of (its domain role), not the slot/thing being received. * avc sets :cvc, cvc sets :nni_group, uni sets :ntd on their assignments * pri's owns relationships aliased :circuit (AVC) and :port (UNI) * inheritance walks updated to follow the new aliases * pool/metrics aggregations unaffected (still filter by `thing`) * memories and moduledoc examples revised
1 parent 56a6874 commit 0df10eb

8 files changed

Lines changed: 77 additions & 56 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
3434
* New `cvc_metrics` characteristic on CVC carries `avcs_count` and `avcs_total_bandwidth` aggregated live over assigned AVCs.
3535
* New `nni_group_metrics` characteristic on NniGroup carries `cvcs_count`/`cvcs_total_bandwidth` (demand), `nnis_count`/`nnis_total_bandwidth` (capacity), and `utilization = cvcs_total_bandwidth / nnis_total_bandwidth`.
3636
* NBN — NTD brings up assigned UNIs as `unis[]` via the `:port` assignment (issue #49 part 2).
37-
* NBN — NbnEthernet (PRI) brings up four characteristics surfacing the full delivery chain (issue #49 part 3): `avc` single-hop via the `:avc` owns relationship, `uni` single-hop via the `:uni` owns relationship, `cvc` two-hop via `:avc` then `:cvlan`, and `ntd` two-hop via `:uni` then `:port`. All singular.
37+
* NBN — NbnEthernet (PRI) brings up four characteristics surfacing the full delivery chain (issue #49 part 3): `avc` single-hop via the `:circuit` owns relationship, `uni` single-hop via the `:port` owns relationship, `cvc` two-hop via `:circuit` then `:cvc`, and `ntd` two-hop via `:port` then `:ntd`. All singular.
38+
* NBN — consumer-side aliases on assignments and relationships now name the **upstream related resource** the consumer is part of (its domain role), not the slot/thing being received: AVC sets `:cvc` on its cvlan assignment, CVC sets `:nni_group` on its svlan assignment, UNI sets `:ntd` on its port assignment; PRI's two `:owns` relationships are aliased `:circuit` (AVC) and `:port` (UNI). Inheritance walks use these consumer-aliases. Pool/metric aggregations are unaffected — they still filter by `thing`.
3839
* `BandwidthProfile.downstream/1` — atom-to-Mbps mapping used by the metrics aggregation. CVCs are treated as symmetric capacity in this model (satellite asymmetry ignored).
3940

4041
### Refactors (continued):

lib/diffo_example/calculations/inherited_characteristic_via_assignment.ex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ defmodule DiffoExample.Calculations.InheritedCharacteristicViaAssignment do
2727
from this instance back to the source whose characteristic we want.
2828
Each step filters `AssignmentRelationship` by `target_id` and `alias`,
2929
then follows `source_id` to the next set of instances. The aliases are
30-
the assignee's slot names, supplied when the assignment is made.
30+
the **consumer's name for the upstream related resource** at each hop
31+
(e.g. AVC names its CVC slot `:cvc`, CVC names its NniGroup slot
32+
`:nni_group`) — set when the assignment is made.
3133
- `characteristic_module:` *(required)* — the typed characteristic Ash
3234
resource on the final source (e.g. `ShelfCharacteristic`). The calc
3335
queries this resource by `instance_id` and returns the `.value`.
@@ -52,12 +54,12 @@ defmodule DiffoExample.Calculations.InheritedCharacteristicViaAssignment do
5254
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
5355
[via: [:port, :slot], characteristic_module: ShelfCharacteristic]}
5456
55-
# AVC brings up its singular CVC via :cvlan — AssignmentRelationship
56-
# identity guarantees ≤1 source, so we declare :map and ask the calc
57-
# to unwrap.
57+
# AVC brings up its singular CVC via its :cvc consumer-alias on the
58+
# cvlan assignment from the CVC. AssignmentRelationship identity
59+
# guarantees ≤1 source, so we declare :map and ask the calc to unwrap.
5860
calculate :cvc, :map,
5961
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
60-
[via: [:cvlan], characteristic_module: CvcCharacteristic, singular?: true]}
62+
[via: [:cvc], characteristic_module: CvcCharacteristic, singular?: true]}
6163
"""
6264
use Ash.Resource.Calculation
6365

lib/diffo_example/calculations/inherited_characteristic_via_relationship.ex

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ defmodule DiffoExample.Calculations.InheritedCharacteristicViaRelationship do
2727
queries this resource by `instance_id` and returns the `.value`.
2828
- `type:` *(optional)* — filter relationships by type atom (e.g. `:contains`).
2929
- `alias:` *(optional)* — filter relationships by alias atom (e.g. `:avc`).
30-
- `then_via:` *(optional)* — list of `AssignmentRelationship` aliases to
31-
walk **after** the relationship hop. Each step walks back through the
32-
target's incoming assignments (`target_id + alias` identity, so each
33-
step has cardinality ≤1). Use this for mixed paths — one relationship
34-
hop followed by one or more assignment hops — e.g. PRI's `:cvc`
35-
bring-up: `:avc` owns relationship, then `:cvlan` assignment back to
36-
the CVC.
30+
- `then_via:` *(optional)* — list of consumer-alias atoms to walk back
31+
via `AssignmentRelationship` **after** the relationship hop. Each step
32+
walks back through the target's incoming assignments (`target_id +
33+
alias` identity, so each step has cardinality ≤1). Aliases name the
34+
upstream related resource each consumer is part of. Use this for mixed
35+
paths — one relationship hop followed by one or more assignment hops
36+
— e.g. PRI's `:cvc` bring-up: `:circuit` owns relationship, then `:cvc`
37+
assignment back to the CVC.
3738
- `singular?:` *(optional, default `false`)* — unwrap to a single value
3839
when the consumer expects a 1-cardinality result (e.g. PRI's `:avc` or
3940
`:uni` aliased owns-relationship). Declare the calc's return type as
@@ -48,16 +49,19 @@ defmodule DiffoExample.Calculations.InheritedCharacteristicViaRelationship do
4849
{DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
4950
[type: :contains, characteristic_module: NniCharacteristic]}
5051
51-
# PRI brings up the singular AVC it owns via the :avc alias.
52+
# PRI brings up the singular AVC it owns — PRI calls this related
53+
# resource :circuit (its domain role), set as the alias on PRI's
54+
# owns relationship.
5255
calculate :avc, :map,
5356
{DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
54-
[alias: :avc, characteristic_module: AvcCharacteristic, singular?: true]}
57+
[alias: :circuit, characteristic_module: AvcCharacteristic, singular?: true]}
5558
56-
# PRI brings up the singular CVC two-hop — :avc owns relationship,
57-
# then back via the AVC's incoming :cvlan assignment to the CVC.
59+
# PRI brings up the singular CVC two-hop — :circuit owns relationship
60+
# from PRI to AVC, then back via the AVC's :cvc consumer-alias
61+
# assignment from CVC.
5862
calculate :cvc, :map,
5963
{DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
60-
[alias: :avc, then_via: [:cvlan],
64+
[alias: :circuit, then_via: [:cvc],
6165
characteristic_module: CvcCharacteristic, singular?: true]}
6266
"""
6367
use Ash.Resource.Calculation

lib/nbn/resources/avc.ex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,27 @@ defmodule DiffoExample.Nbn.Avc do
9898

9999
calculations do
100100
# The CVC characteristic value brought up from the singular CVC this
101-
# AVC is assigned a cvlan on — single-hop via the :cvlan assignment.
101+
# AVC is part of — single-hop via the AVC's :cvc consumer-alias on its
102+
# cvlan assignment from the CVC.
102103
calculate :cvc,
103104
:map,
104105
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
105106
[
106-
via: [:cvlan],
107+
via: [:cvc],
107108
characteristic_module: DiffoExample.Nbn.CvcCharacteristic,
108109
singular?: true
109110
]} do
110111
public? true
111112
end
112113

113114
# The singular NniGroup characteristic value brought up transitively —
114-
# cvlan to the CVC, then the CVC's svlan to its NniGroup. Two-hop via
115-
# [:cvlan, :svlan].
115+
# AVC's :cvc alias to the CVC, then the CVC's :nni_group alias to its
116+
# NniGroup. Two-hop via [:cvc, :nni_group].
116117
calculate :nni_group,
117118
:map,
118119
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
119120
[
120-
via: [:cvlan, :svlan],
121+
via: [:cvc, :nni_group],
121122
characteristic_module: DiffoExample.Nbn.NniGroupCharacteristic,
122123
singular?: true
123124
]} do

lib/nbn/resources/cvc.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ defmodule DiffoExample.Nbn.Cvc do
112112

113113
calculations do
114114
# The NniGroup characteristic value brought up from the singular
115-
# NniGroup this CVC is assigned an svlan on — single-hop via the
116-
# :svlan assignment.
115+
# NniGroup this CVC is part of — single-hop via the CVC's :nni_group
116+
# consumer-alias on its svlan assignment from the NniGroup.
117117
calculate :nni_group,
118118
:map,
119119
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
120120
[
121-
via: [:svlan],
121+
via: [:nni_group],
122122
characteristic_module: DiffoExample.Nbn.NniGroupCharacteristic,
123123
singular?: true
124124
]} do

lib/nbn/resources/nbn_ethernet.ex

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,52 +95,59 @@ defmodule DiffoExample.Nbn.NbnEthernet do
9595
end
9696

9797
calculations do
98-
# The singular AVC this access owns — single-hop via :avc owns relationship.
98+
# PRI names its two owns relationships by the domain role each plays —
99+
# `:circuit` for the AVC (Access Virtual Circuit) and `:port` for the
100+
# UNI (the customer's port). Both are consumer-aliases on PRI's owns
101+
# relationships, set at relate time.
102+
103+
# The singular AVC this access owns — single-hop via the :circuit owns relationship.
99104
calculate :avc,
100105
:map,
101106
{DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
102107
[
103-
alias: :avc,
108+
alias: :circuit,
104109
characteristic_module: DiffoExample.Nbn.AvcCharacteristic,
105110
singular?: true
106111
]} do
107112
public? true
108113
end
109114

110-
# The singular UNI this access owns — single-hop via :uni owns relationship.
115+
# The singular UNI this access owns — single-hop via the :port owns relationship.
111116
calculate :uni,
112117
:map,
113118
{DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
114119
[
115-
alias: :uni,
120+
alias: :port,
116121
characteristic_module: DiffoExample.Nbn.UniCharacteristic,
117122
singular?: true
118123
]} do
119124
public? true
120125
end
121126

122-
# The singular CVC backing this access's AVC — two-hop via :avc owns
123-
# relationship, then back via the AVC's incoming :cvlan assignment.
127+
# The singular CVC backing this access's circuit — two-hop via the
128+
# :circuit owns relationship, then back via the AVC's :cvc consumer-alias
129+
# assignment to its CVC.
124130
calculate :cvc,
125131
:map,
126132
{DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
127133
[
128-
alias: :avc,
129-
then_via: [:cvlan],
134+
alias: :circuit,
135+
then_via: [:cvc],
130136
characteristic_module: DiffoExample.Nbn.CvcCharacteristic,
131137
singular?: true
132138
]} do
133139
public? true
134140
end
135141

136-
# The singular NTD this access's UNI plugs into — two-hop via :uni
137-
# owns relationship, then back via the UNI's incoming :port assignment.
142+
# The singular NTD this access's port plugs into — two-hop via the
143+
# :port owns relationship, then back via the UNI's :ntd consumer-alias
144+
# assignment to its NTD.
138145
calculate :ntd,
139146
:map,
140147
{DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
141148
[
142-
alias: :uni,
143-
then_via: [:port],
149+
alias: :port,
150+
then_via: [:ntd],
144151
characteristic_module: DiffoExample.Nbn.NtdCharacteristic,
145152
singular?: true
146153
]} do

test/nbn/nbn_ethernet_test.exs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ defmodule DiffoExample.Nbn.NbnEthernetTest do
186186
]
187187
})
188188

189-
# AVC takes a cvlan from CVC; UNI takes a port from NTD. Set explicit
190-
# aliases so the inheritance walks (target_id + alias identity)
191-
# resolve cleanly.
189+
# AVC takes a cvlan from CVC; UNI takes a port from NTD. Consumer
190+
# aliases name the upstream resource each is part of, so the
191+
# inheritance walks (target_id + alias identity) resolve cleanly.
192192
{:ok, _} =
193193
Nbn.assign_cvlan(cvc, %{
194194
assignment: %Assignment{
195195
assignee_id: avc.id,
196-
alias: :cvlan,
196+
alias: :cvc,
197197
operation: :auto_assign
198198
}
199199
})
@@ -202,19 +202,21 @@ defmodule DiffoExample.Nbn.NbnEthernetTest do
202202
Nbn.assign_port(ntd, %{
203203
assignment: %Assignment{
204204
assignee_id: uni.id,
205-
alias: :port,
205+
alias: :ntd,
206206
operation: :auto_assign
207207
}
208208
})
209209

210-
# PRI owns the AVC and UNI
210+
# PRI owns the AVC and UNI. Aliases name the role each related
211+
# resource plays from PRI's perspective — the AVC is the :circuit,
212+
# the UNI is the :port.
211213
{:ok, pri} = Nbn.build_nbn_ethernet(%{})
212214

213215
{:ok, _} =
214216
Nbn.relate_nbn_ethernet(pri, %{
215217
relationships: [
216-
%Relationship{id: avc.id, direction: :forward, type: :owns, alias: :avc},
217-
%Relationship{id: uni.id, direction: :forward, type: :owns, alias: :uni}
218+
%Relationship{id: avc.id, direction: :forward, type: :owns, alias: :circuit},
219+
%Relationship{id: uni.id, direction: :forward, type: :owns, alias: :port}
218220
]
219221
})
220222

@@ -313,7 +315,7 @@ defmodule DiffoExample.Nbn.NbnEthernetTest do
313315
Nbn.assign_svlan(nni_group, %{
314316
assignment: %Assignment{
315317
assignee_id: cvc.id,
316-
alias: :svlan,
318+
alias: :nni_group,
317319
operation: :auto_assign
318320
}
319321
})
@@ -329,7 +331,7 @@ defmodule DiffoExample.Nbn.NbnEthernetTest do
329331
Nbn.assign_cvlan(cvc, %{
330332
assignment: %Assignment{
331333
assignee_id: avc.id,
332-
alias: :cvlan,
334+
alias: :cvc,
333335
operation: :auto_assign
334336
}
335337
})

test/nbn/show_neo4j_test.exs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ defmodule DiffoExample.Nbn.ShowNeo4jTest do
5555
Nbn.assign_svlan(nni_group, %{
5656
assignment: %Assignment{
5757
assignee_id: cvc.id,
58-
alias: :svlan,
58+
alias: :nni_group,
5959
operation: :auto_assign
6060
}
6161
})
@@ -102,7 +102,7 @@ defmodule DiffoExample.Nbn.ShowNeo4jTest do
102102
Nbn.assign_cvlan(cvc1, %{
103103
assignment: %Assignment{
104104
assignee_id: avc.id,
105-
alias: :cvlan,
105+
alias: :cvc,
106106
operation: :auto_assign
107107
}
108108
})
@@ -214,7 +214,7 @@ defmodule DiffoExample.Nbn.ShowNeo4jTest do
214214
Nbn.assign_cvlan(cvc, %{
215215
assignment: %Assignment{
216216
assignee_id: avc.id,
217-
alias: :cvlan,
217+
alias: :cvc,
218218
operation: :auto_assign
219219
}
220220
})
@@ -223,19 +223,19 @@ defmodule DiffoExample.Nbn.ShowNeo4jTest do
223223
Nbn.assign_port(ntd, %{
224224
assignment: %Assignment{
225225
assignee_id: uni.id,
226-
alias: :port,
226+
alias: :ntd,
227227
operation: :auto_assign
228228
}
229229
})
230230

231-
# PRI owns AVC and UNI
231+
# PRI owns AVC (named :circuit from PRI's view) and UNI (named :port).
232232
{:ok, pri} = Nbn.build_nbn_ethernet(%{})
233233

234234
{:ok, _} =
235235
Nbn.relate_nbn_ethernet(pri, %{
236236
relationships: [
237-
%Relationship{id: avc.id, direction: :forward, type: :owns, alias: :avc},
238-
%Relationship{id: uni.id, direction: :forward, type: :owns, alias: :uni}
237+
%Relationship{id: avc.id, direction: :forward, type: :owns, alias: :circuit},
238+
%Relationship{id: uni.id, direction: :forward, type: :owns, alias: :port}
239239
]
240240
})
241241

@@ -290,7 +290,11 @@ defmodule DiffoExample.Nbn.ShowNeo4jTest do
290290

291291
{:ok, _} =
292292
Nbn.assign_port(ntd, %{
293-
assignment: %Assignment{assignee_id: uni.id, operation: :auto_assign}
293+
assignment: %Assignment{
294+
assignee_id: uni.id,
295+
alias: :ntd,
296+
operation: :auto_assign
297+
}
294298
})
295299
end
296300

0 commit comments

Comments
 (0)