|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.spark.status.api.v1 |
| 18 | + |
| 19 | +import javax.ws.rs.core.MediaType |
| 20 | +import javax.ws.rs._ |
| 21 | + |
| 22 | +import org.apache.spark.SparkException |
| 23 | +import org.apache.spark.SparkException |
| 24 | + |
| 25 | +@Produces(Array(MediaType.APPLICATION_JSON)) |
| 26 | +private[v1] class StageTaskSummary(uiRoot: UIRoot) { |
| 27 | + |
| 28 | + @GET |
| 29 | + def stageData( |
| 30 | + @PathParam("appId") appId: String, |
| 31 | + @PathParam("stageId") stageId: Int, |
| 32 | + @PathParam("attemptId") attemptId: Int, |
| 33 | + @DefaultValue("0.05,0.25,0.5,0.75,0.95") @QueryParam("quantiles") quantileString: String |
| 34 | + ): TaskMetricDistributions = { |
| 35 | + uiRoot.withSparkUI(appId) { ui => |
| 36 | + val listener = ui.stagesTab.listener |
| 37 | + val stageAndStatus = AllStagesResource.stagesAndStatus(ui) |
| 38 | + val oneStage = stageAndStatus.flatMap { case (status, stages) => |
| 39 | + val matched = stages.find { stage => |
| 40 | + stage.stageId == stageId && stage.attemptId == attemptId |
| 41 | + } |
| 42 | + matched.map { status -> _ } |
| 43 | + }.headOption |
| 44 | + oneStage match { |
| 45 | + case Some((status, stageInfo)) => |
| 46 | + val stageUiData = listener.synchronized { |
| 47 | + listener.stageIdToData.get((stageInfo.stageId, stageInfo.attemptId)). |
| 48 | + getOrElse(throw new SparkException("failed to get full stage data for stage: " + |
| 49 | + stageInfo.stageId + ":" + stageInfo.attemptId) |
| 50 | + ) |
| 51 | + } |
| 52 | + val quantiles = quantileString.split(",").map{_.toDouble} |
| 53 | + println("quantiles = " + quantiles.mkString(",")) |
| 54 | + AllStagesResource.taskMetricDistributions(stageUiData.taskData.values, quantiles) |
| 55 | + case None => |
| 56 | + val stageAttempts = stageAndStatus.flatMap{ case (status, stages) => |
| 57 | + stages.filter { _.stageId == stageId }.map{_.attemptId} |
| 58 | + } |
| 59 | + if (stageAttempts.isEmpty) { |
| 60 | + throw new NotFoundException(s"unknown stage: $stageId") |
| 61 | + } else { |
| 62 | + throw new NotFoundException(s"unknown attempt for stage $stageId. " + |
| 63 | + s"Found attempts: ${stageAttempts.mkString("[", ",", "]")}") |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments