DRILL-5923: Display name for query state

closes #1021


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/30da051b
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/30da051b
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/30da051b

Branch: refs/heads/master
Commit: 30da051b968926b7ead388b7df56c402dbdd5cb8
Parents: ed6c4bc
Author: Prasad Nagaraj Subramanya <prasadn...@gmail.com>
Authored: Thu Nov 9 15:00:15 2017 -0800
Committer: Arina Ielchiieva <arina.yelchiy...@gmail.com>
Committed: Mon Nov 13 11:45:20 2017 +0200

----------------------------------------------------------------------
 .../server/rest/profile/ProfileResources.java   |  8 ++--
 .../exec/server/rest/profile/ProfileUtil.java   | 48 ++++++++++++++++++++
 .../server/rest/profile/ProfileWrapper.java     |  4 ++
 .../src/main/resources/rest/profile/profile.ftl |  3 +-
 4 files changed, 59 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/30da051b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileResources.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileResources.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileResources.java
index 875c96e..14056b0 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileResources.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileResources.java
@@ -63,7 +63,7 @@ import com.google.common.collect.Lists;
 @Path("/")
 @RolesAllowed(DrillUserPrincipal.AUTHENTICATED_ROLE)
 public class ProfileResources {
-  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ProfileResources.class);
+  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ProfileResources.class);
 
   @Inject UserAuthEnabled authEnabled;
   @Inject WorkManager work;
@@ -217,7 +217,8 @@ public class ProfileResources {
             runningQueries.add(
                 new ProfileInfo(work.getContext().getConfig(),
                     runningEntry.getKey(), profile.getStart(), 
System.currentTimeMillis(),
-                    profile.getForeman().getAddress(), profile.getQuery(), 
profile.getState().name(),
+                    profile.getForeman().getAddress(), profile.getQuery(),
+                    ProfileUtil.getQueryStateDisplayName(profile.getState()),
                     profile.getUser(), profile.getTotalCost(), 
profile.getQueueName()));
           }
         } catch (Exception e) {
@@ -247,7 +248,8 @@ public class ProfileResources {
             finishedQueries.add(
                 new ProfileInfo(work.getContext().getConfig(),
                     profileEntry.getKey(), profile.getStart(), 
profile.getEnd(),
-                    profile.getForeman().getAddress(), profile.getQuery(), 
profile.getState().name(),
+                    profile.getForeman().getAddress(), profile.getQuery(),
+                    ProfileUtil.getQueryStateDisplayName(profile.getState()),
                     profile.getUser(), profile.getTotalCost(), 
profile.getQueueName()));
           }
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/drill/blob/30da051b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileUtil.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileUtil.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileUtil.java
new file mode 100644
index 0000000..cfc7977
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileUtil.java
@@ -0,0 +1,48 @@
+/*
+ * 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.drill.exec.server.rest.profile;
+
+import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState;
+
+public class ProfileUtil {
+  // Display names for QueryState enum in UserBitShared.proto
+  private static final String[] queryStateDisplayNames = {
+    "Starting", // STARTING = 0
+    "Running", // RUNNING = 1
+    "Succeeded", // COMPLETED = 2
+    "Canceled", // CANCELED = 3
+    "Failed", // FAILED = 4
+    "CancellationRequested", // CANCELLATION_REQUESTED = 5
+    "Enqueued" // ENQUEUED = 6
+  };
+
+
+  /**
+   * Utility to return display name for query state
+   * @param queryState
+   * @return display string for query state
+   */
+  public final static String getQueryStateDisplayName(QueryState queryState) {
+    int queryStateOrdinal = queryState.getNumber();
+    if (queryStateOrdinal >= queryStateDisplayNames.length) {
+      return queryState.name();
+    } else {
+      return queryStateDisplayNames[queryStateOrdinal];
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/30da051b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java
index ef9ccc3..3a7d432 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java
@@ -148,6 +148,10 @@ public class ProfileWrapper {
     return id;
   }
 
+  public String getQueryStateDisplayName() {
+    return ProfileUtil.getQueryStateDisplayName(profile.getState());
+  }
+
   public String getPlanningDuration() {
     //Check if Planning End is known
     if (profile.getPlanEnd() > 0L) {

http://git-wip-us.apache.org/repos/asf/drill/blob/30da051b/exec/java-exec/src/main/resources/rest/profile/profile.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/profile/profile.ftl 
b/exec/java-exec/src/main/resources/rest/profile/profile.ftl
index 889e17a..ff78da3 100644
--- a/exec/java-exec/src/main/resources/rest/profile/profile.ftl
+++ b/exec/java-exec/src/main/resources/rest/profile/profile.ftl
@@ -135,6 +135,7 @@ table.sortable thead .sorting_desc { background-image: 
url("/static/img/black-de
 
   <#assign queueName = model.getProfile().getQueueName() />
   <#assign queued = queueName != "" && queueName != "-" />
+
   <div class="page-header"></div>
   <h3>Query Profile</h3>
   <div class="panel-group" id="query-profile-accordion">
@@ -162,7 +163,7 @@ table.sortable thead .sorting_desc { background-image: 
url("/static/img/black-de
             </thead>
             <tbody>
               <tr>
-                  <td>${model.getProfile().getState().name()}</td>
+                  <td>${model.getQueryStateDisplayName()}</td>
                   <td>${model.getProfile().getForeman().getAddress()}</td>
                   <td>${model.getProfile().getTotalFragments()}</td>
      <#if queued>

Reply via email to