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:39 UTC

[4/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/manager/MgrBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/MgrBase.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/MgrBase.java
index cf50a87..1d069d3 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/MgrBase.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/MgrBase.java
@@ -21,12 +21,14 @@ package org.apache.ambari.logsearch.manager;
 
 import java.io.File;
 import java.io.IOException;
+import java.text.ParseException;
 import java.util.Date;
 import java.util.Scanner;
 
 import org.apache.ambari.logsearch.common.MessageEnums;
 import org.apache.ambari.logsearch.dao.SolrDaoBase;
 import org.apache.ambari.logsearch.query.QueryGeneration;
+import org.apache.ambari.logsearch.util.DateUtil;
 import org.apache.ambari.logsearch.util.JSONUtil;
 import org.apache.ambari.logsearch.util.RESTErrorUtil;
 import org.apache.ambari.logsearch.util.SolrUtil;
@@ -60,7 +62,7 @@ public class MgrBase {
   JSONUtil jsonUtil;
 
   @Autowired
-  QueryGeneration queryGenrator;
+  QueryGeneration queryGenerator;
 
   @Autowired
   StringUtil stringUtil;
@@ -68,16 +70,35 @@ public class MgrBase {
   @Autowired
   RESTErrorUtil restErrorUtil;
 
+  @Autowired
+  DateUtil dateUtil;
+
   JsonSerializer<Date> jsonDateSerialiazer = null;
   JsonDeserializer<Date> jsonDateDeserialiazer = null;
 
+  public enum LOG_TYPE {
+    SERVICE {
+      @Override
+      public String getLabel() {
+        return "Service";
+      }
+    },
+    AUDIT {
+      @Override
+      public String getLabel() {
+        return "Audit";
+      }
+    };
+    public abstract String getLabel();
+  }
+
   public MgrBase() {
     jsonDateSerialiazer = new JsonSerializer<Date>() {
 
       @Override
       public JsonElement serialize(Date paramT,
-                                   java.lang.reflect.Type paramType,
-                                   JsonSerializationContext paramJsonSerializationContext) {
+          java.lang.reflect.Type paramType,
+          JsonSerializationContext paramJsonSerializationContext) {
 
         return paramT == null ? null : new JsonPrimitive(paramT.getTime());
       }
@@ -86,38 +107,33 @@ public class MgrBase {
     jsonDateDeserialiazer = new JsonDeserializer<Date>() {
 
       @Override
-      public Date deserialize(JsonElement json,
-                              java.lang.reflect.Type typeOfT,
-                              JsonDeserializationContext context) throws JsonParseException {
+      public Date deserialize(JsonElement json, java.lang.reflect.Type typeOfT,
+          JsonDeserializationContext context) throws JsonParseException {
         return json == null ? null : new Date(json.getAsLong());
       }
 
     };
   }
 
-  public String convertObjToString(Object obj) throws IOException {
+  public String convertObjToString(Object obj) {
     if (obj == null) {
       return "";
     }
-    /*ObjectMapper mapper = new ObjectMapper();
-    ObjectWriter w = mapper.writerWithDefaultPrettyPrinter();
-    return mapper.writeValueAsString(obj);*/
 
     Gson gson = new GsonBuilder()
-      .registerTypeAdapter(Date.class, jsonDateSerialiazer)
-      .registerTypeAdapter(Date.class, jsonDateDeserialiazer).create();
+        .registerTypeAdapter(Date.class, jsonDateSerialiazer)
+        .registerTypeAdapter(Date.class, jsonDateDeserialiazer).create();
 
     return gson.toJson(obj);
   }
 
-
   public String getHadoopServiceConfigJSON() {
     StringBuilder result = new StringBuilder("");
 
     // Get file from resources folder
     ClassLoader classLoader = getClass().getClassLoader();
-    File file = new File(classLoader
-      .getResource("HadoopServiceConfig.json").getFile());
+    File file = new File(classLoader.getResource("HadoopServiceConfig.json")
+        .getFile());
 
     try (Scanner scanner = new Scanner(file)) {
 
@@ -131,37 +147,67 @@ public class MgrBase {
     } catch (IOException e) {
       logger.error("Unable to read HadoopServiceConfig.json", e);
       throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+          MessageEnums.ERROR_SYSTEM);
     }
 
     String hadoopServiceConfig = result.toString();
-    if (jsonUtil.isJSONValid(hadoopServiceConfig))
+    if (jsonUtil.isJSONValid(hadoopServiceConfig)) {
       return hadoopServiceConfig;
+    }
     throw restErrorUtil.createRESTException("Improper JSON",
-      MessageEnums.ERROR_SYSTEM);
+        MessageEnums.ERROR_SYSTEM);
 
   }
 
-  public VSolrLogList getLogAsPaginationProvided(SolrQuery solrQuery, SolrDaoBase solrDaoBase) {
+  public VSolrLogList getLogAsPaginationProvided(SolrQuery solrQuery,
+      SolrDaoBase solrDaoBase) {
     try {
       QueryResponse response = solrDaoBase.process(solrQuery);
+      VSolrLogList collection = new VSolrLogList();
       SolrDocumentList docList = response.getResults();
-      VSolrLogList collection = new VSolrLogList(docList);
-      collection.setStartIndex((int) docList.getStart());
-      collection.setTotalCount(docList.getNumFound());
-      Integer rowNumber = solrQuery.getRows();
-      if (rowNumber == null) {
-        logger.error("No RowNumber was set in solrQuery");
-        return new VSolrLogList();
+      if (docList != null && !docList.isEmpty()) {
+        collection.setSolrDocuments(docList);
+        collection.setStartIndex((int) docList.getStart());
+        collection.setTotalCount(docList.getNumFound());
+        Integer rowNumber = solrQuery.getRows();
+        if (rowNumber == null) {
+          logger.error("No RowNumber was set in solrQuery");
+          return new VSolrLogList();
+        }
+        collection.setPageSize(rowNumber);
       }
-      collection.setPageSize(rowNumber);
       return collection;
     } 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);
+    }
+
+  }
+
+  protected String getUnit(String unit) {
+    if (stringUtil.isEmpty(unit)) {
+      unit = "+1HOUR";
     }
+    return unit;
+  }
 
+  protected String getFrom(String from) {
+    if (stringUtil.isEmpty(from)) {
+      Date date =  dateUtil.getTodayFromDate();
+      try {
+        from = dateUtil.convertGivenDateFormatToSolrDateFormat(date);
+      } catch (ParseException e) {
+        from = "NOW";
+      }
+    }
+    return from;
   }
 
+  protected String getTo(String to) {
+    if (stringUtil.isEmpty(to)) {
+      to = "NOW";
+    }
+    return to;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java
index 0a4328b..0dccb74 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java
@@ -19,22 +19,17 @@
 
 package org.apache.ambari.logsearch.manager;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.ambari.logsearch.common.MessageEnums;
 import org.apache.ambari.logsearch.view.VNameValue;
 import org.apache.ambari.logsearch.view.VNameValueList;
 import org.apache.ambari.logsearch.web.security.LogsearchSimpleAuthenticationProvider;
-import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 @Component
 public class PublicMgr extends MgrBase {
-  private static Logger logger = Logger.getLogger(PublicMgr.class);
-
   @Autowired
   LogsearchSimpleAuthenticationProvider simpleAuthenticationProvider;
 
@@ -46,10 +41,6 @@ public class PublicMgr extends MgrBase {
     nameValue.setValue("" + simpleAuthenticationProvider.isEnable());
     nameValues.add(nameValue);
     nameValueList.setVNameValues(nameValues);
-    try {
-      return convertObjToString(nameValueList);
-    } catch (IOException e) {
-      throw restErrorUtil.createRESTException(e.getMessage(), MessageEnums.ERROR_SYSTEM);
-    }
+    return convertObjToString(nameValueList);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java
index d76a3e7..a60402e 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java
@@ -32,7 +32,7 @@ import org.apache.ambari.logsearch.common.MessageEnums;
 import org.apache.ambari.logsearch.common.SearchCriteria;
 import org.apache.ambari.logsearch.dao.UserConfigSolrDao;
 import org.apache.ambari.logsearch.query.QueryGeneration;
-import org.apache.ambari.logsearch.util.ConfigUtil;
+import org.apache.ambari.logsearch.util.PropertiesUtil;
 import org.apache.ambari.logsearch.util.RESTErrorUtil;
 import org.apache.ambari.logsearch.util.SolrUtil;
 import org.apache.ambari.logsearch.util.StringUtil;
@@ -58,6 +58,8 @@ import com.google.gson.JsonParseException;
 
 @Component
 public class UserConfigMgr extends MgrBase {
+  private static final String DEFAULT_LEVELS = "FATAL,ERROR,WARN,INFO,DEBUG,TRACE";
+
   static Logger logger = Logger.getLogger(UserConfigMgr.class);
 
   @Autowired
@@ -80,34 +82,35 @@ public class UserConfigMgr extends MgrBase {
     SolrInputDocument solrInputDoc = new SolrInputDocument();
     if (!isValid(vHistory)) {
       throw restErrorUtil.createRESTException("No FilterName Specified",
-        MessageEnums.INVALID_INPUT_DATA);
+          MessageEnums.INVALID_INPUT_DATA);
     }
 
     if (isNotUnique(vHistory) && !vHistory.isOverwrite()) {
       throw restErrorUtil.createRESTException(
-        "Name '" + vHistory.getFilterName() + "' already exists",
-        MessageEnums.INVALID_INPUT_DATA);
+          "Name '" + vHistory.getFilterName() + "' already exists",
+          MessageEnums.INVALID_INPUT_DATA);
     }
 
     solrInputDoc.addField(LogSearchConstants.ID, vHistory.getId());
-    solrInputDoc.addField(LogSearchConstants.USER_NAME,
-      vHistory.getUserName());
+    solrInputDoc.addField(LogSearchConstants.USER_NAME, vHistory.getUserName());
     solrInputDoc.addField(LogSearchConstants.VALUES, vHistory.getValues());
     solrInputDoc.addField(LogSearchConstants.FILTER_NAME,
-      vHistory.getFilterName());
-    solrInputDoc.addField(LogSearchConstants.ROW_TYPE,
-      vHistory.getRowType());
+        vHistory.getFilterName());
+    solrInputDoc.addField(LogSearchConstants.ROW_TYPE, vHistory.getRowType());
     List<String> shareNameList = vHistory.getShareNameList();
-    if (shareNameList != null && !shareNameList.isEmpty())
+    if (shareNameList != null && !shareNameList.isEmpty()){
       solrInputDoc.addField(LogSearchConstants.SHARE_NAME_LIST, shareNameList);
+    }
+    solrInputDoc.addField(LogSearchConstants.COMPOSITE_KEY,
+        vHistory.getFilterName() + "-" + vHistory.getUserName());
 
     try {
       userConfigSolrDao.addDocs(solrInputDoc);
       return convertObjToString(solrInputDoc);
     } catch (SolrException | SolrServerException | IOException e) {
-      logger.error(e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      logger.error("Error saving user config. solrDoc=" + solrInputDoc, e);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
@@ -118,16 +121,17 @@ public class UserConfigMgr extends MgrBase {
     if (filterName != null && rowType != null) {
       SolrQuery solrQuery = new SolrQuery();
       filterName = solrUtil.makeSearcableString(filterName);
-      solrQuery.setQuery(LogSearchConstants.COMPOSITE_KEY + ":"
-        + filterName + "-" + rowType);
+      solrQuery.setQuery(LogSearchConstants.COMPOSITE_KEY + ":" + filterName
+          + "-" + rowType);
       queryGenerator.setRowCount(solrQuery, 0);
       try {
-        Long numFound = userConfigSolrDao.process(solrQuery)
-          .getResults().getNumFound();
-        if (numFound > 0)
+        Long numFound = userConfigSolrDao.process(solrQuery).getResults()
+            .getNumFound();
+        if (numFound > 0) {
           return true;
+        }
       } catch (SolrException | SolrServerException | IOException e) {
-        logger.error(e);
+        logger.error("Error while checking if userConfig is unique.", e);
       }
     }
     return false;
@@ -136,18 +140,18 @@ public class UserConfigMgr extends MgrBase {
   private boolean isValid(VUserConfig vHistory) {
 
     return !stringUtil.isEmpty(vHistory.getFilterName())
-      && !stringUtil.isEmpty(vHistory.getRowType())
-      && !stringUtil.isEmpty(vHistory.getUserName())
-      && !stringUtil.isEmpty(vHistory.getValues());
+        && !stringUtil.isEmpty(vHistory.getRowType())
+        && !stringUtil.isEmpty(vHistory.getUserName())
+        && !stringUtil.isEmpty(vHistory.getValues());
   }
 
   public void deleteUserConfig(String id) {
     try {
       userConfigSolrDao.removeDoc("id:" + id);
     } catch (SolrException | SolrServerException | IOException e) {
-      logger.error(e);
-      throw restErrorUtil.createRESTException(e.getMessage(),
-        MessageEnums.ERROR_SYSTEM);
+      logger.error("Deleting userCounfig. id=" + id, e);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
@@ -158,24 +162,21 @@ public class UserConfigMgr extends MgrBase {
     VUserConfigList userConfigList = new VUserConfigList();
 
     String rowType = (String) searchCriteria
-      .getParamValue(LogSearchConstants.ROW_TYPE);
+        .getParamValue(LogSearchConstants.ROW_TYPE);
     if (stringUtil.isEmpty(rowType)) {
-      throw restErrorUtil.createRESTException(
-        "row type was not specified",
-        MessageEnums.INVALID_INPUT_DATA);
+      throw restErrorUtil.createRESTException("row type was not specified",
+          MessageEnums.INVALID_INPUT_DATA);
     }
 
     String userName = (String) searchCriteria
-      .getParamValue(LogSearchConstants.USER_NAME);
+        .getParamValue(LogSearchConstants.USER_NAME);
     if (stringUtil.isEmpty(userName)) {
-      throw restErrorUtil.createRESTException(
-        "user name was not specified",
-        MessageEnums.INVALID_INPUT_DATA);
+      throw restErrorUtil.createRESTException("user name was not specified",
+          MessageEnums.INVALID_INPUT_DATA);
     }
     String filterName = (String) searchCriteria
-      .getParamValue(LogSearchConstants.FILTER_NAME);
-    filterName = stringUtil.isEmpty(filterName) ? "*" : "*" + filterName
-      + "*";
+        .getParamValue(LogSearchConstants.FILTER_NAME);
+    filterName = stringUtil.isEmpty(filterName) ? "*" : "*" + filterName + "*";
 
     try {
 
@@ -183,19 +184,20 @@ public class UserConfigMgr extends MgrBase {
       queryGenerator.setMainQuery(userConfigQuery, null);
       queryGenerator.setPagination(userConfigQuery, searchCriteria);
       queryGenerator.setSingleIncludeFilter(userConfigQuery,
-        LogSearchConstants.ROW_TYPE, rowType);
+          LogSearchConstants.ROW_TYPE, rowType);
       queryGenerator.setSingleORFilter(userConfigQuery,
-        LogSearchConstants.USER_NAME, userName,
-        LogSearchConstants.SHARE_NAME_LIST, userName);
+          LogSearchConstants.USER_NAME, userName,
+          LogSearchConstants.SHARE_NAME_LIST, userName);
       queryGenerator.setSingleIncludeFilter(userConfigQuery,
-        LogSearchConstants.FILTER_NAME, filterName);
+          LogSearchConstants.FILTER_NAME, filterName);
 
       if (stringUtil.isEmpty(searchCriteria.getSortBy())
-        || searchCriteria.getSortBy().equals("historyName"))
-        searchCriteria
-          .setSortBy(LogSearchConstants.FILTER_NAME);
-      if (stringUtil.isEmpty(searchCriteria.getSortType()))
+          || searchCriteria.getSortBy().equals("historyName")) {
+        searchCriteria.setSortBy(LogSearchConstants.FILTER_NAME);
+      }
+      if (stringUtil.isEmpty(searchCriteria.getSortType())) {
         searchCriteria.setSortType("" + SolrQuery.ORDER.asc);
+      }
 
       queryGenerator.setSingleSortOrder(userConfigQuery, searchCriteria);
       solrList = userConfigSolrDao.process(userConfigQuery).getResults();
@@ -205,21 +207,19 @@ public class UserConfigMgr extends MgrBase {
       for (SolrDocument solrDoc : solrList) {
         VUserConfig userConfig = new VUserConfig();
         userConfig.setFilterName(""
-          + solrDoc.get(LogSearchConstants.FILTER_NAME));
+            + solrDoc.get(LogSearchConstants.FILTER_NAME));
         userConfig.setId("" + solrDoc.get(LogSearchConstants.ID));
         userConfig.setValues("" + solrDoc.get(LogSearchConstants.VALUES));
-        userConfig.setRowType(""
-          + solrDoc.get(LogSearchConstants.ROW_TYPE));
+        userConfig.setRowType("" + solrDoc.get(LogSearchConstants.ROW_TYPE));
         try {
           List<String> shareNameList = (List<String>) solrDoc
-            .get(LogSearchConstants.SHARE_NAME_LIST);
+              .get(LogSearchConstants.SHARE_NAME_LIST);
           userConfig.setShareNameList(shareNameList);
         } catch (Exception e) {
           // do nothing
         }
 
-        userConfig.setUserName(""
-          + solrDoc.get(LogSearchConstants.USER_NAME));
+        userConfig.setUserName("" + solrDoc.get(LogSearchConstants.USER_NAME));
 
         configList.add(userConfig);
       }
@@ -231,17 +231,17 @@ public class UserConfigMgr extends MgrBase {
       userConfigList.setPageSize((int) searchCriteria.getMaxRows());
 
       userConfigList.setTotalCount((long) solrList.getNumFound());
-      userConfigList
-        .setResultSize((int) (configList.size() - searchCriteria
+      userConfigList.setResultSize((int) (configList.size() - searchCriteria
           .getStartIndex()));
     } catch (SolrException | SolrServerException | IOException e) {
       // do nothing
+      logger.error(e);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
-    try {
-      return convertObjToString(userConfigList);
-    } catch (IOException e) {
-      return "";
-    }
+
+    return convertObjToString(userConfigList);
+
   }
 
   public String updateUserConfig(VUserConfig vuserConfig) {
@@ -270,35 +270,49 @@ public class UserConfigMgr extends MgrBase {
       if (documentList != null && documentList.size() > 0) {
         SolrDocument configDoc = documentList.get(0);
         String configJson = jsonUtil.objToJson(configDoc);
-        HashMap<String, Object> configMap = (HashMap<String, Object>) jsonUtil.jsonToMapObject(configJson);
+        HashMap<String, Object> configMap = (HashMap<String, Object>) jsonUtil
+            .jsonToMapObject(configJson);
         String json = (String) configMap.get(LogSearchConstants.VALUES);
-        logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil.jsonToObj(json, VLogfeederFilterWrapper.class);
+        logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil.jsonToObj(
+            json, VLogfeederFilterWrapper.class);
         logfeederFilterWrapper.setId("" + configDoc.get(LogSearchConstants.ID));
 
       } else {
+        String logfeederDefaultLevels = PropertiesUtil
+            .getProperty("logfeeder.include.default.level", DEFAULT_LEVELS);
+        JSONArray levelJsonArray = new JSONArray();
+        try {
+          String levelArray[] = logfeederDefaultLevels.split(",");
+          for (String level : levelArray) {
+            levelJsonArray.put(level.toUpperCase());
+          }
+        } catch (Exception e) {
+          logger.error("Error spliting logfeederDefaultLevels="
+              + logfeederDefaultLevels, e);
+          throw restErrorUtil.createRESTException(e.getMessage(),
+              MessageEnums.ERROR_SYSTEM);
+        }
         String hadoopServiceString = getHadoopServiceConfigJSON();
+        String key = null;
+        JSONArray componentArray = null;
         try {
-
           JSONObject componentList = new JSONObject();
           JSONObject jsonValue = new JSONObject();
 
-          JSONObject hadoopServiceJsonObject = new JSONObject(hadoopServiceString)
-            .getJSONObject("service");
-          Iterator<String> hadoopSerivceKeys = hadoopServiceJsonObject
-            .keys();
+          JSONObject hadoopServiceJsonObject = new JSONObject(
+              hadoopServiceString).getJSONObject("service");
+          Iterator<String> hadoopSerivceKeys = hadoopServiceJsonObject.keys();
           while (hadoopSerivceKeys.hasNext()) {
-            String key = hadoopSerivceKeys.next();
-            JSONArray componentArray = hadoopServiceJsonObject
-              .getJSONObject(key).getJSONArray("components");
+            key = hadoopSerivceKeys.next();
+            componentArray = hadoopServiceJsonObject.getJSONObject(key)
+                .getJSONArray("components");
             for (int i = 0; i < componentArray.length(); i++) {
-              JSONObject compJsonObject = (JSONObject) componentArray
-                .get(i);
-              String componentName = compJsonObject
-                .getString("name");
+              JSONObject compJsonObject = (JSONObject) componentArray.get(i);
+              String componentName = compJsonObject.getString("name");
               JSONObject innerContent = new JSONObject();
               innerContent.put("label", componentName);
               innerContent.put("hosts", new JSONArray());
-              innerContent.put("defaultLevels", new JSONArray());
+              innerContent.put("defaultLevels", levelJsonArray);
               componentList.put(componentName, innerContent);
             }
           }
@@ -306,14 +320,16 @@ public class UserConfigMgr extends MgrBase {
           return saveUserFiter(jsonValue.toString());
 
         } catch (JsonParseException | JSONException je) {
-          logger.error(je);
+          logger.error("Error parsing JSON. key=" + key + ", componentArray="
+              + componentArray, je);
           logfeederFilterWrapper = new VLogfeederFilterWrapper();
         }
       }
       return convertObjToString(logfeederFilterWrapper);
     } catch (SolrException | SolrServerException | IOException e) {
       logger.error(e);
-      throw restErrorUtil.createRESTException(e.getMessage(), MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
   }
 
@@ -324,11 +340,12 @@ public class UserConfigMgr extends MgrBase {
    * @return
    */
   public String saveUserFiter(String json) {
-    VLogfeederFilterWrapper logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil.jsonToObj(json,
-      VLogfeederFilterWrapper.class);
+    VLogfeederFilterWrapper logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil
+        .jsonToObj(json, VLogfeederFilterWrapper.class);
     if (logfeederFilterWrapper == null) {
       logger.error("filter json is not a valid :" + json);
-      throw restErrorUtil.createRESTException("Invalid filter json", MessageEnums.ERROR_SYSTEM);
+      throw restErrorUtil.createRESTException("Invalid filter json",
+          MessageEnums.ERROR_SYSTEM);
     }
     String id = logfeederFilterWrapper.getId();
     if (!stringUtil.isEmpty(id)) {
@@ -336,17 +353,20 @@ public class UserConfigMgr extends MgrBase {
     }
     String filterName = LogSearchConstants.LOGFEEDER_FILTER_NAME;
     json = jsonUtil.objToJson(logfeederFilterWrapper);
-    SolrInputDocument conifgDocument = new SolrInputDocument();
-    conifgDocument.addField(LogSearchConstants.ID, new Date().getTime());
-    conifgDocument.addField(LogSearchConstants.ROW_TYPE, filterName);
-    conifgDocument.addField(LogSearchConstants.VALUES, json);
-    conifgDocument.addField(LogSearchConstants.USER_NAME, filterName);
-    conifgDocument.addField(LogSearchConstants.FILTER_NAME, filterName);
+    SolrInputDocument configDocument = new SolrInputDocument();
+    configDocument.addField(LogSearchConstants.ID, new Date().getTime());
+    configDocument.addField(LogSearchConstants.ROW_TYPE, filterName);
+    configDocument.addField(LogSearchConstants.VALUES, json);
+    configDocument.addField(LogSearchConstants.USER_NAME, filterName);
+    configDocument.addField(LogSearchConstants.FILTER_NAME, filterName);
+    configDocument.addField(LogSearchConstants.COMPOSITE_KEY, filterName + "-"
+        + filterName);
     try {
-      userConfigSolrDao.addDocs(conifgDocument);
+      userConfigSolrDao.addDocs(configDocument);
     } catch (SolrException | SolrServerException | IOException e) {
-      logger.error(e);
-      throw restErrorUtil.createRESTException(e.getMessage(), MessageEnums.ERROR_SYSTEM);
+      logger.error("Saving UserConfig. config=" + configDocument, e);
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
     return getUserFilter();
   }
@@ -356,27 +376,25 @@ public class UserConfigMgr extends MgrBase {
     try {
       SolrQuery userListQuery = new SolrQuery();
       queryGenerator.setMainQuery(userListQuery, null);
-      queryGenerator.setFacetField(userListQuery,
-        LogSearchConstants.USER_NAME);
-      QueryResponse queryResponse = userConfigSolrDao
-        .process(userListQuery);
-      if (queryResponse == null)
+      queryGenerator.setFacetField(userListQuery, LogSearchConstants.USER_NAME);
+      QueryResponse queryResponse = userConfigSolrDao.process(userListQuery);
+      if (queryResponse == null) {
         return convertObjToString(userList);
+      }
       List<Count> counList = queryResponse.getFacetField(
-        LogSearchConstants.USER_NAME).getValues();
+          LogSearchConstants.USER_NAME).getValues();
       for (Count cnt : counList) {
         String userName = cnt.getName();
         userList.add(userName);
       }
     } catch (SolrException | SolrServerException | IOException e) {
+      logger.warn("Error getting all users.", e);
       // do nothing
+      throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+          .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
     }
+    return convertObjToString(userList);
 
-    try {
-      return convertObjToString(userList);
-    } catch (IOException e) {
-      return "";
-    }
   }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java
index 38a31fb..2f47ec5 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java
@@ -27,94 +27,67 @@ import java.util.regex.Pattern;
 
 import org.apache.ambari.logsearch.common.LogSearchConstants;
 import org.apache.ambari.logsearch.common.SearchCriteria;
-import org.apache.ambari.logsearch.util.BizUtil;
+import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
 import org.apache.ambari.logsearch.util.ConfigUtil;
-import org.apache.ambari.logsearch.util.DateUtil;
-import org.apache.ambari.logsearch.util.JSONUtil;
 import org.apache.ambari.logsearch.util.PropertiesUtil;
-import org.apache.ambari.logsearch.util.RESTErrorUtil;
-import org.apache.ambari.logsearch.util.SolrUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
 import org.apache.log4j.Logger;
 import org.apache.solr.client.solrj.SolrQuery;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 @Component
 public class QueryGeneration extends QueryGenerationBase {
 
-  static Logger logger = Logger.getLogger(QueryGeneration.class);
-
-  @Autowired
-  SolrUtil solrUtil;
-
-  @Autowired
-  RESTErrorUtil restErrorUtil;
-
-  @Autowired
-  BizUtil bizUtil;
-
-  @Autowired
-  DateUtil dateUtil;
-
-  @Autowired
-  StringUtil stringUtil;
-
-  @Autowired
-  JSONUtil jsonUtil;
-
-  public SolrQuery commonFilterQuery(SearchCriteria searchCriteria) {
+  private static Logger logger = Logger.getLogger(QueryGeneration.class);
 
+  public SolrQuery commonServiceFilterQuery(SearchCriteria searchCriteria) {
+    LOG_TYPE logType = LOG_TYPE.SERVICE;
     SolrQuery solrQuery = new SolrQuery();
-
-    String jsonHCNames = (String) searchCriteria
-      .getParamValue("treeParams");
+    String treeParams = (String) searchCriteria.getParamValue("treeParams");
     String givenQuery = (String) searchCriteria.getParamValue("q");
     String level = (String) searchCriteria.getParamValue("level");
-
     String startTime = (String) searchCriteria.getParamValue("from");
     String endTime = (String) searchCriteria.getParamValue("to");
     String iMessage = (String) searchCriteria.getParamValue("iMessage");
     String eMessage = (String) searchCriteria.getParamValue("eMessage");
     String gEmessage = (String) searchCriteria.getParamValue("gEMessage");
-    String selectedComp = (String) searchCriteria
-      .getParamValue("selectComp");
+    String selectedComp = (String) searchCriteria.getParamValue("selectComp");
     String bundleId = (String) searchCriteria
-      .getParamValue(LogSearchConstants.BUNDLE_ID);
+        .getParamValue(LogSearchConstants.BUNDLE_ID);
     String globalExcludeComp = (String) searchCriteria
-      .getParamValue("gMustNot");
+        .getParamValue("gMustNot");
     String unselectedComp = (String) searchCriteria
-      .getParamValue("unselectComp");
+        .getParamValue("unselectComp");
     String urlHostName = (String) searchCriteria.getParamValue("host_name");
-    String urlComponents = (String) searchCriteria.getParamValue("components_name");
-
+    String urlComponentName = (String) searchCriteria
+        .getParamValue("component_name");
+    String file_name = (String) searchCriteria.getParamValue("file_name");
     String advQuery = (String) searchCriteria.getParamValue("advanceSearch");
+    // build advance query
     if (!stringUtil.isEmpty(advQuery)) {
       String advQueryParameters[] = advQuery.split(Pattern.quote("}{"));
       SolrQuery advSolrQuery = new SolrQuery();
-
       for (String queryParam : advQueryParameters) {
         String params[] = queryParam.split(Pattern.quote("="));
-        advSolrQuery.setParam(params[0], params[1]);
+        if (params != null && params.length > 1)
+          advSolrQuery.setParam(params[0], params[1]);
       }
-
       // Building and adding levels to filters
       setFilterClauseWithFieldName(advSolrQuery, level,
-        LogSearchConstants.SOLR_LEVEL, "", "OR");
+          LogSearchConstants.SOLR_LEVEL, "", CONDITION.OR);
 
       // Adding Logtime to filters
-      setSingleRangeFilter(advSolrQuery, LogSearchConstants.LOGTIME,
-        startTime, endTime);
+      setSingleRangeFilter(advSolrQuery, LogSearchConstants.LOGTIME, startTime,
+          endTime);
 
       // Building and adding exlcude components to filters
       setFilterClauseWithFieldName(advSolrQuery, unselectedComp,
-        LogSearchConstants.SOLR_COMPONENT,
-        LogSearchConstants.MINUS_OPERATOR, "AND");
+          LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
+          CONDITION.AND);
 
       // Building and adding exlcude components to filters
       setFilterClauseWithFieldName(advSolrQuery, selectedComp,
-        LogSearchConstants.SOLR_COMPONENT,
-        LogSearchConstants.NO_OPERATOR, "OR");
+          LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.NO_OPERATOR,
+          CONDITION.OR);
 
       // Set Pagination
       setPagination(advSolrQuery, searchCriteria);
@@ -126,52 +99,67 @@ public class QueryGeneration extends QueryGenerationBase {
 
     // Adding Logtime to filters
     setSingleRangeFilter(solrQuery, LogSearchConstants.LOGTIME, startTime,
-      endTime);
+        endTime);
+
+    // String mainFilterQuery = buildQueryFromJSONCompHost(jsonHCNames,
+    // selectedComp);
 
-    String mainFilterQuery = buildQueryFromJSONCompHost(jsonHCNames, selectedComp);
+    // if (mainFilterQuery != null && !mainFilterQuery.equals(""))
+    // solrQuery.addFilterQuery(mainFilterQuery);
 
-    if (mainFilterQuery != null && !mainFilterQuery.equals(""))
-      solrQuery.addFilterQuery(mainFilterQuery);
+    // add component filter
+    addFilter(solrQuery, selectedComp, LogSearchConstants.SOLR_COMPONENT,
+        CONDITION.OR);
+
+    // add treeParams filter
+    // hosts comma separated list
+    addFilterQueryFromArray(solrQuery, treeParams,
+        LogSearchConstants.SOLR_HOST, CONDITION.OR);
 
     // Building and adding levels to filters
-    setFilterClauseWithFieldName(solrQuery, level, LogSearchConstants.SOLR_LEVEL, "", "OR");
+    setFilterClauseWithFieldName(solrQuery, level,
+        LogSearchConstants.SOLR_LEVEL, LogSearchConstants.NO_OPERATOR,
+        CONDITION.OR);
 
     // Building and adding include string to filters
-    setFilterClauseForSolrSearchableString(solrQuery, iMessage, "OR", "",
-      LogSearchConstants.SOLR_LOG_MESSAGE);
+    setFilterClauseForSolrSearchableString(solrQuery, iMessage, CONDITION.OR,
+        LogSearchConstants.NO_OPERATOR, LogSearchConstants.SOLR_KEY_LOG_MESSAGE);
 
     // Building and adding global exclude string to filters
-    setFilterClauseForSolrSearchableString(solrQuery, gEmessage, "AND",
-      LogSearchConstants.MINUS_OPERATOR,
-      LogSearchConstants.SOLR_LOG_MESSAGE);
+    setFilterClauseForSolrSearchableString(solrQuery, gEmessage, CONDITION.AND,
+        LogSearchConstants.MINUS_OPERATOR, LogSearchConstants.SOLR_KEY_LOG_MESSAGE);
 
     // Building and adding exclude string to filter
-    setFilterClauseForSolrSearchableString(solrQuery, eMessage, "AND",
-      LogSearchConstants.MINUS_OPERATOR,
-      LogSearchConstants.SOLR_LOG_MESSAGE);
+    setFilterClauseForSolrSearchableString(solrQuery, eMessage, CONDITION.AND,
+        LogSearchConstants.MINUS_OPERATOR, LogSearchConstants.SOLR_KEY_LOG_MESSAGE);
 
     // Building and adding logfile to filters
     applyLogFileFilter(solrQuery, searchCriteria);
 
     // Building and adding exclude components to filters
     setFilterClauseWithFieldName(solrQuery, globalExcludeComp,
-      LogSearchConstants.SOLR_COMPONENT,
-      LogSearchConstants.MINUS_OPERATOR, "AND");
+        LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
+        CONDITION.AND);
 
     // Building and adding exlcude components to filters
     setFilterClauseWithFieldName(solrQuery, unselectedComp,
-      LogSearchConstants.SOLR_COMPONENT,
-      LogSearchConstants.MINUS_OPERATOR, "AND");
-
-    //Building and addding host names given url
-    setFilterClauseWithFieldName(solrQuery, urlHostName,
-      LogSearchConstants.SOLR_HOST,
-      "", "OR");
-
-    //Building and addding component names given url
-    setFilterClauseWithFieldName(solrQuery, urlComponents,
-      LogSearchConstants.SOLR_COMPONENT,
-      "", "OR");
+        LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
+        CONDITION.AND);
+
+    // Building and adding host names given url
+    // setFilterClauseWithFieldName(solrQuery, urlHostName,
+    // LogSearchConstants.SOLR_HOST,
+    // "", "OR");
+    urlHostName = solrUtil.escapeQueryChars(urlHostName);
+    setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_HOST, urlHostName);
+    //
+    // //Building and addding component names given url
+    // setFilterClauseWithFieldName(solrQuery, urlComponents,
+    // LogSearchConstants.SOLR_COMPONENT,
+    // "", "OR");
+    urlComponentName = solrUtil.escapeQueryChars(urlComponentName);
+    setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_COMPONENT,
+        urlComponentName);
 
     // Set Pagination
     setPagination(solrQuery, searchCriteria);
@@ -182,156 +170,161 @@ public class QueryGeneration extends QueryGenerationBase {
     // Set Bundle Id
     setSingleIncludeFilter(solrQuery, LogSearchConstants.BUNDLE_ID, bundleId);
 
+    // Set filename
+    file_name = solrUtil.escapeQueryChars(file_name);
+    setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_PATH, file_name);
+    // include query
     this.setUserSpecificFilter(searchCriteria, solrQuery,
-      LogSearchConstants.INCLUDE_QUERY,
-      LogSearchConstants.INCLUDE_QUERY);
-
+        LogSearchConstants.INCLUDE_QUERY, LogSearchConstants.INCLUDE_QUERY,
+        logType);
+    // exclude query
     this.setUserSpecificFilter(searchCriteria, solrQuery,
-      LogSearchConstants.EXCLUDE_QUERY,
-      LogSearchConstants.EXCLUDE_QUERY);
+        LogSearchConstants.EXCLUDE_QUERY, LogSearchConstants.EXCLUDE_QUERY,
+        logType);
     return solrQuery;
   }
 
   public void applyLogFileFilter(SolrQuery solrQuery,
-                                 SearchCriteria searchCriteria) {
-    String hostLogFile = (String) searchCriteria
-      .getParamValue("hostLogFile");
-    String compLogFile = (String) searchCriteria
-      .getParamValue("compLogFile");
+      SearchCriteria searchCriteria) {
+    String hostLogFile = (String) searchCriteria.getParamValue("hostLogFile");
+    String compLogFile = (String) searchCriteria.getParamValue("compLogFile");
     String givenQuery = (String) searchCriteria.getParamValue("q");
     String logfileQuery = "";
-    if (hostLogFile != null && !hostLogFile.equals("")
-      && compLogFile != null && !compLogFile.equals("")) {
-      logfileQuery = "host:" + hostLogFile + " AND type:" + compLogFile;
-      if (givenQuery != null && !givenQuery.equals(""))
-        logfileQuery = "(" + givenQuery + ") AND (" + logfileQuery
-          + ")";
-      solrQuery.addFilterQuery(logfileQuery);
+    if (!stringUtil.isEmpty(hostLogFile) && !stringUtil.isEmpty(compLogFile)) {
+      logfileQuery = LogSearchConstants.SOLR_HOST + ":" + hostLogFile + " "
+          + CONDITION.AND + " " + LogSearchConstants.SOLR_COMPONENT + ":"
+          + compLogFile;
+      if (!stringUtil.isEmpty(givenQuery)) {
+        logfileQuery = "(" + givenQuery + ") " + CONDITION.AND + " ("
+            + logfileQuery + ")";
+      }
+      if (!stringUtil.isEmpty(logfileQuery)) {
+        solrQuery.addFilterQuery(logfileQuery);
+      }
     }
   }
 
   public void setUserSpecificFilter(SearchCriteria searchCriteria,
-                                    SolrQuery solrQuery, String paramName, String operation) {
-
+      SolrQuery solrQuery, String paramName, String operation, LOG_TYPE logType) {
     String queryString = (String) searchCriteria.getParamValue(paramName);
     String columnQuery = (String) searchCriteria
-      .getParamValue(LogSearchConstants.COLUMN_QUERY);
-    if (!stringUtil.isEmpty(queryString) && "[]".equals(queryString))
+        .getParamValue(LogSearchConstants.COLUMN_QUERY);
+    if (stringUtil.isEmpty(queryString)) {
       queryString = null;
+    }
+    // if (!stringUtil.isEmpty(queryString) && "[]".equals(queryString)) {
+    // queryString = null;
+    // }
     if (!stringUtil.isEmpty(columnQuery) && stringUtil.isEmpty(queryString)
-      && !paramName.equals(LogSearchConstants.EXCLUDE_QUERY))
+        && !paramName.equals(LogSearchConstants.EXCLUDE_QUERY)) {
       queryString = columnQuery;
+    }
     List<String> conditionQuries = new ArrayList<String>();
     List<String> referalConditionQuries = new ArrayList<String>();
     List<String> elments = new ArrayList<String>();
-    if (!stringUtil.isEmpty(queryString)) {
-      List<HashMap<String, Object>> queryList = jsonUtil
+    // convert json to list of hashmap
+    List<HashMap<String, Object>> queryList = jsonUtil
         .jsonToMapObjectList(queryString);
-      if (!stringUtil.isEmpty(columnQuery)
-        && !columnQuery.equals(queryString) && !paramName.equals(LogSearchConstants.EXCLUDE_QUERY)) {
+    // null and size check
+    if (queryList != null && queryList.size() > 0) {
+      if (!stringUtil.isEmpty(columnQuery) && !columnQuery.equals(queryString)
+          && !paramName.equals(LogSearchConstants.EXCLUDE_QUERY)) {
         List<HashMap<String, Object>> columnQueryList = jsonUtil
-          .jsonToMapObjectList(columnQuery);
-        queryList.addAll(columnQueryList);
+            .jsonToMapObjectList(columnQuery);
+        if (columnQueryList != null && columnQueryList.size() > 0) {
+          queryList.addAll(columnQueryList);
+        }
       }
-
       for (HashMap<String, Object> columnListMap : queryList) {
         String orQuery = "";
-        String field = "";
-        for (String key : columnListMap.keySet()) {
-          String originalKey = getOriginalKey(key);
-          String value = getOriginalValue(originalKey, ""
-            + columnListMap.get(key));
-          orQuery = originalKey + ":"
-            + putWildCardByType(value, originalKey);
-
-          boolean isSame = false;
-          for (String temp : elments) {
-            if (key.equals(temp))
-              isSame = true;
-          }
-          if (isSame
-            && !operation
-            .equals(LogSearchConstants.EXCLUDE_QUERY)) {
-            for (String tempCondition : conditionQuries) {
-              if (tempCondition.contains(originalKey)) {
-                String newCondtion = tempCondition + " OR "
-                  + orQuery;
-                referalConditionQuries.remove(tempCondition);
-                referalConditionQuries.add(newCondtion);
+        StringBuilder field = new StringBuilder();
+        if (columnListMap != null) {
+          for (String key : columnListMap.keySet()) {
+            if (!stringUtil.isEmpty(key)) {
+              String originalKey = getOriginalKey(key, logType);
+              String value = getOriginalValue(originalKey,
+                  "" + columnListMap.get(key));
+              orQuery = putWildCardByType(value, originalKey, logType);
+              boolean isSame = false;
+              if (elments.contains(key)) {
+                isSame = true;
+              }
+              if (isSame && !operation.equals(LogSearchConstants.EXCLUDE_QUERY)) {
+                for (String tempCondition : conditionQuries) {
+                  if (tempCondition.contains(originalKey)) {
+                    String newCondtion = tempCondition + " "
+                        + CONDITION.OR.name() + " " + orQuery;
+                    referalConditionQuries.remove(tempCondition);
+                    referalConditionQuries.add(newCondtion);
+                  }
+                }
+                conditionQuries.removeAll(conditionQuries);
+                conditionQuries.addAll(referalConditionQuries);
+              } else {
+                conditionQuries.add(orQuery.toString());
+                referalConditionQuries.add(orQuery.toString());
               }
+              field.append(key);
+              elments.add(field.toString());
             }
-            conditionQuries.removeAll(conditionQuries);
-            conditionQuries.addAll(referalConditionQuries);
-          } else {
-            conditionQuries.add(orQuery);
-            referalConditionQuries.add(orQuery);
           }
-
-          field = key;
-          elments.add(field);
         }
-
       }
     }
-    if (!referalConditionQuries.isEmpty()) {
+    if (!referalConditionQuries.isEmpty() && !stringUtil.isEmpty(operation)) {
       if (operation.equals(LogSearchConstants.INCLUDE_QUERY)
-        || operation.equals(LogSearchConstants.COLUMN_QUERY)) {
-        for (String filter : referalConditionQuries)
-          solrQuery.addFilterQuery(filter);
+          || operation.equals(LogSearchConstants.COLUMN_QUERY)) {
+        for (String filter : referalConditionQuries) {
+          if (!stringUtil.isEmpty(filter)) {
+            solrQuery.addFilterQuery(filter);
+          }
+        }
       } else if (operation.equals(LogSearchConstants.EXCLUDE_QUERY)) {
-
         for (String filter : referalConditionQuries) {
-          filter = "-" + filter;
-          solrQuery.addFilterQuery(filter);
+          if (!stringUtil.isEmpty(filter)) {
+            filter = LogSearchConstants.MINUS_OPERATOR + filter;
+            solrQuery.addFilterQuery(filter);
+          }
         }
       }
     }
   }
 
   public SolrQuery commonAuditFilterQuery(SearchCriteria searchCriteria) {
-
+    LOG_TYPE logType = LOG_TYPE.AUDIT;
     SolrQuery solrQuery = new SolrQuery();
     solrQuery.setQuery("*:*");
-
     String startTime = (String) searchCriteria.getParamValue("startTime");
     String endTime = (String) searchCriteria.getParamValue("endTime");
     String selectedComp = (String) searchCriteria
-      .getParamValue("includeString");
-
+        .getParamValue("includeString");
     this.setFilterClauseWithFieldName(solrQuery, selectedComp,
-      LogSearchConstants.AUDIT_COMPONENT,
-      LogSearchConstants.NO_OPERATOR, "OR");
-
+        LogSearchConstants.AUDIT_COMPONENT, LogSearchConstants.NO_OPERATOR,
+        CONDITION.OR);
     String globalExcludeComp = (String) searchCriteria
-      .getParamValue("gMustNot");
-
+        .getParamValue("gMustNot");
     this.setUserSpecificFilter(searchCriteria, solrQuery,
-      LogSearchConstants.INCLUDE_QUERY,
-      LogSearchConstants.INCLUDE_QUERY);
-
+        LogSearchConstants.INCLUDE_QUERY, LogSearchConstants.INCLUDE_QUERY,
+        logType);
     this.setUserSpecificFilter(searchCriteria, solrQuery,
-      LogSearchConstants.EXCLUDE_QUERY,
-      LogSearchConstants.EXCLUDE_QUERY);
-
+        LogSearchConstants.EXCLUDE_QUERY, LogSearchConstants.EXCLUDE_QUERY,
+        logType);
     String unselectedComp = (String) searchCriteria
-      .getParamValue("unselectComp");
-
+        .getParamValue("unselectComp");
     this.setFilterClauseWithFieldName(solrQuery, globalExcludeComp,
-      LogSearchConstants.AUDIT_COMPONENT,
-      LogSearchConstants.MINUS_OPERATOR, "AND");
-
+        LogSearchConstants.AUDIT_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
+        CONDITION.AND);
     // Building and adding exlcude components to filters
     this.setFilterClauseWithFieldName(solrQuery, unselectedComp,
-      LogSearchConstants.AUDIT_COMPONENT,
-      LogSearchConstants.MINUS_OPERATOR, "AND");
-
+        LogSearchConstants.AUDIT_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
+        CONDITION.AND);
     // Adding Logtime to filters
     this.setSingleRangeFilter(solrQuery, LogSearchConstants.AUDIT_EVTTIME,
-      startTime, endTime);
-
+        startTime, endTime);
     this.setPagination(solrQuery, searchCriteria);
     try {
-      if (searchCriteria.getSortBy().isEmpty()) {
+      if (searchCriteria.getSortBy() == null
+          || searchCriteria.getSortBy().isEmpty()) {
         searchCriteria.setSortBy(LogSearchConstants.AUDIT_EVTTIME);
         searchCriteria.setSortType(SolrQuery.ORDER.desc.toString());
       }
@@ -339,52 +332,40 @@ public class QueryGeneration extends QueryGenerationBase {
       searchCriteria.setSortBy(LogSearchConstants.AUDIT_EVTTIME);
       searchCriteria.setSortType(SolrQuery.ORDER.desc.toString());
     }
-
     this.setSortOrderDefaultServiceLog(solrQuery, searchCriteria);
     return solrQuery;
   }
 
-  private String putWildCardByType(String str, String key) {
-
-    String auditSuffix = PropertiesUtil
-      .getProperty("auditlog.solr.core.logs");
-    String serviceLogs = PropertiesUtil.getProperty("solr.core.logs");
-
-    String type = ConfigUtil.schemaFieldsName.get(key + auditSuffix);
-    if (type == null)
+  private String putWildCardByType(String str, String key, LOG_TYPE logType) {
+    String type;
+    switch (logType) {
+    case AUDIT:
+      String auditSuffix = PropertiesUtil
+          .getProperty("auditlog.solr.core.logs");
+      type = ConfigUtil.schemaFieldsName.get(key + auditSuffix);
+      break;
+    case SERVICE:
+      String serviceLogs = PropertiesUtil.getProperty("solr.core.logs");
       type = ConfigUtil.schemaFieldsName.get(key + serviceLogs);
-    if (type == null)
-      return "*" + str + "*";
-    if ("text_std_token_lower_case".equalsIgnoreCase(type))
-      return giveSplittedStringQuery(str);
-    if ("key_lower_case".equalsIgnoreCase(type)
-      || "string".equalsIgnoreCase(type))
-      //return solrUtil.makeSolrSearchString(str);
-      return solrUtil.makeSolrSearchStringWithoutAsterisk(str);
-    if ("ip_address".equalsIgnoreCase(type))
-      return str;
-    return putEscapeCharacterForNumber(str);
-  }
-
-  private String giveSplittedStringQuery(String str) {
-    try {
-      String splittedString[] = str
-        .split("/|-|@|&|^|%|$|#|!|~|:|;|\\*|\\+");
-      String newStr = "(";
-      int cnt = 0;
-      for (String normalString : splittedString) {
-        cnt++;
-        if (!normalString.isEmpty()) {
-          newStr += "*" + normalString + "*";
-        }
-        if (!normalString.isEmpty() && cnt < splittedString.length)
-          newStr += " AND ";
-      }
-      newStr += ")";
-      return newStr;
-    } catch (Exception e) {
-      return "*" + str + "*";
+      break;
+    default:
+      // set as null
+      type = null;
+    }
+    if (key.equalsIgnoreCase(LogSearchConstants.SOLR_LOG_MESSAGE)) {
+      return solrUtil.escapeForLogMessage(key, str);
     }
+    if (type == null) {
+      return key + ":" + "*" + str + "*";
+    } else if ("text_std_token_lower_case".equalsIgnoreCase(type)) {
+      return key + ":" + solrUtil.escapeForStandardTokenizer(str);
+    } else if ("key_lower_case".equalsIgnoreCase(type)
+        || "string".equalsIgnoreCase(type)) {
+      return key + ":" + solrUtil.makeSolrSearchStringWithoutAsterisk(str);
+    } else if ("ip_address".equalsIgnoreCase(type)) {
+      return key + ":" + str;
+    }
+    return key + ":" + putEscapeCharacterForNumber(str);
   }
 
   private String putEscapeCharacterForNumber(String str) {
@@ -403,40 +384,56 @@ public class QueryGeneration extends QueryGenerationBase {
 
   private String getOriginalValue(String name, String value) {
     String solrValue = PropertiesUtil.getProperty(name);
-
+    if (stringUtil.isEmpty(solrValue)) {
+      return value;
+    }
     try {
-      String propertyFieldMappings[] = solrValue.split(",");
-      HashMap<String, String> propertyFieldValue = new HashMap<String, String>();
-      for (String temp : propertyFieldMappings) {
-        String arrayValue[] = temp.split(":");
-        propertyFieldValue.put(arrayValue[0].toLowerCase(Locale.ENGLISH),
-          arrayValue[1].toLowerCase(Locale.ENGLISH));
+      String propertyFieldMappings[] = solrValue
+          .split(LogSearchConstants.LIST_SEPARATOR);
+      if (propertyFieldMappings != null && propertyFieldMappings.length > 0) {
+        HashMap<String, String> propertyFieldValue = new HashMap<String, String>();
+        for (String temp : propertyFieldMappings) {
+          if (!stringUtil.isEmpty(temp)) {
+            String arrayValue[] = temp.split(":");
+            if (arrayValue.length > 1) {
+              propertyFieldValue.put(arrayValue[0].toLowerCase(Locale.ENGLISH),
+                  arrayValue[1].toLowerCase(Locale.ENGLISH));
+            } else {
+              logger.warn("array length is less than required length 1");
+            }
+          }
+        }
+        String originalValue = propertyFieldValue.get(value
+            .toLowerCase(Locale.ENGLISH));
+        if (!stringUtil.isEmpty(originalValue)) {
+          return originalValue;
+        }
       }
-      String originalValue = propertyFieldValue.get(value.toLowerCase(Locale.ENGLISH));
-      if (originalValue != null && !originalValue.isEmpty())
-        return originalValue;
-
     } catch (Exception e) {
       // do nothing
     }
     return value;
-
   }
 
-  private String getOriginalKey(String key) {
-    String originalServiceKey = ConfigUtil.serviceLogsColumnMapping.get(key
-      + LogSearchConstants.UI_SUFFIX);
-    String originalAuditKey = ConfigUtil.auditLogsColumnMapping.get(key
-      + LogSearchConstants.UI_SUFFIX);
-    if (originalAuditKey != null && originalServiceKey == null) {
-      return originalAuditKey;
-    }
-    if (originalServiceKey != null && originalAuditKey == null) {
-      return originalServiceKey;
+  private String getOriginalKey(String key, LOG_TYPE logType) {
+    String originalKey;
+    switch (logType) {
+    case AUDIT:
+      originalKey = ConfigUtil.auditLogsColumnMapping.get(key
+          + LogSearchConstants.UI_SUFFIX);
+      break;
+    case SERVICE:
+      originalKey = ConfigUtil.serviceLogsColumnMapping.get(key
+          + LogSearchConstants.UI_SUFFIX);
+      break;
+    default:
+      originalKey = null;
+      // set as null
     }
-    if (originalAuditKey != null && originalServiceKey != null) {
-      return originalServiceKey;
+    if (stringUtil.isEmpty(originalKey)) {
+      // return default values
+      return key;
     }
-    return key;
+    return originalKey;
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java
index e357d02..cc61127 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java
@@ -31,11 +31,10 @@ import org.apache.ambari.logsearch.util.StringUtil;
 import org.apache.log4j.Logger;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrQuery.ORDER;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import com.google.gson.Gson;
+
 public abstract class QueryGenerationBase extends QueryBase {
 
   static Logger logger = Logger.getLogger(QueryGenerationBase.class);
@@ -49,76 +48,92 @@ public abstract class QueryGenerationBase extends QueryBase {
   @Autowired
   JSONUtil jsonUtil;
 
+  public static enum CONDITION {
+    OR, AND
+  }
+
   // SetMethods to apply to the query
   public void setFilterClauseForSolrSearchableString(SolrQuery solrQuery,
-                                                     String commaSepratedString, String booleanOperator, String opr,
-                                                     String messageField) {
-    String operator = opr;
+      String commaSepratedString, CONDITION condition, String operator,
+      String messageField) {
     String filterQuery = "";
-    if (commaSepratedString != null && !commaSepratedString.isEmpty()) {
-
-      String queryMsg = "";
-      operator = operator == null ? "" : operator;
+    if (!stringUtil.isEmpty(commaSepratedString)) {
+      StringBuilder queryMsg = new StringBuilder();
+      operator = (operator == null ? LogSearchConstants.NO_OPERATOR : operator);
       String[] msgList = commaSepratedString
-        .split(LogSearchConstants.I_E_SEPRATOR);
+          .split(LogSearchConstants.I_E_SEPRATOR);
       int count = 0;
       for (String temp : msgList) {
         count += 1;
-
-        queryMsg = queryMsg + " " + operator + messageField + ":"
-          + solrUtil.makeSolrSearchString(temp);
-        if (msgList.length > count)
-          queryMsg = queryMsg + " " + booleanOperator + " ";
+        if (LogSearchConstants.SOLR_LOG_MESSAGE.equalsIgnoreCase(messageField)) {
+          queryMsg.append(" " + operator
+              + solrUtil.escapeForLogMessage(messageField, temp));
+        } else {
+          temp = solrUtil.escapeForStandardTokenizer(temp);
+          if(temp.startsWith("\"") && temp.endsWith("\"")){
+            temp = temp.substring(1);
+            temp = temp.substring(0, temp.length()-1);
+          }
+          temp = "*" + temp + "*";
+          queryMsg.append(" " + operator + messageField + ":"
+              + temp);
+        }
+        if (msgList.length > count){
+          queryMsg.append(" " + condition.name() + " ");
+        }
       }
-      filterQuery = queryMsg;
+      filterQuery = queryMsg.toString();
       solrQuery.addFilterQuery(filterQuery);
       logger.debug("Filter added :- " + filterQuery);
     }
   }
 
   public void setFilterClauseWithFieldName(SolrQuery solrQuery,
-                                           String commaSepratedString, String field, String operator,
-                                           String condition) {
-    if (commaSepratedString != null && !commaSepratedString.isEmpty()) {
-      String[] arrayOfSepratedString = commaSepratedString.split(",");
-      String filterQuery;
-      if ("OR".equals(condition))
-        filterQuery = solrUtil.orList(operator + field,
-          arrayOfSepratedString, "");
-      else
-        filterQuery = solrUtil.andList(operator + field,
-          arrayOfSepratedString, "");
-      solrQuery.addFilterQuery(filterQuery);
-      logger.debug("Filter added :- " + filterQuery);
+      String commaSepratedString, String field, String operator,
+      CONDITION condition) {
+    if (!stringUtil.isEmpty(commaSepratedString)) {
+      String[] arrayOfSepratedString = commaSepratedString.split(LogSearchConstants.LIST_SEPARATOR);
+      String filterQuery = null;
+      if (CONDITION.OR.equals(condition)) {
+        filterQuery = solrUtil.orList(operator + field, arrayOfSepratedString,"");
+      } else if (CONDITION.AND.equals(condition)) {
+        filterQuery = solrUtil.andList(operator + field, arrayOfSepratedString,"");
+      }else{
+        logger.warn("Not a valid condition :" + condition.name());
+      }
+      //add
+      if(!stringUtil.isEmpty(filterQuery)){
+        solrQuery.addFilterQuery(filterQuery);
+        logger.debug("Filter added :- " + filterQuery);
+      }
+
     }
   }
 
   public void setSortOrderDefaultServiceLog(SolrQuery solrQuery,
-                                            SearchCriteria searchCriteria) {
+      SearchCriteria searchCriteria) {
     List<SolrQuery.SortClause> defaultSort = new ArrayList<SolrQuery.SortClause>();
     if (searchCriteria.getSortBy() != null
-      && (!searchCriteria.getSortBy().isEmpty())) {
+        && (!searchCriteria.getSortBy().isEmpty())) {
       ORDER order = SolrQuery.ORDER.asc;
       if (searchCriteria.getSortType() != null
-        && (!searchCriteria.getSortType().isEmpty())
-        && !searchCriteria.getSortType().equalsIgnoreCase(
-        order.toString())) {
+          && (!searchCriteria.getSortType().isEmpty())
+          && !searchCriteria.getSortType().equalsIgnoreCase(order.toString())) {
         order = SolrQuery.ORDER.desc;
       }
-      SolrQuery.SortClause logtimeSortClause = SolrQuery.SortClause
-        .create(searchCriteria.getSortBy(), order);
+      SolrQuery.SortClause logtimeSortClause = SolrQuery.SortClause.create(
+          searchCriteria.getSortBy(), order);
       defaultSort.add(logtimeSortClause);
     } else {
       // by default sorting by logtime and sequence number in
       // Descending order
-      SolrQuery.SortClause logtimeSortClause = SolrQuery.SortClause
-        .create(LogSearchConstants.LOGTIME, SolrQuery.ORDER.desc);
-
+      SolrQuery.SortClause logtimeSortClause = SolrQuery.SortClause.create(
+          LogSearchConstants.LOGTIME, SolrQuery.ORDER.desc);
       defaultSort.add(logtimeSortClause);
 
     }
     SolrQuery.SortClause sequenceNumberSortClause = SolrQuery.SortClause
-      .create(LogSearchConstants.SEQUNCE_ID, SolrQuery.ORDER.desc);
+        .create(LogSearchConstants.SEQUNCE_ID, SolrQuery.ORDER.desc);
     defaultSort.add(sequenceNumberSortClause);
     solrQuery.setSorts(defaultSort);
     logger.debug("Sort Order :-" + defaultSort);
@@ -157,20 +172,28 @@ public abstract class QueryGenerationBase extends QueryBase {
   // Example of list can be [logtime desc,seq_num desc]
   @SuppressWarnings("unchecked")
   public void setMultipleSortOrder(SolrQuery solrQuery,
-                                   SearchCriteria searchCriteria) {
+      SearchCriteria searchCriteria) {
     List<SolrQuery.SortClause> sort = new ArrayList<SolrQuery.SortClause>();
-    List<String> sortList = (List<String>) searchCriteria
-      .getParamValue("sort");
-    for (String sortOrder : sortList) {
-      String sortByAndOrder[] = sortOrder.split(" ");
-      ORDER order = sortByAndOrder[1].contains("asc") ? SolrQuery.ORDER.asc
-        : SolrQuery.ORDER.desc;
-      SolrQuery.SortClause sortOrder2 = SolrQuery.SortClause.create(
-        sortByAndOrder[0], order);
-      sort.add(sortOrder2);
-      logger.debug("Sort Order :-" + sort);
+    List<String> sortList = (List<String>) searchCriteria.getParamValue("sort");
+    if (sortList != null) {
+      for (String sortOrder : sortList) {
+        if (!stringUtil.isEmpty(sortOrder)) {
+          String sortByAndOrder[] = sortOrder.split(" ");
+          if (sortByAndOrder.length > 1) {
+            ORDER order = sortByAndOrder[1].contains("asc") ? SolrQuery.ORDER.asc
+                : SolrQuery.ORDER.desc;
+            SolrQuery.SortClause solrSortClause = SolrQuery.SortClause.create(
+                sortByAndOrder[0], order);
+            sort.add(solrSortClause);
+            logger.debug("Sort Order :-" + sort);
+          } else {
+            // log warn
+            logger.warn("Not a valid sort Clause " + sortOrder);
+          }
+        }
+      }
+      solrQuery.setSorts(sort);
     }
-    solrQuery.setSorts(sort);
   }
 
   public void setSingleIncludeFilter(SolrQuery solrQuery, String filterType,
@@ -184,25 +207,26 @@ public abstract class QueryGenerationBase extends QueryBase {
   }
 
   public void setSingleExcludeFilter(SolrQuery solrQuery, String filterType,
-                                     String filterValue) {
-    if (filterType != null && !filterType.isEmpty() && filterValue != null
-      && !filterValue.isEmpty()) {
-      String filterQuery = "-"
-        + buildFilterQuery(filterType, filterValue);
+      String filterValue) {
+    if (!stringUtil.isEmpty(filterValue) && !stringUtil.isEmpty(filterType)) {
+      String filterQuery = LogSearchConstants.MINUS_OPERATOR
+          + buildFilterQuery(filterType, filterValue);
       solrQuery.addFilterQuery(filterQuery);
       logger.debug("Filter added :- " + filterQuery);
     }
   }
 
   public void setSingleRangeFilter(SolrQuery solrQuery, String filterType,
-                                   String filterFromValue, String filterToValue) {
-    if (filterType != null && !filterType.isEmpty()
-      && filterFromValue != null && !filterFromValue.isEmpty()
-      && filterToValue != null && !filterToValue.isEmpty()) {
+      String filterFromValue, String filterToValue) {
+    if (!stringUtil.isEmpty(filterToValue)
+        && !stringUtil.isEmpty(filterType)
+        && !stringUtil.isEmpty(filterFromValue)) {
       String filterQuery = buildInclusiveRangeFilterQuery(filterType,
-        filterFromValue, filterToValue);
-      solrQuery.addFilterQuery(filterQuery);
-      logger.debug("Filter added :- " + filterQuery);
+          filterFromValue, filterToValue);
+      if (!stringUtil.isEmpty(filterQuery)) {
+        solrQuery.addFilterQuery(filterQuery);
+        logger.debug("Filter added :- " + filterQuery);
+      }
     }
   }
 
@@ -227,8 +251,10 @@ public abstract class QueryGenerationBase extends QueryBase {
         + " to " + maxRows.intValue());
   }
 
-  public void setSingleORFilter(SolrQuery solrQuery, String filterName1, String value1, String filterName2, String value2) {
-    String filterQuery = filterName1 + ":" + value1 + " OR " + filterName2 + ":" + value2;
+  public void setSingleORFilter(SolrQuery solrQuery, String filterName1,
+      String value1, String filterName2, String value2) {
+    String filterQuery = filterName1 + ":" + value1 + " " + CONDITION.OR.name()
+        + " " + filterName2 + ":" + value2;
     solrQuery.setFilterQueries(filterQuery);
   }
 
@@ -255,68 +281,66 @@ public abstract class QueryGenerationBase extends QueryBase {
     return filterQuery;
   }
 
-  public String buildQueryFromJSONCompHost(String jsonHCNames,
-                                           String selectedComponent) {
-    String queryHostComponent = "";
-    // Building and adding exclude string to filters
-    String selectedCompQuery = "";
-
-    if (selectedComponent != null && !selectedComponent.equals("")) {
-      String[] selectedComponents = selectedComponent.split(",");
-      selectedCompQuery = solrUtil.orList(LogSearchConstants.SOLR_COMPONENT, selectedComponents);
-
-    }
-
-    // Building Query of Host and Components from given json
-    if (jsonHCNames != null && !jsonHCNames.equals("")
-      && !jsonHCNames.equals("[]")) {
-
-      try {
-        JSONArray jarray = new JSONArray(jsonHCNames);
-        int flagHost = 0;
-        int flagComp;
-        int count;
-        for (int i = 0; i < jarray.length(); i++) {
-          if (flagHost == 1)
-            queryHostComponent = queryHostComponent + " OR ";
-          JSONObject jsonObject = jarray.getJSONObject(i);
-          String host = jsonObject.getString("h");
-          queryHostComponent = queryHostComponent + "( host:" + host;
-          List<String> components = JSONUtil.JSONToList(jsonObject
-            .getJSONArray("c"));
-          if (components.isEmpty())
-            queryHostComponent = queryHostComponent + " AND ";
-
-          flagComp = 0;
-          count = 0;
-          for (String comp : components) {
-            if (flagComp == 0)
-              queryHostComponent = queryHostComponent + " ( ";
-            count += 1;
-            queryHostComponent = queryHostComponent + " "
-              + " type:" + comp;
-            if (components.size() <= count)
-              queryHostComponent = queryHostComponent + " ) ";
-            else
-              queryHostComponent = queryHostComponent + " OR ";
-            flagComp = 1;
-          }
-          queryHostComponent = queryHostComponent + " ) ";
-          flagHost = 1;
-        }
-      } catch (JSONException e) {
-        logger.error(e);
-      }
-    }
-    if (selectedCompQuery != null && !selectedCompQuery.equals("")) {
-      if (queryHostComponent == null || queryHostComponent.equals(""))
-        queryHostComponent = selectedCompQuery;
-      else
-        queryHostComponent = queryHostComponent + " OR "
-          + selectedCompQuery;
-    }
-    return queryHostComponent;
-  }
+//  public String buildQueryFromJSONCompHost(String jsonHCNames,
+//      String selectedComponent) {
+//    String queryHostComponent = "";
+//    // Building and adding exclude string to filters
+//    String selectedCompQuery = "";
+//    if (!stringUtil.isEmpty(selectedComponent)) {
+//      String[] selectedComponents = selectedComponent
+//          .split(LogSearchConstants.LIST_SEPARATOR);
+//      selectedCompQuery = solrUtil.orList(LogSearchConstants.SOLR_COMPONENT,
+//          selectedComponents);
+//    }
+//
+//    // Building Query of Host and Components from given json
+//    if (jsonHCNames != null && !jsonHCNames.equals("")
+//        && !jsonHCNames.equals("[]")) {
+//
+//      try {
+//        JSONArray jarray = new JSONArray(jsonHCNames);
+//        int flagHost = 0;
+//        int flagComp;
+//        int count;
+//        for (int i = 0; i < jarray.length(); i++) {
+//          if (flagHost == 1)
+//            queryHostComponent = queryHostComponent + " OR ";
+//          JSONObject jsonObject = jarray.getJSONObject(i);
+//          String host = jsonObject.getString("h");
+//          queryHostComponent = queryHostComponent + "( host:" + host;
+//          List<String> components = JSONUtil.JSONToList(jsonObject
+//              .getJSONArray("c"));
+//          if (!components.isEmpty())
+//            queryHostComponent = queryHostComponent + " AND ";
+//
+//          flagComp = 0;
+//          count = 0;
+//          for (String comp : components) {
+//            if (flagComp == 0)
+//              queryHostComponent = queryHostComponent + " ( ";
+//            count += 1;
+//            queryHostComponent = queryHostComponent + " " + " type:" + comp;
+//            if (components.size() <= count)
+//              queryHostComponent = queryHostComponent + " ) ";
+//            else
+//              queryHostComponent = queryHostComponent + " OR ";
+//            flagComp = 1;
+//          }
+//          queryHostComponent = queryHostComponent + " ) ";
+//          flagHost = 1;
+//        }
+//      } catch (JSONException e) {
+//        logger.error(e);
+//      }
+//    }
+//    if (selectedCompQuery != null && !selectedCompQuery.equals("")) {
+//      if (queryHostComponent == null || queryHostComponent.equals(""))
+//        queryHostComponent = selectedCompQuery;
+//      else
+//        queryHostComponent = queryHostComponent + " OR " + selectedCompQuery;
+//    }
+//    return queryHostComponent;
+//  }
 
   // JSON BuildMethods
 
@@ -386,4 +410,60 @@ public abstract class QueryGenerationBase extends QueryBase {
     logger.info("Build JSONQuery is :- " + jsonQuery);
     return jsonQuery;
   }
+
+  public String buildListQuery(String paramValue, String solrFieldName,
+      CONDITION condition) {
+    if (!stringUtil.isEmpty(paramValue)) {
+      String[] values = paramValue.split(LogSearchConstants.LIST_SEPARATOR);
+      switch (condition) {
+      case OR:
+        return solrUtil.orList(solrFieldName, values,"*");
+      case AND:
+        return solrUtil.andList(solrFieldName, values, "");
+      default:
+        logger.error("Invalid condition " + condition.name());
+      }
+    }
+    return "";
+  }
+
+
+  public void addFilterQueryFromArray(SolrQuery solrQuery, String jsonArrStr,
+      String solrFieldName, CONDITION condition) {
+    if (!stringUtil.isEmpty(jsonArrStr) && condition != null && solrQuery!=null) {
+      Gson gson = new Gson();
+      String[] arr = null;
+      try {
+        arr = gson.fromJson(jsonArrStr, String[].class);
+      } catch (Exception exception) {
+        logger.error("Invaild json array:" + jsonArrStr);
+        return;
+      }
+      String query;;
+      switch (condition) {
+      case OR:
+        query = solrUtil.orList(solrFieldName, arr,"");
+        break;
+      case AND:
+        query = solrUtil.andList(solrFieldName, arr, "");
+        break;
+      default:
+        query=null;
+        logger.error("Invalid condition :" + condition.name());
+      }
+      if (!stringUtil.isEmpty(query)) {
+        solrQuery.addFilterQuery(query);
+      }
+    }
+  }
+
+  public void addFilter(SolrQuery solrQuery, String paramValue,
+      String solrFieldName, CONDITION condition) {
+    String filterQuery = buildListQuery(paramValue, solrFieldName, condition);
+    if (!stringUtil.isEmpty(filterQuery)) {
+      if (solrQuery != null) {
+        solrQuery.addFilterQuery(filterQuery);
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditREST.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditREST.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditREST.java
index 6e47d34..92bfb01 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditREST.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditREST.java
@@ -28,8 +28,6 @@ import javax.ws.rs.core.Response;
 
 import org.apache.ambari.logsearch.common.SearchCriteria;
 import org.apache.ambari.logsearch.manager.AuditMgr;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/DashboardREST.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/DashboardREST.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/DashboardREST.java
index 5f56ccb..1e107ed 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/DashboardREST.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/DashboardREST.java
@@ -114,7 +114,7 @@ public class DashboardREST {
     searchCriteria
       .addParam("startDate", request.getParameter("start_time"));
     searchCriteria.addParam("endDate", request.getParameter("end_time"));
-    return logMgr.getComponenetsCount(searchCriteria);
+    return logMgr.getComponentsCount(searchCriteria);
   }
 
   @GET
@@ -188,7 +188,6 @@ public class DashboardREST {
     searchCriteria.addParam("hostLogFile", request.getParameter("host"));
     searchCriteria.addParam("compLogFile",
       request.getParameter("component"));
-    searchCriteria.addParam("unit", request.getParameter("unit"));
     searchCriteria.addParam("format", request.getParameter("format"));
     searchCriteria.addParam("utcOffset", request.getParameter("utcOffset"));
     return logMgr.exportToTextFile(searchCriteria);
@@ -250,14 +249,6 @@ public class DashboardREST {
   }
 
   @GET
-  @Path("/getCurrentPageOfKeywordSearch")
-  @Produces({"application/json"})
-  public String getCurrentPageOfKeywordSearch(@Context HttpServletRequest request) {
-    String requestDate = (String) request.getParameter("requestDate");
-    return logMgr.getCurrentPageOfKeywordSearch(requestDate);
-  }
-
-  @GET
   @Path("/getAnyGraphData")
   @Produces({"application/json"})
   public String getAnyGraphData(@Context HttpServletRequest request) {
@@ -290,17 +281,6 @@ public class DashboardREST {
   }
 
   @GET
-  @Path("/getSuggestoins")
-  @Produces({"application/json"})
-  public String getSuggestions(@Context HttpServletRequest request) {
-    SearchCriteria searchCriteria = new SearchCriteria();
-    searchCriteria.addParam("fieldName", request.getParameter("fieldName"));
-    searchCriteria.addParam("valueToSuggest",
-      request.getParameter("valueToSuggest"));
-    return logMgr.getSuggestions(searchCriteria);
-  }
-
-  @GET
   @Path("/getHadoopServiceConfigJSON")
   @Produces({"application/json"})
   public String getHadoopServiceConfigJSON() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/888faf26/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/UserConfigREST.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/UserConfigREST.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/UserConfigREST.java
index c459ab7..40b215c 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/UserConfigREST.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/UserConfigREST.java
@@ -33,8 +33,6 @@ import org.apache.ambari.logsearch.common.LogSearchConstants;
 import org.apache.ambari.logsearch.common.SearchCriteria;
 import org.apache.ambari.logsearch.manager.UserConfigMgr;
 import org.apache.ambari.logsearch.util.RESTErrorUtil;
-import org.apache.ambari.logsearch.view.VLogfeederFilter;
-import org.apache.ambari.logsearch.view.VLogfeederFilterWrapper;
 import org.apache.ambari.logsearch.view.VUserConfig;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;