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/09/13 10:41:29 UTC
[12/51] [abbrv] ambari git commit: AMBARI-18227. Add unit tests for
Log Search components and refactor them as needed - Vol 1. (Miklos Gergely
via oleewere)
http://git-wip-us.apache.org/repos/asf/ambari/blob/dfa9bd38/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 e612475..a0c1134 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 java.io.File;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -40,46 +41,40 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import com.google.gson.JsonParseException;
-import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
+import org.apache.ambari.logsearch.manager.MgrBase.LogType;
import org.apache.ambari.logsearch.util.PropertiesUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
@Component
public class UserConfigSolrDao extends SolrDaoBase {
- static private Logger logger = Logger.getLogger(UserConfigSolrDao.class);
+ private static final Logger logger = Logger.getLogger(UserConfigSolrDao.class);
private static final String DEFAULT_LEVELS = "FATAL,ERROR,WARN,INFO,DEBUG,TRACE";
public UserConfigSolrDao() {
- super(LOG_TYPE.SERVICE);
+ super(LogType.SERVICE);
}
@PostConstruct
public void postConstructor() {
-
String solrUrl = PropertiesUtil.getProperty("logsearch.solr.url");
String zkConnectString = PropertiesUtil.getProperty("logsearch.solr.zk_connect_string");
- String collection = PropertiesUtil.getProperty("logsearch.solr.collection.history",
- "history");
- String configName = PropertiesUtil.getProperty(
- "logsearch.solr.history.config.name", "history");
- int replicationFactor = PropertiesUtil.getIntProperty(
- "logsearch.collection.history.replication.factor", 2);
+ String collection = PropertiesUtil.getProperty("logsearch.solr.collection.history", "history");
+ String configName = PropertiesUtil.getProperty("logsearch.solr.history.config.name", "history");
+ int replicationFactor = PropertiesUtil.getIntProperty("logsearch.collection.history.replication.factor", 2);
String splitInterval = "none";
int numberOfShards = 1;
try {
connectToSolr(solrUrl, zkConnectString, collection);
- setupCollections(splitInterval, configName, numberOfShards,
- replicationFactor,true);
+ setupCollections(splitInterval, configName, numberOfShards, replicationFactor, true);
intializeLogFeederFilter();
} catch (Exception e) {
- logger.error(
- "error while connecting to Solr for history logs : solrUrl="
- + solrUrl + ", zkConnectString=" + zkConnectString
- + ", collection=" + collection, e);
+ logger.error("error while connecting to Solr for history logs : solrUrl=" + solrUrl + ", zkConnectString=" + zkConnectString +
+ ", collection=" + collection, e);
}
}
@@ -91,8 +86,7 @@ public class UserConfigSolrDao extends SolrDaoBase {
}
}
- public void saveUserFiter(VLogfeederFilterWrapper logfeederFilterWrapper) throws SolrException,
- SolrServerException, IOException {
+ public void saveUserFilter(VLogfeederFilterWrapper logfeederFilterWrapper) throws SolrException, SolrServerException, IOException {
String filterName = LogSearchConstants.LOGFEEDER_FILTER_NAME;
String json = jsonUtil.objToJson(logfeederFilterWrapper);
SolrInputDocument configDocument = new SolrInputDocument();
@@ -104,47 +98,32 @@ public class UserConfigSolrDao extends SolrDaoBase {
addDocs(configDocument);
}
- public void deleteUserConfig(String id) throws SolrException,
- SolrServerException, IOException {
+ public void deleteUserConfig(String id) throws SolrException, SolrServerException, IOException {
removeDoc("id:" + id);
}
@SuppressWarnings("unchecked")
- public VLogfeederFilterWrapper getUserFilter() throws SolrServerException,
- IOException {
+ public VLogfeederFilterWrapper getUserFilter() throws SolrServerException, IOException {
- String filterName = LogSearchConstants.LOGFEEDER_FILTER_NAME;
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("*:*");
- String fq = LogSearchConstants.ROW_TYPE + ":" + filterName;
+ String fq = LogSearchConstants.ROW_TYPE + ":" + LogSearchConstants.LOGFEEDER_FILTER_NAME;
solrQuery.setFilterQueries(fq);
QueryResponse response = process(solrQuery);
SolrDocumentList documentList = response.getResults();
VLogfeederFilterWrapper logfeederFilterWrapper = null;
- if (documentList != null && documentList.size() > 0) {
+ if (!CollectionUtils.isEmpty(documentList)) {
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(
- "logsearch.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);
- }
+ String logfeederDefaultLevels = PropertiesUtil.getProperty("logsearch.logfeeder.include.default.level", DEFAULT_LEVELS);
+ JSONArray levelJsonArray = new JSONArray(Arrays.asList(logfeederDefaultLevels.split(",")));
String hadoopServiceString = getHadoopServiceConfigJSON();
String key = null;
@@ -153,13 +132,11 @@ public class UserConfigSolrDao extends SolrDaoBase {
JSONObject componentList = new JSONObject();
JSONObject jsonValue = new JSONObject();
- JSONObject hadoopServiceJsonObject = new JSONObject(hadoopServiceString)
- .getJSONObject("service");
+ JSONObject hadoopServiceJsonObject = new JSONObject(hadoopServiceString).getJSONObject("service");
Iterator<String> hadoopSerivceKeys = hadoopServiceJsonObject.keys();
while (hadoopSerivceKeys.hasNext()) {
key = hadoopSerivceKeys.next();
- componentArray = hadoopServiceJsonObject.getJSONObject(key)
- .getJSONArray("components");
+ 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");
@@ -171,27 +148,24 @@ public class UserConfigSolrDao extends SolrDaoBase {
}
}
jsonValue.put("filter", componentList);
- logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil
- .jsonToObj(jsonValue.toString(), VLogfeederFilterWrapper.class);
+ logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil.jsonToObj(jsonValue.toString(), VLogfeederFilterWrapper.class);
logfeederFilterWrapper.setId(""+new Date().getTime());
- saveUserFiter(logfeederFilterWrapper);
+ saveUserFilter(logfeederFilterWrapper);
} catch (JsonParseException | JSONException je) {
- logger.error("Error parsing JSON. key=" + key + ", componentArray="
- + componentArray, je);
+ logger.error("Error parsing JSON. key=" + key + ", componentArray=" + componentArray, je);
logfeederFilterWrapper = new VLogfeederFilterWrapper();
}
}
return logfeederFilterWrapper;
}
- public String getHadoopServiceConfigJSON() {
+ private 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)) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/dfa9bd38/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserDao.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserDao.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserDao.java
index 6b2f049..b7853df 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserDao.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserDao.java
@@ -20,46 +20,43 @@ package org.apache.ambari.logsearch.dao;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
-import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Repository;
+
+import org.apache.ambari.logsearch.util.CommonUtil;
import org.apache.ambari.logsearch.util.FileUtil;
import org.apache.ambari.logsearch.util.JSONUtil;
import org.apache.ambari.logsearch.util.PropertiesUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
import org.apache.ambari.logsearch.web.model.Privilege;
import org.apache.ambari.logsearch.web.model.Role;
import org.apache.ambari.logsearch.web.model.User;
import org.apache.ambari.logsearch.web.security.LogsearchFileAuthenticationProvider;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@Repository
public class UserDao {
-
private static final Logger logger = Logger.getLogger(UserDao.class);
- private static final Md5PasswordEncoder md5Encoder = new Md5PasswordEncoder();
- @Autowired
- JSONUtil jsonUtil;
+ private static final String USER_NAME = "username";
+ private static final String PASSWORD = "password";
+ private static final String ENC_PASSWORD = "en_password";
+ private static final String NAME = "name";
@Autowired
- StringUtil stringUtil;
-
+ private JSONUtil jsonUtil;
@Autowired
- FileUtil fileUtil;
-
+ private FileUtil fileUtil;
@Autowired
- LogsearchFileAuthenticationProvider fileAuthenticationProvider;
-
- private HashMap<String, Object> userInfos = null;
+ private LogsearchFileAuthenticationProvider fileAuthenticationProvider;
private ArrayList<HashMap<String, String>> userList = null;
@@ -68,23 +65,17 @@ public class UserDao {
public void initialization() {
if (fileAuthenticationProvider.isEnable()) {
try {
- String USER_PASS_JSON_FILE_NAME = PropertiesUtil
- .getProperty("logsearch.login.credentials.file");
- logger.info("USER PASS JSON file NAME:" + USER_PASS_JSON_FILE_NAME);
- File jsonFile = fileUtil
- .getFileFromClasspath(USER_PASS_JSON_FILE_NAME);
+ String userPassJsonFileName = PropertiesUtil.getProperty("logsearch.login.credentials.file");
+ logger.info("USER PASS JSON file NAME:" + userPassJsonFileName);
+ File jsonFile = fileUtil.getFileFromClasspath(userPassJsonFileName);
if (jsonFile == null || !jsonFile.exists()) {
- logger.fatal("user_pass json file not found in classpath :"
- + USER_PASS_JSON_FILE_NAME);
+ logger.fatal("user_pass json file not found in classpath :" + userPassJsonFileName);
System.exit(1);
}
- userInfos = jsonUtil.readJsonFromFile(jsonFile);
- userList = (ArrayList<HashMap<String, String>>) userInfos
- .get("users");
+ HashMap<String, Object> userInfos = jsonUtil.readJsonFromFile(jsonFile);
+ userList = (ArrayList<HashMap<String, String>>) userInfos.get("users");
if (userList != null) {
- // encrypting password using MD5 algo with salt username
boolean isUpdated = this.encryptAllPassword();
- // updating json
userInfos.put("users", userList);
if (isUpdated) {
String jsonStr = jsonUtil.mapToJSON(userInfos);
@@ -95,108 +86,78 @@ public class UserDao {
}
} catch (Exception exception) {
- logger.error("Error while reading user prop file :"
- + exception.getMessage());
- userInfos = new HashMap<String, Object>();
+ logger.error("Error while reading user prop file :" + exception.getMessage());
userList = new ArrayList<HashMap<String, String>>();
}
} else {
logger.info("File auth is disabled.");
}
-
}
- /**
- * @param username
- * @return
- */
public User loadUserByUsername(final String username) {
logger.debug(" loadUserByUsername username" + username);
- HashMap<String, Object> userInfo = this.findByusername(username);
+ HashMap<String, String> userInfo = findByusername(username);
User user = new User();
if (userInfo != null) {
- user.setFirstName(userInfo.get(UserInfoAttributes.NAME) != null ? (String) userInfo
- .get(UserInfoAttributes.NAME) : "Unknown");
- user.setLastName(userInfo.get(UserInfoAttributes.NAME) != null ? (String) userInfo
- .get(UserInfoAttributes.NAME) : "Unknown");
- user.setUsername(userInfo.get(UserInfoAttributes.USER_NAME) != null ? (String) userInfo
- .get(UserInfoAttributes.USER_NAME) : "");
- user.setPassword(userInfo.get(UserInfoAttributes.ENC_PASSWORD) != null ? (String) userInfo
- .get(UserInfoAttributes.ENC_PASSWORD) : "");
+ user.setFirstName(userInfo.get(NAME) != null ? userInfo.get(NAME) : "Unknown");
+ user.setLastName(userInfo.get(NAME) != null ? userInfo.get(NAME) : "Unknown");
+ user.setUsername(userInfo.get(USER_NAME) != null ? userInfo.get(USER_NAME) : "");
+ user.setPassword(userInfo.get(ENC_PASSWORD) != null ? userInfo.get(ENC_PASSWORD) : "");
}
Role r = new Role();
r.setName("ROLE_USER");
Privilege priv = new Privilege();
priv.setName("READ_PRIVILEGE");
- ArrayList<Privilege> plist = new ArrayList<Privilege>();
- plist.add(priv);
- r.setPrivileges(plist);
- List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
- roles.add(r);
- user.setAuthorities(roles);
+ r.setPrivileges(Arrays.asList(priv));
+ user.setAuthorities(Arrays.asList((GrantedAuthority)r));
+
return user;
}
- /**
- * @param username
- * @return
- */
- public HashMap<String, Object> findByusername(final String username) {
- if (this.userList == null) {
+ private HashMap<String, String> findByusername(final String username) {
+ if (userList == null) {
return null;
}
@SuppressWarnings("unchecked")
- HashMap<String, Object> userInfo = (HashMap<String, Object>) CollectionUtils
- .find(this.userList, new Predicate() {
- @Override
- public boolean evaluate(Object args) {
- HashMap<String, Object> tmpuserInfo = (HashMap<String, Object>) args;
- String objUsername = (String) tmpuserInfo
- .get(UserInfoAttributes.USER_NAME);
- if (objUsername != null && username != null) {
- return username.equalsIgnoreCase(objUsername);
+ HashMap<String, String> userInfo = (HashMap<String, String>) CollectionUtils.find(userList,
+ new Predicate() {
+ @Override
+ public boolean evaluate(Object args) {
+ HashMap<String, String> tmpUserInfo = (HashMap<String, String>) args;
+ String objUsername = tmpUserInfo.get(USER_NAME);
+ return (objUsername != null && username != null && username.equalsIgnoreCase(objUsername));
}
- return false;
- }
- });
+ });
+
return userInfo;
}
private boolean encryptAllPassword() {
boolean isUpdated = false;
for (HashMap<String, String> user : userList) {
- // user
- String encPassword = user.get(UserInfoAttributes.ENC_PASSWORD);
- String username = user.get(UserInfoAttributes.USER_NAME);
- String password = user.get(UserInfoAttributes.PASSWORD);
- if (!stringUtil.isEmpty(password)) {
- encPassword = encryptPassword(username, password);
- user.put(UserInfoAttributes.PASSWORD, "");
- user.put(UserInfoAttributes.ENC_PASSWORD, encPassword);
+ String encPassword = user.get(ENC_PASSWORD);
+ String username = user.get(USER_NAME);
+ String password = user.get(PASSWORD);
+ if (!StringUtils.isBlank(password)) {
+ encPassword = CommonUtil.encryptPassword(username, password);
+ user.put(PASSWORD, "");
+ user.put(ENC_PASSWORD, encPassword);
isUpdated = true;
}
- if (stringUtil.isEmpty(password) && stringUtil.isEmpty(encPassword)) {
- // log error
- logger.error("Password is empty or null for username : "
- + username);
+ if (StringUtils.isBlank(password) && StringUtils.isBlank(encPassword)) {
+ logger.error("Password is empty or null for username : " + username);
}
}
return isUpdated;
}
-
- /**
- * @param username
- * @param password
- * @return
- */
+
public String encryptPassword(String username, String password) {
- if (!stringUtil.isEmpty(username)) {
+ if (!StringUtils.isEmpty(username)) {
username = username.toLowerCase();
}
- String saltEncodedpasswd = md5Encoder
- .encodePassword(password, username);
+ String saltEncodedpasswd = CommonUtil.encryptPassword(password, username);
return saltEncodedpasswd;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/dfa9bd38/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserInfoAttributes.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserInfoAttributes.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserInfoAttributes.java
deleted file mode 100644
index 7bc3555..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserInfoAttributes.java
+++ /dev/null
@@ -1,28 +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.dao;
-
-public interface UserInfoAttributes {
-
- public static final String USER_NAME = "username";
- public static final String PASSWORD = "password";
- public static final String ENC_PASSWORD = "en_password";
- public static final String NAME = "name";
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/dfa9bd38/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
index d3975b3..3793f50 100644
--- 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
@@ -29,14 +29,12 @@ 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.SolrUtil;
-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.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -46,7 +44,6 @@ 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.apache.solr.schema.TextField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -55,32 +52,16 @@ import org.springframework.stereotype.Component;
@Component
public class GraphDataGenerator extends GraphDataGeneratorBase {
- @Autowired
- StringUtil stringUtil;
+ private static final Logger logger = Logger.getLogger(GraphDataGenerator.class);
@Autowired
- QueryGeneration queryGenerator;
-
+ private QueryGeneration queryGenerator;
@Autowired
- RESTErrorUtil restErrorUtil;
-
+ private RESTErrorUtil restErrorUtil;
@Autowired
- DateUtil dateUtil;
-
- @Autowired
- SolrUtil solrUtil;
-
- private static Logger logger = Logger.getLogger(GraphDataGenerator.class);
+ private SolrUtil solrUtil;
- /**
- *
- * @param searchCriteria
- * @param solrDaoBase
- * @param solrQuery
- * @return
- */
- public VBarDataList getAnyGraphData(SearchCriteria searchCriteria,
- SolrDaoBase solrDaoBase, SolrQuery solrQuery) {
+ public VBarDataList getAnyGraphData(SearchCriteria searchCriteria, SolrDaoBase solrDaoBase, SolrQuery solrQuery) {
// X axis credentials
String xAxisField = (String) searchCriteria.getParamValue("xAxis");
String stackField = (String) searchCriteria.getParamValue("stackBy");
@@ -88,7 +69,7 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
String to = (String) searchCriteria.getParamValue("to");
String unit = (String) searchCriteria.getParamValue("unit");
String typeXAxis = solrDaoBase.schemaFieldsNameMap.get(xAxisField);
- typeXAxis = (stringUtil.isEmpty(typeXAxis)) ? "string" : typeXAxis;
+ typeXAxis = (StringUtils.isBlank(typeXAxis)) ? "string" : typeXAxis;
// Y axis credentials
String yAxisField = (String) searchCriteria.getParamValue("yAxis");
@@ -96,17 +77,14 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
searchCriteria.addParam("type", typeXAxis);
String fieldTime = (String) searchCriteria.getParamValue("fieldTime");
// decide graph type based on user request parameter
- GRAPH_TYPE garphType = getGraphType(searchCriteria);
+ GraphType garphType = getGraphType(searchCriteria);
switch (garphType) {
case NORMAL_GRAPH:
- return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase,
- typeXAxis, fieldTime, solrQuery);
+ 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);
+ 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);
+ return nonRangeStackGraph(xAxisField, yAxisField, stackField, from, to, solrDaoBase, typeXAxis, fieldTime, solrQuery);
case RANGE_STACK_GRAPH:
return rangeStackGraph(xAxisField, stackField, from, to, unit, solrDaoBase, solrQuery);
default:
@@ -115,9 +93,9 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
}
}
- private GRAPH_TYPE getGraphType(SearchCriteria searchCriteria) {
+ private GraphType getGraphType(SearchCriteria searchCriteria) {
// default graph type is unknown
- GRAPH_TYPE graphType = GRAPH_TYPE.UNKNOWN;
+ GraphType graphType = GraphType.UNKNOWN;
// X axis credentials
String xAxisField = (String) searchCriteria.getParamValue("xAxis");
String stackField = (String) searchCriteria.getParamValue("stackBy");
@@ -127,46 +105,35 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
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)
+ if (StringUtils.isBlank(xAxisField) || StringUtils.isBlank(yAxisField)) {
+ graphType = GraphType.UNKNOWN;
+ } else if (StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(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)
+ graphType = GraphType.NORMAL_GRAPH;
+ } else if (StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(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)
+ graphType = GraphType.RANGE_NON_STACK_GRAPH;
+ } else if (!StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(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)
+ graphType = GraphType.NON_RANGE_STACK_GRAPH;
+ } else if (!StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(from)
&& (xType.contains("date") || xType.contains("time"))) {
- // Range Stack GraphType
- graphType = GRAPH_TYPE.RANGE_STACK_GRAPH;
+ graphType = GraphType.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) {
+ 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.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);
@@ -214,20 +181,17 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
return dataList;
} catch (SolrException | SolrServerException | IOException e) {
String query = solrQuery != null ? solrQuery.toQueryString() : "";
- logger.error("Got exception for solr query :" + query,
- e.getCause());
+ 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);
+ 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}")){
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
+ if (jsonFacetResponse.toString().equals("{count=0}")) {
return dataList;
}
VNameValue value = new VNameValue();
@@ -242,31 +206,26 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
return dataList;
} catch (SolrException | SolrServerException | IOException e) {
String query = solrQuery != null ? solrQuery.toQueryString() : "";
- logger.error("Got exception for solr query :" + query,
- e.getCause());
+ 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) {
+ 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);
+ String mainQuery = queryGenerator.buildInclusiveRangeFilterQuery(fieldTime, from, to);
queryGenerator.setMainQuery(solrQuery, mainQuery);
queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
String jsonQuery = "";
if (solrUtil.isSolrFieldNumber(typeXAxis,solrDaoBase)) {
String function = (yAxisField.contains("count")) ? "sum" : yAxisField;
- jsonQuery = queryGenerator.buidlJSONFacetRangeQueryForNumber(stackField,
- xAxisField, function);
+ jsonQuery = queryGenerator.buidlJSONFacetRangeQueryForNumber(stackField, xAxisField, function);
} else {
- jsonQuery = queryGenerator.buildJsonFacetTermsRangeQuery(stackField,
- xAxisField);
+ jsonQuery = queryGenerator.buildJsonFacetTermsRangeQuery(stackField, xAxisField);
}
try {
queryGenerator.setJSONFacet(solrQuery, jsonQuery);
@@ -279,16 +238,12 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
if (count <= 0) {
return dataList;
}
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
- .getResponse().get("facets");
- if (jsonFacetResponse == null
- || jsonFacetResponse.toString().equals("{count=0}")) {
+ 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)) {
+ extractNonRangeStackValuesFromBucket(jsonFacetResponse, stackField, vGraphData, typeXAxis);
+ if (LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(stackField) && LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(xAxisField)) {
Collection<VBarGraphData> levelVGraphData = dataList.getGraphData();
for (VBarGraphData garphData : levelVGraphData) {
Collection<VNameValue> valueList = garphData.getDataCount();
@@ -312,17 +267,14 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
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);
+ 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) {
+ 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();
@@ -330,8 +282,7 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
queryGenerator.setMainQuery(solrQuery, null);
if (solrUtil.isSolrFieldNumber(typeXAxis,solrDaoBase)) {
queryGenerator.setSingleRangeFilter(solrQuery, fieldTime, from, to);
- return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase,
- typeXAxis, fieldTime, solrQuery);
+ return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase, typeXAxis, fieldTime, solrQuery);
} else {
try {
queryGenerator.setFacetRange(solrQuery, xAxisField, from, to, unit);
@@ -360,44 +311,36 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
}
return dataList;
} catch (SolrException | SolrServerException | IOException e) {
- logger.error("Got exception for solr query :" + solrQuery,
- e.getCause());
+ logger.error("Got exception for solr query :" + solrQuery, e.getCause());
}
}
return null;
}
@SuppressWarnings("unchecked")
- private VBarDataList rangeStackGraph(String xAxisField, String stackField,
- String from, String to, String unit, SolrDaoBase solrDaoBase,
- SolrQuery solrQuery) {
+ private VBarDataList rangeStackGraph(String xAxisField, String stackField, String from, String to, String unit,
+ SolrDaoBase solrDaoBase, 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("\\", "");
+ 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
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
+ if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
return dataList;
}
- extractRangeStackValuesFromBucket(jsonFacetResponse, "x", "y",
- histogramData);
+ 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());
+ logger.error("Got exception for solr query :" + solrQuery, e.getCause());
}
return null;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/dfa9bd38/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 a813e96..49006e2 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
@@ -25,95 +25,50 @@ 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.commons.lang.StringUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.springframework.beans.factory.annotation.Autowired;
-public class GraphDataGeneratorBase extends MgrBase {
-
-
- @Autowired
- DateUtil dateUtil;
+class GraphDataGeneratorBase extends MgrBase {
@Autowired
- StringUtil stringUtil;
+ private DateUtil dateUtil;
- private static String BUCKETS = "buckets";
+ private static final 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";
- }
-
- };
- abstract String getType();
+ private static enum DataType {
+ LONG("long"),
+ DOUBLE("double"),
+ FLOAT("long"),
+ INT("long");
+
+ private String type;
+
+ DataType(String type) {
+ this.type = type;
+ }
+
+ String getType() {
+ return type;
+ }
}
- 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();
+ protected static enum GraphType {
+ UNKNOWN,
+ NORMAL_GRAPH,
+ RANGE_NON_STACK_GRAPH,
+ NON_RANGE_STACK_GRAPH,
+ RANGE_STACK_GRAPH;
}
@SuppressWarnings("unchecked")
- protected void extractRangeStackValuesFromBucket(
- SimpleOrderedMap<Object> jsonFacetResponse, String outerField,
+ protected void extractRangeStackValuesFromBucket(SimpleOrderedMap<Object> jsonFacetResponse, String outerField,
String innerField, List<VBarGraphData> histogramData) {
if (jsonFacetResponse != null) {
- NamedList<Object> stack = (NamedList<Object>) jsonFacetResponse
- .get(outerField);
+ NamedList<Object> stack = (NamedList<Object>) jsonFacetResponse.get(outerField);
if (stack != null) {
ArrayList<Object> stackBuckets = (ArrayList<Object>) stack.get(BUCKETS);
if (stackBuckets != null) {
@@ -121,26 +76,19 @@ public class GraphDataGeneratorBase extends MgrBase {
VBarGraphData vBarGraphData = new VBarGraphData();
SimpleOrderedMap<Object> level = (SimpleOrderedMap<Object>) stackBucket;
if (level != null) {
- String name = level.getVal(0) != null ? level.getVal(0)
- .toString().toUpperCase() : "";
+ 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);
+ NamedList<Object> innerFiledValue = (NamedList<Object>) level.get(innerField);
if (innerFiledValue != null) {
- ArrayList<Object> levelBuckets = (ArrayList<Object>) innerFiledValue
- .get(BUCKETS);
+ 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);
+ 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);
}
}
@@ -156,27 +104,23 @@ public class GraphDataGeneratorBase extends MgrBase {
}
@SuppressWarnings("unchecked")
- protected boolean extractNonRangeStackValuesFromBucket(
- SimpleOrderedMap<Object> jsonFacetResponse, String level,
+ protected boolean extractNonRangeStackValuesFromBucket(SimpleOrderedMap<Object> jsonFacetResponse, String level,
Collection<VBarGraphData> vGraphDatas, String typeXAxis) {
boolean zeroFlag = true;
if (jsonFacetResponse == null || jsonFacetResponse.get(level) == null
|| jsonFacetResponse.get(level).toString().equals("{count=0}")) {
return false;
}
- NamedList<Object> levelList = (NamedList<Object>) jsonFacetResponse
- .get(level);
+ 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);
+ 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() : "";
+ String name = valueCount.getVal(0) != null ? valueCount.getVal(0).toString().trim() : "";
if (isTypeNumber(typeXAxis)) {
VNameValue nameValue = new VNameValue();
Double sumValue = (Double) valueCount.getVal(2);
@@ -188,24 +132,16 @@ public class GraphDataGeneratorBase extends MgrBase {
nameValue.setValue(value);
levelCounts.add(nameValue);
} else {
- SimpleOrderedMap<Object> valueCountMap = (SimpleOrderedMap<Object>) valueCount
- .getVal(2);
+ SimpleOrderedMap<Object> valueCountMap = (SimpleOrderedMap<Object>) valueCount.getVal(2);
if (valueCountMap != null) {
- ArrayList<Object> buckets = (ArrayList<Object>) valueCountMap
- .get(BUCKETS);
+ 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);
+ 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);
+ 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);
}
}
@@ -222,59 +158,12 @@ public class GraphDataGeneratorBase extends MgrBase {
return zeroFlag;
}
- @SuppressWarnings("unchecked")
- protected boolean extractValuesFromJson(
- 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}")) {
- 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> 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++;
- }
- }
- }
- return zeroFlag;
- }
-
protected boolean isTypeNumber(String typeXAxis) {
- if (stringUtil.isEmpty(typeXAxis)) {
+ if (StringUtils.isBlank(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());
+ return typeXAxis.contains(DataType.LONG.getType()) || typeXAxis.contains(DataType.INT.getType())
+ || typeXAxis.contains(DataType.FLOAT.getType()) || typeXAxis.contains(DataType.DOUBLE.getType());
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/dfa9bd38/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 ab287bc..947fdbb 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
@@ -41,10 +41,8 @@ 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;
-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.StringUtil;
import org.apache.ambari.logsearch.view.VBarDataList;
import org.apache.ambari.logsearch.view.VBarGraphData;
import org.apache.ambari.logsearch.view.VGroupList;
@@ -69,54 +67,41 @@ import org.springframework.stereotype.Component;
@Component
public class AuditMgr extends MgrBase {
- static Logger logger = Logger.getLogger(AuditMgr.class);
+ private static final Logger logger = Logger.getLogger(AuditMgr.class);
@Autowired
- AuditSolrDao auditSolrDao;
-
+ private AuditSolrDao auditSolrDao;
@Autowired
- RESTErrorUtil restErrorUtil;
-
+ private RESTErrorUtil restErrorUtil;
@Autowired
- JSONUtil jsonUtil;
-
+ private BizUtil bizUtil;
@Autowired
- StringUtil stringUtil;
-
+ private DateUtil dateUtil;
@Autowired
- BizUtil bizUtil;
-
- @Autowired
- DateUtil dateUtil;
-
- @Autowired
- GraphDataGenerator graphDataGenerator;
+ private GraphDataGenerator graphDataGenerator;
public String getLogs(SearchCriteria searchCriteria) {
String lastPage = (String) searchCriteria.getParamValue("isLastPage");
Boolean isLastPage = Boolean.parseBoolean(lastPage);
if (isLastPage) {
SolrQuery lastPageQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
- VSolrLogList collection = getLastPage(searchCriteria,LogSearchConstants.AUDIT_EVTTIME,auditSolrDao,lastPageQuery);
+ VSolrLogList collection = getLastPage(searchCriteria, LogSearchConstants.AUDIT_EVTTIME, auditSolrDao, lastPageQuery);
if(collection == null){
collection = new VSolrLogList();
}
return convertObjToString(collection);
}
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
- VSolrLogList collection = getLogAsPaginationProvided(solrQuery,
- auditSolrDao);
+ VSolrLogList collection = getLogAsPaginationProvided(solrQuery, auditSolrDao);
return convertObjToString(collection);
}
- public SolrDocumentList getComponents(SearchCriteria searchCriteria) {
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ private SolrDocumentList getComponents(SearchCriteria searchCriteria) {
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
SolrDocumentList docList = new SolrDocumentList();
try {
- queryGenerator.setFacetField(solrQuery,
- LogSearchConstants.AUDIT_COMPONENT);
+ queryGenerator.setFacetField(solrQuery, LogSearchConstants.AUDIT_COMPONENT);
queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
List<FacetField> facetFields = null;
List<Count> componentsCount = new ArrayList<Count>();
@@ -146,8 +131,7 @@ public class AuditMgr extends MgrBase {
return docList;
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -167,14 +151,10 @@ public class AuditMgr extends MgrBase {
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(
- LogSearchConstants.AUDIT_COMPONENT,
- LogSearchConstants.AUDIT_EVTTIME, from, to, unit).replace("\\",
- "");
+ String jsonHistogramQuery = queryGenerator.buildJSONFacetTermTimeRangeQuery(LogSearchConstants.AUDIT_COMPONENT,
+ LogSearchConstants.AUDIT_EVTTIME, from, to, unit).replace("\\", "");
try {
queryGenerator.setJSONFacet(solrQuery, jsonHistogramQuery);
@@ -183,24 +163,20 @@ public class AuditMgr extends MgrBase {
if (response == null){
return convertObjToString(dataList);
}
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
- .getResponse().get("facets");
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
- if (jsonFacetResponse == null
- || jsonFacetResponse.toString().equals("{count=0}")){
+ if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
return convertObjToString(dataList);
}
- extractValuesFromBucket(jsonFacetResponse, "x", "y",
- histogramData);
+ extractValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
dataList.setGraphData(histogramData);
return convertObjToString(dataList);
} catch (SolrServerException | SolrException | IOException e) {
logger.error(e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -212,8 +188,7 @@ public class AuditMgr extends MgrBase {
if (top == null){
top = new Integer(topCounts);
}
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
try {
List<VNameValue> nameValues = new ArrayList<VNameValue>();
@@ -226,13 +201,12 @@ public class AuditMgr extends MgrBase {
List<Count> countList = new ArrayList<FacetField.Count>();
QueryResponse queryResponse = auditSolrDao.process(solrQuery);
- if(queryResponse == null){
+ if (queryResponse == null) {
return convertObjToString(nameValueList);
}
if (queryResponse.getFacetField(facetField) != null) {
- FacetField queryFacetField = queryResponse
- .getFacetField(facetField);
+ FacetField queryFacetField = queryResponse.getFacetField(facetField);
if (queryFacetField != null) {
countList = queryFacetField.getValues();
}
@@ -249,8 +223,7 @@ public class AuditMgr extends MgrBase {
} catch (SolrException | IOException | SolrServerException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -260,16 +233,12 @@ public class AuditMgr extends MgrBase {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setParam("event", "/audit/logs/live/count");
try {
- String startDate = dateUtil
- .convertGivenDateFormatToSolrDateFormat(ManageStartEndTime.startDate);
-
- String endDate = dateUtil
- .convertGivenDateFormatToSolrDateFormat(ManageStartEndTime.endDate);
+ Date[] timeRange = ManageStartEndTime.getStartEndTime();
+ String startDate = dateUtil.convertGivenDateFormatToSolrDateFormat(timeRange[0]);
+ String endDate = dateUtil.convertGivenDateFormatToSolrDateFormat(timeRange[1]);
queryGenerator.setMainQuery(solrQuery, null);
- queryGenerator.setFacetRange(solrQuery,
- LogSearchConstants.AUDIT_EVTTIME, startDate, endDate,
- "+2MINUTE");
+ queryGenerator.setFacetRange(solrQuery, LogSearchConstants.AUDIT_EVTTIME, startDate, endDate, "+2MINUTE");
List<RangeFacet.Count> listCount;
QueryResponse response = auditSolrDao.process(solrQuery);
@@ -301,22 +270,21 @@ public class AuditMgr extends MgrBase {
} catch (SolrException | SolrServerException | ParseException
| IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
public String topTenUsers(SearchCriteria searchCriteria) {
- String jsonUserQuery = "{Users:{type:terms, field:reqUser, facet:{ Repo:{ type:terms, field:repo, facet:{eventCount:\"sum(event_count)\"}}}}}";
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ String jsonUserQuery =
+ "{Users:{type:terms, field:reqUser, facet:{ Repo:{ type:terms, field:repo, facet:{eventCount:\"sum(event_count)\"}}}}}";
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
queryGenerator.setJSONFacet(solrQuery, jsonUserQuery);
queryGenerator.setRowCount(solrQuery, 0);
try {
VBarDataList vBarDataList = new VBarDataList();
QueryResponse queryResponse = auditSolrDao.process(solrQuery);
- if(queryResponse == null){
+ if (queryResponse == null) {
return convertObjToString(vBarDataList);
}
@@ -327,12 +295,11 @@ public class AuditMgr extends MgrBase {
}
@SuppressWarnings("unchecked")
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList
- .get("facets");
- if(jsonFacetResponse == null){
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList.get("facets");
+ if (jsonFacetResponse == null) {
return convertObjToString(vBarDataList);
}
- if(jsonFacetResponse.toString().equals("{count=0}")){
+ if (jsonFacetResponse.toString().equals("{count=0}")) {
return convertObjToString(vBarDataList);
}
vBarDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
@@ -340,16 +307,15 @@ public class AuditMgr extends MgrBase {
} catch (SolrServerException | SolrException | IOException e) {
logger.error("Error during solrQuery=" + e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
public String topTenResources(SearchCriteria searchCriteria) {
- String jsonUserQuery = "{Users:{type:terms,field:resource,facet:{Repo:{type:terms,field:repo,facet:{eventCount:\"sum(event_count)\"}}}}}";
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ String jsonUserQuery =
+ "{Users:{type:terms,field:resource,facet:{Repo:{type:terms,field:repo,facet:{eventCount:\"sum(event_count)\"}}}}}";
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
queryGenerator.setJSONFacet(solrQuery, jsonUserQuery);
queryGenerator.setRowCount(solrQuery, 0);
try {
@@ -365,16 +331,14 @@ public class AuditMgr extends MgrBase {
}
@SuppressWarnings("unchecked")
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList
- .get("facets");
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList.get("facets");
vBarDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
return convertObjToString(vBarDataList);
} catch (SolrServerException | SolrException | IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -385,19 +349,15 @@ public class AuditMgr extends MgrBase {
String to = getTo((String) searchCriteria.getParamValue("endTime"));
String unit = getUnit((String) searchCriteria.getParamValue("unit"));
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
VBarDataList dataList = new VBarDataList();
List<VBarGraphData> histogramData = new ArrayList<VBarGraphData>();
queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
- String jsonHistogramQuery = queryGenerator
- .buildJSONFacetTermTimeRangeQuery(
- LogSearchConstants.AUDIT_REQUEST_USER,
- LogSearchConstants.AUDIT_EVTTIME, from, to, unit)
- .replace("\\", "");
+ String jsonHistogramQuery = queryGenerator.buildJSONFacetTermTimeRangeQuery(LogSearchConstants.AUDIT_REQUEST_USER,
+ LogSearchConstants.AUDIT_EVTTIME, from, to, unit).replace("\\", "");
try {
queryGenerator.setJSONFacet(solrQuery, jsonHistogramQuery);
@@ -406,11 +366,9 @@ public class AuditMgr extends MgrBase {
if (response == null){
return convertObjToString(dataList);
}
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
- .getResponse().get("facets");
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
- if (jsonFacetResponse == null
- || jsonFacetResponse.toString().equals("{count=0}")){
+ if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
return convertObjToString(dataList);
}
extractValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
@@ -420,63 +378,19 @@ public class AuditMgr extends MgrBase {
} catch (SolrException | IOException | SolrServerException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().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 {
- queryGenerator.setFacetField(solrQuery,
- LogSearchConstants.AUDIT_REQUEST_USER);
- queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
- List<FacetField> facetFields = null;
- List<Count> componentsCount = new ArrayList<Count>();
- FacetField facetField = null;
-
- QueryResponse queryResponse = auditSolrDao.process(solrQuery);
- if (queryResponse == null) {
- return docList;
- }
-
- facetFields = queryResponse.getFacetFields();
- if (facetFields == null) {
- return docList;
- }
- if (!facetFields.isEmpty()) {
- facetField = facetFields.get(0);
- }
- if (facetField != null) {
- componentsCount = facetField.getValues();
- }
-
- for (Count compnonet : componentsCount) {
- SolrDocument solrDocument = new SolrDocument();
- solrDocument.addField("type", compnonet.getName());
- docList.add(solrDocument);
- }
- return docList;
- } catch (SolrException | SolrServerException | IOException e) {
- logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
- }
- }
-
public String getAuditLogsSchemaFieldsName() {
- String excludeArray[] = PropertiesUtil
- .getPropertyStringList("logsearch.solr.audit.logs.exclude.columnlist");
+ String excludeArray[] = PropertiesUtil.getPropertyStringList("logsearch.solr.audit.logs.exclude.columnlist");
List<String> fieldNames = new ArrayList<String>();
HashMap<String, String> uiFieldColumnMapping = new HashMap<String, String>();
ConfigUtil.getSchemaFieldsName(excludeArray, fieldNames,auditSolrDao);
for (String fieldName : fieldNames) {
- String uiField = ConfigUtil.auditLogsColumnMapping.get(fieldName
- + LogSearchConstants.SOLR_SUFFIX);
+ String uiField = ConfigUtil.auditLogsColumnMapping.get(fieldName + LogSearchConstants.SOLR_SUFFIX);
if (uiField == null) {
uiFieldColumnMapping.put(fieldName, fieldName);
} else {
@@ -492,8 +406,7 @@ public class AuditMgr extends MgrBase {
public String getAnyGraphData(SearchCriteria searchCriteria) {
searchCriteria.addParam("fieldTime", LogSearchConstants.AUDIT_EVTTIME);
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
- VBarDataList result = graphDataGenerator.getAnyGraphData(searchCriteria,
- auditSolrDao, solrQuery);
+ VBarDataList result = graphDataGenerator.getAnyGraphData(searchCriteria, auditSolrDao, solrQuery);
if (result == null) {
result = new VBarDataList();
}
@@ -502,13 +415,10 @@ public class AuditMgr extends MgrBase {
}
@SuppressWarnings("unchecked")
- public void extractValuesFromBucket(
- 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");
+ private void extractValuesFromBucket(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();
@@ -518,13 +428,10 @@ public class AuditMgr extends MgrBase {
Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
vBarGraphData.setDataCounts(vNameValues);
- ArrayList<Object> levelBuckets = (ArrayList<Object>) ((NamedList<Object>) level
- .get(innerField)).get("buckets");
+ 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));
+ String value = dateUtil.convertDateWithMillisecondsToSolrDate((Date) countValue.getVal(0));
String count = "" + countValue.getVal(1);
VNameValue vNameValue = new VNameValue();
@@ -536,12 +443,12 @@ public class AuditMgr extends MgrBase {
}
}
- @SuppressWarnings({"unchecked", "resource"})
+ @SuppressWarnings({"unchecked"})
public Response exportUserTableToTextFile(SearchCriteria searchCriteria) {
- String jsonUserQuery = "{ Users: { type: terms, field: reqUser, facet: {Repo: { type: terms, field: repo, facet: { eventCount: \"sum(event_count)\"}}}},x:{ type: terms,field: resource, facet: {y: { type: terms, field: repo,facet: { eventCount: \"sum(event_count)\"}}}}}";
+ String jsonUserQuery =
+ "{ Users: { type: terms, field: reqUser, facet: {Repo: { type: terms, field: repo, facet: { eventCount: \"sum(event_count)\"}}}},x:{ type: terms,field: resource, facet: {y: { type: terms, field: repo,facet: { eventCount: \"sum(event_count)\"}}}}}";
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
String startTime = (String) searchCriteria.getParamValue("startTime");
String endTime = (String) searchCriteria.getParamValue("endTime");
@@ -562,7 +469,7 @@ public class AuditMgr extends MgrBase {
}
NamedList<Object> namedList = queryResponse.getResponse();
- if(namedList == null){
+ if (namedList == null) {
VResponse response = new VResponse();
response.setMsgDesc("Query was not able to execute "+solrQuery);
throw restErrorUtil.createRESTException(response);
@@ -570,12 +477,9 @@ public class AuditMgr extends MgrBase {
VBarDataList vBarUserDataList = new VBarDataList();
VBarDataList vBarResourceDataList = new VBarDataList();
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList
- .get("facets");
- vBarUserDataList = bizUtil
- .buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
- vBarResourceDataList = bizUtil
- .buildSummaryForTopCounts(jsonFacetResponse,"y","x");
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList.get("facets");
+ vBarUserDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
+ vBarResourceDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"y","x");
String data = "";
String summary = "";
if ("text".equals(dataFormat)) {
@@ -584,8 +488,7 @@ public class AuditMgr extends MgrBase {
summary += "\n\n\n\n";
data += addBlank("Users") + "Components/Access" + "\n";
data += "--------------------------------------------------------------------------\n";
- Collection<VBarGraphData> tableUserData = vBarUserDataList
- .getGraphData();
+ Collection<VBarGraphData> tableUserData = vBarUserDataList.getGraphData();
for (VBarGraphData graphData : tableUserData) {
String userName = graphData.getName();
String largeUserName = "";
@@ -596,13 +499,11 @@ public class AuditMgr extends MgrBase {
} else
data += addBlank(userName);
- Collection<VNameValue> vnameValueList = graphData
- .getDataCount();
+ Collection<VNameValue> vnameValueList = graphData.getDataCount();
int count = 0;
String blank = "";
for (VNameValue vNameValue : vnameValueList) {
- data += blank + vNameValue.getName() + " "
- + vNameValue.getValue() + "\n";
+ data += blank + vNameValue.getName() + " " + vNameValue.getValue() + "\n";
if (count == 0)
blank = addBlank(blank);
count++;
@@ -617,8 +518,7 @@ public class AuditMgr extends MgrBase {
data += "\n\n\n\n\n\n";
data += addBlank("Resources") + "Components/Access" + "\n";
data += "--------------------------------------------------------------------------\n";
- Collection<VBarGraphData> tableResourceData = vBarResourceDataList
- .getGraphData();
+ Collection<VBarGraphData> tableResourceData = vBarResourceDataList.getGraphData();
for (VBarGraphData graphData : tableResourceData) {
String resourceName = graphData.getName();
String largeResourceName = resourceName;
@@ -631,13 +531,11 @@ public class AuditMgr extends MgrBase {
//resourceName = resourceName.replaceAll("(.{45})", resourceName.substring(0, 45)+"\n");
data += addBlank(resourceName);
- Collection<VNameValue> vnameValueList = graphData
- .getDataCount();
+ Collection<VNameValue> vnameValueList = graphData.getDataCount();
int count = 0;
String blank = "";
for (VNameValue vNameValue : vnameValueList) {
- data += blank + vNameValue.getName() + " "
- + vNameValue.getValue() + "\n";
+ data += blank + vNameValue.getName() + " " + vNameValue.getValue() + "\n";
if (count == 0)
blank = addBlank(blank);
count++;
@@ -660,22 +558,19 @@ public class AuditMgr extends MgrBase {
data = "{" + convertObjToString(vBarUserDataList) + "," + convertObjToString(vBarResourceDataList) + "}";
dataFormat = "json";
}
- String fileName = "Users_Resource" + startTime + endTime
- + ".";
+ String fileName = "Users_Resource" + startTime + endTime + ".";
File file = File.createTempFile(fileName, dataFormat);
fis = new FileOutputStream(file);
fis.write(data.getBytes());
return Response
.ok(file, MediaType.APPLICATION_OCTET_STREAM)
- .header("Content-Disposition",
- "attachment;filename=" + fileName + dataFormat)
+ .header("Content-Disposition", "attachment;filename=" + fileName + dataFormat)
.build();
} catch (SolrServerException | SolrException | IOException e) {
logger.error("Error during solrQuery=" + e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
} finally {
if (fis != null) {
try {
@@ -704,21 +599,18 @@ public class AuditMgr extends MgrBase {
SolrQuery serivceLoadQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
try {
- queryGenerator.setFacetField(serivceLoadQuery,
- LogSearchConstants.AUDIT_COMPONENT);
- QueryResponse serviceLoadResponse = auditSolrDao
- .process(serivceLoadQuery);
+ queryGenerator.setFacetField(serivceLoadQuery, LogSearchConstants.AUDIT_COMPONENT);
+ QueryResponse serviceLoadResponse = auditSolrDao.process(serivceLoadQuery);
if (serviceLoadResponse == null){
return convertObjToString(dataList);
}
- FacetField serviceFacetField =serviceLoadResponse.getFacetField(
- LogSearchConstants.AUDIT_COMPONENT);
- if(serviceFacetField == null){
+ FacetField serviceFacetField =serviceLoadResponse.getFacetField(LogSearchConstants.AUDIT_COMPONENT);
+ if (serviceFacetField == null) {
return convertObjToString(dataList);
}
List<Count> serviceLoadFacets = serviceFacetField.getValues();
- if(serviceLoadFacets == null){
+ if (serviceLoadFacets == null) {
return convertObjToString(dataList);
}
for (Count cnt : serviceLoadFacets) {
@@ -733,70 +625,11 @@ public class AuditMgr extends MgrBase {
vBarGraphData.setDataCounts(valueList);
}
-
return convertObjToString(dataList);
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error during solrQuery=" + e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
-
- /*
- String preDefinedJSON = getHadoopServiceConfigJSON();
- try {
- JSONObject serviceJSON = new JSONObject(preDefinedJSON).getJSONObject("service");
- HashMap<String, Object> serviceMap = jsonUtil.jsonToMapObject(serviceJSON.toString());
- Iterator<Entry<String, Object>> serviceMapIterator= serviceMap.entrySet().iterator();
- List<VNameValue> newValueList = new ArrayList<VNameValue>();
- for (VNameValue vNameValue : valueList) {
- String name=vNameValue.getName();
- while (serviceMapIterator.hasNext()) {
- Map.Entry<String, Object> tempMap = serviceMapIterator
- .next();
-
- String keyName = tempMap.getKey();
-
- JSONObject valueObj = new JSONObject(tempMap.toString().replace(keyName+"=", ""));
- if(name.contains(keyName.toLowerCase())){
- vNameValue.setName(valueObj.getString("label"));
- break;
- }
- JSONArray componentsArray = valueObj.getJSONArray("components");
-
- for(int i =0;i< componentsArray.length();i++){
- JSONObject jObj = componentsArray.getJSONObject(i);
- String jsonName = jObj.getString("name");
- if(name.contains(jsonName.toLowerCase())){
- vNameValue.setName(valueObj.getString("label"));
- break;
- }
- }
-
- }
- if(newValueList.isEmpty()){
- newValueList.add(vNameValue);
- }else{
- boolean isMatch = false;
- for(VNameValue vValue: newValueList){
- if(vValue.getName().equalsIgnoreCase(vNameValue.getName())){
- isMatch =true;
- Integer cnt1 = Integer.parseInt(vValue.getValue());
- Integer cnt2 = Integer.parseInt(vNameValue.getValue());
- vValue.setValue((cnt1+cnt2)+"");
- }
- }
- if(!isMatch)
- newValueList.add(vNameValue);
- }
- }
- vBarGraphData.setDataCounts(newValueList);
- vBarGraphData.setName("ServiceList");
- return convertObjToString(dataList);
-
- } catch (Exception e) {
- throw restErrorUtil.createRESTException(e.getMessage(),
- MessageEnums.ERROR_SYSTEM);
- }*/
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/dfa9bd38/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java
index 1bd9a78..8badb61 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java
@@ -32,6 +32,7 @@ import org.apache.ambari.logsearch.view.VLogFile;
import org.apache.ambari.logsearch.view.VLogFileList;
import org.apache.ambari.logsearch.view.VSolrLogList;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -46,24 +47,13 @@ import org.springframework.stereotype.Component;
@Component
public class LogFileMgr extends MgrBase {
- private static Logger logger = Logger.getLogger(LogFileMgr.class);
-
+ private static final Logger logger = Logger.getLogger(LogFileMgr.class);
@Autowired
- ServiceLogsSolrDao serviceLogsSolrDao;
-
+ private ServiceLogsSolrDao serviceLogsSolrDao;
@Autowired
- AuditSolrDao auditSolrDao;
+ private AuditSolrDao auditSolrDao;
- @Autowired
- LogsMgr logMgr;
-
- /**
- * Search logFiles
- *
- * @param searchCriteria
- * @return
- */
public String searchLogFiles(SearchCriteria searchCriteria) {
VLogFileList logFileList = new VLogFileList();
List<VLogFile> logFiles = new ArrayList<VLogFile>();
@@ -72,31 +62,26 @@ public class LogFileMgr extends MgrBase {
int minCount = 1;// to remove zero count facet
SolrQuery solrQuery = new SolrQuery();
queryGenerator.setMainQuery(solrQuery, null);
- queryGenerator.setFacetFieldWithMincount(solrQuery, LogSearchConstants.SOLR_PATH,
- minCount);
+ queryGenerator.setFacetFieldWithMincount(solrQuery, LogSearchConstants.SOLR_PATH, minCount);
// adding filter
- queryGenerator.setSingleIncludeFilter(solrQuery,
- LogSearchConstants.SOLR_COMPONENT, componentName);
- queryGenerator.setSingleIncludeFilter(solrQuery,
- LogSearchConstants.SOLR_HOST, host);
+ queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_COMPONENT, componentName);
+ queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_HOST, host);
try {
String logType = (String) searchCriteria.getParamValue("logType");
- if (stringUtil.isEmpty(logType)) {
- logType = LOG_TYPE.SERVICE.name();// default is service Log
+ if (StringUtils.isBlank(logType)) {
+ logType = LogType.SERVICE.name();// default is service Log
}
SolrDaoBase daoMgr = null;
- if (logType.equalsIgnoreCase(LOG_TYPE.SERVICE.name())) {
+ if (logType.equalsIgnoreCase(LogType.SERVICE.name())) {
daoMgr = serviceLogsSolrDao;
- } else if (logType.equalsIgnoreCase(LOG_TYPE.AUDIT.name())) {
+ } else if (logType.equalsIgnoreCase(LogType.AUDIT.name())) {
daoMgr = auditSolrDao;
} else {
- throw restErrorUtil.createRESTException(logType
- + " is not a valid logType", MessageEnums.INVALID_INPUT_DATA);
+ throw restErrorUtil.createRESTException(logType + " is not a valid logType", MessageEnums.INVALID_INPUT_DATA);
}
QueryResponse queryResponse = daoMgr.process(solrQuery);
if (queryResponse.getFacetField(LogSearchConstants.SOLR_PATH) != null) {
- FacetField queryFacetField = queryResponse
- .getFacetField(LogSearchConstants.SOLR_PATH);
+ FacetField queryFacetField = queryResponse.getFacetField(LogSearchConstants.SOLR_PATH);
if (queryFacetField != null) {
List<Count> countList = queryFacetField.getValues();
for (Count count : countList) {
@@ -110,10 +95,8 @@ public class LogFileMgr extends MgrBase {
}
}
} catch (SolrException | SolrServerException | IOException e) {
- logger.error("Error in solr query :" + e.getLocalizedMessage()
- + "\n Query :" + solrQuery.toQueryString(), e.getCause());
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ logger.error("Error in solr query :" + e.getLocalizedMessage() + "\n Query :" + solrQuery.toQueryString(), e.getCause());
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
logFileList.setLogFiles(logFiles);
String jsonStr = "";
@@ -127,28 +110,22 @@ public class LogFileMgr extends MgrBase {
String logFile = (String) searchCriteria.getParamValue("name");
String component = (String) searchCriteria.getParamValue("component");
String tailSize = (String) searchCriteria.getParamValue("tailSize");
- if (stringUtil.isEmpty(host)) {
- throw restErrorUtil.createRESTException("missing Host Name",
- MessageEnums.ERROR_SYSTEM);
+ if (StringUtils.isBlank(host)) {
+ throw restErrorUtil.createRESTException("missing Host Name", MessageEnums.ERROR_SYSTEM);
}
- tailSize = (stringUtil.isEmpty(tailSize)) ? "10" : tailSize;
+ tailSize = (StringUtils.isBlank(tailSize)) ? "10" : tailSize;
SolrQuery logFileTailQuery = new SolrQuery();
try {
int tail = Integer.parseInt(tailSize);
tail = tail > 100 ? 100 : tail;
queryGenerator.setMainQuery(logFileTailQuery, null);
- queryGenerator.setSingleIncludeFilter(logFileTailQuery,
- LogSearchConstants.SOLR_HOST, host);
- if (!stringUtil.isEmpty(logFile)) {
- queryGenerator.setSingleIncludeFilter(logFileTailQuery,
- LogSearchConstants.SOLR_PATH,
- solrUtil.makeSolrSearchString(logFile));
- } else if (!stringUtil.isEmpty(component)) {
- queryGenerator.setSingleIncludeFilter(logFileTailQuery,
- LogSearchConstants.SOLR_COMPONENT, component);
+ queryGenerator.setSingleIncludeFilter(logFileTailQuery, LogSearchConstants.SOLR_HOST, host);
+ if (!StringUtils.isBlank(logFile)) {
+ queryGenerator.setSingleIncludeFilter(logFileTailQuery, LogSearchConstants.SOLR_PATH, solrUtil.makeSolrSearchString(logFile));
+ } else if (!StringUtils.isBlank(component)) {
+ queryGenerator.setSingleIncludeFilter(logFileTailQuery, LogSearchConstants.SOLR_COMPONENT, component);
} else {
- throw restErrorUtil.createRESTException("component or logfile parameter must be present",
- MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException("component or logfile parameter must be present", MessageEnums.ERROR_SYSTEM);
}
queryGenerator.setRowCount(logFileTailQuery, tail);