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:36 UTC
[19/51] [abbrv] ambari git commit: AMBARI-18253. Fix LogSearch
utility classes (Miklos Gergely via oleewere)
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java
index 9baccce..53e0aab 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java
@@ -38,16 +38,19 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.ws.rs.core.Response;
+import org.apache.ambari.logsearch.common.ConfigHelper;
import org.apache.ambari.logsearch.common.LogSearchConstants;
import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.ambari.logsearch.common.PropertiesHelper;
import org.apache.ambari.logsearch.common.SearchCriteria;
import org.apache.ambari.logsearch.dao.ServiceLogsSolrDao;
import org.apache.ambari.logsearch.graph.GraphDataGenerator;
import org.apache.ambari.logsearch.query.QueryGenerationBase;
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.FileUtil;
-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.view.VBarDataList;
import org.apache.ambari.logsearch.view.VBarGraphData;
import org.apache.ambari.logsearch.view.VCount;
@@ -97,10 +100,6 @@ public class LogsMgr extends MgrBase {
@Autowired
private ServiceLogsSolrDao serviceLogsSolrDao;
@Autowired
- private BizUtil bizUtil;
- @Autowired
- private FileUtil fileUtil;
- @Autowired
private GraphDataGenerator graphDataGenerator;
public String searchLogs(SearchCriteria searchCriteria) {
@@ -114,7 +113,7 @@ public class LogsMgr extends MgrBase {
return getPageByKeyword(searchCriteria);
} catch (SolrException | SolrServerException e) {
logger.error("Error while getting keyword=" + keyword, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
} else if (!StringUtils.isBlank(logId)) {
@@ -122,7 +121,7 @@ public class LogsMgr extends MgrBase {
return getPageByLogId(searchCriteria);
} catch (SolrException e) {
logger.error("Error while getting keyword=" + keyword, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
} else if (isLastPage) {
@@ -152,10 +151,10 @@ public class LogsMgr extends MgrBase {
SolrQuery solrQuery = new SolrQuery();
VGroupList collection = new VGroupList();
- queryGenerator.setMainQuery(solrQuery, null);
- queryGenerator.setFacetField(solrQuery,
+ SolrUtil.setMainQuery(solrQuery, null);
+ SolrUtil.setFacetField(solrQuery,
field);
- queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
+ SolrUtil.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
try {
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
if(response == null){
@@ -190,7 +189,7 @@ public class LogsMgr extends MgrBase {
return convertObjToString(collection);
} catch (IOException | SolrServerException | SolrException e) {
logger.error(e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
@@ -205,8 +204,8 @@ public class LogsMgr extends MgrBase {
String hierarchy = "host,type,level";
VGraphInfo graphInfo = new VGraphInfo();
try {
- queryGenerator.setMainQuery(solrQuery, null);
- queryGenerator.setFacetPivot(solrQuery, 1, hierarchy);
+ SolrUtil.setMainQuery(solrQuery, null);
+ SolrUtil.setFacetPivot(solrQuery, 1, hierarchy);
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
if (response == null) {
return convertObjToString(graphInfo);
@@ -228,7 +227,7 @@ public class LogsMgr extends MgrBase {
return convertObjToString(graphInfo);
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -255,11 +254,11 @@ public class LogsMgr extends MgrBase {
VCountList collection = new VCountList();
List<VCount> vCounts = new ArrayList<VCount>();
SolrQuery solrQuery = new SolrQuery();
- queryGenerator.setMainQuery(solrQuery, null);
+ SolrUtil.setMainQuery(solrQuery, null);
if(field == null){
return collection;
}
- queryGenerator.setFacetField(solrQuery, field);
+ SolrUtil.setFacetField(solrQuery, field);
try {
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
if (response == null){
@@ -286,7 +285,7 @@ public class LogsMgr extends MgrBase {
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
@@ -419,7 +418,7 @@ public class LogsMgr extends MgrBase {
VNodeList list = new VNodeList();
try {
- queryGenerator.setFacetPivot(solrQuery, 1, firstHirarchy,
+ SolrUtil.setFacetPivot(solrQuery, 1, firstHirarchy,
secondHirarchy);
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
@@ -454,7 +453,7 @@ public class LogsMgr extends MgrBase {
list.setvNodeList(dataList);
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
@@ -485,7 +484,7 @@ public class LogsMgr extends MgrBase {
String secondHirarchy = "type,level";
try {
- queryGenerator.setFacetPivot(solrQuery, 1, firstHirarchy,
+ SolrUtil.setFacetPivot(solrQuery, 1, firstHirarchy,
secondHirarchy);
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
List<List<PivotField>> firstHirarchicalPivotFields = null;
@@ -516,7 +515,7 @@ public class LogsMgr extends MgrBase {
return convertObjToString(list);
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -536,7 +535,7 @@ public class LogsMgr extends MgrBase {
HashMap<String, String> map = new HashMap<String, String>();
List<VNameValue> logsCounts = new ArrayList<VNameValue>();
try {
- queryGenerator.setFacetField(query, LogSearchConstants.SOLR_LEVEL);
+ SolrUtil.setFacetField(query, LogSearchConstants.SOLR_LEVEL);
List<Count> logLevelCounts = getFacetCounts(query,
LogSearchConstants.SOLR_LEVEL);
if (logLevelCounts == null) {
@@ -587,11 +586,11 @@ public class LogsMgr extends MgrBase {
String key = (String) searchCriteria.getParamValue("keyword");
if(StringUtils.isBlank(key)){
- throw restErrorUtil.createRESTException("Keyword was not given",
+ throw RESTErrorUtil.createRESTException("Keyword was not given",
MessageEnums.DATA_NOT_FOUND);
}
- String keyword = solrUtil.escapeForStandardTokenizer(key);
+ String keyword = SolrUtil.escapeForStandardTokenizer(key);
if(keyword.startsWith("\"") && keyword.endsWith("\"")){
keyword = keyword.substring(1);
@@ -625,13 +624,13 @@ public class LogsMgr extends MgrBase {
queryResponse = serviceLogsSolrDao.process(
nextPageLogTimeQuery);
if(queryResponse == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
SolrDocumentList docList = queryResponse.getResults();
if(docList ==null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
@@ -639,10 +638,10 @@ public class LogsMgr extends MgrBase {
Date logDate = (Date) solrDoc.get(LogSearchConstants.LOGTIME);
if(logDate == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
- nextPageLogTime = dateUtil
+ nextPageLogTime = DateUtil
.convertDateWithMillisecondsToSolrDate(logDate);
nextPageLogID = ""
+ solrDoc.get(LogSearchConstants.ID);
@@ -661,17 +660,17 @@ public class LogsMgr extends MgrBase {
LogSearchConstants.LOGTIME, "\"" + nextPageLogTime + "\"");
queryGenerator.setSingleExcludeFilter(listRemoveIds,
LogSearchConstants.ID, nextPageLogID);
- queryGenerator.setFl(listRemoveIds, LogSearchConstants.ID);
+ SolrUtil.setFl(listRemoveIds, LogSearchConstants.ID);
queryResponse = serviceLogsSolrDao.process(
listRemoveIds);
if(queryResponse == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
SolrDocumentList docListIds = queryResponse.getResults();
if(docListIds ==null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
boolean isFirst = true;
@@ -726,13 +725,13 @@ public class LogsMgr extends MgrBase {
queryResponse = serviceLogsSolrDao.process(
logTimeThroughRangeQuery);
if(queryResponse == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
SolrDocumentList documentList = queryResponse.getResults();
if(documentList ==null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
@@ -743,10 +742,10 @@ public class LogsMgr extends MgrBase {
Date keywordLogDate = (Date) solrDocument.get(LogSearchConstants.LOGTIME);
if(keywordLogDate == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
- String originalKeywordDate = dateUtil
+ String originalKeywordDate = DateUtil
.convertDateWithMillisecondsToSolrDate(keywordLogDate);
String keywordId = "" + solrDocument.get(LogSearchConstants.ID);
@@ -758,14 +757,14 @@ public class LogsMgr extends MgrBase {
if (!StringUtils.isBlank(sortByType) && sortByType
.equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) {
keywordLogDate = DateUtils.addMilliseconds(keywordLogDate, 1);
- String keywordDateTime = dateUtil
+ String keywordDateTime = DateUtil
.convertDateWithMillisecondsToSolrDate(keywordLogDate);
queryGenerator.setSingleRangeFilter(rangeLogQuery,
LogSearchConstants.LOGTIME, startTime,
keywordDateTime);
} else {
keywordLogDate = DateUtils.addMilliseconds(keywordLogDate, -1);
- String keywordDateTime = dateUtil
+ String keywordDateTime = DateUtil
.convertDateWithMillisecondsToSolrDate(keywordLogDate);
queryGenerator.setSingleRangeFilter(rangeLogQuery,
LogSearchConstants.LOGTIME, keywordDateTime,
@@ -784,7 +783,7 @@ public class LogsMgr extends MgrBase {
.commonServiceFilterQuery(searchCriteria);
queryGenerator.setSingleIncludeFilter(sameIdQuery,
LogSearchConstants.LOGTIME, "\"" + originalKeywordDate + "\"");
- queryGenerator.setFl(sameIdQuery, LogSearchConstants.ID);
+ SolrUtil.setFl(sameIdQuery, LogSearchConstants.ID);
SolrDocumentList sameQueryDocList = serviceLogsSolrDao.process(sameIdQuery)
.getResults();
for (SolrDocument solrDocumenent : sameQueryDocList) {
@@ -819,7 +818,7 @@ public class LogsMgr extends MgrBase {
int maxRows = searchCriteria.getMaxRows();
if (currentPageNumber == 0) {
- throw restErrorUtil.createRESTException("This is first Page Not",
+ throw RESTErrorUtil.createRESTException("This is first Page Not",
MessageEnums.DATA_NOT_FOUND);
}
@@ -838,20 +837,20 @@ public class LogsMgr extends MgrBase {
queryResponse = serviceLogsSolrDao.process(
lastLogTime);
if(queryResponse == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
SolrDocumentList docList = queryResponse.getResults();
if(docList ==null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
SolrDocument solrDoc = docList.get(0);
Date logDate = (Date) solrDoc.get(LogSearchConstants.LOGTIME);
String sortByType = searchCriteria.getSortType();
- lastLogsLogTime = dateUtil
+ lastLogsLogTime = DateUtil
.convertDateWithMillisecondsToSolrDate(logDate);
String lastLogsLogId = ""
+ solrDoc.get(LogSearchConstants.ID);
@@ -867,17 +866,17 @@ public class LogsMgr extends MgrBase {
LogSearchConstants.LOGTIME, "\"" + lastLogsLogTime + "\"");
queryGenerator.setSingleExcludeFilter(listRemoveIds,
LogSearchConstants.ID, lastLogsLogId);
- queryGenerator.setFl(listRemoveIds, LogSearchConstants.ID);
+ SolrUtil.setFl(listRemoveIds, LogSearchConstants.ID);
queryResponse = serviceLogsSolrDao.process(
lastLogTime);
if(queryResponse == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
SolrDocumentList docListIds = queryResponse.getResults();
if(docListIds == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
boolean isFirst = true;
@@ -942,13 +941,13 @@ public class LogsMgr extends MgrBase {
queryResponse = serviceLogsSolrDao.process(
logTimeThroughRangeQuery);
if(queryResponse == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
SolrDocumentList documentList = queryResponse.getResults();
if(documentList == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
SolrDocument solrDocument = new SolrDocument();
@@ -958,10 +957,10 @@ public class LogsMgr extends MgrBase {
Date keywordLogDate = (Date) solrDocument.get(LogSearchConstants.LOGTIME);
if(keywordLogDate == null){
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
- String originalKeywordDate = dateUtil
+ String originalKeywordDate = DateUtil
.convertDateWithMillisecondsToSolrDate(keywordLogDate);
String keywordId = "" + solrDocument.get(LogSearchConstants.ID);
@@ -972,8 +971,8 @@ public class LogsMgr extends MgrBase {
if (!StringUtils.isBlank(sortByType) && sortByType
.equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) {
- // keywordLogDate = dateUtil.addMilliSecondsToDate(keywordLogDate, 1);
- String keywordDateTime = dateUtil
+ // keywordLogDate = DateUtil.addMilliSecondsToDate(keywordLogDate, 1);
+ String keywordDateTime = DateUtil
.convertDateWithMillisecondsToSolrDate(keywordLogDate);
queryGenerator.setSingleRangeFilter(rangeLogQuery,
LogSearchConstants.LOGTIME, startTime,
@@ -981,8 +980,8 @@ public class LogsMgr extends MgrBase {
} else {
- // keywordLogDate = dateUtil.addMilliSecondsToDate(keywordLogDate, -1);
- String keywordDateTime = dateUtil
+ // keywordLogDate = DateUtil.addMilliSecondsToDate(keywordLogDate, -1);
+ String keywordDateTime = DateUtil
.convertDateWithMillisecondsToSolrDate(keywordLogDate);
queryGenerator.setSingleRangeFilter(rangeLogQuery,
LogSearchConstants.LOGTIME, keywordDateTime,
@@ -998,7 +997,7 @@ public class LogsMgr extends MgrBase {
.commonServiceFilterQuery(searchCriteria);
queryGenerator.setSingleIncludeFilter(sameIdQuery,
LogSearchConstants.LOGTIME, "\"" + originalKeywordDate + "\"");
- queryGenerator.setFl(sameIdQuery, LogSearchConstants.ID);
+ SolrUtil.setFl(sameIdQuery, LogSearchConstants.ID);
SolrDocumentList sameQueryDocList = serviceLogsSolrDao.process(sameIdQuery)
.getResults();
for (SolrDocument solrDocumenent : sameQueryDocList) {
@@ -1028,7 +1027,7 @@ public class LogsMgr extends MgrBase {
}
}
- throw restErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
+ throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found",
MessageEnums.ERROR_SYSTEM);
}
@@ -1051,10 +1050,10 @@ public class LogsMgr extends MgrBase {
try {
SolrQuery logTimeByIdQuery = new SolrQuery();
- queryGenerator.setMainQuery(logTimeByIdQuery, null);
+ SolrUtil.setMainQuery(logTimeByIdQuery, null);
queryGenerator.setSingleIncludeFilter(logTimeByIdQuery,
LogSearchConstants.ID, logId);
- queryGenerator.setRowCount(solrQuery, 1);
+ SolrUtil.setRowCount(solrQuery, 1);
QueryResponse queryResponse = serviceLogsSolrDao
.process(logTimeByIdQuery);
@@ -1073,9 +1072,9 @@ public class LogsMgr extends MgrBase {
}
if (dateOfLogId != null) {
- logTime = dateUtil.convertDateWithMillisecondsToSolrDate(dateOfLogId);
+ logTime = DateUtil.convertDateWithMillisecondsToSolrDate(dateOfLogId);
Date endDate = DateUtils.addMilliseconds(dateOfLogId, 1);
- endTimeMinusOneMilli = (String) dateUtil
+ endTimeMinusOneMilli = (String) DateUtil
.convertDateWithMillisecondsToSolrDate(endDate);
}
@@ -1088,7 +1087,7 @@ public class LogsMgr extends MgrBase {
solrQuery.remove(LogSearchConstants.LOGTIME);
queryGenerator.setSingleRangeFilter(solrQuery,
LogSearchConstants.LOGTIME, endTimeMinusOneMilli, endLogTime);
- queryGenerator.setRowCount(solrQuery, 0);
+ SolrUtil.setRowCount(solrQuery, 0);
startIndex = countQuery(solrQuery,serviceLogsSolrDao);
} catch (SolrException | SolrServerException | IOException e) {
logger.error(e);
@@ -1128,7 +1127,7 @@ public class LogsMgr extends MgrBase {
logger.error(e);
}
- throw restErrorUtil.createRESTException("LogId not Found",
+ throw RESTErrorUtil.createRESTException("LogId not Found",
MessageEnums.ERROR_SYSTEM);
}
@@ -1138,7 +1137,7 @@ public class LogsMgr extends MgrBase {
List<VNameValue> logsCounts = new ArrayList<VNameValue>();
try {
- queryGenerator.setFacetRange(solrQuery, LogSearchConstants.LOGTIME,
+ SolrUtil.setFacetRange(solrQuery, LogSearchConstants.LOGTIME,
from, to, unit);
List<RangeFacet.Count> logLevelCounts = null;
@@ -1205,8 +1204,8 @@ public class LogsMgr extends MgrBase {
"\\", "");
try {
- queryGenerator.setJSONFacet(solrQuery, jsonHistogramQuery);
- queryGenerator.setRowCount(solrQuery,Integer.parseInt(deafalutValue));
+ SolrUtil.setJSONFacet(solrQuery, jsonHistogramQuery);
+ SolrUtil.setRowCount(solrQuery,Integer.parseInt(deafalutValue));
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
if (response == null){
return convertObjToString(dataList);
@@ -1259,7 +1258,7 @@ public class LogsMgr extends MgrBase {
} catch (SolrServerException | SolrException | IOException e) {
logger.error(e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
@@ -1278,7 +1277,7 @@ public class LogsMgr extends MgrBase {
public String cancelFindRequestByDate(String uniqueId) {
if (StringUtils.isEmpty(uniqueId)) {
logger.error("Unique id is Empty");
- throw restErrorUtil.createRESTException("Unique id is Empty",
+ throw RESTErrorUtil.createRESTException("Unique id is Empty",
MessageEnums.DATA_NOT_FOUND);
}
@@ -1292,7 +1291,7 @@ public class LogsMgr extends MgrBase {
public boolean cancelRequest(String uniqueId) {
if (StringUtils.isBlank(uniqueId)) {
logger.error("Unique id is Empty");
- throw restErrorUtil.createRESTException("Unique id is Empty",
+ throw RESTErrorUtil.createRESTException("Unique id is Empty",
MessageEnums.DATA_NOT_FOUND);
}
for (String date : cancelByDate) {
@@ -1318,10 +1317,10 @@ public class LogsMgr extends MgrBase {
utcOffset = "0";
}
- if (!dateUtil.isDateValid(from) || !dateUtil.isDateValid(to)) {
+ if (!DateUtil.isDateValid(from) || !DateUtil.isDateValid(to)) {
logger.error("Not valid date format. Valid format should be"
+ LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z);
- throw restErrorUtil.createRESTException("Not valid date format. Valid format should be"
+ throw RESTErrorUtil.createRESTException("Not valid date format. Valid format should be"
+ LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z,
MessageEnums.INVALID_INPUT_DATA);
@@ -1332,13 +1331,13 @@ public class LogsMgr extends MgrBase {
to = to.replace("T", " ");
to = to.replace(".", ",");
- to = dateUtil.addOffsetToDate(to, Long.parseLong(utcOffset),
+ to = DateUtil.addOffsetToDate(to, Long.parseLong(utcOffset),
"yyyy-MM-dd HH:mm:ss,SSS");
- from = dateUtil.addOffsetToDate(from, Long.parseLong(utcOffset),
+ from = DateUtil.addOffsetToDate(from, Long.parseLong(utcOffset),
"yyyy-MM-dd HH:mm:ss,SSS");
}
- String fileName = dateUtil.getCurrentDateInString();
+ String fileName = DateUtil.getCurrentDateInString();
if (searchCriteria.getParamValue("hostLogFile") != null
&& searchCriteria.getParamValue("compLogFile") != null) {
fileName = searchCriteria.getParamValue("hostLogFile") + "_"
@@ -1349,16 +1348,16 @@ public class LogsMgr extends MgrBase {
try {
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
if (response == null) {
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
SolrDocumentList docList = response.getResults();
if (docList == null) {
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
- VSummary vsummary = bizUtil.buildSummaryForLogFile(docList);
+ VSummary vsummary = BizUtil.buildSummaryForLogFile(docList);
vsummary.setFormat(format);
vsummary.setFrom(from);
vsummary.setTo(to);
@@ -1421,7 +1420,7 @@ public class LogsMgr extends MgrBase {
Date logTimeDateObj = (Date) solrDoc.get(LogSearchConstants.LOGTIME);
if(logTimeDateObj != null){
- String logTime = dateUtil.convertSolrDateToNormalDateFormat(
+ String logTime = DateUtil.convertSolrDateToNormalDateFormat(
logTimeDateObj.getTime(), Long.parseLong(utcOffset));
solrDoc.remove(LogSearchConstants.LOGTIME);
solrDoc.addField(LogSearchConstants.LOGTIME, logTime);
@@ -1429,20 +1428,20 @@ public class LogsMgr extends MgrBase {
}
if (format.toLowerCase(Locale.ENGLISH).equals(".txt")) {
- textToSave = bizUtil.convertObjectToNormalText(docList);
+ textToSave = BizUtil.convertObjectToNormalText(docList);
} else if (format.toLowerCase(Locale.ENGLISH).equals(".json")) {
textToSave = convertObjToString(docList);
} else {
- throw restErrorUtil.createRESTException(
+ throw RESTErrorUtil.createRESTException(
"unsoported format either should be json or text",
MessageEnums.ERROR_SYSTEM);
}
- return fileUtil.saveToFile(textToSave, fileName, vsummary);
+ return FileUtil.saveToFile(textToSave, fileName, vsummary);
} catch (SolrException | SolrServerException | IOException
| ParseException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -1460,7 +1459,7 @@ public class LogsMgr extends MgrBase {
VNodeList list = new VNodeList();
try {
- queryGenerator.setFacetPivot(solrQuery, 1, componentLevelHirachy);
+ SolrUtil.setFacetPivot(solrQuery, 1, componentLevelHirachy);
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
@@ -1498,7 +1497,7 @@ public class LogsMgr extends MgrBase {
return convertObjToString(list);
} catch (SolrException | SolrServerException | IOException e) {
logger.error(e.getMessage() + "SolrQuery"+solrQuery);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -1516,9 +1515,9 @@ public class LogsMgr extends MgrBase {
queryGenerator.setSingleIncludeFilter(solrQuery,
LogSearchConstants.BUNDLE_ID, bundelId);
- queryGenerator.setMainQuery(solrQuery, null);
+ SolrUtil.setMainQuery(solrQuery, null);
solrQuery.setSort(LogSearchConstants.LOGTIME, SolrQuery.ORDER.asc);
- queryGenerator.setRowCount(solrQuery, 1);
+ SolrUtil.setRowCount(solrQuery, 1);
List<VNameValue> vNameValues = new ArrayList<VNameValue>();
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
@@ -1544,11 +1543,11 @@ public class LogsMgr extends MgrBase {
}
solrQuery.clear();
- queryGenerator.setMainQuery(solrQuery, null);
+ SolrUtil.setMainQuery(solrQuery, null);
queryGenerator.setSingleIncludeFilter(solrQuery,
LogSearchConstants.BUNDLE_ID, bundelId);
solrQuery.setSort(LogSearchConstants.LOGTIME, SolrQuery.ORDER.desc);
- queryGenerator.setRowCount(solrQuery, 1);
+ SolrUtil.setRowCount(solrQuery, 1);
solrDocList.clear();
response = serviceLogsSolrDao.process(solrQuery);
@@ -1595,14 +1594,14 @@ public class LogsMgr extends MgrBase {
}
public String getServiceLogsFieldsName() {
- String fieldsNameStrArry[] = PropertiesUtil
+ String fieldsNameStrArry[] = PropertiesHelper
.getPropertyStringList("logsearch.service.logs.fields");
if (fieldsNameStrArry.length > 0) {
List<String> uiFieldNames = new ArrayList<String>();
String temp = null;
for (String field : fieldsNameStrArry) {
- temp = ConfigUtil.serviceLogsColumnMapping.get(field
+ temp = ConfigHelper.serviceLogsColumnMapping.get(field
+ LogSearchConstants.SOLR_SUFFIX);
if (temp == null){
uiFieldNames.add(field);
@@ -1613,7 +1612,7 @@ public class LogsMgr extends MgrBase {
return convertObjToString(uiFieldNames);
}
- throw restErrorUtil.createRESTException(
+ throw RESTErrorUtil.createRESTException(
"No field name found in property file",
MessageEnums.DATA_NOT_FOUND);
@@ -1622,14 +1621,14 @@ public class LogsMgr extends MgrBase {
public String getServiceLogsSchemaFieldsName() {
List<String> fieldNames = new ArrayList<String>();
- String excludeArray[] = PropertiesUtil
+ String excludeArray[] = PropertiesHelper
.getPropertyStringList("logsearch.solr.service.logs.exclude.columnlist");
HashMap<String, String> uiFieldColumnMapping = new LinkedHashMap<String, String>();
- ConfigUtil.getSchemaFieldsName(excludeArray, fieldNames,serviceLogsSolrDao);
+ ConfigHelper.getSchemaFieldsName(excludeArray, fieldNames,serviceLogsSolrDao);
for (String fieldName : fieldNames) {
- String uiField = ConfigUtil.serviceLogsColumnMapping.get(fieldName
+ String uiField = ConfigHelper.serviceLogsColumnMapping.get(fieldName
+ LogSearchConstants.SOLR_SUFFIX);
if (uiField != null) {
uiFieldColumnMapping.put(fieldName, uiField);
@@ -1641,7 +1640,7 @@ public class LogsMgr extends MgrBase {
HashMap<String, String> uiFieldColumnMappingSorted = new LinkedHashMap<String, String>();
uiFieldColumnMappingSorted.put(LogSearchConstants.SOLR_LOG_MESSAGE, LogSearchConstants.SOLR_LOG_MESSAGE);
- Iterator<Entry<String, String>> it = bizUtil
+ Iterator<Entry<String, String>> it = BizUtil
.sortHashMapByValues(uiFieldColumnMapping).entrySet().iterator();
while (it.hasNext()) {
@SuppressWarnings("rawtypes")
@@ -1674,7 +1673,7 @@ public class LogsMgr extends MgrBase {
.get(innerField)).get("buckets");
for (Object temp1 : levelBuckets) {
SimpleOrderedMap<Object> countValue = (SimpleOrderedMap<Object>) temp1;
- String value = dateUtil
+ String value = DateUtil
.convertDateWithMillisecondsToSolrDate((Date) countValue
.getVal(0));
@@ -1724,9 +1723,9 @@ public class LogsMgr extends MgrBase {
String sequenceId = null;
try {
SolrQuery solrQuery = new SolrQuery();
- queryGenerator.setMainQuery(solrQuery,
+ SolrUtil.setMainQuery(solrQuery,
queryGenerator.buildFilterQuery(LogSearchConstants.ID, id));
- queryGenerator.setRowCount(solrQuery, 1);
+ SolrUtil.setRowCount(solrQuery, 1);
QueryResponse response = serviceLogsSolrDao.process(solrQuery);
if(response == null){
return convertObjToString(vSolrLogList);
@@ -1735,7 +1734,7 @@ public class LogsMgr extends MgrBase {
if (docList != null && !docList.isEmpty()) {
Date date = (Date) docList.get(0).getFieldValue(
LogSearchConstants.LOGTIME);
- logTime = dateUtil.convertDateWithMillisecondsToSolrDate(date);
+ logTime = DateUtil.convertDateWithMillisecondsToSolrDate(date);
sequenceId = ""
+ docList.get(0).getFieldValue(
LogSearchConstants.SEQUNCE_ID);
@@ -1744,7 +1743,7 @@ public class LogsMgr extends MgrBase {
return convertObjToString(vSolrLogList);
}
} catch (SolrServerException | SolrException | IOException e) {
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
if (LogSearchConstants.SCROLL_TYPE_BEFORE.equals(scrollType)) {
@@ -1798,7 +1797,7 @@ public class LogsMgr extends MgrBase {
private VSolrLogList whenScrollUp(SearchCriteria searchCriteria,
String logTime, String sequenceId, String maxRows) {
SolrQuery solrQuery = new SolrQuery();
- queryGenerator.setMainQuery(solrQuery, null);
+ SolrUtil.setMainQuery(solrQuery, null);
/*queryGenerator.setSingleExcludeFilter(solrQuery,
LogSearchConstants.SEQUNCE_ID, sequenceId);*/
try {
@@ -1815,7 +1814,7 @@ public class LogsMgr extends MgrBase {
queryGenerator.setSingleRangeFilter(solrQuery,
LogSearchConstants.LOGTIME, "*", logTime);
- queryGenerator.setRowCount(solrQuery, Integer.parseInt(maxRows));
+ SolrUtil.setRowCount(solrQuery, Integer.parseInt(maxRows));
String order1 = LogSearchConstants.LOGTIME + " "
+ LogSearchConstants.DESCENDING_ORDER;
String order2 = LogSearchConstants.SEQUNCE_ID + " "
@@ -1832,7 +1831,7 @@ public class LogsMgr extends MgrBase {
private VSolrLogList whenScrollDown(SearchCriteria searchCriteria,
String logTime, String sequenceId, String maxRows) {
SolrQuery solrQuery = new SolrQuery();
- queryGenerator.setMainQuery(solrQuery, null);
+ SolrUtil.setMainQuery(solrQuery, null);
queryGenerator.applyLogFileFilter(solrQuery, searchCriteria);
/*queryGenerator.setSingleExcludeFilter(solrQuery,
@@ -1848,7 +1847,7 @@ public class LogsMgr extends MgrBase {
LogSearchConstants.SEQUNCE_ID, sequenceId, "*");
queryGenerator.setSingleRangeFilter(solrQuery,
LogSearchConstants.LOGTIME, logTime, "*");
- queryGenerator.setRowCount(solrQuery, Integer.parseInt(maxRows));
+ SolrUtil.setRowCount(solrQuery, Integer.parseInt(maxRows));
String order1 = LogSearchConstants.LOGTIME + " "
+ LogSearchConstants.ASCENDING_ORDER;
@@ -1874,13 +1873,13 @@ public class LogsMgr extends MgrBase {
utc.set(Calendar.MINUTE, 0);
utc.set(Calendar.MILLISECOND, 001);
utc.set(Calendar.SECOND, 0);
- dateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime());
- String from = dateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime());
+ DateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime());
+ String from = DateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime());
utc.set(Calendar.MILLISECOND, 999);
utc.set(Calendar.SECOND, 59);
utc.set(Calendar.MINUTE, 59);
utc.set(Calendar.HOUR, 23);
- String to = dateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime());
+ String to = DateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime());
queryGenerator.setSingleRangeFilter(solrQuery,
LogSearchConstants.LOGTIME, from,to);
String level = LogSearchConstants.FATAL+","+LogSearchConstants.ERROR+","+LogSearchConstants.WARN;
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/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 02e2e69..c0be79d 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
@@ -60,20 +60,8 @@ public class MgrBase {
private static final Logger logger = Logger.getLogger(MgrBase.class);
@Autowired
- protected SolrUtil solrUtil;
-
- @Autowired
- protected JSONUtil jsonUtil;
-
- @Autowired
protected QueryGeneration queryGenerator;
- @Autowired
- protected RESTErrorUtil restErrorUtil;
-
- @Autowired
- protected DateUtil dateUtil;
-
private JsonSerializer<Date> jsonDateSerialiazer = null;
private JsonDeserializer<Date> jsonDateDeserialiazer = null;
@@ -142,14 +130,14 @@ public class MgrBase {
} catch (IOException e) {
logger.error("Unable to read HadoopServiceConfig.json", e);
- throw restErrorUtil.createRESTException(e.getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw RESTErrorUtil.createRESTException(e.getMessage(), 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);
+ throw RESTErrorUtil.createRESTException("Improper JSON", MessageEnums.ERROR_SYSTEM);
}
@@ -174,8 +162,8 @@ public class MgrBase {
int numberOfLogsOnLastPage = 0;
VSolrLogList collection = null;
try {
- queryGenerator.setStart(lastPageQuery, 0);
- queryGenerator.setRowCount(lastPageQuery, maxRows);
+ SolrUtil.setStart(lastPageQuery, 0);
+ SolrUtil.setRowCount(lastPageQuery, maxRows);
collection = getLogAsPaginationProvided(lastPageQuery, solrDoaBase);
totalLogs = countQuery(lastPageQuery,solrDoaBase);
if(maxRows != null){
@@ -199,7 +187,7 @@ public class MgrBase {
} catch (SolrException | SolrServerException | IOException | NumberFormatException e) {
logger.error("Count Query was not executed successfully",e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
return collection;
}
@@ -223,7 +211,7 @@ public class MgrBase {
return collection;
} 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);
}
}
@@ -249,9 +237,9 @@ public class MgrBase {
protected String getFrom(String from) {
if (StringUtils.isBlank(from)) {
- Date date = dateUtil.getTodayFromDate();
+ Date date = DateUtil.getTodayFromDate();
try {
- from = dateUtil.convertGivenDateFormatToSolrDateFormat(date);
+ from = DateUtil.convertGivenDateFormatToSolrDateFormat(date);
} catch (ParseException e) {
from = "NOW";
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/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 28f806c..59c1bbd 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
@@ -29,6 +29,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.JSONUtil;
import org.apache.ambari.logsearch.util.RESTErrorUtil;
import org.apache.ambari.logsearch.util.SolrUtil;
import org.apache.ambari.logsearch.view.VLogfeederFilterWrapper;
@@ -55,21 +56,17 @@ public class UserConfigMgr extends MgrBase {
@Autowired
private UserConfigSolrDao userConfigSolrDao;
@Autowired
- private SolrUtil solrUtil;
- @Autowired
- private RESTErrorUtil restErrorUtil;
- @Autowired
private QueryGeneration queryGenerator;
public String saveUserConfig(VUserConfig vHistory) {
SolrInputDocument solrInputDoc = new SolrInputDocument();
if (!isValid(vHistory)) {
- throw restErrorUtil.createRESTException("No FilterName Specified", MessageEnums.INVALID_INPUT_DATA);
+ throw RESTErrorUtil.createRESTException("No FilterName Specified", MessageEnums.INVALID_INPUT_DATA);
}
if (isNotUnique(vHistory) && !vHistory.isOverwrite()) {
- throw restErrorUtil.createRESTException( "Name '" + vHistory.getFiltername() + "' already exists", MessageEnums.INVALID_INPUT_DATA);
+ throw RESTErrorUtil.createRESTException( "Name '" + vHistory.getFiltername() + "' already exists", MessageEnums.INVALID_INPUT_DATA);
}
String loggedInUserName = vHistory.getUserName();
String filterName = vHistory.getFiltername();
@@ -85,8 +82,8 @@ public class UserConfigMgr extends MgrBase {
}
// Check whether the Filter Name exists in solr
SolrQuery solrQuery = new SolrQuery();
- queryGenerator.setMainQuery(solrQuery, null);
- queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.FILTER_NAME, solrUtil.makeSearcableString(filterName));
+ SolrUtil.setMainQuery(solrQuery, null);
+ queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.FILTER_NAME, SolrUtil.makeSearcableString(filterName));
queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.USER_NAME, loggedInUserName);
try {
QueryResponse queryResponse = userConfigSolrDao.process(solrQuery);
@@ -94,12 +91,12 @@ public class UserConfigMgr extends MgrBase {
SolrDocumentList documentList = queryResponse.getResults();
if (documentList != null && !documentList.isEmpty() && !vHistory.isOverwrite()) {
logger.error("Filtername is already present");
- throw restErrorUtil.createRESTException("Filtername is already present", MessageEnums.INVALID_INPUT_DATA);
+ throw RESTErrorUtil.createRESTException("Filtername is already present", MessageEnums.INVALID_INPUT_DATA);
}
}
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error in checking same filtername config", e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
try {
@@ -107,7 +104,7 @@ public class UserConfigMgr extends MgrBase {
return convertObjToString(solrInputDoc);
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error saving user config. solrDoc=" + solrInputDoc, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -117,9 +114,9 @@ public class UserConfigMgr extends MgrBase {
if (filterName != null && rowType != null) {
SolrQuery solrQuery = new SolrQuery();
- filterName = solrUtil.makeSearcableString(filterName);
+ filterName = SolrUtil.makeSearcableString(filterName);
solrQuery.setQuery(LogSearchConstants.COMPOSITE_KEY + ":" + filterName + "-" + rowType);
- queryGenerator.setRowCount(solrQuery, 0);
+ SolrUtil.setRowCount(solrQuery, 0);
try {
Long numFound = userConfigSolrDao.process(solrQuery).getResults().getNumFound();
if (numFound > 0) {
@@ -143,7 +140,7 @@ public class UserConfigMgr extends MgrBase {
try {
userConfigSolrDao.deleteUserConfig(id);
} catch (SolrException | SolrServerException | IOException e) {
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -155,12 +152,12 @@ public class UserConfigMgr extends MgrBase {
String rowType = (String) searchCriteria.getParamValue(LogSearchConstants.ROW_TYPE);
if (StringUtils.isBlank(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);
if (StringUtils.isBlank(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 = StringUtils.isBlank(filterName) ? "*" : "*" + filterName + "*";
@@ -168,11 +165,11 @@ public class UserConfigMgr extends MgrBase {
try {
SolrQuery userConfigQuery = new SolrQuery();
- queryGenerator.setMainQuery(userConfigQuery, null);
+ SolrUtil.setMainQuery(userConfigQuery, null);
queryGenerator.setPagination(userConfigQuery, searchCriteria);
queryGenerator.setSingleIncludeFilter(userConfigQuery, LogSearchConstants.ROW_TYPE, rowType);
queryGenerator.setSingleORFilter(userConfigQuery, LogSearchConstants.USER_NAME, userName, LogSearchConstants.SHARE_NAME_LIST, userName);
- queryGenerator.setSingleIncludeFilter(userConfigQuery, LogSearchConstants.FILTER_NAME, solrUtil.makeSearcableString(filterName));
+ queryGenerator.setSingleIncludeFilter(userConfigQuery, LogSearchConstants.FILTER_NAME, SolrUtil.makeSearcableString(filterName));
if (StringUtils.isBlank(searchCriteria.getSortBy())) {
searchCriteria.setSortBy(LogSearchConstants.FILTER_NAME);
@@ -214,7 +211,7 @@ public class UserConfigMgr extends MgrBase {
} catch (SolrException | SolrServerException | IOException e) {
// do nothing
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);
}
return convertObjToString(userConfigList);
@@ -233,14 +230,14 @@ public class UserConfigMgr extends MgrBase {
userFilter = userConfigSolrDao.getUserFilter();
} catch (SolrServerException | 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);
}
return convertObjToString(userFilter);
}
public String saveUserFiter(String json) {
if (!StringUtils.isBlank(json)) {
- VLogfeederFilterWrapper logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil.jsonToObj(json, VLogfeederFilterWrapper.class);
+ VLogfeederFilterWrapper logfeederFilterWrapper = (VLogfeederFilterWrapper) JSONUtil.jsonToObj(json, VLogfeederFilterWrapper.class);
try {
if (logfeederFilterWrapper == null) {
logger.error(json + " is a invalid json");
@@ -248,7 +245,7 @@ public class UserConfigMgr extends MgrBase {
userConfigSolrDao.saveUserFilter(logfeederFilterWrapper);
} catch (SolrException | SolrServerException | IOException e) {
logger.error("user config not able to save", e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
return getUserFilter();
@@ -258,8 +255,8 @@ public class UserConfigMgr extends MgrBase {
List<String> userList = new ArrayList<String>();
try {
SolrQuery userListQuery = new SolrQuery();
- queryGenerator.setMainQuery(userListQuery, null);
- queryGenerator.setFacetField(userListQuery, LogSearchConstants.USER_NAME);
+ SolrUtil.setMainQuery(userListQuery, null);
+ SolrUtil.setFacetField(userListQuery, LogSearchConstants.USER_NAME);
QueryResponse queryResponse = userConfigSolrDao.process(userListQuery);
if (queryResponse == null) {
return convertObjToString(userList);
@@ -271,7 +268,7 @@ public class UserConfigMgr extends MgrBase {
}
} catch (SolrException | SolrServerException | IOException e) {
logger.warn("Error getting all users.", e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
return convertObjToString(userList);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/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 0c8be45..16cf932 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
@@ -25,12 +25,14 @@ import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
+import org.apache.ambari.logsearch.common.ConfigHelper;
import org.apache.ambari.logsearch.common.LogSearchConstants;
+import org.apache.ambari.logsearch.common.PropertiesHelper;
import org.apache.ambari.logsearch.common.SearchCriteria;
import org.apache.ambari.logsearch.dao.SolrDaoBase;
import org.apache.ambari.logsearch.manager.MgrBase.LogType;
-import org.apache.ambari.logsearch.util.ConfigUtil;
-import org.apache.ambari.logsearch.util.PropertiesUtil;
+import org.apache.ambari.logsearch.util.JSONUtil;
+import org.apache.ambari.logsearch.util.SolrUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.lucene.analysis.core.KeywordTokenizerFactory;
@@ -87,7 +89,7 @@ public class QueryGeneration extends QueryGenerationBase {
return advSolrQuery;
}
- setMainQuery(solrQuery, givenQuery);
+ SolrUtil.setMainQuery(solrQuery, givenQuery);
setSingleRangeFilter(solrQuery, LogSearchConstants.LOGTIME, startTime, endTime);
addFilter(solrQuery, selectedComp, LogSearchConstants.SOLR_COMPONENT, Condition.OR);
@@ -104,15 +106,15 @@ public class QueryGeneration extends QueryGenerationBase {
setFilterClauseWithFieldName(solrQuery, globalExcludeComp, LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR, Condition.AND);
setFilterClauseWithFieldName(solrQuery, unselectedComp, LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR, Condition.AND);
- urlHostName = solrUtil.escapeQueryChars(urlHostName);
+ urlHostName = SolrUtil.escapeQueryChars(urlHostName);
setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_HOST, urlHostName);
- urlComponentName = solrUtil.escapeQueryChars(urlComponentName);
+ urlComponentName = SolrUtil.escapeQueryChars(urlComponentName);
setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_COMPONENT, urlComponentName);
setPagination(solrQuery, searchCriteria);
setSortOrderDefaultServiceLog(solrQuery, searchCriteria);
setSingleIncludeFilter(solrQuery, LogSearchConstants.BUNDLE_ID, bundleId);
- file_name = solrUtil.escapeQueryChars(file_name);
+ file_name = SolrUtil.escapeQueryChars(file_name);
setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_PATH, file_name);
setUserSpecificFilter(searchCriteria, solrQuery, LogSearchConstants.INCLUDE_QUERY, LogSearchConstants.INCLUDE_QUERY, logType);
setUserSpecificFilter(searchCriteria, solrQuery, LogSearchConstants.EXCLUDE_QUERY, LogSearchConstants.EXCLUDE_QUERY, logType);
@@ -150,10 +152,10 @@ public class QueryGeneration extends QueryGenerationBase {
List<String> conditionQuries = new ArrayList<String>();
List<String> referalConditionQuries = new ArrayList<String>();
List<String> elments = new ArrayList<String>();
- List<HashMap<String, Object>> queryList = jsonUtil.jsonToMapObjectList(queryString);
+ List<HashMap<String, Object>> queryList = JSONUtil.jsonToMapObjectList(queryString);
if (queryList != null && queryList.size() > 0) {
if (!StringUtils.isBlank(columnQuery) && !columnQuery.equals(queryString) && !paramName.equals(LogSearchConstants.EXCLUDE_QUERY)) {
- List<HashMap<String, Object>> columnQueryList = jsonUtil.jsonToMapObjectList(columnQuery);
+ List<HashMap<String, Object>> columnQueryList = JSONUtil.jsonToMapObjectList(columnQuery);
if (columnQueryList != null && columnQueryList.size() > 0) {
queryList.addAll(columnQueryList);
}
@@ -255,7 +257,7 @@ public class QueryGeneration extends QueryGenerationBase {
fieldType = serviceLogsSolrDao.schemaFieldsNameMap.get(key);
solrDaoBase = serviceLogsSolrDao;
if (key.equalsIgnoreCase(LogSearchConstants.SOLR_LOG_MESSAGE)) {
- return solrUtil.escapeForLogMessage(key, str);
+ return SolrUtil.escapeForLogMessage(key, str);
}
break;
default:
@@ -264,7 +266,7 @@ public class QueryGeneration extends QueryGenerationBase {
fieldType = null;
}
if (!StringUtils.isBlank(fieldType)) {
- if (solrUtil.isSolrFieldNumber(fieldType, solrDaoBase)) {
+ if (SolrUtil.isSolrFieldNumber(fieldType, solrDaoBase)) {
String value = putEscapeCharacterForNumber(str, fieldType,solrDaoBase);
if (!StringUtils.isBlank(value)) {
return key + ":" + value;
@@ -272,9 +274,9 @@ public class QueryGeneration extends QueryGenerationBase {
return null;
}
} else if (checkTokenizer(fieldType, StandardTokenizerFactory.class,solrDaoBase)) {
- return key + ":" + solrUtil.escapeForStandardTokenizer(str);
+ return key + ":" + SolrUtil.escapeForStandardTokenizer(str);
} else if (checkTokenizer(fieldType, KeywordTokenizerFactory.class,solrDaoBase)|| "string".equalsIgnoreCase(fieldType)) {
- return key + ":" + solrUtil.makeSolrSearchStringWithoutAsterisk(str);
+ return key + ":" + SolrUtil.makeSolrSearchStringWithoutAsterisk(str);
} else if (checkTokenizer(fieldType, PathHierarchyTokenizerFactory.class,solrDaoBase)) {
return key + ":" + str;
}
@@ -296,7 +298,7 @@ public class QueryGeneration extends QueryGenerationBase {
private String parseInputValueAsPerFieldType(String str,String fieldType,SolrDaoBase solrDaoBase ) {
try {
- HashMap<String, Object> fieldTypeInfoMap= solrUtil.getFieldTypeInfoMap(fieldType,solrDaoBase);
+ HashMap<String, Object> fieldTypeInfoMap= SolrUtil.getFieldTypeInfoMap(fieldType,solrDaoBase);
String className = (String) fieldTypeInfoMap.get("class");
if( className.equalsIgnoreCase(TrieDoubleField.class.getSimpleName())){
return ""+ Double.parseDouble(str);
@@ -314,7 +316,7 @@ public class QueryGeneration extends QueryGenerationBase {
}
private String getOriginalValue(String name, String value) {
- String solrValue = PropertiesUtil.getProperty(name);
+ String solrValue = PropertiesHelper.getProperty(name);
if (StringUtils.isBlank(solrValue)) {
return value;
}
@@ -347,10 +349,10 @@ public class QueryGeneration extends QueryGenerationBase {
String originalKey;
switch (logType) {
case AUDIT:
- originalKey = ConfigUtil.auditLogsColumnMapping.get(key + LogSearchConstants.UI_SUFFIX);
+ originalKey = ConfigHelper.auditLogsColumnMapping.get(key + LogSearchConstants.UI_SUFFIX);
break;
case SERVICE:
- originalKey = ConfigUtil.serviceLogsColumnMapping.get(key + LogSearchConstants.UI_SUFFIX);
+ originalKey = ConfigHelper.serviceLogsColumnMapping.get(key + LogSearchConstants.UI_SUFFIX);
break;
default:
originalKey = null;
@@ -362,7 +364,7 @@ public class QueryGeneration extends QueryGenerationBase {
}
private boolean checkTokenizer(String fieldType, Class tokenizerFactoryClass, SolrDaoBase solrDaoBase) {
- HashMap<String, Object> fieldTypeMap = solrUtil.getFieldTypeInfoMap(fieldType,solrDaoBase);
+ HashMap<String, Object> fieldTypeMap = SolrUtil.getFieldTypeInfoMap(fieldType,solrDaoBase);
HashMap<String, Object> analyzer = (HashMap<String, Object>) fieldTypeMap.get("analyzer");
if (analyzer != null) {
HashMap<String, Object> tokenizerMap = (HashMap<String, Object>) analyzer.get("tokenizer");
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/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 ca6df65..77d4969 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
@@ -26,8 +26,6 @@ import org.apache.ambari.logsearch.common.LogSearchConstants;
import org.apache.ambari.logsearch.common.SearchCriteria;
import org.apache.ambari.logsearch.dao.AuditSolrDao;
import org.apache.ambari.logsearch.dao.ServiceLogsSolrDao;
-import org.apache.ambari.logsearch.util.JSONUtil;
-import org.apache.ambari.logsearch.util.QueryBase;
import org.apache.ambari.logsearch.util.SolrUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@@ -37,21 +35,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.Gson;
-public abstract class QueryGenerationBase extends QueryBase {
+public abstract class QueryGenerationBase {
private static final Logger logger = Logger.getLogger(QueryGenerationBase.class);
-
- @Autowired
- protected SolrUtil solrUtil;
@Autowired
protected AuditSolrDao auditSolrDao;
@Autowired
protected ServiceLogsSolrDao serviceLogsSolrDao;
-
- @Autowired
- protected JSONUtil jsonUtil;
public static enum Condition {
OR, AND
@@ -69,9 +61,9 @@ public abstract class QueryGenerationBase extends QueryBase {
for (String temp : msgList) {
count += 1;
if (LogSearchConstants.SOLR_LOG_MESSAGE.equalsIgnoreCase(messageField)) {
- queryMsg.append(" " + operator + solrUtil.escapeForLogMessage(messageField, temp));
+ queryMsg.append(" " + operator + SolrUtil.escapeForLogMessage(messageField, temp));
} else {
- temp = solrUtil.escapeForStandardTokenizer(temp);
+ temp = SolrUtil.escapeForStandardTokenizer(temp);
if(temp.startsWith("\"") && temp.endsWith("\"")){
temp = temp.substring(1);
temp = temp.substring(0, temp.length()-1);
@@ -95,9 +87,9 @@ public abstract class QueryGenerationBase extends QueryBase {
String[] arrayOfSepratedString = commaSepratedString.split(LogSearchConstants.LIST_SEPARATOR);
String filterQuery = null;
if (Condition.OR.equals(condition)) {
- filterQuery = solrUtil.orList(operator + field, arrayOfSepratedString,"");
+ filterQuery = SolrUtil.orList(operator + field, arrayOfSepratedString,"");
} else if (Condition.AND.equals(condition)) {
- filterQuery = solrUtil.andList(operator + field, arrayOfSepratedString,"");
+ filterQuery = SolrUtil.andList(operator + field, arrayOfSepratedString,"");
}else{
logger.warn("Not a valid condition :" + condition.name());
}
@@ -207,15 +199,15 @@ public abstract class QueryGenerationBase extends QueryBase {
Integer maxRows = null;
try {
startIndex = (Integer) searchCriteria.getStartIndex();
- setStart(solrQuery, startIndex);
+ SolrUtil.setStart(solrQuery, startIndex);
} catch (ClassCastException e) {
- setStart(solrQuery, 0);
+ SolrUtil.setStart(solrQuery, 0);
}
try {
maxRows = (Integer) searchCriteria.getMaxRows();
- setRowCount(solrQuery, maxRows);
+ SolrUtil.setRowCount(solrQuery, maxRows);
} catch (ClassCastException e) {
- setRowCount(solrQuery, 10);
+ SolrUtil.setRowCount(solrQuery, 10);
}
if (startIndex != null && maxRows != null)
@@ -269,9 +261,9 @@ public abstract class QueryGenerationBase extends QueryBase {
String[] values = paramValue.split(LogSearchConstants.LIST_SEPARATOR);
switch (condition) {
case OR:
- return solrUtil.orList(solrFieldName, values,"");
+ return SolrUtil.orList(solrFieldName, values,"");
case AND:
- return solrUtil.andList(solrFieldName, values, "");
+ return SolrUtil.andList(solrFieldName, values, "");
default:
logger.error("Invalid condition " + condition.name());
}
@@ -292,10 +284,10 @@ public abstract class QueryGenerationBase extends QueryBase {
String query;;
switch (condition) {
case OR:
- query = solrUtil.orList(solrFieldName, arr,"");
+ query = SolrUtil.orList(solrFieldName, arr,"");
break;
case AND:
- query = solrUtil.andList(solrFieldName, arr, "");
+ query = SolrUtil.andList(solrFieldName, arr, "");
break;
default:
query=null;
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java
index a906ceb..7a27e1c 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java
@@ -32,7 +32,6 @@ import io.swagger.annotations.ApiOperation;
import org.apache.ambari.logsearch.common.LogSearchConstants;
import org.apache.ambari.logsearch.common.SearchCriteria;
import org.apache.ambari.logsearch.manager.LogsMgr;
-import org.apache.ambari.logsearch.util.RESTErrorUtil;
import org.apache.ambari.logsearch.view.VCountList;
import org.apache.ambari.logsearch.view.VNameValueList;
import org.apache.ambari.logsearch.view.VNodeList;
@@ -54,9 +53,6 @@ public class ServiceLogsREST {
@Autowired
LogsMgr logMgr;
- @Autowired
- RESTErrorUtil restErrorUtil;
-
@GET
@Produces({"application/json"})
@ApiOperation(SEARCH_LOGS_OD)
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/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 a79a737..699dc17 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
@@ -36,7 +36,6 @@ import io.swagger.annotations.ApiOperation;
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.VUserConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -52,9 +51,6 @@ import static org.apache.ambari.logsearch.doc.DocConstants.UserConfigOperationDe
public class UserConfigREST {
@Autowired
- RESTErrorUtil restErrorUtil;
-
- @Autowired
UserConfigMgr userConfigMgr;
@POST
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/solr/metrics/SolrMetricsLoader.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/solr/metrics/SolrMetricsLoader.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/solr/metrics/SolrMetricsLoader.java
index c644cd5..53e2ca2 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/solr/metrics/SolrMetricsLoader.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/solr/metrics/SolrMetricsLoader.java
@@ -27,9 +27,9 @@ import java.util.TreeMap;
import javax.management.MalformedObjectNameException;
+import org.apache.ambari.logsearch.common.PropertiesHelper;
import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient;
import org.apache.ambari.logsearch.solr.AmbariSolrCloudClientBuilder;
-import org.apache.ambari.logsearch.util.PropertiesUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
import org.apache.hadoop.metrics2.sink.timeline.TimelineMetrics;
@@ -172,15 +172,15 @@ public class SolrMetricsLoader extends TimerTask {
public static void startSolrMetricsLoaderTasks() {
try {
- String collectorHosts = PropertiesUtil.getProperty("logsearch.solr.metrics.collector.hosts");
+ String collectorHosts = PropertiesHelper.getProperty("logsearch.solr.metrics.collector.hosts");
if (StringUtils.isEmpty(collectorHosts)) {
LOG.warn("No Ambari Metrics service is available, no Solr metrics will be loaded!");
return;
}
- int solrJmxPort = PropertiesUtil.getIntProperty("logsearch.solr.jmx.port");
+ int solrJmxPort = PropertiesHelper.getIntProperty("logsearch.solr.jmx.port");
- String zkConnectString = PropertiesUtil.getProperty("logsearch.solr.zk_connect_string");
+ String zkConnectString = PropertiesHelper.getProperty("logsearch.solr.zk_connect_string");
AmbariSolrCloudClient ambariSolrCloudClient = new AmbariSolrCloudClientBuilder()
.withZkConnectString(zkConnectString)
.build();
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/BizUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/BizUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/BizUtil.java
index 814b8ee..bd6cfbb 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/BizUtil.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/BizUtil.java
@@ -43,13 +43,15 @@ import org.apache.log4j.Logger;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.util.SimpleOrderedMap;
-import org.springframework.stereotype.Component;
-@Component
public class BizUtil {
private static final Logger logger = Logger.getLogger(BizUtil.class);
- public String convertObjectToNormalText(SolrDocumentList docList) {
+ private BizUtil() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static String convertObjectToNormalText(SolrDocumentList docList) {
String textToSave = "";
HashMap<String, String> blankFieldsMap = new HashMap<String, String>();
if (docList == null){
@@ -76,7 +78,7 @@ public class BizUtil {
for (String field : fieldsForBlankCaculation) {
if (!StringUtils.isBlank(field)) {
- blankFieldsMap.put(field, addBlanksToString(maxLengthOfField - field.length(), field));
+ blankFieldsMap.put(field, StringUtils.rightPad(field, maxLengthOfField - field.length()));
}
}
@@ -114,7 +116,7 @@ public class BizUtil {
return textToSave;
}
- public VSummary buildSummaryForLogFile(SolrDocumentList docList) {
+ public static VSummary buildSummaryForLogFile(SolrDocumentList docList) {
VSummary vsummary = new VSummary();
if (CollectionUtils.isEmpty(docList)) {
return vsummary;
@@ -170,19 +172,8 @@ public class BizUtil {
return vsummary;
}
- private String addBlanksToString(int count, String field) {
- if (StringUtils.isBlank(field)) {
- return field;
- }
- if (count > 0) {
- return String.format("%-" + count + "s", field);
- }
- return field;
-
- }
-
@SuppressWarnings({"unchecked", "rawtypes"})
- public VBarDataList buildSummaryForTopCounts(SimpleOrderedMap<Object> jsonFacetResponse,String innerJsonKey,String outerJsonKey) {
+ public static VBarDataList buildSummaryForTopCounts(SimpleOrderedMap<Object> jsonFacetResponse,String innerJsonKey,String outerJsonKey) {
VBarDataList vBarDataList = new VBarDataList();
@@ -240,7 +231,7 @@ public class BizUtil {
return vBarDataList;
}
- public HashMap<String, String> sortHashMapByValues(HashMap<String, String> passedMap) {
+ public static HashMap<String, String> sortHashMapByValues(HashMap<String, String> passedMap) {
if (passedMap == null ) {
return passedMap;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/CommonUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/CommonUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/CommonUtil.java
index 8ec04f8..1cfe469 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/CommonUtil.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/CommonUtil.java
@@ -23,6 +23,10 @@ import java.security.SecureRandom;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
public class CommonUtil {
+ private CommonUtil() {
+ throw new UnsupportedOperationException();
+ }
+
private static SecureRandom secureRandom = new SecureRandom();
private static int counter = 0;
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ConfigUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ConfigUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ConfigUtil.java
deleted file mode 100644
index 88f92a2..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ConfigUtil.java
+++ /dev/null
@@ -1,140 +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.util;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import org.apache.ambari.logsearch.common.LogSearchConstants;
-import org.apache.ambari.logsearch.common.MessageEnums;
-import org.apache.ambari.logsearch.dao.SolrDaoBase;
-import org.apache.ambari.logsearch.manager.MgrBase;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.log4j.Logger;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
-
-public class ConfigUtil {
- private static final Logger logger = Logger.getLogger(MgrBase.class);
-
- public static HashMap<String, String> serviceLogsColumnMapping = new HashMap<String, String>();
-
- public static HashMap<String, String> auditLogsColumnMapping = new HashMap<String, String>();
-
-
- public static void initializeApplicationConfig() {
- initializeColumnMapping();
- }
-
- private static void intializeUISolrColumnMapping(String columnMappingArray[], HashMap<String, String> columnMappingMap) {
-
- if (columnMappingArray != null && columnMappingArray.length > 0) {
- for (String columnMapping : columnMappingArray) {
- String mapping[] = columnMapping.split(":");
- if (mapping.length > 1) {
- String solrField = mapping[0];
- String uiField = mapping[1];
-
- columnMappingMap.put(solrField + LogSearchConstants.SOLR_SUFFIX, uiField);
- columnMappingMap.put(uiField + LogSearchConstants.UI_SUFFIX, solrField);
- }
- }
- }
- }
- private static void initializeColumnMapping() {
- String serviceLogsColumnMappingArray[] = PropertiesUtil.getPropertyStringList("logsearch.solr.service.logs.column.mapping");
- String auditLogsColumnMappingArray[] = PropertiesUtil.getPropertyStringList("logsearch.solr.audit.logs.column.mapping");
-
- // Initializing column mapping for Service Logs
- intializeUISolrColumnMapping(serviceLogsColumnMappingArray, serviceLogsColumnMapping);
-
- // Initializing column mapping for Audit Logs
- intializeUISolrColumnMapping(auditLogsColumnMappingArray, auditLogsColumnMapping);
- }
-
- public static void extractSchemaFieldsName(String responseString, HashMap<String, String> schemaFieldsNameMap,
- HashMap<String, String> schemaFieldTypeMap) {
- try {
- JSONObject jsonObject = new JSONObject(responseString);
- JSONObject schemajsonObject = jsonObject.getJSONObject("schema");
- JSONArray jsonArrayList = schemajsonObject.getJSONArray("fields");
- JSONArray fieldTypeJsonArray = schemajsonObject
- .getJSONArray("fieldTypes");
- if (jsonArrayList == null) {
- return;
- }
- if (fieldTypeJsonArray == null) {
- return;
- }
- HashMap<String, String> _schemaFieldTypeMap = new HashMap<String, String>();
- HashMap<String, String> _schemaFieldsNameMap = new HashMap<String, String>();
- for (int i = 0; i < fieldTypeJsonArray.length(); i++) {
- JSONObject typeObject = fieldTypeJsonArray.getJSONObject(i);
- String name = typeObject.getString("name");
- String fieldTypeJson = typeObject.toString();
- _schemaFieldTypeMap.put(name, fieldTypeJson);
- }
-
- for (int i = 0; i < jsonArrayList.length(); i++) {
- JSONObject explrObject = jsonArrayList.getJSONObject(i);
- String name = explrObject.getString("name");
- String type = explrObject.getString("type");
- if (!name.contains("@") && !name.startsWith("_")
- && !name.contains("_md5") && !name.contains("_ms")
- && !name.contains(LogSearchConstants.NGRAM_SUFFIX)
- && !name.contains("tags") && !name.contains("_str")) {
- _schemaFieldsNameMap.put(name, type);
- }
- }
- schemaFieldsNameMap.clear();
- schemaFieldTypeMap.clear();
- schemaFieldsNameMap.putAll(_schemaFieldsNameMap);
- schemaFieldTypeMap.putAll(_schemaFieldTypeMap);
- } catch (Exception e) {
- logger.error(e + "Credentials not specified in logsearch.properties " + MessageEnums.ERROR_SYSTEM);
- }
- }
-
- @SuppressWarnings("rawtypes")
- public static void getSchemaFieldsName(String excludeArray[], List<String> fieldNames, SolrDaoBase solrDaoBase) {
- if (!solrDaoBase.schemaFieldsNameMap.isEmpty()) {
- Iterator iteratorSechmaFieldsName = solrDaoBase.schemaFieldsNameMap.entrySet().iterator();
- while (iteratorSechmaFieldsName.hasNext()) {
- Map.Entry fieldName = (Map.Entry) iteratorSechmaFieldsName.next();
- String field = "" + fieldName.getKey();
- if (!isExclude(field, excludeArray)) {
- fieldNames.add(field);
- }
- }
- }
- }
-
- private static boolean isExclude(String name, String excludeArray[]) {
- if (!ArrayUtils.isEmpty(excludeArray)) {
- for (String exclude : excludeArray) {
- if (name.equals(exclude)){
- return true;
- }
- }
- }
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/DateUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/DateUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/DateUtil.java
index 516d828..0de0dbc 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/DateUtil.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/DateUtil.java
@@ -24,26 +24,24 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import org.apache.ambari.logsearch.common.LogSearchConstants;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DateUtils;
import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-@Component
public class DateUtil {
private static final Logger logger = Logger.getLogger(DateUtil.class);
private DateUtil() {
-
+ throw new UnsupportedOperationException();
}
- public String addOffsetToDate(String date, Long utcOffset, String dateFormat) {
+ public static String addOffsetToDate(String date, Long utcOffset, String dateFormat) {
if (StringUtils.isBlank(date)) {
logger.debug("input date is empty or null.");
return null;
@@ -64,7 +62,7 @@ public class DateUtil {
}
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
Date startDate = formatter.parse(modifiedDate);
- long toWithOffset = getTimeWithOffset(startDate, utcOffset);
+ long toWithOffset = startDate.getTime() + TimeUnit.MINUTES.toMillis(utcOffset);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(toWithOffset);
retDate = formatter.format(calendar.getTime());
@@ -74,25 +72,17 @@ public class DateUtil {
return retDate;
}
- private long getTimeWithOffset(Date date, Long utcOffset) {
- return date.getTime() + TimeUnit.MINUTES.toMillis(utcOffset);
- }
-
- public String getCurrentDateInString() {
+ public static String getCurrentDateInString() {
DateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss", Locale.ENGLISH);
Date today = Calendar.getInstance().getTime();
return df.format(today);
}
- public Date getTodayFromDate() {
- Calendar c = new GregorianCalendar();
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- return c.getTime();
+ public static Date getTodayFromDate() {
+ return DateUtils.truncate(new Date(), Calendar.DATE);
}
- public String convertGivenDateFormatToSolrDateFormat(Date date) throws ParseException {
+ public static String convertGivenDateFormatToSolrDateFormat(Date date) throws ParseException {
String time = date.toString();
SimpleDateFormat input = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
SimpleDateFormat output = new SimpleDateFormat(LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z, Locale.ENGLISH);
@@ -103,7 +93,7 @@ public class DateUtil {
return output.format(d);
}
- public String convertDateWithMillisecondsToSolrDate(Date date) {
+ public static String convertDateWithMillisecondsToSolrDate(Date date) {
if (date == null) {
return "";
}
@@ -114,7 +104,7 @@ public class DateUtil {
return formatter.format(date);
}
- public String convertSolrDateToNormalDateFormat(long d, long utcOffset) throws ParseException {
+ public static String convertSolrDateToNormalDateFormat(long d, long utcOffset) throws ParseException {
Date date = new Date(d);
SimpleDateFormat formatter = new SimpleDateFormat(LogSearchConstants.SOLR_DATE_FORMAT, Locale.ENGLISH);
TimeZone timeZone = TimeZone.getTimeZone("GMT");
@@ -124,7 +114,7 @@ public class DateUtil {
}
- public boolean isDateValid(String value) {
+ public static boolean isDateValid(String value) {
if (StringUtils.isBlank(value)) {
return false;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afbca7f/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ExternalServerClient.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ExternalServerClient.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ExternalServerClient.java
deleted file mode 100644
index 882a8bd..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ExternalServerClient.java
+++ /dev/null
@@ -1,96 +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.util;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.PostConstruct;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.apache.ambari.logsearch.web.security.LogsearchAbstractAuthenticationProvider;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-import org.glassfish.jersey.client.JerseyClient;
-import org.glassfish.jersey.client.JerseyClientBuilder;
-import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
-import org.glassfish.jersey.filter.LoggingFilter;
-import org.springframework.stereotype.Component;
-
-/**
- * Layer to send REST request to External server using jersey client
- */
-@Component
-public class ExternalServerClient {
- private static Logger LOG = Logger.getLogger(ExternalServerClient.class);
- private static final ThreadLocal<JerseyClient> localJerseyClient = new ThreadLocal<JerseyClient>(){
- @Override
- protected JerseyClient initialValue() {
- return JerseyClientBuilder.createClient();
- }
- };
- private String hostURL = "http://host:ip";// default
- private boolean enableLog = false;// default
-
- @PostConstruct
- public void initialization() {
- hostURL = PropertiesUtil.getProperty(
- LogsearchAbstractAuthenticationProvider.AUTH_METHOD_PROP_START_WITH
- + "external_auth.host_url", hostURL);
- }
-
- /**
- * Send GET request to an external server
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public Object sendGETRequest(String url, Class klass, MultivaluedMap<String, String> queryParam,
- String username, String password)
- throws Exception {
- url = hostURL + url;
- JerseyClient client = localJerseyClient.get();
- HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basicBuilder().build();
-
- client.register(authFeature);
- if (enableLog) {
- client.register(LoggingFilter.class);
- }
-
- WebTarget target = client.target(url);
- LOG.debug("URL: " + url);
- for (Map.Entry<String, List<String>> entry : queryParam.entrySet()) {
- target = target.queryParam(entry.getKey(), entry.getValue());
- LOG.debug(
- String.format("Query parameter: name - %s ; value - %s ;" + entry.getKey(), StringUtils.join(entry.getValue(),',')));
- }
- target
- .property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_USERNAME, username)
- .property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_PASSWORD, password);
- Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
- try {
- return invocationBuilder.get().readEntity(klass);
- } catch (Exception e) {
- throw new Exception(e.getCause());
- } finally {
- localJerseyClient.remove();
- }
- }
-}