You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/how_to/use_diffo_provider_extension.livemd
+45-46Lines changed: 45 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,7 +144,12 @@ end
144
144
145
145
Diffo also has an inbuilt Spark DSL extension [Diffo.Provider.Instance.Extension](https://hexdocs.pm/diffo/Diffo.Provider.Instance.Extension.html) which provides DSL and functions for use in building and operating domain specific services and resources.
146
146
147
-
Currently it has DSL to allow you to declare specification, features, characteristics, and party roles. It can be used for services or resources.
147
+
The extension has two top-level sections:
148
+
149
+
**`structure do`** — describes the static shape of the Instance kind: its TMF Specification, Characteristics, Features, and Party roles. All declarations are baked into the module at compile time and introspectable at runtime via generated functions (`specification/0`, `characteristics/0`, `features/0`, `parties/0`) and `Diffo.Provider.Instance.Info`.
150
+
151
+
**`behaviour do`** — declares which Ash actions should be wired for instance lifecycle management. Declaring `create :name` injects `:specified_by`, `:features`, and `:characteristics` arguments onto that action, and the `BuildBefore`/`BuildAfter` changes registered on `BaseInstance` automatically handle specification upsert, feature and characteristic creation, party validation, and graph relationship wiring for every create action. You write the action body for your domain-specific accepts and arguments; the structural wiring is handled for you.
152
+
148
153
Feature and Instance Characteristics can have payloads defined by [Ash.TypedStruct](https://hexdocs.pm/ash/Ash.TypedStruct.html). TypedStruct are DSL specified types which are effectively lightweight embedded resources. We've extended both [AshJason](https://hexdocs.pm/ash_jason/) and [AshOutstanding](https://hexdocs.pm/ash_outstanding/) to support Ash.TypedStruct.
149
154
150
155
For partial resource allocation and assignment we've created Diffo.Provider.Assigner. It is used by the host resource, which declares a characteristic with an Diffo.Provider.AssignableValue TypedStruct. Allocation is managed within the Provider domain using this characteristic. Assignment to Services or Resources is via 'reverse' type: "assignedTo" relationships enriched by relationship characteristics.
@@ -172,7 +177,6 @@ defmodule Diffo.Compute.Cluster do
172
177
aliasDiffo.Provider.BaseInstance
173
178
aliasDiffo.Provider.Instance.Relationship
174
179
aliasDiffo.Provider.Instance.Characteristic
175
-
aliasDiffo.Provider.Instance.ActionHelper
176
180
aliasDiffo.Compute
177
181
aliasDiffo.Compute.ClusterValue
178
182
aliasDiffo.Compute.Tenant
@@ -187,42 +191,40 @@ defmodule Diffo.Compute.Cluster do
187
191
plural_name :Clusters
188
192
end
189
193
190
-
specification do
191
-
id "4bcfc4c9-e776-4878-a658-e8d81857bed7"
192
-
name "cluster"
193
-
type :resourceSpecification
194
-
description "A Cluster Resource Instance"
195
-
category "Network Resource"
196
-
end
194
+
structure do
195
+
specification do
196
+
id "4bcfc4c9-e776-4878-a658-e8d81857bed7"
197
+
name "cluster"
198
+
type :resourceSpecification
199
+
description "A Cluster Resource Instance"
200
+
category "Network Resource"
201
+
end
202
+
203
+
characteristics do
204
+
characteristic :cluster, ClusterValue
205
+
end
197
206
198
-
characteristics do
199
-
characteristic :cluster, ClusterValue
207
+
parties do
208
+
party :operator, Tenant
209
+
party :manager, Engineer
210
+
end
200
211
end
201
212
202
-
parties do
203
-
party :operator, Tenant
204
-
party :manager, Engineer
213
+
behaviour do
214
+
actions do
215
+
create :build
216
+
end
205
217
end
206
218
207
219
actions do
208
220
create :builddo
209
221
description "creates a new Cluster resource instance for build"
@@ -685,7 +684,7 @@ What happens when I request a specific assignment from an instance to which the
685
684
686
685
In this tutorial you've used Diffo's Provider Instance Extension to define a Compute domain with a composite Cluster resource comprised of assigned GPU cores, and the Provider Party Extension to define Tenant and Engineer party kinds that operate and manage those resources.
687
686
688
-
The BaseParty fragment follows the same pattern as BaseInstance — domain-specific resources use it as a fragment and finish their actions with a domain-scoped reload to pick up extended fields.
687
+
`BaseParty`follows the same pattern as `BaseInstance` — domain-specific party resources use it as a fragment and write their own `build` action for domain-specific attributes. No manual wiring is needed.
689
688
690
689
A `BasePlace` extension for domain-specific Place kinds (such as a DataCentre with its own attributes) follows the same pattern and will be added in a future release.
0 commit comments