Skip to content

Commit 2e5d6ff

Browse files
committed
Access — adopt consumer-alias-names-related-resource convention
Match the NBN convention from #49: alias on the consumer's assignment names the upstream related resource it's part of, not the slot/thing being received. * Card sets :shelf on its slot assignment (was :slot) * Path sets :card on its port assignment (was :port) * Card.shelf walks via [:shelf]; Card.slot filters alias :shelf * Path.card walks via [:card]; Path.shelf via [:card, :shelf]; Path.port filters alias :card * Shelf.cards filters alias :shelf (was :slot) * ShelfTotalPorts filters alias :shelf * Tests updated; 54/54 pass
1 parent 0df10eb commit 2e5d6ff

7 files changed

Lines changed: 37 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
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).
3737
* 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`.
38+
* NBN and Access — 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. NBN: 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). Access: Card sets `:shelf` on its slot assignment, Path sets `:card` on its port assignment, and `Shelf.cards` filters on `alias: :shelf`. Inheritance walks use these consumer-aliases. Pool/metric aggregations are unaffected — they still filter by `thing`.
3939
* `BandwidthProfile.downstream/1` — atom-to-Mbps mapping used by the metrics aggregation. CVCs are treated as symmetric capacity in this model (satellite asymmetry ignored).
4040

4141
### Refactors (continued):

lib/access/calculations/shelf_total_ports.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ defmodule DiffoExample.Access.Calculations.ShelfTotalPorts do
77
Sums the `:ports` pool capacity across every card a shelf has assigned
88
a slot to.
99
10-
For each outgoing slot-assignment (alias `:slot`, source = shelf), looks
11-
up the assigned card's `AssignableCharacteristic` for the `:ports` pool
12-
and sums `(last - first + 1)` across all of them.
10+
For each outgoing slot-assignment (cards consumer-alias their upstream
11+
Shelf relationship as `:shelf`), looks up the assigned card's
12+
`AssignableCharacteristic` for the `:ports` pool and sums
13+
`(last - first + 1)` across all of them.
1314
1415
Local-to-this-repo for now. Could in time become a more general
1516
diffo-side primitive (`SumPoolCapacityOfAssignees` or similar) once the
@@ -26,7 +27,7 @@ defmodule DiffoExample.Access.Calculations.ShelfTotalPorts do
2627
Enum.map(records, fn shelf ->
2728
assignments =
2829
Diffo.Provider.AssignmentRelationship
29-
|> Ash.Query.filter_input(source_id: shelf.id, alias: :slot)
30+
|> Ash.Query.filter_input(source_id: shelf.id, alias: :shelf)
3031
|> Ash.read!(domain: Diffo.Provider)
3132

3233
Enum.reduce(assignments, 0, fn assignment, acc ->

lib/access/resources/card.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,21 @@ defmodule DiffoExample.Access.Card do
8989
end
9090

9191
calculations do
92-
# The shelf characteristic value brought up from the shelf this card is
93-
# in — derived live via the :slot assignment.
92+
# The shelf characteristic value brought up from the shelf this card
93+
# is part of — Card's :shelf consumer-alias on its slot assignment
94+
# from the Shelf.
9495
calculate :shelf,
9596
{:array, :map},
9697
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
97-
[via: [:slot], characteristic_module: DiffoExample.Access.ShelfCharacteristic]} do
98+
[via: [:shelf], characteristic_module: DiffoExample.Access.ShelfCharacteristic]} do
9899
public? true
99100
end
100101

101-
# The slot number this card occupies on its shelf — the value of the
102-
# shelf's :slots-pool assignment to this card.
102+
# The slot number this card occupies on its shelf — the :value of
103+
# the assignment Card aliases :shelf (its upstream Shelf).
103104
calculate :slot,
104105
{:array, :integer},
105-
{Diffo.Provider.Calculations.FieldFromAssignment, [alias: :slot, field: :value]} do
106+
{Diffo.Provider.Calculations.FieldFromAssignment, [alias: :shelf, field: :value]} do
106107
public? true
107108
end
108109
end

lib/access/resources/path.ex

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,31 @@ defmodule DiffoExample.Access.Path do
7777

7878
calculations do
7979
# The card characteristic value brought up from the card this path is
80-
# assigned a port on — via the :port assignment.
80+
# part of — Path's :card consumer-alias on its port assignment from
81+
# the Card.
8182
calculate :card,
8283
{:array, :map},
8384
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
84-
[via: [:port], characteristic_module: DiffoExample.Access.CardCharacteristic]} do
85+
[via: [:card], characteristic_module: DiffoExample.Access.CardCharacteristic]} do
8586
public? true
8687
end
8788

88-
# The port number this path occupies on its card — the value of the
89-
# card's :ports-pool assignment to this path.
89+
# The port number this path occupies on its card — the :value of the
90+
# assignment Path aliases :card (its upstream Card).
9091
calculate :port,
9192
{:array, :integer},
92-
{Diffo.Provider.Calculations.FieldFromAssignment, [alias: :port, field: :value]} do
93+
{Diffo.Provider.Calculations.FieldFromAssignment, [alias: :card, field: :value]} do
9394
public? true
9495
end
9596

96-
# The shelf characteristic value brought up transitively — port to the
97-
# card, then the card's slot to its shelf. Two-hop via [:port, :slot].
97+
# The shelf characteristic value brought up transitively — Path's
98+
# :card alias to the Card, then the Card's :shelf alias to its Shelf.
99+
# Two-hop via [:card, :shelf].
98100
calculate :shelf,
99101
{:array, :map},
100102
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
101103
[
102-
via: [:port, :slot],
104+
via: [:card, :shelf],
103105
characteristic_module: DiffoExample.Access.ShelfCharacteristic
104106
]} do
105107
public? true

lib/access/resources/shelf.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ defmodule DiffoExample.Access.Shelf do
9696
calculate :cards,
9797
{:array, :map},
9898
{DiffoExample.Calculations.ReverseInheritedCharacteristic,
99-
[alias: :slot, characteristic_module: DiffoExample.Access.CardCharacteristic]} do
99+
[alias: :shelf, characteristic_module: DiffoExample.Access.CardCharacteristic]} do
100100
public? true
101101
end
102102

test/access/path_test.exs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ defmodule DiffoExample.Access.PathTest do
104104
# now assign a port from a line card
105105
[_dslam, line_card] = create_dslam_with_line_card("QDONC-0001", tl(places), parties)
106106

107-
# path-as-assignee names its slot :port when requesting the port-assignment
108-
# from the line card. This alias lets the InheritedCharacteristic calc
109-
# traverse path → port → card (and transitively card → slot → shelf).
107+
# path-as-assignee names its upstream Card relationship :card when
108+
# requesting the port-assignment. The consumer-alias names the
109+
# related resource, letting the inheritance calc traverse path → :card
110+
# → card (and transitively card → :shelf → shelf).
110111
Access.assign_port!(line_card, %{
111-
assignment: %Assignment{assignee_id: path.id, alias: :port, operation: :auto_assign}
112+
assignment: %Assignment{assignee_id: path.id, alias: :card, operation: :auto_assign}
112113
})
113114

114115
# 5 cables each assigned a pair to the path, plus 1 line card assigned a port
@@ -245,10 +246,11 @@ defmodule DiffoExample.Access.PathTest do
245246
]
246247
})
247248

248-
# card-as-assignee names its slot :slot when requesting; alias lets
249-
# downstream calculations traverse the assignment by name.
249+
# card-as-assignee names its upstream Shelf relationship :shelf when
250+
# requesting the slot-assignment; consumer-aliases let downstream calcs
251+
# traverse by relationship.
250252
Access.assign_slot!(shelf, %{
251-
assignment: %Assignment{assignee_id: card.id, alias: :slot, operation: :auto_assign}
253+
assignment: %Assignment{assignee_id: card.id, alias: :shelf, operation: :auto_assign}
252254
})
253255

254256
[shelf, card]

test/access/shelf_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,16 @@ defmodule DiffoExample.Access.ShelfTest do
180180
]
181181
})
182182

183-
# Each card-as-assignee names its slot :slot when requesting.
183+
# Each card-as-assignee names its upstream Shelf relationship :shelf
184+
# when requesting.
184185
{:ok, _shelf} =
185186
Access.assign_slot(shelf, %{
186-
assignment: %Assignment{assignee_id: card_a.id, alias: :slot, operation: :auto_assign}
187+
assignment: %Assignment{assignee_id: card_a.id, alias: :shelf, operation: :auto_assign}
187188
})
188189

189190
{:ok, shelf} =
190191
Access.assign_slot(shelf, %{
191-
assignment: %Assignment{assignee_id: card_b.id, alias: :slot, operation: :auto_assign}
192+
assignment: %Assignment{assignee_id: card_b.id, alias: :shelf, operation: :auto_assign}
192193
})
193194

194195
# Shelf brings up its cards (in slot order) and aggregates total ports.

0 commit comments

Comments
 (0)