Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed 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 com.facebook.presto.server;
 
 
 
 import java.util.List;
 import java.util.Map;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.io.Resources.getResource;
 
 @Path("/")
 public class QueryExecutionResource
 {
     // synthetic task id used by the output buffer of the top task
     private static final TaskId OUTPUT_TASK_ID = new TaskId("output""buffer""id");
 
     private final QueryManager manager;
 
     @Inject
     public QueryExecutionResource(QueryManager manager)
     {
         checkNotNull(manager"manager is null");
         this. = manager;
     }
 
     @GET
     @Path("/ui/query-execution")
     public String getUi()
             throws IOException
     {
         return Resources.toString(getResource(getClass(), "query-execution.html"), .);
     }
 
     @GET
     @Path("/v1/query-execution/{queryId}")
     public Response getTaskInfo(@PathParam("queryId"String queryId)
     {
         QueryInfo query;
         try {
             query = .getQueryInfo(QueryId.valueOf(queryId));
         }
         catch (NoSuchElementException e) {
             return Response.status(..).build();
         }
 
         List<StageInfostages = collectStages(query.getOutputStage());
 
         List<Tasktasks = new ArrayList<>();
         List<Flowflows = new ArrayList<>();
         for (StageInfo stage : stages) {
             for (TaskInfo task : stage.getTasks()) {
                 int bufferedPages = 0;
                 for (BufferInfo bufferInfo : task.getOutputBuffers().getBuffers()) {
                     bufferedPages += bufferInfo.getBufferedPages();
 
                     if (!bufferInfo.getBufferId().equals()) {
                         flows.add(new Flow(
                                 task.getTaskId().toString(),
                                 bufferInfo.getBufferId().toString(),
                                 bufferInfo.getPagesSent(),
                                bufferInfo.getBufferedPages(),
                                bufferInfo.isFinished()));
                    }
                }
                long last = System.currentTimeMillis();
                if (task.getStats().getEndTime() != null) {
                    last = task.getStats().getEndTime().getMillis();
                }
                tasks.add(new Task(task.getTaskId().toString(),
                        task.getState().toString(),
                        task.getSelf().getHost(),
                        last - task.getStats().getCreateTime().getMillis(),
                        task.getStats().getTotalCpuTime().roundTo(.),
                        task.getStats().getTotalBlockedTime().roundTo(.),
                        task.getStats().getRawInputDataSize().roundTo(..),
                        task.getStats().getRawInputPositions(),
                        task.getStats().getOutputDataSize().roundTo(..),
                        task.getStats().getOutputPositions(),
                        task.getStats().getMemoryReservation().roundTo(..),
                        task.getStats().getQueuedDrivers(),
                        task.getStats().getRunningDrivers(),
                        task.getStats().getCompletedDrivers(),
                        bufferedPages));
            }
        }
        Map<StringObjectresult = ImmutableMap.<StringObject>builder()
                .put("tasks"tasks)
                .put("flows"flows)
                .build();
        return Response.ok(result).build();
    }
    private static List<StageInfocollectStages(StageInfo stage)
    {
        ImmutableList.Builder<StageInforesult = ImmutableList.builder();
        result.add(stage);
        for (StageInfo child : stage.getSubStages()) {
            result.addAll(collectStages(child));
        }
        return result.build();
    }
    public static class Flow
    {
        private final String from;
        private final String to;
        private final long pagesSent;
        private final int bufferedPages;
        private final boolean finished;
        public Flow(String fromString tolong pagesSentint bufferedPagesboolean finished)
        {
            this. = from;
            this. = to;
            this. = pagesSent;
            this. = bufferedPages;
            this. = finished;
        }
        @JsonProperty
        public String getFrom()
        {
            return ;
        }
        @JsonProperty
        public String getTo()
        {
            return ;
        }
        @JsonProperty
        public long getPagesSent()
        {
            return ;
        }
        @JsonProperty
        public int getBufferedPages()
        {
            return ;
        }
        @JsonProperty
        public boolean isFinished()
        {
            return ;
        }
    }
    public static class Task
    {
        private final String taskId;
        private final String state;
        private final String host;
        private final long uptime;
        private final long cpuMillis;
        private final long blockedMillis;
        private final long inputBytes;
        private final long inputRows;
        private final long outputBytes;
        private final long outputRows;
        private final long usedMemoryBytes;
        private final int queuedSplits;
        private final int runningSplits;
        private final int completedSplits;
        private final int bufferedPages;
        public Task(
                String taskId,
                String state,
                String host,
                long uptimeMillis,
                long cpuMillis,
                long blockedMillis,
                long inputBytes,
                long inputRows,
                long outputBytes,
                long outputRows,
                long usedMemoryBytes,
                int queuedSplits,
                int runningSplits,
                int completedSplits,
                int bufferedPages)
        {
            this. = taskId;
            this. = state;
            this. = host;
            this. = uptimeMillis;
            this. = cpuMillis;
            this. = blockedMillis;
            this. = inputBytes;
            this. = inputRows;
            this. = outputBytes;
            this. = outputRows;
            this. = usedMemoryBytes;
            this. = queuedSplits;
            this. = runningSplits;
            this. = completedSplits;
            this. = bufferedPages;
        }
        @JsonProperty
        public String getTaskId()
        {
            return ;
        }
        @JsonProperty
        public String getState()
        {
            return ;
        }
        @JsonProperty
        public String getHost()
        {
            return ;
        }
        @JsonProperty
        public long getUptime()
        {
            return ;
        }
        @JsonProperty
        public long getCpuMillis()
        {
            return ;
        }
        @JsonProperty
        public long getBlockedMillis()
        {
            return ;
        }
        @JsonProperty
        public long getInputBytes()
        {
            return ;
        }
        @JsonProperty
        public long getInputRows()
        {
            return ;
        }
        @JsonProperty
        public long getOutputBytes()
        {
            return ;
        }
        @JsonProperty
        public long getOutputRows()
        {
            return ;
        }
        @JsonProperty
        public long getUsedMemoryBytes()
        {
            return ;
        }
        @JsonProperty
        public int getQueuedSplits()
        {
            return ;
        }
        @JsonProperty
        public int getRunningSplits()
        {
            return ;
        }
        @JsonProperty
        public int getCompletedSplits()
        {
            return ;
        }
        @JsonProperty
        public int getBufferedPages()
        {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X