mengw15 commented on code in PR #9356: URL: https://github.com/apache/texera/pull/9356#discussion_r4550602165
########## result-service/build.sbt: ########## @@ -0,0 +1,87 @@ +// 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. + +import scala.collection.Seq + +name := "result-service" + + +enablePlugins(JavaAppPackaging) + +// Ship LICENSE-binary, NOTICE-binary, DISCLAIMER, and the licenses/ +// directory at the top of the Universal dist zip. +// See project/AddMetaInfLicenseFiles.scala. +Universal / mappings := AddMetaInfLicenseFiles.distMappings( + (Universal / mappings).value, + (ThisBuild / baseDirectory).value, + baseDirectory.value / "LICENSE-binary", + baseDirectory.value / "NOTICE-binary" +) + +// Enable semanticdb for Scalafix +ThisBuild / semanticdbEnabled := true +ThisBuild / semanticdbVersion := scalafixSemanticdb.revision + +// Manage dependency conflicts by always using the latest revision +ThisBuild / conflictManager := ConflictManager.latestRevision + +// Restrict parallel execution of tests to avoid conflicts +Global / concurrentRestrictions += Tags.limit(Tags.Test, 1) Review Comment: Every module's build.sbt sets this line, file-service's included, so the build already runs one test at a time and this copy changes nothing on its own. Scoping it would be a change across all of them. ########## result-service/src/main/scala/org/apache/texera/service/ResultService.scala: ########## @@ -0,0 +1,95 @@ +/* + * 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 + +import com.fasterxml.jackson.module.scala.DefaultScalaModule +import com.typesafe.scalalogging.LazyLogging +import io.dropwizard.configuration.{EnvironmentVariableSubstitutor, SubstitutingSourceProvider} +import io.dropwizard.core.Application +import io.dropwizard.core.setup.{Bootstrap, Environment} +import org.apache.texera.auth.{AuthFeatures, RequestLoggingFilter, RoleAnnotationEnforcer} +import org.apache.texera.common.config.StorageConfig +import org.apache.texera.dao.SqlServer +import org.apache.texera.service.resource.{HealthCheckResource, ResultResource} +import org.eclipse.jetty.server.session.SessionHandler + +import java.nio.file.Path + +/** + * Serves execution results, so they can be read without a computing unit (#5363). Results live + * in Iceberg tables behind Lakekeeper, which manages table metadata but cannot return rows, so + * this service does the reading, the way file-service does in front of LakeFS. + */ +class ResultService extends Application[ResultServiceConfiguration] with LazyLogging { + override def initialize(bootstrap: Bootstrap[ResultServiceConfiguration]): Unit = { + // enable environment variable substitution in YAML config + bootstrap.setConfigurationSourceProvider( + new SubstitutingSourceProvider( + bootstrap.getConfigurationSourceProvider, + new EnvironmentVariableSubstitutor(false) + ) + ) + // Register Scala module to Dropwizard default object mapper + bootstrap.getObjectMapper.registerModule(DefaultScalaModule) + } + + override def run(configuration: ResultServiceConfiguration, environment: Environment): Unit = { + // Bridge this service's logs to the OTel collector under its own service.name. + org.apache.texera.observability.OtelInit.init("result-service") + // Serve backend at /api + environment.jersey.setUrlPattern("/api/*") + SqlServer.initConnection( + StorageConfig.jdbcUrl, + StorageConfig.jdbcUsername, + StorageConfig.jdbcPassword + ) + + environment.jersey.register(classOf[SessionHandler]) Review Comment: Every service registers it this way, file-service and the CU's ComputingUnitMaster included, so I'd keep this one in line. Dropping it would be a change across all of them. ########## result-service/src/main/scala/org/apache/texera/service/resource/ResultResource.scala: ########## @@ -0,0 +1,266 @@ +/* + * 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 com.fasterxml.jackson.databind.node.ObjectNode +import io.dropwizard.auth.Auth +import jakarta.annotation.security.RolesAllowed +import jakarta.ws.rs.core.MediaType +import jakarta.ws.rs.{ + BadRequestException, + DefaultValue, + ForbiddenException, + GET, + NotFoundException, + Path, + PathParam, + Produces, + QueryParam, + ServiceUnavailableException +} +import org.apache.texera.amber.core.storage.model.VirtualDocument +import org.apache.texera.amber.core.storage.{ + DocumentFactory, + ExecutionResultUris, + WarehouseReadGuard, + WarehouseUnavailableException +} +import org.apache.texera.amber.core.tuple.{Attribute, Schema, Tuple, TupleUtils} +import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity, OperatorIdentity} +import org.apache.texera.amber.core.workflow.PortIdentity +import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde +import org.apache.texera.auth.SessionUser +import org.apache.texera.auth.util.WorkflowAccess +import org.apache.texera.dao.SqlServer +import org.apache.texera.dao.jooq.generated.Tables.{ + OPERATOR_PORT_EXECUTIONS, + WORKFLOW_EXECUTIONS, + WORKFLOW_VERSION +} +import org.apache.texera.dao.jooq.generated.enums.OutputModeEnum +import org.apache.texera.service.resource.ResultResource._ +import org.jooq.DSLContext + +import java.net.URI +import java.util.Locale +import scala.jdk.CollectionConverters._ + +object ResultResource { + // workflow_executions.status of a run that has ended: COMPLETED, FAILED and KILLED. + private val FinishedStatuses: java.util.List[java.lang.Short] = + List[java.lang.Short](3.toShort, 4.toShort, 5.toShort).asJava + + // A page is read into memory in a service everyone shares, so one request must not be able to + // ask for a whole table. This is far above the rows a result panel shows at once. + private val MaxPageSize = 1000 + + private def context: DSLContext = SqlServer.getInstance().createDSLContext() + + case class LatestExecution(eid: Integer) + + /** One result of an execution. `outputMode` and `rowCount` are null where not recorded. */ + case class PortResult( + operatorId: String, + portIndex: Int, + outputMode: String, + rowCount: java.lang.Long + ) + Review Comment: Switched to `Option` in 4f02e8c42, as file-service's `Contributor.uid` does. The JSON still carries null for a value that was not recorded. -- 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]
