mengw15 commented on code in PR #7760: URL: https://github.com/apache/texera/pull/7760#discussion_r3810308262
########## file-service/src/main/scala/org/apache/texera/service/resource/ManagedResource.scala: ########## @@ -0,0 +1,64 @@ +/* + * 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 org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum +import org.apache.texera.dao.jooq.generated.tables.Dataset.DATASET +import org.apache.texera.dao.jooq.generated.tables.DatasetUserAccess.DATASET_USER_ACCESS +import org.apache.texera.dao.jooq.generated.tables.records.{DatasetRecord, DatasetUserAccessRecord} +import org.jooq.{Record, Table, TableField} + +/** + * Describes one user-owned, name-scoped, shareable resource by the columns that carry its + * identity, ownership, and per-user grants. + * + * @param label how the resource is named in user-facing messages ("dataset", "model") + * @tparam R record type of the resource table + * @tparam A record type of the companion user-access table + */ +case class ManagedResource[R <: Record, A <: Record]( Review Comment: Naming nit. `ManagedResource` reads as though it covers any shareable resource, but requiring owner, name and public flag as columns of one table fits only datasets and models — `workflow` keeps ownership in `workflow_of_user`, and `project` and `workflow_computing_unit` have no `is_public`. A name closer to what it actually models would carry that. ########## common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/model/LakeFSFileDocument.scala: ########## @@ -36,21 +37,50 @@ object LakeFSFileDocument { // In the local development or other architectures, this token can be empty. lazy val userJwtToken: String = sys.env.getOrElse(EnvironmentalVariable.ENV_USER_JWT_TOKEN, "").trim + + private lazy val datasetPresignEndpoint: String = + sys.env + .getOrElse( + EnvironmentalVariable.ENV_FILE_SERVICE_GET_DATASET_PRESIGNED_URL_ENDPOINT, + "http://localhost:9092/api/dataset/presign-download" + ) + .trim + + private lazy val modelPresignEndpoint: String = + sys.env + .getOrElse( + EnvironmentalVariable.ENV_FILE_SERVICE_GET_MODEL_PRESIGNED_URL_ENDPOINT, + "http://localhost:9092/api/model/presign-download" + ) + .trim + + /** + * The file-service presign-download endpoint serving this resource type. Each resource type + * owns an endpoint because they enforce different access control + */ + def presignEndpointOf(resourceType: ResourceType.Value): String = + resourceType match { + case ResourceType.Datasets => datasetPresignEndpoint + case ResourceType.Models => modelPresignEndpoint + } } /** * A read-only document over a single file stored in a LakeFS repository, addressed by the URI - * {scheme}:///{repositoryName}/{versionHash}/{fileRelativePath}. This is the shared behavior - * for every versioned-file resource (datasets, models, …): the file bytes are fetched via a - * presigned URL, falling back to a direct LakeFS fetch. + * {scheme}:///{repositoryName}/{versionHash}/{fileRelativePath}. + * + * Every versioned-file resource (datasets, models, …) reads its files the same way — fetch the + * bytes through a presigned URL, falling back to a direct LakeFS fetch * - * @param uri the resolved {scheme}:///{repositoryName}/{versionHash}/{file} URI - * @param presignEndpoint the file-service presign-download endpoint for this resource kind + * @param uri the resolved {scheme}:///{repositoryName}/{versionHash}/{file} URI + * @param resourceType which resource this file belongs to, selecting the presign endpoint */ -private[storage] abstract class LakeFSFileDocument(uri: URI, presignEndpoint: String) +private[storage] class LakeFSFileDocument(uri: URI, val resourceType: ResourceType.Value) Review Comment: Good simplification — the presign endpoint really was all the two subclasses carried. Could the description cover it? It's half the diff and outside `file-service`, so a later reader sees `DatasetFileDocument` and `ModelFileDocument` deleted four days after #6860 added them with nothing saying why. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
