You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by el...@apache.org on 2018/07/25 22:35:13 UTC
[50/50] [abbrv] phoenix git commit: PHOENIX-4817 Fixed Phoenix
Tracing Web Application (fixed check null, trace table name, webapp path,
column names) and traceserver.py
PHOENIX-4817 Fixed Phoenix Tracing Web Application (fixed check null, trace table name, webapp path, column names) and traceserver.py
Closes #311
Signed-off-by: Josh Elser <el...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/8a874cc9
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8a874cc9
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8a874cc9
Branch: refs/heads/master
Commit: 8a874cc95c3365a566453fb9ebbe8e31b6d51b38
Parents: f2781d4
Author: Vitaly Monastyrev <VM...@domain.corp>
Authored: Tue Jul 24 12:14:12 2018 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Jul 25 14:07:01 2018 -0400
----------------------------------------------------------------------
bin/traceserver.py | 6 +-
.../apache/phoenix/tracingwebapp/http/Main.java | 13 +--
.../tracingwebapp/http/TraceServlet.java | 87 +++++++++++---------
3 files changed, 62 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a874cc9/bin/traceserver.py
----------------------------------------------------------------------
diff --git a/bin/traceserver.py b/bin/traceserver.py
index 665099e..62e168c 100755
--- a/bin/traceserver.py
+++ b/bin/traceserver.py
@@ -116,8 +116,10 @@ else:
# " -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n " + \
# " -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true" + \
-java_cmd = '%(java)s $PHOENIX_OPTS ' + \
- '-cp ' + hbase_config_path + os.pathsep + phoenix_utils.phoenix_traceserver_jar + os.pathsep + phoenix_utils.phoenix_client_jar + \
+java_cmd = '%(java)s ' + \
+ '-cp ' + hbase_config_path + os.pathsep + phoenix_utils.phoenix_traceserver_jar + os.pathsep + \
+ phoenix_utils.phoenix_client_jar + os.pathsep + phoenix_utils.phoenix_queryserver_jar + \
+ os.pathsep + phoenix_utils.hadoop_classpath + \
" -Dproc_phoenixtraceserver" + \
" -Dlog4j.configuration=file:" + os.path.join(phoenix_utils.current_dir, "log4j.properties") + \
" -Dpsql.root.logger=%(root_logger)s" + \
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a874cc9/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/Main.java
----------------------------------------------------------------------
diff --git a/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/Main.java b/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/Main.java
index 5875fc1..249f8e6 100755
--- a/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/Main.java
+++ b/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/Main.java
@@ -47,6 +47,7 @@ public final class Main extends Configured implements Tool {
public static final String TRACE_SERVER_HTTP_JETTY_HOME_KEY =
"phoenix.traceserver.http.home";
public static final String DEFAULT_HTTP_HOME = "/";
+ public static final String DEFAULT_WEBAPP_DIR_LOCATION = "src/main/webapp";
public static void main(String[] args) throws Exception {
int ret = ToolRunner.run(HBaseConfiguration.create(), new Main(), args);
@@ -62,15 +63,17 @@ public final class Main extends Configured implements Tool {
final String home = getConf().get(TRACE_SERVER_HTTP_JETTY_HOME_KEY,
DEFAULT_HTTP_HOME);
//setting up the embedded server
- ProtectionDomain domain = Main.class.getProtectionDomain();
- URL location = domain.getCodeSource().getLocation();
- String webappDirLocation = location.toString().split("target")[0] +"src/main/webapp";
Server server = new Server(port);
WebAppContext root = new WebAppContext();
+ URL webAppDir = Thread.currentThread().getContextClassLoader().getResource(DEFAULT_WEBAPP_DIR_LOCATION);
+ if (webAppDir == null) {
+ throw new RuntimeException(String.format("No %s directory was found into the JAR file", DEFAULT_WEBAPP_DIR_LOCATION));
+ }
+
root.setContextPath(home);
- root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml");
- root.setResourceBase(webappDirLocation);
+ root.setDescriptor(DEFAULT_WEBAPP_DIR_LOCATION + "/WEB-INF/web.xml");
+ root.setResourceBase(webAppDir.toURI().toString());
root.setParentLoaderPriority(true);
server.setHandler(root);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a874cc9/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/TraceServlet.java
----------------------------------------------------------------------
diff --git a/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/TraceServlet.java b/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/TraceServlet.java
index c20b20d..98250e8 100755
--- a/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/TraceServlet.java
+++ b/phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/TraceServlet.java
@@ -24,8 +24,11 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
import org.codehaus.jackson.map.ObjectMapper;
-import org.apache.phoenix.metrics.MetricInfo;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
@@ -42,14 +45,21 @@ public class TraceServlet extends HttpServlet {
private static Connection con;
protected String DEFAULT_LIMIT = "25";
protected String DEFAULT_COUNTBY = "hostname";
+ protected String DESCRIPTION_COUNTBY = "description";
protected String LOGIC_AND = "AND";
protected String LOGIC_OR = "OR";
protected String TRACING_TABLE = "SYSTEM.TRACING_STATS";
-
+ @Override
+ public void init() {
+ Configuration conf = HBaseConfiguration.create();
+ TRACING_TABLE =
+ conf.get(QueryServices.TRACING_STATS_TABLE_NAME_ATTRIB,
+ QueryServicesOptions.DEFAULT_TRACING_STATS_TABLE_NAME);
+ }
protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
+ throws ServletException, IOException {
//reading url params
String action = request.getParameter("action");
@@ -60,7 +70,7 @@ public class TraceServlet extends HttpServlet {
if ("getall".equals(action)) {
jsonObject = getAll(limit);
} else if ("getCount".equals(action)) {
- jsonObject = getCount("description");
+ jsonObject = getCount(DESCRIPTION_COUNTBY);
} else if ("getDistribution".equals(action)) {
jsonObject = getCount(DEFAULT_COUNTBY);
} else if ("searchTrace".equals(action)) {
@@ -98,33 +108,36 @@ public class TraceServlet extends HttpServlet {
if(countby == null) {
countby = DEFAULT_COUNTBY;
}
- // Throws exception if the column not present in the trace table.
- MetricInfo.getColumnName(countby.toLowerCase());
String sqlQuery = "SELECT "+countby+", COUNT(*) AS count FROM " + TRACING_TABLE + " GROUP BY "+countby+" HAVING COUNT(*) > 1 ";
json = getResults(sqlQuery);
return json;
}
//search the trace over parent id or trace id
- protected String searchTrace(String parentId, String traceId,String logic) {
+ protected String searchTrace(String parentId, String traceId, String logic) {
+
String json = null;
String query = null;
// Check the parent Id, trace id type or long or not.
try {
+ if (parentId != null) {
Long.parseLong(parentId);
+ }
+ if (traceId != null) {
Long.parseLong(traceId);
+ }
} catch (NumberFormatException e) {
- throw new RuntimeException("The passed parentId/traceId is not a number.", e);
+ throw new RuntimeException("The passed parentId/traceId is not a number.", e);
}
- if(!logic.equals(LOGIC_AND) || !logic.equals(LOGIC_OR)) {
- throw new RuntimeException("Wrong logical operator passed to the query. Only "+ LOGIC_AND+","+LOGIC_OR+" are allowed.") ;
+ if (logic != null && !logic.equals(LOGIC_AND) && !logic.equals(LOGIC_OR)) {
+ throw new RuntimeException("Wrong logical operator passed to the query. Only " + LOGIC_AND + "," + LOGIC_OR + " are allowed.");
}
- if(parentId != null && traceId != null) {
- query = "SELECT * FROM " + TRACING_TABLE + " WHERE parent_id="+parentId+" "+logic+" trace_id="+traceId;
- }else if (parentId != null && traceId == null) {
- query = "SELECT * FROM " + TRACING_TABLE + " WHERE parent_id="+parentId;
- }else if(parentId == null && traceId != null) {
- query = "SELECT * FROM " + TRACING_TABLE + " WHERE trace_id="+traceId;
+ if (parentId != null && traceId != null) {
+ query = "SELECT * FROM " + TRACING_TABLE + " WHERE parent_id=" + parentId + " " + logic + " trace_id=" + traceId;
+ } else if (parentId != null && traceId == null) {
+ query = "SELECT * FROM " + TRACING_TABLE + " WHERE parent_id=" + parentId;
+ } else if (parentId == null && traceId != null) {
+ query = "SELECT * FROM " + TRACING_TABLE + " WHERE trace_id=" + traceId;
}
json = getResults(query);
return getJson(json);
@@ -133,37 +146,37 @@ public class TraceServlet extends HttpServlet {
//return json string
protected String getJson(String json) {
String output = json.toString().replace("_id\":", "_id\":\"")
- .replace(",\"hostname", "\",\"hostname")
- .replace(",\"parent", "\",\"parent")
- .replace(",\"end", "\",\"end");
+ .replace(",\"hostname", "\",\"hostname")
+ .replace(",\"parent", "\",\"parent")
+ .replace(",\"end", "\",\"end");
return output;
}
//get results with passing sql query
protected String getResults(String sqlQuery) {
String json = null;
- if(sqlQuery == null){
+ if (sqlQuery == null) {
json = "{error:true,msg:'SQL was null'}";
- }else{
- try {
- con = ConnectionFactory.getConnection();
- EntityFactory nutrientEntityFactory = new EntityFactory(con,sqlQuery);
- List<Map<String, Object>> nutrients = nutrientEntityFactory
- .findMultiple();
- ObjectMapper mapper = new ObjectMapper();
- json = mapper.writeValueAsString(nutrients);
- } catch (Exception e) {
- json = "{error:true,msg:'Serrver Error:"+e.getMessage()+"'}";
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- json = "{error:true,msg:'SQL Serrver Error:"+e.getMessage()+"'}";
+ } else {
+ try {
+ con = ConnectionFactory.getConnection();
+ EntityFactory nutrientEntityFactory = new EntityFactory(con, sqlQuery);
+ List<Map<String, Object>> nutrients = nutrientEntityFactory
+ .findMultiple();
+ ObjectMapper mapper = new ObjectMapper();
+ json = mapper.writeValueAsString(nutrients);
+ } catch (Exception e) {
+ json = "{error:true,msg:'Server Error:" + e.getMessage() + "'}";
+ } finally {
+ if (con != null) {
+ try {
+ con.close();
+ } catch (SQLException e) {
+ json = "{error:true,msg:'SQL Serrver Error:" + e.getMessage() + "'}";
+ }
}
}
}
- }
return json;
}
}