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-9431-6597c1b2cbb446da4cae4c8b6bbc0dafcf010232
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 6a19cba6373d903071bf99348da462cafd057531
Author: Matthew B. <[email protected]>
AuthorDate: Mon Nov 16 09:39:49 2026 +0000

    refactor(file-service): share presign/multipart endpoints in a trait (#9431)
    
    ### What changes were proposed in this PR?
    - Added a `ResourceUploadSupport` trait holding the presigned-download
    and multipart-upload delegations to `ResourceUploadService`,
    parameterized by an abstract `resourceStorage` descriptor.
    - `DatasetResource` and `ModelResource` mix in the trait and supply
    `resourceStorage` (`ResourceStorage.Dataset` / `ResourceStorage.Model`);
    their five duplicated private helpers are removed.
    - Behavior is unchanged: the JAX-RS endpoint methods and annotations
    stay on each resource and call the inherited helpers.
    ### Any related issues, documentation, discussions?
    Closes: #9428
    ### How was this PR tested?
    - Run `sbt "FileService/compile"` and `sbt "FileService/Test/compile"`,
    expect both to succeed (they pass locally).
    - The runtime resource specs need Postgres and LakeFS, unavailable
    locally; confirm the file-service job stays green in CI.
    ### Was this PR authored or co-authored using generative AI tooling?
    Co-authored with Claude Opus 4.8 in compliance with ASF
---
 .../texera/service/resource/DatasetResource.scala  | 45 +----------
 .../texera/service/resource/ModelResource.scala    | 48 +-----------
 .../service/resource/ResourceUploadSupport.scala   | 89 ++++++++++++++++++++++
 3 files changed, 95 insertions(+), 87 deletions(-)

diff --git 
a/file-service/src/main/scala/org/apache/texera/service/resource/DatasetResource.scala
 
b/file-service/src/main/scala/org/apache/texera/service/resource/DatasetResource.scala
index 7dcf0574ef..5c2f8dfacf 100644
--- 
a/file-service/src/main/scala/org/apache/texera/service/resource/DatasetResource.scala
+++ 
b/file-service/src/main/scala/org/apache/texera/service/resource/DatasetResource.scala
@@ -261,7 +261,7 @@ object DatasetResource {
 
 @Produces(Array(MediaType.APPLICATION_JSON, "image/jpeg", "application/pdf"))
 @Path("/dataset")
-class DatasetResource extends LazyLogging {
+class DatasetResource extends LazyLogging with ResourceUploadSupport {
   private val ERR_USER_HAS_NO_ACCESS_TO_DATASET_MESSAGE = "User has no access 
to this dataset"
   private val ERR_DATASET_VERSION_NOT_FOUND_MESSAGE = "The version of the 
dataset not found"
   private val EXPIRATION_MINUTES = 5
@@ -274,6 +274,8 @@ class DatasetResource extends LazyLogging {
 
   private val resourceType = ResourceType.Dataset
 
+  override protected def resourceStorage = ResourceStorage.Dataset
+
   /**
     * The single read rule for a dataset: anonymous callers get public 
datasets only, a
     * signed-in caller goes through userHasReadAccess. Shared with 
getDashboardDataset
@@ -1117,20 +1119,6 @@ class DatasetResource extends LazyLogging {
     DatasetVersionRootFileNodesResponse(nodes, size)
   }
 
-  private def generatePresignedResponse(
-      encodedUrl: String,
-      repositoryName: String,
-      commitHash: String,
-      uid: Integer
-  ): Response =
-    ResourceUploadService.presignedUrlResponse(
-      ResourceStorage.Dataset,
-      encodedUrl,
-      repositoryName,
-      commitHash,
-      uid
-    )
-
   // === Multipart helpers ===
 
   private def getDatasetBy(ownerEmail: String, datasetName: String) = {
@@ -1148,33 +1136,6 @@ class DatasetResource extends LazyLogging {
     dataset
   }
 
-  private def listMultipartUploads(did: Integer, requesterUid: Int): Response =
-    ResourceUploadService.listUploads(ResourceStorage.Dataset, did, 
requesterUid)
-
-  private def initMultipartUpload(
-      did: Integer,
-      encodedFilePath: String,
-      fileSizeBytes: Optional[java.lang.Long],
-      partSizeBytes: Optional[java.lang.Long],
-      restart: Optional[java.lang.Boolean],
-      uid: Integer
-  ): Response =
-    ResourceUploadService.initUpload(
-      ResourceStorage.Dataset,
-      did,
-      encodedFilePath,
-      fileSizeBytes,
-      partSizeBytes,
-      restart,
-      uid
-    )
-
-  private def finishMultipartUpload(did: Integer, encodedFilePath: String, 
uid: Int): Response =
-    ResourceUploadService.finishUpload(ResourceStorage.Dataset, did, 
encodedFilePath, uid)
-
-  private def abortMultipartUpload(did: Integer, encodedFilePath: String, uid: 
Int): Response =
-    ResourceUploadService.abortUpload(ResourceStorage.Dataset, did, 
encodedFilePath, uid)
-
   /**
     * Updates the cover image for a dataset.
     *
diff --git 
a/file-service/src/main/scala/org/apache/texera/service/resource/ModelResource.scala
 
b/file-service/src/main/scala/org/apache/texera/service/resource/ModelResource.scala
index 979f414b75..66d24f3bfd 100644
--- 
a/file-service/src/main/scala/org/apache/texera/service/resource/ModelResource.scala
+++ 
b/file-service/src/main/scala/org/apache/texera/service/resource/ModelResource.scala
@@ -185,10 +185,12 @@ object ModelResource {
 
 @Produces(Array(MediaType.APPLICATION_JSON))
 @Path("/model")
-class ModelResource extends LazyLogging {
+class ModelResource extends LazyLogging with ResourceUploadSupport {
   private val ERR_USER_HAS_NO_ACCESS_TO_MODEL_MESSAGE = "User has no access to 
this model"
   private val ERR_MODEL_VERSION_NOT_FOUND_MESSAGE = "The version of the model 
not found"
 
+  override protected def resourceStorage = ResourceStorage.Model
+
   /**
     * Helper function to get the model from DB with additional information 
including
     * user access privilege and owner email
@@ -646,10 +648,6 @@ class ModelResource extends LazyLogging {
   // Presigned downloads
   // 
===========================================================================
 
-  /**
-    * Resolves a presign request against the model tables and wraps the signed 
URL.
-    * The resolution itself is shared with datasets; only the descriptor 
differs.
-    */
   /** Size of a model's LakeFS repository, or 0 if LakeFS cannot answer. */
   private def repositorySizeOrZero(model: Model): Long = {
     try {
@@ -664,20 +662,6 @@ class ModelResource extends LazyLogging {
     }
   }
 
-  private def generatePresignedResponse(
-      encodedUrl: String,
-      repositoryName: String,
-      commitHash: String,
-      uid: Integer
-  ): Response =
-    ResourceUploadService.presignedUrlResponse(
-      ResourceStorage.Model,
-      encodedUrl,
-      repositoryName,
-      commitHash,
-      uid
-    )
-
   @GET
   @RolesAllowed(Array("REGULAR", "ADMIN"))
   @Path("/presign-download")
@@ -1183,30 +1167,4 @@ class ModelResource extends LazyLogging {
     model
   }
 
-  private def listMultipartUploads(mid: Integer, requesterUid: Int): Response =
-    ResourceUploadService.listUploads(ResourceStorage.Model, mid, requesterUid)
-
-  private def initMultipartUpload(
-      mid: Integer,
-      encodedFilePath: String,
-      fileSizeBytes: Optional[java.lang.Long],
-      partSizeBytes: Optional[java.lang.Long],
-      restart: Optional[java.lang.Boolean],
-      uid: Integer
-  ): Response =
-    ResourceUploadService.initUpload(
-      ResourceStorage.Model,
-      mid,
-      encodedFilePath,
-      fileSizeBytes,
-      partSizeBytes,
-      restart,
-      uid
-    )
-
-  private def finishMultipartUpload(mid: Integer, encodedFilePath: String, 
uid: Int): Response =
-    ResourceUploadService.finishUpload(ResourceStorage.Model, mid, 
encodedFilePath, uid)
-
-  private def abortMultipartUpload(mid: Integer, encodedFilePath: String, uid: 
Int): Response =
-    ResourceUploadService.abortUpload(ResourceStorage.Model, mid, 
encodedFilePath, uid)
 }
diff --git 
a/file-service/src/main/scala/org/apache/texera/service/resource/ResourceUploadSupport.scala
 
b/file-service/src/main/scala/org/apache/texera/service/resource/ResourceUploadSupport.scala
new file mode 100644
index 0000000000..eaa16edd27
--- /dev/null
+++ 
b/file-service/src/main/scala/org/apache/texera/service/resource/ResourceUploadSupport.scala
@@ -0,0 +1,89 @@
+/*
+ * 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.service.resource
+
+import jakarta.ws.rs.core.Response
+import org.jooq.Record
+
+import java.util.Optional
+
+/**
+  * The presigned-download and multipart-upload delegations shared by every 
versioned
+  * file resource. DatasetResource and ModelResource each expose the same 
endpoints and
+  * forwarded them to [[ResourceUploadService]] with their own storage 
descriptor; the two
+  * copies differed only in that descriptor. A mixing-in resource supplies its
+  * [[ResourceStorage]] once and keeps the single-line endpoint methods that 
call these.
+  *
+  * The storage descriptor is held as an existential because the service 
methods abstract
+  * over its four record type parameters and use them only to type the 
descriptor argument.
+  */
+trait ResourceUploadSupport {
+
+  protected def resourceStorage: ResourceStorage[_ <: Record, _ <: Record, _ 
<: Record, _ <: Record]
+
+  protected def generatePresignedResponse(
+      encodedUrl: String,
+      repositoryName: String,
+      commitHash: String,
+      uid: Integer
+  ): Response =
+    ResourceUploadService.presignedUrlResponse(
+      resourceStorage,
+      encodedUrl,
+      repositoryName,
+      commitHash,
+      uid
+    )
+
+  protected def listMultipartUploads(resourceId: Integer, requesterUid: Int): 
Response =
+    ResourceUploadService.listUploads(resourceStorage, resourceId, 
requesterUid)
+
+  protected def initMultipartUpload(
+      resourceId: Integer,
+      encodedFilePath: String,
+      fileSizeBytes: Optional[java.lang.Long],
+      partSizeBytes: Optional[java.lang.Long],
+      restart: Optional[java.lang.Boolean],
+      uid: Integer
+  ): Response =
+    ResourceUploadService.initUpload(
+      resourceStorage,
+      resourceId,
+      encodedFilePath,
+      fileSizeBytes,
+      partSizeBytes,
+      restart,
+      uid
+    )
+
+  protected def finishMultipartUpload(
+      resourceId: Integer,
+      encodedFilePath: String,
+      uid: Int
+  ): Response =
+    ResourceUploadService.finishUpload(resourceStorage, resourceId, 
encodedFilePath, uid)
+
+  protected def abortMultipartUpload(
+      resourceId: Integer,
+      encodedFilePath: String,
+      uid: Int
+  ): Response =
+    ResourceUploadService.abortUpload(resourceStorage, resourceId, 
encodedFilePath, uid)
+}

Reply via email to