Elffuss BraidHub

kikocis/EDC public

main · 7.0 KiBRenderedRawPermalink
1# Processing Callbacks
2
3## Decision
4
5Implement the ability for clients to specify callback endpoints to be invoked at specific points during request processing:
6
7- Callback endpoints can be specified for _Contract Negotiation_ and _Transfer Process_ state transitions when a request is made via the _Management API_
8- Callback endpoints are scoped to the particular state machine instance associated with the request.
9- Clients can request the callbacks to be invoked *transactionally* or on a *best-effort* basis.
10- Callback endpoints can be remote or local (in-process). The initial implementation will support HTTPS endpoints.
11
12## Rationale
13
14Currently, the EDC provides support for listeners (e.g. `TransferProcessListener`) and event subscribers (`EventSubscriber`). However, there is no way to provide callback endpoint
15information that can be used by listener and subscriber implementations when a request is made via the Management API. Processing callbacks will address this gap and provide
16support for invoking HTTPS endpoints.
17
18> Note, this functionality can also be used to align EDR handling with the migration to the IDS Dataspace Protocol specifications.
19
20## Configuration Scheme
21
22Support for two types of callbacks will be implemented: static endpoints and dynamic endpoints. Static endpoints are configured in the EDC and referenced by identifier; dynamic
23endpoints are specified at the time a request is made.
24
25### Static Endpoints
26
27The static endpoint registration will be done using a configuration extension. This allows for the development of more elaborate endpoint registration mechanisms in the future.
28
29A static endpoint will be registered using EDC configuration:
30
31```
32edc.callback.endpoint1.uri=
33edc.callback.endpoint1.events=
34edc.callback.endpoint1.transactional=
35edc.callback.endpoint1.auth-key=
36edc.callback.endpoint1.auth-code-id=
37```
38
39The previous configuration will create a static endpoint registration for the id `endpoint1` with the following properties:
40
41- The `uri` is scheme-specific address used to dispatch a callback notification.
42- The optional `events` property is a collection of processing events corresponding to a state machine state.
43- If the optional `transactional` property is true, callback dispatches will be conducted transactionally (on supported configurations) during the state machine transition. The
44 default is false.
45- The optional `auth-key` property defines the transport specific header to use for sending an authentication value. If the `auth-code-id` value is set and this property is not
46 set, the value `Authorization` will be used.
47- The optional id to use when resolving a required callback authorization key from the Vault.
48
49Static callback endpoints are referenced by their id when a client makes a request. They may be reused by multiple requests.
50
51### Dynamic Endpoints
52
53Dynamic endpoints are registered as part of a client request and are therefore scoped to the latter. Dynamic endpoints have three properties:
54
55- `uri`
56- `events`
57- `transactional`
58
59Dynamic endpoints do not have explicit API keys. Security can be provided at the network layer or through a URI with an randomly-generated single-use path part.
60
61### Event Naming
62
63Event names will be constructed using a hierarchical period notation. For example, `contract.negotiation.initiated`. Abstract events can also be referenced. For
64example, `contract.negotiation` can be used to denote all contract negotiation subtypes.
65
66## New Services
67
68### The CallbackRegistry
69
70A `CallbackRegistry` to manage static endpoints will be added to the `control-plane-spi` module:
71
72```
73package org.eclipse.edc.connector.spi.callback
74
75public interface CallbackRegistry {
76
77 void register(CallbackAddress address);
78
79 List<CallbackAddress> resolve(String state);
80
81}
82```
83
84This registry will be implemented in `control-plane-aggregate-services` as a simple, in-memory service. Dynamic endpoint will be persisted with the transfer process.
85
86## Impact on Existing Services
87
88### Management API
89
90`ContractNegotiationDto` and `TransferRequestDto` will be enhanced to include a collection of `CallbackAddress` types that model dynamic endpoint configurations:
91
92```
93public class CallbackAddress {
94
95 private String uri;
96
97 private Set<String> events;
98
99 private boolean transactional
100
101 ....
102}
103```
104
105Provided dynamic callback addresses will be persisted alongside the request.
106
107### State Machines
108
109During a state transition, a `ContractNegotiationEventListener` or `TransferProcessEventListener` will resolve `CallbackAddress` entries matching the state to be transitioned to by
110querying the `CallbackRegistry` and current `TransferProcess`. If a resolved callback is marked as transactional, an invocation error will mark the current transaction as
111rollback-only; otherwise, invocation errors will be logged and the transaction will proceed. Invocations will use the standard EDC retry mechanism.
112
113> Note that the event framework and EventRouter will be refactored to include contract negotiation and transfer process data as part of a pre-requisite Decision Record.
114
115> Note that transactional callback endpoints must be idempotent. De-duplication can be performed by comparing the associated process id and state with previous invocations.
116
117#### Dispatching
118
119Dispatching to callback endpoints will be performed by registered `RemoteMessageDispatcher`s corresponding to the protocol part of the callback URI. These dispatchers will send
120events representing the `ContractNegotiation` or `TransferProcess` data received by the event listener.
121
122### DataFlowController
123
124The `DataFlowController` interface will need to be changed to return an explicit result type. See below for details.
125
126## EndpointDataReferenceReceiver and Processing Callbacks
127
128The existing mechanism for propagating and handling `EndpointDataReference`s will be adapted to processing callbacks. EDR configuration keys, e.g. `edc.receiver.http.dynamic.`
129and `edc.receiver.http.` will be aliases for the registration of `CallbackAddress` configurations.
130
131> Note we need to discuss whether to keep support of fallback `edc.receiver.http.dynamic.` endpoints. Also, we need to discuss continuing to support `EndpointDataReferenceReceiver`
132> implementations. The implementations in EDC can be converted to `RemoteMessageDispatcher`s but we need to discuss how to handle end-user supplied `EndpointDataReferenceReceiver`
133> implementations.
134
135The most significant change will involve propagating the EDR from the provider to the consumer. The new IDS protocol `TransferStartMessage` contains a `dataAddress` field that can be
136used to propagate the EDR instead of requiring the `DataFlowController` to send the EDR out-of-band to the client. The `DataFlowController` will need to return the EDR from
137the `initiateFlow` method using a `DataFlowResponse`:
138
139```
140 StatusResult<DataFlowResponse> initiateFlow(DataRequest dataRequest, DataAddress contentAddress, Policy policy);
141```
142
143If a reference is returned, it will be stored in the Vault and then sent with the `TransferStartMessage` by a dispatching listener. The client will receive the EDR and propagate it
144as part of its transfer process state transition.
145
146