venkata91 commented on code in PR #57016: URL: https://github.com/apache/spark/pull/57016#discussion_r3532031935
########## sql/connect/server/src/main/scala/org/apache/spark/status/api/v1/connect/ConnectResource.scala: ########## @@ -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. + */ + +package org.apache.spark.status.api.v1.connect + +import jakarta.ws.rs._ +import jakarta.ws.rs.core.MediaType + +import org.apache.spark.sql.connect.ui.{ExecutionInfo, SessionInfo, SparkConnectServerAppStatusStore} +import org.apache.spark.status.api.v1.{BaseAppResource, NotFoundException} + +@Produces(Array(MediaType.APPLICATION_JSON)) +private[v1] class ConnectResource extends BaseAppResource { + + @GET + @Path("sessions") + def sessionList(): Seq[SessionData] = withUI { ui => + val store = new SparkConnectServerAppStatusStore(ui.store.store) + store.getSessionList.map(prepareSessionData) + } + + @GET + @Path("sessions/{sessionId}") + def session(@PathParam("sessionId") sessionId: String): SessionData = withUI { ui => + val store = new SparkConnectServerAppStatusStore(ui.store.store) + store + .getSession(sessionId) + .map(prepareSessionData) + .getOrElse(throw new NotFoundException("unknown session id: " + sessionId)) + } + + @GET + @Path("operations") + def operationList(): Seq[ExecutionData] = withUI { ui => + val store = new SparkConnectServerAppStatusStore(ui.store.store) + store.getExecutionList.map(prepareExecutionData) + } + + @GET + @Path("operations/{jobTag}") Review Comment: Good catch, thanks — fixed. The operation-detail route now keys on `operationId` (a validated UUID, so always path-safe) instead of the `jobTag`: - Added a secondary `@KVIndex("operationId")` on `ExecutionInfo` and a `getExecutionByOperationId` lookup on the store. - `GET .../connect/operations/{operationId}` now looks up by that index; `jobTag` is still returned in the DTO for reference. - Regression test added with `userId = "tenant/alice"` (`ConnectResourceWithActualDataSuite`): it drives a real query, confirms the returned `jobTag` contains the raw `/`, and that the operation is still fetchable via its `operationId`. A store-level test in `ConnectResourceSuite` exercises the new index directly (also covering the History Server replay path, which uses the same `SparkConnectServerAppStatusStore`). Implementation note: I used a method-based `@JsonIgnore @KVIndex("operationId") def` rather than annotating the constructor `val`, because Scala targets a param-`val` annotation at the parameter (not the field/getter), so the KVStore reflection doesn't pick it up — the tests caught that. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
