[ 
https://issues.apache.org/jira/browse/PHOENIX-2186?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14705645#comment-14705645
 ] 

ASF GitHub Bot commented on PHOENIX-2186:
-----------------------------------------

Github user ndimiduk commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/111#discussion_r37573414
  
    --- Diff: 
phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/TraceServlet.java
 ---
    @@ -0,0 +1,160 @@
    +/*
    + * 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.phoenix.tracingwebapp.http;
    +
    +import java.io.IOException;
    +import java.io.PrintWriter;
    +
    +import javax.servlet.ServletException;
    +import javax.servlet.http.HttpServlet;
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.codehaus.jackson.map.ObjectMapper;
    +
    +import java.sql.Connection;
    +import java.sql.DriverManager;
    +import java.sql.ResultSet;
    +import java.sql.SQLException;
    +import java.sql.PreparedStatement;
    +import java.sql.Statement;
    +import java.util.List;
    +import java.util.Map;
    +
    +/**
    + *
    + * Server to show trace information
    + *
    + *
    + * @since 4.4.1
    + */
    +public class TraceServlet extends HttpServlet {
    +
    +  protected Connection con;
    +  protected String DEFAULT_LIMIT = "25";
    +  protected String DEFAULT_COUNTBY = "hostname";
    +  protected String LOGIC_AND = "AND";
    +  protected String LOGIC_OR = "OR";
    +  protected String PHOENIX_HOST = "localhost";
    +  protected String TRACING_TABLE = "SYSTEM.TRACING_STATS";
    +  protected int PHOENIX_PORT = 2181;
    +  
    +  
    +  protected void doGet(HttpServletRequest request, HttpServletResponse 
response)
    +      throws ServletException, IOException {
    +    
    +    //reading url params
    +    String action = request.getParameter("action");
    +    String limit = request.getParameter("limit");
    +    String traceid = request.getParameter("traceid");
    +    String parentid = request.getParameter("parentid");
    +    String jsonObject = "{}";
    +    if ("getall".equals(action)) {
    +      jsonObject = getAll(limit);
    +    } else if ("getCount".equals(action)) {
    +      jsonObject = getCount("description");
    +    } else if ("getDistribution".equals(action)) {
    +      jsonObject = getCount(DEFAULT_COUNTBY);
    +    } else if ("searchTrace".equals(action)) {
    +      jsonObject = searchTrace(parentid, traceid, LOGIC_OR);
    +    } else {
    +      jsonObject = "{ \"Server\": \"Phoenix Tracing Web App\", \"API 
version\": 0.1 }";
    +    }
    +    //response send as json
    +    response.setContentType("application/json");    
    +    String output = jsonObject;
    +    PrintWriter out = response.getWriter();
    +    out.print(output);
    +    out.flush();
    +
    +  }
    +
    +  //get all trace results with limit count
    +  protected String getAll(String limit) {
    +    String json = null;
    +    if(limit == null) {
    +      limit = DEFAULT_LIMIT;
    +    }
    +    String sqlQuery = "SELECT * FROM " + TRACING_TABLE + " LIMIT "+limit;
    +    json = getResults(sqlQuery);    
    +    return getJson(json);
    +  }
    +
    +  //get count on traces can pick on param to count
    +  protected String getCount(String countby) {
    +    String json = null;
    +    if(countby == null) {
    +      countby = DEFAULT_COUNTBY;
    +    }
    +    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) {
    +    String json = null;
    +    String query = null;
    +    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);
    +  }
    +
    +  //return json string
    +  protected String getJson(String json) {
    +    String output = json.toString().replace("_id\":", "_id\":\"")
    +        .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){
    +    json = "{error:true,msg:'SQL was null'}";
    --- End diff --
    
    indentation and formatting here is off.


> Creating backend services for the Phoenix Tracing Web App
> ---------------------------------------------------------
>
>                 Key: PHOENIX-2186
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2186
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: Nishani 
>            Assignee: Nishani 
>
> This will include the following components.
> Main class 
> Pom file
> Launch script 
> Backend trace service API



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to