This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-9265-748c8cbc0cdc18c8141b5858169034ec28756ea2 in repository https://gitbox.apache.org/repos/asf/texera.git
commit 858eeec4939ea44c605ce8c9f1fef34cffe5410e Author: Xinyuan Lin <[email protected]> AuthorDate: Wed Nov 4 04:43:20 2026 +0000 refactor(amber): consolidate websocket and collab message models (#9265) ### What changes were proposed in this PR? Consolidates nineteen single-line case classes defining WebSocket control requests and collaboration messages into their respective base trait definition files: - `amber/src/main/scala/org/apache/texera/web/model/websocket/request/TexeraWebSocketRequest.scala`: Consolidates `HeartBeatRequest`, `RetryRequest`, `SkipTupleRequest`, `WorkflowCheckpointRequest`, `WorkflowKillRequest`, `WorkflowPauseRequest`, and `WorkflowResumeRequest` (7 standalone files deleted). - `amber/src/main/scala/org/apache/texera/web/model/collab/request/CollabWebSocketRequest.scala`: Consolidates `AcquireLockRequest`, `CommandRequest`, `HeartBeatRequest`, `RestoreVersionRequest`, `TryLockRequest`, and `WIdRequest` (6 standalone files deleted). - `amber/src/main/scala/org/apache/texera/web/model/collab/event/CollabWebSocketEvent.scala`: Consolidates `CommandEvent`, `LockGrantedEvent`, `LockRejectedEvent`, `ReleaseLockEvent`, `RestoreVersionEvent`, and `WorkflowAccessEvent` (6 standalone files deleted). Deletes 19 redundant source files and their duplicate license headers (-396 net lines in production code). Adds `CollabWebSocketMessageSpec` pinning the polymorphic serialization wire contract across all collaboration requests and events. | Surface | Pinned | | --- | --- | | Package namespaces | `org.apache.texera.web.model.websocket.request`, `org.apache.texera.web.model.collab.request`, `org.apache.texera.web.model.collab.event` unchanged | | Class names & signatures | All 19 case class names, field names, and types identical | | Jackson polymorphic wire mappings | `@JsonTypeInfo` and `@JsonSubTypes` discriminator resolutions preserved | | Public API & imports | Unchanged; existing import sites continue to resolve identically | ### Any related issues? Closes #9264. ### How was this PR tested? - **Tests passed**: ```bash sbt "WorkflowExecutionService/testOnly org.apache.texera.web.model.websocket.request.TexeraWebSocketRequestSpec org.apache.texera.web.model.collab.CollabWebSocketMessageSpec org.apache.texera.web.resource.CollaborationResourceSpec org.apache.texera.web.WebsocketInputSpec" ``` - `TexeraWebSocketRequestSpec`: 12/12 passed - `CollabWebSocketMessageSpec`: 11/11 passed (positive zero-arg subtypes, payload roundtrips, unknown type ID rejection, missing type rejection) - `CollaborationResourceSpec`: 28/28 passed - `WebsocketInputSpec`: 6/6 passed - Total: 57/57 tests succeeded. - **Code formatting & linting**: ```bash sbt "WorkflowExecutionService/scalafmtCheck" "WorkflowExecutionService/Test/scalafmtCheck" sbt "WorkflowExecutionService/scalafix --check" "WorkflowExecutionService/Test/scalafix --check" ``` All passed cleanly. - **Net change**: 23 files changed, +140 / -418 (net -278 lines overall; production code net -396 lines). ### Was this PR authored or co-authored using generative AI tooling? No. --- .../model/collab/event/CollabWebSocketEvent.scala | 7 ++ .../web/model/collab/event/CommandEvent.scala | 22 ---- .../web/model/collab/event/LockGrantedEvent.scala | 22 ---- .../web/model/collab/event/LockRejectedEvent.scala | 22 ---- .../web/model/collab/event/ReleaseLockEvent.scala | 22 ---- .../model/collab/event/RestoreVersionEvent.scala | 22 ---- .../model/collab/event/WorkflowAccessEvent.scala | 22 ---- .../model/collab/request/AcquireLockRequest.scala | 22 ---- .../collab/request/CollabWebSocketRequest.scala | 7 ++ .../web/model/collab/request/CommandRequest.scala | 22 ---- .../model/collab/request/HeartBeatRequest.scala | 22 ---- .../collab/request/RestoreVersionRequest.scala | 22 ---- .../web/model/collab/request/TryLockRequest.scala | 22 ---- .../web/model/collab/request/WIdRequest.scala | 22 ---- .../model/websocket/request/HeartBeatRequest.scala | 22 ---- .../web/model/websocket/request/RetryRequest.scala | 22 ---- .../model/websocket/request/SkipTupleRequest.scala | 22 ---- .../websocket/request/TexeraWebSocketRequest.scala | 8 ++ .../request/WorkflowCheckpointRequest.scala | 22 ---- .../websocket/request/WorkflowKillRequest.scala | 22 ---- .../websocket/request/WorkflowPauseRequest.scala | 22 ---- .../websocket/request/WorkflowResumeRequest.scala | 22 ---- .../model/collab/CollabWebSocketMessageSpec.scala | 118 +++++++++++++++++++++ 23 files changed, 140 insertions(+), 418 deletions(-) diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/event/CollabWebSocketEvent.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/event/CollabWebSocketEvent.scala index afc3a2df9f..2d2b5f8fce 100644 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/event/CollabWebSocketEvent.scala +++ b/amber/src/main/scala/org/apache/texera/web/model/collab/event/CollabWebSocketEvent.scala @@ -36,3 +36,10 @@ import org.apache.texera.web.model.collab.response.HeartBeatResponse ) ) trait CollabWebSocketEvent {} + +case class CommandEvent(commandMessage: String) extends CollabWebSocketEvent +case class LockGrantedEvent() extends CollabWebSocketEvent +case class LockRejectedEvent() extends CollabWebSocketEvent +case class ReleaseLockEvent() extends CollabWebSocketEvent +case class RestoreVersionEvent() extends CollabWebSocketEvent +case class WorkflowAccessEvent(workflowReadonly: Boolean) extends CollabWebSocketEvent diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/event/CommandEvent.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/event/CommandEvent.scala deleted file mode 100644 index d42aa3e081..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/event/CommandEvent.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.event - -case class CommandEvent(commandMessage: String) extends CollabWebSocketEvent diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/event/LockGrantedEvent.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/event/LockGrantedEvent.scala deleted file mode 100644 index 73930ba086..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/event/LockGrantedEvent.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.event - -case class LockGrantedEvent() extends CollabWebSocketEvent diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/event/LockRejectedEvent.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/event/LockRejectedEvent.scala deleted file mode 100644 index 227a186640..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/event/LockRejectedEvent.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.event - -case class LockRejectedEvent() extends CollabWebSocketEvent diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/event/ReleaseLockEvent.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/event/ReleaseLockEvent.scala deleted file mode 100644 index f7e4975013..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/event/ReleaseLockEvent.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.event - -case class ReleaseLockEvent() extends CollabWebSocketEvent diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/event/RestoreVersionEvent.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/event/RestoreVersionEvent.scala deleted file mode 100644 index 2e2dec5db8..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/event/RestoreVersionEvent.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.event - -case class RestoreVersionEvent() extends CollabWebSocketEvent diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/event/WorkflowAccessEvent.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/event/WorkflowAccessEvent.scala deleted file mode 100644 index 5b4523337a..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/event/WorkflowAccessEvent.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.event - -case class WorkflowAccessEvent(workflowReadonly: Boolean) extends CollabWebSocketEvent diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/request/AcquireLockRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/request/AcquireLockRequest.scala deleted file mode 100644 index 2bea78f53d..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/request/AcquireLockRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.request - -case class AcquireLockRequest() extends CollabWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/request/CollabWebSocketRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/request/CollabWebSocketRequest.scala index f8f1de5220..0cfdb29b2f 100644 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/request/CollabWebSocketRequest.scala +++ b/amber/src/main/scala/org/apache/texera/web/model/collab/request/CollabWebSocketRequest.scala @@ -34,3 +34,10 @@ import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo} ) ) trait CollabWebSocketRequest {} + +case class AcquireLockRequest() extends CollabWebSocketRequest +case class CommandRequest(commandMessage: String) extends CollabWebSocketRequest +case class HeartBeatRequest() extends CollabWebSocketRequest +case class RestoreVersionRequest() extends CollabWebSocketRequest +case class TryLockRequest() extends CollabWebSocketRequest +case class WIdRequest(wId: Int) extends CollabWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/request/CommandRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/request/CommandRequest.scala deleted file mode 100644 index 798d38d410..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/request/CommandRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.request - -case class CommandRequest(commandMessage: String) extends CollabWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/request/HeartBeatRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/request/HeartBeatRequest.scala deleted file mode 100644 index ffeb81df76..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/request/HeartBeatRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.request - -case class HeartBeatRequest() extends CollabWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/request/RestoreVersionRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/request/RestoreVersionRequest.scala deleted file mode 100644 index ce05116a3c..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/request/RestoreVersionRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.request - -case class RestoreVersionRequest() extends CollabWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/request/TryLockRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/request/TryLockRequest.scala deleted file mode 100644 index 05c35ad245..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/request/TryLockRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.request - -case class TryLockRequest() extends CollabWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/collab/request/WIdRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/collab/request/WIdRequest.scala deleted file mode 100644 index c90912b6ec..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/collab/request/WIdRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.collab.request - -case class WIdRequest(wId: Int) extends CollabWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/HeartBeatRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/websocket/request/HeartBeatRequest.scala deleted file mode 100644 index 712aa98773..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/HeartBeatRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.websocket.request - -case class HeartBeatRequest() extends TexeraWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/RetryRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/websocket/request/RetryRequest.scala deleted file mode 100644 index 6a0bfba039..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/RetryRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.websocket.request - -case class RetryRequest(workers: Seq[String]) extends TexeraWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/SkipTupleRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/websocket/request/SkipTupleRequest.scala deleted file mode 100644 index 11f9a3e63f..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/SkipTupleRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.websocket.request - -case class SkipTupleRequest(workerIds: Array[String]) extends TexeraWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/TexeraWebSocketRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/websocket/request/TexeraWebSocketRequest.scala index a6153cad5e..5a1575df72 100644 --- a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/TexeraWebSocketRequest.scala +++ b/amber/src/main/scala/org/apache/texera/web/model/websocket/request/TexeraWebSocketRequest.scala @@ -44,3 +44,11 @@ import org.apache.texera.web.model.websocket.request.python.{ ) ) trait TexeraWebSocketRequest {} + +case class HeartBeatRequest() extends TexeraWebSocketRequest +case class RetryRequest(workers: Seq[String]) extends TexeraWebSocketRequest +case class SkipTupleRequest(workerIds: Array[String]) extends TexeraWebSocketRequest +case class WorkflowCheckpointRequest() extends TexeraWebSocketRequest +case class WorkflowKillRequest() extends TexeraWebSocketRequest +case class WorkflowPauseRequest() extends TexeraWebSocketRequest +case class WorkflowResumeRequest() extends TexeraWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowCheckpointRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowCheckpointRequest.scala deleted file mode 100644 index 79c82a25a4..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowCheckpointRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.websocket.request - -case class WorkflowCheckpointRequest() extends TexeraWebSocketRequest() diff --git a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowKillRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowKillRequest.scala deleted file mode 100644 index da5adfe294..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowKillRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.websocket.request - -case class WorkflowKillRequest() extends TexeraWebSocketRequest() diff --git a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowPauseRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowPauseRequest.scala deleted file mode 100644 index 0eb23d6b21..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowPauseRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.websocket.request - -case class WorkflowPauseRequest() extends TexeraWebSocketRequest diff --git a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowResumeRequest.scala b/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowResumeRequest.scala deleted file mode 100644 index 669202616e..0000000000 --- a/amber/src/main/scala/org/apache/texera/web/model/websocket/request/WorkflowResumeRequest.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.texera.web.model.websocket.request - -case class WorkflowResumeRequest() extends TexeraWebSocketRequest diff --git a/amber/src/test/scala/org/apache/texera/web/model/collab/CollabWebSocketMessageSpec.scala b/amber/src/test/scala/org/apache/texera/web/model/collab/CollabWebSocketMessageSpec.scala new file mode 100644 index 0000000000..02ed4d9306 --- /dev/null +++ b/amber/src/test/scala/org/apache/texera/web/model/collab/CollabWebSocketMessageSpec.scala @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.web.model.collab + +import com.fasterxml.jackson.databind.exc.InvalidTypeIdException +import org.apache.texera.amber.util.JSONUtils.objectMapper +import org.apache.texera.web.model.collab.event._ +import org.apache.texera.web.model.collab.request._ +import org.apache.texera.web.model.collab.response.HeartBeatResponse +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +/** + * Pins the Jackson polymorphic wire contract for collaboration WebSocket messages. + * + * Both [[CollabWebSocketRequest]] and [[CollabWebSocketEvent]] carry `@JsonTypeInfo` + * on the "type" property with unqualified class names as wire IDs. + */ +class CollabWebSocketMessageSpec extends AnyFlatSpec with Matchers { + + private def readRequest(json: String): CollabWebSocketRequest = + objectMapper.readValue(json, classOf[CollabWebSocketRequest]) + + private def readEvent(json: String): CollabWebSocketEvent = + objectMapper.readValue(json, classOf[CollabWebSocketEvent]) + + private def write(obj: AnyRef): String = + objectMapper.writeValueAsString(obj) + + "CollabWebSocketRequest" should "deserialize zero-arg request subtypes" in { + readRequest("""{"type":"AcquireLockRequest"}""") shouldBe AcquireLockRequest() + readRequest("""{"type":"TryLockRequest"}""") shouldBe TryLockRequest() + readRequest("""{"type":"HeartBeatRequest"}""") shouldBe HeartBeatRequest() + readRequest("""{"type":"RestoreVersionRequest"}""") shouldBe RestoreVersionRequest() + } + + it should "deserialize and serialize CommandRequest with string payload" in { + val json = """{"type":"CommandRequest","commandMessage":"user-edit-op"}""" + val req = readRequest(json).asInstanceOf[CommandRequest] + req.commandMessage shouldBe "user-edit-op" + val roundTrip = readRequest(write(req)).asInstanceOf[CommandRequest] + roundTrip.commandMessage shouldBe "user-edit-op" + } + + it should "deserialize and serialize WIdRequest with integer payload" in { + val json = """{"type":"WIdRequest","wId":42}""" + val req = readRequest(json).asInstanceOf[WIdRequest] + req.wId shouldBe 42 + val roundTrip = readRequest(write(req)).asInstanceOf[WIdRequest] + roundTrip.wId shouldBe 42 + } + + it should "reject unknown request type IDs" in { + val ex = intercept[InvalidTypeIdException](readRequest("""{"type":"NonExistentRequest"}""")) + ex.getMessage should include("NonExistentRequest") + } + + it should "reject request frames without type property" in { + val ex = intercept[InvalidTypeIdException](readRequest("""{"commandMessage":"hello"}""")) + ex.getMessage should include("type") + } + + "CollabWebSocketEvent" should "deserialize zero-arg event subtypes" in { + readEvent("""{"type":"LockGrantedEvent"}""") shouldBe LockGrantedEvent() + readEvent("""{"type":"LockRejectedEvent"}""") shouldBe LockRejectedEvent() + readEvent("""{"type":"ReleaseLockEvent"}""") shouldBe ReleaseLockEvent() + readEvent("""{"type":"RestoreVersionEvent"}""") shouldBe RestoreVersionEvent() + } + + it should "deserialize and serialize CommandEvent with string payload" in { + val json = """{"type":"CommandEvent","commandMessage":"state-synced"}""" + val evt = readEvent(json).asInstanceOf[CommandEvent] + evt.commandMessage shouldBe "state-synced" + val roundTrip = readEvent(write(evt)).asInstanceOf[CommandEvent] + roundTrip.commandMessage shouldBe "state-synced" + } + + it should "deserialize and serialize WorkflowAccessEvent with boolean flag" in { + val json = """{"type":"WorkflowAccessEvent","workflowReadonly":true}""" + val evt = readEvent(json).asInstanceOf[WorkflowAccessEvent] + evt.workflowReadonly shouldBe true + val roundTrip = readEvent(write(evt)).asInstanceOf[WorkflowAccessEvent] + roundTrip.workflowReadonly shouldBe true + } + + it should "deserialize HeartBeatResponse" in { + val json = """{"type":"HeartBeatResponse"}""" + val evt = readEvent(json).asInstanceOf[HeartBeatResponse] + evt shouldBe a[HeartBeatResponse] + } + + it should "reject unknown event type IDs" in { + val ex = intercept[InvalidTypeIdException](readEvent("""{"type":"UnknownCollabEvent"}""")) + ex.getMessage should include("UnknownCollabEvent") + } + + it should "reject event frames without type property" in { + val ex = intercept[InvalidTypeIdException](readEvent("""{"workflowReadonly":false}""")) + ex.getMessage should include("type") + } +}
