You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2016/04/25 17:14:42 UTC

[7/9] ambari git commit: AMBARI-16034. Incremental changes to LogSearch to bring it up to date in the trunk (Dharmesh Makwana via oleewere)

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDao.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDao.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDao.java
index 9703273..d144172 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDao.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDao.java
@@ -21,13 +21,19 @@ package org.apache.ambari.logsearch.dao;
 
 import javax.annotation.PostConstruct;
 
+import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
 import org.apache.ambari.logsearch.util.PropertiesUtil;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 @Component
 public class ServiceLogsSolrDao extends SolrDaoBase {
+
   static private Logger logger = Logger.getLogger(ServiceLogsSolrDao.class);
+  
+  public ServiceLogsSolrDao() {
+    super(LOG_TYPE.SERVICE);
+  }
 
   @PostConstruct
   public void postConstructor() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
index 228ddd1..147e148 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
@@ -27,8 +27,11 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.apache.ambari.logsearch.common.LogsearchContextUtil;
+import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
 import org.apache.ambari.logsearch.util.ConfigUtil;
 import org.apache.ambari.logsearch.util.JSONUtil;
+import org.apache.ambari.logsearch.util.RESTErrorUtil;
 import org.apache.ambari.logsearch.util.StringUtil;
 import org.apache.log4j.Logger;
 import org.apache.solr.client.solrj.SolrClient;
@@ -55,16 +58,21 @@ import org.springframework.beans.factory.annotation.Autowired;
 public abstract class SolrDaoBase {
   static private Logger logger = Logger.getLogger(SolrDaoBase.class);
 
-  static Logger logPerfomance = Logger
+  private static Logger logPerformance = Logger
     .getLogger("org.apache.ambari.logsearch.performance");
 
   private static final String ROUTER_FIELD = "_router_field_";
+ 
+  protected LOG_TYPE logType;
 
   @Autowired
   StringUtil stringUtil;
 
   @Autowired
   JSONUtil jsonUtil;
+  
+  @Autowired
+  RESTErrorUtil restErrorUtil;
 
   String collectionName = null;
   // List<String> collectionList = new ArrayList<String>();
@@ -81,6 +89,13 @@ public abstract class SolrDaoBase {
   private boolean populateFieldsThreadActive = false;
 
   int SETUP_RETRY_SECOND = 30;
+  
+  private boolean isZkhost=false;//by default its false
+  
+  //set logtype
+  public SolrDaoBase(LOG_TYPE logType) {
+    this.logType = logType;
+  }
 
   public SolrClient connectToSolr(String url, String zkHosts,
                                   String collection) throws Exception {
@@ -94,6 +109,7 @@ public abstract class SolrDaoBase {
         + solrDetail);
     }
     if (!stringUtil.isEmpty(zkHosts)) {
+      isZkhost=true;
       solrDetail = "zkHosts=" + zkHosts + ", collection=" + collection;
       logger.info("Using zookeepr. " + solrDetail);
       solrClouldClient = new CloudSolrClient(zkHosts);
@@ -170,51 +186,48 @@ public abstract class SolrDaoBase {
     return status;
   }
 
-  public void setupCollections(final String splitMode,
-                               final String configName, final int numberOfShards,
-                               final int replicationFactor) throws Exception {
-    setup_status = createCollectionsIfNeeded(splitMode, configName,
-      numberOfShards, replicationFactor);
-    logger.info("Setup status for " + collectionName + " is "
-      + setup_status);
-    if (!setup_status) {
-      // Start a background thread to do setup
-      Thread setupThread = new Thread("setup_collection_"
-        + collectionName) {
-        @Override
-        public void run() {
-          logger.info("Started monitoring thread to check availability of Solr server. collection="
-            + collectionName);
-          int retryCount = 0;
-          while (true) {
-            try {
-              Thread.sleep(SETUP_RETRY_SECOND);
-              retryCount++;
-              setup_status = createCollectionsIfNeeded(splitMode,
-                configName, numberOfShards,
-                replicationFactor);
-              if (setup_status) {
-                logger.info("Setup for collection "
-                  + collectionName
-                  + " is successful. Exiting setup retry thread");
+  public void setupCollections(final String splitMode, final String configName,
+      final int numberOfShards, final int replicationFactor) throws Exception {
+    if (isZkhost) {
+      setup_status = createCollectionsIfNeeded(splitMode, configName,
+          numberOfShards, replicationFactor);
+      logger.info("Setup status for " + collectionName + " is " + setup_status);
+      if (!setup_status) {
+        // Start a background thread to do setup
+        Thread setupThread = new Thread("setup_collection_" + collectionName) {
+          @Override
+          public void run() {
+            logger
+                .info("Started monitoring thread to check availability of Solr server. collection="
+                    + collectionName);
+            int retryCount = 0;
+            while (true) {
+              try {
+                Thread.sleep(SETUP_RETRY_SECOND);
+                retryCount++;
+                setup_status = createCollectionsIfNeeded(splitMode, configName,
+                    numberOfShards, replicationFactor);
+                if (setup_status) {
+                  logger.info("Setup for collection " + collectionName
+                      + " is successful. Exiting setup retry thread");
+                  break;
+                }
+              } catch (InterruptedException sleepInterrupted) {
+                logger.info("Sleep interrupted while setting up collection "
+                    + collectionName);
                 break;
+              } catch (Exception e) {
+                logger
+                    .error("Error setting up collection=" + collectionName, e);
               }
-            } catch (InterruptedException sleepInterrupted) {
-              logger.info("Sleep interrupted while setting up collection "
-                + collectionName);
-              break;
-            } catch (Exception e) {
-              logger.error("Error setting up collection="
-                + collectionName, e);
+              logger.error("Error setting collection. collection="
+                  + collectionName + ", retryCount=" + retryCount);
             }
-            logger.error("Error setting collection. collection="
-              + collectionName + ", retryCount=" + retryCount);
           }
-        }
-
-      };
-      setupThread.setDaemon(true);
-      setupThread.start();
+        };
+        setupThread.setDaemon(true);
+        setupThread.start();
+      }
     }
     populateSchemaFields();
   }
@@ -257,7 +270,7 @@ public abstract class SolrDaoBase {
       return allCollectionList;
     } catch (SolrException e) {
       logger.error(e);
-      return null;
+      return new ArrayList<String>();
     }
   }
 
@@ -420,7 +433,7 @@ public abstract class SolrDaoBase {
   }
 
   public QueryResponse process(SolrQuery solrQuery)
-    throws SolrServerException, IOException, SolrException {
+    throws SolrServerException, IOException {
     if (solrClient != null) {
       String event = solrQuery.get("event");
       solrQuery.remove("event");
@@ -428,7 +441,7 @@ public abstract class SolrDaoBase {
         METHOD.POST);
 
       if (event != null && !"/getLiveLogsCount".equalsIgnoreCase(event)) {
-        logPerfomance.info("\n Username :- "
+        logPerformance.info("\n Username :- "
           + LogsearchContextUtil.getCurrentUsername()
           + " Event :- " + event + " SolrQuery :- " + solrQuery
           + "\nQuery Time Execution :- "
@@ -438,14 +451,16 @@ public abstract class SolrDaoBase {
       }
       return queryResponse;
     } else {
-      return null;
+      throw restErrorUtil.createRESTException(
+          "Solr configuration improper for " + logType.getLabel() +" logs",
+          MessageEnums.ERROR_SYSTEM);
     }
   }
 
   public UpdateResponse addDocs(SolrInputDocument doc)
     throws SolrServerException, IOException, SolrException {
     UpdateResponse updateResoponse = solrClient.add(doc);
-    logPerfomance.info("\n Username :- "
+    logPerformance.info("\n Username :- "
       + LogsearchContextUtil.getCurrentUsername()
       + " Update Time Execution :- " + updateResoponse.getQTime()
       + " Total Time Elapsed is :- "
@@ -458,7 +473,7 @@ public abstract class SolrDaoBase {
     IOException, SolrException {
     UpdateResponse updateResoponse = solrClient.deleteByQuery(query);
     solrClient.commit();
-    logPerfomance.info("\n Username :- "
+    logPerformance.info("\n Username :- "
       + LogsearchContextUtil.getCurrentUsername()
       + " Remove Time Execution :- " + updateResoponse.getQTime()
       + " Total Time Elapsed is :- "
@@ -481,7 +496,7 @@ public abstract class SolrDaoBase {
           int retryCount = 0;
           while (true) {
             try {
-              Thread.sleep(SETUP_RETRY_SECOND);
+              Thread.sleep(SETUP_RETRY_SECOND * 1000);
               retryCount++;
               boolean _result = _populateSchemaFields();
               if (_result) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserConfigSolrDao.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserConfigSolrDao.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserConfigSolrDao.java
index 750cf07..b5c042d 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserConfigSolrDao.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserConfigSolrDao.java
@@ -21,6 +21,7 @@ package org.apache.ambari.logsearch.dao;
 
 import javax.annotation.PostConstruct;
 
+import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
 import org.apache.ambari.logsearch.util.PropertiesUtil;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
@@ -30,6 +31,10 @@ public class UserConfigSolrDao extends SolrDaoBase {
 
   static private Logger logger = Logger.getLogger(UserConfigSolrDao.class);
 
+  public UserConfigSolrDao() {
+    super(LOG_TYPE.SERVICE);
+  }
+
   @PostConstruct
   public void postConstructor() {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGenerator.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGenerator.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGenerator.java
new file mode 100644
index 0000000..92baaff
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGenerator.java
@@ -0,0 +1,414 @@
+/*
+ * 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.ambari.logsearch.graph;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.ambari.logsearch.common.LogSearchConstants;
+import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.ambari.logsearch.common.SearchCriteria;
+import org.apache.ambari.logsearch.dao.SolrDaoBase;
+import org.apache.ambari.logsearch.query.QueryGeneration;
+import org.apache.ambari.logsearch.util.ConfigUtil;
+import org.apache.ambari.logsearch.util.DateUtil;
+import org.apache.ambari.logsearch.util.RESTErrorUtil;
+import org.apache.ambari.logsearch.util.StringUtil;
+import org.apache.ambari.logsearch.view.VBarDataList;
+import org.apache.ambari.logsearch.view.VBarGraphData;
+import org.apache.ambari.logsearch.view.VNameValue;
+import org.apache.log4j.Logger;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.response.FacetField;
+import org.apache.solr.client.solrj.response.FacetField.Count;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.RangeFacet;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.SimpleOrderedMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class GraphDataGenerator extends GraphDataGeneratorBase {
+
+  @Autowired
+  StringUtil stringUtil;
+
+  @Autowired
+  QueryGeneration queryGenerator;
+
+  @Autowired
+  RESTErrorUtil restErrorUtil;
+
+  @Autowired
+  DateUtil dateUtil;
+
+  private static Logger logger = Logger.getLogger(GraphDataGenerator.class);
+
+  /**
+   *
+   * @param searchCriteria
+   * @param solrDaoBase
+   * @param solrQuery
+   * @return
+   */
+  public VBarDataList getAnyGraphData(SearchCriteria searchCriteria,
+      SolrDaoBase solrDaoBase, SolrQuery solrQuery) {
+    // X axis credentials
+    String xAxisField = (String) searchCriteria.getParamValue("xAxis");
+    String stackField = (String) searchCriteria.getParamValue("stackBy");
+    String from = (String) searchCriteria.getParamValue("from");
+    String to = (String) searchCriteria.getParamValue("to");
+    String unit = (String) searchCriteria.getParamValue("unit");
+    String suffix = (String) searchCriteria.getParamValue("suffix");
+    String typeXAxis = ConfigUtil.schemaFieldsName.get(xAxisField + suffix);
+    typeXAxis = (stringUtil.isEmpty(typeXAxis)) ? "string" : typeXAxis;
+
+    // Y axis credentials
+    String yAxisField = (String) searchCriteria.getParamValue("yAxis");
+    // add updated typeXAxis as a type parameter
+    searchCriteria.addParam("type", typeXAxis);
+    String fieldTime = (String) searchCriteria.getParamValue("fieldTime");
+    // decide graph type based on user request parameter
+    GRAPH_TYPE garphType = getGraphType(searchCriteria);
+    switch (garphType) {
+    case NORMAL_GRAPH:
+      return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase,
+          typeXAxis, fieldTime, solrQuery);
+    case RANGE_NON_STACK_GRAPH:
+      return rangeNonStackGraph(xAxisField, yAxisField, from, to, unit,
+          solrDaoBase, typeXAxis, fieldTime, solrQuery);
+    case NON_RANGE_STACK_GRAPH:
+      return nonRangeStackGraph(xAxisField, yAxisField, stackField, from, to,
+          solrDaoBase, typeXAxis, fieldTime, solrQuery);
+    case RANGE_STACK_GRAPH:
+      return rangeStackGraph(xAxisField, yAxisField, stackField, from, to,
+          unit, solrDaoBase, typeXAxis, fieldTime, solrQuery);
+    default:
+      logger.warn("Invalid graph type :" + garphType.name());
+      return null;
+    }
+  }
+
+  private GRAPH_TYPE getGraphType(SearchCriteria searchCriteria) {
+    // default graph type is unknown
+    GRAPH_TYPE graphType = GRAPH_TYPE.UNKNOWN;
+    // X axis credentials
+    String xAxisField = (String) searchCriteria.getParamValue("xAxis");
+    String stackField = (String) searchCriteria.getParamValue("stackBy");
+    String from = (String) searchCriteria.getParamValue("from");
+    String to = (String) searchCriteria.getParamValue("to");
+    String xType = (String) searchCriteria.getParamValue("type");
+    if (xType != null) {
+      // Y axis credentials
+      String yAxisField = (String) searchCriteria.getParamValue("yAxis");
+      if (stringUtil.isEmpty(xAxisField) || stringUtil.isEmpty(yAxisField)) {
+        graphType = GRAPH_TYPE.UNKNOWN;
+      } else if (stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
+          && !stringUtil.isEmpty(from)
+          && !(xType.contains("date") || xType.contains("time"))) {
+        // Normal Graph Type
+        graphType = GRAPH_TYPE.NORMAL_GRAPH;
+      } else if (stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
+          && !stringUtil.isEmpty(from)
+          && (xType.contains("date") || xType.contains("time"))) {
+        // Range(Non-Stack) Graph Type
+        graphType = GRAPH_TYPE.RANGE_NON_STACK_GRAPH;
+      } else if (!stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
+          && !stringUtil.isEmpty(from)
+          && !(xType.contains("date") || xType.contains("time"))) {
+        // Non-Range Stack Graph Type
+        graphType = GRAPH_TYPE.NON_RANGE_STACK_GRAPH;
+      } else if (!stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
+          && !stringUtil.isEmpty(from)
+          && (xType.contains("date") || xType.contains("time"))) {
+        // Range Stack GraphType
+        graphType = GRAPH_TYPE.RANGE_STACK_GRAPH;
+      }
+    }
+    return graphType;
+  }
+
+  @SuppressWarnings("unchecked")
+  private VBarDataList normalGraph(String xAxisField, String yAxisField, String from,
+      String to, SolrDaoBase solrDaoBase, String typeXAxis, String fieldTime,
+      SolrQuery solrQuery) {
+    VBarDataList dataList = new VBarDataList();
+    Collection<VBarGraphData> vBarGraphDatas = new ArrayList<VBarGraphData>();
+    VBarGraphData vBarGraphData = new VBarGraphData();
+    Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
+    queryGenerator.setMainQuery(solrQuery, null);
+    queryGenerator.setSingleIncludeFilter(solrQuery, fieldTime, "[" + from
+        + " TO " + to + "]");
+    if (typeXAxis.contains("string") || typeXAxis.contains("key_lower_case")
+        || typeXAxis.contains("text")) {
+      queryGenerator.setFacetField(solrQuery, xAxisField);
+      try {
+        QueryResponse response = solrDaoBase.process(solrQuery);
+        if (response != null && response.getResults() != null) {
+          long count = response.getResults().getNumFound();
+          if (count > 0) {
+            FacetField facetField = response.getFacetField(xAxisField);
+            if (facetField != null) {
+              List<Count> countValues = facetField.getValues();
+              if (countValues != null) {
+                for (Count countValue : countValues) {
+                  if (countValue != null) {
+                    VNameValue vNameValue = new VNameValue();
+                    vNameValue.setName(countValue.getName());
+                    vNameValue.setValue("" + countValue.getCount());
+                    vNameValues.add(vNameValue);
+                  }
+                }
+              }
+              vBarGraphData.setName(xAxisField);
+              vBarGraphDatas.add(vBarGraphData);
+              dataList.setGraphData(vBarGraphDatas);
+            }
+          }
+        }
+        if (xAxisField.equalsIgnoreCase(LogSearchConstants.SOLR_LEVEL)) {
+          List<String> logLevels = new ArrayList<String>();
+          logLevels.add(LogSearchConstants.FATAL);
+          logLevels.add(LogSearchConstants.ERROR);
+          logLevels.add(LogSearchConstants.WARN);
+          logLevels.add(LogSearchConstants.INFO);
+          logLevels.add(LogSearchConstants.DEBUG);
+          logLevels.add(LogSearchConstants.TRACE);
+          Collection<VNameValue> sortedVNameValues = new ArrayList<VNameValue>();
+          for (String level : logLevels) {
+            VNameValue value = new VNameValue();
+            value.setName(level);
+            String val = "0";
+            for (VNameValue valueLevel : vNameValues) {
+              if (valueLevel.getName().equalsIgnoreCase(level)) {
+                val = valueLevel.getValue();
+                break;
+              }
+            }
+            value.setValue(val);
+            sortedVNameValues.add(value);
+          }
+          vBarGraphData.setDataCounts(sortedVNameValues);
+        } else {
+          vBarGraphData.setDataCounts(vNameValues);
+        }
+        return dataList;
+      } catch (SolrException | SolrServerException | IOException e) {
+        String query = solrQuery != null ? solrQuery.toQueryString() : "";
+        logger.error("Got exception for solr query :" + query,
+            e.getCause());
+      }
+    } else {
+      queryGenerator.setRowCount(solrQuery, 0);
+      String yAxis = yAxisField.contains("count") ? "sum" : yAxisField;
+      String jsonQuery = queryGenerator.buildJSONFacetAggregatedFuncitonQuery(
+          yAxis, xAxisField);
+      queryGenerator.setJSONFacet(solrQuery, jsonQuery);
+      try {
+        QueryResponse response = solrDaoBase.process(solrQuery);
+        SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
+            .getResponse().get("facets");
+        if (jsonFacetResponse.toString().equals("{count=0}")){
+          return dataList;
+        }
+        VNameValue value = new VNameValue();
+        String sum = (String) jsonFacetResponse.getVal(1);
+        value.setName(xAxisField);
+        value.setValue(sum != null ? sum.substring(0, sum.indexOf(".")) : "");
+        vNameValues.add(value);
+        vBarGraphData.setDataCounts(vNameValues);
+        vBarGraphData.setName(xAxisField);
+        vBarGraphDatas.add(vBarGraphData);
+        dataList.setGraphData(vBarGraphDatas);
+        return dataList;
+      } catch (SolrException | SolrServerException | IOException e) {
+        String query = solrQuery != null ? solrQuery.toQueryString() : "";
+        logger.error("Got exception for solr query :" + query,
+            e.getCause());
+      }
+    }
+    return null;
+  }
+
+  @SuppressWarnings("unchecked")
+  private VBarDataList nonRangeStackGraph(String xAxisField, String yAxisField,
+      String stackField, String from, String to, SolrDaoBase solrDaoBase,
+      String typeXAxis, String fieldTime, SolrQuery solrQuery) {
+    VBarDataList dataList = new VBarDataList();
+    Collection<VBarGraphData> vGraphData = new ArrayList<VBarGraphData>();
+    String mainQuery = queryGenerator.buildInclusiveRangeFilterQuery(fieldTime,
+        from, to);
+    queryGenerator.setMainQuery(solrQuery, mainQuery);
+    queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
+    String jsonQuery = "";
+    if (isTypeNumber(typeXAxis)) {
+      String function = (yAxisField.contains("count")) ? "sum" : yAxisField;
+      jsonQuery = queryGenerator.buidlJSONFacetRangeQueryForNumber(stackField,
+          xAxisField, function);
+    } else {
+      jsonQuery = queryGenerator.buildJsonFacetTermsRangeQuery(stackField,
+          xAxisField);
+    }
+    try {
+      queryGenerator.setJSONFacet(solrQuery, jsonQuery);
+      dataList.setGraphData(vGraphData);
+      QueryResponse response = solrDaoBase.process(solrQuery);
+      if (response == null) {
+        response = new QueryResponse();
+      }
+      Long count = response.getResults().getNumFound();
+      if (count <= 0) {
+        return dataList;
+      }
+      SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
+          .getResponse().get("facets");
+      if (jsonFacetResponse == null
+          || jsonFacetResponse.toString().equals("{count=0}")) {
+        return dataList;
+      }
+      extractNonRangeStackValuesFromBucket(jsonFacetResponse, stackField,
+          vGraphData, typeXAxis);
+      if (LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(stackField)
+          && LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(xAxisField)) {
+        Collection<VBarGraphData> levelVGraphData = dataList.getGraphData();
+        List<String> logLevels = new ArrayList<String>();
+        logLevels.add(LogSearchConstants.FATAL);
+        logLevels.add(LogSearchConstants.ERROR);
+        logLevels.add(LogSearchConstants.WARN);
+        logLevels.add(LogSearchConstants.INFO);
+        logLevels.add(LogSearchConstants.DEBUG);
+        logLevels.add(LogSearchConstants.TRACE);
+        for (VBarGraphData garphData : levelVGraphData) {
+          Collection<VNameValue> valueList = garphData.getDataCount();
+          Collection<VNameValue> valueListSorted = new ArrayList<VNameValue>();
+          for (String level : logLevels) {
+            String val = "0";
+            for (VNameValue value : valueList) {
+              if (value.getName().equalsIgnoreCase(level)) {
+                val = value.getValue();
+                break;
+              }
+            }
+            VNameValue v1 = new VNameValue();
+            v1.setName(level.toUpperCase());
+            v1.setValue(val);
+            valueListSorted.add(v1);
+          }
+          garphData.setDataCounts(valueListSorted);
+        }
+      }
+      return dataList;
+    } catch (SolrException | IOException | SolrServerException e) {
+      String query = solrQuery != null ? solrQuery.toQueryString() : "";
+      logger.error("Got exception for solr query :" + query,
+          e.getCause());
+      throw restErrorUtil.createRESTException(MessageEnums.DATA_NOT_FOUND
+          .getMessage().getMessage(), MessageEnums.DATA_NOT_FOUND);
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  private VBarDataList rangeNonStackGraph(String xAxisField, String yAxisField,
+      String from, String to, String unit, SolrDaoBase solrDaoBase,
+      String typeXAxis, String fieldTime, SolrQuery solrQuery) {
+    VBarDataList dataList = new VBarDataList();
+    Collection<VBarGraphData> vBarGraphDatas = new ArrayList<VBarGraphData>();
+    VBarGraphData vBarGraphData = new VBarGraphData();
+    Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
+    queryGenerator.setMainQuery(solrQuery, null);
+    if (isTypeNumber(typeXAxis)) {
+      queryGenerator.setSingleRangeFilter(solrQuery, fieldTime, from, to);
+      return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase,
+          typeXAxis, fieldTime, solrQuery);
+    } else {
+      try {
+        queryGenerator.setFacetRange(solrQuery, xAxisField, from, to, unit);
+        QueryResponse response = solrDaoBase.process(solrQuery);
+        if (response != null) {
+          Long count = response.getResults().getNumFound();
+          if (count > 0) {
+            @SuppressWarnings("rawtypes")
+            List<RangeFacet> rangeFacet = response.getFacetRanges();
+            if (rangeFacet != null && rangeFacet.size() > 0) {
+              List<RangeFacet.Count> listCount = rangeFacet.get(0).getCounts();
+              if (listCount != null) {
+                for (RangeFacet.Count cnt : listCount) {
+                  VNameValue vNameValue = new VNameValue();
+                  vNameValue.setName(cnt.getValue());
+                  vNameValue.setValue("" + cnt.getCount());
+                  vNameValues.add(vNameValue);
+                }
+                vBarGraphData.setDataCounts(vNameValues);
+                vBarGraphDatas.add(vBarGraphData);
+                vBarGraphData.setName(xAxisField);
+                dataList.setGraphData(vBarGraphDatas);
+              }
+            }
+          }
+        }
+        return dataList;
+      } catch (SolrException | SolrServerException | IOException e) {
+        logger.error("Got exception for solr query :" + solrQuery,
+            e.getCause());
+      }
+    }
+    return null;
+  }
+
+  @SuppressWarnings("unchecked")
+  private VBarDataList rangeStackGraph(String xAxisField, String yAxisField,
+      String stackField, String from, String to, String unit,
+      SolrDaoBase solrDaoBase, String typeXAxis, String fieldTime,
+      SolrQuery solrQuery) {
+    VBarDataList dataList = new VBarDataList();
+    List<VBarGraphData> histogramData = new ArrayList<VBarGraphData>();
+    queryGenerator.setMainQuery(solrQuery, null);
+    queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
+    String jsonHistogramQuery = queryGenerator
+        .buildJSONFacetTermTimeRangeQuery(stackField, xAxisField, from, to,
+            unit).replace("\\", "");
+    try {
+      solrQuery.set("json.facet", jsonHistogramQuery);
+      queryGenerator.setRowCount(solrQuery, 0);
+      QueryResponse response = solrDaoBase.process(solrQuery);
+      if (response != null) {
+        SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
+            .getResponse().get("facets");
+        if (jsonFacetResponse == null
+            || jsonFacetResponse.toString().equals("{count=0}")) {
+          // return
+          return dataList;
+        }
+        extractRangeStackValuesFromBucket(jsonFacetResponse, "x", "y",
+            histogramData);
+        dataList.setGraphData(histogramData);
+      }
+      return dataList;
+    } catch (SolrException | IOException | SolrServerException e) {
+      logger.error("Got exception for solr query :" + solrQuery,
+          e.getCause());
+    }
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java
index c32dc36..a813e96 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java
@@ -18,167 +18,263 @@
  */
 package org.apache.ambari.logsearch.graph;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
 
+import org.apache.ambari.logsearch.manager.MgrBase;
 import org.apache.ambari.logsearch.util.DateUtil;
+import org.apache.ambari.logsearch.util.StringUtil;
 import org.apache.ambari.logsearch.view.VBarGraphData;
 import org.apache.ambari.logsearch.view.VNameValue;
 import org.apache.solr.client.solrj.response.RangeFacet;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.ObjectWriter;
 import org.springframework.beans.factory.annotation.Autowired;
 
-public class GraphDataGeneratorBase {
+public class GraphDataGeneratorBase extends MgrBase {
+
 
   @Autowired
   DateUtil dateUtil;
 
-  @SuppressWarnings("unchecked")
-  protected void extractRangeStackValuesFromBucket(
-    SimpleOrderedMap<Object> jsonFacetResponse, String outerField,
-    String innerField, List<VBarGraphData> histogramData) {
-    NamedList<Object> stack = (NamedList<Object>) jsonFacetResponse
-      .get(outerField);
-    ArrayList<Object> stackBuckets = (ArrayList<Object>) stack
-      .get("buckets");
-    for (Object temp : stackBuckets) {
-      VBarGraphData vBarGraphData = new VBarGraphData();
+  @Autowired
+  StringUtil stringUtil;
 
-      SimpleOrderedMap<Object> level = (SimpleOrderedMap<Object>) temp;
-      String name = ((String) level.getVal(0)).toUpperCase();
-      vBarGraphData.setName(name);
+  private static String BUCKETS = "buckets";
+  
+  public static enum DATA_TYPE {
+    LONG {
+      @Override
+      String getType() {
+        return "long";
+      }
+    },
+    DOUBLE {
+      @Override
+      String getType() {
+        return "double";
+      }
+    },
+    FLOAT {
+      @Override
+      String getType() {
+        return "long";
+      }
+    },
+    INT {
+      @Override
+      String getType() {
+        return "long";
+      }
 
-      Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
-      vBarGraphData.setDataCounts(vNameValues);
-      ArrayList<Object> levelBuckets = (ArrayList<Object>) ((NamedList<Object>) level
-        .get(innerField)).get("buckets");
-      for (Object temp1 : levelBuckets) {
-        SimpleOrderedMap<Object> countValue = (SimpleOrderedMap<Object>) temp1;
-        String value = dateUtil
-          .convertDateWithMillisecondsToSolrDate((Date) countValue
-            .getVal(0));
+    };
+    abstract String getType();
+  }
 
-        String count = "" + countValue.getVal(1);
-        VNameValue vNameValue = new VNameValue();
-        vNameValue.setName(value);
-        vNameValue.setValue(count);
-        vNameValues.add(vNameValue);
+  public static enum GRAPH_TYPE {
+    UNKNOWN {
+      @Override
+      int getType() {
+        return 0;
+      }
+    },
+    NORMAL_GRAPH {
+      @Override
+      int getType() {
+        return 1;
+      }
+    },
+    RANGE_NON_STACK_GRAPH {
+      @Override
+      int getType() {
+        return 2;
+      }
+    },
+    NON_RANGE_STACK_GRAPH {
+      @Override
+      int getType() {
+        return 3;
+      }
+    },
+    RANGE_STACK_GRAPH {
+      @Override
+      int getType() {
+        return 4;
+      }
+    };
+    abstract int getType();
+  }
+
+  @SuppressWarnings("unchecked")
+  protected void extractRangeStackValuesFromBucket(
+      SimpleOrderedMap<Object> jsonFacetResponse, String outerField,
+      String innerField, List<VBarGraphData> histogramData) {
+    if (jsonFacetResponse != null) {
+      NamedList<Object> stack = (NamedList<Object>) jsonFacetResponse
+          .get(outerField);
+      if (stack != null) {
+        ArrayList<Object> stackBuckets = (ArrayList<Object>) stack.get(BUCKETS);
+        if (stackBuckets != null) {
+          for (Object stackBucket : stackBuckets) {
+            VBarGraphData vBarGraphData = new VBarGraphData();
+            SimpleOrderedMap<Object> level = (SimpleOrderedMap<Object>) stackBucket;
+            if (level != null) {
+              String name = level.getVal(0) != null ? level.getVal(0)
+                  .toString().toUpperCase() : "";
+              vBarGraphData.setName(name);
+              Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
+              NamedList<Object> innerFiledValue = (NamedList<Object>) level
+                  .get(innerField);
+              if (innerFiledValue != null) {
+                ArrayList<Object> levelBuckets = (ArrayList<Object>) innerFiledValue
+                    .get(BUCKETS);
+                if (levelBuckets != null) {
+                  for (Object levelBucket : levelBuckets) {
+                    SimpleOrderedMap<Object> countValue = (SimpleOrderedMap<Object>) levelBucket;
+                    if (countValue != null) {
+                      String innerName = dateUtil
+                          .convertDateWithMillisecondsToSolrDate((Date) countValue
+                              .getVal(0));
+                      String innerValue = countValue.getVal(1) != null ? countValue
+                          .getVal(1).toString() : "";
+                      VNameValue vNameValue = new VNameValue(innerName,
+                          innerValue);
+                      vNameValues.add(vNameValue);
+                    }
+                  }
+                }
+              }
+              vBarGraphData.setDataCounts(vNameValues);
+            }
+            histogramData.add(vBarGraphData);
+          }
+        }
       }
-      histogramData.add(vBarGraphData);
     }
   }
 
   @SuppressWarnings("unchecked")
   protected boolean extractNonRangeStackValuesFromBucket(
-    SimpleOrderedMap<Object> jsonFacetResponse, String level,
-    Collection<VBarGraphData> vGraphDatas, String typeXAxis) {
-
+      SimpleOrderedMap<Object> jsonFacetResponse, String level,
+      Collection<VBarGraphData> vGraphDatas, String typeXAxis) {
     boolean zeroFlag = true;
-    if (jsonFacetResponse.get(level).toString().equals("{count=0}")) {
+    if (jsonFacetResponse == null || jsonFacetResponse.get(level) == null
+        || jsonFacetResponse.get(level).toString().equals("{count=0}")) {
       return false;
     }
-
-    NamedList<Object> list = (NamedList<Object>) jsonFacetResponse
-      .get(level);
-
-    ArrayList<Object> list3 = (ArrayList<Object>) list.get("buckets");
-    int i = 0;
-    for (i = 0; i < list3.size(); i++) {
-      VBarGraphData vGraphData = new VBarGraphData();
-
-
-      Collection<VNameValue> levelCounts = new ArrayList<VNameValue>();
-      vGraphData.setDataCounts(levelCounts);
-
-      SimpleOrderedMap<Object> valueCount = (SimpleOrderedMap<Object>) list3
-        .get(i);
-      String name = ("" + valueCount.getVal(0)).trim();
-      if (isTypeNumber(typeXAxis)) {
-        VNameValue nameValue = new VNameValue();
-        String value = ("" + valueCount.getVal(2)).trim().substring(0, ("" + valueCount.getVal(2)).indexOf("."));
-        nameValue.setName(name);
-        nameValue.setValue(value);
-        levelCounts.add(nameValue);
-      } else {
-        SimpleOrderedMap<Object> l1 = (SimpleOrderedMap<Object>) valueCount
-          .getVal(2);
-        ArrayList<Object> l2 = (ArrayList<Object>) l1.get("buckets");
-        for (int j = 0; l2 != null && j < l2.size(); j++) {
-          VNameValue nameValue = new VNameValue();
-          SimpleOrderedMap<Object> innerValueCount = (SimpleOrderedMap<Object>) l2
-            .get(j);
-          nameValue.setName(("" + innerValueCount.getVal(0)).trim());
-          nameValue.setValue(("" + innerValueCount.getVal(1)).trim());
-          levelCounts.add(nameValue);
+    NamedList<Object> levelList = (NamedList<Object>) jsonFacetResponse
+        .get(level);
+    if (levelList != null) {
+      ArrayList<Object> bucketList = (ArrayList<Object>) levelList.get(BUCKETS);
+      if (bucketList != null) {
+        for (int index = 0; index < bucketList.size(); index++) {
+          SimpleOrderedMap<Object> valueCount = (SimpleOrderedMap<Object>) bucketList
+              .get(index);
+          if (valueCount != null && valueCount.size() > 2) {
+            VBarGraphData vGraphData = new VBarGraphData();
+            Collection<VNameValue> levelCounts = new ArrayList<VNameValue>();
+            String name = valueCount.getVal(0) != null ? valueCount.getVal(0)
+                .toString().trim() : "";
+            if (isTypeNumber(typeXAxis)) {
+              VNameValue nameValue = new VNameValue();
+              Double sumValue = (Double) valueCount.getVal(2);
+              String value = "0";// default is zero
+              if (sumValue != null) {
+                value = "" + sumValue.longValue();
+              }
+              nameValue.setName(name);
+              nameValue.setValue(value);
+              levelCounts.add(nameValue);
+            } else {
+              SimpleOrderedMap<Object> valueCountMap = (SimpleOrderedMap<Object>) valueCount
+                  .getVal(2);
+              if (valueCountMap != null) {
+                ArrayList<Object> buckets = (ArrayList<Object>) valueCountMap
+                    .get(BUCKETS);
+                if (buckets != null) {
+                  for (int innerIndex = 0; innerIndex < buckets.size(); innerIndex++) {
+                    SimpleOrderedMap<Object> innerValueCount = (SimpleOrderedMap<Object>) buckets
+                        .get(innerIndex);
+                    if (innerValueCount != null) {
+                      String innerName = innerValueCount.getVal(0) != null ? innerValueCount
+                          .getVal(0).toString().trim()
+                          : "";
+                      String innerValue = innerValueCount.getVal(1) != null ? innerValueCount
+                          .getVal(1).toString().trim()
+                          : "";
+                      VNameValue nameValue = new VNameValue(innerName,
+                          innerValue);
+                      levelCounts.add(nameValue);
+                    }
+                  }
+                }
+              }
+            }
+            vGraphData.setName(name);
+            vGraphData.setDataCounts(levelCounts);
+            vGraphDatas.add(vGraphData);
+          }
         }
       }
-
-      vGraphData.setName(name);
-      vGraphDatas.add(vGraphData);
     }
     return zeroFlag;
   }
 
   @SuppressWarnings("unchecked")
   protected boolean extractValuesFromJson(
-    SimpleOrderedMap<Object> jsonFacetResponse, String level,
-    VBarGraphData histogramData, List<RangeFacet.Count> counts) {
+      SimpleOrderedMap<Object> jsonFacetResponse, String level,
+      VBarGraphData histogramData, List<RangeFacet.Count> counts) {
     histogramData.setName(level);
     Collection<VNameValue> levelCounts = new ArrayList<VNameValue>();
     histogramData.setDataCounts(levelCounts);
     boolean zeroFlag = true;
     if (jsonFacetResponse.get(level).toString().equals("{count=0}")) {
-      for (RangeFacet.Count date : counts) {
-        VNameValue nameValue = new VNameValue();
-
-        nameValue.setName(date.getValue());
-        nameValue.setValue("0");
-
-        levelCounts.add(nameValue);
+      if (counts != null) {
+        for (RangeFacet.Count date : counts) {
+          VNameValue nameValue = new VNameValue();
+          nameValue.setName(date.getValue());
+          nameValue.setValue("0");
+          levelCounts.add(nameValue);
+        }
       }
       return false;
     }
-    NamedList<Object> list = (NamedList<Object>) jsonFacetResponse
-      .get(level);
-    NamedList<Object> list2 = (NamedList<Object>) list.getVal(1);
-    ArrayList<Object> list3 = (ArrayList<Object>) list2.get("buckets");
-    int i = 0;
-    for (RangeFacet.Count date : counts) {
-      VNameValue nameValue = new VNameValue();
-      SimpleOrderedMap<Object> valueCount = (SimpleOrderedMap<Object>) list3
-        .get(i);
-      String count = ("" + valueCount.getVal(1)).trim();
-      if (!"0".equals(count)) {
-        zeroFlag = false;
+    NamedList<Object> levelList = (NamedList<Object>) jsonFacetResponse
+        .get(level);
+    if (levelList != null && counts != null && levelList.size() > 1) {
+      NamedList<Object> levelValues = (NamedList<Object>) levelList.getVal(1);
+      if (levelValues != null) {
+        ArrayList<Object> bucketList = (ArrayList<Object>) levelValues
+            .get(BUCKETS);
+        int i = 0;
+        for (RangeFacet.Count date : counts) {
+          SimpleOrderedMap<Object> valueCount = (SimpleOrderedMap<Object>) bucketList
+              .get(i);
+          if (valueCount != null) {
+            Double count = (Double) valueCount.getVal(1);
+            if (count != null && !count.equals(0D)) {
+              zeroFlag = false;
+            }
+            String name = date.getValue();
+            String value = count != null ? "" + count.longValue() : "0";
+            VNameValue nameValue = new VNameValue(name, value);
+            levelCounts.add(nameValue);
+          }
+          i++;
+        }
       }
-      nameValue.setName(date.getValue());
-      nameValue.setValue(count);
-
-      levelCounts.add(nameValue);
-      i++;
     }
-
     return zeroFlag;
   }
 
   protected boolean isTypeNumber(String typeXAxis) {
-    return "long".contains(typeXAxis) || "int".contains(typeXAxis)
-      || "float".contains(typeXAxis) || "double".contains(typeXAxis);
-  }
-
-  public String convertObjToString(Object obj) throws IOException {
-    if (obj == null) {
-      return "";
+    if (stringUtil.isEmpty(typeXAxis)) {
+      return false;
+    } else {
+      return typeXAxis.contains(DATA_TYPE.LONG.getType()) || typeXAxis.contains(DATA_TYPE.INT.getType())
+          || typeXAxis.contains(DATA_TYPE.FLOAT.getType()) || typeXAxis.contains(DATA_TYPE.DOUBLE.getType());
     }
-    ObjectMapper mapper = new ObjectMapper();
-    ObjectWriter w = mapper.writerWithDefaultPrettyPrinter();
-    return w.writeValueAsString(obj);
   }
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGnerator.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGnerator.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGnerator.java
deleted file mode 100644
index 44143f4..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGnerator.java
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
- * 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.ambari.logsearch.graph;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.ambari.logsearch.common.LogSearchConstants;
-import org.apache.ambari.logsearch.common.MessageEnums;
-import org.apache.ambari.logsearch.common.SearchCriteria;
-import org.apache.ambari.logsearch.dao.SolrDaoBase;
-import org.apache.ambari.logsearch.query.QueryGeneration;
-import org.apache.ambari.logsearch.util.ConfigUtil;
-import org.apache.ambari.logsearch.util.DateUtil;
-import org.apache.ambari.logsearch.util.RESTErrorUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
-import org.apache.ambari.logsearch.view.VBarDataList;
-import org.apache.ambari.logsearch.view.VBarGraphData;
-import org.apache.ambari.logsearch.view.VNameValue;
-import org.apache.log4j.Logger;
-import org.apache.solr.client.solrj.SolrQuery;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.response.FacetField;
-import org.apache.solr.client.solrj.response.FacetField.Count;
-import org.apache.solr.client.solrj.response.QueryResponse;
-import org.apache.solr.client.solrj.response.RangeFacet;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.util.SimpleOrderedMap;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Component
-public class GraphDataGnerator extends GraphDataGeneratorBase {
-
-  @Autowired
-  StringUtil stringUtil;
-
-  @Autowired
-  QueryGeneration queryGenerator;
-
-  @Autowired
-  RESTErrorUtil restErrorUtil;
-
-  @Autowired
-  DateUtil dateUtil;
-
-  private static Logger logger = Logger.getLogger(GraphDataGnerator.class);
-
-  public String getAnyGraphData(SearchCriteria searchCriteria,
-                                SolrDaoBase solrDaoBase, SolrQuery solrQuery) {
-    // X axis credentials
-    String xAxisField = (String) searchCriteria.getParamValue("xAxis");
-    String stackField = (String) searchCriteria.getParamValue("stackBy");
-    String from = (String) searchCriteria.getParamValue("from");
-    String to = (String) searchCriteria.getParamValue("to");
-    String unit = (String) searchCriteria.getParamValue("unit");
-    String suffix = (String) searchCriteria.getParamValue("suffix");
-    String typeXAxis = ConfigUtil.schemaFieldsName.get(xAxisField + suffix);
-    typeXAxis = (stringUtil.isEmpty(typeXAxis)) ? "string" : typeXAxis;
-
-    // Y axis credentials
-    String yAxisField = (String) searchCriteria.getParamValue("yAxis");
-
-    searchCriteria.addParam("type", typeXAxis);
-    String fieldTime = (String) searchCriteria.getParamValue("feildTime");
-
-    int garphType = getGraphType(searchCriteria);
-
-    switch (garphType) {
-      case 1:
-        return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase,
-          typeXAxis, fieldTime, solrQuery);
-      case 2:
-        return rangeNonStackGraph(xAxisField, yAxisField, from, to, unit,
-          solrDaoBase, typeXAxis, fieldTime, solrQuery);
-      case 3:
-        return nonRangeStackGraph(xAxisField, yAxisField, stackField, from,
-          to, solrDaoBase, typeXAxis, fieldTime, solrQuery);
-      case 4:
-        return rangeStackGraph(xAxisField, yAxisField, stackField, from,
-          to, unit, solrDaoBase, typeXAxis, fieldTime, solrQuery);
-      default:
-        return null;
-    }
-  }
-
-  private int getGraphType(SearchCriteria searchCriteria) {
-    // X axis credentials
-    String xAxisField = (String) searchCriteria.getParamValue("xAxis");
-    String stackField = (String) searchCriteria.getParamValue("stackBy");
-    String from = (String) searchCriteria.getParamValue("from");
-    String to = (String) searchCriteria.getParamValue("to");
-    String xType = (String) searchCriteria.getParamValue("type");
-
-    if (xType == null)
-      return 0;
-
-    // Y axis credentials
-    String yAxisField = (String) searchCriteria.getParamValue("yAxis");
-    if (stringUtil.isEmpty(xAxisField) || stringUtil.isEmpty(yAxisField)) {
-    }
-    // Normal Graph Type
-    else if (stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
-      && !stringUtil.isEmpty(from)
-      && !(xType.contains("date") || xType.contains("time")))
-      return 1;
-      // Range(Non-Stack) Graph Type
-    else if (stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
-      && !stringUtil.isEmpty(from)
-      && (xType.contains("date") || xType.contains("time")))
-      return 2;
-      // Non-Range Stack Graph Type
-    else if (!stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
-      && !stringUtil.isEmpty(from)
-      && !(xType.contains("date") || xType.contains("time")))
-      return 3;
-      // Range Stack GraphType
-    else if (!stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
-      && !stringUtil.isEmpty(from)
-      && (xType.contains("date") || xType.contains("time")))
-      return 4;
-
-    return 0;
-  }
-
-  @SuppressWarnings("unchecked")
-  private String normalGraph(String xAxisField, String yAxisField,
-                             String from, String to, SolrDaoBase solrDaoBase, String typeXAxis,
-                             String fieldTime, SolrQuery solrQuery) {
-    VBarDataList dataList = new VBarDataList();
-    Collection<VBarGraphData> vBarGraphDatas = new ArrayList<VBarGraphData>();
-    VBarGraphData vBarGraphData = new VBarGraphData();
-    Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
-
-    queryGenerator.setMainQuery(solrQuery, null);
-    queryGenerator.setSingleIncludeFilter(solrQuery, fieldTime, "[" + from
-      + " TO " + to + "]");
-    if (typeXAxis.contains("string")
-      || typeXAxis.contains("key_lower_case")
-      || typeXAxis.contains("text")) {
-      queryGenerator.setFacetField(solrQuery, xAxisField);
-      try {
-        QueryResponse response = solrDaoBase.process(solrQuery);
-        Long count = response.getResults().getNumFound();
-
-        if (response != null && count > 0) {
-          FacetField facetField = response.getFacetField(xAxisField);
-          if (facetField != null) {
-            List<Count> countValues = facetField.getValues();
-            for (Count cnt : countValues) {
-              VNameValue vNameValue = new VNameValue();
-              vNameValue.setName(cnt.getName());
-              vNameValue.setValue("" + cnt.getCount());
-              vNameValues.add(vNameValue);
-            }
-            vBarGraphData.setDataCounts(vNameValues);
-            vBarGraphData.setName(xAxisField);
-            vBarGraphDatas.add(vBarGraphData);
-            dataList.setGraphData(vBarGraphDatas);
-          }
-        }
-        return convertObjToString(dataList);
-      } catch (SolrException | SolrServerException | IOException e) {
-
-      }
-    } else {
-      queryGenerator.setRowCount(solrQuery, 0);
-      String yAxis = yAxisField.contains("count") ? "sum" : yAxisField;
-      String jsonQuery = queryGenerator
-        .buildJSONFacetAggregatedFuncitonQuery(yAxis,
-          xAxisField);
-      queryGenerator.setJSONFacet(solrQuery, jsonQuery);
-      try {
-        QueryResponse response = solrDaoBase.process(solrQuery);
-
-        SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
-          .getResponse().get("facets");
-        if (jsonFacetResponse.toString().equals("{count=0}"))
-          return convertObjToString(dataList);
-        VNameValue value = new VNameValue();
-        String sum = jsonFacetResponse.getVal(1).toString();
-        value.setName(xAxisField);
-        value.setValue(sum.substring(0, sum.indexOf(".")));
-
-        vNameValues.add(value);
-        vBarGraphData.setDataCounts(vNameValues);
-        vBarGraphData.setName(xAxisField);
-        vBarGraphDatas.add(vBarGraphData);
-        dataList.setGraphData(vBarGraphDatas);
-        return convertObjToString(dataList);
-      } catch (SolrException | SolrServerException | IOException e) {
-
-      }
-    }
-
-    return null;
-  }
-
-  @SuppressWarnings("unchecked")
-  private String nonRangeStackGraph(String xAxisField, String yAxisField,
-                                    String stackField, String from, String to, SolrDaoBase solrDaoBase,
-                                    String typeXAxis, String fieldTime, SolrQuery solrQuery) {
-    VBarDataList dataList = new VBarDataList();
-    Collection<VBarGraphData> vGraphData = new ArrayList<VBarGraphData>();
-
-    String mainQuery = queryGenerator.buildInclusiveRangeFilterQuery(
-      fieldTime, from, to);
-    queryGenerator.setMainQuery(solrQuery, mainQuery);
-    queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
-    String jsonQuery = "";
-
-    if (isTypeNumber(typeXAxis)) {
-      String function = (yAxisField.contains("count")) ? "sum"
-        : yAxisField;
-      jsonQuery = queryGenerator.buidlJSONFacetRangeQueryForNumber(
-        stackField, xAxisField, function);
-    } else {
-      jsonQuery = queryGenerator.buildJsonFacetTermsRangeQuery(
-        stackField, xAxisField);
-    }
-
-    try {
-      queryGenerator.setJSONFacet(solrQuery, jsonQuery);
-      dataList.setGraphData(vGraphData);
-
-      QueryResponse response = solrDaoBase.process(solrQuery);
-      if (response == null) {
-        response = new QueryResponse();
-      }
-      Long count = response.getResults().getNumFound();
-      if (count <= 0)
-        return convertObjToString(dataList);
-
-      SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
-        .getResponse().get("facets");
-      if (jsonFacetResponse == null
-        || jsonFacetResponse.toString().equals("{count=0}")) {
-        return convertObjToString(dataList);
-      }
-
-      extractNonRangeStackValuesFromBucket(jsonFacetResponse, stackField, vGraphData,
-        typeXAxis);
-
-      if (LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(stackField)
-        && LogSearchConstants.SOLR_LEVEL
-        .equalsIgnoreCase(xAxisField)) {
-        Collection<VBarGraphData> levelVGraphData = dataList.getGraphData();
-        List<String> logLevels = new ArrayList<String>();
-
-        logLevels.add(LogSearchConstants.FATAL);
-        logLevels.add(LogSearchConstants.ERROR);
-        logLevels.add(LogSearchConstants.WARN);
-        logLevels.add(LogSearchConstants.INFO);
-        logLevels.add(LogSearchConstants.DEBUG);
-        logLevels.add(LogSearchConstants.TRACE);
-
-        for (VBarGraphData garphData : levelVGraphData) {
-          Collection<VNameValue> valueList = garphData.getDataCount();
-          Collection<VNameValue> valueListSorted = new ArrayList<VNameValue>();
-          for (String level : logLevels) {
-            String val = "0";
-            for (VNameValue value : valueList) {
-              if (value.getName().equalsIgnoreCase(level)) {
-                val = value.getValue();
-                break;
-              }
-            }
-            VNameValue v1 = new VNameValue();
-            v1.setName(level.toUpperCase());
-            v1.setValue(val);
-            valueListSorted.add(v1);
-          }
-          garphData.setDataCounts(valueListSorted);
-        }
-      }
-
-      return convertObjToString(dataList);
-    } catch (SolrException | IOException | SolrServerException e) {
-      logger.error(e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.DATA_NOT_FOUND);
-    }
-
-  }
-
-  @SuppressWarnings("unchecked")
-  private String rangeNonStackGraph(String xAxisField, String yAxisField,
-                                    String from, String to, String unit, SolrDaoBase solrDaoBase,
-                                    String typeXAxis, String fieldTime, SolrQuery solrQuery) {
-    VBarDataList dataList = new VBarDataList();
-    Collection<VBarGraphData> vBarGraphDatas = new ArrayList<VBarGraphData>();
-    VBarGraphData vBarGraphData = new VBarGraphData();
-    Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
-
-    queryGenerator.setMainQuery(solrQuery, null);
-
-    if (isTypeNumber(typeXAxis)) {
-      queryGenerator.setSingleRangeFilter(solrQuery, fieldTime, from, to);
-      return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase,
-        typeXAxis, fieldTime, solrQuery);
-    } else {
-      try {
-        queryGenerator.setFacetRange(solrQuery, xAxisField, from, to,
-          unit);
-        QueryResponse response = solrDaoBase.process(solrQuery);
-        if (response == null)
-          response = new QueryResponse();
-        Long count = response.getResults().getNumFound();
-        if (count > 0) {
-
-          @SuppressWarnings("rawtypes")
-          List<RangeFacet> rangeFacet = response.getFacetRanges();
-          if (rangeFacet == null)
-            return convertObjToString(dataList);
-
-          List<RangeFacet.Count> listCount = rangeFacet.get(0)
-            .getCounts();
-          if (listCount != null) {
-            for (RangeFacet.Count cnt : listCount) {
-              VNameValue vNameValue = new VNameValue();
-              vNameValue.setName(cnt.getValue());
-              vNameValue.setValue("" + cnt.getCount());
-              vNameValues.add(vNameValue);
-            }
-            vBarGraphData.setDataCounts(vNameValues);
-            vBarGraphDatas.add(vBarGraphData);
-            vBarGraphData.setName(xAxisField);
-            dataList.setGraphData(vBarGraphDatas);
-          }
-        }
-        return convertObjToString(dataList);
-      } catch (SolrException | SolrServerException | IOException e) {
-
-      }
-    }
-    return null;
-  }
-
-  @SuppressWarnings("unchecked")
-  private String rangeStackGraph(String xAxisField, String yAxisField,
-                                 String stackField, String from, String to, String unit,
-                                 SolrDaoBase solrDaoBase, String typeXAxis, String fieldTime, SolrQuery solrQuery) {
-    VBarDataList dataList = new VBarDataList();
-    List<VBarGraphData> histogramData = new ArrayList<VBarGraphData>();
-
-    queryGenerator.setMainQuery(solrQuery, null);
-    queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
-
-    String jsonHistogramQuery = queryGenerator
-      .buildJSONFacetTermTimeRangeQuery(stackField, xAxisField, from,
-        to, unit).replace("\\", "");
-
-    try {
-      solrQuery.set("json.facet", jsonHistogramQuery);
-      queryGenerator.setRowCount(solrQuery, 0);
-      QueryResponse response = solrDaoBase.process(solrQuery);
-      if (response == null)
-        response = new QueryResponse();
-
-      SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
-        .getResponse().get("facets");
-
-      if (jsonFacetResponse == null
-        || jsonFacetResponse.toString().equals("{count=0}"))
-        return convertObjToString(dataList);
-
-      extractRangeStackValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
-
-      dataList.setGraphData(histogramData);
-      return convertObjToString(dataList);
-
-    } catch (SolrException | IOException | SolrServerException e) {
-    }
-
-    return null;
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java
index e16faa0..b5efd24 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java
@@ -37,8 +37,7 @@ import org.apache.ambari.logsearch.common.ManageStartEndTime;
 import org.apache.ambari.logsearch.common.MessageEnums;
 import org.apache.ambari.logsearch.common.SearchCriteria;
 import org.apache.ambari.logsearch.dao.AuditSolrDao;
-import org.apache.ambari.logsearch.graph.GraphDataGnerator;
-import org.apache.ambari.logsearch.query.QueryGeneration;
+import org.apache.ambari.logsearch.graph.GraphDataGenerator;
 import org.apache.ambari.logsearch.util.BizUtil;
 import org.apache.ambari.logsearch.util.ConfigUtil;
 import org.apache.ambari.logsearch.util.DateUtil;
@@ -51,6 +50,7 @@ import org.apache.ambari.logsearch.view.VBarGraphData;
 import org.apache.ambari.logsearch.view.VGroupList;
 import org.apache.ambari.logsearch.view.VNameValue;
 import org.apache.ambari.logsearch.view.VNameValueList;
+import org.apache.ambari.logsearch.view.VResponse;
 import org.apache.ambari.logsearch.view.VSolrLogList;
 import org.apache.log4j.Logger;
 import org.apache.solr.client.solrj.SolrQuery;
@@ -72,9 +72,6 @@ public class AuditMgr extends MgrBase {
   static Logger logger = Logger.getLogger(AuditMgr.class);
 
   @Autowired
-  QueryGeneration queryGenerator;
-
-  @Autowired
   AuditSolrDao auditSolrDao;
 
   @Autowired
@@ -93,69 +90,20 @@ public class AuditMgr extends MgrBase {
   DateUtil dateUtil;
 
   @Autowired
-  GraphDataGnerator graphDataGnerator;
-
-  public String getAllSolrFields() {
-
-    Collection<String> fieldNames = new ArrayList<String>();
-    SolrQuery solrQuery = new SolrQuery();
-
-    int numberDocument = 0;
-    int size = 0;
-
-    try {
-      queryGenerator.setMainQuery(solrQuery, null);
-      queryGenerator.setRowCount(solrQuery, 10);
-
-      SearchCriteria searchCriteria = new SearchCriteria();
-      searchCriteria.setSortBy(LogSearchConstants.AUDIT_EVTTIME);
-      searchCriteria.setSortType(SolrQuery.ORDER.asc.toString());
-
-      queryGenerator.setSortOrderDefaultServiceLog(solrQuery,
-        searchCriteria);
-      SolrDocumentList docList = auditSolrDao.process(solrQuery)
-        .getResults();
-
-      if (docList.size() > 0) {
-        for (int i = 0; i < 10; i++) {
-          if (docList.get(i).size() > size) {
-            size = docList.get(i).size();
-            numberDocument = i;
-          }
-        }
-        fieldNames = docList.get(numberDocument).getFieldNames();
-        return convertObjToString(fieldNames);
-      }
-      return convertObjToString(fieldNames);
-
-    } catch (SolrException | SolrServerException | IOException e) {
-      logger.error(e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
-    }
-  }
+  GraphDataGenerator graphDataGenerator;
 
   public String getLogs(SearchCriteria searchCriteria) {
-    SolrQuery solrQuery = queryGenerator
-      .commonAuditFilterQuery(searchCriteria);
-    try {
-      QueryResponse response = auditSolrDao.process(solrQuery);
-      SolrDocumentList docList = response.getResults();
-      VSolrLogList collection = new VSolrLogList(docList);
-      collection.setStartIndex((int) docList.getStart());
-      collection.setTotalCount(docList.getNumFound());
-      collection.setPageSize(searchCriteria.getMaxRows());
-      return convertObjToString(collection);
-    } catch (SolrException | SolrServerException | IOException e) {
-      logger.error("Error during solrQuery=" + solrQuery, e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
-    }
+    SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
+    VSolrLogList collection = getLogAsPaginationProvided(solrQuery,
+        auditSolrDao);
+    return convertObjToString(collection);
+
   }
 
   public SolrDocumentList getComponents(SearchCriteria searchCriteria) {
     SolrQuery solrQuery = queryGenerator
       .commonAuditFilterQuery(searchCriteria);
+    SolrDocumentList docList = new SolrDocumentList();
     try {
       queryGenerator.setFacetField(solrQuery,
         LogSearchConstants.AUDIT_COMPONENT);
@@ -166,12 +114,12 @@ public class AuditMgr extends MgrBase {
 
       QueryResponse queryResponse = auditSolrDao.process(solrQuery);
       if (queryResponse == null) {
-        queryResponse = new QueryResponse();
+        return docList;
       }
 
       facetFields = queryResponse.getFacetFields();
       if (facetFields == null) {
-        return new SolrDocumentList();
+        return docList;
       }
       if (!facetFields.isEmpty()) {
         facetField = facetFields.get(0);
@@ -179,7 +127,7 @@ public class AuditMgr extends MgrBase {
       if (facetField != null) {
         componentsCount = facetField.getValues();
       }
-      SolrDocumentList docList = new SolrDocumentList();
+    
       for (Count compnonet : componentsCount) {
         SolrDocument solrDocument = new SolrDocument();
         solrDocument.addField("type", compnonet.getName());
@@ -188,25 +136,17 @@ public class AuditMgr extends MgrBase {
       return docList;
     } catch (SolrException | SolrServerException | IOException e) {
       logger.error("Error during solrQuery=" + solrQuery, e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
   public String getAuditComponents(SearchCriteria searchCriteria) {
     VGroupList vGroupList = new VGroupList();
+    SolrDocumentList docList = getComponents(searchCriteria);
 
-    try {
-
-      SolrDocumentList docList = getComponents(searchCriteria);
-
-      vGroupList.setGroupDocuments(docList);
-      return convertObjToString(vGroupList);
-    } catch (SolrException | IOException e) {
-      logger.error("Error", e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
-    }
+    vGroupList.setGroupDocuments(docList);
+    return convertObjToString(vGroupList);
   }
 
   @SuppressWarnings("unchecked")
@@ -214,9 +154,11 @@ public class AuditMgr extends MgrBase {
     VBarDataList dataList = new VBarDataList();
     SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
 
-    String from = (String) searchCriteria.getParamValue("startTime");
-    String to = (String) searchCriteria.getParamValue("endTime");
-    String unit = (String) searchCriteria.getParamValue("unit");
+    String from = getFrom((String) searchCriteria.getParamValue("startTime"));
+    String to = getTo((String) searchCriteria.getParamValue("endTime"));
+    String unit = getUnit((String) searchCriteria.getParamValue("unit"));
+    
+    
 
     List<VBarGraphData> histogramData = new ArrayList<VBarGraphData>();
     String jsonHistogramQuery = queryGenerator.buildJSONFacetTermTimeRangeQuery(
@@ -228,15 +170,16 @@ public class AuditMgr extends MgrBase {
       queryGenerator.setJSONFacet(solrQuery, jsonHistogramQuery);
       queryGenerator.setRowCount(solrQuery, 0);
       QueryResponse response = auditSolrDao.process(solrQuery);
-      if (response == null)
-        response = new QueryResponse();
-
+      if (response == null){
+        return convertObjToString(dataList);
+      }
       SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
         .getResponse().get("facets");
 
       if (jsonFacetResponse == null
-        || jsonFacetResponse.toString().equals("{count=0}"))
+        || jsonFacetResponse.toString().equals("{count=0}")){
         return convertObjToString(dataList);
+      }
 
       extractValuesFromBucket(jsonFacetResponse, "x", "y",
         histogramData);
@@ -246,17 +189,19 @@ public class AuditMgr extends MgrBase {
 
     } catch (SolrServerException | SolrException | IOException e) {
       logger.error(e);
-      throw restErrorUtil.createRESTException("No Request Parameter",
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
 
     }
   }
 
   public String getTopAuditFieldCount(SearchCriteria searchCriteria) {
+    int topCounts = 10;
     Integer top = (Integer) searchCriteria.getParamValue("top");
     String facetField = (String) searchCriteria.getParamValue("field");
-    if (top == null)
-      top = new Integer(10);
+    if (top == null){
+      top = new Integer(topCounts);
+    }
     SolrQuery solrQuery = queryGenerator
       .commonAuditFilterQuery(searchCriteria);
     try {
@@ -266,11 +211,15 @@ public class AuditMgr extends MgrBase {
       VNameValueList nameValueList = new VNameValueList(nameValues);
 
       queryGenerator.setFacetField(solrQuery, facetField);
-      queryGenerator.setFacetSort(solrQuery, "count");
+      queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_COUNT);
       queryGenerator.setFacetLimit(solrQuery, top.intValue());
 
       List<Count> countList = new ArrayList<FacetField.Count>();
       QueryResponse queryResponse = auditSolrDao.process(solrQuery);
+      if(queryResponse == null){
+        return convertObjToString(nameValueList);
+      }
+      
       if (queryResponse.getFacetField(facetField) != null) {
         FacetField queryFacetField = queryResponse
           .getFacetField(facetField);
@@ -290,13 +239,14 @@ public class AuditMgr extends MgrBase {
 
     } catch (SolrException | IOException | SolrServerException e) {
       logger.error("Error during solrQuery=" + solrQuery, e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
-  @SuppressWarnings("unchecked")
+  @SuppressWarnings({ "unchecked", "rawtypes" })
   public String getLiveLogCounts() {
+    VNameValueList nameValueList = new VNameValueList();
     SolrQuery solrQuery = new SolrQuery();
     solrQuery.setParam("event", "/getLiveLogsCount");
     try {
@@ -313,11 +263,18 @@ public class AuditMgr extends MgrBase {
       List<RangeFacet.Count> listCount;
 
       QueryResponse response = auditSolrDao.process(solrQuery);
-      @SuppressWarnings("rawtypes")
+ 
       List<RangeFacet> rangeFacet = response.getFacetRanges();
-      if (rangeFacet == null)
-        return convertObjToString(new VNameValueList());
-      listCount = rangeFacet.get(0).getCounts();
+      if (rangeFacet == null){
+        return convertObjToString(nameValueList);
+      }
+      RangeFacet range=rangeFacet.get(0);
+      
+      if(range == null){
+        return convertObjToString(nameValueList);
+      }
+      
+      listCount = range.getCounts();
 
       List<VNameValue> nameValues = new ArrayList<VNameValue>();
       int count = 0;
@@ -328,15 +285,14 @@ public class AuditMgr extends MgrBase {
         nameValues.add(nameValue);
         count++;
       }
-      VNameValueList nameValueList = new VNameValueList(nameValues);
-
+      nameValueList.setVNameValues(nameValues);
       return convertObjToString(nameValueList);
 
     } catch (SolrException | SolrServerException | ParseException
       | IOException e) {
       logger.error("Error during solrQuery=" + solrQuery, e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
@@ -345,13 +301,17 @@ public class AuditMgr extends MgrBase {
     String jsonUserQuery = "{Users:{type:terms, field:reqUser, facet:{ Repo:{ type:terms, field:repo, facet:{eventCount:\"sum(event_count)\"}}}}}";
     SolrQuery solrQuery = queryGenerator
       .commonAuditFilterQuery(searchCriteria);
-    solrQuery.set("json.facet", jsonUserQuery);
+    queryGenerator.setJSONFacet(solrQuery, jsonUserQuery);
     queryGenerator.setRowCount(solrQuery, 0);
     try {
+      VBarDataList vBarDataList = new VBarDataList();
       QueryResponse queryResponse = auditSolrDao.process(solrQuery);
+      if(queryResponse == null){
+        return convertObjToString(vBarDataList);
+      }
 
       NamedList<Object> namedList = queryResponse.getResponse();
-      VBarDataList vBarDataList = new VBarDataList();
+      
       if (namedList == null) {
         return convertObjToString(vBarDataList);
       }
@@ -359,13 +319,19 @@ public class AuditMgr extends MgrBase {
       @SuppressWarnings("unchecked")
       SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList
         .get("facets");
-      vBarDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse);
+      if(jsonFacetResponse == null){
+        return convertObjToString(vBarDataList);
+      }
+      if(jsonFacetResponse.toString().equals("{count=0}")){
+        return convertObjToString(vBarDataList);
+      }
+      vBarDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
       return convertObjToString(vBarDataList);
 
     } catch (SolrServerException | SolrException | IOException e) {
       logger.error("Error during solrQuery=" + e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
@@ -374,13 +340,16 @@ public class AuditMgr extends MgrBase {
     String jsonUserQuery = "{Users:{type:terms,field:resource,facet:{Repo:{type:terms,field:repo,facet:{eventCount:\"sum(event_count)\"}}}}}";
     SolrQuery solrQuery = queryGenerator
       .commonAuditFilterQuery(searchCriteria);
-    solrQuery.set("json.facet", jsonUserQuery);
+    queryGenerator.setJSONFacet(solrQuery, jsonUserQuery);
     queryGenerator.setRowCount(solrQuery, 0);
     try {
+      VBarDataList vBarDataList = new VBarDataList();
       QueryResponse queryResponse = auditSolrDao.process(solrQuery);
+      if(queryResponse == null){
+        return convertObjToString(vBarDataList);
+      }
 
       NamedList<Object> namedList = queryResponse.getResponse();
-      VBarDataList vBarDataList = new VBarDataList();
       if (namedList == null) {
         return convertObjToString(vBarDataList);
       }
@@ -389,22 +358,23 @@ public class AuditMgr extends MgrBase {
       SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList
         .get("facets");
 
-      vBarDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse);
+      vBarDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
       return convertObjToString(vBarDataList);
 
     } catch (SolrServerException | SolrException | IOException e) {
       logger.error("Error during solrQuery=" + solrQuery, e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
   @SuppressWarnings("unchecked")
   public String getRequestUserLineGraph(SearchCriteria searchCriteria) {
 
-    String from = (String) searchCriteria.getParamValue("startTime");
-    String to = (String) searchCriteria.getParamValue("endTime");
-    String unit = (String) searchCriteria.getParamValue("unit");
+    String from = getFrom((String) searchCriteria.getParamValue("startTime"));
+    String to = getTo((String) searchCriteria.getParamValue("endTime"));
+    String unit = getUnit((String) searchCriteria.getParamValue("unit"));
+    
     SolrQuery solrQuery = queryGenerator
       .commonAuditFilterQuery(searchCriteria);
 
@@ -420,19 +390,19 @@ public class AuditMgr extends MgrBase {
       .replace("\\", "");
 
     try {
-      solrQuery.set("json.facet", jsonHistogramQuery);
+      queryGenerator.setJSONFacet(solrQuery, jsonHistogramQuery);
       queryGenerator.setRowCount(solrQuery, 0);
       QueryResponse response = auditSolrDao.process(solrQuery);
-      if (response == null)
-        response = new QueryResponse();
-
+      if (response == null){
+        return convertObjToString(dataList);
+      }
       SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
         .getResponse().get("facets");
 
       if (jsonFacetResponse == null
-        || jsonFacetResponse.toString().equals("{count=0}"))
+        || jsonFacetResponse.toString().equals("{count=0}")){
         return convertObjToString(dataList);
-
+      }
       extractValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
 
       dataList.setGraphData(histogramData);
@@ -440,13 +410,14 @@ public class AuditMgr extends MgrBase {
 
     } catch (SolrException | IOException | SolrServerException e) {
       logger.error("Error during solrQuery=" + solrQuery, e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
 
   }
 
   public SolrDocumentList getRequestUser(SearchCriteria searchCriteria) {
+    SolrDocumentList docList = new SolrDocumentList();
     SolrQuery solrQuery = queryGenerator
       .commonAuditFilterQuery(searchCriteria);
     try {
@@ -459,12 +430,12 @@ public class AuditMgr extends MgrBase {
 
       QueryResponse queryResponse = auditSolrDao.process(solrQuery);
       if (queryResponse == null) {
-        queryResponse = new QueryResponse();
+        return docList;
       }
 
       facetFields = queryResponse.getFacetFields();
       if (facetFields == null) {
-        return new SolrDocumentList();
+        return docList;
       }
       if (!facetFields.isEmpty()) {
         facetField = facetFields.get(0);
@@ -472,7 +443,7 @@ public class AuditMgr extends MgrBase {
       if (facetField != null) {
         componentsCount = facetField.getValues();
       }
-      SolrDocumentList docList = new SolrDocumentList();
+     
       for (Count compnonet : componentsCount) {
         SolrDocument solrDocument = new SolrDocument();
         solrDocument.addField("type", compnonet.getName());
@@ -481,22 +452,22 @@ public class AuditMgr extends MgrBase {
       return docList;
     } catch (SolrException | SolrServerException | IOException e) {
       logger.error("Error during solrQuery=" + solrQuery, e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
   public String getAuditLogsSchemaFieldsName() {
     String suffix = PropertiesUtil.getProperty("auditlog.solr.core.logs");
     String excludeArray[] = PropertiesUtil
-      .getPropertyStringList("auditlog.exclude.columnlist");
+        .getPropertyStringList("auditlog.exclude.columnlist");
     List<String> fieldNames = new ArrayList<String>();
     HashMap<String, String> uiFieldColumnMapping = new HashMap<String, String>();
     ConfigUtil.getSchemaFieldsName(suffix, excludeArray, fieldNames);
 
     for (String fieldName : fieldNames) {
       String uiField = ConfigUtil.auditLogsColumnMapping.get(fieldName
-        + LogSearchConstants.SOLR_SUFFIX);
+          + LogSearchConstants.SOLR_SUFFIX);
       if (uiField == null) {
         uiFieldColumnMapping.put(fieldName, fieldName);
       } else {
@@ -504,33 +475,24 @@ public class AuditMgr extends MgrBase {
       }
     }
 
-    try {
-      uiFieldColumnMapping = bizUtil
-        .sortHashMapByValuesD(uiFieldColumnMapping);
-      return convertObjToString(uiFieldColumnMapping);
-    } catch (IOException e) {
-      logger.error(e);
-    }
-    throw restErrorUtil.createRESTException(
-      "Cache is Empty for FieldsName", MessageEnums.DATA_NOT_FOUND);
+    uiFieldColumnMapping = bizUtil.sortHashMapByValues(uiFieldColumnMapping);
+    return convertObjToString(uiFieldColumnMapping);
+
   }
 
   public String getAnyGraphData(SearchCriteria searchCriteria) {
-    searchCriteria.addParam("feildTime", LogSearchConstants.AUDIT_EVTTIME);
+    searchCriteria.addParam("fieldTime", LogSearchConstants.AUDIT_EVTTIME);
     String suffix = PropertiesUtil.getProperty("auditlog.solr.core.logs");
     searchCriteria.addParam("suffix", suffix);
-    SolrQuery solrQuery = queryGenerator
-      .commonAuditFilterQuery(searchCriteria);
-    String result = graphDataGnerator.getAnyGraphData(searchCriteria,
-      auditSolrDao, solrQuery);
-    if (result != null)
-      return result;
-    try {
-      return convertObjToString(new VBarDataList());
-    } catch (IOException e) {
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+    SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
+    VBarDataList result = graphDataGenerator.getAnyGraphData(searchCriteria,
+        auditSolrDao, solrQuery);
+    if (result == null) {
+      result = new VBarDataList();
     }
+
+    return convertObjToString(result);
+
   }
 
   @SuppressWarnings("unchecked")
@@ -586,20 +548,27 @@ public class AuditMgr extends MgrBase {
     String dataFormat = (String) searchCriteria.getParamValue("format");
     try {
       QueryResponse queryResponse = auditSolrDao.process(solrQuery);
+      if(queryResponse == null){
+        VResponse response = new VResponse();
+        response.setMsgDesc("Query was not able to execute "+solrQuery);
+        throw restErrorUtil.createRESTException(response);
+      }
 
       NamedList<Object> namedList = queryResponse.getResponse();
+      if(namedList == null){
+        VResponse response = new VResponse();
+        response.setMsgDesc("Query was not able to execute "+solrQuery);
+        throw restErrorUtil.createRESTException(response);
+      }
       VBarDataList vBarUserDataList = new VBarDataList();
       VBarDataList vBarResourceDataList = new VBarDataList();
-      if (namedList == null) {
-
-      }
 
       SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList
         .get("facets");
       vBarUserDataList = bizUtil
-        .buildSummaryForTopCounts(jsonFacetResponse);
+        .buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
       vBarResourceDataList = bizUtil
-        .buildSummaryForResourceCounts(jsonFacetResponse);
+        .buildSummaryForTopCounts(jsonFacetResponse,"y","x");
       String data = "";
       String summary = "";
       if ("text".equals(dataFormat)) {
@@ -698,8 +667,8 @@ public class AuditMgr extends MgrBase {
 
     } catch (SolrServerException | SolrException | IOException e) {
       logger.error("Error during solrQuery=" + e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
@@ -725,10 +694,19 @@ public class AuditMgr extends MgrBase {
         LogSearchConstants.AUDIT_COMPONENT);
       QueryResponse serviceLoadResponse = auditSolrDao
         .process(serivceLoadQuery);
-      if (serviceLoadResponse == null)
-        return "[]";
-      List<Count> serviceLoadFacets = serviceLoadResponse.getFacetField(
-        LogSearchConstants.AUDIT_COMPONENT).getValues();
+      if (serviceLoadResponse == null){
+        return convertObjToString(dataList);
+      }
+      FacetField serviceFacetField =serviceLoadResponse.getFacetField(
+          LogSearchConstants.AUDIT_COMPONENT);
+      if(serviceFacetField == null){
+        return convertObjToString(dataList);
+      }
+      
+      List<Count> serviceLoadFacets = serviceFacetField.getValues();
+      if(serviceLoadFacets == null){
+        return convertObjToString(dataList);
+      }
       for (Count cnt : serviceLoadFacets) {
         List<VNameValue> valueList = new ArrayList<VNameValue>();
         VBarGraphData vBarGraphData = new VBarGraphData();
@@ -746,8 +724,8 @@ public class AuditMgr extends MgrBase {
 
     } catch (SolrException | SolrServerException | IOException e) {
       logger.error("Error during solrQuery=" + e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
     
   /*