1818import com .fasterxml .jackson .core .JsonProcessingException ;
1919import com .fasterxml .jackson .databind .ObjectMapper ;
2020import org .eclipse .dataplane .domain .Result ;
21+ import org .eclipse .dataplane .domain .controlplane .ControlPlane ;
2122import org .eclipse .dataplane .domain .dataflow .DataFlow ;
2223import org .eclipse .dataplane .domain .dataflow .DataFlowPrepareMessage ;
2324import org .eclipse .dataplane .domain .dataflow .DataFlowResponseMessage ;
2627import org .eclipse .dataplane .domain .dataflow .DataFlowStatusResponseMessage ;
2728import org .eclipse .dataplane .domain .dataflow .DataFlowSuspendMessage ;
2829import org .eclipse .dataplane .domain .dataflow .DataFlowTerminateMessage ;
30+ import org .eclipse .dataplane .domain .registration .ControlPlaneRegistrationMessage ;
2931import org .eclipse .dataplane .domain .registration .DataPlaneRegistrationMessage ;
3032import org .eclipse .dataplane .logic .OnCompleted ;
3133import org .eclipse .dataplane .logic .OnPrepare ;
3234import org .eclipse .dataplane .logic .OnStart ;
3335import org .eclipse .dataplane .logic .OnStarted ;
3436import org .eclipse .dataplane .logic .OnSuspend ;
3537import org .eclipse .dataplane .logic .OnTerminate ;
38+ import org .eclipse .dataplane .port .DataPlaneRegistrationApiController ;
3639import org .eclipse .dataplane .port .DataPlaneSignalingApiController ;
3740import org .eclipse .dataplane .port .exception .DataFlowNotifyControlPlaneFailed ;
3841import org .eclipse .dataplane .port .exception .DataplaneNotRegistered ;
42+ import org .eclipse .dataplane .port .store .ControlPlaneStore ;
3943import org .eclipse .dataplane .port .store .DataFlowStore ;
44+ import org .eclipse .dataplane .port .store .InMemoryControlPlaneStore ;
4045import org .eclipse .dataplane .port .store .InMemoryDataFlowStore ;
4146
4247import java .net .URI ;
5358public class Dataplane {
5459
5560 private final ObjectMapper objectMapper = new ObjectMapper ().configure (FAIL_ON_UNKNOWN_PROPERTIES , false );
56- private final DataFlowStore store = new InMemoryDataFlowStore (objectMapper );
61+ private final DataFlowStore dataFlowStore = new InMemoryDataFlowStore (objectMapper );
62+ private final ControlPlaneStore controlPlaneStore = new InMemoryControlPlaneStore (objectMapper );
5763 private String id ;
5864 private String endpoint ;
5965 private final Set <String > transferTypes = new HashSet <>();
@@ -76,16 +82,20 @@ public DataPlaneSignalingApiController controller() {
7682 return new DataPlaneSignalingApiController (this );
7783 }
7884
85+ public DataPlaneRegistrationApiController registrationController () {
86+ return new DataPlaneRegistrationApiController (this );
87+ }
88+
7989 public Result <DataFlow > getById (String dataFlowId ) {
80- return store .findById (dataFlowId );
90+ return dataFlowStore .findById (dataFlowId );
8191 }
8292
8393 public Result <Void > save (DataFlow dataFlow ) {
84- return store .save (dataFlow );
94+ return dataFlowStore .save (dataFlow );
8595 }
8696
8797 public Result <DataFlowStatusResponseMessage > status (String dataFlowId ) {
88- return store .findById (dataFlowId )
98+ return dataFlowStore .findById (dataFlowId )
8999 .map (f -> new DataFlowStatusResponseMessage (f .getId (), f .getState ().name ()));
90100 }
91101
@@ -153,24 +163,24 @@ public Result<DataFlowResponseMessage> start(DataFlowStartMessage message) {
153163 }
154164
155165 public Result <Void > suspend (String flowId , DataFlowSuspendMessage message ) {
156- return store .findById (flowId )
166+ return dataFlowStore .findById (flowId )
157167 .map (dataFlow -> {
158168 dataFlow .transitionToSuspended (message .reason ());
159169 return dataFlow ;
160170 })
161171 .compose (onSuspend ::action )
162- .compose (store ::save )
172+ .compose (dataFlowStore ::save )
163173 .map (it -> null );
164174 }
165175
166176 public Result <Void > terminate (String dataFlowId , DataFlowTerminateMessage message ) {
167- return store .findById (dataFlowId )
177+ return dataFlowStore .findById (dataFlowId )
168178 .map (dataFlow -> {
169179 dataFlow .transitionToTerminated (message .reason ());
170180 return dataFlow ;
171181 })
172182 .compose (onTerminate ::action )
173- .compose (store ::save )
183+ .compose (dataFlowStore ::save )
174184 .map (it -> null );
175185 }
176186
@@ -180,7 +190,7 @@ public Result<Void> terminate(String dataFlowId, DataFlowTerminateMessage messag
180190 * @param dataFlowId the data flow id.
181191 */
182192 public Result <Void > notifyPrepared (String dataFlowId , OnPrepare onPrepare ) {
183- return store .findById (dataFlowId )
193+ return dataFlowStore .findById (dataFlowId )
184194 .compose (onPrepare ::action )
185195 .compose (dataFlow -> {
186196 dataFlow .transitionToPrepared ();
@@ -197,7 +207,7 @@ public Result<Void> notifyPrepared(String dataFlowId, OnPrepare onPrepare) {
197207 * @param dataFlowId the data flow id.
198208 */
199209 public Result <Void > notifyStarted (String dataFlowId , OnStart onStart ) {
200- return store .findById (dataFlowId )
210+ return dataFlowStore .findById (dataFlowId )
201211 .compose (onStart ::action )
202212 .compose (dataFlow -> {
203213 dataFlow .transitionToStarted ();
@@ -215,7 +225,7 @@ public Result<Void> notifyStarted(String dataFlowId, OnStart onStart) {
215225 * @param dataFlowId id of the data flow
216226 */
217227 public Result <Void > notifyCompleted (String dataFlowId ) {
218- return store .findById (dataFlowId )
228+ return dataFlowStore .findById (dataFlowId )
219229 .compose (dataFlow -> {
220230 dataFlow .transitionToCompleted ();
221231
@@ -230,7 +240,7 @@ public Result<Void> notifyCompleted(String dataFlowId) {
230240 * @param throwable the error
231241 */
232242 public Result <Void > notifyErrored (String dataFlowId , Throwable throwable ) {
233- return store .findById (dataFlowId )
243+ return dataFlowStore .findById (dataFlowId )
234244 .compose (dataFlow -> {
235245 dataFlow .transitionToTerminated (throwable .getMessage ());
236246
@@ -239,7 +249,7 @@ public Result<Void> notifyErrored(String dataFlowId, Throwable throwable) {
239249 }
240250
241251 public Result <Void > started (String flowId , DataFlowStartedNotificationMessage startedNotificationMessage ) {
242- return store .findById (flowId )
252+ return dataFlowStore .findById (flowId )
243253 .map (dataFlow -> {
244254 dataFlow .setDataAddress (startedNotificationMessage .dataAddress ());
245255 return dataFlow ;
@@ -258,7 +268,7 @@ public Result<Void> started(String flowId, DataFlowStartedNotificationMessage st
258268 * @return result indicating whether data flow was completed successfully
259269 */
260270 public Result <Void > completed (String flowId ) {
261- return store .findById (flowId ).compose (onCompleted ::action )
271+ return dataFlowStore .findById (flowId ).compose (onCompleted ::action )
262272 .compose (dataFlow -> {
263273 dataFlow .transitionToCompleted ();
264274 return save (dataFlow );
@@ -316,6 +326,23 @@ private Result<String> toJson(Object message) {
316326 }
317327 }
318328
329+ public ControlPlaneStore controlPlaneStore () {
330+ return controlPlaneStore ;
331+ }
332+
333+ public Result <Void > registerControlPlane (ControlPlaneRegistrationMessage message ) {
334+ var controlPlane = ControlPlane .newInstance ()
335+ .id (message .controlplaneId ())
336+ .endpoint (message .endpoint ())
337+ .build ();
338+
339+ return controlPlaneStore .save (controlPlane );
340+ }
341+
342+ public Result <Void > deleteControlPlane (String id ) {
343+ return controlPlaneStore .delete (id );
344+ }
345+
319346 public static class Builder {
320347
321348 private final Dataplane dataplane = new Dataplane ();
0 commit comments